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/test/test_render_view_host.h"
13 class RenderProcessHostUnitTest
: public RenderViewHostTestHarness
{};
15 // Tests that guest RenderProcessHosts are not considered suitable hosts when
16 // searching for RenderProcessHost.
17 TEST_F(RenderProcessHostUnitTest
, GuestsAreNotSuitableHosts
) {
18 GURL
test_url("http://foo.com");
20 MockRenderProcessHost
guest_host(browser_context());
21 guest_host
.set_is_isolated_guest(true);
23 EXPECT_FALSE(RenderProcessHostImpl::IsSuitableHost(
24 &guest_host
, browser_context(), test_url
));
25 EXPECT_TRUE(RenderProcessHostImpl::IsSuitableHost(
26 process(), browser_context(), test_url
));
29 RenderProcessHost::GetExistingProcessHost(browser_context(), test_url
));
32 #if !defined(OS_ANDROID)
33 TEST_F(RenderProcessHostUnitTest
, RendererProcessLimit
) {
34 // Disable any overrides.
35 RenderProcessHostImpl::SetMaxRendererProcessCount(0);
37 // Verify that the limit is between 1 and kMaxRendererProcessCount.
38 EXPECT_GT(RenderProcessHostImpl::GetMaxRendererProcessCount(), 0u);
39 EXPECT_LE(RenderProcessHostImpl::GetMaxRendererProcessCount(),
40 kMaxRendererProcessCount
);
42 // Add dummy process hosts to saturate the limit.
43 ASSERT_NE(0u, kMaxRendererProcessCount
);
44 ScopedVector
<MockRenderProcessHost
> hosts
;
45 for (size_t i
= 0; i
< kMaxRendererProcessCount
; ++i
) {
46 hosts
.push_back(new MockRenderProcessHost(browser_context()));
49 // Verify that the renderer sharing will happen.
50 GURL
test_url("http://foo.com");
51 EXPECT_TRUE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost(
52 browser_context(), test_url
));
56 #if defined(OS_ANDROID)
57 TEST_F(RenderProcessHostUnitTest
, NoRendererProcessLimitOnAndroid
) {
58 // Disable any overrides.
59 RenderProcessHostImpl::SetMaxRendererProcessCount(0);
61 // Verify that by default the limit on Android returns max size_t.
62 EXPECT_EQ(std::numeric_limits
<size_t>::max(),
63 RenderProcessHostImpl::GetMaxRendererProcessCount());
65 // Add a few dummy process hosts.
66 ASSERT_NE(0u, kMaxRendererProcessCount
);
67 ScopedVector
<MockRenderProcessHost
> hosts
;
68 for (size_t i
= 0; i
< kMaxRendererProcessCount
; ++i
) {
69 hosts
.push_back(new MockRenderProcessHost(browser_context()));
72 // Verify that the renderer sharing still won't happen.
73 GURL
test_url("http://foo.com");
74 EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost(
75 browser_context(), test_url
));
79 } // namespace content