| 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" | 8 #include "chrome/common/chrome_constants.h" |
| 9 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
| 10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| 11 #include "content/browser/browsing_instance.h" | 11 #include "content/browser/browsing_instance.h" |
| 12 #include "content/browser/child_process_security_policy.h" | 12 #include "content/browser/child_process_security_policy.h" |
| 13 #include "content/browser/content_browser_client.h" | 13 #include "content/browser/content_browser_client.h" |
| 14 #include "content/browser/renderer_host/browser_render_process_host.h" | 14 #include "content/browser/renderer_host/browser_render_process_host.h" |
| 15 #include "content/browser/renderer_host/render_view_host.h" | 15 #include "content/browser/renderer_host/render_view_host.h" |
| 16 #include "content/browser/renderer_host/test_render_view_host.h" | 16 #include "content/browser/renderer_host/test_render_view_host.h" |
| 17 #include "content/browser/site_instance.h" | 17 #include "content/browser/site_instance.h" |
| 18 #include "content/browser/tab_contents/navigation_entry.h" | 18 #include "content/browser/tab_contents/navigation_entry.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
| 20 #include "content/browser/webui/empty_web_ui_factory.h" | 20 #include "content/browser/webui/empty_web_ui_factory.h" |
| 21 #include "content/common/content_client.h" | 21 #include "content/common/content_client.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 // TODO(estade): this shouldn't need to be chrome:, but it does (or else GURL |
| 28 // doesn't think that the webui URLs have a host). Figure out where this is |
| 29 // coming from and fix it. |
| 30 const char kWebUIScheme[] = "chrome"; |
| 27 const char kSameAsAnyInstanceURL[] = "about:internets"; | 31 const char kSameAsAnyInstanceURL[] = "about:internets"; |
| 28 | 32 |
| 29 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { | 33 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { |
| 30 public: | 34 public: |
| 31 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { | 35 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { |
| 32 return HasWebUIScheme(url); | 36 return HasWebUIScheme(url); |
| 33 } | 37 } |
| 34 virtual bool HasWebUIScheme(const GURL& url) const { | 38 virtual bool HasWebUIScheme(const GURL& url) const { |
| 35 return url.SchemeIs(chrome::kChromeUIScheme); | 39 return url.SchemeIs(kWebUIScheme); |
| 36 } | 40 } |
| 37 }; | 41 }; |
| 38 | 42 |
| 39 class SiteInstanceTestBrowserClient : public content::ContentBrowserClient { | 43 class SiteInstanceTestBrowserClient : public content::ContentBrowserClient { |
| 40 public: | 44 public: |
| 41 virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE { | 45 virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE { |
| 42 return &factory_; | 46 return &factory_; |
| 43 } | 47 } |
| 44 | 48 |
| 45 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE { | 49 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE { |
| 46 return url == GURL(kSameAsAnyInstanceURL) || | 50 return url.spec() == kSameAsAnyInstanceURL; |
| 47 url == GURL(chrome::kAboutCrashURL); | |
| 48 } | 51 } |
| 49 | 52 |
| 50 private: | 53 private: |
| 51 SiteInstanceTestWebUIFactory factory_; | 54 SiteInstanceTestWebUIFactory factory_; |
| 52 }; | 55 }; |
| 53 | 56 |
| 54 class SiteInstanceTest : public testing::Test { | 57 class SiteInstanceTest : public testing::Test { |
| 55 public: | 58 public: |
| 56 SiteInstanceTest() | 59 SiteInstanceTest() |
| 57 : ui_thread_(BrowserThread::UI, &message_loop_), | 60 : ui_thread_(BrowserThread::UI, &message_loop_), |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 485 |
| 483 scoped_refptr<SiteInstance> extension2_instance( | 486 scoped_refptr<SiteInstance> extension2_instance( |
| 484 CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); | 487 CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); |
| 485 | 488 |
| 486 scoped_ptr<RenderProcessHost> extension_host( | 489 scoped_ptr<RenderProcessHost> extension_host( |
| 487 extension1_instance->GetProcess()); | 490 extension1_instance->GetProcess()); |
| 488 EXPECT_EQ(extension1_instance->GetProcess(), | 491 EXPECT_EQ(extension1_instance->GetProcess(), |
| 489 extension2_instance->GetProcess()); | 492 extension2_instance->GetProcess()); |
| 490 | 493 |
| 491 // Create some WebUI instances and make sure they share a process. | 494 // Create some WebUI instances and make sure they share a process. |
| 492 scoped_refptr<SiteInstance> webui1_instance(CreateSiteInstance(&rph_factory, | 495 scoped_refptr<SiteInstance> webui1_instance( |
| 493 GURL(chrome::kChromeUIScheme + std::string("://newtab")))); | 496 CreateSiteInstance(&rph_factory, |
| 497 GURL(kWebUIScheme + std::string("://newtab")))); |
| 494 policy->GrantWebUIBindings(webui1_instance->GetProcess()->id()); | 498 policy->GrantWebUIBindings(webui1_instance->GetProcess()->id()); |
| 495 | 499 |
| 496 scoped_refptr<SiteInstance> webui2_instance( CreateSiteInstance(&rph_factory, | 500 scoped_refptr<SiteInstance> webui2_instance( |
| 497 GURL(chrome::kChromeUIScheme + std::string("://history")))); | 501 CreateSiteInstance(&rph_factory, |
| 502 GURL(kWebUIScheme + std::string("://history")))); |
| 498 | 503 |
| 499 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); | 504 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); |
| 500 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); | 505 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); |
| 501 | 506 |
| 502 // Make sure none of differing privilege processes are mixed. | 507 // Make sure none of differing privilege processes are mixed. |
| 503 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 508 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
| 504 | 509 |
| 505 for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) { | 510 for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) { |
| 506 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 511 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
| 507 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 512 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 GURL("chrome-extension://baz/bar"))); | 574 GURL("chrome-extension://baz/bar"))); |
| 570 EXPECT_EQ(s5a, s5b); | 575 EXPECT_EQ(s5a, s5b); |
| 571 | 576 |
| 572 // The derived profiles with the different sites. | 577 // The derived profiles with the different sites. |
| 573 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( | 578 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( |
| 574 GURL("chrome-extension://baz/bar"))); | 579 GURL("chrome-extension://baz/bar"))); |
| 575 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( | 580 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( |
| 576 GURL("chrome-extension://foo/boo"))); | 581 GURL("chrome-extension://foo/boo"))); |
| 577 EXPECT_NE(s6a, s6b); | 582 EXPECT_NE(s6a, s6b); |
| 578 } | 583 } |
| OLD | NEW |