chrome/browser/extensions: Remove use of MessageLoopProxy and deprecated MessageLoop...
[chromium-blink-merge.git] / content / browser / renderer_host / render_process_host_unittest.cc
blob83aa6b2273e6101082c77fb2333621c348697861
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
3 // found in the LICENSE file.
5 #include <limits>
7 #include "base/command_line.h"
8 #include "content/public/common/content_constants.h"
9 #include "content/public/common/content_switches.h"
10 #include "content/public/test/mock_render_process_host.h"
11 #include "content/test/test_render_view_host.h"
13 namespace content {
15 class RenderProcessHostUnitTest : public RenderViewHostTestHarness {};
17 // Tests that guest RenderProcessHosts are not considered suitable hosts when
18 // searching for RenderProcessHost.
19 TEST_F(RenderProcessHostUnitTest, GuestsAreNotSuitableHosts) {
20 GURL test_url("http://foo.com");
22 MockRenderProcessHost guest_host(browser_context());
23 guest_host.set_is_isolated_guest(true);
25 EXPECT_FALSE(RenderProcessHostImpl::IsSuitableHost(
26 &guest_host, browser_context(), test_url));
27 EXPECT_TRUE(RenderProcessHostImpl::IsSuitableHost(
28 process(), browser_context(), test_url));
29 EXPECT_EQ(
30 process(),
31 RenderProcessHost::GetExistingProcessHost(browser_context(), test_url));
34 #if !defined(OS_ANDROID)
35 TEST_F(RenderProcessHostUnitTest, RendererProcessLimit) {
36 // This test shouldn't run with --site-per-process mode, which prohibits
37 // the renderer process reuse this test explicitly exercises.
38 const base::CommandLine& command_line =
39 *base::CommandLine::ForCurrentProcess();
40 if (command_line.HasSwitch(switches::kSitePerProcess))
41 return;
43 // Disable any overrides.
44 RenderProcessHostImpl::SetMaxRendererProcessCount(0);
46 // Verify that the limit is between 1 and kMaxRendererProcessCount.
47 EXPECT_GT(RenderProcessHostImpl::GetMaxRendererProcessCount(), 0u);
48 EXPECT_LE(RenderProcessHostImpl::GetMaxRendererProcessCount(),
49 kMaxRendererProcessCount);
51 // Add dummy process hosts to saturate the limit.
52 ASSERT_NE(0u, kMaxRendererProcessCount);
53 ScopedVector<MockRenderProcessHost> hosts;
54 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) {
55 hosts.push_back(new MockRenderProcessHost(browser_context()));
58 // Verify that the renderer sharing will happen.
59 GURL test_url("http://foo.com");
60 EXPECT_TRUE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost(
61 browser_context(), test_url));
63 #endif
65 #if defined(OS_ANDROID)
66 TEST_F(RenderProcessHostUnitTest, NoRendererProcessLimitOnAndroid) {
67 // Disable any overrides.
68 RenderProcessHostImpl::SetMaxRendererProcessCount(0);
70 // Verify that by default the limit on Android returns max size_t.
71 EXPECT_EQ(std::numeric_limits<size_t>::max(),
72 RenderProcessHostImpl::GetMaxRendererProcessCount());
74 // Add a few dummy process hosts.
75 ASSERT_NE(0u, kMaxRendererProcessCount);
76 ScopedVector<MockRenderProcessHost> hosts;
77 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) {
78 hosts.push_back(new MockRenderProcessHost(browser_context()));
81 // Verify that the renderer sharing still won't happen.
82 GURL test_url("http://foo.com");
83 EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost(
84 browser_context(), test_url));
86 #endif
88 } // namespace content