OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/browser/automation/automation_util.h" | 6 #include "chrome/browser/automation/automation_util.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, ProcessOverflow) { | 170 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, ProcessOverflow) { |
171 // Set max renderers to 1 to force running out of processes. | 171 // Set max renderers to 1 to force running out of processes. |
172 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); | 172 content::RenderProcessHost::SetMaxRendererProcessCountForTest(1); |
173 | 173 |
174 host_resolver()->AddRule("*", "127.0.0.1"); | 174 host_resolver()->AddRule("*", "127.0.0.1"); |
175 ASSERT_TRUE(test_server()->Start()); | 175 ASSERT_TRUE(test_server()->Start()); |
176 | 176 |
177 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); | 177 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
178 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); | 178 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app2"))); |
179 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("hosted_app"))); | 179 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("hosted_app"))); |
| 180 ASSERT_TRUE( |
| 181 LoadExtension(test_data_dir_.AppendASCII("api_test/app_process"))); |
180 | 182 |
181 // The app under test acts on URLs whose host is "localhost", | 183 // The app under test acts on URLs whose host is "localhost", |
182 // so the URLs we navigate to must have host "localhost". | 184 // so the URLs we navigate to must have host "localhost". |
183 GURL base_url = test_server()->GetURL( | 185 GURL base_url = test_server()->GetURL( |
184 "files/extensions/"); | 186 "files/extensions/"); |
185 GURL::Replacements replace_host; | 187 GURL::Replacements replace_host; |
186 std::string host_str("localhost"); // Must stay in scope with replace_host. | 188 std::string host_str("localhost"); // Must stay in scope with replace_host. |
187 replace_host.SetHostStr(host_str); | 189 replace_host.SetHostStr(host_str); |
188 base_url = base_url.ReplaceComponents(replace_host); | 190 base_url = base_url.ReplaceComponents(replace_host); |
189 | 191 |
190 // Create a tab for each type of renderer that might exist. | 192 // Load an extension before adding tabs. |
| 193 const Extension* extension1 = LoadExtension( |
| 194 test_data_dir_.AppendASCII("api_test/browser_action/basics")); |
| 195 ASSERT_TRUE(extension1); |
| 196 GURL extension1_url = extension1->url(); |
| 197 |
| 198 // Create multiple tabs for each type of renderer that might exist. |
191 ui_test_utils::NavigateToURLWithDisposition( | 199 ui_test_utils::NavigateToURLWithDisposition( |
192 browser(), base_url.Resolve("isolated_apps/app1/main.html"), | 200 browser(), base_url.Resolve("isolated_apps/app1/main.html"), |
193 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 201 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
194 ui_test_utils::NavigateToURLWithDisposition( | 202 ui_test_utils::NavigateToURLWithDisposition( |
195 browser(), GURL(chrome::kChromeUINewTabURL), | 203 browser(), GURL(chrome::kChromeUINewTabURL), |
196 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 204 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
197 ui_test_utils::NavigateToURLWithDisposition( | 205 ui_test_utils::NavigateToURLWithDisposition( |
198 browser(), base_url.Resolve("hosted_app/main.html"), | 206 browser(), base_url.Resolve("hosted_app/main.html"), |
199 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 207 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
200 ui_test_utils::NavigateToURLWithDisposition( | 208 ui_test_utils::NavigateToURLWithDisposition( |
201 browser(), base_url.Resolve("test_file.html"), | 209 browser(), base_url.Resolve("test_file.html"), |
202 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 210 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 211 |
203 ui_test_utils::NavigateToURLWithDisposition( | 212 ui_test_utils::NavigateToURLWithDisposition( |
204 browser(), base_url.Resolve("isolated_apps/app2/main.html"), | 213 browser(), base_url.Resolve("isolated_apps/app2/main.html"), |
205 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 214 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 215 ui_test_utils::NavigateToURLWithDisposition( |
| 216 browser(), GURL(chrome::kChromeUINewTabURL), |
| 217 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 218 ui_test_utils::NavigateToURLWithDisposition( |
| 219 browser(), base_url.Resolve("api_test/app_process/path1/empty.html"), |
| 220 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 221 ui_test_utils::NavigateToURLWithDisposition( |
| 222 browser(), base_url.Resolve("test_file_with_body.html"), |
| 223 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
206 | 224 |
207 ASSERT_EQ(5, browser()->tab_count()); | 225 // Load another copy of isolated app 1. |
| 226 ui_test_utils::NavigateToURLWithDisposition( |
| 227 browser(), base_url.Resolve("isolated_apps/app1/main.html"), |
| 228 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 229 |
| 230 // Load another extension. |
| 231 const Extension* extension2 = LoadExtension( |
| 232 test_data_dir_.AppendASCII("api_test/browser_action/close_background")); |
| 233 ASSERT_TRUE(extension2); |
| 234 GURL extension2_url = extension2->url(); |
| 235 |
| 236 // Get tab processes. |
| 237 ASSERT_EQ(9, browser()->tab_count()); |
208 content::RenderProcessHost* isolated1_host = | 238 content::RenderProcessHost* isolated1_host = |
209 browser()->GetTabContentsAt(0)->GetRenderProcessHost(); | 239 browser()->GetTabContentsAt(0)->GetRenderProcessHost(); |
210 content::RenderProcessHost* ntp_host = | 240 content::RenderProcessHost* ntp1_host = |
211 browser()->GetTabContentsAt(1)->GetRenderProcessHost(); | 241 browser()->GetTabContentsAt(1)->GetRenderProcessHost(); |
212 content::RenderProcessHost* normal_extension_host = | 242 content::RenderProcessHost* hosted1_host = |
213 browser()->GetTabContentsAt(2)->GetRenderProcessHost(); | 243 browser()->GetTabContentsAt(2)->GetRenderProcessHost(); |
214 content::RenderProcessHost* web_host = | 244 content::RenderProcessHost* web1_host = |
215 browser()->GetTabContentsAt(3)->GetRenderProcessHost(); | 245 browser()->GetTabContentsAt(3)->GetRenderProcessHost(); |
| 246 |
216 content::RenderProcessHost* isolated2_host = | 247 content::RenderProcessHost* isolated2_host = |
217 browser()->GetTabContentsAt(4)->GetRenderProcessHost(); | 248 browser()->GetTabContentsAt(4)->GetRenderProcessHost(); |
| 249 content::RenderProcessHost* ntp2_host = |
| 250 browser()->GetTabContentsAt(5)->GetRenderProcessHost(); |
| 251 content::RenderProcessHost* hosted2_host = |
| 252 browser()->GetTabContentsAt(6)->GetRenderProcessHost(); |
| 253 content::RenderProcessHost* web2_host = |
| 254 browser()->GetTabContentsAt(7)->GetRenderProcessHost(); |
218 | 255 |
219 // Isolated apps shared with each other, but no one else. They're clannish | 256 content::RenderProcessHost* second_isolated1_host = |
220 // like that. | 257 browser()->GetTabContentsAt(8)->GetRenderProcessHost(); |
221 ASSERT_EQ(isolated1_host, isolated2_host); | |
222 ASSERT_NE(isolated1_host, ntp_host); | |
223 ASSERT_NE(isolated1_host, normal_extension_host); | |
224 ASSERT_NE(isolated1_host, web_host); | |
225 | 258 |
226 // And cause we're here, make sure everyone else is also clannish. This could | 259 // Get extension processes. |
227 // technially go in another test, but not worth the extra setup overhead. | 260 ExtensionProcessManager* process_manager = |
228 ASSERT_NE(web_host, ntp_host); | 261 browser()->GetProfile()->GetExtensionProcessManager(); |
229 ASSERT_NE(web_host, normal_extension_host); | 262 content::RenderProcessHost* extension1_host = |
230 ASSERT_NE(normal_extension_host, ntp_host); | 263 process_manager->GetSiteInstanceForURL(extension1_url)->GetProcess(); |
| 264 content::RenderProcessHost* extension2_host = |
| 265 process_manager->GetSiteInstanceForURL(extension2_url)->GetProcess(); |
| 266 |
| 267 // An isolated app only shares with other instances of itself, not other |
| 268 // isolated apps or anything else. |
| 269 EXPECT_EQ(isolated1_host, second_isolated1_host); |
| 270 EXPECT_NE(isolated1_host, isolated2_host); |
| 271 EXPECT_NE(isolated1_host, ntp1_host); |
| 272 EXPECT_NE(isolated1_host, hosted1_host); |
| 273 EXPECT_NE(isolated1_host, web1_host); |
| 274 EXPECT_NE(isolated1_host, extension1_host); |
| 275 EXPECT_NE(isolated2_host, ntp1_host); |
| 276 EXPECT_NE(isolated2_host, hosted1_host); |
| 277 EXPECT_NE(isolated2_host, web1_host); |
| 278 EXPECT_NE(isolated2_host, extension1_host); |
| 279 |
| 280 // Everything else is clannish. WebUI only shares with other WebUI. |
| 281 EXPECT_EQ(ntp1_host, ntp2_host); |
| 282 EXPECT_NE(ntp1_host, hosted1_host); |
| 283 EXPECT_NE(ntp1_host, web1_host); |
| 284 EXPECT_NE(ntp1_host, extension1_host); |
| 285 |
| 286 // Hosted apps only share with each other. |
| 287 EXPECT_EQ(hosted1_host, hosted2_host); |
| 288 EXPECT_NE(hosted1_host, web1_host); |
| 289 EXPECT_NE(hosted1_host, extension1_host); |
| 290 |
| 291 // Web pages only share with each other. |
| 292 EXPECT_EQ(web1_host, web2_host); |
| 293 EXPECT_NE(web1_host, extension1_host); |
| 294 |
| 295 // Extensions only share with each other. |
| 296 EXPECT_EQ(extension1_host, extension2_host); |
231 } | 297 } |
OLD | NEW |