| 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 <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 8 #include "content/public/common/content_constants.h" | 7 #include "content/public/common/content_constants.h" |
| 9 #include "content/public/common/content_switches.h" | 8 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/mock_render_process_host.h" | 9 #include "content/public/test/mock_render_process_host.h" |
| 11 #include "content/test/test_render_view_host.h" | 10 #include "content/test/test_render_view_host.h" |
| 12 | 11 |
| 13 namespace content { | 12 namespace content { |
| 14 | 13 |
| 15 class RenderProcessHostUnitTest : public RenderViewHostTestHarness {}; | 14 class RenderProcessHostUnitTest : public RenderViewHostTestHarness {}; |
| 16 | 15 |
| 17 // Tests that guest RenderProcessHosts are not considered suitable hosts when | 16 // Tests that guest RenderProcessHosts are not considered suitable hosts when |
| 18 // searching for RenderProcessHost. | 17 // searching for RenderProcessHost. |
| 19 TEST_F(RenderProcessHostUnitTest, GuestsAreNotSuitableHosts) { | 18 TEST_F(RenderProcessHostUnitTest, GuestsAreNotSuitableHosts) { |
| 20 GURL test_url("http://foo.com"); | 19 GURL test_url("http://foo.com"); |
| 21 | 20 |
| 22 MockRenderProcessHost guest_host(browser_context()); | 21 MockRenderProcessHost guest_host(browser_context()); |
| 23 guest_host.set_is_for_guests_only(true); | 22 guest_host.set_is_for_guests_only(true); |
| 24 | 23 |
| 25 EXPECT_FALSE(RenderProcessHostImpl::IsSuitableHost( | 24 EXPECT_FALSE(RenderProcessHostImpl::IsSuitableHost( |
| 26 &guest_host, browser_context(), test_url)); | 25 &guest_host, browser_context(), test_url)); |
| 27 EXPECT_TRUE(RenderProcessHostImpl::IsSuitableHost( | 26 EXPECT_TRUE(RenderProcessHostImpl::IsSuitableHost( |
| 28 process(), browser_context(), test_url)); | 27 process(), browser_context(), test_url)); |
| 29 EXPECT_EQ( | 28 EXPECT_EQ( |
| 30 process(), | 29 process(), |
| 31 RenderProcessHost::GetExistingProcessHost(browser_context(), test_url)); | 30 RenderProcessHost::GetExistingProcessHost(browser_context(), test_url)); |
| 32 } | 31 } |
| 33 | 32 |
| 34 #if !defined(OS_ANDROID) | 33 #if !defined(OS_ANDROID) |
| 35 TEST_F(RenderProcessHostUnitTest, RendererProcessLimit) { | 34 TEST_F(RenderProcessHostUnitTest, RendererProcessLimit) { |
| 36 // This test shouldn't run with --site-per-process mode, which prohibits | 35 // This test shouldn't run with --site-per-process mode, which prohibits |
| 37 // the renderer process reuse this test explicitly exercises. | 36 // the renderer process reuse this test explicitly exercises. |
| 38 const base::CommandLine& command_line = | 37 if (AreAllSitesIsolatedForTesting()) |
| 39 *base::CommandLine::ForCurrentProcess(); | |
| 40 if (command_line.HasSwitch(switches::kSitePerProcess)) | |
| 41 return; | 38 return; |
| 42 | 39 |
| 43 // Disable any overrides. | 40 // Disable any overrides. |
| 44 RenderProcessHostImpl::SetMaxRendererProcessCount(0); | 41 RenderProcessHostImpl::SetMaxRendererProcessCount(0); |
| 45 | 42 |
| 46 // Verify that the limit is between 1 and kMaxRendererProcessCount. | 43 // Verify that the limit is between 1 and kMaxRendererProcessCount. |
| 47 EXPECT_GT(RenderProcessHostImpl::GetMaxRendererProcessCount(), 0u); | 44 EXPECT_GT(RenderProcessHostImpl::GetMaxRendererProcessCount(), 0u); |
| 48 EXPECT_LE(RenderProcessHostImpl::GetMaxRendererProcessCount(), | 45 EXPECT_LE(RenderProcessHostImpl::GetMaxRendererProcessCount(), |
| 49 kMaxRendererProcessCount); | 46 kMaxRendererProcessCount); |
| 50 | 47 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 79 } | 76 } |
| 80 | 77 |
| 81 // Verify that the renderer sharing still won't happen. | 78 // Verify that the renderer sharing still won't happen. |
| 82 GURL test_url("http://foo.com"); | 79 GURL test_url("http://foo.com"); |
| 83 EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( | 80 EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
| 84 browser_context(), test_url)); | 81 browser_context(), test_url)); |
| 85 } | 82 } |
| 86 #endif | 83 #endif |
| 87 | 84 |
| 88 } // namespace content | 85 } // namespace content |
| OLD | NEW |