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

Unified Diff: chrome/browser/extensions/extension_browsertests_misc.cc

Issue 173649: Allow DOMUI pages to call window.open(), giving DOMUI privileges to the new (Closed)
Patch Set: more comments Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_factory.cc ('k') | chrome/browser/extensions/extension_dom_ui.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_browsertests_misc.cc
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc
index 88da761eb4d7e0102ca76aeff3a0b8dfa59226c1..2226cff7b0bbc94f8223b119209407e1b0ca1556 100644
--- a/chrome/browser/extensions/extension_browsertests_misc.cc
+++ b/chrome/browser/extensions/extension_browsertests_misc.cc
@@ -501,3 +501,91 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UninstallDisabled) {
EXPECT_EQ(0u, service->extensions()->size());
EXPECT_EQ(0u, service->disabled_extensions()->size());
}
+
+// Tests that an extension page can call window.open to an extension URL and
+// the new window has extension privileges.
+IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) {
+ ASSERT_TRUE(LoadExtension(
+ test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
+
+ ui_test_utils::NavigateToURL(
+ browser(),
+ GURL("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/test.html"));
+
+ bool result = false;
+ ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ browser()->GetSelectedTabContents()->render_view_host(), L"",
+ L"testWindowOpen('newtab.html')", &result);
+ ASSERT_TRUE(result);
+
+ // Now the current tab should be the new tab.
+ ui_test_utils::WaitForNavigation(
+ &browser()->GetSelectedTabContents()->controller());
+ ASSERT_EQ(browser()->GetSelectedTabContents()->GetURL().path(),
+ "/newtab.html");
+
+ result = false;
+ ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ browser()->GetSelectedTabContents()->render_view_host(), L"",
+ L"testExtensionApi()", &result);
+ EXPECT_TRUE(result);
+}
+
+// Tests that if an extension page calls window.open to an invalid extension
+// URL, the browser doesn't crash.
+IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenInvalidExtension) {
+ ASSERT_TRUE(LoadExtension(
+ test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
+
+ ui_test_utils::NavigateToURL(
+ browser(),
+ GURL("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/test.html"));
+
+ bool result = false;
+ ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ browser()->GetSelectedTabContents()->render_view_host(), L"",
+ L"testWindowOpen('"
+ L"chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab/newtab.html"
+ L"')", &result);
+ ASSERT_TRUE(result);
+
+ // Now the current tab should be the new tab.
+ ui_test_utils::WaitForNavigation(
+ &browser()->GetSelectedTabContents()->controller());
+ ASSERT_EQ(browser()->GetSelectedTabContents()->GetURL().path(),
+ "/newtab.html");
+
+ // If we got to this point, we didn't crash, so we're good.
+}
+
+// Tests that calling window.open from the newtab page to an extension URL
+// does not give the new window extension privileges - because the opening page
+// does not have extension privileges.
+IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenNoPrivileges) {
+ ASSERT_TRUE(LoadExtension(
+ test_data_dir_.AppendASCII("uitest").AppendASCII("window_open")));
+
+ ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
+
+ bool result = false;
+ ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ browser()->GetSelectedTabContents()->render_view_host(), L"",
+ L"window.open('"
+ L"chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/newtab.html"
+ L"');"
+ L"window.domAutomationController.send(true);", &result);
+ ASSERT_TRUE(result);
+
+ // Now the current tab should be the new tab.
+ ui_test_utils::WaitForNavigation(
+ &browser()->GetSelectedTabContents()->controller());
+ ASSERT_EQ(browser()->GetSelectedTabContents()->GetURL().path(),
+ "/newtab.html");
+
+ // Extension API should fail.
+ result = false;
+ ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ browser()->GetSelectedTabContents()->render_view_host(), L"",
+ L"testExtensionApi()", &result);
+ EXPECT_FALSE(result);
+}
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_factory.cc ('k') | chrome/browser/extensions/extension_dom_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698