| 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/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/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 18 matching lines...) Expand all Loading... |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "url/url_util.h" | 30 #include "url/url_util.h" |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const char kPrivilegedScheme[] = "privileged"; | 35 const char kPrivilegedScheme[] = "privileged"; |
| 36 | 36 |
| 37 class SiteInstanceTestWebUIControllerFactory : public WebUIControllerFactory { | 37 class SiteInstanceTestWebUIControllerFactory : public WebUIControllerFactory { |
| 38 public: | 38 public: |
| 39 virtual WebUIController* CreateWebUIControllerForURL( | 39 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, |
| 40 WebUI* web_ui, const GURL& url) const override { | 40 const GURL& url) const override { |
| 41 return NULL; | 41 return NULL; |
| 42 } | 42 } |
| 43 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 43 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
| 44 const GURL& url) const override { | 44 const GURL& url) const override { |
| 45 return WebUI::kNoWebUI; | 45 return WebUI::kNoWebUI; |
| 46 } | 46 } |
| 47 virtual bool UseWebUIForURL(BrowserContext* browser_context, | 47 bool UseWebUIForURL(BrowserContext* browser_context, |
| 48 const GURL& url) const override { |
| 49 return HasWebUIScheme(url); |
| 50 } |
| 51 bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
| 48 const GURL& url) const override { | 52 const GURL& url) const override { |
| 49 return HasWebUIScheme(url); | 53 return HasWebUIScheme(url); |
| 50 } | 54 } |
| 51 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, | |
| 52 const GURL& url) const override { | |
| 53 return HasWebUIScheme(url); | |
| 54 } | |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class SiteInstanceTestBrowserClient : public TestContentBrowserClient { | 57 class SiteInstanceTestBrowserClient : public TestContentBrowserClient { |
| 58 public: | 58 public: |
| 59 SiteInstanceTestBrowserClient() | 59 SiteInstanceTestBrowserClient() |
| 60 : privileged_process_id_(-1) { | 60 : privileged_process_id_(-1) { |
| 61 WebUIControllerFactory::RegisterFactory(&factory_); | 61 WebUIControllerFactory::RegisterFactory(&factory_); |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual ~SiteInstanceTestBrowserClient() { | 64 ~SiteInstanceTestBrowserClient() override { |
| 65 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); | 65 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual bool IsSuitableHost(RenderProcessHost* process_host, | 68 bool IsSuitableHost(RenderProcessHost* process_host, |
| 69 const GURL& site_url) override { | 69 const GURL& site_url) override { |
| 70 return (privileged_process_id_ == process_host->GetID()) == | 70 return (privileged_process_id_ == process_host->GetID()) == |
| 71 site_url.SchemeIs(kPrivilegedScheme); | 71 site_url.SchemeIs(kPrivilegedScheme); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void set_privileged_process_id(int process_id) { | 74 void set_privileged_process_id(int process_id) { |
| 75 privileged_process_id_ = process_id; | 75 privileged_process_id_ = process_id; |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 SiteInstanceTestWebUIControllerFactory factory_; | 79 SiteInstanceTestWebUIControllerFactory factory_; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Make a few methods public for tests. | 152 // Make a few methods public for tests. |
| 153 using BrowsingInstance::browser_context; | 153 using BrowsingInstance::browser_context; |
| 154 using BrowsingInstance::HasSiteInstance; | 154 using BrowsingInstance::HasSiteInstance; |
| 155 using BrowsingInstance::GetSiteInstanceForURL; | 155 using BrowsingInstance::GetSiteInstanceForURL; |
| 156 using BrowsingInstance::RegisterSiteInstance; | 156 using BrowsingInstance::RegisterSiteInstance; |
| 157 using BrowsingInstance::UnregisterSiteInstance; | 157 using BrowsingInstance::UnregisterSiteInstance; |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 virtual ~TestBrowsingInstance() { | 160 ~TestBrowsingInstance() override { (*delete_counter_)++; } |
| 161 (*delete_counter_)++; | |
| 162 } | |
| 163 | 161 |
| 164 int* delete_counter_; | 162 int* delete_counter_; |
| 165 }; | 163 }; |
| 166 | 164 |
| 167 // Subclass of SiteInstanceImpl that updates a counter when deleted. | 165 // Subclass of SiteInstanceImpl that updates a counter when deleted. |
| 168 class TestSiteInstance : public SiteInstanceImpl { | 166 class TestSiteInstance : public SiteInstanceImpl { |
| 169 public: | 167 public: |
| 170 static TestSiteInstance* CreateTestSiteInstance( | 168 static TestSiteInstance* CreateTestSiteInstance( |
| 171 BrowserContext* browser_context, | 169 BrowserContext* browser_context, |
| 172 int* site_delete_counter, | 170 int* site_delete_counter, |
| 173 int* browsing_delete_counter) { | 171 int* browsing_delete_counter) { |
| 174 TestBrowsingInstance* browsing_instance = | 172 TestBrowsingInstance* browsing_instance = |
| 175 new TestBrowsingInstance(browser_context, browsing_delete_counter); | 173 new TestBrowsingInstance(browser_context, browsing_delete_counter); |
| 176 return new TestSiteInstance(browsing_instance, site_delete_counter); | 174 return new TestSiteInstance(browsing_instance, site_delete_counter); |
| 177 } | 175 } |
| 178 | 176 |
| 179 private: | 177 private: |
| 180 TestSiteInstance(BrowsingInstance* browsing_instance, int* delete_counter) | 178 TestSiteInstance(BrowsingInstance* browsing_instance, int* delete_counter) |
| 181 : SiteInstanceImpl(browsing_instance), delete_counter_(delete_counter) {} | 179 : SiteInstanceImpl(browsing_instance), delete_counter_(delete_counter) {} |
| 182 virtual ~TestSiteInstance() { | 180 ~TestSiteInstance() override { (*delete_counter_)++; } |
| 183 (*delete_counter_)++; | |
| 184 } | |
| 185 | 181 |
| 186 int* delete_counter_; | 182 int* delete_counter_; |
| 187 }; | 183 }; |
| 188 | 184 |
| 189 } // namespace | 185 } // namespace |
| 190 | 186 |
| 191 // Test to ensure no memory leaks for SiteInstance objects. | 187 // Test to ensure no memory leaks for SiteInstance objects. |
| 192 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { | 188 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { |
| 193 // The existence of this object will cause WebContentsImpl to create our | 189 // The existence of this object will cause WebContentsImpl to create our |
| 194 // test one instead of the real one. | 190 // test one instead of the real one. |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 776 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
| 781 host.reset(instance->GetProcess()); | 777 host.reset(instance->GetProcess()); |
| 782 | 778 |
| 783 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( | 779 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( |
| 784 browser_context.get(), GURL())); | 780 browser_context.get(), GURL())); |
| 785 | 781 |
| 786 DrainMessageLoops(); | 782 DrainMessageLoops(); |
| 787 } | 783 } |
| 788 | 784 |
| 789 } // namespace content | 785 } // namespace content |
| OLD | NEW |