| 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);
|
| +}
|
|
|