OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 subframe->SendRendererInitiatedNavigationRequest(kUrl1, false); | 144 subframe->SendRendererInitiatedNavigationRequest(kUrl1, false); |
145 subframe->PrepareForCommit(); | 145 subframe->PrepareForCommit(); |
146 subframe->SendNavigateWithParams(¶ms); | 146 subframe->SendNavigateWithParams(¶ms); |
147 } | 147 } |
148 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl1); | 148 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl1); |
149 site_instance->set_process_reuse_policy( | 149 site_instance->set_process_reuse_policy( |
150 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); | 150 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); |
151 EXPECT_EQ(subframe->GetProcess(), site_instance->GetProcess()); | 151 EXPECT_EQ(subframe->GetProcess(), site_instance->GetProcess()); |
152 } | 152 } |
153 | 153 |
| 154 // Check that only new processes that haven't yet hosted any web content are |
| 155 // allowed to be reused to host a site requiring a dedicated process. |
| 156 TEST_F(RenderProcessHostUnitTest, IsUnused) { |
| 157 const GURL kUrl1("http://foo.com"); |
| 158 |
| 159 // A process for a SiteInstance that has no site should be able to host any |
| 160 // site that requires a dedicated process. |
| 161 EXPECT_FALSE(main_test_rfh()->GetSiteInstance()->HasSite()); |
| 162 EXPECT_TRUE(main_test_rfh()->GetProcess()->IsUnused()); |
| 163 { |
| 164 scoped_refptr<SiteInstanceImpl> site_instance = |
| 165 SiteInstanceImpl::Create(browser_context()); |
| 166 EXPECT_FALSE(site_instance->HasSite()); |
| 167 EXPECT_TRUE(site_instance->GetProcess()->IsUnused()); |
| 168 } |
| 169 |
| 170 // Navigation should mark the process as unable to become a dedicated process |
| 171 // for arbitrary sites. |
| 172 NavigateAndCommit(kUrl1); |
| 173 EXPECT_FALSE(main_test_rfh()->GetProcess()->IsUnused()); |
| 174 |
| 175 // A process for a SiteInstance with a preassigned site should be considered |
| 176 // "used" from the point the process is created via GetProcess(). |
| 177 { |
| 178 scoped_refptr<SiteInstanceImpl> site_instance = |
| 179 SiteInstanceImpl::CreateForURL(browser_context(), kUrl1); |
| 180 EXPECT_FALSE(site_instance->GetProcess()->IsUnused()); |
| 181 } |
| 182 } |
| 183 |
154 // Tests that RenderProcessHost will not consider reusing a process that has | 184 // Tests that RenderProcessHost will not consider reusing a process that has |
155 // committed an error page. | 185 // committed an error page. |
156 TEST_F(RenderProcessHostUnitTest, DoNotReuseError) { | 186 TEST_F(RenderProcessHostUnitTest, DoNotReuseError) { |
157 const GURL kUrl1("http://foo.com"); | 187 const GURL kUrl1("http://foo.com"); |
158 const GURL kUrl2("http://bar.com"); | 188 const GURL kUrl2("http://bar.com"); |
159 | 189 |
160 // At first, trying to get a RenderProcessHost with the | 190 // At first, trying to get a RenderProcessHost with the |
161 // REUSE_PENDING_OR_COMMITTED_SITE policy should return a new process. | 191 // REUSE_PENDING_OR_COMMITTED_SITE policy should return a new process. |
162 scoped_refptr<SiteInstanceImpl> site_instance = | 192 scoped_refptr<SiteInstanceImpl> site_instance = |
163 SiteInstanceImpl::CreateForURL(browser_context(), kUrl1); | 193 SiteInstanceImpl::CreateForURL(browser_context(), kUrl1); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // main RFH, as it was registered with the regular site URL when it committed. | 502 // main RFH, as it was registered with the regular site URL when it committed. |
473 main_test_rfh()->PrepareForCommit(); | 503 main_test_rfh()->PrepareForCommit(); |
474 main_test_rfh()->SendNavigate(0, true, kUrl); | 504 main_test_rfh()->SendNavigate(0, true, kUrl); |
475 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl); | 505 site_instance = SiteInstanceImpl::CreateForURL(browser_context(), kUrl); |
476 site_instance->set_process_reuse_policy( | 506 site_instance->set_process_reuse_policy( |
477 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); | 507 SiteInstanceImpl::ProcessReusePolicy::REUSE_PENDING_OR_COMMITTED_SITE); |
478 EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess()); | 508 EXPECT_EQ(main_test_rfh()->GetProcess(), site_instance->GetProcess()); |
479 } | 509 } |
480 | 510 |
481 } // namespace content | 511 } // namespace content |
OLD | NEW |