| OLD | NEW |
| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 using content::BrowserContext; | 31 namespace content { |
| 32 using content::BrowserThread; | |
| 33 using content::BrowserThreadImpl; | |
| 34 using content::MockRenderProcessHost; | |
| 35 using content::MockRenderProcessHostFactory; | |
| 36 using content::NavigationEntry; | |
| 37 using content::NavigationEntryImpl; | |
| 38 using content::SiteInstance; | |
| 39 using content::WebContentsImpl; | |
| 40 using content::WebUI; | |
| 41 using content::WebUIController; | |
| 42 | 32 |
| 43 namespace { | 33 namespace { |
| 44 | 34 |
| 45 const char kSameAsAnyInstanceURL[] = "about:internets"; | 35 const char kSameAsAnyInstanceURL[] = "about:internets"; |
| 46 | 36 |
| 47 const char kPrivilegedScheme[] = "privileged"; | 37 const char kPrivilegedScheme[] = "privileged"; |
| 48 | 38 |
| 49 class SiteInstanceTestWebUIControllerFactory | 39 class SiteInstanceTestWebUIControllerFactory : public WebUIControllerFactory { |
| 50 : public content::WebUIControllerFactory { | |
| 51 public: | 40 public: |
| 52 virtual WebUIController* CreateWebUIControllerForURL( | 41 virtual WebUIController* CreateWebUIControllerForURL( |
| 53 WebUI* web_ui, const GURL& url) const OVERRIDE { | 42 WebUI* web_ui, const GURL& url) const OVERRIDE { |
| 54 return NULL; | 43 return NULL; |
| 55 } | 44 } |
| 56 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 45 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
| 57 const GURL& url) const OVERRIDE { | 46 const GURL& url) const OVERRIDE { |
| 58 return WebUI::kNoWebUI; | 47 return WebUI::kNoWebUI; |
| 59 } | 48 } |
| 60 virtual bool UseWebUIForURL(BrowserContext* browser_context, | 49 virtual bool UseWebUIForURL(BrowserContext* browser_context, |
| 61 const GURL& url) const OVERRIDE { | 50 const GURL& url) const OVERRIDE { |
| 62 return content::GetContentClient()->HasWebUIScheme(url); | 51 return GetContentClient()->HasWebUIScheme(url); |
| 63 } | 52 } |
| 64 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, | 53 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
| 65 const GURL& url) const OVERRIDE { | 54 const GURL& url) const OVERRIDE { |
| 66 return content::GetContentClient()->HasWebUIScheme(url); | 55 return GetContentClient()->HasWebUIScheme(url); |
| 67 } | 56 } |
| 68 virtual bool IsURLAcceptableForWebUI( | 57 virtual bool IsURLAcceptableForWebUI( |
| 69 BrowserContext* browser_context, | 58 BrowserContext* browser_context, |
| 70 const GURL& url, | 59 const GURL& url, |
| 71 bool data_urls_allowed) const OVERRIDE { | 60 bool data_urls_allowed) const OVERRIDE { |
| 72 return false; | 61 return false; |
| 73 } | 62 } |
| 74 }; | 63 }; |
| 75 | 64 |
| 76 class SiteInstanceTestClient : public TestContentClient { | 65 class SiteInstanceTestClient : public TestContentClient { |
| 77 public: | 66 public: |
| 78 SiteInstanceTestClient() { | 67 SiteInstanceTestClient() { |
| 79 } | 68 } |
| 80 | 69 |
| 81 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { | 70 virtual bool HasWebUIScheme(const GURL& url) const OVERRIDE { |
| 82 return url.SchemeIs(chrome::kChromeUIScheme); | 71 return url.SchemeIs(chrome::kChromeUIScheme); |
| 83 } | 72 } |
| 84 }; | 73 }; |
| 85 | 74 |
| 86 class SiteInstanceTestBrowserClient : public content::TestContentBrowserClient { | 75 class SiteInstanceTestBrowserClient : public TestContentBrowserClient { |
| 87 public: | 76 public: |
| 88 SiteInstanceTestBrowserClient() | 77 SiteInstanceTestBrowserClient() |
| 89 : privileged_process_id_(-1) { | 78 : privileged_process_id_(-1) { |
| 90 } | 79 } |
| 91 | 80 |
| 92 virtual content::WebUIControllerFactory* | 81 virtual WebUIControllerFactory* GetWebUIControllerFactory() OVERRIDE { |
| 93 GetWebUIControllerFactory() OVERRIDE { | |
| 94 return &factory_; | 82 return &factory_; |
| 95 } | 83 } |
| 96 | 84 |
| 97 virtual bool IsSuitableHost(content::RenderProcessHost* process_host, | 85 virtual bool IsSuitableHost(RenderProcessHost* process_host, |
| 98 const GURL& site_url) OVERRIDE { | 86 const GURL& site_url) OVERRIDE { |
| 99 return (privileged_process_id_ == process_host->GetID()) == | 87 return (privileged_process_id_ == process_host->GetID()) == |
| 100 site_url.SchemeIs(kPrivilegedScheme); | 88 site_url.SchemeIs(kPrivilegedScheme); |
| 101 } | 89 } |
| 102 | 90 |
| 103 void set_privileged_process_id(int process_id) { | 91 void set_privileged_process_id(int process_id) { |
| 104 privileged_process_id_ = process_id; | 92 privileged_process_id_ = process_id; |
| 105 } | 93 } |
| 106 | 94 |
| 107 private: | 95 private: |
| 108 SiteInstanceTestWebUIControllerFactory factory_; | 96 SiteInstanceTestWebUIControllerFactory factory_; |
| 109 int privileged_process_id_; | 97 int privileged_process_id_; |
| 110 }; | 98 }; |
| 111 | 99 |
| 112 class SiteInstanceTest : public testing::Test { | 100 class SiteInstanceTest : public testing::Test { |
| 113 public: | 101 public: |
| 114 SiteInstanceTest() | 102 SiteInstanceTest() |
| 115 : ui_thread_(BrowserThread::UI, &message_loop_), | 103 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 116 file_user_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, | 104 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, |
| 117 &message_loop_), | 105 &message_loop_), |
| 118 io_thread_(content::BrowserThread::IO, &message_loop_), | 106 io_thread_(BrowserThread::IO, &message_loop_), |
| 119 old_client_(NULL), | 107 old_client_(NULL), |
| 120 old_browser_client_(NULL) { | 108 old_browser_client_(NULL) { |
| 121 } | 109 } |
| 122 | 110 |
| 123 virtual void SetUp() { | 111 virtual void SetUp() { |
| 124 old_client_ = content::GetContentClient(); | 112 old_client_ = GetContentClient(); |
| 125 old_browser_client_ = content::GetContentClient()->browser(); | 113 old_browser_client_ = GetContentClient()->browser(); |
| 126 content::SetContentClient(&client_); | 114 SetContentClient(&client_); |
| 127 content::GetContentClient()->set_browser_for_testing(&browser_client_); | 115 GetContentClient()->set_browser_for_testing(&browser_client_); |
| 128 url_util::AddStandardScheme(kPrivilegedScheme); | 116 url_util::AddStandardScheme(kPrivilegedScheme); |
| 129 url_util::AddStandardScheme(chrome::kChromeUIScheme); | 117 url_util::AddStandardScheme(chrome::kChromeUIScheme); |
| 130 } | 118 } |
| 131 | 119 |
| 132 virtual void TearDown() { | 120 virtual void TearDown() { |
| 133 // Ensure that no RenderProcessHosts are left over after the tests. | 121 // Ensure that no RenderProcessHosts are left over after the tests. |
| 134 EXPECT_TRUE(content::RenderProcessHost::AllHostsIterator().IsAtEnd()); | 122 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd()); |
| 135 | 123 |
| 136 content::GetContentClient()->set_browser_for_testing(old_browser_client_); | 124 GetContentClient()->set_browser_for_testing(old_browser_client_); |
| 137 content::SetContentClient(old_client_); | 125 SetContentClient(old_client_); |
| 138 | 126 |
| 139 // http://crbug.com/143565 found SiteInstanceTest leaking an | 127 // http://crbug.com/143565 found SiteInstanceTest leaking an |
| 140 // AppCacheDatabase. This happens because some part of the test indirectly | 128 // AppCacheDatabase. This happens because some part of the test indirectly |
| 141 // calls StoragePartitionImplMap::PostCreateInitialization(), which posts | 129 // calls StoragePartitionImplMap::PostCreateInitialization(), which posts |
| 142 // a task to the IO thread to create the AppCacheDatabase. Since the | 130 // a task to the IO thread to create the AppCacheDatabase. Since the |
| 143 // message loop is not running, the AppCacheDatabase ends up getting | 131 // message loop is not running, the AppCacheDatabase ends up getting |
| 144 // created when DrainMessageLoops() gets called at the end of a test case. | 132 // created when DrainMessageLoops() gets called at the end of a test case. |
| 145 // Immediately after, the test case ends and the AppCacheDatabase gets | 133 // Immediately after, the test case ends and the AppCacheDatabase gets |
| 146 // scheduled for deletion. Here, call DrainMessageLoops() again so the | 134 // scheduled for deletion. Here, call DrainMessageLoops() again so the |
| 147 // AppCacheDatabase actually gets deleted. | 135 // AppCacheDatabase actually gets deleted. |
| 148 DrainMessageLoops(); | 136 DrainMessageLoops(); |
| 149 } | 137 } |
| 150 | 138 |
| 151 void set_privileged_process_id(int process_id) { | 139 void set_privileged_process_id(int process_id) { |
| 152 browser_client_.set_privileged_process_id(process_id); | 140 browser_client_.set_privileged_process_id(process_id); |
| 153 } | 141 } |
| 154 | 142 |
| 155 void DrainMessageLoops() { | 143 void DrainMessageLoops() { |
| 156 // We don't just do this in TearDown() because we create TestBrowserContext | 144 // We don't just do this in TearDown() because we create TestBrowserContext |
| 157 // objects in each test, which will be destructed before | 145 // objects in each test, which will be destructed before |
| 158 // TearDown() is called. | 146 // TearDown() is called. |
| 159 MessageLoop::current()->RunAllPending(); | 147 MessageLoop::current()->RunAllPending(); |
| 160 message_loop_.RunAllPending(); | 148 message_loop_.RunAllPending(); |
| 161 } | 149 } |
| 162 | 150 |
| 163 private: | 151 private: |
| 164 MessageLoopForUI message_loop_; | 152 MessageLoopForUI message_loop_; |
| 165 content::TestBrowserThread ui_thread_; | 153 TestBrowserThread ui_thread_; |
| 166 content::TestBrowserThread file_user_blocking_thread_; | 154 TestBrowserThread file_user_blocking_thread_; |
| 167 content::TestBrowserThread io_thread_; | 155 TestBrowserThread io_thread_; |
| 168 | 156 |
| 169 SiteInstanceTestClient client_; | 157 SiteInstanceTestClient client_; |
| 170 SiteInstanceTestBrowserClient browser_client_; | 158 SiteInstanceTestBrowserClient browser_client_; |
| 171 content::ContentClient* old_client_; | 159 ContentClient* old_client_; |
| 172 content::ContentBrowserClient* old_browser_client_; | 160 ContentBrowserClient* old_browser_client_; |
| 173 }; | 161 }; |
| 174 | 162 |
| 175 // Subclass of BrowsingInstance that updates a counter when deleted and | 163 // Subclass of BrowsingInstance that updates a counter when deleted and |
| 176 // returns TestSiteInstances from GetSiteInstanceForURL. | 164 // returns TestSiteInstances from GetSiteInstanceForURL. |
| 177 class TestBrowsingInstance : public BrowsingInstance { | 165 class TestBrowsingInstance : public BrowsingInstance { |
| 178 public: | 166 public: |
| 179 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter) | 167 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter) |
| 180 : BrowsingInstance(browser_context), | 168 : BrowsingInstance(browser_context), |
| 181 delete_counter_(delete_counter) { | 169 delete_counter_(delete_counter) { |
| 182 } | 170 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 205 |
| 218 int* delete_counter_; | 206 int* delete_counter_; |
| 219 }; | 207 }; |
| 220 | 208 |
| 221 } // namespace | 209 } // namespace |
| 222 | 210 |
| 223 // Test to ensure no memory leaks for SiteInstance objects. | 211 // Test to ensure no memory leaks for SiteInstance objects. |
| 224 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { | 212 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { |
| 225 // The existence of this object will cause WebContentsImpl to create our | 213 // The existence of this object will cause WebContentsImpl to create our |
| 226 // test one instead of the real one. | 214 // test one instead of the real one. |
| 227 content::RenderViewHostTestEnabler rvh_test_enabler; | 215 RenderViewHostTestEnabler rvh_test_enabler; |
| 228 int site_delete_counter = 0; | 216 int site_delete_counter = 0; |
| 229 int browsing_delete_counter = 0; | 217 int browsing_delete_counter = 0; |
| 230 const GURL url("test:foo"); | 218 const GURL url("test:foo"); |
| 231 | 219 |
| 232 // Ensure that instances are deleted when their NavigationEntries are gone. | 220 // Ensure that instances are deleted when their NavigationEntries are gone. |
| 233 TestSiteInstance* instance = | 221 TestSiteInstance* instance = |
| 234 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter, | 222 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter, |
| 235 &browsing_delete_counter); | 223 &browsing_delete_counter); |
| 236 EXPECT_EQ(0, site_delete_counter); | 224 EXPECT_EQ(0, site_delete_counter); |
| 237 | 225 |
| 238 NavigationEntryImpl* e1 = new NavigationEntryImpl( | 226 NavigationEntryImpl* e1 = new NavigationEntryImpl( |
| 239 instance, 0, url, content::Referrer(), string16(), | 227 instance, 0, url, Referrer(), string16(), PAGE_TRANSITION_LINK, false); |
| 240 content::PAGE_TRANSITION_LINK, false); | |
| 241 | 228 |
| 242 // Redundantly setting e1's SiteInstance shouldn't affect the ref count. | 229 // Redundantly setting e1's SiteInstance shouldn't affect the ref count. |
| 243 e1->set_site_instance(instance); | 230 e1->set_site_instance(instance); |
| 244 EXPECT_EQ(0, site_delete_counter); | 231 EXPECT_EQ(0, site_delete_counter); |
| 245 | 232 |
| 246 // Add a second reference | 233 // Add a second reference |
| 247 NavigationEntryImpl* e2 = new NavigationEntryImpl( | 234 NavigationEntryImpl* e2 = new NavigationEntryImpl( |
| 248 instance, 0, url, content::Referrer(), string16(), | 235 instance, 0, url, Referrer(), string16(), PAGE_TRANSITION_LINK, false); |
| 249 content::PAGE_TRANSITION_LINK, false); | |
| 250 | 236 |
| 251 // Now delete both entries and be sure the SiteInstance goes away. | 237 // Now delete both entries and be sure the SiteInstance goes away. |
| 252 delete e1; | 238 delete e1; |
| 253 EXPECT_EQ(0, site_delete_counter); | 239 EXPECT_EQ(0, site_delete_counter); |
| 254 EXPECT_EQ(0, browsing_delete_counter); | 240 EXPECT_EQ(0, browsing_delete_counter); |
| 255 delete e2; | 241 delete e2; |
| 256 EXPECT_EQ(1, site_delete_counter); | 242 EXPECT_EQ(1, site_delete_counter); |
| 257 // instance is now deleted | 243 // instance is now deleted |
| 258 EXPECT_EQ(1, browsing_delete_counter); | 244 EXPECT_EQ(1, browsing_delete_counter); |
| 259 // browsing_instance is now deleted | 245 // browsing_instance is now deleted |
| 260 | 246 |
| 261 // Ensure that instances are deleted when their RenderViewHosts are gone. | 247 // Ensure that instances are deleted when their RenderViewHosts are gone. |
| 262 scoped_ptr<content::TestBrowserContext> browser_context( | 248 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 263 new content::TestBrowserContext()); | |
| 264 instance = | 249 instance = |
| 265 TestSiteInstance::CreateTestSiteInstance(browser_context.get(), | 250 TestSiteInstance::CreateTestSiteInstance(browser_context.get(), |
| 266 &site_delete_counter, | 251 &site_delete_counter, |
| 267 &browsing_delete_counter); | 252 &browsing_delete_counter); |
| 268 { | 253 { |
| 269 scoped_ptr<WebContentsImpl> web_contents( | 254 scoped_ptr<WebContentsImpl> web_contents( |
| 270 WebContentsImpl::Create(browser_context.get(), instance, | 255 WebContentsImpl::Create(browser_context.get(), instance, |
| 271 MSG_ROUTING_NONE, NULL)); | 256 MSG_ROUTING_NONE, NULL)); |
| 272 EXPECT_EQ(1, site_delete_counter); | 257 EXPECT_EQ(1, site_delete_counter); |
| 273 EXPECT_EQ(1, browsing_delete_counter); | 258 EXPECT_EQ(1, browsing_delete_counter); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 292 const GURL url("test:foo"); | 277 const GURL url("test:foo"); |
| 293 | 278 |
| 294 SiteInstanceImpl* instance1 = | 279 SiteInstanceImpl* instance1 = |
| 295 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter1, | 280 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter1, |
| 296 &browsing_delete_counter); | 281 &browsing_delete_counter); |
| 297 SiteInstanceImpl* instance2 = | 282 SiteInstanceImpl* instance2 = |
| 298 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter2, | 283 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter2, |
| 299 &browsing_delete_counter); | 284 &browsing_delete_counter); |
| 300 | 285 |
| 301 NavigationEntryImpl* e1 = new NavigationEntryImpl( | 286 NavigationEntryImpl* e1 = new NavigationEntryImpl( |
| 302 instance1, 0, url, content::Referrer(), string16(), | 287 instance1, 0, url, Referrer(), string16(), PAGE_TRANSITION_LINK, false); |
| 303 content::PAGE_TRANSITION_LINK, false); | |
| 304 // Clone the entry | 288 // Clone the entry |
| 305 NavigationEntryImpl* e2 = new NavigationEntryImpl(*e1); | 289 NavigationEntryImpl* e2 = new NavigationEntryImpl(*e1); |
| 306 | 290 |
| 307 // Should be able to change the SiteInstance of the cloned entry. | 291 // Should be able to change the SiteInstance of the cloned entry. |
| 308 e2->set_site_instance(instance2); | 292 e2->set_site_instance(instance2); |
| 309 | 293 |
| 310 // The first SiteInstance should go away after deleting e1, since e2 should | 294 // The first SiteInstance should go away after deleting e1, since e2 should |
| 311 // no longer be referencing it. | 295 // no longer be referencing it. |
| 312 delete e1; | 296 delete e1; |
| 313 EXPECT_EQ(1, site_delete_counter1); | 297 EXPECT_EQ(1, site_delete_counter1); |
| 314 EXPECT_EQ(0, site_delete_counter2); | 298 EXPECT_EQ(0, site_delete_counter2); |
| 315 | 299 |
| 316 // The second SiteInstance should go away after deleting e2. | 300 // The second SiteInstance should go away after deleting e2. |
| 317 delete e2; | 301 delete e2; |
| 318 EXPECT_EQ(1, site_delete_counter1); | 302 EXPECT_EQ(1, site_delete_counter1); |
| 319 EXPECT_EQ(1, site_delete_counter2); | 303 EXPECT_EQ(1, site_delete_counter2); |
| 320 | 304 |
| 321 // Both BrowsingInstances are also now deleted | 305 // Both BrowsingInstances are also now deleted |
| 322 EXPECT_EQ(2, browsing_delete_counter); | 306 EXPECT_EQ(2, browsing_delete_counter); |
| 323 | 307 |
| 324 DrainMessageLoops(); | 308 DrainMessageLoops(); |
| 325 } | 309 } |
| 326 | 310 |
| 327 // Test to ensure GetProcess returns and creates processes correctly. | 311 // Test to ensure GetProcess returns and creates processes correctly. |
| 328 TEST_F(SiteInstanceTest, GetProcess) { | 312 TEST_F(SiteInstanceTest, GetProcess) { |
| 329 // Ensure that GetProcess returns a process. | 313 // Ensure that GetProcess returns a process. |
| 330 scoped_ptr<content::TestBrowserContext> browser_context( | 314 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 331 new content::TestBrowserContext()); | 315 scoped_ptr<RenderProcessHost> host1; |
| 332 scoped_ptr<content::RenderProcessHost> host1; | |
| 333 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( | 316 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
| 334 SiteInstance::Create(browser_context.get()))); | 317 SiteInstance::Create(browser_context.get()))); |
| 335 host1.reset(instance->GetProcess()); | 318 host1.reset(instance->GetProcess()); |
| 336 EXPECT_TRUE(host1.get() != NULL); | 319 EXPECT_TRUE(host1.get() != NULL); |
| 337 | 320 |
| 338 // Ensure that GetProcess creates a new process. | 321 // Ensure that GetProcess creates a new process. |
| 339 scoped_refptr<SiteInstanceImpl> instance2(static_cast<SiteInstanceImpl*>( | 322 scoped_refptr<SiteInstanceImpl> instance2(static_cast<SiteInstanceImpl*>( |
| 340 SiteInstance::Create(browser_context.get()))); | 323 SiteInstance::Create(browser_context.get()))); |
| 341 scoped_ptr<content::RenderProcessHost> host2(instance2->GetProcess()); | 324 scoped_ptr<RenderProcessHost> host2(instance2->GetProcess()); |
| 342 EXPECT_TRUE(host2.get() != NULL); | 325 EXPECT_TRUE(host2.get() != NULL); |
| 343 EXPECT_NE(host1.get(), host2.get()); | 326 EXPECT_NE(host1.get(), host2.get()); |
| 344 | 327 |
| 345 DrainMessageLoops(); | 328 DrainMessageLoops(); |
| 346 } | 329 } |
| 347 | 330 |
| 348 // Test to ensure SetSite and site() work properly. | 331 // Test to ensure SetSite and site() work properly. |
| 349 TEST_F(SiteInstanceTest, SetSite) { | 332 TEST_F(SiteInstanceTest, SetSite) { |
| 350 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( | 333 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
| 351 SiteInstance::Create(NULL))); | 334 SiteInstance::Create(NULL))); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 | 405 |
| 423 DrainMessageLoops(); | 406 DrainMessageLoops(); |
| 424 } | 407 } |
| 425 | 408 |
| 426 // Test to ensure that there is only one SiteInstance per site in a given | 409 // Test to ensure that there is only one SiteInstance per site in a given |
| 427 // BrowsingInstance, when process-per-site is not in use. | 410 // BrowsingInstance, when process-per-site is not in use. |
| 428 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 411 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
| 429 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | 412 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( |
| 430 switches::kProcessPerSite)); | 413 switches::kProcessPerSite)); |
| 431 int delete_counter = 0; | 414 int delete_counter = 0; |
| 432 scoped_ptr<content::TestBrowserContext> browser_context( | 415 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 433 new content::TestBrowserContext()); | |
| 434 TestBrowsingInstance* browsing_instance = | 416 TestBrowsingInstance* browsing_instance = |
| 435 new TestBrowsingInstance(browser_context.get(), &delete_counter); | 417 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
| 436 | 418 |
| 437 const GURL url_a1("http://www.google.com/1.html"); | 419 const GURL url_a1("http://www.google.com/1.html"); |
| 438 scoped_refptr<SiteInstanceImpl> site_instance_a1( | 420 scoped_refptr<SiteInstanceImpl> site_instance_a1( |
| 439 static_cast<SiteInstanceImpl*>( | 421 static_cast<SiteInstanceImpl*>( |
| 440 browsing_instance->GetSiteInstanceForURL(url_a1))); | 422 browsing_instance->GetSiteInstanceForURL(url_a1))); |
| 441 EXPECT_TRUE(site_instance_a1.get() != NULL); | 423 EXPECT_TRUE(site_instance_a1.get() != NULL); |
| 442 | 424 |
| 443 // A separate site should create a separate SiteInstance. | 425 // A separate site should create a separate SiteInstance. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 466 new TestBrowsingInstance(browser_context.get(), &delete_counter); | 448 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
| 467 // Ensure the new SiteInstance is ref counted so that it gets deleted. | 449 // Ensure the new SiteInstance is ref counted so that it gets deleted. |
| 468 scoped_refptr<SiteInstanceImpl> site_instance_a2_2( | 450 scoped_refptr<SiteInstanceImpl> site_instance_a2_2( |
| 469 static_cast<SiteInstanceImpl*>( | 451 static_cast<SiteInstanceImpl*>( |
| 470 browsing_instance2->GetSiteInstanceForURL(url_a2))); | 452 browsing_instance2->GetSiteInstanceForURL(url_a2))); |
| 471 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); | 453 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); |
| 472 EXPECT_FALSE(site_instance_a1->IsRelatedSiteInstance(site_instance_a2_2)); | 454 EXPECT_FALSE(site_instance_a1->IsRelatedSiteInstance(site_instance_a2_2)); |
| 473 | 455 |
| 474 // The two SiteInstances for http://google.com should not use the same process | 456 // The two SiteInstances for http://google.com should not use the same process |
| 475 // if process-per-site is not enabled. | 457 // if process-per-site is not enabled. |
| 476 scoped_ptr<content::RenderProcessHost> process_a1( | 458 scoped_ptr<RenderProcessHost> process_a1(site_instance_a1->GetProcess()); |
| 477 site_instance_a1->GetProcess()); | 459 scoped_ptr<RenderProcessHost> process_a2_2( |
| 478 scoped_ptr<content::RenderProcessHost> process_a2_2( | |
| 479 site_instance_a2_2->GetProcess()); | 460 site_instance_a2_2->GetProcess()); |
| 480 EXPECT_NE(process_a1.get(), process_a2_2.get()); | 461 EXPECT_NE(process_a1.get(), process_a2_2.get()); |
| 481 | 462 |
| 482 // Should be able to see that we do have SiteInstances. | 463 // Should be able to see that we do have SiteInstances. |
| 483 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 464 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
| 484 GURL("http://mail.google.com"))); | 465 GURL("http://mail.google.com"))); |
| 485 EXPECT_TRUE(browsing_instance2->HasSiteInstance( | 466 EXPECT_TRUE(browsing_instance2->HasSiteInstance( |
| 486 GURL("http://mail.google.com"))); | 467 GURL("http://mail.google.com"))); |
| 487 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 468 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
| 488 GURL("http://mail.yahoo.com"))); | 469 GURL("http://mail.yahoo.com"))); |
| 489 | 470 |
| 490 // Should be able to see that we don't have SiteInstances. | 471 // Should be able to see that we don't have SiteInstances. |
| 491 EXPECT_FALSE(browsing_instance->HasSiteInstance( | 472 EXPECT_FALSE(browsing_instance->HasSiteInstance( |
| 492 GURL("https://www.google.com"))); | 473 GURL("https://www.google.com"))); |
| 493 EXPECT_FALSE(browsing_instance2->HasSiteInstance( | 474 EXPECT_FALSE(browsing_instance2->HasSiteInstance( |
| 494 GURL("http://www.yahoo.com"))); | 475 GURL("http://www.yahoo.com"))); |
| 495 | 476 |
| 496 // browsing_instances will be deleted when their SiteInstances are deleted. | 477 // browsing_instances will be deleted when their SiteInstances are deleted. |
| 497 // The processes will be unregistered when the RPH scoped_ptrs go away. | 478 // The processes will be unregistered when the RPH scoped_ptrs go away. |
| 498 | 479 |
| 499 DrainMessageLoops(); | 480 DrainMessageLoops(); |
| 500 } | 481 } |
| 501 | 482 |
| 502 // Test to ensure that there is only one RenderProcessHost per site for an | 483 // Test to ensure that there is only one RenderProcessHost per site for an |
| 503 // entire BrowserContext, if process-per-site is in use. | 484 // entire BrowserContext, if process-per-site is in use. |
| 504 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { | 485 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { |
| 505 CommandLine::ForCurrentProcess()->AppendSwitch( | 486 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 506 switches::kProcessPerSite); | 487 switches::kProcessPerSite); |
| 507 int delete_counter = 0; | 488 int delete_counter = 0; |
| 508 scoped_ptr<content::TestBrowserContext> browser_context( | 489 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 509 new content::TestBrowserContext()); | |
| 510 TestBrowsingInstance* browsing_instance = | 490 TestBrowsingInstance* browsing_instance = |
| 511 new TestBrowsingInstance(browser_context.get(), &delete_counter); | 491 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
| 512 | 492 |
| 513 const GURL url_a1("http://www.google.com/1.html"); | 493 const GURL url_a1("http://www.google.com/1.html"); |
| 514 scoped_refptr<SiteInstanceImpl> site_instance_a1( | 494 scoped_refptr<SiteInstanceImpl> site_instance_a1( |
| 515 static_cast<SiteInstanceImpl*>( | 495 static_cast<SiteInstanceImpl*>( |
| 516 browsing_instance->GetSiteInstanceForURL(url_a1))); | 496 browsing_instance->GetSiteInstanceForURL(url_a1))); |
| 517 EXPECT_TRUE(site_instance_a1.get() != NULL); | 497 EXPECT_TRUE(site_instance_a1.get() != NULL); |
| 518 scoped_ptr<content::RenderProcessHost> process_a1( | 498 scoped_ptr<RenderProcessHost> process_a1( |
| 519 site_instance_a1->GetProcess()); | 499 site_instance_a1->GetProcess()); |
| 520 | 500 |
| 521 // A separate site should create a separate SiteInstance. | 501 // A separate site should create a separate SiteInstance. |
| 522 const GURL url_b1("http://www.yahoo.com/"); | 502 const GURL url_b1("http://www.yahoo.com/"); |
| 523 scoped_refptr<SiteInstanceImpl> site_instance_b1( | 503 scoped_refptr<SiteInstanceImpl> site_instance_b1( |
| 524 static_cast<SiteInstanceImpl*>( | 504 static_cast<SiteInstanceImpl*>( |
| 525 browsing_instance->GetSiteInstanceForURL(url_b1))); | 505 browsing_instance->GetSiteInstanceForURL(url_b1))); |
| 526 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); | 506 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); |
| 527 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1)); | 507 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1)); |
| 528 | 508 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 544 new TestBrowsingInstance(browser_context.get(), &delete_counter); | 524 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
| 545 scoped_refptr<SiteInstanceImpl> site_instance_a1_2( | 525 scoped_refptr<SiteInstanceImpl> site_instance_a1_2( |
| 546 static_cast<SiteInstanceImpl*>( | 526 static_cast<SiteInstanceImpl*>( |
| 547 browsing_instance2->GetSiteInstanceForURL(url_a1))); | 527 browsing_instance2->GetSiteInstanceForURL(url_a1))); |
| 548 EXPECT_TRUE(site_instance_a1.get() != NULL); | 528 EXPECT_TRUE(site_instance_a1.get() != NULL); |
| 549 EXPECT_NE(site_instance_a1.get(), site_instance_a1_2.get()); | 529 EXPECT_NE(site_instance_a1.get(), site_instance_a1_2.get()); |
| 550 EXPECT_EQ(process_a1.get(), site_instance_a1_2->GetProcess()); | 530 EXPECT_EQ(process_a1.get(), site_instance_a1_2->GetProcess()); |
| 551 | 531 |
| 552 // A visit to the original site in a new BrowsingInstance (different browser | 532 // A visit to the original site in a new BrowsingInstance (different browser |
| 553 // context) should return a different SiteInstance with a different process. | 533 // context) should return a different SiteInstance with a different process. |
| 554 scoped_ptr<content::TestBrowserContext> browser_context2( | 534 scoped_ptr<TestBrowserContext> browser_context2(new TestBrowserContext()); |
| 555 new content::TestBrowserContext()); | |
| 556 TestBrowsingInstance* browsing_instance3 = | 535 TestBrowsingInstance* browsing_instance3 = |
| 557 new TestBrowsingInstance(browser_context2.get(), &delete_counter); | 536 new TestBrowsingInstance(browser_context2.get(), &delete_counter); |
| 558 scoped_refptr<SiteInstanceImpl> site_instance_a2_3( | 537 scoped_refptr<SiteInstanceImpl> site_instance_a2_3( |
| 559 static_cast<SiteInstanceImpl*>( | 538 static_cast<SiteInstanceImpl*>( |
| 560 browsing_instance3->GetSiteInstanceForURL(url_a2))); | 539 browsing_instance3->GetSiteInstanceForURL(url_a2))); |
| 561 EXPECT_TRUE(site_instance_a2_3.get() != NULL); | 540 EXPECT_TRUE(site_instance_a2_3.get() != NULL); |
| 562 scoped_ptr<content::RenderProcessHost> process_a2_3( | 541 scoped_ptr<RenderProcessHost> process_a2_3( |
| 563 site_instance_a2_3->GetProcess()); | 542 site_instance_a2_3->GetProcess()); |
| 564 EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); | 543 EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); |
| 565 EXPECT_NE(process_a1.get(), process_a2_3.get()); | 544 EXPECT_NE(process_a1.get(), process_a2_3.get()); |
| 566 | 545 |
| 567 // Should be able to see that we do have SiteInstances. | 546 // Should be able to see that we do have SiteInstances. |
| 568 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 547 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
| 569 GURL("http://mail.google.com"))); // visited before | 548 GURL("http://mail.google.com"))); // visited before |
| 570 EXPECT_TRUE(browsing_instance2->HasSiteInstance( | 549 EXPECT_TRUE(browsing_instance2->HasSiteInstance( |
| 571 GURL("http://mail.google.com"))); // visited before | 550 GURL("http://mail.google.com"))); // visited before |
| 572 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 551 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
| 573 GURL("http://mail.yahoo.com"))); // visited before | 552 GURL("http://mail.yahoo.com"))); // visited before |
| 574 | 553 |
| 575 // Should be able to see that we don't have SiteInstances. | 554 // Should be able to see that we don't have SiteInstances. |
| 576 EXPECT_FALSE(browsing_instance2->HasSiteInstance( | 555 EXPECT_FALSE(browsing_instance2->HasSiteInstance( |
| 577 GURL("http://www.yahoo.com"))); // different BI, same browser context | 556 GURL("http://www.yahoo.com"))); // different BI, same browser context |
| 578 EXPECT_FALSE(browsing_instance->HasSiteInstance( | 557 EXPECT_FALSE(browsing_instance->HasSiteInstance( |
| 579 GURL("https://www.google.com"))); // not visited before | 558 GURL("https://www.google.com"))); // not visited before |
| 580 EXPECT_FALSE(browsing_instance3->HasSiteInstance( | 559 EXPECT_FALSE(browsing_instance3->HasSiteInstance( |
| 581 GURL("http://www.yahoo.com"))); // different BI, different context | 560 GURL("http://www.yahoo.com"))); // different BI, different context |
| 582 | 561 |
| 583 // browsing_instances will be deleted when their SiteInstances are deleted. | 562 // browsing_instances will be deleted when their SiteInstances are deleted. |
| 584 // The processes will be unregistered when the RPH scoped_ptrs go away. | 563 // The processes will be unregistered when the RPH scoped_ptrs go away. |
| 585 | 564 |
| 586 DrainMessageLoops(); | 565 DrainMessageLoops(); |
| 587 } | 566 } |
| 588 | 567 |
| 589 static SiteInstanceImpl* CreateSiteInstance( | 568 static SiteInstanceImpl* CreateSiteInstance(BrowserContext* browser_context, |
| 590 content::BrowserContext* browser_context, | 569 RenderProcessHostFactory* factory, |
| 591 content::RenderProcessHostFactory* factory, | 570 const GURL& url) { |
| 592 const GURL& url) { | |
| 593 SiteInstanceImpl* instance = | 571 SiteInstanceImpl* instance = |
| 594 reinterpret_cast<SiteInstanceImpl*>( | 572 reinterpret_cast<SiteInstanceImpl*>( |
| 595 SiteInstance::CreateForURL(browser_context, url)); | 573 SiteInstance::CreateForURL(browser_context, url)); |
| 596 instance->set_render_process_host_factory(factory); | 574 instance->set_render_process_host_factory(factory); |
| 597 return instance; | 575 return instance; |
| 598 } | 576 } |
| 599 | 577 |
| 600 // Test to ensure that pages that require certain privileges are grouped | 578 // Test to ensure that pages that require certain privileges are grouped |
| 601 // in processes with similar pages. | 579 // in processes with similar pages. |
| 602 TEST_F(SiteInstanceTest, ProcessSharingByType) { | 580 TEST_F(SiteInstanceTest, ProcessSharingByType) { |
| 603 MockRenderProcessHostFactory rph_factory; | 581 MockRenderProcessHostFactory rph_factory; |
| 604 ChildProcessSecurityPolicyImpl* policy = | 582 ChildProcessSecurityPolicyImpl* policy = |
| 605 ChildProcessSecurityPolicyImpl::GetInstance(); | 583 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 606 | 584 |
| 607 // Make a bunch of mock renderers so that we hit the limit. | 585 // Make a bunch of mock renderers so that we hit the limit. |
| 608 scoped_ptr<content::TestBrowserContext> browser_context( | 586 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 609 new content::TestBrowserContext()); | |
| 610 std::vector<MockRenderProcessHost*> hosts; | 587 std::vector<MockRenderProcessHost*> hosts; |
| 611 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) | 588 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) |
| 612 hosts.push_back(new MockRenderProcessHost(browser_context.get())); | 589 hosts.push_back(new MockRenderProcessHost(browser_context.get())); |
| 613 | 590 |
| 614 // Create some extension instances and make sure they share a process. | 591 // Create some extension instances and make sure they share a process. |
| 615 scoped_refptr<SiteInstanceImpl> extension1_instance( | 592 scoped_refptr<SiteInstanceImpl> extension1_instance( |
| 616 CreateSiteInstance(browser_context.get(), &rph_factory, | 593 CreateSiteInstance(browser_context.get(), &rph_factory, |
| 617 GURL(kPrivilegedScheme + std::string("://foo/bar")))); | 594 GURL(kPrivilegedScheme + std::string("://foo/bar")))); |
| 618 set_privileged_process_id(extension1_instance->GetProcess()->GetID()); | 595 set_privileged_process_id(extension1_instance->GetProcess()->GetID()); |
| 619 | 596 |
| 620 scoped_refptr<SiteInstanceImpl> extension2_instance( | 597 scoped_refptr<SiteInstanceImpl> extension2_instance( |
| 621 CreateSiteInstance(browser_context.get(), &rph_factory, | 598 CreateSiteInstance(browser_context.get(), &rph_factory, |
| 622 GURL(kPrivilegedScheme + std::string("://baz/bar")))); | 599 GURL(kPrivilegedScheme + std::string("://baz/bar")))); |
| 623 | 600 |
| 624 scoped_ptr<content::RenderProcessHost> extension_host( | 601 scoped_ptr<RenderProcessHost> extension_host( |
| 625 extension1_instance->GetProcess()); | 602 extension1_instance->GetProcess()); |
| 626 EXPECT_EQ(extension1_instance->GetProcess(), | 603 EXPECT_EQ(extension1_instance->GetProcess(), |
| 627 extension2_instance->GetProcess()); | 604 extension2_instance->GetProcess()); |
| 628 | 605 |
| 629 // Create some WebUI instances and make sure they share a process. | 606 // Create some WebUI instances and make sure they share a process. |
| 630 scoped_refptr<SiteInstanceImpl> webui1_instance(CreateSiteInstance( | 607 scoped_refptr<SiteInstanceImpl> webui1_instance(CreateSiteInstance( |
| 631 browser_context.get(), &rph_factory, | 608 browser_context.get(), &rph_factory, |
| 632 GURL(chrome::kChromeUIScheme + std::string("://newtab")))); | 609 GURL(chrome::kChromeUIScheme + std::string("://newtab")))); |
| 633 policy->GrantWebUIBindings(webui1_instance->GetProcess()->GetID()); | 610 policy->GrantWebUIBindings(webui1_instance->GetProcess()->GetID()); |
| 634 | 611 |
| 635 scoped_refptr<SiteInstanceImpl> webui2_instance(CreateSiteInstance( | 612 scoped_refptr<SiteInstanceImpl> webui2_instance(CreateSiteInstance( |
| 636 browser_context.get(), &rph_factory, | 613 browser_context.get(), &rph_factory, |
| 637 GURL(chrome::kChromeUIScheme + std::string("://history")))); | 614 GURL(chrome::kChromeUIScheme + std::string("://history")))); |
| 638 | 615 |
| 639 scoped_ptr<content::RenderProcessHost> dom_host( | 616 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); |
| 640 webui1_instance->GetProcess()); | |
| 641 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); | 617 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); |
| 642 | 618 |
| 643 // Make sure none of differing privilege processes are mixed. | 619 // Make sure none of differing privilege processes are mixed. |
| 644 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 620 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
| 645 | 621 |
| 646 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) { | 622 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
| 647 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 623 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
| 648 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 624 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
| 649 } | 625 } |
| 650 | 626 |
| 651 STLDeleteContainerPointers(hosts.begin(), hosts.end()); | 627 STLDeleteContainerPointers(hosts.begin(), hosts.end()); |
| 652 | 628 |
| 653 DrainMessageLoops(); | 629 DrainMessageLoops(); |
| 654 } | 630 } |
| 655 | 631 |
| 656 // Test to ensure that HasWrongProcessForURL behaves properly for different | 632 // Test to ensure that HasWrongProcessForURL behaves properly for different |
| 657 // types of URLs. | 633 // types of URLs. |
| 658 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { | 634 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { |
| 659 scoped_ptr<content::TestBrowserContext> browser_context( | 635 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 660 new content::TestBrowserContext()); | 636 scoped_ptr<RenderProcessHost> host; |
| 661 scoped_ptr<content::RenderProcessHost> host; | |
| 662 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( | 637 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
| 663 SiteInstance::Create(browser_context.get()))); | 638 SiteInstance::Create(browser_context.get()))); |
| 664 | 639 |
| 665 EXPECT_FALSE(instance->HasSite()); | 640 EXPECT_FALSE(instance->HasSite()); |
| 666 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 641 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
| 667 | 642 |
| 668 instance->SetSite(GURL("http://evernote.com/")); | 643 instance->SetSite(GURL("http://evernote.com/")); |
| 669 EXPECT_TRUE(instance->HasSite()); | 644 EXPECT_TRUE(instance->HasSite()); |
| 670 | 645 |
| 671 // Check prior to "assigning" a process to the instance, which is expected | 646 // Check prior to "assigning" a process to the instance, which is expected |
| 672 // to return false due to not being attached to any process yet. | 647 // to return false due to not being attached to any process yet. |
| 673 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://google.com"))); | 648 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://google.com"))); |
| 674 | 649 |
| 675 // The call to GetProcess actually creates a new real process, which works | 650 // The call to GetProcess actually creates a new real process, which works |
| 676 // fine, but might be a cause for problems in different contexts. | 651 // fine, but might be a cause for problems in different contexts. |
| 677 host.reset(instance->GetProcess()); | 652 host.reset(instance->GetProcess()); |
| 678 EXPECT_TRUE(host.get() != NULL); | 653 EXPECT_TRUE(host.get() != NULL); |
| 679 EXPECT_TRUE(instance->HasProcess()); | 654 EXPECT_TRUE(instance->HasProcess()); |
| 680 | 655 |
| 681 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); | 656 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); |
| 682 EXPECT_FALSE(instance->HasWrongProcessForURL( | 657 EXPECT_FALSE(instance->HasWrongProcessForURL( |
| 683 GURL("javascript:alert(document.location.href);"))); | 658 GURL("javascript:alert(document.location.href);"))); |
| 684 | 659 |
| 685 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); | 660 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); |
| 686 | 661 |
| 687 DrainMessageLoops(); | 662 DrainMessageLoops(); |
| 688 } | 663 } |
| 664 |
| 665 } // namespace content |
| OLD | NEW |