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 "content/browser/site_instance_impl.h" | 5 #include "content/browser/site_instance_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 }; | 146 }; |
147 | 147 |
148 // Test to ensure no memory leaks for SiteInstance objects. | 148 // Test to ensure no memory leaks for SiteInstance objects. |
149 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { | 149 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { |
150 // The existence of this object will cause WebContentsImpl to create our | 150 // The existence of this object will cause WebContentsImpl to create our |
151 // test one instead of the real one. | 151 // test one instead of the real one. |
152 RenderViewHostTestEnabler rvh_test_enabler; | 152 RenderViewHostTestEnabler rvh_test_enabler; |
153 const GURL url("test:foo"); | 153 const GURL url("test:foo"); |
154 | 154 |
155 // Ensure that instances are deleted when their NavigationEntries are gone. | 155 // Ensure that instances are deleted when their NavigationEntries are gone. |
156 scoped_refptr<SiteInstanceImpl> instance = SiteInstanceImpl::Create(nullptr); | 156 constexpr int child_process_param_id = 0; |
| 157 scoped_refptr<SiteInstanceImpl> instance = |
| 158 SiteInstanceImpl::Create(nullptr, child_process_param_id); |
157 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 159 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
158 | 160 |
159 NavigationEntryImpl* e1 = new NavigationEntryImpl( | 161 NavigationEntryImpl* e1 = new NavigationEntryImpl( |
160 instance, url, Referrer(), base::string16(), ui::PAGE_TRANSITION_LINK, | 162 instance, url, Referrer(), base::string16(), ui::PAGE_TRANSITION_LINK, |
161 false); | 163 false); |
162 | 164 |
163 // Redundantly setting e1's SiteInstance shouldn't affect the ref count. | 165 // Redundantly setting e1's SiteInstance shouldn't affect the ref count. |
164 e1->set_site_instance(instance); | 166 e1->set_site_instance(instance); |
165 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 167 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
166 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 168 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 205 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
204 // contents is now deleted, along with instance and browsing_instance | 206 // contents is now deleted, along with instance and browsing_instance |
205 } | 207 } |
206 | 208 |
207 // Test that NavigationEntries with SiteInstances can be cloned, but that their | 209 // Test that NavigationEntries with SiteInstances can be cloned, but that their |
208 // SiteInstances can be changed afterwards. Also tests that the ref counts are | 210 // SiteInstances can be changed afterwards. Also tests that the ref counts are |
209 // updated properly after the change. | 211 // updated properly after the change. |
210 TEST_F(SiteInstanceTest, CloneNavigationEntry) { | 212 TEST_F(SiteInstanceTest, CloneNavigationEntry) { |
211 const GURL url("test:foo"); | 213 const GURL url("test:foo"); |
212 | 214 |
| 215 constexpr int child_process_param_id = 0; |
213 std::unique_ptr<NavigationEntryImpl> e1 = | 216 std::unique_ptr<NavigationEntryImpl> e1 = |
214 base::WrapUnique(new NavigationEntryImpl( | 217 base::WrapUnique(new NavigationEntryImpl( |
215 SiteInstanceImpl::Create(nullptr), url, Referrer(), | 218 SiteInstanceImpl::Create(nullptr, child_process_param_id), url, |
216 base::string16(), ui::PAGE_TRANSITION_LINK, false)); | 219 Referrer(), base::string16(), ui::PAGE_TRANSITION_LINK, false)); |
217 | 220 |
218 // Clone the entry. | 221 // Clone the entry. |
219 std::unique_ptr<NavigationEntryImpl> e2 = e1->Clone(); | 222 std::unique_ptr<NavigationEntryImpl> e2 = e1->Clone(); |
220 | 223 |
221 // Should be able to change the SiteInstance of the cloned entry. | 224 // Should be able to change the SiteInstance of the cloned entry. |
222 e2->set_site_instance(SiteInstanceImpl::Create(nullptr)); | 225 e2->set_site_instance( |
| 226 SiteInstanceImpl::Create(nullptr, child_process_param_id)); |
223 | 227 |
224 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 228 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
225 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 229 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
226 | 230 |
227 // The first SiteInstance and BrowsingInstance should go away after resetting | 231 // The first SiteInstance and BrowsingInstance should go away after resetting |
228 // e1, since e2 should no longer be referencing it. | 232 // e1, since e2 should no longer be referencing it. |
229 e1.reset(); | 233 e1.reset(); |
230 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 234 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
231 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 235 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
232 | 236 |
233 // The second SiteInstance should go away after resetting e2. | 237 // The second SiteInstance should go away after resetting e2. |
234 e2.reset(); | 238 e2.reset(); |
235 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 239 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
236 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 240 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
237 | 241 |
238 DrainMessageLoop(); | 242 DrainMessageLoop(); |
239 } | 243 } |
240 | 244 |
241 // Test to ensure GetProcess returns and creates processes correctly. | 245 // Test to ensure GetProcess returns and creates processes correctly. |
242 TEST_F(SiteInstanceTest, GetProcess) { | 246 TEST_F(SiteInstanceTest, GetProcess) { |
243 // Ensure that GetProcess returns a process. | 247 // Ensure that GetProcess returns a process. |
244 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 248 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
245 std::unique_ptr<RenderProcessHost> host1; | 249 std::unique_ptr<RenderProcessHost> host1; |
| 250 constexpr int child_process_param_id = 0; |
246 scoped_refptr<SiteInstanceImpl> instance( | 251 scoped_refptr<SiteInstanceImpl> instance( |
247 SiteInstanceImpl::Create(browser_context.get())); | 252 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
248 host1.reset(instance->GetProcess()); | 253 host1.reset(instance->GetProcess()); |
249 EXPECT_TRUE(host1.get() != nullptr); | 254 EXPECT_TRUE(host1.get() != nullptr); |
250 | 255 |
251 // Ensure that GetProcess creates a new process. | 256 // Ensure that GetProcess creates a new process. |
252 scoped_refptr<SiteInstanceImpl> instance2( | 257 scoped_refptr<SiteInstanceImpl> instance2( |
253 SiteInstanceImpl::Create(browser_context.get())); | 258 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
254 std::unique_ptr<RenderProcessHost> host2(instance2->GetProcess()); | 259 std::unique_ptr<RenderProcessHost> host2(instance2->GetProcess()); |
255 EXPECT_TRUE(host2.get() != nullptr); | 260 EXPECT_TRUE(host2.get() != nullptr); |
256 EXPECT_NE(host1.get(), host2.get()); | 261 EXPECT_NE(host1.get(), host2.get()); |
257 | 262 |
258 DrainMessageLoop(); | 263 DrainMessageLoop(); |
259 } | 264 } |
260 | 265 |
261 // Test to ensure SetSite and site() work properly. | 266 // Test to ensure SetSite and site() work properly. |
262 TEST_F(SiteInstanceTest, SetSite) { | 267 TEST_F(SiteInstanceTest, SetSite) { |
263 scoped_refptr<SiteInstanceImpl> instance(SiteInstanceImpl::Create(nullptr)); | 268 constexpr int child_process_param_id = 0; |
| 269 scoped_refptr<SiteInstanceImpl> instance( |
| 270 SiteInstanceImpl::Create(nullptr, child_process_param_id)); |
264 EXPECT_FALSE(instance->HasSite()); | 271 EXPECT_FALSE(instance->HasSite()); |
265 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 272 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
266 | 273 |
267 instance->SetSite(GURL("http://www.google.com/index.html")); | 274 instance->SetSite(GURL("http://www.google.com/index.html")); |
268 EXPECT_EQ(GURL("http://google.com"), instance->GetSiteURL()); | 275 EXPECT_EQ(GURL("http://google.com"), instance->GetSiteURL()); |
269 | 276 |
270 EXPECT_TRUE(instance->HasSite()); | 277 EXPECT_TRUE(instance->HasSite()); |
271 | 278 |
272 DrainMessageLoop(); | 279 DrainMessageLoop(); |
273 } | 280 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 422 |
416 DrainMessageLoop(); | 423 DrainMessageLoop(); |
417 } | 424 } |
418 | 425 |
419 // Test to ensure that there is only one SiteInstance per site in a given | 426 // Test to ensure that there is only one SiteInstance per site in a given |
420 // BrowsingInstance, when process-per-site is not in use. | 427 // BrowsingInstance, when process-per-site is not in use. |
421 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 428 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
422 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 429 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
423 switches::kProcessPerSite)); | 430 switches::kProcessPerSite)); |
424 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 431 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 432 constexpr int child_process_param_id = 0; |
425 BrowsingInstance* browsing_instance = | 433 BrowsingInstance* browsing_instance = |
426 new BrowsingInstance(browser_context.get()); | 434 new BrowsingInstance(browser_context.get(), child_process_param_id); |
427 | 435 |
428 const GURL url_a1("http://www.google.com/1.html"); | 436 const GURL url_a1("http://www.google.com/1.html"); |
429 scoped_refptr<SiteInstanceImpl> site_instance_a1( | 437 scoped_refptr<SiteInstanceImpl> site_instance_a1( |
430 browsing_instance->GetSiteInstanceForURL(url_a1)); | 438 browsing_instance->GetSiteInstanceForURL(url_a1)); |
431 EXPECT_TRUE(site_instance_a1.get() != nullptr); | 439 EXPECT_TRUE(site_instance_a1.get() != nullptr); |
432 | 440 |
433 // A separate site should create a separate SiteInstance. | 441 // A separate site should create a separate SiteInstance. |
434 const GURL url_b1("http://www.yahoo.com/"); | 442 const GURL url_b1("http://www.yahoo.com/"); |
435 scoped_refptr<SiteInstanceImpl> site_instance_b1( | 443 scoped_refptr<SiteInstanceImpl> site_instance_b1( |
436 | 444 |
437 browsing_instance->GetSiteInstanceForURL(url_b1)); | 445 browsing_instance->GetSiteInstanceForURL(url_b1)); |
438 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); | 446 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); |
439 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1.get())); | 447 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1.get())); |
440 | 448 |
441 // Getting the new SiteInstance from the BrowsingInstance and from another | 449 // Getting the new SiteInstance from the BrowsingInstance and from another |
442 // SiteInstance in the BrowsingInstance should give the same result. | 450 // SiteInstance in the BrowsingInstance should give the same result. |
443 EXPECT_EQ(site_instance_b1.get(), | 451 EXPECT_EQ(site_instance_b1.get(), |
444 site_instance_a1->GetRelatedSiteInstance(url_b1)); | 452 site_instance_a1->GetRelatedSiteInstance(url_b1)); |
445 | 453 |
446 // A second visit to the original site should return the same SiteInstance. | 454 // A second visit to the original site should return the same SiteInstance. |
447 const GURL url_a2("http://www.google.com/2.html"); | 455 const GURL url_a2("http://www.google.com/2.html"); |
448 EXPECT_EQ(site_instance_a1.get(), | 456 EXPECT_EQ(site_instance_a1.get(), |
449 browsing_instance->GetSiteInstanceForURL(url_a2)); | 457 browsing_instance->GetSiteInstanceForURL(url_a2)); |
450 EXPECT_EQ(site_instance_a1.get(), | 458 EXPECT_EQ(site_instance_a1.get(), |
451 site_instance_a1->GetRelatedSiteInstance(url_a2)); | 459 site_instance_a1->GetRelatedSiteInstance(url_a2)); |
452 | 460 |
453 // A visit to the original site in a new BrowsingInstance (same or different | 461 // A visit to the original site in a new BrowsingInstance (same or different |
454 // browser context) should return a different SiteInstance. | 462 // browser context) should return a different SiteInstance. |
455 BrowsingInstance* browsing_instance2 = | 463 BrowsingInstance* browsing_instance2 = |
456 new BrowsingInstance(browser_context.get()); | 464 new BrowsingInstance(browser_context.get(), child_process_param_id); |
457 // Ensure the new SiteInstance is ref counted so that it gets deleted. | 465 // Ensure the new SiteInstance is ref counted so that it gets deleted. |
458 scoped_refptr<SiteInstanceImpl> site_instance_a2_2( | 466 scoped_refptr<SiteInstanceImpl> site_instance_a2_2( |
459 browsing_instance2->GetSiteInstanceForURL(url_a2)); | 467 browsing_instance2->GetSiteInstanceForURL(url_a2)); |
460 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); | 468 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); |
461 EXPECT_FALSE( | 469 EXPECT_FALSE( |
462 site_instance_a1->IsRelatedSiteInstance(site_instance_a2_2.get())); | 470 site_instance_a1->IsRelatedSiteInstance(site_instance_a2_2.get())); |
463 | 471 |
464 // The two SiteInstances for http://google.com should not use the same process | 472 // The two SiteInstances for http://google.com should not use the same process |
465 // if process-per-site is not enabled. | 473 // if process-per-site is not enabled. |
466 std::unique_ptr<RenderProcessHost> process_a1(site_instance_a1->GetProcess()); | 474 std::unique_ptr<RenderProcessHost> process_a1(site_instance_a1->GetProcess()); |
(...skipping 20 matching lines...) Expand all Loading... |
487 | 495 |
488 DrainMessageLoop(); | 496 DrainMessageLoop(); |
489 } | 497 } |
490 | 498 |
491 // Test to ensure that there is only one RenderProcessHost per site for an | 499 // Test to ensure that there is only one RenderProcessHost per site for an |
492 // entire BrowserContext, if process-per-site is in use. | 500 // entire BrowserContext, if process-per-site is in use. |
493 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { | 501 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { |
494 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 502 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
495 switches::kProcessPerSite); | 503 switches::kProcessPerSite); |
496 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 504 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 505 constexpr int child_process_param_id = 0; |
497 scoped_refptr<BrowsingInstance> browsing_instance = | 506 scoped_refptr<BrowsingInstance> browsing_instance = |
498 new BrowsingInstance(browser_context.get()); | 507 new BrowsingInstance(browser_context.get(), child_process_param_id); |
499 | 508 |
500 const GURL url_a1("http://www.google.com/1.html"); | 509 const GURL url_a1("http://www.google.com/1.html"); |
501 scoped_refptr<SiteInstanceImpl> site_instance_a1( | 510 scoped_refptr<SiteInstanceImpl> site_instance_a1( |
502 browsing_instance->GetSiteInstanceForURL(url_a1)); | 511 browsing_instance->GetSiteInstanceForURL(url_a1)); |
503 EXPECT_TRUE(site_instance_a1.get() != nullptr); | 512 EXPECT_TRUE(site_instance_a1.get() != nullptr); |
504 std::unique_ptr<RenderProcessHost> process_a1(site_instance_a1->GetProcess()); | 513 std::unique_ptr<RenderProcessHost> process_a1(site_instance_a1->GetProcess()); |
505 | 514 |
506 // A separate site should create a separate SiteInstance. | 515 // A separate site should create a separate SiteInstance. |
507 const GURL url_b1("http://www.yahoo.com/"); | 516 const GURL url_b1("http://www.yahoo.com/"); |
508 scoped_refptr<SiteInstanceImpl> site_instance_b1( | 517 scoped_refptr<SiteInstanceImpl> site_instance_b1( |
509 browsing_instance->GetSiteInstanceForURL(url_b1)); | 518 browsing_instance->GetSiteInstanceForURL(url_b1)); |
510 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); | 519 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); |
511 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1.get())); | 520 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1.get())); |
512 | 521 |
513 // Getting the new SiteInstance from the BrowsingInstance and from another | 522 // Getting the new SiteInstance from the BrowsingInstance and from another |
514 // SiteInstance in the BrowsingInstance should give the same result. | 523 // SiteInstance in the BrowsingInstance should give the same result. |
515 EXPECT_EQ(site_instance_b1.get(), | 524 EXPECT_EQ(site_instance_b1.get(), |
516 site_instance_a1->GetRelatedSiteInstance(url_b1)); | 525 site_instance_a1->GetRelatedSiteInstance(url_b1)); |
517 | 526 |
518 // A second visit to the original site should return the same SiteInstance. | 527 // A second visit to the original site should return the same SiteInstance. |
519 const GURL url_a2("http://www.google.com/2.html"); | 528 const GURL url_a2("http://www.google.com/2.html"); |
520 EXPECT_EQ(site_instance_a1.get(), | 529 EXPECT_EQ(site_instance_a1.get(), |
521 browsing_instance->GetSiteInstanceForURL(url_a2)); | 530 browsing_instance->GetSiteInstanceForURL(url_a2)); |
522 EXPECT_EQ(site_instance_a1.get(), | 531 EXPECT_EQ(site_instance_a1.get(), |
523 site_instance_a1->GetRelatedSiteInstance(url_a2)); | 532 site_instance_a1->GetRelatedSiteInstance(url_a2)); |
524 | 533 |
525 // A visit to the original site in a new BrowsingInstance (same browser | 534 // A visit to the original site in a new BrowsingInstance (same browser |
526 // context) should return a different SiteInstance with the same process. | 535 // context) should return a different SiteInstance with the same process. |
527 BrowsingInstance* browsing_instance2 = | 536 BrowsingInstance* browsing_instance2 = |
528 new BrowsingInstance(browser_context.get()); | 537 new BrowsingInstance(browser_context.get(), child_process_param_id); |
529 scoped_refptr<SiteInstanceImpl> site_instance_a1_2( | 538 scoped_refptr<SiteInstanceImpl> site_instance_a1_2( |
530 browsing_instance2->GetSiteInstanceForURL(url_a1)); | 539 browsing_instance2->GetSiteInstanceForURL(url_a1)); |
531 EXPECT_TRUE(site_instance_a1.get() != nullptr); | 540 EXPECT_TRUE(site_instance_a1.get() != nullptr); |
532 EXPECT_NE(site_instance_a1.get(), site_instance_a1_2.get()); | 541 EXPECT_NE(site_instance_a1.get(), site_instance_a1_2.get()); |
533 EXPECT_EQ(process_a1.get(), site_instance_a1_2->GetProcess()); | 542 EXPECT_EQ(process_a1.get(), site_instance_a1_2->GetProcess()); |
534 | 543 |
535 // A visit to the original site in a new BrowsingInstance (different browser | 544 // A visit to the original site in a new BrowsingInstance (different browser |
536 // context) should return a different SiteInstance with a different process. | 545 // context) should return a different SiteInstance with a different process. |
537 std::unique_ptr<TestBrowserContext> browser_context2( | 546 std::unique_ptr<TestBrowserContext> browser_context2( |
538 new TestBrowserContext()); | 547 new TestBrowserContext()); |
539 BrowsingInstance* browsing_instance3 = | 548 BrowsingInstance* browsing_instance3 = |
540 new BrowsingInstance(browser_context2.get()); | 549 new BrowsingInstance(browser_context2.get(), child_process_param_id); |
541 scoped_refptr<SiteInstanceImpl> site_instance_a2_3( | 550 scoped_refptr<SiteInstanceImpl> site_instance_a2_3( |
542 browsing_instance3->GetSiteInstanceForURL(url_a2)); | 551 browsing_instance3->GetSiteInstanceForURL(url_a2)); |
543 EXPECT_TRUE(site_instance_a2_3.get() != nullptr); | 552 EXPECT_TRUE(site_instance_a2_3.get() != nullptr); |
544 std::unique_ptr<RenderProcessHost> process_a2_3( | 553 std::unique_ptr<RenderProcessHost> process_a2_3( |
545 site_instance_a2_3->GetProcess()); | 554 site_instance_a2_3->GetProcess()); |
546 EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); | 555 EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); |
547 EXPECT_NE(process_a1.get(), process_a2_3.get()); | 556 EXPECT_NE(process_a1.get(), process_a2_3.get()); |
548 | 557 |
549 // Should be able to see that we do have SiteInstances. | 558 // Should be able to see that we do have SiteInstances. |
550 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 559 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
(...skipping 13 matching lines...) Expand all Loading... |
564 | 573 |
565 // browsing_instances will be deleted when their SiteInstances are deleted. | 574 // browsing_instances will be deleted when their SiteInstances are deleted. |
566 // The processes will be unregistered when the RPH scoped_ptrs go away. | 575 // The processes will be unregistered when the RPH scoped_ptrs go away. |
567 | 576 |
568 DrainMessageLoop(); | 577 DrainMessageLoop(); |
569 } | 578 } |
570 | 579 |
571 static scoped_refptr<SiteInstanceImpl> CreateSiteInstance( | 580 static scoped_refptr<SiteInstanceImpl> CreateSiteInstance( |
572 BrowserContext* browser_context, | 581 BrowserContext* browser_context, |
573 const GURL& url) { | 582 const GURL& url) { |
574 return SiteInstanceImpl::CreateForURL(browser_context, url); | 583 constexpr int child_process_param_id = 0; |
| 584 return SiteInstanceImpl::CreateForURL(browser_context, url, |
| 585 child_process_param_id); |
575 } | 586 } |
576 | 587 |
577 // Test to ensure that pages that require certain privileges are grouped | 588 // Test to ensure that pages that require certain privileges are grouped |
578 // in processes with similar pages. | 589 // in processes with similar pages. |
579 TEST_F(SiteInstanceTest, ProcessSharingByType) { | 590 TEST_F(SiteInstanceTest, ProcessSharingByType) { |
580 // This test shouldn't run with --site-per-process mode, which prohibits | 591 // This test shouldn't run with --site-per-process mode, which prohibits |
581 // the renderer process reuse this test explicitly exercises. | 592 // the renderer process reuse this test explicitly exercises. |
582 if (AreAllSitesIsolatedForTesting()) | 593 if (AreAllSitesIsolatedForTesting()) |
583 return; | 594 return; |
584 | 595 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 646 |
636 // Disable the process limit override. | 647 // Disable the process limit override. |
637 RenderProcessHost::SetMaxRendererProcessCount(0u); | 648 RenderProcessHost::SetMaxRendererProcessCount(0u); |
638 } | 649 } |
639 | 650 |
640 // Test to ensure that HasWrongProcessForURL behaves properly for different | 651 // Test to ensure that HasWrongProcessForURL behaves properly for different |
641 // types of URLs. | 652 // types of URLs. |
642 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { | 653 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { |
643 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 654 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
644 std::unique_ptr<RenderProcessHost> host; | 655 std::unique_ptr<RenderProcessHost> host; |
| 656 constexpr int child_process_param_id = 0; |
645 scoped_refptr<SiteInstanceImpl> instance( | 657 scoped_refptr<SiteInstanceImpl> instance( |
646 SiteInstanceImpl::Create(browser_context.get())); | 658 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
647 | 659 |
648 EXPECT_FALSE(instance->HasSite()); | 660 EXPECT_FALSE(instance->HasSite()); |
649 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 661 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
650 | 662 |
651 instance->SetSite(GURL("http://evernote.com/")); | 663 instance->SetSite(GURL("http://evernote.com/")); |
652 EXPECT_TRUE(instance->HasSite()); | 664 EXPECT_TRUE(instance->HasSite()); |
653 | 665 |
654 // Check prior to "assigning" a process to the instance, which is expected | 666 // Check prior to "assigning" a process to the instance, which is expected |
655 // to return false due to not being attached to any process yet. | 667 // to return false due to not being attached to any process yet. |
656 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://google.com"))); | 668 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://google.com"))); |
657 | 669 |
658 // The call to GetProcess actually creates a new real process, which works | 670 // The call to GetProcess actually creates a new real process, which works |
659 // fine, but might be a cause for problems in different contexts. | 671 // fine, but might be a cause for problems in different contexts. |
660 host.reset(instance->GetProcess()); | 672 host.reset(instance->GetProcess()); |
661 EXPECT_TRUE(host.get() != nullptr); | 673 EXPECT_TRUE(host.get() != nullptr); |
662 EXPECT_TRUE(instance->HasProcess()); | 674 EXPECT_TRUE(instance->HasProcess()); |
663 | 675 |
664 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); | 676 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); |
665 EXPECT_FALSE(instance->HasWrongProcessForURL( | 677 EXPECT_FALSE(instance->HasWrongProcessForURL( |
666 GURL("javascript:alert(document.location.href);"))); | 678 GURL("javascript:alert(document.location.href);"))); |
667 | 679 |
668 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://gpu"))); | 680 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://gpu"))); |
669 | 681 |
670 // Test that WebUI SiteInstances reject normal web URLs. | 682 // Test that WebUI SiteInstances reject normal web URLs. |
671 const GURL webui_url("chrome://gpu"); | 683 const GURL webui_url("chrome://gpu"); |
672 scoped_refptr<SiteInstanceImpl> webui_instance( | 684 scoped_refptr<SiteInstanceImpl> webui_instance( |
673 SiteInstanceImpl::Create(browser_context.get())); | 685 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
674 webui_instance->SetSite(webui_url); | 686 webui_instance->SetSite(webui_url); |
675 std::unique_ptr<RenderProcessHost> webui_host(webui_instance->GetProcess()); | 687 std::unique_ptr<RenderProcessHost> webui_host(webui_instance->GetProcess()); |
676 | 688 |
677 // Simulate granting WebUI bindings for the process. | 689 // Simulate granting WebUI bindings for the process. |
678 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings( | 690 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings( |
679 webui_host->GetID()); | 691 webui_host->GetID()); |
680 | 692 |
681 EXPECT_TRUE(webui_instance->HasProcess()); | 693 EXPECT_TRUE(webui_instance->HasProcess()); |
682 EXPECT_FALSE(webui_instance->HasWrongProcessForURL(webui_url)); | 694 EXPECT_FALSE(webui_instance->HasWrongProcessForURL(webui_url)); |
683 EXPECT_TRUE(webui_instance->HasWrongProcessForURL(GURL("http://google.com"))); | 695 EXPECT_TRUE(webui_instance->HasWrongProcessForURL(GURL("http://google.com"))); |
684 EXPECT_TRUE(webui_instance->HasWrongProcessForURL(GURL("http://gpu"))); | 696 EXPECT_TRUE(webui_instance->HasWrongProcessForURL(GURL("http://gpu"))); |
685 | 697 |
686 // WebUI uses process-per-site, so another instance will use the same process | 698 // WebUI uses process-per-site, so another instance will use the same process |
687 // even if we haven't called GetProcess yet. Make sure HasWrongProcessForURL | 699 // even if we haven't called GetProcess yet. Make sure HasWrongProcessForURL |
688 // doesn't crash (http://crbug.com/137070). | 700 // doesn't crash (http://crbug.com/137070). |
689 scoped_refptr<SiteInstanceImpl> webui_instance2( | 701 scoped_refptr<SiteInstanceImpl> webui_instance2( |
690 SiteInstanceImpl::Create(browser_context.get())); | 702 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
691 webui_instance2->SetSite(webui_url); | 703 webui_instance2->SetSite(webui_url); |
692 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); | 704 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); |
693 EXPECT_TRUE( | 705 EXPECT_TRUE( |
694 webui_instance2->HasWrongProcessForURL(GURL("http://google.com"))); | 706 webui_instance2->HasWrongProcessForURL(GURL("http://google.com"))); |
695 | 707 |
696 DrainMessageLoop(); | 708 DrainMessageLoop(); |
697 } | 709 } |
698 | 710 |
699 // Test to ensure that HasWrongProcessForURL behaves properly even when | 711 // Test to ensure that HasWrongProcessForURL behaves properly even when |
700 // --site-per-process is used (http://crbug.com/160671). | 712 // --site-per-process is used (http://crbug.com/160671). |
701 TEST_F(SiteInstanceTest, HasWrongProcessForURLInSitePerProcess) { | 713 TEST_F(SiteInstanceTest, HasWrongProcessForURLInSitePerProcess) { |
702 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess()); | 714 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess()); |
703 | 715 |
704 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 716 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
705 std::unique_ptr<RenderProcessHost> host; | 717 std::unique_ptr<RenderProcessHost> host; |
| 718 constexpr int child_process_param_id = 0; |
706 scoped_refptr<SiteInstanceImpl> instance( | 719 scoped_refptr<SiteInstanceImpl> instance( |
707 SiteInstanceImpl::Create(browser_context.get())); | 720 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
708 | 721 |
709 instance->SetSite(GURL("http://evernote.com/")); | 722 instance->SetSite(GURL("http://evernote.com/")); |
710 EXPECT_TRUE(instance->HasSite()); | 723 EXPECT_TRUE(instance->HasSite()); |
711 | 724 |
712 // Check prior to "assigning" a process to the instance, which is expected | 725 // Check prior to "assigning" a process to the instance, which is expected |
713 // to return false due to not being attached to any process yet. | 726 // to return false due to not being attached to any process yet. |
714 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://google.com"))); | 727 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://google.com"))); |
715 | 728 |
716 // The call to GetProcess actually creates a new real process, which works | 729 // The call to GetProcess actually creates a new real process, which works |
717 // fine, but might be a cause for problems in different contexts. | 730 // fine, but might be a cause for problems in different contexts. |
718 host.reset(instance->GetProcess()); | 731 host.reset(instance->GetProcess()); |
719 EXPECT_TRUE(host.get() != nullptr); | 732 EXPECT_TRUE(host.get() != nullptr); |
720 EXPECT_TRUE(instance->HasProcess()); | 733 EXPECT_TRUE(instance->HasProcess()); |
721 | 734 |
722 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); | 735 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); |
723 EXPECT_FALSE(instance->HasWrongProcessForURL( | 736 EXPECT_FALSE(instance->HasWrongProcessForURL( |
724 GURL("javascript:alert(document.location.href);"))); | 737 GURL("javascript:alert(document.location.href);"))); |
725 | 738 |
726 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://gpu"))); | 739 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://gpu"))); |
727 | 740 |
728 DrainMessageLoop(); | 741 DrainMessageLoop(); |
729 } | 742 } |
730 | 743 |
731 // Test that we do not reuse a process in process-per-site mode if it has the | 744 // Test that we do not reuse a process in process-per-site mode if it has the |
732 // wrong bindings for its URL. http://crbug.com/174059. | 745 // wrong bindings for its URL. http://crbug.com/174059. |
733 TEST_F(SiteInstanceTest, ProcessPerSiteWithWrongBindings) { | 746 TEST_F(SiteInstanceTest, ProcessPerSiteWithWrongBindings) { |
734 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 747 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
735 std::unique_ptr<RenderProcessHost> host; | 748 std::unique_ptr<RenderProcessHost> host; |
736 std::unique_ptr<RenderProcessHost> host2; | 749 std::unique_ptr<RenderProcessHost> host2; |
| 750 constexpr int child_process_param_id = 0; |
737 scoped_refptr<SiteInstanceImpl> instance( | 751 scoped_refptr<SiteInstanceImpl> instance( |
738 SiteInstanceImpl::Create(browser_context.get())); | 752 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
739 | 753 |
740 EXPECT_FALSE(instance->HasSite()); | 754 EXPECT_FALSE(instance->HasSite()); |
741 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 755 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
742 | 756 |
743 // Simulate navigating to a WebUI URL in a process that does not have WebUI | 757 // Simulate navigating to a WebUI URL in a process that does not have WebUI |
744 // bindings. This already requires bypassing security checks. | 758 // bindings. This already requires bypassing security checks. |
745 const GURL webui_url("chrome://gpu"); | 759 const GURL webui_url("chrome://gpu"); |
746 instance->SetSite(webui_url); | 760 instance->SetSite(webui_url); |
747 EXPECT_TRUE(instance->HasSite()); | 761 EXPECT_TRUE(instance->HasSite()); |
748 | 762 |
749 // The call to GetProcess actually creates a new real process. | 763 // The call to GetProcess actually creates a new real process. |
750 host.reset(instance->GetProcess()); | 764 host.reset(instance->GetProcess()); |
751 EXPECT_TRUE(host.get() != nullptr); | 765 EXPECT_TRUE(host.get() != nullptr); |
752 EXPECT_TRUE(instance->HasProcess()); | 766 EXPECT_TRUE(instance->HasProcess()); |
753 | 767 |
754 // Without bindings, this should look like the wrong process. | 768 // Without bindings, this should look like the wrong process. |
755 EXPECT_TRUE(instance->HasWrongProcessForURL(webui_url)); | 769 EXPECT_TRUE(instance->HasWrongProcessForURL(webui_url)); |
756 | 770 |
757 // WebUI uses process-per-site, so another instance would normally use the | 771 // WebUI uses process-per-site, so another instance would normally use the |
758 // same process. Make sure it doesn't use the same process if the bindings | 772 // same process. Make sure it doesn't use the same process if the bindings |
759 // are missing. | 773 // are missing. |
760 scoped_refptr<SiteInstanceImpl> instance2( | 774 scoped_refptr<SiteInstanceImpl> instance2( |
761 SiteInstanceImpl::Create(browser_context.get())); | 775 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
762 instance2->SetSite(webui_url); | 776 instance2->SetSite(webui_url); |
763 host2.reset(instance2->GetProcess()); | 777 host2.reset(instance2->GetProcess()); |
764 EXPECT_TRUE(host2.get() != nullptr); | 778 EXPECT_TRUE(host2.get() != nullptr); |
765 EXPECT_TRUE(instance2->HasProcess()); | 779 EXPECT_TRUE(instance2->HasProcess()); |
766 EXPECT_NE(host.get(), host2.get()); | 780 EXPECT_NE(host.get(), host2.get()); |
767 | 781 |
768 DrainMessageLoop(); | 782 DrainMessageLoop(); |
769 } | 783 } |
770 | 784 |
771 // Test that we do not register processes with empty sites for process-per-site | 785 // Test that we do not register processes with empty sites for process-per-site |
772 // mode. | 786 // mode. |
773 TEST_F(SiteInstanceTest, NoProcessPerSiteForEmptySite) { | 787 TEST_F(SiteInstanceTest, NoProcessPerSiteForEmptySite) { |
774 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 788 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
775 switches::kProcessPerSite); | 789 switches::kProcessPerSite); |
776 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 790 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
777 std::unique_ptr<RenderProcessHost> host; | 791 std::unique_ptr<RenderProcessHost> host; |
| 792 constexpr int child_process_param_id = 0; |
778 scoped_refptr<SiteInstanceImpl> instance( | 793 scoped_refptr<SiteInstanceImpl> instance( |
779 SiteInstanceImpl::Create(browser_context.get())); | 794 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id)); |
780 | 795 |
781 instance->SetSite(GURL()); | 796 instance->SetSite(GURL()); |
782 EXPECT_TRUE(instance->HasSite()); | 797 EXPECT_TRUE(instance->HasSite()); |
783 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 798 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
784 host.reset(instance->GetProcess()); | 799 host.reset(instance->GetProcess()); |
785 | 800 |
786 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( | 801 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( |
787 browser_context.get(), GURL())); | 802 browser_context.get(), GURL())); |
788 | 803 |
789 DrainMessageLoop(); | 804 DrainMessageLoop(); |
790 } | 805 } |
791 | 806 |
792 TEST_F(SiteInstanceTest, DefaultSubframeSiteInstance) { | 807 TEST_F(SiteInstanceTest, DefaultSubframeSiteInstance) { |
793 if (AreAllSitesIsolatedForTesting()) | 808 if (AreAllSitesIsolatedForTesting()) |
794 return; // --top-document-isolation is not possible. | 809 return; // --top-document-isolation is not possible. |
795 | 810 |
796 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 811 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
797 switches::kTopDocumentIsolation); | 812 switches::kTopDocumentIsolation); |
798 | 813 |
799 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 814 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 815 constexpr int child_process_param_id = 0; |
800 scoped_refptr<SiteInstanceImpl> main_instance = | 816 scoped_refptr<SiteInstanceImpl> main_instance = |
801 SiteInstanceImpl::Create(browser_context.get()); | 817 SiteInstanceImpl::Create(browser_context.get(), child_process_param_id); |
802 scoped_refptr<SiteInstanceImpl> subframe_instance = | 818 scoped_refptr<SiteInstanceImpl> subframe_instance = |
803 main_instance->GetDefaultSubframeSiteInstance(); | 819 main_instance->GetDefaultSubframeSiteInstance(); |
804 int subframe_instance_id = subframe_instance->GetId(); | 820 int subframe_instance_id = subframe_instance->GetId(); |
805 | 821 |
806 EXPECT_NE(main_instance, subframe_instance); | 822 EXPECT_NE(main_instance, subframe_instance); |
807 EXPECT_EQ(subframe_instance, main_instance->GetDefaultSubframeSiteInstance()); | 823 EXPECT_EQ(subframe_instance, main_instance->GetDefaultSubframeSiteInstance()); |
808 EXPECT_FALSE(main_instance->IsDefaultSubframeSiteInstance()); | 824 EXPECT_FALSE(main_instance->IsDefaultSubframeSiteInstance()); |
809 EXPECT_TRUE(subframe_instance->IsDefaultSubframeSiteInstance()); | 825 EXPECT_TRUE(subframe_instance->IsDefaultSubframeSiteInstance()); |
810 | 826 |
811 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 827 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
(...skipping 20 matching lines...) Expand all Loading... |
832 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 848 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
833 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 849 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
834 | 850 |
835 // Free the subframe instance, which should free the browsing instance. | 851 // Free the subframe instance, which should free the browsing instance. |
836 subframe_instance = nullptr; | 852 subframe_instance = nullptr; |
837 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 853 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
838 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 854 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
839 } | 855 } |
840 | 856 |
841 } // namespace content | 857 } // namespace content |
OLD | NEW |