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

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

Issue 11607012: Add tabs.onReplaced event to notify listeners of tabs being swapped due to prerendering or instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix some other stuff in tabs.json. Created 7 years, 11 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 | « chrome/browser/extensions/event_names.cc ('k') | chrome/common/extensions/api/tabs.json » ('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) 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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); } 573 ~RestorePrerenderMode() { PrerenderManager::SetMode(prev_mode_); }
574 private: 574 private:
575 PrerenderManager::PrerenderManagerMode prev_mode_; 575 PrerenderManager::PrerenderManagerMode prev_mode_;
576 }; 576 };
577 577
578 } // namespace 578 } // namespace
579 579
580 class PrerenderBrowserTest : virtual public InProcessBrowserTest { 580 class PrerenderBrowserTest : virtual public InProcessBrowserTest {
581 public: 581 public:
582 PrerenderBrowserTest() 582 PrerenderBrowserTest()
583 : prerender_contents_factory_(NULL), 583 : autostart_test_server_(true),
584 prerender_contents_factory_(NULL),
584 #if defined(FULL_SAFE_BROWSING) 585 #if defined(FULL_SAFE_BROWSING)
585 safe_browsing_factory_(new TestSafeBrowsingServiceFactory()), 586 safe_browsing_factory_(new TestSafeBrowsingServiceFactory()),
586 #endif 587 #endif
587 use_https_src_server_(false), 588 use_https_src_server_(false),
588 call_javascript_(true), 589 call_javascript_(true),
589 loader_path_("files/prerender/prerender_loader.html"), 590 loader_path_("files/prerender/prerender_loader.html"),
590 explicitly_set_browser_(NULL) {} 591 explicitly_set_browser_(NULL) {}
591 592
592 virtual ~PrerenderBrowserTest() {} 593 virtual ~PrerenderBrowserTest() {}
593 594
(...skipping 23 matching lines...) Expand all
617 switches::kExtraPluginDir, 618 switches::kExtraPluginDir,
618 app_dir.Append(FILE_PATH_LITERAL("plugins"))); 619 app_dir.Append(FILE_PATH_LITERAL("plugins")));
619 #endif 620 #endif
620 command_line->AppendSwitch(switches::kAlwaysAuthorizePlugins); 621 command_line->AppendSwitch(switches::kAlwaysAuthorizePlugins);
621 } 622 }
622 623
623 virtual void SetUpOnMainThread() OVERRIDE { 624 virtual void SetUpOnMainThread() OVERRIDE {
624 current_browser()->profile()->GetPrefs()->SetBoolean( 625 current_browser()->profile()->GetPrefs()->SetBoolean(
625 prefs::kPromptForDownload, false); 626 prefs::kPromptForDownload, false);
626 IncreasePrerenderMemory(); 627 IncreasePrerenderMemory();
627 ASSERT_TRUE(test_server()->Start()); 628 if (autostart_test_server_)
629 ASSERT_TRUE(test_server()->Start());
628 } 630 }
629 631
630 // Overload for a single expected final status 632 // Overload for a single expected final status
631 void PrerenderTestURL(const std::string& html_file, 633 void PrerenderTestURL(const std::string& html_file,
632 FinalStatus expected_final_status, 634 FinalStatus expected_final_status,
633 int expected_number_of_loads) { 635 int expected_number_of_loads) {
634 PrerenderTestURL(html_file, 636 PrerenderTestURL(html_file,
635 expected_final_status, 637 expected_final_status,
636 expected_number_of_loads, 638 expected_number_of_loads,
637 false); 639 false);
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 } 972 }
971 973
972 void IncreasePrerenderMemory() { 974 void IncreasePrerenderMemory() {
973 // Increase the memory allowed in a prerendered page above normal settings. 975 // Increase the memory allowed in a prerendered page above normal settings.
974 // Debug build bots occasionally run against the default limit, and tests 976 // Debug build bots occasionally run against the default limit, and tests
975 // were failing because the prerender was canceled due to memory exhaustion. 977 // were failing because the prerender was canceled due to memory exhaustion.
976 // http://crbug.com/93076 978 // http://crbug.com/93076
977 GetPrerenderManager()->mutable_config().max_bytes = 1000 * 1024 * 1024; 979 GetPrerenderManager()->mutable_config().max_bytes = 1000 * 1024 * 1024;
978 } 980 }
979 981
982 protected:
983 bool autostart_test_server_;
984
980 private: 985 private:
981 void PrerenderTestURLImpl( 986 void PrerenderTestURLImpl(
982 const GURL& prerender_url, 987 const GURL& prerender_url,
983 const GURL& destination_url, 988 const GURL& destination_url,
984 const std::deque<FinalStatus>& expected_final_status_queue, 989 const std::deque<FinalStatus>& expected_final_status_queue,
985 int expected_number_of_loads, 990 int expected_number_of_loads,
986 bool prerender_should_wait_for_ready_title) { 991 bool prerender_should_wait_for_ready_title) {
987 dest_url_ = destination_url; 992 dest_url_ = destination_url;
988 993
989 std::vector<net::TestServer::StringPair> replacement_text; 994 std::vector<net::TestServer::StringPair> replacement_text;
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 // Checks that the referrer policy is used when prerendering on HTTPS. 2640 // Checks that the referrer policy is used when prerendering on HTTPS.
2636 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSSLReferrerPolicy) { 2641 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderSSLReferrerPolicy) {
2637 set_use_https_src(true); 2642 set_use_https_src(true);
2638 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html"); 2643 set_loader_path("files/prerender/prerender_loader_with_referrer_policy.html");
2639 PrerenderTestURL("files/prerender/prerender_referrer_policy.html", 2644 PrerenderTestURL("files/prerender/prerender_referrer_policy.html",
2640 FINAL_STATUS_USED, 2645 FINAL_STATUS_USED,
2641 1); 2646 1);
2642 NavigateToDestURL(); 2647 NavigateToDestURL();
2643 } 2648 }
2644 2649
2645 // Test interaction of the webNavigation API with prerender. 2650 // Test interaction of the webNavigation and tabs API with prerender.
2646 class PrerenderBrowserTestWithExtensions : public PrerenderBrowserTest, 2651 class PrerenderBrowserTestWithExtensions : public PrerenderBrowserTest,
2647 public ExtensionApiTest { 2652 public ExtensionApiTest {
2648 public: 2653 public:
2649 PrerenderBrowserTestWithExtensions() {} 2654 PrerenderBrowserTestWithExtensions() {
2655 autostart_test_server_ = false;
2656 }
2650 virtual ~PrerenderBrowserTestWithExtensions() {} 2657 virtual ~PrerenderBrowserTestWithExtensions() {}
2651 2658
2652 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 2659 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
2653 PrerenderBrowserTest::SetUpCommandLine(command_line); 2660 PrerenderBrowserTest::SetUpCommandLine(command_line);
2654 ExtensionApiTest::SetUpCommandLine(command_line); 2661 ExtensionApiTest::SetUpCommandLine(command_line);
2655 } 2662 }
2656 2663
2657 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 2664 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
2658 PrerenderBrowserTest::SetUpInProcessBrowserTestFixture(); 2665 PrerenderBrowserTest::SetUpInProcessBrowserTestFixture();
2659 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); 2666 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
2660 } 2667 }
2661 2668
2662 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { 2669 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
2663 PrerenderBrowserTest::TearDownInProcessBrowserTestFixture(); 2670 PrerenderBrowserTest::TearDownInProcessBrowserTestFixture();
2664 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); 2671 ExtensionApiTest::TearDownInProcessBrowserTestFixture();
2665 } 2672 }
2666 2673
2667 virtual void SetUpOnMainThread() OVERRIDE { 2674 virtual void SetUpOnMainThread() OVERRIDE {
2668 PrerenderBrowserTest::SetUpOnMainThread(); 2675 PrerenderBrowserTest::SetUpOnMainThread();
2669 } 2676 }
2670 }; 2677 };
2671 2678
2672 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTestWithExtensions, WebNavigation) { 2679 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTestWithExtensions, WebNavigation) {
2673 // PrerenderBrowserTest automatically started a test server. Restart it, so
2674 // ExtensionApiTest can register its test parameters.
2675 test_server()->Stop();
gavinp 2013/01/07 20:36:26 Nice change. Thank you! I like making tests faster
2676 ASSERT_TRUE(StartTestServer()); 2680 ASSERT_TRUE(StartTestServer());
2677 extensions::FrameNavigationState::set_allow_extension_scheme(true); 2681 extensions::FrameNavigationState::set_allow_extension_scheme(true);
2678 2682
2679 CommandLine::ForCurrentProcess()->AppendSwitch( 2683 CommandLine::ForCurrentProcess()->AppendSwitch(
2680 switches::kAllowLegacyExtensionManifests); 2684 switches::kAllowLegacyExtensionManifests);
2681 2685
2682 // Wait for the extension to set itself up and return control to us. 2686 // Wait for the extension to set itself up and return control to us.
2683 ASSERT_TRUE( 2687 ASSERT_TRUE(
2684 RunExtensionSubtest("webnavigation", "test_prerender.html")) << message_; 2688 RunExtensionSubtest("webnavigation", "test_prerender.html")) << message_;
2685 2689
2686 ResultCatcher catcher; 2690 ResultCatcher catcher;
2687 2691
2688 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 2692 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
2689 2693
2690 ChannelDestructionWatcher channel_close_watcher; 2694 ChannelDestructionWatcher channel_close_watcher;
2691 channel_close_watcher.WatchChannel( 2695 channel_close_watcher.WatchChannel(
2692 chrome::GetActiveWebContents(browser())->GetRenderProcessHost()); 2696 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
2693 NavigateToDestURL(); 2697 NavigateToDestURL();
2694 channel_close_watcher.WaitForChannelClose(); 2698 channel_close_watcher.WaitForChannelClose();
2695 2699
2696 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 2700 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
2697 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 2701 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
2698 } 2702 }
2699 2703
2704 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTestWithExtensions, TabsApi) {
2705 ASSERT_TRUE(StartTestServer());
2706 extensions::FrameNavigationState::set_allow_extension_scheme(true);
2707
2708 // Wait for the extension to set itself up and return control to us.
2709 ASSERT_TRUE(RunExtensionSubtest("tabs/on_replaced", "on_replaced.html"))
2710 << message_;
2711
2712 ResultCatcher catcher;
2713
2714 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
2715
2716 ChannelDestructionWatcher channel_close_watcher;
2717 channel_close_watcher.WatchChannel(
2718 chrome::GetActiveWebContents(browser())->GetRenderProcessHost());
2719 NavigateToDestURL();
2720 channel_close_watcher.WaitForChannelClose();
2721
2722 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
2723 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
2724 }
2725
2700 } // namespace prerender 2726 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/extensions/event_names.cc ('k') | chrome/common/extensions/api/tabs.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698