| OLD | NEW |
| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "chrome/browser/prerender/prerender_contents.h" | 7 #include "chrome/browser/prerender/prerender_contents.h" |
| 8 #include "chrome/browser/prerender/prerender_manager.h" | 8 #include "chrome/browser/prerender/prerender_manager.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 command_line->AppendSwitchPath( | 107 command_line->AppendSwitchPath( |
| 108 switches::kExtraPluginDir, | 108 switches::kExtraPluginDir, |
| 109 app_dir.Append(FILE_PATH_LITERAL("plugins"))); | 109 app_dir.Append(FILE_PATH_LITERAL("plugins"))); |
| 110 #endif | 110 #endif |
| 111 } | 111 } |
| 112 | 112 |
| 113 void PrerenderTestURL(const std::string& html_file, | 113 void PrerenderTestURL(const std::string& html_file, |
| 114 FinalStatus expected_final_status, | 114 FinalStatus expected_final_status, |
| 115 int total_navigations) { | 115 int total_navigations) { |
| 116 ASSERT_TRUE(test_server()->Start()); | 116 ASSERT_TRUE(test_server()->Start()); |
| 117 std::string src_path = "files/prerender/prerender_loader.html?"; |
| 118 src_path.append(html_file); |
| 117 std::string dest_path = "files/prerender/"; | 119 std::string dest_path = "files/prerender/"; |
| 118 dest_path.append(html_file); | 120 dest_path.append(html_file); |
| 121 |
| 122 GURL src_url = test_server()->GetURL(src_path); |
| 119 dest_url_ = test_server()->GetURL(dest_path); | 123 dest_url_ = test_server()->GetURL(dest_path); |
| 120 | 124 |
| 121 std::vector<net::TestServer::StringPair> replacement_text; | |
| 122 replacement_text.push_back( | |
| 123 make_pair("REPLACE_WITH_PREFETCH_URL", dest_url_.spec())); | |
| 124 std::string replacement_path; | |
| 125 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( | |
| 126 "files/prerender/prerender_loader.html", | |
| 127 replacement_text, | |
| 128 &replacement_path)); | |
| 129 GURL src_url = test_server()->GetURL(replacement_path); | |
| 130 | |
| 131 Profile* profile = browser()->GetSelectedTabContents()->profile(); | 125 Profile* profile = browser()->GetSelectedTabContents()->profile(); |
| 132 PrerenderManager* prerender_manager = profile->GetPrerenderManager(); | 126 PrerenderManager* prerender_manager = profile->GetPrerenderManager(); |
| 133 ASSERT_TRUE(prerender_manager); | 127 ASSERT_TRUE(prerender_manager); |
| 134 | 128 |
| 135 // This is needed to exit the event loop once the prerendered page has | 129 // This is needed to exit the event loop once the prerendered page has |
| 136 // stopped loading or was cancelled. | 130 // stopped loading or was cancelled. |
| 137 prerender_manager->SetPrerenderContentsFactory( | 131 prerender_manager->SetPrerenderContentsFactory( |
| 138 new WaitForLoadPrerenderContentsFactory(expected_final_status)); | 132 new WaitForLoadPrerenderContentsFactory(expected_final_status)); |
| 139 | 133 |
| 140 // ui_test_utils::NavigateToURL uses its own observer and message loop. | 134 // ui_test_utils::NavigateToURL uses its own observer and message loop. |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 FINAL_STATUS_USED, 1); | 284 FINAL_STATUS_USED, 1); |
| 291 NavigateToDestURL(); | 285 NavigateToDestURL(); |
| 292 } | 286 } |
| 293 | 287 |
| 294 // Checks that popups on a prerendered page cause cancellation. | 288 // Checks that popups on a prerendered page cause cancellation. |
| 295 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPopup) { | 289 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPopup) { |
| 296 PrerenderTestURL("prerender_popup.html", | 290 PrerenderTestURL("prerender_popup.html", |
| 297 FINAL_STATUS_CREATE_NEW_WINDOW, 1); | 291 FINAL_STATUS_CREATE_NEW_WINDOW, 1); |
| 298 } | 292 } |
| 299 | 293 |
| 300 // Test that page-based redirects to https will cancel prerenders. | |
| 301 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderRedirectToHttps) { | |
| 302 net::TestServer https_server(net::TestServer::TYPE_HTTPS, | |
| 303 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 304 ASSERT_TRUE(https_server.Start()); | |
| 305 GURL https_url = https_server.GetURL("files/prerender/prerender_page.html"); | |
| 306 std::vector<net::TestServer::StringPair> replacement_text; | |
| 307 replacement_text.push_back( | |
| 308 make_pair("REPLACE_WITH_HTTPS_URL", https_url.spec())); | |
| 309 std::string redirect_path; | |
| 310 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( | |
| 311 "prerender_redirect_to_https.html", | |
| 312 replacement_text, | |
| 313 &redirect_path)); | |
| 314 PrerenderTestURL(redirect_path, | |
| 315 FINAL_STATUS_HTTPS, | |
| 316 2); | |
| 317 } | |
| 318 | |
| 319 } // namespace prerender | 294 } // namespace prerender |
| OLD | NEW |