Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/extensions/process_management_browsertest.cc

Issue 2380193003: Block navigations in extensions via ShouldTransferNavigation (not via OpenURL). (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/site_instance.h" 21 #include "content/public/browser/site_instance.h"
20 #include "content/public/browser/web_contents.h" 22 #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"
21 #include "extensions/browser/extension_host.h" 25 #include "extensions/browser/extension_host.h"
22 #include "extensions/browser/process_manager.h" 26 #include "extensions/browser/process_manager.h"
23 #include "extensions/common/switches.h" 27 #include "extensions/common/switches.h"
24 #include "net/dns/mock_host_resolver.h" 28 #include "net/dns/mock_host_resolver.h"
25 #include "net/test/embedded_test_server/embedded_test_server.h" 29 #include "net/test/embedded_test_server/embedded_test_server.h"
26 30
27 using content::NavigationController; 31 using content::NavigationController;
28 using content::WebContents; 32 using content::WebContents;
29 33
30 namespace { 34 namespace {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 process_ids.insert(host->render_process_host()->GetID()); 237 process_ids.insert(host->render_process_host()->GetID());
234 238
235 // We've loaded 5 extensions with background pages, 1 extension without 239 // We've loaded 5 extensions with background pages, 1 extension without
236 // background page, and one isolated app. We expect only 2 unique processes 240 // background page, and one isolated app. We expect only 2 unique processes
237 // hosting those extensions. 241 // hosting those extensions.
238 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile); 242 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
239 243
240 EXPECT_GE((size_t) 6, process_map->size()); 244 EXPECT_GE((size_t) 6, process_map->size());
241 EXPECT_EQ((size_t) 2, process_ids.size()); 245 EXPECT_EQ((size_t) 2, process_ids.size());
242 } 246 }
247
248 IN_PROC_BROWSER_TEST_F(ProcessManagementTest,
249 NavigateExtensionTabToWebViaPost) {
250 host_resolver()->AddRule("*", "127.0.0.1");
251 ASSERT_TRUE(embedded_test_server()->Start());
252
253 // Load an extension.
254 const extensions::Extension* extension = LoadExtension(
255 test_data_dir_.AppendASCII("api_test/browser_action/popup_with_form"));
256 ASSERT_TRUE(extension);
257
258 // Navigate a tab to an extension page.
259 GURL extension_url = extension->GetResourceURL("popup.html");
260 ui_test_utils::NavigateToURL(browser(), extension_url);
261 WebContents* web_contents =
262 browser()->tab_strip_model()->GetActiveWebContents();
263 EXPECT_EQ(extension_url, web_contents->GetLastCommittedURL());
264 content::RenderProcessHost* old_process_host =
265 web_contents->GetMainFrame()->GetProcess();
266
267 // Note that the |setTimeout| call below is needed to make sure
268 // ExecuteScriptAndExtractBool returns *after* a scheduled navigation has
269 // already started.
270 GURL web_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
271 std::string navigation_starting_script =
272 "var form = document.getElementById('form');\n"
273 "form.action = '" + web_url.spec() + "';\n"
274 "form.submit();\n"
275 "setTimeout(\n"
276 " function() { window.domAutomationController.send(true); },\n"
277 " 0);\n";
278
279 // Try to trigger navigation to a webpage from within the tab.
280 bool ignored_script_result = false;
281 content::TestNavigationObserver nav_observer(web_contents, 1);
282 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
283 web_contents, navigation_starting_script, &ignored_script_result));
284
285 // Verify that the navigation succeeded.
286 nav_observer.Wait();
287 EXPECT_EQ(web_url, web_contents->GetLastCommittedURL());
288
289 // Verify that the navigation transferred the contents to another renderer
290 // process.
291 if (extensions::IsIsolateExtensionsEnabled()) {
292 content::RenderProcessHost* new_process_host =
293 web_contents->GetMainFrame()->GetProcess();
294 EXPECT_NE(old_process_host, new_process_host);
295 }
296 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_view_host.cc ('k') | chrome/browser/prerender/prerender_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698