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

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: rebase again Created 7 years, 6 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 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after
2399 2399
2400 // Checks that when the history is cleared, prerendering is cancelled and 2400 // Checks that when the history is cleared, prerendering is cancelled and
2401 // prerendering history is cleared. 2401 // prerendering history is cleared.
2402 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) { 2402 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) {
2403 PrerenderTestURL("files/prerender/prerender_page.html", 2403 PrerenderTestURL("files/prerender/prerender_page.html",
2404 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, 2404 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED,
2405 1); 2405 1);
2406 2406
2407 // Post a task to clear the history, and run the message loop until it 2407 // Post a task to clear the history, and run the message loop until it
2408 // destroys the prerender. 2408 // destroys the prerender.
2409 MessageLoop::current()->PostTask( 2409 base::MessageLoop::current()->PostTask(
2410 FROM_HERE, 2410 FROM_HERE,
2411 base::Bind(&ClearBrowsingData, current_browser(), 2411 base::Bind(&ClearBrowsingData, current_browser(),
2412 BrowsingDataRemover::REMOVE_HISTORY)); 2412 BrowsingDataRemover::REMOVE_HISTORY));
2413 content::RunMessageLoop(); 2413 content::RunMessageLoop();
2414 2414
2415 // Make sure prerender history was cleared. 2415 // Make sure prerender history was cleared.
2416 EXPECT_EQ(0, GetHistoryLength()); 2416 EXPECT_EQ(0, GetHistoryLength());
2417 } 2417 }
2418 2418
2419 // Checks that when the cache is cleared, prerenders are cancelled but 2419 // Checks that when the cache is cleared, prerenders are cancelled but
2420 // prerendering history is not cleared. 2420 // prerendering history is not cleared.
2421 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearCache) { 2421 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearCache) {
2422 PrerenderTestURL("files/prerender/prerender_page.html", 2422 PrerenderTestURL("files/prerender/prerender_page.html",
2423 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, 2423 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED,
2424 1); 2424 1);
2425 2425
2426 // 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
2427 // destroys the prerender. 2427 // destroys the prerender.
2428 MessageLoop::current()->PostTask(FROM_HERE, 2428 base::MessageLoop::current()->PostTask(FROM_HERE,
2429 base::Bind(&ClearBrowsingData, current_browser(), 2429 base::Bind(&ClearBrowsingData, current_browser(),
2430 BrowsingDataRemover::REMOVE_CACHE)); 2430 BrowsingDataRemover::REMOVE_CACHE));
2431 content::RunMessageLoop(); 2431 content::RunMessageLoop();
2432 2432
2433 // Make sure prerender history was not cleared. Not a vital behavior, but 2433 // Make sure prerender history was not cleared. Not a vital behavior, but
2434 // used to compare with PrerenderClearHistory test. 2434 // used to compare with PrerenderClearHistory test.
2435 EXPECT_EQ(1, GetHistoryLength()); 2435 EXPECT_EQ(1, GetHistoryLength());
2436 } 2436 }
2437 2437
2438 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) { 2438 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) {
2439 PrerenderTestURL("files/prerender/prerender_page.html", 2439 PrerenderTestURL("files/prerender/prerender_page.html",
2440 FINAL_STATUS_CANCELLED, 2440 FINAL_STATUS_CANCELLED,
2441 1); 2441 1);
2442 // Post a task to cancel all the prerenders. 2442 // Post a task to cancel all the prerenders.
2443 MessageLoop::current()->PostTask( 2443 base::MessageLoop::current()->PostTask(
2444 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager())); 2444 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2445 content::RunMessageLoop(); 2445 content::RunMessageLoop();
2446 EXPECT_TRUE(GetPrerenderContents() == NULL); 2446 EXPECT_TRUE(GetPrerenderContents() == NULL);
2447 } 2447 }
2448 2448
2449 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEvents) { 2449 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEvents) {
2450 PrerenderTestURL("files/prerender/prerender_page.html", 2450 PrerenderTestURL("files/prerender/prerender_page.html",
2451 FINAL_STATUS_CANCELLED, 1); 2451 FINAL_STATUS_CANCELLED, 1);
2452 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0)); 2452 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
2453 EXPECT_TRUE(DidReceivePrerenderLoadEventForLinkNumber(0)); 2453 EXPECT_TRUE(DidReceivePrerenderLoadEventForLinkNumber(0));
2454 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0)); 2454 EXPECT_FALSE(DidReceivePrerenderStopEventForLinkNumber(0));
2455 2455
2456 MessageLoop::current()->PostTask( 2456 base::MessageLoop::current()->PostTask(
2457 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager())); 2457 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2458 content::RunMessageLoop(); 2458 content::RunMessageLoop();
2459 2459
2460 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0)); 2460 EXPECT_TRUE(DidReceivePrerenderStartEventForLinkNumber(0));
2461 EXPECT_TRUE(DidReceivePrerenderStopEventForLinkNumber(0)); 2461 EXPECT_TRUE(DidReceivePrerenderStopEventForLinkNumber(0));
2462 EXPECT_FALSE(HadPrerenderEventErrors()); 2462 EXPECT_FALSE(HadPrerenderEventErrors());
2463 } 2463 }
2464 2464
2465 // Cancels the prerender of a page with its own prerender. The second prerender 2465 // Cancels the prerender of a page with its own prerender. The second prerender
2466 // should never be started. 2466 // should never be started.
2467 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 2467 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2468 PrerenderCancelPrerenderWithPrerender) { 2468 PrerenderCancelPrerenderWithPrerender) {
2469 PrerenderTestURL("files/prerender/prerender_infinite_a.html", 2469 PrerenderTestURL("files/prerender/prerender_infinite_a.html",
2470 FINAL_STATUS_CANCELLED, 2470 FINAL_STATUS_CANCELLED,
2471 1); 2471 1);
2472 // Post a task to cancel all the prerenders. 2472 // Post a task to cancel all the prerenders.
2473 MessageLoop::current()->PostTask( 2473 base::MessageLoop::current()->PostTask(
2474 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager())); 2474 FROM_HERE, base::Bind(&CancelAllPrerenders, GetPrerenderManager()));
2475 content::RunMessageLoop(); 2475 content::RunMessageLoop();
2476 EXPECT_TRUE(GetPrerenderContents() == NULL); 2476 EXPECT_TRUE(GetPrerenderContents() == NULL);
2477 } 2477 }
2478 2478
2479 // PrerenderBrowserTest.PrerenderEventsNoLoad may pass flakily on regression, 2479 // PrerenderBrowserTest.PrerenderEventsNoLoad may pass flakily on regression,
2480 // so please be aggressive about filing bugs when this test is failing. 2480 // so please be aggressive about filing bugs when this test is failing.
2481 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEventsNoLoad) { 2481 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderEventsNoLoad) {
2482 // This should be canceled. 2482 // This should be canceled.
2483 PrerenderTestURL("files/prerender/prerender_http_auth_container.html", 2483 PrerenderTestURL("files/prerender/prerender_http_auth_container.html",
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2788 // Checks that non-http/https main page redirects cancel the prerender. 2788 // Checks that non-http/https main page redirects cancel the prerender.
2789 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 2789 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2790 PrerenderCancelMainFrameRedirectUnsupportedScheme) { 2790 PrerenderCancelMainFrameRedirectUnsupportedScheme) {
2791 GURL url = test_server()->GetURL( 2791 GURL url = test_server()->GetURL(
2792 CreateServerRedirect("invalidscheme://www.google.com/test.html")); 2792 CreateServerRedirect("invalidscheme://www.google.com/test.html"));
2793 PrerenderTestURL(url, FINAL_STATUS_UNSUPPORTED_SCHEME, 1); 2793 PrerenderTestURL(url, FINAL_STATUS_UNSUPPORTED_SCHEME, 1);
2794 NavigateToDestURL(); 2794 NavigateToDestURL();
2795 } 2795 }
2796 2796
2797 } // namespace prerender 2797 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prefs/chrome_pref_service_unittest.cc ('k') | chrome/browser/prerender/prerender_local_predictor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698