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/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // in a process of that type, even if that means creating a new process. | 62 // in a process of that type, even if that means creating a new process. |
63 void TestProcessOverflow() { | 63 void TestProcessOverflow() { |
64 int tab_count = 1; | 64 int tab_count = 1; |
65 int host_count = 1; | 65 int host_count = 1; |
66 WebContents* tab1 = NULL; | 66 WebContents* tab1 = NULL; |
67 WebContents* tab2 = NULL; | 67 WebContents* tab2 = NULL; |
68 content::RenderProcessHost* rph1 = NULL; | 68 content::RenderProcessHost* rph1 = NULL; |
69 content::RenderProcessHost* rph2 = NULL; | 69 content::RenderProcessHost* rph2 = NULL; |
70 content::RenderProcessHost* rph3 = NULL; | 70 content::RenderProcessHost* rph3 = NULL; |
71 | 71 |
72 #if defined(USE_VIRTUAL_KEYBOARD) | |
73 ++host_count; // For the virtual keyboard. | |
74 #endif | |
75 | |
76 // Change the first tab to be the new tab page (TYPE_WEBUI). | 72 // Change the first tab to be the new tab page (TYPE_WEBUI). |
77 GURL newtab(chrome::kTestNewTabURL); | 73 GURL newtab(chrome::kTestNewTabURL); |
78 ui_test_utils::NavigateToURL(browser(), newtab); | 74 ui_test_utils::NavigateToURL(browser(), newtab); |
79 EXPECT_EQ(tab_count, browser()->tab_count()); | 75 EXPECT_EQ(tab_count, browser()->tab_count()); |
80 tab1 = browser()->GetWebContentsAt(tab_count - 1); | 76 tab1 = browser()->GetWebContentsAt(tab_count - 1); |
81 rph1 = tab1->GetRenderProcessHost(); | 77 rph1 = tab1->GetRenderProcessHost(); |
82 EXPECT_EQ(tab1->GetURL(), newtab); | 78 EXPECT_EQ(tab1->GetURL(), newtab); |
83 EXPECT_EQ(host_count, RenderProcessHostCount()); | 79 EXPECT_EQ(host_count, RenderProcessHostCount()); |
84 | 80 |
85 // Create a new TYPE_TABBED tab. It should be in its own process. | 81 // Create a new TYPE_TABBED tab. It should be in its own process. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 EXPECT_EQ(host_count, RenderProcessHostCount()); | 119 EXPECT_EQ(host_count, RenderProcessHostCount()); |
124 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1); | 120 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1); |
125 | 121 |
126 // Create a TYPE_EXTENSION tab. It should be in its own process. | 122 // Create a TYPE_EXTENSION tab. It should be in its own process. |
127 // (the bookmark manager is implemented as an extension) | 123 // (the bookmark manager is implemented as an extension) |
128 GURL bookmarks(chrome::kTestBookmarksURL); | 124 GURL bookmarks(chrome::kTestBookmarksURL); |
129 browser()->ShowSingletonTab(bookmarks); | 125 browser()->ShowSingletonTab(bookmarks); |
130 if (browser()->tab_count() == tab_count) | 126 if (browser()->tab_count() == tab_count) |
131 ui_test_utils::WaitForNewTab(browser()); | 127 ui_test_utils::WaitForNewTab(browser()); |
132 tab_count++; | 128 tab_count++; |
133 #if !defined(USE_VIRTUAL_KEYBOARD) | |
134 // The virtual keyboard already creates an extension process. So this | |
135 // should not increase the process count. | |
136 host_count++; | 129 host_count++; |
137 #endif | |
138 EXPECT_EQ(tab_count, browser()->tab_count()); | 130 EXPECT_EQ(tab_count, browser()->tab_count()); |
139 tab1 = browser()->GetWebContentsAt(tab_count - 1); | 131 tab1 = browser()->GetWebContentsAt(tab_count - 1); |
140 rph3 = tab1->GetRenderProcessHost(); | 132 rph3 = tab1->GetRenderProcessHost(); |
141 EXPECT_EQ(tab1->GetURL(), bookmarks); | 133 EXPECT_EQ(tab1->GetURL(), bookmarks); |
142 EXPECT_EQ(host_count, RenderProcessHostCount()); | 134 EXPECT_EQ(host_count, RenderProcessHostCount()); |
143 EXPECT_NE(rph1, rph3); | 135 EXPECT_NE(rph1, rph3); |
144 EXPECT_NE(rph2, rph3); | 136 EXPECT_NE(rph2, rph3); |
145 } | 137 } |
146 }; | 138 }; |
147 | 139 |
148 | 140 |
149 class RenderProcessHostTestWithCommandLine : public RenderProcessHostTest { | 141 class RenderProcessHostTestWithCommandLine : public RenderProcessHostTest { |
150 protected: | 142 protected: |
151 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 143 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
152 InProcessBrowserTest::SetUpCommandLine(command_line); | 144 InProcessBrowserTest::SetUpCommandLine(command_line); |
153 command_line->AppendSwitchASCII(switches::kRendererProcessLimit, "1"); | 145 command_line->AppendSwitchASCII(switches::kRendererProcessLimit, "1"); |
154 } | 146 } |
155 }; | 147 }; |
156 | 148 |
157 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { | 149 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, ProcessPerTab) { |
158 // Set max renderers to 1 to force running out of processes. | 150 // Set max renderers to 1 to force running out of processes. |
159 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 151 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
160 | 152 |
161 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 153 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
162 parsed_command_line.AppendSwitch(switches::kProcessPerTab); | 154 parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
163 | 155 |
164 int tab_count = 1; | 156 int tab_count = 1; |
165 int host_count = 1; | 157 int host_count = 1; |
166 | 158 |
167 #if defined(USE_VIRTUAL_KEYBOARD) | |
168 ++host_count; // For the virtual keyboard. | |
169 #endif | |
170 | |
171 // Change the first tab to be the new tab page (TYPE_WEBUI). | 159 // Change the first tab to be the new tab page (TYPE_WEBUI). |
172 GURL newtab(chrome::kTestNewTabURL); | 160 GURL newtab(chrome::kTestNewTabURL); |
173 ui_test_utils::NavigateToURL(browser(), newtab); | 161 ui_test_utils::NavigateToURL(browser(), newtab); |
174 EXPECT_EQ(tab_count, browser()->tab_count()); | 162 EXPECT_EQ(tab_count, browser()->tab_count()); |
175 EXPECT_EQ(host_count, RenderProcessHostCount()); | 163 EXPECT_EQ(host_count, RenderProcessHostCount()); |
176 | 164 |
177 // Create a new TYPE_TABBED tab. It should be in its own process. | 165 // Create a new TYPE_TABBED tab. It should be in its own process. |
178 GURL page1("data:text/html,hello world1"); | 166 GURL page1("data:text/html,hello world1"); |
179 browser()->ShowSingletonTab(page1); | 167 browser()->ShowSingletonTab(page1); |
180 if (browser()->tab_count() == tab_count) | 168 if (browser()->tab_count() == tab_count) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // Set max renderers to 1 to force running out of processes. | 238 // Set max renderers to 1 to force running out of processes. |
251 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 239 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
252 TestProcessOverflow(); | 240 TestProcessOverflow(); |
253 } | 241 } |
254 | 242 |
255 // Variation of the ProcessOverflow test, which is driven through command line | 243 // Variation of the ProcessOverflow test, which is driven through command line |
256 // parameter instead of direct function call into the class. | 244 // parameter instead of direct function call into the class. |
257 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { | 245 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { |
258 TestProcessOverflow(); | 246 TestProcessOverflow(); |
259 } | 247 } |
OLD | NEW |