| 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 "content/public/common/content_constants.h" |
| 5 #include "content/public/test/mock_render_process_host.h" | 6 #include "content/public/test/mock_render_process_host.h" |
| 6 #include "content/test/test_render_view_host.h" | 7 #include "content/test/test_render_view_host.h" |
| 7 | 8 |
| 8 namespace content { | 9 namespace content { |
| 9 | 10 |
| 10 class RenderProcessHostUnitTest : public RenderViewHostTestHarness {}; | 11 class RenderProcessHostUnitTest : public RenderViewHostTestHarness {}; |
| 11 | 12 |
| 12 // Tests that guest RenderProcessHosts are not considered suitable hosts when | 13 // Tests that guest RenderProcessHosts are not considered suitable hosts when |
| 13 // searching for RenderProcessHost. | 14 // searching for RenderProcessHost. |
| 14 TEST_F(RenderProcessHostUnitTest, GuestsAreNotSuitableHosts) { | 15 TEST_F(RenderProcessHostUnitTest, GuestsAreNotSuitableHosts) { |
| 15 GURL test_url("http://foo.com"); | 16 GURL test_url("http://foo.com"); |
| 16 | 17 |
| 17 MockRenderProcessHost guest_host(browser_context()); | 18 MockRenderProcessHost guest_host(browser_context()); |
| 18 guest_host.set_is_isolated_guest(true); | 19 guest_host.set_is_isolated_guest(true); |
| 19 | 20 |
| 20 EXPECT_FALSE(RenderProcessHostImpl::IsSuitableHost( | 21 EXPECT_FALSE(RenderProcessHostImpl::IsSuitableHost( |
| 21 &guest_host, browser_context(), test_url)); | 22 &guest_host, browser_context(), test_url)); |
| 22 EXPECT_TRUE(RenderProcessHostImpl::IsSuitableHost( | 23 EXPECT_TRUE(RenderProcessHostImpl::IsSuitableHost( |
| 23 process(), browser_context(), test_url)); | 24 process(), browser_context(), test_url)); |
| 24 EXPECT_EQ( | 25 EXPECT_EQ( |
| 25 process(), | 26 process(), |
| 26 RenderProcessHost::GetExistingProcessHost(browser_context(), test_url)); | 27 RenderProcessHost::GetExistingProcessHost(browser_context(), test_url)); |
| 27 } | 28 } |
| 28 | 29 |
| 30 #if defined(OS_ANDROID) |
| 31 TEST_F(RenderProcessHostUnitTest, NoRendererProcessLimitOnAndroid) { |
| 32 // Disable any overrides. |
| 33 RenderProcessHostImpl::SetMaxRendererProcessCount(0); |
| 34 |
| 35 // Verify that by default the limit on Android returns 0u, meaning there is no |
| 36 // limit. |
| 37 EXPECT_EQ(0u, RenderProcessHostImpl::GetMaxRendererProcessCount()); |
| 38 |
| 39 // Add a few dummy process hosts. |
| 40 ASSERT_NE(0u, kMaxRendererProcessCount); |
| 41 ScopedVector<MockRenderProcessHost> hosts; |
| 42 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
| 43 hosts.push_back(new MockRenderProcessHost(browser_context())); |
| 44 } |
| 45 |
| 46 // Verify that the renderer sharing still won't happen. |
| 47 GURL test_url("http://foo.com"); |
| 48 EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
| 49 browser_context(), test_url)); |
| 50 } |
| 51 #endif |
| 52 |
| 53 #if !defined(OS_ANDROID) |
| 54 TEST_F(RenderProcessHostUnitTest, RendererProcessLimit) { |
| 55 // Disable any overrides. |
| 56 RenderProcessHostImpl::SetMaxRendererProcessCount(0); |
| 57 |
| 58 // Verify that the limit is between 1 and kMaxRendererProcessCount. |
| 59 EXPECT_GT(RenderProcessHostImpl::GetMaxRendererProcessCount(), 0u); |
| 60 EXPECT_LE(RenderProcessHostImpl::GetMaxRendererProcessCount(), |
| 61 kMaxRendererProcessCount); |
| 62 |
| 63 // Add dummy process hosts to saturate the limit. |
| 64 ASSERT_NE(0u, kMaxRendererProcessCount); |
| 65 ScopedVector<MockRenderProcessHost> hosts; |
| 66 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
| 67 hosts.push_back(new MockRenderProcessHost(browser_context())); |
| 68 } |
| 69 |
| 70 // Verify that the renderer sharing will happen. |
| 71 GURL test_url("http://foo.com"); |
| 72 EXPECT_TRUE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
| 73 browser_context(), test_url)); |
| 74 } |
| 75 #endif |
| 76 |
| 29 } // namespace content | 77 } // namespace content |
| OLD | NEW |