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

Side by Side Diff: content/browser/site_instance_impl_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/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/browser/webui/web_ui_controller_factory_registry.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/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 HasWebUIScheme(url); 50 return GetContentClient()->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 HasWebUIScheme(url); 54 return GetContentClient()->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
64 class SiteInstanceTestBrowserClient : public TestContentBrowserClient { 74 class SiteInstanceTestBrowserClient : public TestContentBrowserClient {
65 public: 75 public:
66 SiteInstanceTestBrowserClient() 76 SiteInstanceTestBrowserClient()
67 : privileged_process_id_(-1) { 77 : privileged_process_id_(-1) {
68 WebUIControllerFactory::RegisterFactory(&factory_);
69 } 78 }
70 79
71 ~SiteInstanceTestBrowserClient() { 80 virtual WebUIControllerFactory* GetWebUIControllerFactory() OVERRIDE {
72 WebUIControllerFactoryRegistry::UnregisterFactoryForTesting(&factory_); 81 return &factory_;
73 } 82 }
74 83
75 virtual bool IsSuitableHost(RenderProcessHost* process_host, 84 virtual bool IsSuitableHost(RenderProcessHost* process_host,
76 const GURL& site_url) OVERRIDE { 85 const GURL& site_url) OVERRIDE {
77 return (privileged_process_id_ == process_host->GetID()) == 86 return (privileged_process_id_ == process_host->GetID()) ==
78 site_url.SchemeIs(kPrivilegedScheme); 87 site_url.SchemeIs(kPrivilegedScheme);
79 } 88 }
80 89
81 void set_privileged_process_id(int process_id) { 90 void set_privileged_process_id(int process_id) {
82 privileged_process_id_ = process_id; 91 privileged_process_id_ = process_id;
83 } 92 }
84 93
85 private: 94 private:
86 SiteInstanceTestWebUIControllerFactory factory_; 95 SiteInstanceTestWebUIControllerFactory factory_;
87 int privileged_process_id_; 96 int privileged_process_id_;
88 }; 97 };
89 98
90 class SiteInstanceTest : public testing::Test { 99 class SiteInstanceTest : public testing::Test {
91 public: 100 public:
92 SiteInstanceTest() 101 SiteInstanceTest()
93 : ui_thread_(BrowserThread::UI, &message_loop_), 102 : ui_thread_(BrowserThread::UI, &message_loop_),
94 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, 103 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING,
95 &message_loop_), 104 &message_loop_),
96 io_thread_(BrowserThread::IO, &message_loop_), 105 io_thread_(BrowserThread::IO, &message_loop_),
106 old_client_(NULL),
97 old_browser_client_(NULL) { 107 old_browser_client_(NULL) {
98 } 108 }
99 109
100 virtual void SetUp() { 110 virtual void SetUp() {
111 old_client_ = GetContentClient();
101 old_browser_client_ = GetContentClient()->browser(); 112 old_browser_client_ = GetContentClient()->browser();
113 SetContentClient(&client_);
102 GetContentClient()->set_browser_for_testing(&browser_client_); 114 GetContentClient()->set_browser_for_testing(&browser_client_);
103 url_util::AddStandardScheme(kPrivilegedScheme); 115 url_util::AddStandardScheme(kPrivilegedScheme);
104 url_util::AddStandardScheme(chrome::kChromeUIScheme); 116 url_util::AddStandardScheme(chrome::kChromeUIScheme);
105 } 117 }
106 118
107 virtual void TearDown() { 119 virtual void TearDown() {
108 // Ensure that no RenderProcessHosts are left over after the tests. 120 // Ensure that no RenderProcessHosts are left over after the tests.
109 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd()); 121 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd());
110 122
111 GetContentClient()->set_browser_for_testing(old_browser_client_); 123 GetContentClient()->set_browser_for_testing(old_browser_client_);
124 SetContentClient(old_client_);
112 125
113 // http://crbug.com/143565 found SiteInstanceTest leaking an 126 // http://crbug.com/143565 found SiteInstanceTest leaking an
114 // AppCacheDatabase. This happens because some part of the test indirectly 127 // AppCacheDatabase. This happens because some part of the test indirectly
115 // calls StoragePartitionImplMap::PostCreateInitialization(), which posts 128 // calls StoragePartitionImplMap::PostCreateInitialization(), which posts
116 // a task to the IO thread to create the AppCacheDatabase. Since the 129 // a task to the IO thread to create the AppCacheDatabase. Since the
117 // message loop is not running, the AppCacheDatabase ends up getting 130 // message loop is not running, the AppCacheDatabase ends up getting
118 // created when DrainMessageLoops() gets called at the end of a test case. 131 // created when DrainMessageLoops() gets called at the end of a test case.
119 // Immediately after, the test case ends and the AppCacheDatabase gets 132 // Immediately after, the test case ends and the AppCacheDatabase gets
120 // scheduled for deletion. Here, call DrainMessageLoops() again so the 133 // scheduled for deletion. Here, call DrainMessageLoops() again so the
121 // AppCacheDatabase actually gets deleted. 134 // AppCacheDatabase actually gets deleted.
(...skipping 11 matching lines...) Expand all
133 MessageLoop::current()->RunUntilIdle(); 146 MessageLoop::current()->RunUntilIdle();
134 message_loop_.RunUntilIdle(); 147 message_loop_.RunUntilIdle();
135 } 148 }
136 149
137 private: 150 private:
138 MessageLoopForUI message_loop_; 151 MessageLoopForUI message_loop_;
139 TestBrowserThread ui_thread_; 152 TestBrowserThread ui_thread_;
140 TestBrowserThread file_user_blocking_thread_; 153 TestBrowserThread file_user_blocking_thread_;
141 TestBrowserThread io_thread_; 154 TestBrowserThread io_thread_;
142 155
156 SiteInstanceTestClient client_;
143 SiteInstanceTestBrowserClient browser_client_; 157 SiteInstanceTestBrowserClient browser_client_;
158 ContentClient* old_client_;
144 ContentBrowserClient* old_browser_client_; 159 ContentBrowserClient* old_browser_client_;
145 }; 160 };
146 161
147 // Subclass of BrowsingInstance that updates a counter when deleted and 162 // Subclass of BrowsingInstance that updates a counter when deleted and
148 // returns TestSiteInstances from GetSiteInstanceForURL. 163 // returns TestSiteInstances from GetSiteInstanceForURL.
149 class TestBrowsingInstance : public BrowsingInstance { 164 class TestBrowsingInstance : public BrowsingInstance {
150 public: 165 public:
151 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter) 166 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter)
152 : BrowsingInstance(browser_context), 167 : BrowsingInstance(browser_context),
153 delete_counter_(delete_counter) { 168 delete_counter_(delete_counter) {
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); 714 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com")));
700 EXPECT_FALSE(instance->HasWrongProcessForURL( 715 EXPECT_FALSE(instance->HasWrongProcessForURL(
701 GURL("javascript:alert(document.location.href);"))); 716 GURL("javascript:alert(document.location.href);")));
702 717
703 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); 718 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings")));
704 719
705 DrainMessageLoops(); 720 DrainMessageLoops();
706 } 721 }
707 722
708 } // namespace content 723 } // 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