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.
7 #include "content/public/common/content_constants.h"
8 #include "content/public/test/mock_render_process_host.h"
9 #include "content/public/test/test_utils.h"
10 #include "content/test/test_render_view_host.h"
14 class RenderProcessHostUnitTest
: public RenderViewHostTestHarness
{};
16 // Tests that guest RenderProcessHosts are not considered suitable hosts when
17 // searching for RenderProcessHost.
18 TEST_F(RenderProcessHostUnitTest
, GuestsAreNotSuitableHosts
) {
19 GURL
test_url("http://foo.com");
21 MockRenderProcessHost
guest_host(browser_context());
22 guest_host
.set_is_for_guests_only(true);
24 EXPECT_FALSE(RenderProcessHostImpl::IsSuitableHost(
25 &guest_host
, browser_context(), test_url
));
26 EXPECT_TRUE(RenderProcessHostImpl::IsSuitableHost(
27 process(), browser_context(), test_url
));
30 RenderProcessHost::GetExistingProcessHost(browser_context(), test_url
));
33 #if !defined(OS_ANDROID)
34 TEST_F(RenderProcessHostUnitTest
, RendererProcessLimit
) {
35 // This test shouldn't run with --site-per-process mode, which prohibits
36 // the renderer process reuse this test explicitly exercises.
37 if (AreAllSitesIsolatedForTesting())
40 // Disable any overrides.
41 RenderProcessHostImpl::SetMaxRendererProcessCount(0);
43 // Verify that the limit is between 1 and kMaxRendererProcessCount.
44 EXPECT_GT(RenderProcessHostImpl::GetMaxRendererProcessCount(), 0u);
45 EXPECT_LE(RenderProcessHostImpl::GetMaxRendererProcessCount(),
46 kMaxRendererProcessCount
);
48 // Add dummy process hosts to saturate the limit.
49 ASSERT_NE(0u, kMaxRendererProcessCount
);
50 ScopedVector
<MockRenderProcessHost
> hosts
;
51 for (size_t i
= 0; i
< kMaxRendererProcessCount
; ++i
) {
52 hosts
.push_back(new MockRenderProcessHost(browser_context()));
55 // Verify that the renderer sharing will happen.
56 GURL
test_url("http://foo.com");
57 EXPECT_TRUE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost(
58 browser_context(), test_url
));
62 #if defined(OS_ANDROID)
63 TEST_F(RenderProcessHostUnitTest
, NoRendererProcessLimitOnAndroid
) {
64 // Disable any overrides.
65 RenderProcessHostImpl::SetMaxRendererProcessCount(0);
67 // Verify that by default the limit on Android returns max size_t.
68 EXPECT_EQ(std::numeric_limits
<size_t>::max(),
69 RenderProcessHostImpl::GetMaxRendererProcessCount());
71 // Add a few dummy process hosts.
72 ASSERT_NE(0u, kMaxRendererProcessCount
);
73 ScopedVector
<MockRenderProcessHost
> hosts
;
74 for (size_t i
= 0; i
< kMaxRendererProcessCount
; ++i
) {
75 hosts
.push_back(new MockRenderProcessHost(browser_context()));
78 // Verify that the renderer sharing still won't happen.
79 GURL
test_url("http://foo.com");
80 EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost(
81 browser_context(), test_url
));
85 } // namespace content