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