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

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

Issue 7104081: Browser Test (Prerendering) for Favicon (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/test/test_timeouts.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 11 #include "chrome/browser/content_settings/host_content_settings_map.h"
12 #include "chrome/browser/favicon/favicon_tab_helper.h"
11 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/prerender/prerender_contents.h" 14 #include "chrome/browser/prerender/prerender_contents.h"
13 #include "chrome/browser/prerender/prerender_manager.h" 15 #include "chrome/browser/prerender/prerender_manager.h"
14 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "chrome/browser/task_manager/task_manager.h" 18 #include "chrome/browser/task_manager/task_manager.h"
17 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
20 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 expected_final_status); 376 expected_final_status);
375 PrerenderTestURLImpl(url, expected_final_status_queue, total_navigations); 377 PrerenderTestURLImpl(url, expected_final_status_queue, total_navigations);
376 } 378 }
377 379
378 void NavigateToDestURL() const { 380 void NavigateToDestURL() const {
379 NavigateToURLImpl(dest_url_); 381 NavigateToURLImpl(dest_url_);
380 } 382 }
381 383
382 void OpenDestUrlInNewWindowViaJs() const { 384 void OpenDestUrlInNewWindowViaJs() const {
383 // Make sure in navigating we have a URL to use in the PrerenderManager. 385 // Make sure in navigating we have a URL to use in the PrerenderManager.
384 TestPrerenderContents* prerender_contents = 386 TestPrerenderContents* prerender_contents = GetPrerenderContents();
385 static_cast<TestPrerenderContents*>(
386 prerender_manager()->FindEntry(dest_url_));
387 ASSERT_TRUE(prerender_contents != NULL); 387 ASSERT_TRUE(prerender_contents != NULL);
388 prerender_contents->set_quit_message_loop_on_destruction(false); 388 prerender_contents->set_quit_message_loop_on_destruction(false);
389 389
390 bool open_window_result = false; 390 bool open_window_result = false;
391 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 391 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
392 browser()->GetSelectedTabContents()->render_view_host(), L"", 392 browser()->GetSelectedTabContents()->render_view_host(), L"",
393 L"window.domAutomationController.send(JsOpenLinkInNewWindow())", 393 L"window.domAutomationController.send(JsOpenLinkInNewWindow())",
394 &open_window_result)); 394 &open_window_result));
395 EXPECT_TRUE(open_window_result); 395 EXPECT_TRUE(open_window_result);
396 396
397 // If the prerender contents has not been destroyed, run message loop. 397 // If the prerender contents has not been destroyed, run message loop.
398 if (prerender_manager()->FindEntry(dest_url_) != NULL) { 398 if (GetPrerenderContents() != NULL) {
399 prerender_contents->set_quit_message_loop_on_destruction(true); 399 prerender_contents->set_quit_message_loop_on_destruction(true);
400 ui_test_utils::RunMessageLoop(); 400 ui_test_utils::RunMessageLoop();
401 } 401 }
402 } 402 }
403 403
404 void OpenDestUrlInNewWindowViaClick() const { 404 void OpenDestUrlInNewWindowViaClick() const {
405 // Make sure in navigating we have a URL to use in the PrerenderManager. 405 // Make sure in navigating we have a URL to use in the PrerenderManager.
406 TestPrerenderContents* prerender_contents = 406 TestPrerenderContents* prerender_contents = GetPrerenderContents();
407 static_cast<TestPrerenderContents*>(
408 prerender_manager()->FindEntry(dest_url_));
409 ASSERT_TRUE(prerender_contents != NULL); 407 ASSERT_TRUE(prerender_contents != NULL);
410 prerender_contents->set_quit_message_loop_on_destruction(false); 408 prerender_contents->set_quit_message_loop_on_destruction(false);
411 409
412 bool click_prerendered_link_result = false; 410 bool click_prerendered_link_result = false;
413 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 411 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
414 browser()->GetSelectedTabContents()->render_view_host(), L"", 412 browser()->GetSelectedTabContents()->render_view_host(), L"",
415 L"window.domAutomationController.send(ClickOpenLinkInNewWindow())", 413 L"window.domAutomationController.send(ClickOpenLinkInNewWindow())",
416 &click_prerendered_link_result)); 414 &click_prerendered_link_result));
417 EXPECT_TRUE(click_prerendered_link_result); 415 EXPECT_TRUE(click_prerendered_link_result);
418 416
419 // If the prerender contents has not been destroyed, run message loop. 417 // If the prerender contents has not been destroyed, run message loop.
420 if (prerender_manager()->FindEntry(dest_url_) != NULL) { 418 if (GetPrerenderContents() != NULL) {
421 prerender_contents->set_quit_message_loop_on_destruction(true); 419 prerender_contents->set_quit_message_loop_on_destruction(true);
422 ui_test_utils::RunMessageLoop(); 420 ui_test_utils::RunMessageLoop();
423 } 421 }
424 } 422 }
425 423
426 // Should be const but test_server()->GetURL(...) is not const. 424 // Should be const but test_server()->GetURL(...) is not const.
427 void NavigateToURL(const std::string& dest_html_file) { 425 void NavigateToURL(const std::string& dest_html_file) {
428 GURL dest_url = test_server()->GetURL(dest_html_file); 426 GURL dest_url = test_server()->GetURL(dest_html_file);
429 NavigateToURLImpl(dest_url); 427 NavigateToURLImpl(dest_url);
430 } 428 }
(...skipping 27 matching lines...) Expand all
458 PrerenderManager* prerender_manager() const { 456 PrerenderManager* prerender_manager() const {
459 Profile* profile = browser()->GetSelectedTabContents()->profile(); 457 Profile* profile = browser()->GetSelectedTabContents()->profile();
460 PrerenderManager* prerender_manager = profile->GetPrerenderManager(); 458 PrerenderManager* prerender_manager = profile->GetPrerenderManager();
461 return prerender_manager; 459 return prerender_manager;
462 } 460 }
463 461
464 FakeSafeBrowsingService* GetSafeBrowsingService() { 462 FakeSafeBrowsingService* GetSafeBrowsingService() {
465 return safe_browsing_factory_->most_recent_service(); 463 return safe_browsing_factory_->most_recent_service();
466 } 464 }
467 465
466 TestPrerenderContents* GetPrerenderContents() const {
467 return static_cast<TestPrerenderContents*>(
468 prerender_manager()->FindEntry(dest_url_));
469 }
470
468 private: 471 private:
469 void PrerenderTestURLImpl( 472 void PrerenderTestURLImpl(
470 const GURL& url, 473 const GURL& url,
471 const std::deque<FinalStatus>& expected_final_status_queue, 474 const std::deque<FinalStatus>& expected_final_status_queue,
472 int total_navigations) { 475 int total_navigations) {
473 dest_url_ = url; 476 dest_url_ = url;
474 477
475 std::vector<net::TestServer::StringPair> replacement_text; 478 std::vector<net::TestServer::StringPair> replacement_text;
476 replacement_text.push_back( 479 replacement_text.push_back(
477 make_pair("REPLACE_WITH_PRERENDER_URL", dest_url_.spec())); 480 make_pair("REPLACE_WITH_PRERENDER_URL", dest_url_.spec()));
(...skipping 25 matching lines...) Expand all
503 prerender_manager()->SetPrerenderContentsFactory( 506 prerender_manager()->SetPrerenderContentsFactory(
504 prerender_contents_factory_); 507 prerender_contents_factory_);
505 FinalStatus expected_final_status = expected_final_status_queue.front(); 508 FinalStatus expected_final_status = expected_final_status_queue.front();
506 509
507 // ui_test_utils::NavigateToURL uses its own observer and message loop. 510 // ui_test_utils::NavigateToURL uses its own observer and message loop.
508 // Since the test needs to wait until the prerendered page has stopped 511 // Since the test needs to wait until the prerendered page has stopped
509 // loading, rather than the page directly navigated to, need to 512 // loading, rather than the page directly navigated to, need to
510 // handle browser navigation directly. 513 // handle browser navigation directly.
511 browser()->OpenURL(src_url, GURL(), CURRENT_TAB, PageTransition::TYPED); 514 browser()->OpenURL(src_url, GURL(), CURRENT_TAB, PageTransition::TYPED);
512 515
513 TestPrerenderContents* prerender_contents = NULL;
514 ui_test_utils::RunMessageLoop(); 516 ui_test_utils::RunMessageLoop();
515 517
516 prerender_contents = 518 TestPrerenderContents* prerender_contents = GetPrerenderContents();
517 static_cast<TestPrerenderContents*>(
518 prerender_manager()->FindEntry(dest_url_));
519 519
520 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { 520 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) {
521 ASSERT_TRUE(prerender_contents != NULL); 521 ASSERT_TRUE(prerender_contents != NULL);
522 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); 522 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status());
523 523
524 if (call_javascript_) { 524 if (call_javascript_) {
525 // Check if page behaves as expected while in prerendered state. 525 // Check if page behaves as expected while in prerendered state.
526 bool prerender_test_result = false; 526 bool prerender_test_result = false;
527 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 527 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
528 prerender_contents->render_view_host_mutable(), L"", 528 prerender_contents->render_view_host_mutable(), L"",
529 L"window.domAutomationController.send(DidPrerenderPass())", 529 L"window.domAutomationController.send(DidPrerenderPass())",
530 &prerender_test_result)); 530 &prerender_test_result));
531 EXPECT_TRUE(prerender_test_result); 531 EXPECT_TRUE(prerender_test_result);
532 } 532 }
533 } else { 533 } else {
534 // In the failure case, we should have removed dest_url_ from the 534 // In the failure case, we should have removed dest_url_ from the
535 // prerender_manager. 535 // prerender_manager.
536 EXPECT_TRUE(prerender_contents == NULL); 536 EXPECT_TRUE(prerender_contents == NULL);
537 } 537 }
538 } 538 }
539 539
540 void NavigateToURLImpl(const GURL& dest_url) const { 540 void NavigateToURLImpl(const GURL& dest_url) const {
541 // Make sure in navigating we have a URL to use in the PrerenderManager. 541 // Make sure in navigating we have a URL to use in the PrerenderManager.
542 EXPECT_TRUE(prerender_manager()->FindEntry(dest_url_) != NULL); 542 EXPECT_TRUE(GetPrerenderContents() != NULL);
543 543
544 // ui_test_utils::NavigateToURL waits until DidStopLoading is called on 544 // ui_test_utils::NavigateToURL waits until DidStopLoading is called on
545 // the current tab. As that tab is going to end up deleted, and may never 545 // the current tab. As that tab is going to end up deleted, and may never
546 // finish loading before that happens, exit the message loop on the deletion 546 // finish loading before that happens, exit the message loop on the deletion
547 // of the used prerender contents instead. 547 // of the used prerender contents instead.
548 // 548 //
549 // As PrerenderTestURL waits until the prerendered page has completely 549 // As PrerenderTestURL waits until the prerendered page has completely
550 // loaded, there is no race between loading |dest_url| and swapping the 550 // loaded, there is no race between loading |dest_url| and swapping the
551 // prerendered TabContents into the tab. 551 // prerendered TabContents into the tab.
552 browser()->OpenURL(dest_url, GURL(), CURRENT_TAB, PageTransition::TYPED); 552 browser()->OpenURL(dest_url, GURL(), CURRENT_TAB, PageTransition::TYPED);
553 ui_test_utils::RunMessageLoop(); 553 ui_test_utils::RunMessageLoop();
554 554
555 // Make sure the PrerenderContents found earlier was used or removed. 555 // Make sure the PrerenderContents found earlier was used or removed.
556 EXPECT_TRUE(prerender_manager()->FindEntry(dest_url_) == NULL); 556 EXPECT_TRUE(GetPrerenderContents() == NULL);
557 557
558 if (call_javascript_) { 558 if (call_javascript_) {
559 // Check if page behaved as expected when actually displayed. 559 // Check if page behaved as expected when actually displayed.
560 bool display_test_result = false; 560 bool display_test_result = false;
561 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 561 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
562 browser()->GetSelectedTabContents()->render_view_host(), L"", 562 browser()->GetSelectedTabContents()->render_view_host(), L"",
563 L"window.domAutomationController.send(DidDisplayPass())", 563 L"window.domAutomationController.send(DidDisplayPass())",
564 &display_test_result)); 564 &display_test_result));
565 EXPECT_TRUE(display_test_result); 565 EXPECT_TRUE(display_test_result);
566 } 566 }
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
1333 } 1333 }
1334 1334
1335 // Checks that a local storage write will not cause prerender to fail. 1335 // Checks that a local storage write will not cause prerender to fail.
1336 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderLocalStorageWrite) { 1336 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderLocalStorageWrite) {
1337 PrerenderTestURL("files/prerender/prerender_localstorage_write.html", 1337 PrerenderTestURL("files/prerender/prerender_localstorage_write.html",
1338 FINAL_STATUS_USED, 1338 FINAL_STATUS_USED,
1339 1); 1339 1);
1340 NavigateToDestURL(); 1340 NavigateToDestURL();
1341 } 1341 }
1342 1342
1343 // Checks that the favicon is properly loaded on prerender.
1344 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderFavicon) {
1345 PrerenderTestURL("files/prerender/prerender_favicon.html",
1346 FINAL_STATUS_USED,
1347 1);
1348 TestPrerenderContents* prerender_contents = GetPrerenderContents();
1349 ASSERT_TRUE(prerender_contents != NULL);
1350 prerender_contents->set_quit_message_loop_on_destruction(false);
1351 // The Favicon should show within two seconds of navigating to the page,
1352 // otherwise something is wrong.
1353 MessageLoopForUI::current()->PostDelayedTask(
cbentzel 2011/06/09 15:41:04 I agree with Pawel that this is pretty hairy. Co
Paweł Hajdan Jr. 2011/06/09 19:29:20 Yes, that's what I'd like to see. Please do that.
1354 FROM_HERE,
1355 new MessageLoop::QuitTask(),
1356 TestTimeouts::action_timeout_ms());
1357 NavigateToDestURL();
1358 ASSERT_TRUE(TabContentsWrapper::GetCurrentWrapperForContents(
1359 browser()->GetSelectedTabContents())->favicon_tab_helper()
1360 ->FaviconIsValid());
1361 }
1362
1343 } // namespace prerender 1363 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698