Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <deque> 5 #include <deque>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 DISALLOW_COPY_AND_ASSIGN(DestructionMessageFilter); 185 DISALLOW_COPY_AND_ASSIGN(DestructionMessageFilter);
186 }; 186 };
187 187
188 void OnChannelDestroyed() { 188 void OnChannelDestroyed() {
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
190 190
191 EXPECT_FALSE(channel_destroyed_); 191 EXPECT_FALSE(channel_destroyed_);
192 channel_destroyed_ = true; 192 channel_destroyed_ = true;
193 if (waiting_for_channel_destruction_) { 193 if (waiting_for_channel_destruction_) {
194 waiting_for_channel_destruction_ = false; 194 waiting_for_channel_destruction_ = false;
195 MessageLoop::current()->Quit(); 195 base::MessageLoop::current()->Quit();
196 } 196 }
197 } 197 }
198 198
199 bool channel_destroyed_; 199 bool channel_destroyed_;
200 bool waiting_for_channel_destruction_; 200 bool waiting_for_channel_destruction_;
201 201
202 DISALLOW_COPY_AND_ASSIGN(ChannelDestructionWatcher); 202 DISALLOW_COPY_AND_ASSIGN(ChannelDestructionWatcher);
203 }; 203 };
204 204
205 // PrerenderContents that stops the UI message loop on DidStopLoading(). 205 // PrerenderContents that stops the UI message loop on DidStopLoading().
(...skipping 17 matching lines...) Expand all
223 was_hidden_(false), 223 was_hidden_(false),
224 was_shown_(false), 224 was_shown_(false),
225 should_be_shown_(expected_final_status == FINAL_STATUS_USED), 225 should_be_shown_(expected_final_status == FINAL_STATUS_USED),
226 quit_message_loop_on_destruction_( 226 quit_message_loop_on_destruction_(
227 expected_final_status != FINAL_STATUS_APP_TERMINATING && 227 expected_final_status != FINAL_STATUS_APP_TERMINATING &&
228 expected_final_status != FINAL_STATUS_MAX), 228 expected_final_status != FINAL_STATUS_MAX),
229 expected_pending_prerenders_(0), 229 expected_pending_prerenders_(0),
230 prerender_should_wait_for_ready_title_( 230 prerender_should_wait_for_ready_title_(
231 prerender_should_wait_for_ready_title) { 231 prerender_should_wait_for_ready_title) {
232 if (expected_number_of_loads == 0) 232 if (expected_number_of_loads == 0)
233 MessageLoopForUI::current()->Quit(); 233 base::MessageLoopForUI::current()->Quit();
234 } 234 }
235 235
236 virtual ~TestPrerenderContents() { 236 virtual ~TestPrerenderContents() {
237 if (expected_final_status_ == FINAL_STATUS_MAX) { 237 if (expected_final_status_ == FINAL_STATUS_MAX) {
238 EXPECT_EQ(match_complete_status(), MATCH_COMPLETE_REPLACEMENT); 238 EXPECT_EQ(match_complete_status(), MATCH_COMPLETE_REPLACEMENT);
239 } else { 239 } else {
240 EXPECT_EQ(expected_final_status_, final_status()) << 240 EXPECT_EQ(expected_final_status_, final_status()) <<
241 " when testing URL " << prerender_url().path() << 241 " when testing URL " << prerender_url().path() <<
242 " (Expected: " << NameFromFinalStatus(expected_final_status_) << 242 " (Expected: " << NameFromFinalStatus(expected_final_status_) <<
243 ", Actual: " << NameFromFinalStatus(final_status()) << ")"; 243 ", Actual: " << NameFromFinalStatus(final_status()) << ")";
(...skipping 12 matching lines...) Expand all
256 EXPECT_TRUE(new_render_view_host_); 256 EXPECT_TRUE(new_render_view_host_);
257 257
258 EXPECT_EQ(should_be_shown_, was_shown_); 258 EXPECT_EQ(should_be_shown_, was_shown_);
259 259
260 // When the PrerenderContents is destroyed, quit the UI message loop. 260 // When the PrerenderContents is destroyed, quit the UI message loop.
261 // This happens on navigation to used prerendered pages, and soon 261 // This happens on navigation to used prerendered pages, and soon
262 // after cancellation of unused prerendered pages. 262 // after cancellation of unused prerendered pages.
263 if (quit_message_loop_on_destruction_) { 263 if (quit_message_loop_on_destruction_) {
264 // The message loop may not be running if this is swapped in 264 // The message loop may not be running if this is swapped in
265 // synchronously on a Navigation. 265 // synchronously on a Navigation.
266 MessageLoop* loop = MessageLoopForUI::current(); 266 base::MessageLoop* loop = base::MessageLoopForUI::current();
267 if (loop->is_running()) 267 if (loop->is_running())
268 loop->Quit(); 268 loop->Quit();
269 } 269 }
270 } 270 }
271 271
272 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE { 272 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE {
273 // On quit, it's possible to end up here when render processes are closed 273 // On quit, it's possible to end up here when render processes are closed
274 // before the PrerenderManager is destroyed. As a result, it's possible to 274 // before the PrerenderManager is destroyed. As a result, it's possible to
275 // get either FINAL_STATUS_APP_TERMINATING or FINAL_STATUS_RENDERER_CRASHED 275 // get either FINAL_STATUS_APP_TERMINATING or FINAL_STATUS_RENDERER_CRASHED
276 // on quit. 276 // on quit.
(...skipping 15 matching lines...) Expand all
292 if (url.spec() != content::kChromeUICrashURL) 292 if (url.spec() != content::kChromeUICrashURL)
293 return PrerenderContents::AddAliasURL(url); 293 return PrerenderContents::AddAliasURL(url);
294 return true; 294 return true;
295 } 295 }
296 296
297 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE { 297 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE {
298 PrerenderContents::DidStopLoading(render_view_host); 298 PrerenderContents::DidStopLoading(render_view_host);
299 ++number_of_loads_; 299 ++number_of_loads_;
300 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status_) && 300 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status_) &&
301 number_of_loads_ == expected_number_of_loads_) { 301 number_of_loads_ == expected_number_of_loads_) {
302 MessageLoopForUI::current()->Quit(); 302 base::MessageLoopForUI::current()->Quit();
303 } 303 }
304 } 304 }
305 305
306 virtual void AddPendingPrerender( 306 virtual void AddPendingPrerender(
307 scoped_ptr<PendingPrerenderInfo> pending_prerender_info) OVERRIDE { 307 scoped_ptr<PendingPrerenderInfo> pending_prerender_info) OVERRIDE {
308 PrerenderContents::AddPendingPrerender(pending_prerender_info.Pass()); 308 PrerenderContents::AddPendingPrerender(pending_prerender_info.Pass());
309 if (expected_pending_prerenders_ > 0 && 309 if (expected_pending_prerenders_ > 0 &&
310 pending_prerender_count() == expected_pending_prerenders_) { 310 pending_prerender_count() == expected_pending_prerenders_) {
311 MessageLoop::current()->Quit(); 311 base::MessageLoop::current()->Quit();
312 } 312 }
313 } 313 }
314 314
315 virtual WebContents* CreateWebContents( 315 virtual WebContents* CreateWebContents(
316 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE { 316 content::SessionStorageNamespace* session_storage_namespace) OVERRIDE {
317 WebContents* web_contents = PrerenderContents::CreateWebContents( 317 WebContents* web_contents = PrerenderContents::CreateWebContents(
318 session_storage_namespace); 318 session_storage_namespace);
319 string16 ready_title = ASCIIToUTF16(kReadyTitle); 319 string16 ready_title = ASCIIToUTF16(kReadyTitle);
320 if (prerender_should_wait_for_ready_title_) 320 if (prerender_should_wait_for_ready_title_)
321 ready_title_watcher_.reset(new content::TitleWatcher( 321 ready_title_watcher_.reset(new content::TitleWatcher(
(...skipping 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 2398
2399 // Checks that when the history is cleared, prerendering is cancelled and 2399 // Checks that when the history is cleared, prerendering is cancelled and
2400 // prerendering history is cleared. 2400 // prerendering history is cleared.
2401 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) { 2401 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) {
2402 PrerenderTestURL("files/prerender/prerender_page.html", 2402 PrerenderTestURL("files/prerender/prerender_page.html",
2403 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, 2403 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED,
2404 1); 2404 1);
2405 2405
2406 // Post a task to clear the history, and run the message loop until it 2406 // Post a task to clear the history, and run the message loop until it
2407 // destroys the prerender. 2407 // destroys the prerender.
2408 MessageLoop::current()->PostTask( 2408 base::MessageLoop::current()->PostTask(
2409 FROM_HERE, 2409 FROM_HERE,
2410 base::Bind(&ClearBrowsingData, current_browser(), 2410 base::Bind(&ClearBrowsingData,
2411 current_browser(),
2411 BrowsingDataRemover::REMOVE_HISTORY)); 2412 BrowsingDataRemover::REMOVE_HISTORY));
2412 content::RunMessageLoop(); 2413 content::RunMessageLoop();
2413 2414
2414 // Make sure prerender history was cleared. 2415 // Make sure prerender history was cleared.
2415 EXPECT_EQ(0, GetHistoryLength()); 2416 EXPECT_EQ(0, GetHistoryLength());
2416 } 2417 }
2417 2418
2418 // Checks that when the cache is cleared, prerenders are cancelled but 2419 // Checks that when the cache is cleared, prerenders are cancelled but
2419 // prerendering history is not cleared. 2420 // prerendering history is not cleared.
2420 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearCache) { 2421 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearCache) {
2421 PrerenderTestURL("files/prerender/prerender_page.html", 2422 PrerenderTestURL("files/prerender/prerender_page.html",
2422 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, 2423 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED,
2423 1); 2424 1);
2424 2425
2425 // Post a task to clear the cache, and run the message loop until it 2426 // Post a task to clear the cache, and run the message loop until it
2426 // destroys the prerender. 2427 // destroys the prerender.
2427 MessageLoop::current()->PostTask(FROM_HERE, 2428 base::MessageLoop::current()->PostTask(
2428 base::Bind(&ClearBrowsingData, current_browser(), 2429 FROM_HERE,
2430 base::Bind(&ClearBrowsingData,
2431 current_browser(),
2429 BrowsingDataRemover::REMOVE_CACHE)); 2432 BrowsingDataRemover::REMOVE_CACHE));
2430 content::RunMessageLoop(); 2433 content::RunMessageLoop();
2431 2434
2432 // Make sure prerender history was not cleared. Not a vital behavior, but 2435 // Make sure prerender history was not cleared. Not a vital behavior, but
2433 // used to compare with PrerenderClearHistory test. 2436 // used to compare with PrerenderClearHistory test.
2434 EXPECT_EQ(1, GetHistoryLength()); 2437 EXPECT_EQ(1, GetHistoryLength());
2435 } 2438 }
2436 2439
2437 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) { 2440 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) {
2438 PrerenderTestURL("files/prerender/prerender_page.html", 2441 PrerenderTestURL("files/prerender/prerender_page.html",
2439 FINAL_STATUS_CANCELLED, 2442 FINAL_STATUS_CANCELLED,
2440 1); 2443 1);
2441 // Post a task to cancel all the prerenders. 2444 // Post a task to cancel all the prerenders.
2442 MessageLoop::current()->PostTask( 2445 base::MessageLoop::current()->PostTask(
2443 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager())); 2446 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2444 content::RunMessageLoop(); 2447 content::RunMessageLoop();
2445 EXPECT_TRUE(GetPrerenderContents() == NULL); 2448 EXPECT_TRUE(GetPrerenderContents() == NULL);
2446 } 2449 }
2447 2450
2448 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEvents) { 2451 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEvents) {
2449 PrerenderTestURL("files/prerender/prerender_page.html", 2452 PrerenderTestURL("files/prerender/prerender_page.html",
2450 FINAL_STATUS_CANCELLED, 1); 2453 FINAL_STATUS_CANCELLED, 1);
2451 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0)); 2454 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
2452 EXPECT_TRUE(DidReceivePrerenderLoadEventForLinkNumber(0)); 2455 EXPECT_TRUE(DidReceivePrerenderLoadEventForLinkNumber(0));
2453 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0)); 2456 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
2454 2457
2455 MessageLoop::current()->PostTask( 2458 base::MessageLoop::current()->PostTask(
2456 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager())); 2459 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2457 content::RunMessageLoop(); 2460 content::RunMessageLoop();
2458 2461
2459 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0)); 2462 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
2460 EXPECT_TRUE(DidReceivePrerenderStopEventForLinkNumber(0)); 2463 EXPECT_TRUE(DidReceivePrerenderStopEventForLinkNumber(0));
2461 EXPECT_FALSE(HadPrerenderEventErrors()); 2464 EXPECT_FALSE(HadPrerenderEventErrors());
2462 } 2465 }
2463 2466
2464 // Cancels the prerender of a page with its own prerender. The second prerender 2467 // Cancels the prerender of a page with its own prerender. The second prerender
2465 // should never be started. 2468 // should never be started.
2466 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 2469 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2467 PrerenderCancelPrerenderWithPrerender) { 2470 PrerenderCancelPrerenderWithPrerender) {
2468 PrerenderTestURL("files/prerender/prerender_infinite_a.html", 2471 PrerenderTestURL("files/prerender/prerender_infinite_a.html",
2469 FINAL_STATUS_CANCELLED, 2472 FINAL_STATUS_CANCELLED,
2470 1); 2473 1);
2471 // Post a task to cancel all the prerenders. 2474 // Post a task to cancel all the prerenders.
2472 MessageLoop::current()->PostTask( 2475 base::MessageLoop::current()->PostTask(
2473 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager())); 2476 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2474 content::RunMessageLoop(); 2477 content::RunMessageLoop();
2475 EXPECT_TRUE(GetPrerenderContents() == NULL); 2478 EXPECT_TRUE(GetPrerenderContents() == NULL);
2476 } 2479 }
2477 2480
2478 // PrerenderBrowserTest.PrerenderEventsNoLoad may pass flakily on regression, 2481 // PrerenderBrowserTest.PrerenderEventsNoLoad may pass flakily on regression,
2479 // so please be aggressive about filing bugs when this test is failing. 2482 // so please be aggressive about filing bugs when this test is failing.
2480 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEventsNoLoad) { 2483 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEventsNoLoad) {
2481 // This should be canceled. 2484 // This should be canceled.
2482 PrerenderTestURL("files/prerender/prerender_http_auth_container.html", 2485 PrerenderTestURL("files/prerender/prerender_http_auth_container.html",
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 // Checks that non-http/https main page redirects cancel the prerender. 2784 // Checks that non-http/https main page redirects cancel the prerender.
2782 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 2785 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2783 PrerenderCancelMainFrameRedirectUnsupportedScheme) { 2786 PrerenderCancelMainFrameRedirectUnsupportedScheme) {
2784 GURL url = test_server()->GetURL( 2787 GURL url = test_server()->GetURL(
2785 CreateServerRedirect("invalidscheme://www.google.com/test.html")); 2788 CreateServerRedirect("invalidscheme://www.google.com/test.html"));
2786 PrerenderTestURL(url, FINAL_STATUS_UNSUPPORTED_SCHEME, 1); 2789 PrerenderTestURL(url, FINAL_STATUS_UNSUPPORTED_SCHEME, 1);
2787 NavigateToDestURL(); 2790 NavigateToDestURL();
2788 } 2791 }
2789 2792
2790 } // namespace prerender 2793 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698