summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/extensions/api/extension_action
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-01-04 14:17:57 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-01-05 10:05:06 +0000
commit39d357e3248f80abea0159765ff39554affb40db (patch)
treeaba0e6bfb76de0244bba0f5fdbd64b830dd6e621 /chromium/chrome/browser/extensions/api/extension_action
parent87778abf5a1f89266f37d1321b92a21851d8244d (diff)
BASELINE: Update Chromium to 55.0.2883.105
And updates ninja to 1.7.2 Change-Id: I20d43c737f82764d857ada9a55586901b18b9243 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/chrome/browser/extensions/api/extension_action')
-rw-r--r--chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc233
-rw-r--r--chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc19
2 files changed, 241 insertions, 11 deletions
diff --git a/chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc b/chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
index 0ae5d37aee4..7b2e7dd11dd 100644
--- a/chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
+++ b/chromium/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
@@ -22,12 +22,17 @@
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.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/browser_context.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/content_browser_test_utils.h"
+#include "content/public/test/download_test_observer.h"
+#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/notification_types.h"
@@ -36,9 +41,9 @@
#include "extensions/common/feature_switch.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
-#include "grit/theme_resources.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
@@ -106,7 +111,7 @@ class BrowserActionApiTest : public ExtensionApiTest {
return browser_action_test_util_.get();
}
- bool OpenPopup(int index) {
+ WebContents* OpenPopup(int index) {
ResultCatcher catcher;
content::WindowedNotificationObserver popup_observer(
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
@@ -114,7 +119,13 @@ class BrowserActionApiTest : public ExtensionApiTest {
GetBrowserActionsBar()->Press(index);
popup_observer.Wait();
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
- return GetBrowserActionsBar()->HasPopup();
+
+ if (!GetBrowserActionsBar()->HasPopup())
+ return nullptr;
+
+ const auto& source = static_cast<const content::Source<WebContents>&>(
+ popup_observer.source());
+ return source.ptr();
}
ExtensionAction* GetBrowserAction(const Extension& extension) {
@@ -722,7 +733,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionPopupWithIframe) {
extensions::ProcessManager::Get(browser()->profile());
std::set<content::RenderFrameHost*> frame_hosts =
manager->GetRenderFrameHostsForExtension(extension->id());
- for (auto host : frame_hosts) {
+ for (auto* host : frame_hosts) {
if (host->GetFrameName() == "child_frame") {
frame_host = host;
break;
@@ -766,7 +777,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionOpenPopupOnPopup) {
// Open a new web popup window.
chrome::NavigateParams params(browser(), GURL("http://www.google.com/"),
ui::PAGE_TRANSITION_LINK);
- params.disposition = NEW_POPUP;
+ params.disposition = WindowOpenDisposition::NEW_POPUP;
params.window_action = chrome::NavigateParams::SHOW_WINDOW;
ui_test_utils::NavigateToURL(&params);
Browser* popup_browser = params.browser;
@@ -795,5 +806,217 @@ IN_PROC_BROWSER_TEST_F(BrowserActionApiTest, BrowserActionOpenPopupOnPopup) {
EXPECT_TRUE(catcher.GetNextResult()) << message_;
}
+class NavigatingExtensionPopupBrowserTest : public BrowserActionApiTest {
+ public:
+ const Extension& popup_extension() { return *popup_extension_; }
+ const Extension& other_extension() { return *other_extension_; }
+
+ void SetUpOnMainThread() override {
+ BrowserActionApiTest::SetUpOnMainThread();
+
+ host_resolver()->AddRule("*", "127.0.0.1");
+ ASSERT_TRUE(embedded_test_server()->Start());
+
+ // Load an extension with a pop-up.
+ ASSERT_TRUE(popup_extension_ = LoadExtension(test_data_dir_.AppendASCII(
+ "browser_action/popup_with_form")));
+
+ // Load another extension (that we can try navigating to).
+ ASSERT_TRUE(other_extension_ = LoadExtension(test_data_dir_.AppendASCII(
+ "browser_action/popup_with_iframe")));
+ }
+
+ enum ExpectedNavigationStatus {
+ EXPECTING_NAVIGATION_SUCCESS,
+ EXPECTING_NAVIGATION_FAILURE,
+ };
+
+ void TestPopupNavigationViaGet(
+ const GURL& target_url,
+ ExpectedNavigationStatus expected_navigation_status) {
+ std::string navigation_starting_script =
+ "window.location = '" + target_url.spec() + "';\n";
+ TestPopupNavigation(target_url, expected_navigation_status,
+ navigation_starting_script);
+ }
+
+ void TestPopupNavigationViaPost(
+ const GURL& target_url,
+ ExpectedNavigationStatus expected_navigation_status) {
+ std::string navigation_starting_script =
+ "var form = document.getElementById('form');\n"
+ "form.action = '" + target_url.spec() + "';\n"
+ "form.submit();\n";
+ TestPopupNavigation(target_url, expected_navigation_status,
+ navigation_starting_script);
+ }
+
+ private:
+ void TestPopupNavigation(const GURL& target_url,
+ ExpectedNavigationStatus expected_navigation_status,
+ std::string navigation_starting_script) {
+ // Were there any failures so far (e.g. in SetUpOnMainThread)?
+ ASSERT_FALSE(HasFailure());
+
+ // Simulate a click on the browser action to open the popup.
+ WebContents* popup = OpenPopup(0);
+ ASSERT_TRUE(popup);
+ GURL popup_url = popup_extension().GetResourceURL("popup.html");
+ EXPECT_EQ(popup_url, popup->GetLastCommittedURL());
+
+ // Note that the |setTimeout| call below is needed to make sure
+ // ExecuteScriptAndExtractBool returns *after* a scheduled navigation has
+ // already started.
+ std::string script_to_execute =
+ navigation_starting_script +
+ "setTimeout(\n"
+ " function() { window.domAutomationController.send(true); },\n"
+ " 0);\n";
+
+ // Try to navigate the pop-up.
+ bool ignored_script_result = false;
+ content::WebContentsDestroyedWatcher popup_destruction_watcher(popup);
+ EXPECT_TRUE(ExecuteScriptAndExtractBool(popup, script_to_execute,
+ &ignored_script_result));
+ popup = popup_destruction_watcher.web_contents();
+
+ // Verify if the popup navigation succeeded or failed as expected.
+ if (!popup) {
+ // If navigation ends up in a tab, then the tab will be focused and
+ // therefore the popup will be closed, destroying associated WebContents -
+ // don't do any verification in this case.
+ ADD_FAILURE() << "Navigation should not close extension pop-up";
+ } else {
+ // If the extension popup is still opened, then wait until there is no
+ // load in progress, and verify whether the navigation succeeded or not.
+ WaitForLoadStop(popup);
+ if (expected_navigation_status == EXPECTING_NAVIGATION_SUCCESS) {
+ EXPECT_EQ(target_url, popup->GetLastCommittedURL())
+ << "Navigation to " << target_url
+ << " should succeed in an extension pop-up";
+ } else {
+ EXPECT_NE(target_url, popup->GetLastCommittedURL())
+ << "Navigation to " << target_url
+ << " should fail in an extension pop-up";
+ EXPECT_THAT(
+ popup->GetLastCommittedURL(),
+ ::testing::AnyOf(::testing::Eq(popup_url),
+ ::testing::Eq(GURL("chrome-extension://invalid")),
+ ::testing::Eq(GURL("about:blank"))));
+ }
+
+ // Close the pop-up.
+ EXPECT_TRUE(GetBrowserActionsBar()->HidePopup());
+ popup_destruction_watcher.Wait();
+ }
+
+ // Make sure that the web navigation did not succeed somewhere outside of
+ // the extension popup (as it might if ExtensionViewHost::OpenURLFromTab
+ // forwards the navigation to Browser::OpenURL [which doesn't specify a
+ // source WebContents]).
+ TabStripModel* tabs = browser()->tab_strip_model();
+ for (int i = 0; i < tabs->count(); i++) {
+ WebContents* tab_contents = tabs->GetWebContentsAt(i);
+ WaitForLoadStop(tab_contents);
+ EXPECT_NE(target_url, tab_contents->GetLastCommittedURL())
+ << "Navigating an extension pop-up should not affect tabs.";
+ }
+ }
+
+ const Extension* popup_extension_;
+ const Extension* other_extension_;
+};
+
+// Tests that an extension pop-up cannot be navigated to a web page.
+IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest, Webpage) {
+ GURL web_url(embedded_test_server()->GetURL("foo.com", "/title1.html"));
+
+ // With and without --isolate-extension the GET request will be blocked in
+ // ExtensionViewHost::OpenURLFromTab (which silently drops navigations with
+ // CURRENT_TAB disposition).
+ TestPopupNavigationViaGet(web_url, EXPECTING_NAVIGATION_FAILURE);
+
+ // POST requests don't go through ExtensionViewHost::OpenURLFromTab.
+ //
+ // Without --isolate-extensions, there is no process transfer to isolate
+ // extensions into separate processes and therefore
+ // 1) navigating a popup extension to a webpage will succeed (because
+ // ExtensionViewHost::ShouldTransferNavigation won't get called when there
+ // is no transfer),
+ // 2) the webpage will stay in the same renderer process.
+ // This behavior is okay without --isolate-extensions (where webpages and
+ // extensions can coexist in the same process in other scenarios) - therefore
+ // no test verification is needed in this case.
+ //
+ // With --isolate-extensions the navigation should be blocked by
+ // ExtensionViewHost::ShouldTransferNavigation. Test verification is
+ // important in --isolate-extensions mode, because this mode is all about
+ // isolating extensions and webpages into separate processes and therefore we
+ // need to ensure the behavior described above doesn't occur (i.e. that
+ // instead the webpage navigation in an extension popup fails).
+ if (extensions::IsIsolateExtensionsEnabled())
+ TestPopupNavigationViaPost(web_url, EXPECTING_NAVIGATION_FAILURE);
+}
+
+// Tests that an extension pop-up can be navigated to another page
+// in the same extension.
+IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest,
+ PageInSameExtension) {
+ GURL other_page_in_same_extension =
+ popup_extension().GetResourceURL("other_page.html");
+ TestPopupNavigationViaGet(other_page_in_same_extension,
+ EXPECTING_NAVIGATION_SUCCESS);
+ TestPopupNavigationViaPost(other_page_in_same_extension,
+ EXPECTING_NAVIGATION_SUCCESS);
+}
+
+// Tests that an extension pop-up cannot be navigated to a page
+// in another extension.
+IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest,
+ PageInOtherExtension) {
+ GURL other_extension_url = other_extension().GetResourceURL("other.html");
+ TestPopupNavigationViaGet(other_extension_url, EXPECTING_NAVIGATION_FAILURE);
+ TestPopupNavigationViaPost(other_extension_url, EXPECTING_NAVIGATION_FAILURE);
+}
+
+// Tests that navigating an extension pop-up to a http URI that returns
+// Content-Disposition: attachment; filename=...
+// works: No navigation, but download shelf visible + download goes through.
+//
+// Note - there is no "...ViaGet" flavour of this test, because we don't care
+// (yet) if GET succeeds with the download or not (it probably should succeed
+// for consistency with POST, but it always failed in M54 and before). After
+// abandoing ShouldFork/OpenURL for all methods (not just for POST) [see comment
+// about https://crbug.com/646261 in ChromeContentRendererClient::ShouldFork]
+// GET should automagically start working for downloads.
+// TODO(lukasza): https://crbug.com/650694: Add a "Get" flavour of the test once
+// the download works both for GET and POST requests.
+IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest, DownloadViaPost) {
+ content::DownloadTestObserverTerminal downloads_observer(
+ content::BrowserContext::GetDownloadManager(browser()->profile()),
+ 1, // == wait_count (only waiting for "download-test3.gif").
+ content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
+
+ // Navigate to a URL that replies with
+ // Content-Disposition: attachment; filename=...
+ // header.
+ GURL download_url(
+ embedded_test_server()->GetURL("foo.com", "/download-test3.gif"));
+ TestPopupNavigationViaPost(download_url, EXPECTING_NAVIGATION_FAILURE);
+
+ // Verify that "download-test3.gif got downloaded.
+ downloads_observer.WaitForFinished();
+ EXPECT_EQ(0u, downloads_observer.NumDangerousDownloadsSeen());
+ EXPECT_EQ(1u, downloads_observer.NumDownloadsSeenInState(
+ content::DownloadItem::COMPLETE));
+
+ // The test verification below is applicable only to scenarios where the
+ // download shelf is supported - on ChromeOS, instead of the download shelf,
+ // there is a download notification in the right-bottom corner of the screen.
+#if !defined(OS_CHROMEOS)
+ EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
+#endif
+}
+
} // namespace
} // namespace extensions
diff --git a/chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc b/chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
index 009343c5d6d..35b9de583a7 100644
--- a/chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
+++ b/chromium/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
@@ -97,10 +97,10 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) {
content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
content::NotificationService::AllSources());
// Open a new window.
- new_browser = chrome::FindBrowserWithWebContents(
- browser()->OpenURL(content::OpenURLParams(
- GURL("about:"), content::Referrer(), NEW_WINDOW,
- ui::PAGE_TRANSITION_TYPED, false)));
+ new_browser = chrome::FindBrowserWithWebContents(browser()->OpenURL(
+ content::OpenURLParams(GURL("about:"), content::Referrer(),
+ WindowOpenDisposition::NEW_WINDOW,
+ ui::PAGE_TRANSITION_TYPED, false)));
// Hide all the buttons to test that it opens even when the browser action
// is in the overflow bucket.
ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0);
@@ -257,7 +257,14 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, BrowserClickClosesPopup1) {
}
// Test that the extension popup is closed when the browser window is clicked.
-IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, BrowserClickClosesPopup2) {
+#if defined(OS_WIN)
+// Flaky on Windows: http://crbug.com/639130
+#define MAYBE_BrowserClickClosesPopup2 DISABLED_BrowserClickClosesPopup2
+#else
+#define MAYBE_BrowserClickClosesPopup2 BrowserClickClosesPopup2
+#endif
+IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
+ MAYBE_BrowserClickClosesPopup2) {
if (!ShouldRunPopupTest())
return;
@@ -371,7 +378,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
// Create a new browser window to prevent the message loop from terminating.
browser()->OpenURL(content::OpenURLParams(GURL("about:"), content::Referrer(),
- NEW_WINDOW,
+ WindowOpenDisposition::NEW_WINDOW,
ui::PAGE_TRANSITION_TYPED, false));
// Forcibly closing the browser HWND should not cause a crash.