Chromium Code Reviews| 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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 OpenDestURLWithJSImpl("MetaClick()"); | 617 OpenDestURLWithJSImpl("MetaClick()"); |
| 618 #else | 618 #else |
| 619 OpenDestURLWithJSImpl("CtrlClick()"); | 619 OpenDestURLWithJSImpl("CtrlClick()"); |
| 620 #endif | 620 #endif |
| 621 } | 621 } |
| 622 | 622 |
| 623 void OpenDestURLViaWindowOpen() const { | 623 void OpenDestURLViaWindowOpen() const { |
| 624 OpenDestURLWithJSImpl("WindowOpen()"); | 624 OpenDestURLWithJSImpl("WindowOpen()"); |
| 625 } | 625 } |
| 626 | 626 |
| 627 void RemoveLinkElementAndNavigate() const { | |
| 628 OpenDestURLWithJSImpl("RemoveLinkElementAndNavigate()"); | |
| 629 } | |
| 630 | |
| 627 void ClickToNextPageAfterPrerender(Browser* browser) { | 631 void ClickToNextPageAfterPrerender(Browser* browser) { |
| 628 ui_test_utils::WindowedNotificationObserver new_page_observer( | 632 ui_test_utils::WindowedNotificationObserver new_page_observer( |
| 629 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 633 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 630 content::NotificationService::AllSources()); | 634 content::NotificationService::AllSources()); |
| 631 RenderViewHost* render_view_host = | 635 RenderViewHost* render_view_host = |
| 632 browser->GetSelectedWebContents()->GetRenderViewHost(); | 636 browser->GetSelectedWebContents()->GetRenderViewHost(); |
| 633 render_view_host->ExecuteJavascriptInWebFrame( | 637 render_view_host->ExecuteJavascriptInWebFrame( |
| 634 string16(), | 638 string16(), |
| 635 ASCIIToUTF16("ClickOpenLink()")); | 639 ASCIIToUTF16("ClickOpenLink()")); |
| 636 new_page_observer.Wait(); | 640 new_page_observer.Wait(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 | 751 |
| 748 TestPrerenderContents* GetPrerenderContents() const { | 752 TestPrerenderContents* GetPrerenderContents() const { |
| 749 return static_cast<TestPrerenderContents*>( | 753 return static_cast<TestPrerenderContents*>( |
| 750 prerender_manager()->FindEntry(dest_url_)); | 754 prerender_manager()->FindEntry(dest_url_)); |
| 751 } | 755 } |
| 752 | 756 |
| 753 void set_loader_path(const std::string& path) { | 757 void set_loader_path(const std::string& path) { |
| 754 loader_path_ = path; | 758 loader_path_ = path; |
| 755 } | 759 } |
| 756 | 760 |
| 761 void set_loader_query_and_fragment(const std::string& query_and_fragment) { | |
| 762 loader_query_and_fragment_ = query_and_fragment; | |
| 763 } | |
| 764 | |
| 757 GURL GetCrossDomainTestUrl(const std::string& path) { | 765 GURL GetCrossDomainTestUrl(const std::string& path) { |
| 758 static const std::string secondary_domain = "www.foo.com"; | 766 static const std::string secondary_domain = "www.foo.com"; |
| 759 host_resolver()->AddRule(secondary_domain, "127.0.0.1"); | 767 host_resolver()->AddRule(secondary_domain, "127.0.0.1"); |
| 760 std::string url_str(base::StringPrintf( | 768 std::string url_str(base::StringPrintf( |
| 761 "http://%s:%d/%s", | 769 "http://%s:%d/%s", |
| 762 secondary_domain.c_str(), | 770 secondary_domain.c_str(), |
| 763 test_server()->host_port_pair().port(), | 771 test_server()->host_port_pair().port(), |
| 764 path.c_str())); | 772 path.c_str())); |
| 765 return GURL(url_str); | 773 return GURL(url_str); |
| 766 } | 774 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 net::TestServer* src_server = test_server(); | 815 net::TestServer* src_server = test_server(); |
| 808 scoped_ptr<net::TestServer> https_src_server; | 816 scoped_ptr<net::TestServer> https_src_server; |
| 809 if (use_https_src_server_) { | 817 if (use_https_src_server_) { |
| 810 https_src_server.reset( | 818 https_src_server.reset( |
| 811 new net::TestServer(net::TestServer::TYPE_HTTPS, | 819 new net::TestServer(net::TestServer::TYPE_HTTPS, |
| 812 net::TestServer::kLocalhost, | 820 net::TestServer::kLocalhost, |
| 813 FilePath(FILE_PATH_LITERAL("chrome/test/data")))); | 821 FilePath(FILE_PATH_LITERAL("chrome/test/data")))); |
| 814 ASSERT_TRUE(https_src_server->Start()); | 822 ASSERT_TRUE(https_src_server->Start()); |
| 815 src_server = https_src_server.get(); | 823 src_server = https_src_server.get(); |
| 816 } | 824 } |
| 817 GURL src_url = src_server->GetURL(replacement_path); | 825 GURL src_url = src_server->GetURL(replacement_path + |
| 826 loader_query_and_fragment_); | |
|
mmenke
2012/04/24 15:26:15
We have "src_url" but "loader_query_and_fragment_"
gavinp
2012/04/26 23:55:39
I went with the change to loader_url; what src/des
| |
| 818 | 827 |
| 819 ASSERT_TRUE(prerender_manager()); | 828 ASSERT_TRUE(prerender_manager()); |
| 820 prerender_manager()->mutable_config().rate_limit_enabled = false; | 829 prerender_manager()->mutable_config().rate_limit_enabled = false; |
| 821 prerender_manager()->mutable_config().https_allowed = true; | 830 prerender_manager()->mutable_config().https_allowed = true; |
| 822 ASSERT_TRUE(prerender_contents_factory_ == NULL); | 831 ASSERT_TRUE(prerender_contents_factory_ == NULL); |
| 823 prerender_contents_factory_ = | 832 prerender_contents_factory_ = |
| 824 new WaitForLoadPrerenderContentsFactory( | 833 new WaitForLoadPrerenderContentsFactory( |
| 825 expected_number_of_loads, | 834 expected_number_of_loads, |
| 826 expected_final_status_queue, | 835 expected_final_status_queue, |
| 827 prerender_should_wait_for_ready_title); | 836 prerender_should_wait_for_ready_title); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 937 } | 946 } |
| 938 | 947 |
| 939 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; | 948 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; |
| 940 #if defined(ENABLE_SAFE_BROWSING) | 949 #if defined(ENABLE_SAFE_BROWSING) |
| 941 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; | 950 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; |
| 942 #endif | 951 #endif |
| 943 GURL dest_url_; | 952 GURL dest_url_; |
| 944 bool use_https_src_server_; | 953 bool use_https_src_server_; |
| 945 bool call_javascript_; | 954 bool call_javascript_; |
| 946 std::string loader_path_; | 955 std::string loader_path_; |
| 956 std::string loader_query_and_fragment_; | |
| 947 Browser* explicitly_set_browser_; | 957 Browser* explicitly_set_browser_; |
| 948 }; | 958 }; |
| 949 | 959 |
| 950 // Checks that a page is correctly prerendered in the case of a | 960 // Checks that a page is correctly prerendered in the case of a |
| 951 // <link rel=prerender> tag and then loaded into a tab in response to a | 961 // <link rel=prerender> tag and then loaded into a tab in response to a |
| 952 // navigation. | 962 // navigation. |
| 953 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { | 963 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { |
| 954 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 964 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 955 NavigateToDestURL(); | 965 NavigateToDestURL(); |
|
mmenke
2012/04/24 15:26:15
I'd suggest you make sure that the link manager is
gavinp
2012/04/26 23:55:39
Done. These tests can even land without being dis
| |
| 956 } | 966 } |
| 957 | 967 |
| 968 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageRemovingLink) { | |
| 969 set_loader_path("files/prerender/prerender_loader_removing_links.html"); | |
| 970 set_loader_query_and_fragment("?links_to_insert=1&links_to_remove=1"); | |
| 971 PrerenderTestURL("files/prerender/prerender_page.html", | |
| 972 FINAL_STATUS_CANCELLED, 1); | |
| 973 RemoveLinkElementAndNavigate(); | |
| 974 } | |
| 975 | |
| 976 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
| 977 PrerenderPageRemovingLinkWithTwoLinks) { | |
| 978 set_loader_path("files/prerender/prerender_loader_removing_links.html"); | |
| 979 set_loader_query_and_fragment("?links_to_insert=2&links_to_remove=2"); | |
| 980 PrerenderTestURL("files/prerender/prerender_page.html", | |
| 981 FINAL_STATUS_CANCELLED, 1); | |
| 982 RemoveLinkElementAndNavigate(); | |
| 983 } | |
| 984 | |
| 985 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, | |
| 986 PrerenderPageRemovingLinkWithTwoLinksRemovingOne) { | |
| 987 set_loader_path("files/prerender/prerender_loader_removing_links.html"); | |
| 988 set_loader_query_and_fragment("?links_to_insert=2&links_to_remove=1"); | |
| 989 PrerenderTestURL("files/prerender/prerender_page.html", | |
| 990 FINAL_STATUS_USED, 1); | |
| 991 RemoveLinkElementAndNavigate(); | |
| 992 } | |
| 993 | |
| 958 // Checks that prerendering works in incognito mode. | 994 // Checks that prerendering works in incognito mode. |
| 959 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderIncognito) { | 995 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderIncognito) { |
| 960 Profile* normal_profile = current_browser()->profile(); | 996 Profile* normal_profile = current_browser()->profile(); |
| 961 ui_test_utils::OpenURLOffTheRecord(normal_profile, GURL("about:blank")); | 997 ui_test_utils::OpenURLOffTheRecord(normal_profile, GURL("about:blank")); |
| 962 set_browser(BrowserList::FindBrowserWithProfile( | 998 set_browser(BrowserList::FindBrowserWithProfile( |
| 963 normal_profile->GetOffTheRecordProfile())); | 999 normal_profile->GetOffTheRecordProfile())); |
| 964 // Increase memory expectations on the incognito PrerenderManager. | 1000 // Increase memory expectations on the incognito PrerenderManager. |
| 965 IncreasePrerenderMemory(); | 1001 IncreasePrerenderMemory(); |
| 966 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 1002 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 967 NavigateToDestURL(); | 1003 NavigateToDestURL(); |
| (...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2147 WebContents* web_contents = browser()->GetSelectedWebContents(); | 2183 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 2148 bool display_test_result = false; | 2184 bool display_test_result = false; |
| 2149 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 2185 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 2150 web_contents->GetRenderViewHost(), L"", | 2186 web_contents->GetRenderViewHost(), L"", |
| 2151 L"DidDisplayReallyPass()", | 2187 L"DidDisplayReallyPass()", |
| 2152 &display_test_result)); | 2188 &display_test_result)); |
| 2153 ASSERT_TRUE(display_test_result); | 2189 ASSERT_TRUE(display_test_result); |
| 2154 } | 2190 } |
| 2155 | 2191 |
| 2156 } // namespace prerender | 2192 } // namespace prerender |
| OLD | NEW |