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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
| 8 #include <memory> |
| 9 #include <vector> |
8 | 10 |
| 11 #include "base/memory/ptr_util.h" |
9 #include "build/build_config.h" | 12 #include "build/build_config.h" |
10 #include "content/public/common/content_constants.h" | 13 #include "content/public/common/content_constants.h" |
11 #include "content/public/test/mock_render_process_host.h" | 14 #include "content/public/test/mock_render_process_host.h" |
12 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
13 #include "content/test/test_render_view_host.h" | 16 #include "content/test/test_render_view_host.h" |
14 | 17 |
15 namespace content { | 18 namespace content { |
16 | 19 |
17 class RenderProcessHostUnitTest : public RenderViewHostTestHarness {}; | 20 class RenderProcessHostUnitTest : public RenderViewHostTestHarness {}; |
18 | 21 |
(...skipping 24 matching lines...) Expand all Loading... |
43 // Disable any overrides. | 46 // Disable any overrides. |
44 RenderProcessHostImpl::SetMaxRendererProcessCount(0); | 47 RenderProcessHostImpl::SetMaxRendererProcessCount(0); |
45 | 48 |
46 // Verify that the limit is between 1 and kMaxRendererProcessCount. | 49 // Verify that the limit is between 1 and kMaxRendererProcessCount. |
47 EXPECT_GT(RenderProcessHostImpl::GetMaxRendererProcessCount(), 0u); | 50 EXPECT_GT(RenderProcessHostImpl::GetMaxRendererProcessCount(), 0u); |
48 EXPECT_LE(RenderProcessHostImpl::GetMaxRendererProcessCount(), | 51 EXPECT_LE(RenderProcessHostImpl::GetMaxRendererProcessCount(), |
49 kMaxRendererProcessCount); | 52 kMaxRendererProcessCount); |
50 | 53 |
51 // Add dummy process hosts to saturate the limit. | 54 // Add dummy process hosts to saturate the limit. |
52 ASSERT_NE(0u, kMaxRendererProcessCount); | 55 ASSERT_NE(0u, kMaxRendererProcessCount); |
53 ScopedVector<MockRenderProcessHost> hosts; | 56 std::vector<std::unique_ptr<MockRenderProcessHost>> hosts; |
54 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { | 57 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
55 hosts.push_back(new MockRenderProcessHost(browser_context())); | 58 hosts.push_back(base::MakeUnique<MockRenderProcessHost>(browser_context())); |
56 } | 59 } |
57 | 60 |
58 // Verify that the renderer sharing will happen. | 61 // Verify that the renderer sharing will happen. |
59 GURL test_url("http://foo.com"); | 62 GURL test_url("http://foo.com"); |
60 EXPECT_TRUE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( | 63 EXPECT_TRUE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
61 browser_context(), test_url)); | 64 browser_context(), test_url)); |
62 } | 65 } |
63 #endif | 66 #endif |
64 | 67 |
65 #if defined(OS_ANDROID) | 68 #if defined(OS_ANDROID) |
66 TEST_F(RenderProcessHostUnitTest, NoRendererProcessLimitOnAndroid) { | 69 TEST_F(RenderProcessHostUnitTest, NoRendererProcessLimitOnAndroid) { |
67 // Disable any overrides. | 70 // Disable any overrides. |
68 RenderProcessHostImpl::SetMaxRendererProcessCount(0); | 71 RenderProcessHostImpl::SetMaxRendererProcessCount(0); |
69 | 72 |
70 // Verify that by default the limit on Android returns max size_t. | 73 // Verify that by default the limit on Android returns max size_t. |
71 EXPECT_EQ(std::numeric_limits<size_t>::max(), | 74 EXPECT_EQ(std::numeric_limits<size_t>::max(), |
72 RenderProcessHostImpl::GetMaxRendererProcessCount()); | 75 RenderProcessHostImpl::GetMaxRendererProcessCount()); |
73 | 76 |
74 // Add a few dummy process hosts. | 77 // Add a few dummy process hosts. |
75 ASSERT_NE(0u, kMaxRendererProcessCount); | 78 ASSERT_NE(0u, kMaxRendererProcessCount); |
76 ScopedVector<MockRenderProcessHost> hosts; | 79 std::vector<std::unique_ptr<MockRenderProcessHost>> hosts; |
77 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { | 80 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
78 hosts.push_back(new MockRenderProcessHost(browser_context())); | 81 hosts.push_back(base::MakeUnique<MockRenderProcessHost>(browser_context())); |
79 } | 82 } |
80 | 83 |
81 // Verify that the renderer sharing still won't happen. | 84 // Verify that the renderer sharing still won't happen. |
82 GURL test_url("http://foo.com"); | 85 GURL test_url("http://foo.com"); |
83 EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( | 86 EXPECT_FALSE(RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
84 browser_context(), test_url)); | 87 browser_context(), test_url)); |
85 } | 88 } |
86 #endif | 89 #endif |
87 | 90 |
88 } // namespace content | 91 } // namespace content |
OLD | NEW |