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

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

Powered by Google App Engine
This is Rietveld 408576698