| 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 <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/utf_string_conversions.h" |
| 10 #include "base/test/test_timeouts.h" | 11 #include "base/test/test_timeouts.h" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 12 #include "chrome/browser/favicon/favicon_tab_helper.h" | 13 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/prerender/prerender_contents.h" | 15 #include "chrome/browser/prerender/prerender_contents.h" |
| 15 #include "chrome/browser/prerender/prerender_manager.h" | 16 #include "chrome/browser/prerender/prerender_manager.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 18 #include "chrome/browser/task_manager/task_manager.h" | 19 #include "chrome/browser/task_manager/task_manager.h" |
| 19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 private: | 311 private: |
| 311 FakeSafeBrowsingService* most_recent_service_; | 312 FakeSafeBrowsingService* most_recent_service_; |
| 312 }; | 313 }; |
| 313 | 314 |
| 314 class PrerenderBrowserTest : public InProcessBrowserTest { | 315 class PrerenderBrowserTest : public InProcessBrowserTest { |
| 315 public: | 316 public: |
| 316 PrerenderBrowserTest() | 317 PrerenderBrowserTest() |
| 317 : safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), | 318 : safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), |
| 318 prerender_contents_factory_(NULL), | 319 prerender_contents_factory_(NULL), |
| 319 use_https_src_server_(false), | 320 use_https_src_server_(false), |
| 320 call_javascript_(true) { | 321 call_javascript_(true), |
| 322 loader_path_("files/prerender/prerender_loader.html") { |
| 321 EnableDOMAutomation(); | 323 EnableDOMAutomation(); |
| 322 } | 324 } |
| 323 | 325 |
| 324 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 326 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 325 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); | 327 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); |
| 326 } | 328 } |
| 327 | 329 |
| 328 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 330 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 329 command_line->AppendSwitchASCII(switches::kPrerender, | 331 command_line->AppendSwitchASCII(switches::kPrerender, |
| 330 switches::kPrerenderSwitchValueEnabled); | 332 switches::kPrerenderSwitchValueEnabled); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 | 463 |
| 462 FakeSafeBrowsingService* GetSafeBrowsingService() { | 464 FakeSafeBrowsingService* GetSafeBrowsingService() { |
| 463 return safe_browsing_factory_->most_recent_service(); | 465 return safe_browsing_factory_->most_recent_service(); |
| 464 } | 466 } |
| 465 | 467 |
| 466 TestPrerenderContents* GetPrerenderContents() const { | 468 TestPrerenderContents* GetPrerenderContents() const { |
| 467 return static_cast<TestPrerenderContents*>( | 469 return static_cast<TestPrerenderContents*>( |
| 468 prerender_manager()->FindEntry(dest_url_)); | 470 prerender_manager()->FindEntry(dest_url_)); |
| 469 } | 471 } |
| 470 | 472 |
| 473 void set_loader_path(const std::string& path) { |
| 474 loader_path_ = path; |
| 475 } |
| 476 |
| 471 private: | 477 private: |
| 472 void PrerenderTestURLImpl( | 478 void PrerenderTestURLImpl( |
| 473 const GURL& url, | 479 const GURL& url, |
| 474 const std::deque<FinalStatus>& expected_final_status_queue, | 480 const std::deque<FinalStatus>& expected_final_status_queue, |
| 475 int total_navigations) { | 481 int total_navigations) { |
| 476 dest_url_ = url; | 482 dest_url_ = url; |
| 477 | 483 |
| 478 std::vector<net::TestServer::StringPair> replacement_text; | 484 std::vector<net::TestServer::StringPair> replacement_text; |
| 479 replacement_text.push_back( | 485 replacement_text.push_back( |
| 480 make_pair("REPLACE_WITH_PRERENDER_URL", dest_url_.spec())); | 486 make_pair("REPLACE_WITH_PRERENDER_URL", dest_url_.spec())); |
| 481 std::string replacement_path; | 487 std::string replacement_path; |
| 482 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( | 488 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( |
| 483 "files/prerender/prerender_loader.html", | 489 loader_path_, |
| 484 replacement_text, | 490 replacement_text, |
| 485 &replacement_path)); | 491 &replacement_path)); |
| 486 | 492 |
| 487 net::TestServer* src_server = test_server(); | 493 net::TestServer* src_server = test_server(); |
| 488 scoped_ptr<net::TestServer> https_src_server; | 494 scoped_ptr<net::TestServer> https_src_server; |
| 489 if (use_https_src_server_) { | 495 if (use_https_src_server_) { |
| 490 https_src_server.reset( | 496 https_src_server.reset( |
| 491 new net::TestServer(net::TestServer::TYPE_HTTPS, | 497 new net::TestServer(net::TestServer::TYPE_HTTPS, |
| 492 FilePath(FILE_PATH_LITERAL("chrome/test/data")))); | 498 FilePath(FILE_PATH_LITERAL("chrome/test/data")))); |
| 493 ASSERT_TRUE(https_src_server->Start()); | 499 ASSERT_TRUE(https_src_server->Start()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 &display_test_result)); | 570 &display_test_result)); |
| 565 EXPECT_TRUE(display_test_result); | 571 EXPECT_TRUE(display_test_result); |
| 566 } | 572 } |
| 567 } | 573 } |
| 568 | 574 |
| 569 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; | 575 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; |
| 570 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; | 576 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; |
| 571 GURL dest_url_; | 577 GURL dest_url_; |
| 572 bool use_https_src_server_; | 578 bool use_https_src_server_; |
| 573 bool call_javascript_; | 579 bool call_javascript_; |
| 580 std::string loader_path_; |
| 574 }; | 581 }; |
| 575 | 582 |
| 576 // Checks that a page is correctly prerendered in the case of a | 583 // Checks that a page is correctly prerendered in the case of a |
| 577 // <link rel=prerender> tag and then loaded into a tab in response to a | 584 // <link rel=prerender> tag and then loaded into a tab in response to a |
| 578 // navigation. | 585 // navigation. |
| 579 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { | 586 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { |
| 580 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); | 587 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 581 NavigateToDestURL(); | 588 NavigateToDestURL(); |
| 582 } | 589 } |
| 583 | 590 |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 MessageLoopForUI::current()->PostDelayedTask( | 1360 MessageLoopForUI::current()->PostDelayedTask( |
| 1354 FROM_HERE, | 1361 FROM_HERE, |
| 1355 new MessageLoop::QuitTask(), | 1362 new MessageLoop::QuitTask(), |
| 1356 TestTimeouts::action_timeout_ms()); | 1363 TestTimeouts::action_timeout_ms()); |
| 1357 NavigateToDestURL(); | 1364 NavigateToDestURL(); |
| 1358 ASSERT_TRUE(TabContentsWrapper::GetCurrentWrapperForContents( | 1365 ASSERT_TRUE(TabContentsWrapper::GetCurrentWrapperForContents( |
| 1359 browser()->GetSelectedTabContents())->favicon_tab_helper() | 1366 browser()->GetSelectedTabContents())->favicon_tab_helper() |
| 1360 ->FaviconIsValid()); | 1367 ->FaviconIsValid()); |
| 1361 } | 1368 } |
| 1362 | 1369 |
| 1370 // Checks that when a prerendered page is swapped in to a referring page, the |
| 1371 // unload handlers on the referring page are executed. |
| 1372 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) { |
| 1373 set_loader_path("files/prerender/prerender_loader_with_unload.html"); |
| 1374 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); |
| 1375 ui_test_utils::TitleWatcher title_watcher(browser()->GetSelectedTabContents(), |
| 1376 ASCIIToUTF16("Unloaded")); |
| 1377 NavigateToDestURL(); |
| 1378 EXPECT_TRUE(title_watcher.Wait()); |
| 1379 } |
| 1380 |
| 1363 } // namespace prerender | 1381 } // namespace prerender |
| OLD | NEW |