OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/process.h" | 8 #include "base/process.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
11 #include "chrome/browser/ui/browser_tabstrip.h" | 11 #include "chrome/browser/ui/browser_tabstrip.h" |
12 #include "chrome/browser/ui/singleton_tabs.h" | 12 #include "chrome/browser/ui/singleton_tabs.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
15 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/common/test_url_constants.h" | 17 #include "content/common/test_url_constants.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
20 | 20 |
21 using content::WebContents; | 21 using content::WebContents; |
22 | 22 |
23 void PostQuit(MessageLoop* loop) { | 23 void PostQuit(MessageLoop* loop) { |
24 loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 24 loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
25 } | 25 } |
26 | 26 |
27 class RenderProcessHostTest : public InProcessBrowserTest { | 27 class RenderProcessHostTest : public InProcessBrowserTest { |
28 public: | 28 public: |
29 RenderProcessHostTest() { | 29 RenderProcessHostTest() {} |
30 EnableDOMAutomation(); | |
31 } | |
32 | 30 |
33 int RenderProcessHostCount() { | 31 int RenderProcessHostCount() { |
34 content::RenderProcessHost::iterator hosts = | 32 content::RenderProcessHost::iterator hosts = |
35 content::RenderProcessHost::AllHostsIterator(); | 33 content::RenderProcessHost::AllHostsIterator(); |
36 int count = 0; | 34 int count = 0; |
37 while (!hosts.IsAtEnd()) { | 35 while (!hosts.IsAtEnd()) { |
38 if (hosts.GetCurrentValue()->HasConnection()) | 36 if (hosts.GetCurrentValue()->HasConnection()) |
39 count++; | 37 count++; |
40 hosts.Advance(); | 38 hosts.Advance(); |
41 } | 39 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 EXPECT_EQ(host_count, RenderProcessHostCount()); | 135 EXPECT_EQ(host_count, RenderProcessHostCount()); |
138 EXPECT_NE(rph1, rph3); | 136 EXPECT_NE(rph1, rph3); |
139 EXPECT_NE(rph2, rph3); | 137 EXPECT_NE(rph2, rph3); |
140 } | 138 } |
141 }; | 139 }; |
142 | 140 |
143 | 141 |
144 class RenderProcessHostTestWithCommandLine : public RenderProcessHostTest { | 142 class RenderProcessHostTestWithCommandLine : public RenderProcessHostTest { |
145 protected: | 143 protected: |
146 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 144 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
147 InProcessBrowserTest::SetUpCommandLine(command_line); | |
148 command_line->AppendSwitchASCII(switches::kRendererProcessLimit, "1"); | 145 command_line->AppendSwitchASCII(switches::kRendererProcessLimit, "1"); |
149 } | 146 } |
150 }; | 147 }; |
151 | 148 |
152 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { | 149 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { |
153 // Set max renderers to 1 to force running out of processes. | 150 // Set max renderers to 1 to force running out of processes. |
154 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 151 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
155 | 152 |
156 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 153 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
157 parsed_command_line.AppendSwitch(switches::kProcessPerTab); | 154 parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // Set max renderers to 1 to force running out of processes. | 238 // Set max renderers to 1 to force running out of processes. |
242 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 239 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
243 TestProcessOverflow(); | 240 TestProcessOverflow(); |
244 } | 241 } |
245 | 242 |
246 // Variation of the ProcessOverflow test, which is driven through command line | 243 // Variation of the ProcessOverflow test, which is driven through command line |
247 // parameter instead of direct function call into the class. | 244 // parameter instead of direct function call into the class. |
248 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { | 245 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { |
249 TestProcessOverflow(); | 246 TestProcessOverflow(); |
250 } | 247 } |
OLD | NEW |