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/chrome_notification_types.h" | |
9 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/sessions/session_tab_helper.h" | |
13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/extensions/extension_process_policy.h" | 18 #include "chrome/common/extensions/extension_process_policy.h" |
17 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
21 #include "content/public/browser/notification_service.h" | |
19 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
20 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/site_instance.h" | 25 #include "content/public/browser/site_instance.h" |
23 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
24 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
25 #include "content/public/test/test_navigation_observer.h" | 28 #include "content/public/test/test_navigation_observer.h" |
26 #include "extensions/browser/extension_host.h" | 29 #include "extensions/browser/extension_host.h" |
27 #include "extensions/browser/process_manager.h" | 30 #include "extensions/browser/process_manager.h" |
28 #include "extensions/browser/process_map.h" | 31 #include "extensions/browser/process_map.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 // Verify that we really have the Chrome Web Store app loaded in the Web | 386 // Verify that we really have the Chrome Web Store app loaded in the Web |
384 // Contents. | 387 // Contents. |
385 content::RenderProcessHost* new_process_host = | 388 content::RenderProcessHost* new_process_host = |
386 web_contents->GetMainFrame()->GetProcess(); | 389 web_contents->GetMainFrame()->GetProcess(); |
387 EXPECT_TRUE(extensions::ProcessMap::Get(profile())->Contains( | 390 EXPECT_TRUE(extensions::ProcessMap::Get(profile())->Contains( |
388 extensions::kWebStoreAppId, new_process_host->GetID())); | 391 extensions::kWebStoreAppId, new_process_host->GetID())); |
389 | 392 |
390 // Verify that Chrome Web Store is isolated in a separate renderer process. | 393 // Verify that Chrome Web Store is isolated in a separate renderer process. |
391 EXPECT_NE(old_process_host, new_process_host); | 394 EXPECT_NE(old_process_host, new_process_host); |
392 } | 395 } |
396 | |
397 // This test verifies that blocked navigations to extensions pages do not | |
398 // overwrite process-per-site map inside content/. | |
399 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, | |
400 NavigateToBlockedExtensionPageInNewTab) { | |
401 host_resolver()->AddRule("*", "127.0.0.1"); | |
402 ASSERT_TRUE(embedded_test_server()->Start()); | |
403 | |
404 // Load an extension, which will block a request for a specific page in it. | |
405 const extensions::Extension* extension = LoadExtension( | |
406 test_data_dir_.AppendASCII("web_request_site_process_registration")); | |
407 ASSERT_TRUE(extension); | |
408 | |
409 WebContents* web_contents = | |
410 browser()->tab_strip_model()->GetActiveWebContents(); | |
411 GURL blocked_url(extension->GetResourceURL("/blocked.html")); | |
412 | |
413 // Navigating to the blocked extension URL should be done through a redirect, | |
414 // otherwise it will result in an OpenURL IPC from the renderer process, which | |
415 // will initiate a navigation through the browser process. | |
416 GURL redirect_url( | |
417 embedded_test_server()->GetURL("/server-redirect?" + blocked_url.spec())); | |
418 | |
419 // Navigate the current tab to the test page in the extension, which will | |
420 // create the extension process and register the webRequest blocking listener. | |
421 ui_test_utils::NavigateToURL(browser(), | |
422 extension->GetResourceURL("/test.html")); | |
423 | |
424 // Open a new tab to about:blank, which will result in a new SiteInstance | |
425 // without an explicit site URL set. | |
426 ui_test_utils::NavigateToURLWithDisposition( | |
427 browser(), GURL(url::kAboutBlankURL), | |
428 WindowOpenDisposition::NEW_FOREGROUND_TAB, | |
429 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
430 WebContents* new_web_contents = | |
431 browser()->tab_strip_model()->GetActiveWebContents(); | |
432 | |
433 // Navigate the new tab to an extension URL that will be blocked by | |
434 // webRequest. It must be a renderer-initiated navigation. It also uses a | |
435 // redirect, otherwise the regular renderer process will send an OpenURL | |
436 // IPC to the browser due to the chrome-extension:// URL. | |
437 std::string script = | |
438 base::StringPrintf("location.href = '%s';", redirect_url.spec().c_str()); | |
439 content::TestNavigationObserver observer(new_web_contents); | |
440 EXPECT_TRUE(content::ExecuteScript(new_web_contents, script)); | |
441 observer.Wait(); | |
442 | |
443 EXPECT_EQ(observer.last_navigation_url(), blocked_url); | |
444 EXPECT_FALSE(observer.last_navigation_succeeded()); | |
445 | |
446 // Very subtle check for content/ internal functionality :(. | |
nasko
2017/03/14 16:56:02
I was thinking more and more about this test and w
Charlie Reis
2017/03/14 23:46:46
I like that idea.
| |
447 // When a navigation is blocked, it still commits an error page. Since | |
448 // extensions use the process-per-site model, each extension URL is registered | |
449 // in a map from URL to a process. Creating a brand new SiteInstance for the | |
450 // extension URL should always result in a SiteInstance that has a process and | |
451 // the process is the same for all SiteInstances. | |
Charlie Reis
2017/03/13 22:31:33
Thanks for explaining, but I think this is missing
nasko
2017/03/14 16:56:02
Done.
| |
452 scoped_refptr<content::SiteInstance> new_site_instance = | |
453 content::SiteInstance::CreateForURL(web_contents->GetBrowserContext(), | |
454 extension->GetResourceURL("")); | |
455 EXPECT_TRUE(new_site_instance->HasProcess()); | |
456 EXPECT_EQ(new_site_instance->GetProcess(), | |
457 web_contents->GetSiteInstance()->GetProcess()); | |
458 } | |
OLD | NEW |