Index: chrome/browser/extensions/process_management_browsertest.cc |
diff --git a/chrome/browser/extensions/process_management_browsertest.cc b/chrome/browser/extensions/process_management_browsertest.cc |
index 012fb553d0cf27c65aba7a9f90c980fe9cedae4e..57b03120acf465aa54010b231b32b9fd0462583c 100644 |
--- a/chrome/browser/extensions/process_management_browsertest.cc |
+++ b/chrome/browser/extensions/process_management_browsertest.cc |
@@ -6,16 +6,19 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "build/build_config.h" |
+#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/extensions/extension_apitest.h" |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/browser/sessions/session_tab_helper.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/extensions/extension_process_policy.h" |
#include "chrome/common/url_constants.h" |
#include "chrome/test/base/ui_test_utils.h" |
+#include "content/public/browser/notification_service.h" |
#include "content/public/browser/render_frame_host.h" |
#include "content/public/browser/render_process_host.h" |
#include "content/public/browser/render_view_host.h" |
@@ -390,3 +393,80 @@ IN_PROC_BROWSER_TEST_F(ChromeWebStoreProcessTest, |
// Verify that Chrome Web Store is isolated in a separate renderer process. |
EXPECT_NE(old_process_host, new_process_host); |
} |
+ |
+// This test verifies that blocked navigations to extensions pages do not |
+// overwrite process-per-site map inside content/. |
+IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, |
+ NavigateToBlockedExtensionPageInNewTab) { |
+ host_resolver()->AddRule("*", "127.0.0.1"); |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ |
+ // Load an extension, which will block a request for a specifig page in it. |
Devlin
2017/03/11 01:52:17
*specific
nasko
2017/03/13 17:22:03
Done.
|
+ const extensions::Extension* extension = |
+ LoadExtension(test_data_dir_.AppendASCII("web_request_blocking")); |
+ ASSERT_TRUE(extension); |
+ |
+ WebContents* web_contents = |
+ browser()->tab_strip_model()->GetActiveWebContents(); |
+ WebContents* new_web_contents = nullptr; |
+ GURL blocked_url(extension->GetResourceURL("/blocked.html")); |
+ |
+ // Navigating to the blocked extension URL should be done through a redirect, |
+ // otherwise it will result in an OpenURL IPC from the renderer process, which |
+ // will initiate a navigation through the browser process. |
+ GURL redirect_url( |
+ embedded_test_server()->GetURL("/server-redirect?" + blocked_url.spec())); |
+ |
+ // Navigate the current tab to the test page in the extension, which will |
+ // create the extension process and register the webRequest blocking listener. |
+ { |
+ content::TestNavigationObserver observer(web_contents); |
Devlin
2017/03/11 01:52:17
Doesn't NavigateToURL by default block until navig
nasko
2017/03/13 17:22:03
Good point :). I had so many iterations of this co
|
+ ui_test_utils::NavigateToURL(browser(), |
+ extension->GetResourceURL("/test.html")); |
+ observer.Wait(); |
+ } |
+ |
+ // Open a new tab to about:blank, which will result in a new SiteInstance |
+ // without an explicit site set. |
+ { |
+ content::WindowedNotificationObserver tab_added_observer( |
+ chrome::NOTIFICATION_TAB_ADDED, |
+ content::NotificationService::AllSources()); |
+ EXPECT_TRUE(content::ExecuteScript( |
+ web_contents, "chrome.tabs.create({url: 'about:blank'});")); |
Devlin
2017/03/11 01:52:18
Does this have to be done through the extension AP
nasko
2017/03/13 17:22:03
I was trying to mimic as closely what I observed.
|
+ tab_added_observer.Wait(); |
+ new_web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
+ |
+ // If the navigation hasn't committed yet, the test needs to wait for it. |
+ if (new_web_contents->GetLastCommittedURL() != GURL(url::kAboutBlankURL)) { |
Devlin
2017/03/11 01:52:17
The above might also solve this, since NavigateToU
nasko
2017/03/13 17:22:03
Done.
|
+ content::TestNavigationObserver observer(new_web_contents); |
+ observer.Wait(); |
+ } |
+ } |
+ |
+ // Navigate the new tab to an extension URL that will be blocked by |
+ // webRequest. |
+ { |
+ std::string script = base::StringPrintf("location.href = '%s';", |
+ redirect_url.spec().c_str()); |
+ content::TestNavigationObserver observer(new_web_contents); |
+ EXPECT_TRUE(content::ExecuteScript(new_web_contents, script)); |
Devlin
2017/03/11 01:52:17
Same question - does this need to be through Execu
nasko
2017/03/13 17:22:03
This needs to be a renderer initiated navigation a
|
+ observer.Wait(); |
+ |
+ EXPECT_EQ(observer.last_navigation_url(), blocked_url); |
+ EXPECT_FALSE(observer.last_navigation_succeeded()); |
+ } |
+ |
+ // Very subtle check for content/ internal functionality :(. |
+ // When a navigation is blocked, it still commits an error page. Since |
+ // extensions use the process-per-site model, each extension URL is registered |
Devlin
2017/03/11 01:52:17
nit: process-per-extension? process-per-origin?
nasko
2017/03/13 17:22:03
Our codebase and docs already talk about process-p
|
+ // in a map from URL to a process. Creating a brand new SiteInstance for the |
+ // extension URL should always result in a SiteInstance that has a process and |
+ // the process is the same for all SiteInstances. |
+ scoped_refptr<content::SiteInstance> new_site_instance = |
+ content::SiteInstance::CreateForURL(web_contents->GetBrowserContext(), |
+ extension->GetResourceURL("")); |
Devlin
2017/03/11 01:52:17
nit: extension->url()
nasko
2017/03/13 17:22:03
Done.
|
+ EXPECT_TRUE(new_site_instance->HasProcess()); |
+ EXPECT_EQ(new_site_instance->GetProcess(), |
+ web_contents->GetSiteInstance()->GetProcess()); |
+} |