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

Side by Side Diff: content/browser/site_instance_impl_unittest.cc

Issue 9288074: Rename WebUIFactory to WebUIControllerFactory since that's what it creates now. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: blah Created 8 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/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "base/string16.h" 7 #include "base/string16.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/browsing_instance.h" 9 #include "content/browser/browsing_instance.h"
10 #include "content/browser/child_process_security_policy.h" 10 #include "content/browser/child_process_security_policy.h"
11 #include "content/browser/mock_content_browser_client.h" 11 #include "content/browser/mock_content_browser_client.h"
12 #include "content/browser/renderer_host/render_process_host_impl.h" 12 #include "content/browser/renderer_host/render_process_host_impl.h"
13 #include "content/browser/renderer_host/render_view_host.h" 13 #include "content/browser/renderer_host/render_view_host.h"
14 #include "content/browser/renderer_host/test_render_view_host.h" 14 #include "content/browser/renderer_host/test_render_view_host.h"
15 #include "content/browser/site_instance_impl.h" 15 #include "content/browser/site_instance_impl.h"
16 #include "content/browser/tab_contents/navigation_entry_impl.h" 16 #include "content/browser/tab_contents/navigation_entry_impl.h"
17 #include "content/browser/tab_contents/tab_contents.h" 17 #include "content/browser/tab_contents/tab_contents.h"
18 #include "content/browser/webui/empty_web_ui_factory.h" 18 #include "content/public/browser/web_ui_controller_factory.h"
19 #include "content/public/common/content_client.h" 19 #include "content/public/common/content_client.h"
20 #include "content/public/common/content_constants.h" 20 #include "content/public/common/content_constants.h"
21 #include "content/public/common/url_constants.h" 21 #include "content/public/common/url_constants.h"
22 #include "content/test/test_browser_context.h" 22 #include "content/test/test_browser_context.h"
23 #include "googleurl/src/url_util.h" 23 #include "googleurl/src/url_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 using content::BrowserContext;
26 using content::BrowserThread; 27 using content::BrowserThread;
27 using content::BrowserThreadImpl; 28 using content::BrowserThreadImpl;
28 using content::NavigationEntry; 29 using content::NavigationEntry;
29 using content::NavigationEntryImpl; 30 using content::NavigationEntryImpl;
30 using content::SiteInstance; 31 using content::SiteInstance;
32 using content::WebUI;
33 using content::WebUIController;
31 34
32 namespace { 35 namespace {
33 36
34 const char kSameAsAnyInstanceURL[] = "about:internets"; 37 const char kSameAsAnyInstanceURL[] = "about:internets";
35 38
36 const char kPrivilegedScheme[] = "privileged"; 39 const char kPrivilegedScheme[] = "privileged";
37 40
38 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { 41 class SiteInstanceTestWebUIControllerFactory
42 : public content::WebUIControllerFactory {
39 public: 43 public:
40 virtual bool UseWebUIForURL(content::BrowserContext* browser_context, 44 virtual WebUIController* CreateWebUIControllerForURL(
45 WebUI* web_ui, const GURL& url) const OVERRIDE {
46 return NULL;
47 }
48 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
49 const GURL& url) const OVERRIDE {
50 return WebUI::kNoWebUI;
51 }
52 virtual bool UseWebUIForURL(BrowserContext* browser_context,
41 const GURL& url) const OVERRIDE { 53 const GURL& url) const OVERRIDE {
42 return HasWebUIScheme(url); 54 return HasWebUIScheme(url);
43 } 55 }
44 virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, 56 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context,
45 const GURL& url) const OVERRIDE { 57 const GURL& url) const OVERRIDE {
46 return HasWebUIScheme(url); 58 return HasWebUIScheme(url);
47 } 59 }
48 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { 60 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE {
49 return url.SchemeIs(chrome::kChromeUIScheme); 61 return url.SchemeIs(chrome::kChromeUIScheme);
50 } 62 }
63 virtual bool IsURLAcceptableForWebUI(BrowserContext* browser_context,
64 const GURL& url) const OVERRIDE {
65 return false;
66 }
51 }; 67 };
52 68
53 class SiteInstanceTestBrowserClient : public content::MockContentBrowserClient { 69 class SiteInstanceTestBrowserClient : public content::MockContentBrowserClient {
54 public: 70 public:
55 SiteInstanceTestBrowserClient() 71 SiteInstanceTestBrowserClient()
56 : privileged_process_id_(-1) { 72 : privileged_process_id_(-1) {
57 } 73 }
58 74
59 virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE { 75 virtual content::WebUIControllerFactory*
76 GetWebUIControllerFactory() OVERRIDE {
60 return &factory_; 77 return &factory_;
61 } 78 }
62 79
63 virtual bool ShouldUseProcessPerSite(content::BrowserContext* browser_context, 80 virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context,
64 const GURL& effective_url) OVERRIDE { 81 const GURL& effective_url) OVERRIDE {
65 return false; 82 return false;
66 } 83 }
67 84
68 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE { 85 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE {
69 return url == GURL(kSameAsAnyInstanceURL) || 86 return url == GURL(kSameAsAnyInstanceURL) ||
70 url == GURL(chrome::kAboutCrashURL); 87 url == GURL(chrome::kAboutCrashURL);
71 } 88 }
72 89
73 virtual bool IsSuitableHost(content::RenderProcessHost* process_host, 90 virtual bool IsSuitableHost(content::RenderProcessHost* process_host,
74 const GURL& site_url) OVERRIDE { 91 const GURL& site_url) OVERRIDE {
75 return (privileged_process_id_ == process_host->GetID()) == 92 return (privileged_process_id_ == process_host->GetID()) ==
76 site_url.SchemeIs(kPrivilegedScheme); 93 site_url.SchemeIs(kPrivilegedScheme);
77 } 94 }
78 95
79 void set_privileged_process_id(int process_id) { 96 void set_privileged_process_id(int process_id) {
80 privileged_process_id_ = process_id; 97 privileged_process_id_ = process_id;
81 } 98 }
82 99
83 private: 100 private:
84 SiteInstanceTestWebUIFactory factory_; 101 SiteInstanceTestWebUIControllerFactory factory_;
85 int privileged_process_id_; 102 int privileged_process_id_;
86 }; 103 };
87 104
88 class SiteInstanceTest : public testing::Test { 105 class SiteInstanceTest : public testing::Test {
89 public: 106 public:
90 SiteInstanceTest() 107 SiteInstanceTest()
91 : ui_thread_(BrowserThread::UI, &message_loop_), 108 : ui_thread_(BrowserThread::UI, &message_loop_),
92 old_browser_client_(NULL) { 109 old_browser_client_(NULL) {
93 } 110 }
94 111
(...skipping 15 matching lines...) Expand all
110 private: 127 private:
111 MessageLoopForUI message_loop_; 128 MessageLoopForUI message_loop_;
112 BrowserThreadImpl ui_thread_; 129 BrowserThreadImpl ui_thread_;
113 130
114 SiteInstanceTestBrowserClient browser_client_; 131 SiteInstanceTestBrowserClient browser_client_;
115 content::ContentBrowserClient* old_browser_client_; 132 content::ContentBrowserClient* old_browser_client_;
116 }; 133 };
117 134
118 class TestBrowsingInstance : public BrowsingInstance { 135 class TestBrowsingInstance : public BrowsingInstance {
119 public: 136 public:
120 TestBrowsingInstance(content::BrowserContext* browser_context, 137 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter)
121 int* delete_counter)
122 : BrowsingInstance(browser_context), 138 : BrowsingInstance(browser_context),
123 use_process_per_site_(false), 139 use_process_per_site_(false),
124 delete_counter_(delete_counter) { 140 delete_counter_(delete_counter) {
125 } 141 }
126 142
127 // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test 143 // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test
128 // both alternatives without using command-line switches. 144 // both alternatives without using command-line switches.
129 bool ShouldUseProcessPerSite(const GURL& url) { 145 bool ShouldUseProcessPerSite(const GURL& url) {
130 return use_process_per_site_; 146 return use_process_per_site_;
131 } 147 }
(...skipping 17 matching lines...) Expand all
149 165
150 // Set by individual tests. 166 // Set by individual tests.
151 bool use_process_per_site_; 167 bool use_process_per_site_;
152 168
153 int* delete_counter_; 169 int* delete_counter_;
154 }; 170 };
155 171
156 class TestSiteInstance : public SiteInstanceImpl { 172 class TestSiteInstance : public SiteInstanceImpl {
157 public: 173 public:
158 static TestSiteInstance* CreateTestSiteInstance( 174 static TestSiteInstance* CreateTestSiteInstance(
159 content::BrowserContext* browser_context, 175 BrowserContext* browser_context,
160 int* site_delete_counter, 176 int* site_delete_counter,
161 int* browsing_delete_counter) { 177 int* browsing_delete_counter) {
162 TestBrowsingInstance* browsing_instance = 178 TestBrowsingInstance* browsing_instance =
163 new TestBrowsingInstance(browser_context, browsing_delete_counter); 179 new TestBrowsingInstance(browser_context, browsing_delete_counter);
164 return new TestSiteInstance(browsing_instance, site_delete_counter); 180 return new TestSiteInstance(browsing_instance, site_delete_counter);
165 } 181 }
166 182
167 private: 183 private:
168 TestSiteInstance(BrowsingInstance* browsing_instance, int* delete_counter) 184 TestSiteInstance(BrowsingInstance* browsing_instance, int* delete_counter)
169 : SiteInstanceImpl(browsing_instance), delete_counter_(delete_counter) {} 185 : SiteInstanceImpl(browsing_instance), delete_counter_(delete_counter) {}
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 host.reset(instance->GetProcess()); 611 host.reset(instance->GetProcess());
596 EXPECT_TRUE(host.get() != NULL); 612 EXPECT_TRUE(host.get() != NULL);
597 EXPECT_TRUE(instance->HasProcess()); 613 EXPECT_TRUE(instance->HasProcess());
598 614
599 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); 615 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com")));
600 EXPECT_FALSE(instance->HasWrongProcessForURL( 616 EXPECT_FALSE(instance->HasWrongProcessForURL(
601 GURL("javascript:alert(document.location.href);"))); 617 GURL("javascript:alert(document.location.href);")));
602 618
603 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); 619 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings")));
604 } 620 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.cc ('k') | content/browser/tab_contents/render_view_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698