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" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 void TestProcessOverflow() { | 66 void TestProcessOverflow() { |
67 int tab_count = 1; | 67 int tab_count = 1; |
68 int host_count = 1; | 68 int host_count = 1; |
69 WebContents* tab1 = NULL; | 69 WebContents* tab1 = NULL; |
70 WebContents* tab2 = NULL; | 70 WebContents* tab2 = NULL; |
71 content::RenderProcessHost* rph1 = NULL; | 71 content::RenderProcessHost* rph1 = NULL; |
72 content::RenderProcessHost* rph2 = NULL; | 72 content::RenderProcessHost* rph2 = NULL; |
73 content::RenderProcessHost* rph3 = NULL; | 73 content::RenderProcessHost* rph3 = NULL; |
74 | 74 |
75 // Change the first tab to be the new tab page (TYPE_WEBUI). | 75 // Change the first tab to be the new tab page (TYPE_WEBUI). |
76 GURL newtab(chrome::kTestNewTabURL); | 76 GURL newtab(content::kTestNewTabURL); |
77 ui_test_utils::NavigateToURL(browser(), newtab); | 77 ui_test_utils::NavigateToURL(browser(), newtab); |
78 EXPECT_EQ(tab_count, browser()->tab_count()); | 78 EXPECT_EQ(tab_count, browser()->tab_count()); |
79 tab1 = chrome::GetWebContentsAt(browser(), tab_count - 1); | 79 tab1 = chrome::GetWebContentsAt(browser(), tab_count - 1); |
80 rph1 = tab1->GetRenderProcessHost(); | 80 rph1 = tab1->GetRenderProcessHost(); |
81 EXPECT_EQ(tab1->GetURL(), newtab); | 81 EXPECT_EQ(tab1->GetURL(), newtab); |
82 EXPECT_EQ(host_count, RenderProcessHostCount()); | 82 EXPECT_EQ(host_count, RenderProcessHostCount()); |
83 | 83 |
84 // Create a new TYPE_TABBED tab. It should be in its own process. | 84 // Create a new TYPE_TABBED tab. It should be in its own process. |
85 GURL page1("data:text/html,hello world1"); | 85 GURL page1("data:text/html,hello world1"); |
86 chrome::ShowSingletonTab(browser(), page1); | 86 chrome::ShowSingletonTab(browser(), page1); |
(...skipping 17 matching lines...) Expand all Loading... |
104 EXPECT_EQ(tab_count, browser()->tab_count()); | 104 EXPECT_EQ(tab_count, browser()->tab_count()); |
105 tab2 = chrome::GetWebContentsAt(browser(), tab_count - 1); | 105 tab2 = chrome::GetWebContentsAt(browser(), tab_count - 1); |
106 EXPECT_EQ(tab2->GetURL(), page2); | 106 EXPECT_EQ(tab2->GetURL(), page2); |
107 EXPECT_EQ(host_count, RenderProcessHostCount()); | 107 EXPECT_EQ(host_count, RenderProcessHostCount()); |
108 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2); | 108 EXPECT_EQ(tab2->GetRenderProcessHost(), rph2); |
109 | 109 |
110 // Create another TYPE_WEBUI tab. It should share the process with newtab. | 110 // Create another TYPE_WEBUI tab. It should share the process with newtab. |
111 // Note: intentionally create this tab after the TYPE_TABBED tabs to | 111 // Note: intentionally create this tab after the TYPE_TABBED tabs to |
112 // exercise bug 43448 where extension and WebUI tabs could get combined into | 112 // exercise bug 43448 where extension and WebUI tabs could get combined into |
113 // normal renderers. | 113 // normal renderers. |
114 GURL history(chrome::kTestHistoryURL); | 114 GURL history(content::kTestHistoryURL); |
115 chrome::ShowSingletonTab(browser(), history); | 115 chrome::ShowSingletonTab(browser(), history); |
116 if (browser()->tab_count() == tab_count) | 116 if (browser()->tab_count() == tab_count) |
117 ui_test_utils::WaitForNewTab(browser()); | 117 ui_test_utils::WaitForNewTab(browser()); |
118 tab_count++; | 118 tab_count++; |
119 EXPECT_EQ(tab_count, browser()->tab_count()); | 119 EXPECT_EQ(tab_count, browser()->tab_count()); |
120 tab2 = chrome::GetWebContentsAt(browser(), tab_count - 1); | 120 tab2 = chrome::GetWebContentsAt(browser(), tab_count - 1); |
121 EXPECT_EQ(tab2->GetURL(), history); | 121 EXPECT_EQ(tab2->GetURL(), history); |
122 EXPECT_EQ(host_count, RenderProcessHostCount()); | 122 EXPECT_EQ(host_count, RenderProcessHostCount()); |
123 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1); | 123 EXPECT_EQ(tab2->GetRenderProcessHost(), rph1); |
124 | 124 |
125 // Create a TYPE_EXTENSION tab. It should be in its own process. | 125 // Create a TYPE_EXTENSION tab. It should be in its own process. |
126 // (the bookmark manager is implemented as an extension) | 126 // (the bookmark manager is implemented as an extension) |
127 GURL bookmarks(chrome::kTestBookmarksURL); | 127 GURL bookmarks(content::kTestBookmarksURL); |
128 chrome::ShowSingletonTab(browser(), bookmarks); | 128 chrome::ShowSingletonTab(browser(), bookmarks); |
129 if (browser()->tab_count() == tab_count) | 129 if (browser()->tab_count() == tab_count) |
130 ui_test_utils::WaitForNewTab(browser()); | 130 ui_test_utils::WaitForNewTab(browser()); |
131 tab_count++; | 131 tab_count++; |
132 host_count++; | 132 host_count++; |
133 EXPECT_EQ(tab_count, browser()->tab_count()); | 133 EXPECT_EQ(tab_count, browser()->tab_count()); |
134 tab1 = chrome::GetWebContentsAt(browser(), tab_count - 1); | 134 tab1 = chrome::GetWebContentsAt(browser(), tab_count - 1); |
135 rph3 = tab1->GetRenderProcessHost(); | 135 rph3 = tab1->GetRenderProcessHost(); |
136 EXPECT_EQ(tab1->GetURL(), bookmarks); | 136 EXPECT_EQ(tab1->GetURL(), bookmarks); |
137 EXPECT_EQ(host_count, RenderProcessHostCount()); | 137 EXPECT_EQ(host_count, RenderProcessHostCount()); |
(...skipping 15 matching lines...) Expand all Loading... |
153 // Set max renderers to 1 to force running out of processes. | 153 // Set max renderers to 1 to force running out of processes. |
154 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 154 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
155 | 155 |
156 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 156 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
157 parsed_command_line.AppendSwitch(switches::kProcessPerTab); | 157 parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
158 | 158 |
159 int tab_count = 1; | 159 int tab_count = 1; |
160 int host_count = 1; | 160 int host_count = 1; |
161 | 161 |
162 // Change the first tab to be the new tab page (TYPE_WEBUI). | 162 // Change the first tab to be the new tab page (TYPE_WEBUI). |
163 GURL newtab(chrome::kTestNewTabURL); | 163 GURL newtab(content::kTestNewTabURL); |
164 ui_test_utils::NavigateToURL(browser(), newtab); | 164 ui_test_utils::NavigateToURL(browser(), newtab); |
165 EXPECT_EQ(tab_count, browser()->tab_count()); | 165 EXPECT_EQ(tab_count, browser()->tab_count()); |
166 EXPECT_EQ(host_count, RenderProcessHostCount()); | 166 EXPECT_EQ(host_count, RenderProcessHostCount()); |
167 | 167 |
168 // Create a new TYPE_TABBED tab. It should be in its own process. | 168 // Create a new TYPE_TABBED tab. It should be in its own process. |
169 GURL page1("data:text/html,hello world1"); | 169 GURL page1("data:text/html,hello world1"); |
170 chrome::ShowSingletonTab(browser(), page1); | 170 chrome::ShowSingletonTab(browser(), page1); |
171 if (browser()->tab_count() == tab_count) | 171 if (browser()->tab_count() == tab_count) |
172 ui_test_utils::WaitForNewTab(browser()); | 172 ui_test_utils::WaitForNewTab(browser()); |
173 tab_count++; | 173 tab_count++; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 #if defined(OS_WIN) || defined(OS_LINUX) | 206 #if defined(OS_WIN) || defined(OS_LINUX) |
207 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, Backgrounding) { | 207 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, Backgrounding) { |
208 if (!base::Process::CanBackgroundProcesses()) { | 208 if (!base::Process::CanBackgroundProcesses()) { |
209 LOG(ERROR) << "Can't background processes"; | 209 LOG(ERROR) << "Can't background processes"; |
210 return; | 210 return; |
211 } | 211 } |
212 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 212 CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
213 parsed_command_line.AppendSwitch(switches::kProcessPerTab); | 213 parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
214 | 214 |
215 // Change the first tab to be the new tab page (TYPE_WEBUI). | 215 // Change the first tab to be the new tab page (TYPE_WEBUI). |
216 GURL newtab(chrome::kTestNewTabURL); | 216 GURL newtab(content::kTestNewTabURL); |
217 ui_test_utils::NavigateToURL(browser(), newtab); | 217 ui_test_utils::NavigateToURL(browser(), newtab); |
218 | 218 |
219 // Create a new tab. It should be foreground. | 219 // Create a new tab. It should be foreground. |
220 GURL page1("data:text/html,hello world1"); | 220 GURL page1("data:text/html,hello world1"); |
221 base::ProcessHandle pid1 = ShowSingletonTab(page1); | 221 base::ProcessHandle pid1 = ShowSingletonTab(page1); |
222 EXPECT_FALSE(base::Process(pid1).IsProcessBackgrounded()); | 222 EXPECT_FALSE(base::Process(pid1).IsProcessBackgrounded()); |
223 | 223 |
224 // Create another tab. It should be foreground, and the first tab should | 224 // Create another tab. It should be foreground, and the first tab should |
225 // now be background. | 225 // now be background. |
226 GURL page2("data:text/html,hello world2"); | 226 GURL page2("data:text/html,hello world2"); |
(...skipping 14 matching lines...) Expand all Loading... |
241 // Set max renderers to 1 to force running out of processes. | 241 // Set max renderers to 1 to force running out of processes. |
242 content::RenderProcessHost::SetMaxRendererProcessCount(1); | 242 content::RenderProcessHost::SetMaxRendererProcessCount(1); |
243 TestProcessOverflow(); | 243 TestProcessOverflow(); |
244 } | 244 } |
245 | 245 |
246 // Variation of the ProcessOverflow test, which is driven through command line | 246 // Variation of the ProcessOverflow test, which is driven through command line |
247 // parameter instead of direct function call into the class. | 247 // parameter instead of direct function call into the class. |
248 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { | 248 IN_PROC_BROWSER_TEST_F(RenderProcessHostTestWithCommandLine, ProcessOverflow) { |
249 TestProcessOverflow(); | 249 TestProcessOverflow(); |
250 } | 250 } |
OLD | NEW |