| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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-inl.h" | 6 #include "base/stl_util-inl.h" |
| 7 #include "base/string16.h" | 7 #include "base/string16.h" |
| 8 #include "chrome/common/chrome_constants.h" | |
| 9 #include "chrome/test/testing_profile.h" | 8 #include "chrome/test/testing_profile.h" |
| 10 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
| 11 #include "content/browser/browsing_instance.h" | 10 #include "content/browser/browsing_instance.h" |
| 12 #include "content/browser/child_process_security_policy.h" | 11 #include "content/browser/child_process_security_policy.h" |
| 13 #include "content/browser/content_browser_client.h" | 12 #include "content/browser/content_browser_client.h" |
| 14 #include "content/browser/renderer_host/browser_render_process_host.h" | 13 #include "content/browser/renderer_host/browser_render_process_host.h" |
| 15 #include "content/browser/renderer_host/render_view_host.h" | 14 #include "content/browser/renderer_host/render_view_host.h" |
| 16 #include "content/browser/renderer_host/test_render_view_host.h" | 15 #include "content/browser/renderer_host/test_render_view_host.h" |
| 17 #include "content/browser/site_instance.h" | 16 #include "content/browser/site_instance.h" |
| 18 #include "content/browser/tab_contents/navigation_entry.h" | 17 #include "content/browser/tab_contents/navigation_entry.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 20 #include "content/browser/webui/empty_web_ui_factory.h" | 19 #include "content/browser/webui/empty_web_ui_factory.h" |
| 21 #include "content/common/content_client.h" | 20 #include "content/common/content_client.h" |
| 21 #include "content/common/content_constants.h" |
| 22 #include "content/common/url_constants.h" | 22 #include "content/common/url_constants.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const char kSameAsAnyInstanceURL[] = "about:internets"; | 27 const char kSameAsAnyInstanceURL[] = "about:internets"; |
| 28 | 28 |
| 29 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { | 29 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { |
| 30 public: | 30 public: |
| 31 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { | 31 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 465 |
| 466 // Test to ensure that pages that require certain privileges are grouped | 466 // Test to ensure that pages that require certain privileges are grouped |
| 467 // in processes with similar pages. | 467 // in processes with similar pages. |
| 468 TEST_F(SiteInstanceTest, ProcessSharingByType) { | 468 TEST_F(SiteInstanceTest, ProcessSharingByType) { |
| 469 MockRenderProcessHostFactory rph_factory; | 469 MockRenderProcessHostFactory rph_factory; |
| 470 ChildProcessSecurityPolicy* policy = | 470 ChildProcessSecurityPolicy* policy = |
| 471 ChildProcessSecurityPolicy::GetInstance(); | 471 ChildProcessSecurityPolicy::GetInstance(); |
| 472 | 472 |
| 473 // Make a bunch of mock renderers so that we hit the limit. | 473 // Make a bunch of mock renderers so that we hit the limit. |
| 474 std::vector<MockRenderProcessHost*> hosts; | 474 std::vector<MockRenderProcessHost*> hosts; |
| 475 for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) | 475 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) |
| 476 hosts.push_back(new MockRenderProcessHost(NULL)); | 476 hosts.push_back(new MockRenderProcessHost(NULL)); |
| 477 | 477 |
| 478 // Create some extension instances and make sure they share a process. | 478 // Create some extension instances and make sure they share a process. |
| 479 scoped_refptr<SiteInstance> extension1_instance( | 479 scoped_refptr<SiteInstance> extension1_instance( |
| 480 CreateSiteInstance(&rph_factory, GURL("chrome-extension://foo/bar"))); | 480 CreateSiteInstance(&rph_factory, GURL("chrome-extension://foo/bar"))); |
| 481 policy->GrantExtensionBindings(extension1_instance->GetProcess()->id()); | 481 policy->GrantExtensionBindings(extension1_instance->GetProcess()->id()); |
| 482 | 482 |
| 483 scoped_refptr<SiteInstance> extension2_instance( | 483 scoped_refptr<SiteInstance> extension2_instance( |
| 484 CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); | 484 CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); |
| 485 | 485 |
| 486 scoped_ptr<RenderProcessHost> extension_host( | 486 scoped_ptr<RenderProcessHost> extension_host( |
| 487 extension1_instance->GetProcess()); | 487 extension1_instance->GetProcess()); |
| 488 EXPECT_EQ(extension1_instance->GetProcess(), | 488 EXPECT_EQ(extension1_instance->GetProcess(), |
| 489 extension2_instance->GetProcess()); | 489 extension2_instance->GetProcess()); |
| 490 | 490 |
| 491 // Create some WebUI instances and make sure they share a process. | 491 // Create some WebUI instances and make sure they share a process. |
| 492 scoped_refptr<SiteInstance> webui1_instance(CreateSiteInstance(&rph_factory, | 492 scoped_refptr<SiteInstance> webui1_instance(CreateSiteInstance(&rph_factory, |
| 493 GURL(chrome::kChromeUIScheme + std::string("://newtab")))); | 493 GURL(chrome::kChromeUIScheme + std::string("://newtab")))); |
| 494 policy->GrantWebUIBindings(webui1_instance->GetProcess()->id()); | 494 policy->GrantWebUIBindings(webui1_instance->GetProcess()->id()); |
| 495 | 495 |
| 496 scoped_refptr<SiteInstance> webui2_instance( CreateSiteInstance(&rph_factory, | 496 scoped_refptr<SiteInstance> webui2_instance( CreateSiteInstance(&rph_factory, |
| 497 GURL(chrome::kChromeUIScheme + std::string("://history")))); | 497 GURL(chrome::kChromeUIScheme + std::string("://history")))); |
| 498 | 498 |
| 499 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); | 499 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); |
| 500 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); | 500 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); |
| 501 | 501 |
| 502 // Make sure none of differing privilege processes are mixed. | 502 // Make sure none of differing privilege processes are mixed. |
| 503 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 503 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
| 504 | 504 |
| 505 for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) { | 505 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) { |
| 506 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 506 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
| 507 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 507 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
| 508 } | 508 } |
| 509 | 509 |
| 510 STLDeleteContainerPointers(hosts.begin(), hosts.end()); | 510 STLDeleteContainerPointers(hosts.begin(), hosts.end()); |
| 511 } | 511 } |
| 512 | 512 |
| 513 // Test to ensure that profiles that derive from each other share site | 513 // Test to ensure that profiles that derive from each other share site |
| 514 // information. | 514 // information. |
| 515 TEST_F(SiteInstanceTest, GetSiteInstanceMap) { | 515 TEST_F(SiteInstanceTest, GetSiteInstanceMap) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 GURL("chrome-extension://baz/bar"))); | 569 GURL("chrome-extension://baz/bar"))); |
| 570 EXPECT_EQ(s5a, s5b); | 570 EXPECT_EQ(s5a, s5b); |
| 571 | 571 |
| 572 // The derived profiles with the different sites. | 572 // The derived profiles with the different sites. |
| 573 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( | 573 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( |
| 574 GURL("chrome-extension://baz/bar"))); | 574 GURL("chrome-extension://baz/bar"))); |
| 575 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( | 575 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( |
| 576 GURL("chrome-extension://foo/boo"))); | 576 GURL("chrome-extension://foo/boo"))); |
| 577 EXPECT_NE(s6a, s6b); | 577 EXPECT_NE(s6a, s6b); |
| 578 } | 578 } |
| OLD | NEW |