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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 } | 555 } |
556 | 556 |
557 // Test to ensure that pages that require certain privileges are grouped | 557 // Test to ensure that pages that require certain privileges are grouped |
558 // in processes with similar pages. | 558 // in processes with similar pages. |
559 TEST_F(SiteInstanceTest, ProcessSharingByType) { | 559 TEST_F(SiteInstanceTest, ProcessSharingByType) { |
560 // This test shouldn't run with --site-per-process mode, since it doesn't | 560 // This test shouldn't run with --site-per-process mode, since it doesn't |
561 // allow render process reuse, which this test explicitly exercises. | 561 // allow render process reuse, which this test explicitly exercises. |
562 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) | 562 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) |
563 return; | 563 return; |
564 | 564 |
| 565 // On Android by default the number of renderer hosts is unlimited and process |
| 566 // sharing doesn't happen. We set the override so that the test can run |
| 567 // everywhere. |
| 568 RenderProcessHost::SetMaxRendererProcessCount(kMaxRendererProcessCount); |
| 569 |
565 ChildProcessSecurityPolicyImpl* policy = | 570 ChildProcessSecurityPolicyImpl* policy = |
566 ChildProcessSecurityPolicyImpl::GetInstance(); | 571 ChildProcessSecurityPolicyImpl::GetInstance(); |
567 | 572 |
568 // Make a bunch of mock renderers so that we hit the limit. | 573 // Make a bunch of mock renderers so that we hit the limit. |
569 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 574 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
570 ScopedVector<MockRenderProcessHost> hosts; | 575 ScopedVector<MockRenderProcessHost> hosts; |
571 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) | 576 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) |
572 hosts.push_back(new MockRenderProcessHost(browser_context.get())); | 577 hosts.push_back(new MockRenderProcessHost(browser_context.get())); |
573 | 578 |
574 // Create some extension instances and make sure they share a process. | 579 // Create some extension instances and make sure they share a process. |
(...skipping 25 matching lines...) Expand all Loading... |
600 | 605 |
601 // Make sure none of differing privilege processes are mixed. | 606 // Make sure none of differing privilege processes are mixed. |
602 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 607 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
603 | 608 |
604 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { | 609 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
605 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 610 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
606 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 611 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
607 } | 612 } |
608 | 613 |
609 DrainMessageLoops(); | 614 DrainMessageLoops(); |
| 615 |
| 616 // Disable the process limit override. |
| 617 RenderProcessHost::SetMaxRendererProcessCount(0u); |
610 } | 618 } |
611 | 619 |
612 // Test to ensure that HasWrongProcessForURL behaves properly for different | 620 // Test to ensure that HasWrongProcessForURL behaves properly for different |
613 // types of URLs. | 621 // types of URLs. |
614 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { | 622 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { |
615 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 623 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
616 scoped_ptr<RenderProcessHost> host; | 624 scoped_ptr<RenderProcessHost> host; |
617 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( | 625 scoped_refptr<SiteInstanceImpl> instance(static_cast<SiteInstanceImpl*>( |
618 SiteInstance::Create(browser_context.get()))); | 626 SiteInstance::Create(browser_context.get()))); |
619 | 627 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 765 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
758 host.reset(instance->GetProcess()); | 766 host.reset(instance->GetProcess()); |
759 | 767 |
760 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( | 768 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( |
761 browser_context.get(), GURL())); | 769 browser_context.get(), GURL())); |
762 | 770 |
763 DrainMessageLoops(); | 771 DrainMessageLoops(); |
764 } | 772 } |
765 | 773 |
766 } // namespace content | 774 } // namespace content |
OLD | NEW |