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

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

Issue 11819050: Revert 175890: actually, looks like we want this to also help move chromeos webui pages out of src/… (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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/browsing_instance.h" 10 #include "content/browser/browsing_instance.h"
11 #include "content/browser/child_process_security_policy_impl.h" 11 #include "content/browser/child_process_security_policy_impl.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_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.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/web_contents/navigation_entry_impl.h" 16 #include "content/browser/web_contents/navigation_entry_impl.h"
17 #include "content/browser/web_contents/web_contents_impl.h" 17 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/public/browser/web_ui_controller_factory.h" 18 #include "content/browser/webui/web_ui_controller_factory_registry.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/content_switches.h" 21 #include "content/public/common/content_switches.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_browser_thread.h" 25 #include "content/public/test/test_browser_thread.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 "googleurl/src/url_util.h"
(...skipping 11 matching lines...) Expand all
40 virtual WebUIController* CreateWebUIControllerForURL( 40 virtual WebUIController* CreateWebUIControllerForURL(
41 WebUI* web_ui, const GURL& url) const OVERRIDE { 41 WebUI* web_ui, const GURL& url) const OVERRIDE {
42 return NULL; 42 return NULL;
43 } 43 }
44 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, 44 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context,
45 const GURL& url) const OVERRIDE { 45 const GURL& url) const OVERRIDE {
46 return WebUI::kNoWebUI; 46 return WebUI::kNoWebUI;
47 } 47 }
48 virtual bool UseWebUIForURL(BrowserContext* browser_context, 48 virtual bool UseWebUIForURL(BrowserContext* browser_context,
49 const GURL& url) const OVERRIDE { 49 const GURL& url) const OVERRIDE {
50 return GetContentClient()->HasWebUIScheme(url); 50 return HasWebUIScheme(url);
51 } 51 }
52 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, 52 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context,
53 const GURL& url) const OVERRIDE { 53 const GURL& url) const OVERRIDE {
54 return GetContentClient()->HasWebUIScheme(url); 54 return HasWebUIScheme(url);
55 } 55 }
56 virtual bool IsURLAcceptableForWebUI( 56 virtual bool IsURLAcceptableForWebUI(
57 BrowserContext* browser_context, 57 BrowserContext* browser_context,
58 const GURL& url, 58 const GURL& url,
59 bool data_urls_allowed) const OVERRIDE { 59 bool data_urls_allowed) const OVERRIDE {
60 return false; 60 return false;
61 } 61 }
62 }; 62 };
63 63
64 class SiteInstanceTestClient : public TestContentClient {
65 public:
66 SiteInstanceTestClient() {
67 }
68
69 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE {
70 return url.SchemeIs(chrome::kChromeUIScheme);
71 }
72 };
73
74 class SiteInstanceTestBrowserClient : public TestContentBrowserClient { 64 class SiteInstanceTestBrowserClient : public TestContentBrowserClient {
75 public: 65 public:
76 SiteInstanceTestBrowserClient() 66 SiteInstanceTestBrowserClient()
77 : privileged_process_id_(-1) { 67 : privileged_process_id_(-1) {
68 WebUIControllerFactory::RegisterFactory(&factory_);
78 } 69 }
79 70
80 virtual WebUIControllerFactory* GetWebUIControllerFactory() OVERRIDE { 71 ~SiteInstanceTestBrowserClient() {
81 return &factory_; 72 WebUIControllerFactoryRegistry::UnregisterFactoryForTesting(&factory_);
82 } 73 }
83 74
84 virtual bool IsSuitableHost(RenderProcessHost* process_host, 75 virtual bool IsSuitableHost(RenderProcessHost* process_host,
85 const GURL& site_url) OVERRIDE { 76 const GURL& site_url) OVERRIDE {
86 return (privileged_process_id_ == process_host->GetID()) == 77 return (privileged_process_id_ == process_host->GetID()) ==
87 site_url.SchemeIs(kPrivilegedScheme); 78 site_url.SchemeIs(kPrivilegedScheme);
88 } 79 }
89 80
90 void set_privileged_process_id(int process_id) { 81 void set_privileged_process_id(int process_id) {
91 privileged_process_id_ = process_id; 82 privileged_process_id_ = process_id;
92 } 83 }
93 84
94 private: 85 private:
95 SiteInstanceTestWebUIControllerFactory factory_; 86 SiteInstanceTestWebUIControllerFactory factory_;
96 int privileged_process_id_; 87 int privileged_process_id_;
97 }; 88 };
98 89
99 class SiteInstanceTest : public testing::Test { 90 class SiteInstanceTest : public testing::Test {
100 public: 91 public:
101 SiteInstanceTest() 92 SiteInstanceTest()
102 : ui_thread_(BrowserThread::UI, &message_loop_), 93 : ui_thread_(BrowserThread::UI, &message_loop_),
103 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, 94 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING,
104 &message_loop_), 95 &message_loop_),
105 io_thread_(BrowserThread::IO, &message_loop_), 96 io_thread_(BrowserThread::IO, &message_loop_),
106 old_client_(NULL),
107 old_browser_client_(NULL) { 97 old_browser_client_(NULL) {
108 } 98 }
109 99
110 virtual void SetUp() { 100 virtual void SetUp() {
111 old_client_ = GetContentClient();
112 old_browser_client_ = GetContentClient()->browser(); 101 old_browser_client_ = GetContentClient()->browser();
113 SetContentClient(&client_);
114 GetContentClient()->set_browser_for_testing(&browser_client_); 102 GetContentClient()->set_browser_for_testing(&browser_client_);
115 url_util::AddStandardScheme(kPrivilegedScheme); 103 url_util::AddStandardScheme(kPrivilegedScheme);
116 url_util::AddStandardScheme(chrome::kChromeUIScheme); 104 url_util::AddStandardScheme(chrome::kChromeUIScheme);
117 } 105 }
118 106
119 virtual void TearDown() { 107 virtual void TearDown() {
120 // Ensure that no RenderProcessHosts are left over after the tests. 108 // Ensure that no RenderProcessHosts are left over after the tests.
121 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd()); 109 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd());
122 110
123 GetContentClient()->set_browser_for_testing(old_browser_client_); 111 GetContentClient()->set_browser_for_testing(old_browser_client_);
124 SetContentClient(old_client_);
125 112
126 // http://crbug.com/143565 found SiteInstanceTest leaking an 113 // http://crbug.com/143565 found SiteInstanceTest leaking an
127 // AppCacheDatabase. This happens because some part of the test indirectly 114 // AppCacheDatabase. This happens because some part of the test indirectly
128 // calls StoragePartitionImplMap::PostCreateInitialization(), which posts 115 // calls StoragePartitionImplMap::PostCreateInitialization(), which posts
129 // a task to the IO thread to create the AppCacheDatabase. Since the 116 // a task to the IO thread to create the AppCacheDatabase. Since the
130 // message loop is not running, the AppCacheDatabase ends up getting 117 // message loop is not running, the AppCacheDatabase ends up getting
131 // created when DrainMessageLoops() gets called at the end of a test case. 118 // created when DrainMessageLoops() gets called at the end of a test case.
132 // Immediately after, the test case ends and the AppCacheDatabase gets 119 // Immediately after, the test case ends and the AppCacheDatabase gets
133 // scheduled for deletion. Here, call DrainMessageLoops() again so the 120 // scheduled for deletion. Here, call DrainMessageLoops() again so the
134 // AppCacheDatabase actually gets deleted. 121 // AppCacheDatabase actually gets deleted.
(...skipping 11 matching lines...) Expand all
146 MessageLoop::current()->RunUntilIdle(); 133 MessageLoop::current()->RunUntilIdle();
147 message_loop_.RunUntilIdle(); 134 message_loop_.RunUntilIdle();
148 } 135 }
149 136
150 private: 137 private:
151 MessageLoopForUI message_loop_; 138 MessageLoopForUI message_loop_;
152 TestBrowserThread ui_thread_; 139 TestBrowserThread ui_thread_;
153 TestBrowserThread file_user_blocking_thread_; 140 TestBrowserThread file_user_blocking_thread_;
154 TestBrowserThread io_thread_; 141 TestBrowserThread io_thread_;
155 142
156 SiteInstanceTestClient client_;
157 SiteInstanceTestBrowserClient browser_client_; 143 SiteInstanceTestBrowserClient browser_client_;
158 ContentClient* old_client_;
159 ContentBrowserClient* old_browser_client_; 144 ContentBrowserClient* old_browser_client_;
160 }; 145 };
161 146
162 // Subclass of BrowsingInstance that updates a counter when deleted and 147 // Subclass of BrowsingInstance that updates a counter when deleted and
163 // returns TestSiteInstances from GetSiteInstanceForURL. 148 // returns TestSiteInstances from GetSiteInstanceForURL.
164 class TestBrowsingInstance : public BrowsingInstance { 149 class TestBrowsingInstance : public BrowsingInstance {
165 public: 150 public:
166 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter) 151 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter)
167 : BrowsingInstance(browser_context), 152 : BrowsingInstance(browser_context),
168 delete_counter_(delete_counter) { 153 delete_counter_(delete_counter) {
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); 699 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com")));
715 EXPECT_FALSE(instance->HasWrongProcessForURL( 700 EXPECT_FALSE(instance->HasWrongProcessForURL(
716 GURL("javascript:alert(document.location.href);"))); 701 GURL("javascript:alert(document.location.href);")));
717 702
718 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); 703 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings")));
719 704
720 DrainMessageLoops(); 705 DrainMessageLoops();
721 } 706 }
722 707
723 } // namespace content 708 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.cc ('k') | content/browser/web_contents/render_view_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698