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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, | 87 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, |
88 &message_loop_), | 88 &message_loop_), |
89 io_thread_(BrowserThread::IO, &message_loop_), | 89 io_thread_(BrowserThread::IO, &message_loop_), |
90 old_browser_client_(NULL) { | 90 old_browser_client_(NULL) { |
91 } | 91 } |
92 | 92 |
93 virtual void SetUp() { | 93 virtual void SetUp() { |
94 old_browser_client_ = SetBrowserClientForTesting(&browser_client_); | 94 old_browser_client_ = SetBrowserClientForTesting(&browser_client_); |
95 url_util::AddStandardScheme(kPrivilegedScheme); | 95 url_util::AddStandardScheme(kPrivilegedScheme); |
96 url_util::AddStandardScheme(chrome::kChromeUIScheme); | 96 url_util::AddStandardScheme(chrome::kChromeUIScheme); |
| 97 |
| 98 SiteInstanceImpl::set_render_process_host_factory(&rph_factory_); |
97 } | 99 } |
98 | 100 |
99 virtual void TearDown() { | 101 virtual void TearDown() { |
100 // Ensure that no RenderProcessHosts are left over after the tests. | 102 // Ensure that no RenderProcessHosts are left over after the tests. |
101 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd()); | 103 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd()); |
102 | 104 |
103 SetBrowserClientForTesting(old_browser_client_); | 105 SetBrowserClientForTesting(old_browser_client_); |
104 SiteInstanceImpl::set_render_process_host_factory(NULL); | 106 SiteInstanceImpl::set_render_process_host_factory(NULL); |
105 | 107 |
106 // http://crbug.com/143565 found SiteInstanceTest leaking an | 108 // http://crbug.com/143565 found SiteInstanceTest leaking an |
(...skipping 21 matching lines...) Expand all Loading... |
128 } | 130 } |
129 | 131 |
130 private: | 132 private: |
131 base::MessageLoopForUI message_loop_; | 133 base::MessageLoopForUI message_loop_; |
132 TestBrowserThread ui_thread_; | 134 TestBrowserThread ui_thread_; |
133 TestBrowserThread file_user_blocking_thread_; | 135 TestBrowserThread file_user_blocking_thread_; |
134 TestBrowserThread io_thread_; | 136 TestBrowserThread io_thread_; |
135 | 137 |
136 SiteInstanceTestBrowserClient browser_client_; | 138 SiteInstanceTestBrowserClient browser_client_; |
137 ContentBrowserClient* old_browser_client_; | 139 ContentBrowserClient* old_browser_client_; |
| 140 MockRenderProcessHostFactory rph_factory_; |
138 }; | 141 }; |
139 | 142 |
140 // Subclass of BrowsingInstance that updates a counter when deleted and | 143 // Subclass of BrowsingInstance that updates a counter when deleted and |
141 // returns TestSiteInstances from GetSiteInstanceForURL. | 144 // returns TestSiteInstances from GetSiteInstanceForURL. |
142 class TestBrowsingInstance : public BrowsingInstance { | 145 class TestBrowsingInstance : public BrowsingInstance { |
143 public: | 146 public: |
144 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter) | 147 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter) |
145 : BrowsingInstance(browser_context), | 148 : BrowsingInstance(browser_context), |
146 delete_counter_(delete_counter) { | 149 delete_counter_(delete_counter) { |
147 } | 150 } |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 547 |
545 static SiteInstanceImpl* CreateSiteInstance(BrowserContext* browser_context, | 548 static SiteInstanceImpl* CreateSiteInstance(BrowserContext* browser_context, |
546 const GURL& url) { | 549 const GURL& url) { |
547 return static_cast<SiteInstanceImpl*>( | 550 return static_cast<SiteInstanceImpl*>( |
548 SiteInstance::CreateForURL(browser_context, url)); | 551 SiteInstance::CreateForURL(browser_context, url)); |
549 } | 552 } |
550 | 553 |
551 // Test to ensure that pages that require certain privileges are grouped | 554 // Test to ensure that pages that require certain privileges are grouped |
552 // in processes with similar pages. | 555 // in processes with similar pages. |
553 TEST_F(SiteInstanceTest, ProcessSharingByType) { | 556 TEST_F(SiteInstanceTest, ProcessSharingByType) { |
554 MockRenderProcessHostFactory rph_factory; | |
555 SiteInstanceImpl::set_render_process_host_factory(&rph_factory); | |
556 ChildProcessSecurityPolicyImpl* policy = | 557 ChildProcessSecurityPolicyImpl* policy = |
557 ChildProcessSecurityPolicyImpl::GetInstance(); | 558 ChildProcessSecurityPolicyImpl::GetInstance(); |
558 | 559 |
559 // Make a bunch of mock renderers so that we hit the limit. | 560 // Make a bunch of mock renderers so that we hit the limit. |
560 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 561 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
561 ScopedVector<MockRenderProcessHost> hosts; | 562 ScopedVector<MockRenderProcessHost> hosts; |
562 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) | 563 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) |
563 hosts.push_back(new MockRenderProcessHost(browser_context.get())); | 564 hosts.push_back(new MockRenderProcessHost(browser_context.get())); |
564 | 565 |
565 // Create some extension instances and make sure they share a process. | 566 // Create some extension instances and make sure they share a process. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 750 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
750 host.reset(instance->GetProcess()); | 751 host.reset(instance->GetProcess()); |
751 | 752 |
752 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( | 753 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( |
753 browser_context.get(), GURL())); | 754 browser_context.get(), GURL())); |
754 | 755 |
755 DrainMessageLoops(); | 756 DrainMessageLoops(); |
756 } | 757 } |
757 | 758 |
758 } // namespace content | 759 } // namespace content |
OLD | NEW |