| Index: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
|
| diff --git a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
|
| index da79d2e5d26df0ac300c98ed66458ca757ba68a8..e464c23f3f4c8a01401436984088bacc9e5275f6 100644
|
| --- a/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
|
| +++ b/chrome/browser/extensions/api/extension_action/browser_action_apitest.cc
|
| @@ -10,6 +10,7 @@
|
| #include "base/macros.h"
|
| #include "base/threading/thread_restrictions.h"
|
| #include "build/build_config.h"
|
| +#include "chrome/browser/download/download_shelf.h"
|
| #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
|
| #include "chrome/browser/extensions/browser_action_test_util.h"
|
| #include "chrome/browser/extensions/extension_action.h"
|
| @@ -26,7 +27,6 @@
|
| #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/pref_names.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| @@ -856,24 +856,38 @@ class NavigatingExtensionPopupBrowserTest : public BrowserActionApiTest {
|
| 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);
|
| + CreateNavigationScriptForGet(target_url));
|
| }
|
|
|
| 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);
|
| + CreateNavigationScriptForPost(target_url));
|
| + }
|
| +
|
| + void TestPopupDownloadViaGet(const GURL& target_url) {
|
| + TestPopupDownload(target_url, CreateNavigationScriptForGet(target_url));
|
| + }
|
| +
|
| + void TestPopupDownloadViaPost(const GURL& target_url) {
|
| + TestPopupDownload(target_url, CreateNavigationScriptForPost(target_url));
|
| }
|
|
|
| private:
|
| + std::string CreateNavigationScriptForGet(const GURL& target_url) {
|
| + return "window.location = '" + target_url.spec() + "';\n";
|
| + }
|
| +
|
| + std::string CreateNavigationScriptForPost(const GURL& target_url) {
|
| + return "var form = document.getElementById('form');\n"
|
| + "form.action = '" +
|
| + target_url.spec() +
|
| + "';\n"
|
| + "form.submit();\n";
|
| + }
|
| +
|
| void TestPopupNavigation(const GURL& target_url,
|
| ExpectedNavigationStatus expected_navigation_status,
|
| std::string navigation_starting_script) {
|
| @@ -945,6 +959,44 @@ class NavigatingExtensionPopupBrowserTest : public BrowserActionApiTest {
|
| }
|
| }
|
|
|
| + void TestPopupDownload(const GURL& target_url,
|
| + std::string navigation_starting_script) {
|
| + content::DownloadTestObserverTerminal downloads_observer(
|
| + content::BrowserContext::GetDownloadManager(browser()->profile()),
|
| + 1, // == wait_count (only waiting for a single file).
|
| + content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
|
| +
|
| + // Override the default downloads directory, so that the test can cleanup
|
| + // after itself. This section is based on CreateAndSetDownloadsDirectory
|
| + // method defined in a few other source files with tests.
|
| + std::unique_ptr<base::ScopedTempDir> downloads_directory =
|
| + CreateAndSetDownloadsDirectory(browser()->profile()->GetPrefs());
|
| + ASSERT_TRUE(downloads_directory);
|
| +
|
| + // Navigate to a URL that will trigger a download (i.e. by replying with
|
| + // Content-Disposition: attachment; filename=...
|
| + // header).
|
| + TestPopupNavigation(target_url, EXPECTING_NAVIGATION_FAILURE,
|
| + navigation_starting_script);
|
| +
|
| + // Verify that a single file got downloaded.
|
| + downloads_observer.WaitForFinished();
|
| + EXPECT_EQ(0u, downloads_observer.NumDangerousDownloadsSeen());
|
| + EXPECT_EQ(1u, downloads_observer.NumDownloadsSeenInState(
|
| + content::DownloadItem::COMPLETE));
|
| + EXPECT_TRUE(base::PathExists(downloads_directory->GetPath().AppendASCII(
|
| + "download-test3-attachment.gif")));
|
| +
|
| +#if !defined(OS_CHROMEOS)
|
| + // 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.
|
| + EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
|
| + browser()->window()->GetDownloadShelf()->Hide();
|
| +#endif
|
| + }
|
| +
|
| const Extension* popup_extension_;
|
| const Extension* other_extension_;
|
| };
|
| @@ -985,51 +1037,14 @@ IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest,
|
| // 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) {
|
| - // Override the default downloads directory, so that the test can cleanup
|
| - // after itself. This section is based on CreateAndSetDownloadsDirectory
|
| - // method defined in a few other source files with tests.
|
| - base::ThreadRestrictions::ScopedAllowIO allow_io;
|
| - std::unique_ptr<base::ScopedTempDir> downloads_directory =
|
| - CreateAndSetDownloadsDirectory(browser()->profile()->GetPrefs());
|
| - ASSERT_TRUE(downloads_directory);
|
| -
|
| - // Setup monitoring of the downloads.
|
| - content::DownloadTestObserverTerminal downloads_observer(
|
| - content::BrowserContext::GetDownloadManager(browser()->profile()),
|
| - 1, // == wait_count (only waiting for "download-test3.gif").
|
| - content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
|
| -
|
| +IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest, Download) {
|
| // 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));
|
| - EXPECT_TRUE(base::PathExists(downloads_directory->GetPath().AppendASCII(
|
| - "download-test3-attachment.gif")));
|
| -
|
| - // 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
|
| + TestPopupDownloadViaGet(download_url);
|
| + TestPopupDownloadViaPost(download_url);
|
| }
|
|
|
| } // namespace
|
|
|