OLD | NEW |
---|---|
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 | 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/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 | 436 |
437 class PrerenderBrowserTest : public InProcessBrowserTest { | 437 class PrerenderBrowserTest : public InProcessBrowserTest { |
438 public: | 438 public: |
439 PrerenderBrowserTest() | 439 PrerenderBrowserTest() |
440 : prerender_contents_factory_(NULL), | 440 : prerender_contents_factory_(NULL), |
441 #if defined(ENABLE_SAFE_BROWSING) | 441 #if defined(ENABLE_SAFE_BROWSING) |
442 safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), | 442 safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), |
443 #endif | 443 #endif |
444 use_https_src_server_(false), | 444 use_https_src_server_(false), |
445 call_javascript_(true), | 445 call_javascript_(true), |
446 loader_path_("files/prerender/prerender_loader.html") { | 446 loader_path_("files/prerender/prerender_loader.html"), |
447 explicitly_set_browser_(NULL) { | |
447 EnableDOMAutomation(); | 448 EnableDOMAutomation(); |
448 } | 449 } |
449 | 450 |
450 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 451 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
451 #if defined(ENABLE_SAFE_BROWSING) | 452 #if defined(ENABLE_SAFE_BROWSING) |
452 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); | 453 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); |
453 #endif | 454 #endif |
454 } | 455 } |
455 | 456 |
456 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 457 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
457 command_line->AppendSwitchASCII(switches::kPrerenderMode, | 458 command_line->AppendSwitchASCII(switches::kPrerenderMode, |
458 switches::kPrerenderModeSwitchValueEnabled); | 459 switches::kPrerenderModeSwitchValueEnabled); |
459 #if defined(OS_MACOSX) | 460 #if defined(OS_MACOSX) |
460 // The plugins directory isn't read by default on the Mac, so it needs to be | 461 // The plugins directory isn't read by default on the Mac, so it needs to be |
461 // explicitly registered. | 462 // explicitly registered. |
462 FilePath app_dir; | 463 FilePath app_dir; |
463 PathService::Get(chrome::DIR_APP, &app_dir); | 464 PathService::Get(chrome::DIR_APP, &app_dir); |
464 command_line->AppendSwitchPath( | 465 command_line->AppendSwitchPath( |
465 switches::kExtraPluginDir, | 466 switches::kExtraPluginDir, |
466 app_dir.Append(FILE_PATH_LITERAL("plugins"))); | 467 app_dir.Append(FILE_PATH_LITERAL("plugins"))); |
467 #endif | 468 #endif |
468 } | 469 } |
469 | 470 |
470 virtual void SetUpOnMainThread() OVERRIDE { | 471 virtual void SetUpOnMainThread() OVERRIDE { |
471 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 472 current_browser()->profile()->GetPrefs()->SetBoolean( |
472 false); | 473 prefs::kPromptForDownload, false); |
473 // Increase the memory allowed in a prerendered page above normal settings. | 474 // Increase the memory allowed in a prerendered page above normal settings. |
474 // Debug build bots occasionally run against the default limit, and tests | 475 // Debug build bots occasionally run against the default limit, and tests |
475 // were failing because the prerender was canceled due to memory exhaustion. | 476 // were failing because the prerender was canceled due to memory exhaustion. |
476 // http://crbug.com/93076 | 477 // http://crbug.com/93076 |
477 prerender_manager()->mutable_config().max_bytes = 1000 * 1024 * 1024; | 478 prerender_manager()->mutable_config().max_bytes = 1000 * 1024 * 1024; |
478 ASSERT_TRUE(test_server()->Start()); | 479 ASSERT_TRUE(test_server()->Start()); |
479 } | 480 } |
480 | 481 |
481 // Overload for a single expected final status | 482 // Overload for a single expected final status |
482 void PrerenderTestURL(const std::string& html_file, | 483 void PrerenderTestURL(const std::string& html_file, |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 | 657 |
657 void DisableJavascriptCalls() { | 658 void DisableJavascriptCalls() { |
658 call_javascript_ = false; | 659 call_javascript_ = false; |
659 } | 660 } |
660 | 661 |
661 TaskManagerModel* model() const { | 662 TaskManagerModel* model() const { |
662 return TaskManager::GetInstance()->model(); | 663 return TaskManager::GetInstance()->model(); |
663 } | 664 } |
664 | 665 |
665 PrerenderManager* prerender_manager() const { | 666 PrerenderManager* prerender_manager() const { |
666 Profile* profile = browser()->GetSelectedTabContentsWrapper()->profile(); | 667 Profile* profile = |
668 current_browser()->GetSelectedTabContentsWrapper()->profile(); | |
667 PrerenderManager* prerender_manager = | 669 PrerenderManager* prerender_manager = |
668 PrerenderManagerFactory::GetForProfile(profile); | 670 PrerenderManagerFactory::GetForProfile(profile); |
669 return prerender_manager; | 671 return prerender_manager; |
670 } | 672 } |
671 | 673 |
672 // Returns length of |prerender_manager_|'s history, or -1 on failure. | 674 // Returns length of |prerender_manager_|'s history, or -1 on failure. |
673 int GetHistoryLength() const { | 675 int GetHistoryLength() const { |
674 scoped_ptr<DictionaryValue> prerender_dict( | 676 scoped_ptr<DictionaryValue> prerender_dict( |
675 static_cast<DictionaryValue*>(prerender_manager()->GetAsValue())); | 677 static_cast<DictionaryValue*>(prerender_manager()->GetAsValue())); |
676 if (!prerender_dict.get()) | 678 if (!prerender_dict.get()) |
(...skipping 23 matching lines...) Expand all Loading... | |
700 static const std::string secondary_domain = "www.foo.com"; | 702 static const std::string secondary_domain = "www.foo.com"; |
701 host_resolver()->AddRule(secondary_domain, "127.0.0.1"); | 703 host_resolver()->AddRule(secondary_domain, "127.0.0.1"); |
702 std::string url_str(base::StringPrintf( | 704 std::string url_str(base::StringPrintf( |
703 "http://%s:%d/%s", | 705 "http://%s:%d/%s", |
704 secondary_domain.c_str(), | 706 secondary_domain.c_str(), |
705 test_server()->host_port_pair().port(), | 707 test_server()->host_port_pair().port(), |
706 path.c_str())); | 708 path.c_str())); |
707 return GURL(url_str); | 709 return GURL(url_str); |
708 } | 710 } |
709 | 711 |
712 void set_browser(Browser* browser) { | |
713 explicitly_set_browser_ = browser; | |
714 } | |
715 | |
716 Browser* current_browser() const { | |
717 if (explicitly_set_browser_) | |
dominich
2012/03/09 20:49:38
shorter: return explicitly_set_browser_ ? explicit
cbentzel
2012/03/12 13:46:27
I have a weird dislike of ternary operator because
| |
718 return explicitly_set_browser_; | |
719 else | |
720 return browser(); | |
721 } | |
722 | |
710 private: | 723 private: |
711 void PrerenderTestURLImpl( | 724 void PrerenderTestURLImpl( |
712 const GURL& prerender_url, | 725 const GURL& prerender_url, |
713 const GURL& destination_url, | 726 const GURL& destination_url, |
714 const std::deque<FinalStatus>& expected_final_status_queue, | 727 const std::deque<FinalStatus>& expected_final_status_queue, |
715 int expected_number_of_loads) { | 728 int expected_number_of_loads) { |
716 // TODO(cbentzel): Remove dest_url_? | 729 // TODO(cbentzel): Remove dest_url_? |
717 dest_url_ = destination_url; | 730 dest_url_ = destination_url; |
718 | 731 |
719 std::vector<net::TestServer::StringPair> replacement_text; | 732 std::vector<net::TestServer::StringPair> replacement_text; |
(...skipping 27 matching lines...) Expand all Loading... | |
747 new WaitForLoadPrerenderContentsFactory(expected_number_of_loads, | 760 new WaitForLoadPrerenderContentsFactory(expected_number_of_loads, |
748 expected_final_status_queue); | 761 expected_final_status_queue); |
749 prerender_manager()->SetPrerenderContentsFactory( | 762 prerender_manager()->SetPrerenderContentsFactory( |
750 prerender_contents_factory_); | 763 prerender_contents_factory_); |
751 FinalStatus expected_final_status = expected_final_status_queue.front(); | 764 FinalStatus expected_final_status = expected_final_status_queue.front(); |
752 | 765 |
753 // ui_test_utils::NavigateToURL uses its own observer and message loop. | 766 // ui_test_utils::NavigateToURL uses its own observer and message loop. |
754 // Since the test needs to wait until the prerendered page has stopped | 767 // Since the test needs to wait until the prerendered page has stopped |
755 // loading, rather than the page directly navigated to, need to | 768 // loading, rather than the page directly navigated to, need to |
756 // handle browser navigation directly. | 769 // handle browser navigation directly. |
757 browser()->OpenURL(OpenURLParams( | 770 current_browser()->OpenURL(OpenURLParams( |
758 src_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, | 771 src_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
759 false)); | 772 false)); |
760 | 773 |
761 ui_test_utils::RunMessageLoop(); | 774 ui_test_utils::RunMessageLoop(); |
762 | 775 |
763 TestPrerenderContents* prerender_contents = GetPrerenderContents(); | 776 TestPrerenderContents* prerender_contents = GetPrerenderContents(); |
764 | 777 |
765 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { | 778 if (ShouldRenderPrerenderedPageCorrectly(expected_final_status)) { |
766 ASSERT_TRUE(prerender_contents != NULL); | 779 ASSERT_TRUE(prerender_contents != NULL); |
767 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); | 780 EXPECT_EQ(FINAL_STATUS_MAX, prerender_contents->final_status()); |
(...skipping 11 matching lines...) Expand all Loading... | |
779 // In the failure case, we should have removed |dest_url_| from the | 792 // In the failure case, we should have removed |dest_url_| from the |
780 // prerender_manager. We ignore dummy PrerenderContents (as indicated | 793 // prerender_manager. We ignore dummy PrerenderContents (as indicated |
781 // by not having started). | 794 // by not having started). |
782 EXPECT_TRUE(prerender_contents == NULL || | 795 EXPECT_TRUE(prerender_contents == NULL || |
783 !prerender_contents->prerendering_has_started()); | 796 !prerender_contents->prerendering_has_started()); |
784 } | 797 } |
785 } | 798 } |
786 | 799 |
787 void NavigateToURLImpl(const GURL& dest_url, | 800 void NavigateToURLImpl(const GURL& dest_url, |
788 WindowOpenDisposition disposition) const { | 801 WindowOpenDisposition disposition) const { |
802 ASSERT_TRUE(prerender_manager() != NULL); | |
789 // Make sure in navigating we have a URL to use in the PrerenderManager. | 803 // Make sure in navigating we have a URL to use in the PrerenderManager. |
790 ASSERT_TRUE(GetPrerenderContents() != NULL); | 804 ASSERT_TRUE(GetPrerenderContents() != NULL); |
791 | 805 |
792 // If opening the page in a background tab, it won't be shown when swapped | 806 // If opening the page in a background tab, it won't be shown when swapped |
793 // in. | 807 // in. |
794 if (disposition == NEW_BACKGROUND_TAB) | 808 if (disposition == NEW_BACKGROUND_TAB) |
795 GetPrerenderContents()->set_should_be_shown(false); | 809 GetPrerenderContents()->set_should_be_shown(false); |
796 | 810 |
797 scoped_ptr<ui_test_utils::WindowedNotificationObserver> page_load_observer; | 811 scoped_ptr<ui_test_utils::WindowedNotificationObserver> page_load_observer; |
798 WebContents* web_contents = NULL; | 812 WebContents* web_contents = NULL; |
799 | 813 |
800 if (GetPrerenderContents()->prerender_contents()) { | 814 if (GetPrerenderContents()->prerender_contents()) { |
801 // In the case of zero loads, need to wait for the page load to complete | 815 // In the case of zero loads, need to wait for the page load to complete |
802 // before running any Javascript. | 816 // before running any Javascript. |
803 web_contents = | 817 web_contents = |
804 GetPrerenderContents()->prerender_contents()->web_contents(); | 818 GetPrerenderContents()->prerender_contents()->web_contents(); |
805 if (GetPrerenderContents()->number_of_loads() == 0) { | 819 if (GetPrerenderContents()->number_of_loads() == 0) { |
806 page_load_observer.reset( | 820 page_load_observer.reset( |
807 new ui_test_utils::WindowedNotificationObserver( | 821 new ui_test_utils::WindowedNotificationObserver( |
808 content::NOTIFICATION_LOAD_STOP, | 822 content::NOTIFICATION_LOAD_STOP, |
809 content::Source<NavigationController>( | 823 content::Source<NavigationController>( |
810 &web_contents->GetController()))); | 824 &web_contents->GetController()))); |
811 } | 825 } |
812 } | 826 } |
813 | 827 |
814 // Navigate to the prerendered URL, but don't run the message loop. Browser | 828 // Navigate to the prerendered URL, but don't run the message loop. Browser |
815 // issued navigations to prerendered pages will synchronously swap in the | 829 // issued navigations to prerendered pages will synchronously swap in the |
816 // prerendered page. | 830 // prerendered page. |
817 ui_test_utils::NavigateToURLWithDisposition( | 831 ui_test_utils::NavigateToURLWithDisposition( |
818 browser(), dest_url, disposition, ui_test_utils::BROWSER_TEST_NONE); | 832 current_browser(), dest_url, disposition, |
833 ui_test_utils::BROWSER_TEST_NONE); | |
819 | 834 |
820 // Make sure the PrerenderContents found earlier was used or removed. | 835 // Make sure the PrerenderContents found earlier was used or removed. |
821 EXPECT_TRUE(GetPrerenderContents() == NULL); | 836 EXPECT_TRUE(GetPrerenderContents() == NULL); |
822 | 837 |
823 if (call_javascript_ && web_contents) { | 838 if (call_javascript_ && web_contents) { |
824 if (page_load_observer.get()) | 839 if (page_load_observer.get()) |
825 page_load_observer->Wait(); | 840 page_load_observer->Wait(); |
826 | 841 |
827 bool display_test_result = false; | 842 bool display_test_result = false; |
828 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 843 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
829 web_contents->GetRenderViewHost(), L"", | 844 web_contents->GetRenderViewHost(), L"", |
830 L"window.domAutomationController.send(DidDisplayPass())", | 845 L"window.domAutomationController.send(DidDisplayPass())", |
831 &display_test_result)); | 846 &display_test_result)); |
832 EXPECT_TRUE(display_test_result); | 847 EXPECT_TRUE(display_test_result); |
833 } | 848 } |
834 } | 849 } |
835 | 850 |
836 // Opens the prerendered page using javascript functions in the | 851 // Opens the prerendered page using javascript functions in the |
837 // loader page. |javascript_function_name| should be a 0 argument function | 852 // loader page. |javascript_function_name| should be a 0 argument function |
838 // which is invoked. | 853 // which is invoked. |
839 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) | 854 void OpenDestURLWithJSImpl(const std::string& javascript_function_name) |
840 const { | 855 const { |
841 TestPrerenderContents* prerender_contents = GetPrerenderContents(); | 856 TestPrerenderContents* prerender_contents = GetPrerenderContents(); |
842 ASSERT_TRUE(prerender_contents != NULL); | 857 ASSERT_TRUE(prerender_contents != NULL); |
843 | 858 |
844 RenderViewHost* render_view_host = | 859 RenderViewHost* render_view_host = |
845 browser()->GetSelectedWebContents()->GetRenderViewHost(); | 860 current_browser()->GetSelectedWebContents()->GetRenderViewHost(); |
846 render_view_host->ExecuteJavascriptInWebFrame( | 861 render_view_host->ExecuteJavascriptInWebFrame( |
847 string16(), | 862 string16(), |
848 ASCIIToUTF16(javascript_function_name)); | 863 ASCIIToUTF16(javascript_function_name)); |
849 | 864 |
850 // Run message loop until the prerender contents is destroyed. | 865 // Run message loop until the prerender contents is destroyed. |
851 ui_test_utils::RunMessageLoop(); | 866 ui_test_utils::RunMessageLoop(); |
852 } | 867 } |
853 | 868 |
854 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; | 869 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; |
855 #if defined(ENABLE_SAFE_BROWSING) | 870 #if defined(ENABLE_SAFE_BROWSING) |
856 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; | 871 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; |
857 #endif | 872 #endif |
858 GURL dest_url_; | 873 GURL dest_url_; |
859 bool use_https_src_server_; | 874 bool use_https_src_server_; |
860 bool call_javascript_; | 875 bool call_javascript_; |
861 std::string loader_path_; | 876 std::string loader_path_; |
877 Browser* explicitly_set_browser_; | |
862 }; | 878 }; |
863 | 879 |
864 // Checks that a page is correctly prerendered in the case of a | 880 // Checks that a page is correctly prerendered in the case of a |
865 // <link rel=prerender> tag and then loaded into a tab in response to a | 881 // <link rel=prerender> tag and then loaded into a tab in response to a |
866 // navigation. | 882 // navigation. |
867 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { | 883 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { |
868 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 884 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
869 NavigateToDestURL(); | 885 NavigateToDestURL(); |
870 } | 886 } |
871 | 887 |
888 // Checks that prerendering works in incognito mode. | |
889 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderIncognito) { | |
890 Profile* normal_profile = current_browser()->profile(); | |
891 ui_test_utils::OpenURLOffTheRecord(normal_profile, GURL("about:blank")); | |
892 set_browser(BrowserList::FindBrowserWithProfile( | |
893 normal_profile->GetOffTheRecordProfile())); | |
894 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | |
895 NavigateToDestURL(); | |
896 } | |
897 | |
872 // Checks that the visibility API works. | 898 // Checks that the visibility API works. |
873 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibility) { | 899 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderVisibility) { |
874 PrerenderTestURL("files/prerender/prerender_visibility.html", | 900 PrerenderTestURL("files/prerender/prerender_visibility.html", |
875 FINAL_STATUS_USED, | 901 FINAL_STATUS_USED, |
876 1); | 902 1); |
877 NavigateToDestURL(); | 903 NavigateToDestURL(); |
878 } | 904 } |
879 | 905 |
880 // Checks that the visibility API works when the prerender is quickly opened | 906 // Checks that the visibility API works when the prerender is quickly opened |
881 // in a new tab before it stops loading. | 907 // in a new tab before it stops loading. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 PrerenderTestURL("files/prerender/plugin_delay_load.html", | 942 PrerenderTestURL("files/prerender/plugin_delay_load.html", |
917 FINAL_STATUS_USED, | 943 FINAL_STATUS_USED, |
918 1); | 944 1); |
919 NavigateToDestURL(); | 945 NavigateToDestURL(); |
920 } | 946 } |
921 | 947 |
922 // Checks that plugins are not loaded on prerendering pages when click-to-play | 948 // Checks that plugins are not loaded on prerendering pages when click-to-play |
923 // is enabled. | 949 // is enabled. |
924 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickToPlay) { | 950 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickToPlay) { |
925 // Enable click-to-play. | 951 // Enable click-to-play. |
926 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 952 HostContentSettingsMap* content_settings_map = |
953 current_browser()->profile()->GetHostContentSettingsMap(); | |
954 content_settings_map->SetDefaultContentSetting( | |
927 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK); | 955 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK); |
928 | 956 |
929 PrerenderTestURL("files/prerender/prerender_plugin_click_to_play.html", | 957 PrerenderTestURL("files/prerender/prerender_plugin_click_to_play.html", |
930 FINAL_STATUS_USED, | 958 FINAL_STATUS_USED, |
931 1); | 959 1); |
932 NavigateToDestURL(); | 960 NavigateToDestURL(); |
933 } | 961 } |
934 | 962 |
935 // Checks that plugins in an iframe are not loaded while a page is | 963 // Checks that plugins in an iframe are not loaded while a page is |
936 // being preloaded, but are loaded when the page is displayed. | 964 // being preloaded, but are loaded when the page is displayed. |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1286 bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB); | 1314 bool url_b_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileB); |
1287 bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC); | 1315 bool url_c_is_active_prerender = UrlIsInPrerenderManager(kHtmlFileC); |
1288 EXPECT_TRUE((url_b_is_active_prerender || url_c_is_active_prerender) && | 1316 EXPECT_TRUE((url_b_is_active_prerender || url_c_is_active_prerender) && |
1289 !(url_b_is_active_prerender && url_c_is_active_prerender)); | 1317 !(url_b_is_active_prerender && url_c_is_active_prerender)); |
1290 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileB)); | 1318 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileB)); |
1291 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileC)); | 1319 EXPECT_FALSE(UrlIsPendingInPrerenderManager(kHtmlFileC)); |
1292 } | 1320 } |
1293 | 1321 |
1294 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { | 1322 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderTaskManager) { |
1295 // Show the task manager. This populates the model. | 1323 // Show the task manager. This populates the model. |
1296 browser()->window()->ShowTaskManager(); | 1324 current_browser()->window()->ShowTaskManager(); |
1297 // Wait for the model of task manager to start. | 1325 // Wait for the model of task manager to start. |
1298 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 1326 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
1299 | 1327 |
1300 // Start with two resources. | 1328 // Start with two resources. |
1301 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 1329 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
1302 | 1330 |
1303 // One of the resources that has a TabContents associated with it should have | 1331 // One of the resources that has a TabContents associated with it should have |
1304 // the Prerender prefix. | 1332 // the Prerender prefix. |
1305 const string16 prefix = | 1333 const string16 prefix = |
1306 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, string16()); | 1334 l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_PRERENDER_PREFIX, string16()); |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1819 NavigateToDestURL(); | 1847 NavigateToDestURL(); |
1820 favicon_update_watcher.Wait(); | 1848 favicon_update_watcher.Wait(); |
1821 } | 1849 } |
1822 | 1850 |
1823 // Checks that when a prerendered page is swapped in to a referring page, the | 1851 // Checks that when a prerendered page is swapped in to a referring page, the |
1824 // unload handlers on the referring page are executed. | 1852 // unload handlers on the referring page are executed. |
1825 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { | 1853 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { |
1826 set_loader_path("files/prerender/prerender_loader_with_unload.html"); | 1854 set_loader_path("files/prerender/prerender_loader_with_unload.html"); |
1827 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 1855 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
1828 string16 expected_title = ASCIIToUTF16("Unloaded"); | 1856 string16 expected_title = ASCIIToUTF16("Unloaded"); |
1829 ui_test_utils::TitleWatcher title_watcher(browser()->GetSelectedWebContents(), | 1857 ui_test_utils::TitleWatcher title_watcher( |
1830 expected_title); | 1858 current_browser()->GetSelectedWebContents(), expected_title); |
1831 NavigateToDestURL(); | 1859 NavigateToDestURL(); |
1832 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 1860 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
1833 } | 1861 } |
1834 | 1862 |
1835 // Checks that when the history is cleared, prerendering is cancelled and | 1863 // Checks that when the history is cleared, prerendering is cancelled and |
1836 // prerendering history is cleared. | 1864 // prerendering history is cleared. |
1837 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) { | 1865 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearHistory) { |
1838 PrerenderTestURL("files/prerender/prerender_page.html", | 1866 PrerenderTestURL("files/prerender/prerender_page.html", |
1839 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, | 1867 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, |
1840 1); | 1868 1); |
1841 | 1869 |
1842 // Post a task to clear the history, and run the message loop until it | 1870 // Post a task to clear the history, and run the message loop until it |
1843 // destroys the prerender. | 1871 // destroys the prerender. |
1844 MessageLoop::current()->PostTask( | 1872 MessageLoop::current()->PostTask( |
1845 FROM_HERE, | 1873 FROM_HERE, |
1846 base::Bind(&ClearBrowsingData, browser(), | 1874 base::Bind(&ClearBrowsingData, current_browser(), |
1847 BrowsingDataRemover::REMOVE_HISTORY)); | 1875 BrowsingDataRemover::REMOVE_HISTORY)); |
1848 ui_test_utils::RunMessageLoop(); | 1876 ui_test_utils::RunMessageLoop(); |
1849 | 1877 |
1850 // Make sure prerender history was cleared. | 1878 // Make sure prerender history was cleared. |
1851 EXPECT_EQ(0, GetHistoryLength()); | 1879 EXPECT_EQ(0, GetHistoryLength()); |
1852 } | 1880 } |
1853 | 1881 |
1854 // Checks that when the cache is cleared, prerenders are cancelled but | 1882 // Checks that when the cache is cleared, prerenders are cancelled but |
1855 // prerendering history is not cleared. | 1883 // prerendering history is not cleared. |
1856 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearCache) { | 1884 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClearCache) { |
1857 PrerenderTestURL("files/prerender/prerender_page.html", | 1885 PrerenderTestURL("files/prerender/prerender_page.html", |
1858 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, | 1886 FINAL_STATUS_CACHE_OR_HISTORY_CLEARED, |
1859 1); | 1887 1); |
1860 | 1888 |
1861 // Post a task to clear the cache, and run the message loop until it | 1889 // Post a task to clear the cache, and run the message loop until it |
1862 // destroys the prerender. | 1890 // destroys the prerender. |
1863 MessageLoop::current()->PostTask(FROM_HERE, | 1891 MessageLoop::current()->PostTask(FROM_HERE, |
1864 base::Bind(&ClearBrowsingData, browser(), | 1892 base::Bind(&ClearBrowsingData, current_browser(), |
1865 BrowsingDataRemover::REMOVE_CACHE)); | 1893 BrowsingDataRemover::REMOVE_CACHE)); |
1866 ui_test_utils::RunMessageLoop(); | 1894 ui_test_utils::RunMessageLoop(); |
1867 | 1895 |
1868 // Make sure prerender history was not cleared. Not a vital behavior, but | 1896 // Make sure prerender history was not cleared. Not a vital behavior, but |
1869 // used to compare with PrerenderClearHistory test. | 1897 // used to compare with PrerenderClearHistory test. |
1870 EXPECT_EQ(1, GetHistoryLength()); | 1898 EXPECT_EQ(1, GetHistoryLength()); |
1871 } | 1899 } |
1872 | 1900 |
1873 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) { | 1901 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderCancelAll) { |
1874 PrerenderTestURL("files/prerender/prerender_page.html", | 1902 PrerenderTestURL("files/prerender/prerender_page.html", |
(...skipping 11 matching lines...) Expand all Loading... | |
1886 // The prerendered page is navigated to in several ways [navigate via | 1914 // The prerendered page is navigated to in several ways [navigate via |
1887 // omnibox, click on link, key-modified click to open in background tab, etc], | 1915 // omnibox, click on link, key-modified click to open in background tab, etc], |
1888 // followed by a navigation to another page from the prerendered page, followed | 1916 // followed by a navigation to another page from the prerendered page, followed |
1889 // by a back navigation. | 1917 // by a back navigation. |
1890 | 1918 |
1891 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNavigateClickGoBack) { | 1919 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderNavigateClickGoBack) { |
1892 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 1920 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
1893 FINAL_STATUS_USED, | 1921 FINAL_STATUS_USED, |
1894 1); | 1922 1); |
1895 NavigateToDestURL(); | 1923 NavigateToDestURL(); |
1896 ClickToNextPageAfterPrerender(browser()); | 1924 ClickToNextPageAfterPrerender(current_browser()); |
1897 GoBackToPrerender(browser()); | 1925 GoBackToPrerender(current_browser()); |
1898 } | 1926 } |
1899 | 1927 |
1900 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1928 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1901 PrerenderNavigateNavigateGoBack) { | 1929 PrerenderNavigateNavigateGoBack) { |
1902 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 1930 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
1903 FINAL_STATUS_USED, | 1931 FINAL_STATUS_USED, |
1904 1); | 1932 1); |
1905 NavigateToDestURL(); | 1933 NavigateToDestURL(); |
1906 NavigateToNextPageAfterPrerender(browser()); | 1934 NavigateToNextPageAfterPrerender(current_browser()); |
1907 GoBackToPrerender(browser()); | 1935 GoBackToPrerender(current_browser()); |
1908 } | 1936 } |
1909 | 1937 |
1910 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickClickGoBack) { | 1938 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickClickGoBack) { |
1911 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 1939 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
1912 FINAL_STATUS_USED, | 1940 FINAL_STATUS_USED, |
1913 1); | 1941 1); |
1914 OpenDestURLViaClick(); | 1942 OpenDestURLViaClick(); |
1915 ClickToNextPageAfterPrerender(browser()); | 1943 ClickToNextPageAfterPrerender(current_browser()); |
1916 GoBackToPrerender(browser()); | 1944 GoBackToPrerender(current_browser()); |
1917 } | 1945 } |
1918 | 1946 |
1919 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNavigateGoBack) { | 1947 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNavigateGoBack) { |
1920 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 1948 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
1921 FINAL_STATUS_USED, | 1949 FINAL_STATUS_USED, |
1922 1); | 1950 1); |
1923 OpenDestURLViaClick(); | 1951 OpenDestURLViaClick(); |
1924 NavigateToNextPageAfterPrerender(browser()); | 1952 NavigateToNextPageAfterPrerender(current_browser()); |
1925 GoBackToPrerender(browser()); | 1953 GoBackToPrerender(current_browser()); |
1926 } | 1954 } |
1927 | 1955 |
1928 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewWindow) { | 1956 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewWindow) { |
1929 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 1957 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
1930 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, | 1958 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, |
1931 1); | 1959 1); |
1932 OpenDestURLViaClickNewWindow(); | 1960 OpenDestURLViaClickNewWindow(); |
1933 } | 1961 } |
1934 | 1962 |
1935 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewForegroundTab) { | 1963 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewForegroundTab) { |
1936 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 1964 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
1937 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, | 1965 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, |
1938 1); | 1966 1); |
1939 OpenDestURLViaClickNewForegroundTab(); | 1967 OpenDestURLViaClickNewForegroundTab(); |
1940 } | 1968 } |
1941 | 1969 |
1942 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewBackgroundTab) { | 1970 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderClickNewBackgroundTab) { |
1943 PrerenderTestURL("files/prerender/prerender_page_with_link.html", | 1971 PrerenderTestURL("files/prerender/prerender_page_with_link.html", |
1944 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, | 1972 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH, |
1945 1); | 1973 1); |
1946 OpenDestURLViaClickNewBackgroundTab(); | 1974 OpenDestURLViaClickNewBackgroundTab(); |
1947 } | 1975 } |
1948 | 1976 |
1949 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | 1977 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, |
1950 NavigateToPrerenderedPageWhenDevToolsAttached) { | 1978 NavigateToPrerenderedPageWhenDevToolsAttached) { |
1951 DisableJavascriptCalls(); | 1979 DisableJavascriptCalls(); |
1952 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1980 WebContents* web_contents = current_browser()->GetSelectedWebContents(); |
1953 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( | 1981 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
1954 web_contents->GetRenderViewHost()); | 1982 web_contents->GetRenderViewHost()); |
1955 DevToolsManager* manager = DevToolsManager::GetInstance(); | 1983 DevToolsManager* manager = DevToolsManager::GetInstance(); |
1956 FakeDevToolsClientHost client_host; | 1984 FakeDevToolsClientHost client_host; |
1957 manager->RegisterDevToolsClientHostFor(agent, &client_host); | 1985 manager->RegisterDevToolsClientHostFor(agent, &client_host); |
1958 const char* url = "files/prerender/prerender_page.html"; | 1986 const char* url = "files/prerender/prerender_page.html"; |
1959 PrerenderTestURL(url, FINAL_STATUS_DEVTOOLS_ATTACHED, 1); | 1987 PrerenderTestURL(url, FINAL_STATUS_DEVTOOLS_ATTACHED, 1); |
1960 NavigateToURL(url); | 1988 NavigateToURL(url); |
1961 manager->ClientHostClosing(&client_host); | 1989 manager->ClientHostClosing(&client_host); |
1962 } | 1990 } |
1963 | 1991 |
1964 // Validate that the sessionStorage namespace remains the same when swapping | 1992 // Validate that the sessionStorage namespace remains the same when swapping |
1965 // in a prerendered page. | 1993 // in a prerendered page. |
1966 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSessionStorage) { | 1994 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSessionStorage) { |
1967 set_loader_path("files/prerender/prerender_loader_with_session_storage.html"); | 1995 set_loader_path("files/prerender/prerender_loader_with_session_storage.html"); |
1968 PrerenderTestURL(GetCrossDomainTestUrl("files/prerender/prerender_page.html"), | 1996 PrerenderTestURL(GetCrossDomainTestUrl("files/prerender/prerender_page.html"), |
1969 FINAL_STATUS_USED, | 1997 FINAL_STATUS_USED, |
1970 1); | 1998 1); |
1971 NavigateToDestURL(); | 1999 NavigateToDestURL(); |
1972 GoBackToPageBeforePrerender(browser()); | 2000 GoBackToPageBeforePrerender(current_browser()); |
1973 } | 2001 } |
1974 | 2002 |
1975 // Checks that the control group works. A JS alert cannot be detected in the | 2003 // Checks that the control group works. A JS alert cannot be detected in the |
1976 // control group. | 2004 // control group. |
1977 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, ControlGroup) { | 2005 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, ControlGroup) { |
1978 RestorePrerenderMode restore_prerender_mode; | 2006 RestorePrerenderMode restore_prerender_mode; |
1979 PrerenderManager::SetMode( | 2007 PrerenderManager::SetMode( |
1980 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP); | 2008 PrerenderManager::PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP); |
1981 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", | 2009 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", |
1982 FINAL_STATUS_WOULD_HAVE_BEEN_USED, 0); | 2010 FINAL_STATUS_WOULD_HAVE_BEEN_USED, 0); |
1983 NavigateToDestURL(); | 2011 NavigateToDestURL(); |
1984 } | 2012 } |
1985 | 2013 |
1986 // Make sure that the MatchComplete dummy works in the normal case. Once | 2014 // Make sure that the MatchComplete dummy works in the normal case. Once |
1987 // a prerender is cancelled because of a script, a dummy must be created to | 2015 // a prerender is cancelled because of a script, a dummy must be created to |
1988 // account for the MatchComplete case, and it must have a final status of | 2016 // account for the MatchComplete case, and it must have a final status of |
1989 // FINAL_STATUS_WOULD_HAVE_BEEN_USED. | 2017 // FINAL_STATUS_WOULD_HAVE_BEEN_USED. |
1990 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) { | 2018 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) { |
1991 std::deque<FinalStatus> expected_final_status_queue; | 2019 std::deque<FinalStatus> expected_final_status_queue; |
1992 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT); | 2020 expected_final_status_queue.push_back(FINAL_STATUS_JAVASCRIPT_ALERT); |
1993 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); | 2021 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); |
1994 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", | 2022 PrerenderTestURL("files/prerender/prerender_alert_before_onload.html", |
1995 expected_final_status_queue, 1); | 2023 expected_final_status_queue, 1); |
1996 NavigateToDestURL(); | 2024 NavigateToDestURL(); |
1997 } | 2025 } |
1998 | 2026 |
1999 } // namespace prerender | 2027 } // namespace prerender |
OLD | NEW |