| 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/test/testing_profile.h" | 8 #include "chrome/test/testing_profile.h" |
| 9 #include "content/browser/browser_thread.h" | 9 #include "content/browser/browser_thread.h" |
| 10 #include "content/browser/browsing_instance.h" | 10 #include "content/browser/browsing_instance.h" |
| 11 #include "content/browser/child_process_security_policy.h" | 11 #include "content/browser/child_process_security_policy.h" |
| 12 #include "content/browser/content_browser_client.h" | 12 #include "content/browser/mock_content_browser_client.h" |
| 13 #include "content/browser/renderer_host/browser_render_process_host.h" | 13 #include "content/browser/renderer_host/browser_render_process_host.h" |
| 14 #include "content/browser/renderer_host/render_view_host.h" | 14 #include "content/browser/renderer_host/render_view_host.h" |
| 15 #include "content/browser/renderer_host/test_render_view_host.h" | 15 #include "content/browser/renderer_host/test_render_view_host.h" |
| 16 #include "content/browser/site_instance.h" | 16 #include "content/browser/site_instance.h" |
| 17 #include "content/browser/tab_contents/navigation_entry.h" | 17 #include "content/browser/tab_contents/navigation_entry.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "content/browser/webui/empty_web_ui_factory.h" | 19 #include "content/browser/webui/empty_web_ui_factory.h" |
| 20 #include "content/common/content_client.h" | 20 #include "content/common/content_client.h" |
| 21 #include "content/common/content_constants.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 { |
| 32 return HasWebUIScheme(url); | 32 return HasWebUIScheme(url); |
| 33 } | 33 } |
| 34 virtual bool HasWebUIScheme(const GURL& url) const { | 34 virtual bool HasWebUIScheme(const GURL& url) const { |
| 35 return url.SchemeIs(chrome::kChromeUIScheme); | 35 return url.SchemeIs(chrome::kChromeUIScheme); |
| 36 } | 36 } |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class SiteInstanceTestBrowserClient : public content::ContentBrowserClient { | 39 class SiteInstanceTestBrowserClient : public content::MockContentBrowserClient { |
| 40 public: | 40 public: |
| 41 virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE { | 41 virtual content::WebUIFactory* GetWebUIFactory() OVERRIDE { |
| 42 return &factory_; | 42 return &factory_; |
| 43 } | 43 } |
| 44 | 44 |
| 45 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE { | 45 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) OVERRIDE { |
| 46 return url == GURL(kSameAsAnyInstanceURL) || | 46 return url == GURL(kSameAsAnyInstanceURL) || |
| 47 url == GURL(chrome::kAboutCrashURL); | 47 url == GURL(chrome::kAboutCrashURL); |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual GURL GetEffectiveURL(Profile* profile, const GURL& url) OVERRIDE { |
| 51 return url; |
| 52 } |
| 53 |
| 50 private: | 54 private: |
| 51 SiteInstanceTestWebUIFactory factory_; | 55 SiteInstanceTestWebUIFactory factory_; |
| 52 }; | 56 }; |
| 53 | 57 |
| 54 class SiteInstanceTest : public testing::Test { | 58 class SiteInstanceTest : public testing::Test { |
| 55 public: | 59 public: |
| 56 SiteInstanceTest() | 60 SiteInstanceTest() |
| 57 : ui_thread_(BrowserThread::UI, &message_loop_), | 61 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 58 old_browser_client_(NULL) { | 62 old_browser_client_(NULL) { |
| 59 } | 63 } |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 GURL("chrome-extension://baz/bar"))); | 573 GURL("chrome-extension://baz/bar"))); |
| 570 EXPECT_EQ(s5a, s5b); | 574 EXPECT_EQ(s5a, s5b); |
| 571 | 575 |
| 572 // The derived profiles with the different sites. | 576 // The derived profiles with the different sites. |
| 573 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( | 577 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( |
| 574 GURL("chrome-extension://baz/bar"))); | 578 GURL("chrome-extension://baz/bar"))); |
| 575 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( | 579 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( |
| 576 GURL("chrome-extension://foo/boo"))); | 580 GURL("chrome-extension://foo/boo"))); |
| 577 EXPECT_NE(s6a, s6b); | 581 EXPECT_NE(s6a, s6b); |
| 578 } | 582 } |
| OLD | NEW |