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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/extensions/extension_process_policy.h" | |
16 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/render_frame_host.h" | |
19 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
20 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/site_instance.h" | 19 #include "content/public/browser/site_instance.h" |
22 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
23 #include "content/public/test/browser_test_utils.h" | |
24 #include "content/public/test/test_navigation_observer.h" | |
25 #include "extensions/browser/extension_host.h" | 21 #include "extensions/browser/extension_host.h" |
26 #include "extensions/browser/process_manager.h" | 22 #include "extensions/browser/process_manager.h" |
27 #include "extensions/common/switches.h" | 23 #include "extensions/common/switches.h" |
28 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
30 | 26 |
31 using content::NavigationController; | 27 using content::NavigationController; |
32 using content::WebContents; | 28 using content::WebContents; |
33 | 29 |
34 namespace { | 30 namespace { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 process_ids.insert(host->render_process_host()->GetID()); | 241 process_ids.insert(host->render_process_host()->GetID()); |
246 | 242 |
247 // We've loaded 5 extensions with background pages, 1 extension without | 243 // We've loaded 5 extensions with background pages, 1 extension without |
248 // background page, and one isolated app. We expect only 2 unique processes | 244 // background page, and one isolated app. We expect only 2 unique processes |
249 // hosting those extensions. | 245 // hosting those extensions. |
250 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile); | 246 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile); |
251 | 247 |
252 EXPECT_GE((size_t) 6, process_map->size()); | 248 EXPECT_GE((size_t) 6, process_map->size()); |
253 EXPECT_EQ((size_t) 2, process_ids.size()); | 249 EXPECT_EQ((size_t) 2, process_ids.size()); |
254 } | 250 } |
255 | |
256 IN_PROC_BROWSER_TEST_F(ProcessManagementTest, | |
257 NavigateExtensionTabToWebViaPost) { | |
258 host_resolver()->AddRule("*", "127.0.0.1"); | |
259 ASSERT_TRUE(embedded_test_server()->Start()); | |
260 | |
261 // Load an extension. | |
262 const extensions::Extension* extension = LoadExtension( | |
263 test_data_dir_.AppendASCII("api_test/browser_action/popup_with_form")); | |
264 ASSERT_TRUE(extension); | |
265 | |
266 // Navigate a tab to an extension page. | |
267 GURL extension_url = extension->GetResourceURL("popup.html"); | |
268 ui_test_utils::NavigateToURL(browser(), extension_url); | |
269 WebContents* web_contents = | |
270 browser()->tab_strip_model()->GetActiveWebContents(); | |
271 EXPECT_EQ(extension_url, web_contents->GetLastCommittedURL()); | |
272 content::RenderProcessHost* old_process_host = | |
273 web_contents->GetMainFrame()->GetProcess(); | |
274 | |
275 // Note that the |setTimeout| call below is needed to make sure | |
276 // ExecuteScriptAndExtractBool returns *after* a scheduled navigation has | |
277 // already started. | |
278 GURL web_url(embedded_test_server()->GetURL("foo.com", "/title1.html")); | |
279 std::string navigation_starting_script = | |
280 "var form = document.getElementById('form');\n" | |
281 "form.action = '" + web_url.spec() + "';\n" | |
282 "form.submit();\n" | |
283 "setTimeout(\n" | |
284 " function() { window.domAutomationController.send(true); },\n" | |
285 " 0);\n"; | |
286 | |
287 // Try to trigger navigation to a webpage from within the tab. | |
288 bool ignored_script_result = false; | |
289 content::TestNavigationObserver nav_observer(web_contents, 1); | |
290 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
291 web_contents, navigation_starting_script, &ignored_script_result)); | |
292 | |
293 // Verify that the navigation succeeded. | |
294 nav_observer.Wait(); | |
295 EXPECT_EQ(web_url, web_contents->GetLastCommittedURL()); | |
296 | |
297 // Verify that the navigation transferred the contents to another renderer | |
298 // process. | |
299 if (extensions::IsIsolateExtensionsEnabled()) { | |
300 content::RenderProcessHost* new_process_host = | |
301 web_contents->GetMainFrame()->GetProcess(); | |
302 EXPECT_NE(old_process_host, new_process_host); | |
303 } | |
304 } | |
OLD | NEW |