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

Side by Side Diff: content/browser/web_contents/render_view_host_manager_unittest.cc

Issue 11828040: Revert 175971 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
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 "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "content/browser/browser_thread_impl.h" 6 #include "content/browser/browser_thread_impl.h"
7 #include "content/browser/renderer_host/test_render_view_host.h" 7 #include "content/browser/renderer_host/test_render_view_host.h"
8 #include "content/browser/site_instance_impl.h" 8 #include "content/browser/site_instance_impl.h"
9 #include "content/browser/web_contents/navigation_controller_impl.h" 9 #include "content/browser/web_contents/navigation_controller_impl.h"
10 #include "content/browser/web_contents/navigation_entry_impl.h" 10 #include "content/browser/web_contents/navigation_entry_impl.h"
11 #include "content/browser/web_contents/render_view_host_manager.h" 11 #include "content/browser/web_contents/render_view_host_manager.h"
12 #include "content/browser/web_contents/test_web_contents.h" 12 #include "content/browser/web_contents/test_web_contents.h"
13 #include "content/browser/webui/web_ui_controller_factory_registry.h"
14 #include "content/common/view_messages.h" 13 #include "content/common/view_messages.h"
15 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
18 #include "content/public/browser/web_ui_controller.h" 17 #include "content/public/browser/web_ui_controller.h"
18 #include "content/public/browser/web_ui_controller_factory.h"
19 #include "content/public/common/bindings_policy.h" 19 #include "content/public/common/bindings_policy.h"
20 #include "content/public/common/javascript_message_type.h" 20 #include "content/public/common/javascript_message_type.h"
21 #include "content/public/common/page_transition_types.h" 21 #include "content/public/common/page_transition_types.h"
22 #include "content/public/common/url_constants.h" 22 #include "content/public/common/url_constants.h"
23 #include "content/public/test/mock_render_process_host.h" 23 #include "content/public/test/mock_render_process_host.h"
24 #include "content/public/test/test_browser_context.h" 24 #include "content/public/test/test_browser_context.h"
25 #include "content/public/test/test_notification_tracker.h" 25 #include "content/public/test/test_notification_tracker.h"
26 #include "content/test/test_content_browser_client.h" 26 #include "content/test/test_content_browser_client.h"
27 #include "content/test/test_content_client.h" 27 #include "content/test/test_content_client.h"
28 #include "googleurl/src/url_util.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 #include "webkit/glue/glue_serialize.h" 30 #include "webkit/glue/glue_serialize.h"
30 31
31 namespace content { 32 namespace content {
32 namespace { 33 namespace {
33 34
34 class RenderViewHostManagerTestWebUIControllerFactory 35 class RenderViewHostManagerTestWebUIControllerFactory
35 : public WebUIControllerFactory { 36 : public WebUIControllerFactory {
36 public: 37 public:
37 RenderViewHostManagerTestWebUIControllerFactory() 38 RenderViewHostManagerTestWebUIControllerFactory()
38 : should_create_webui_(false) { 39 : should_create_webui_(false) {
39 } 40 }
40 virtual ~RenderViewHostManagerTestWebUIControllerFactory() {} 41 virtual ~RenderViewHostManagerTestWebUIControllerFactory() {}
41 42
42 void set_should_create_webui(bool should_create_webui) { 43 void set_should_create_webui(bool should_create_webui) {
43 should_create_webui_ = should_create_webui; 44 should_create_webui_ = should_create_webui;
44 } 45 }
45 46
46 // WebUIFactory implementation. 47 // WebUIFactory implementation.
47 virtual WebUIController* CreateWebUIControllerForURL( 48 virtual WebUIController* CreateWebUIControllerForURL(
48 WebUI* web_ui, const GURL& url) const OVERRIDE { 49 WebUI* web_ui, const GURL& url) const OVERRIDE {
49 if (!(should_create_webui_ && HasWebUIScheme(url))) 50 if (!(should_create_webui_ && GetContentClient()->HasWebUIScheme(url)))
50 return NULL; 51 return NULL;
51 return new WebUIController(web_ui); 52 return new WebUIController(web_ui);
52 } 53 }
53 54
54 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, 55 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
55 const GURL& url) const OVERRIDE { 56 const GURL& url) const OVERRIDE {
56 return WebUI::kNoWebUI; 57 return WebUI::kNoWebUI;
57 } 58 }
58 59
59 virtual bool UseWebUIForURL(BrowserContext* browser_context, 60 virtual bool UseWebUIForURL(BrowserContext* browser_context,
60 const GURL& url) const OVERRIDE { 61 const GURL& url) const OVERRIDE {
61 return HasWebUIScheme(url); 62 return GetContentClient()->HasWebUIScheme(url);
62 } 63 }
63 64
64 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, 65 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context,
65 const GURL& url) const OVERRIDE { 66 const GURL& url) const OVERRIDE {
66 return HasWebUIScheme(url); 67 return GetContentClient()->HasWebUIScheme(url);
67 } 68 }
68 69
69 virtual bool IsURLAcceptableForWebUI( 70 virtual bool IsURLAcceptableForWebUI(
70 BrowserContext* browser_context, 71 BrowserContext* browser_context,
71 const GURL& url, 72 const GURL& url,
72 bool data_urls_allowed) const OVERRIDE { 73 bool data_urls_allowed) const OVERRIDE {
73 return HasWebUIScheme(url); 74 return GetContentClient()->HasWebUIScheme(url);
74 } 75 }
75 76
76 private: 77 private:
77 bool should_create_webui_; 78 bool should_create_webui_;
78 79
79 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestWebUIControllerFactory); 80 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestWebUIControllerFactory);
80 }; 81 };
81 82
83 class RenderViewHostManagerTestClient : public TestContentClient {
84 public:
85 RenderViewHostManagerTestClient() {
86 }
87
88 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE {
89 return url.SchemeIs(chrome::kChromeUIScheme);
90 }
91 };
92
93 class RenderViewHostManagerTestBrowserClient
94 : public TestContentBrowserClient {
95 public:
96 RenderViewHostManagerTestBrowserClient() {}
97 virtual ~RenderViewHostManagerTestBrowserClient() {}
98
99 void set_should_create_webui(bool should_create_webui) {
100 factory_.set_should_create_webui(should_create_webui);
101 }
102
103 // TestContentBrowserClient implementation.
104 virtual WebUIControllerFactory*
105 GetWebUIControllerFactory() OVERRIDE {
106 return &factory_;
107 }
108
109 private:
110 RenderViewHostManagerTestWebUIControllerFactory factory_;
111
112 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestBrowserClient);
113 };
114
82 } // namespace 115 } // namespace
83 116
84 class RenderViewHostManagerTest 117 class RenderViewHostManagerTest
85 : public RenderViewHostImplTestHarness { 118 : public RenderViewHostImplTestHarness {
86 public: 119 public:
87 virtual void SetUp() OVERRIDE { 120 virtual void SetUp() OVERRIDE {
88 RenderViewHostImplTestHarness::SetUp(); 121 RenderViewHostImplTestHarness::SetUp();
89 WebUIControllerFactory::RegisterFactory(&factory_); 122 old_client_ = GetContentClient();
123 old_browser_client_ = GetContentClient()->browser();
124 SetContentClient(&client_);
125 GetContentClient()->set_browser_for_testing(&browser_client_);
126 url_util::AddStandardScheme(chrome::kChromeUIScheme);
90 } 127 }
91 128
92 virtual void TearDown() OVERRIDE { 129 virtual void TearDown() OVERRIDE {
93 RenderViewHostImplTestHarness::TearDown(); 130 RenderViewHostImplTestHarness::TearDown();
94 WebUIControllerFactoryRegistry::UnregisterFactoryForTesting(&factory_); 131 GetContentClient()->set_browser_for_testing(old_browser_client_);
132 SetContentClient(old_client_);
95 } 133 }
96 134
97 void set_should_create_webui(bool should_create_webui) { 135 void set_should_create_webui(bool should_create_webui) {
98 factory_.set_should_create_webui(should_create_webui); 136 browser_client_.set_should_create_webui(should_create_webui);
99 } 137 }
100 138
101 void NavigateActiveAndCommit(const GURL& url) { 139 void NavigateActiveAndCommit(const GURL& url) {
102 // Note: we navigate the active RenderViewHost because previous navigations 140 // Note: we navigate the active RenderViewHost because previous navigations
103 // won't have committed yet, so NavigateAndCommit does the wrong thing 141 // won't have committed yet, so NavigateAndCommit does the wrong thing
104 // for us. 142 // for us.
105 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_LINK, std::string()); 143 controller().LoadURL(url, Referrer(), PAGE_TRANSITION_LINK, std::string());
106 TestRenderViewHost* old_rvh = test_rvh(); 144 TestRenderViewHost* old_rvh = test_rvh();
107 145
108 // Simulate the ShouldClose_ACK that is received from the current renderer 146 // Simulate the ShouldClose_ACK that is received from the current renderer
(...skipping 12 matching lines...) Expand all
121 old_rvh->OnSwapOutACK(false); 159 old_rvh->OnSwapOutACK(false);
122 } 160 }
123 161
124 bool ShouldSwapProcesses(RenderViewHostManager* manager, 162 bool ShouldSwapProcesses(RenderViewHostManager* manager,
125 const NavigationEntryImpl* cur_entry, 163 const NavigationEntryImpl* cur_entry,
126 const NavigationEntryImpl* new_entry) const { 164 const NavigationEntryImpl* new_entry) const {
127 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry); 165 return manager->ShouldSwapProcessesForNavigation(cur_entry, new_entry);
128 } 166 }
129 167
130 private: 168 private:
131 RenderViewHostManagerTestWebUIControllerFactory factory_; 169 RenderViewHostManagerTestClient client_;
170 RenderViewHostManagerTestBrowserClient browser_client_;
171 ContentClient* old_client_;
172 ContentBrowserClient* old_browser_client_;
132 }; 173 };
133 174
134 // Tests that when you navigate from a chrome:// url to another page, and 175 // Tests that when you navigate from a chrome:// url to another page, and
135 // then do that same thing in another tab, that the two resulting pages have 176 // then do that same thing in another tab, that the two resulting pages have
136 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is 177 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is
137 // a regression test for bug 9364. 178 // a regression test for bug 9364.
138 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) { 179 TEST_F(RenderViewHostManagerTest, NewTabPageProcesses) {
139 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); 180 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current());
140 const GURL kChromeUrl("chrome://foo"); 181 const GURL kChromeUrl("chrome://foo");
141 const GURL kDestUrl("http://www.google.com/"); 182 const GURL kDestUrl("http://www.google.com/");
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 922
882 // Commit. 923 // Commit.
883 manager.DidNavigateMainFrame(host); 924 manager.DidNavigateMainFrame(host);
884 EXPECT_EQ(host, manager.current_host()); 925 EXPECT_EQ(host, manager.current_host());
885 ASSERT_TRUE(host); 926 ASSERT_TRUE(host);
886 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()), 927 EXPECT_EQ(static_cast<SiteInstanceImpl*>(host->GetSiteInstance()),
887 instance); 928 instance);
888 } 929 }
889 930
890 } // namespace content 931 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/render_view_host_manager.cc ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698