Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 7046053: Add PrerenderUnload browser test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Pawel's concerns Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/data/prerender/prerender_loader_with_unload.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
20 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "chrome/test/in_process_browser_test.h" 26 #include "chrome/test/in_process_browser_test.h"
26 #include "chrome/test/ui_test_utils.h" 27 #include "chrome/test/ui_test_utils.h"
27 #include "content/browser/renderer_host/render_view_host.h" 28 #include "content/browser/renderer_host/render_view_host.h"
28 #include "content/browser/tab_contents/tab_contents.h" 29 #include "content/browser/tab_contents/tab_contents.h"
30 #include "content/browser/tab_contents/title_updated_details.h"
mmenke 2011/06/10 00:53:09 nit: No longer needed.
cbentzel 2011/06/10 01:00:20 Done.
29 #include "content/common/notification_service.h" 31 #include "content/common/notification_service.h"
30 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
31 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
32 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
33 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
34 36
35 // Prerender tests work as follows: 37 // Prerender tests work as follows:
36 // 38 //
37 // A page with a prefetch link to the test page is loaded. Once prerendered, 39 // A page with a prefetch link to the test page is loaded. Once prerendered,
38 // its Javascript function DidPrerenderPass() is called, which returns true if 40 // its Javascript function DidPrerenderPass() is called, which returns true if
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 private: 312 private:
311 FakeSafeBrowsingService* most_recent_service_; 313 FakeSafeBrowsingService* most_recent_service_;
312 }; 314 };
313 315
314 class PrerenderBrowserTest : public InProcessBrowserTest { 316 class PrerenderBrowserTest : public InProcessBrowserTest {
315 public: 317 public:
316 PrerenderBrowserTest() 318 PrerenderBrowserTest()
317 : safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), 319 : safe_browsing_factory_(new TestSafeBrowsingServiceFactory()),
318 prerender_contents_factory_(NULL), 320 prerender_contents_factory_(NULL),
319 use_https_src_server_(false), 321 use_https_src_server_(false),
320 call_javascript_(true) { 322 call_javascript_(true),
323 loader_path_("files/prerender/prerender_loader.html") {
321 EnableDOMAutomation(); 324 EnableDOMAutomation();
322 } 325 }
323 326
324 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 327 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
325 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); 328 SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get());
326 } 329 }
327 330
328 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 331 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
329 command_line->AppendSwitchASCII(switches::kPrerender, 332 command_line->AppendSwitchASCII(switches::kPrerender,
330 switches::kPrerenderSwitchValueEnabled); 333 switches::kPrerenderSwitchValueEnabled);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 464
462 FakeSafeBrowsingService* GetSafeBrowsingService() { 465 FakeSafeBrowsingService* GetSafeBrowsingService() {
463 return safe_browsing_factory_->most_recent_service(); 466 return safe_browsing_factory_->most_recent_service();
464 } 467 }
465 468
466 TestPrerenderContents* GetPrerenderContents() const { 469 TestPrerenderContents* GetPrerenderContents() const {
467 return static_cast<TestPrerenderContents*>( 470 return static_cast<TestPrerenderContents*>(
468 prerender_manager()->FindEntry(dest_url_)); 471 prerender_manager()->FindEntry(dest_url_));
469 } 472 }
470 473
474 void set_loader_path(const std::string& path) {
475 loader_path_ = path;
476 }
477
471 private: 478 private:
472 void PrerenderTestURLImpl( 479 void PrerenderTestURLImpl(
473 const GURL& url, 480 const GURL& url,
474 const std::deque<FinalStatus>& expected_final_status_queue, 481 const std::deque<FinalStatus>& expected_final_status_queue,
475 int total_navigations) { 482 int total_navigations) {
476 dest_url_ = url; 483 dest_url_ = url;
477 484
478 std::vector<net::TestServer::StringPair> replacement_text; 485 std::vector<net::TestServer::StringPair> replacement_text;
479 replacement_text.push_back( 486 replacement_text.push_back(
480 make_pair("REPLACE_WITH_PRERENDER_URL", dest_url_.spec())); 487 make_pair("REPLACE_WITH_PRERENDER_URL", dest_url_.spec()));
481 std::string replacement_path; 488 std::string replacement_path;
482 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements( 489 ASSERT_TRUE(net::TestServer::GetFilePathWithReplacements(
483 "files/prerender/prerender_loader.html", 490 loader_path_,
484 replacement_text, 491 replacement_text,
485 &replacement_path)); 492 &replacement_path));
486 493
487 net::TestServer* src_server = test_server(); 494 net::TestServer* src_server = test_server();
488 scoped_ptr<net::TestServer> https_src_server; 495 scoped_ptr<net::TestServer> https_src_server;
489 if (use_https_src_server_) { 496 if (use_https_src_server_) {
490 https_src_server.reset( 497 https_src_server.reset(
491 new net::TestServer(net::TestServer::TYPE_HTTPS, 498 new net::TestServer(net::TestServer::TYPE_HTTPS,
492 FilePath(FILE_PATH_LITERAL("chrome/test/data")))); 499 FilePath(FILE_PATH_LITERAL("chrome/test/data"))));
493 ASSERT_TRUE(https_src_server->Start()); 500 ASSERT_TRUE(https_src_server->Start());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 &display_test_result)); 571 &display_test_result));
565 EXPECT_TRUE(display_test_result); 572 EXPECT_TRUE(display_test_result);
566 } 573 }
567 } 574 }
568 575
569 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_; 576 scoped_ptr<TestSafeBrowsingServiceFactory> safe_browsing_factory_;
570 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_; 577 WaitForLoadPrerenderContentsFactory* prerender_contents_factory_;
571 GURL dest_url_; 578 GURL dest_url_;
572 bool use_https_src_server_; 579 bool use_https_src_server_;
573 bool call_javascript_; 580 bool call_javascript_;
581 std::string loader_path_;
574 }; 582 };
575 583
576 // Checks that a page is correctly prerendered in the case of a 584 // 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 585 // <link rel=prerender> tag and then loaded into a tab in response to a
578 // navigation. 586 // navigation.
579 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { 587 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) {
580 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 588 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
581 NavigateToDestURL(); 589 NavigateToDestURL();
582 } 590 }
583 591
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 MessageLoopForUI::current()->PostDelayedTask( 1361 MessageLoopForUI::current()->PostDelayedTask(
1354 FROM_HERE, 1362 FROM_HERE,
1355 new MessageLoop::QuitTask(), 1363 new MessageLoop::QuitTask(),
1356 TestTimeouts::action_timeout_ms()); 1364 TestTimeouts::action_timeout_ms());
1357 NavigateToDestURL(); 1365 NavigateToDestURL();
1358 ASSERT_TRUE(TabContentsWrapper::GetCurrentWrapperForContents( 1366 ASSERT_TRUE(TabContentsWrapper::GetCurrentWrapperForContents(
1359 browser()->GetSelectedTabContents())->favicon_tab_helper() 1367 browser()->GetSelectedTabContents())->favicon_tab_helper()
1360 ->FaviconIsValid()); 1368 ->FaviconIsValid());
1361 } 1369 }
1362 1370
1371 // Checks that when a prerendered page is swapped in to a referring page, the
1372 // unload handlers on the referring page are executed.
1373 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderUnload) {
1374 set_loader_path("files/prerender/prerender_loader_with_unload.html");
1375 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
1376 ui_test_utils::TitleWatcher title_watcher(browser()->GetSelectedTabContents(),
1377 ASCIIToUTF16("Unloaded"));
1378 NavigateToDestURL();
1379 EXPECT_TRUE(title_watcher.Wait());
1380 }
1381
1363 } // namespace prerender 1382 } // namespace prerender
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/prerender/prerender_loader_with_unload.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698