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

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

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