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"; | |
31 const char kSameAsAnyInstanceURL[] = "about:internets"; | 27 const char kSameAsAnyInstanceURL[] = "about:internets"; |
32 | 28 |
33 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { | 29 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { |
34 public: | 30 public: |
35 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { | 31 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { |
36 return HasWebUIScheme(url); | 32 return HasWebUIScheme(url); |
37 } | 33 } |
38 virtual bool HasWebUIScheme(const GURL& url) const { | 34 virtual bool HasWebUIScheme(const GURL& url) const { |
39 return url.SchemeIs(kWebUIScheme); | 35 return url.SchemeIs(chrome::kChromeUIScheme); |
40 } | 36 } |
41 }; | 37 }; |
42 | 38 |
43 class SiteInstanceTestBrowserClient : public content::ContentBrowserClient { | 39 class SiteInstanceTestBrowserClient : public content::ContentBrowserClient { |
44 public: | 40 public: |
45 virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE { | 41 virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE { |
46 return &factory_; | 42 return &factory_; |
47 } | 43 } |
48 | 44 |
49 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE { | 45 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE { |
50 return url.spec() == kSameAsAnyInstanceURL; | 46 return url == GURL(kSameAsAnyInstanceURL) || |
| 47 url == GURL(chrome::kAboutCrashURL); |
51 } | 48 } |
52 | 49 |
53 private: | 50 private: |
54 SiteInstanceTestWebUIFactory factory_; | 51 SiteInstanceTestWebUIFactory factory_; |
55 }; | 52 }; |
56 | 53 |
57 class SiteInstanceTest : public testing::Test { | 54 class SiteInstanceTest : public testing::Test { |
58 public: | 55 public: |
59 SiteInstanceTest() | 56 SiteInstanceTest() |
60 : ui_thread_(BrowserThread::UI, &message_loop_), | 57 : ui_thread_(BrowserThread::UI, &message_loop_), |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 482 |
486 scoped_refptr<SiteInstance> extension2_instance( | 483 scoped_refptr<SiteInstance> extension2_instance( |
487 CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); | 484 CreateSiteInstance(&rph_factory, GURL("chrome-extension://baz/bar"))); |
488 | 485 |
489 scoped_ptr<RenderProcessHost> extension_host( | 486 scoped_ptr<RenderProcessHost> extension_host( |
490 extension1_instance->GetProcess()); | 487 extension1_instance->GetProcess()); |
491 EXPECT_EQ(extension1_instance->GetProcess(), | 488 EXPECT_EQ(extension1_instance->GetProcess(), |
492 extension2_instance->GetProcess()); | 489 extension2_instance->GetProcess()); |
493 | 490 |
494 // Create some WebUI instances and make sure they share a process. | 491 // Create some WebUI instances and make sure they share a process. |
495 scoped_refptr<SiteInstance> webui1_instance( | 492 scoped_refptr<SiteInstance> webui1_instance(CreateSiteInstance(&rph_factory, |
496 CreateSiteInstance(&rph_factory, | 493 GURL(chrome::kChromeUIScheme + std::string("://newtab")))); |
497 GURL(kWebUIScheme + std::string("://newtab")))); | |
498 policy->GrantWebUIBindings(webui1_instance->GetProcess()->id()); | 494 policy->GrantWebUIBindings(webui1_instance->GetProcess()->id()); |
499 | 495 |
500 scoped_refptr<SiteInstance> webui2_instance( | 496 scoped_refptr<SiteInstance> webui2_instance( CreateSiteInstance(&rph_factory, |
501 CreateSiteInstance(&rph_factory, | 497 GURL(chrome::kChromeUIScheme + std::string("://history")))); |
502 GURL(kWebUIScheme + std::string("://history")))); | |
503 | 498 |
504 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); | 499 scoped_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); |
505 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); | 500 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); |
506 | 501 |
507 // Make sure none of differing privilege processes are mixed. | 502 // Make sure none of differing privilege processes are mixed. |
508 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 503 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
509 | 504 |
510 for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) { | 505 for (size_t i = 0; i < chrome::kMaxRendererProcessCount; ++i) { |
511 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 506 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
512 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 507 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 GURL("chrome-extension://baz/bar"))); | 569 GURL("chrome-extension://baz/bar"))); |
575 EXPECT_EQ(s5a, s5b); | 570 EXPECT_EQ(s5a, s5b); |
576 | 571 |
577 // The derived profiles with the different sites. | 572 // The derived profiles with the different sites. |
578 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( | 573 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( |
579 GURL("chrome-extension://baz/bar"))); | 574 GURL("chrome-extension://baz/bar"))); |
580 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( | 575 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( |
581 GURL("chrome-extension://foo/boo"))); | 576 GURL("chrome-extension://foo/boo"))); |
582 EXPECT_NE(s6a, s6b); | 577 EXPECT_NE(s6a, s6b); |
583 } | 578 } |
OLD | NEW |