| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/macros.h" | 10 #include "base/macros.h" |
| 8 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 9 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 12 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 10 #include "chrome/browser/extensions/browser_action_test_util.h" | 13 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 11 #include "chrome/browser/extensions/extension_action.h" | 14 #include "chrome/browser/extensions/extension_action.h" |
| 12 #include "chrome/browser/extensions/extension_action_icon_factory.h" | 15 #include "chrome/browser/extensions/extension_action_icon_factory.h" |
| 13 #include "chrome/browser/extensions/extension_action_manager.h" | 16 #include "chrome/browser/extensions/extension_action_manager.h" |
| 14 #include "chrome/browser/extensions/extension_action_runner.h" | 17 #include "chrome/browser/extensions/extension_action_runner.h" |
| 15 #include "chrome/browser/extensions/extension_apitest.h" | 18 #include "chrome/browser/extensions/extension_apitest.h" |
| 16 #include "chrome/browser/extensions/extension_tab_util.h" | 19 #include "chrome/browser/extensions/extension_tab_util.h" |
| 17 #include "chrome/browser/extensions/extension_util.h" | 20 #include "chrome/browser/extensions/extension_util.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
| 22 #include "chrome/browser/ui/browser_navigator_params.h" | 25 #include "chrome/browser/ui/browser_navigator_params.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/common/extensions/extension_process_policy.h" | 28 #include "chrome/common/extensions/extension_process_policy.h" |
| 29 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 32 #include "components/prefs/pref_service.h" |
| 28 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
| 29 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
| 31 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/test/browser_test_utils.h" | 37 #include "content/public/test/browser_test_utils.h" |
| 33 #include "content/public/test/content_browser_test_utils.h" | 38 #include "content/public/test/content_browser_test_utils.h" |
| 34 #include "content/public/test/download_test_observer.h" | 39 #include "content/public/test/download_test_observer.h" |
| 35 #include "content/public/test/test_utils.h" | 40 #include "content/public/test/test_utils.h" |
| 36 #include "extensions/browser/extension_registry.h" | 41 #include "extensions/browser/extension_registry.h" |
| 37 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 | 62 |
| 58 namespace extensions { | 63 namespace extensions { |
| 59 namespace { | 64 namespace { |
| 60 | 65 |
| 61 void ExecuteExtensionAction(Browser* browser, const Extension* extension) { | 66 void ExecuteExtensionAction(Browser* browser, const Extension* extension) { |
| 62 ExtensionActionRunner::GetForWebContents( | 67 ExtensionActionRunner::GetForWebContents( |
| 63 browser->tab_strip_model()->GetActiveWebContents()) | 68 browser->tab_strip_model()->GetActiveWebContents()) |
| 64 ->RunAction(extension, true); | 69 ->RunAction(extension, true); |
| 65 } | 70 } |
| 66 | 71 |
| 72 std::unique_ptr<base::ScopedTempDir> CreateAndSetDownloadsDirectory( |
| 73 PrefService* pref_service) { |
| 74 std::unique_ptr<base::ScopedTempDir> dir(new base::ScopedTempDir); |
| 75 |
| 76 if (!dir->CreateUniqueTempDir()) |
| 77 return nullptr; |
| 78 |
| 79 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, dir->GetPath()); |
| 80 pref_service->SetFilePath(prefs::kSaveFileDefaultDirectory, dir->GetPath()); |
| 81 return dir; |
| 82 } |
| 83 |
| 67 // An ImageSkia source that will do nothing (i.e., have a blank skia). We need | 84 // An ImageSkia source that will do nothing (i.e., have a blank skia). We need |
| 68 // this because we need a blank canvas at a certain size, and that can't be done | 85 // this because we need a blank canvas at a certain size, and that can't be done |
| 69 // by just using a null ImageSkia. | 86 // by just using a null ImageSkia. |
| 70 class BlankImageSource : public gfx::CanvasImageSource { | 87 class BlankImageSource : public gfx::CanvasImageSource { |
| 71 public: | 88 public: |
| 72 explicit BlankImageSource(const gfx::Size& size) | 89 explicit BlankImageSource(const gfx::Size& size) |
| 73 : gfx::CanvasImageSource(size, false) {} | 90 : gfx::CanvasImageSource(size, false) {} |
| 74 ~BlankImageSource() override {} | 91 ~BlankImageSource() override {} |
| 75 | 92 |
| 76 void Draw(gfx::Canvas* canvas) override {} | 93 void Draw(gfx::Canvas* canvas) override {} |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 // works: No navigation, but download shelf visible + download goes through. | 1001 // works: No navigation, but download shelf visible + download goes through. |
| 985 // | 1002 // |
| 986 // Note - there is no "...ViaGet" flavour of this test, because we don't care | 1003 // Note - there is no "...ViaGet" flavour of this test, because we don't care |
| 987 // (yet) if GET succeeds with the download or not (it probably should succeed | 1004 // (yet) if GET succeeds with the download or not (it probably should succeed |
| 988 // for consistency with POST, but it always failed in M54 and before). After | 1005 // for consistency with POST, but it always failed in M54 and before). After |
| 989 // abandoing ShouldFork/OpenURL for all methods (not just for POST) [see comment | 1006 // abandoing ShouldFork/OpenURL for all methods (not just for POST) [see comment |
| 990 // about https://crbug.com/646261 in ChromeContentRendererClient::ShouldFork] | 1007 // about https://crbug.com/646261 in ChromeContentRendererClient::ShouldFork] |
| 991 // GET should automagically start working for downloads. | 1008 // GET should automagically start working for downloads. |
| 992 // TODO(lukasza): https://crbug.com/650694: Add a "Get" flavour of the test once | 1009 // TODO(lukasza): https://crbug.com/650694: Add a "Get" flavour of the test once |
| 993 // the download works both for GET and POST requests. | 1010 // the download works both for GET and POST requests. |
| 1011 IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest, DownloadViaPost) { |
| 1012 // Override the default downloads directory, so that the test can cleanup |
| 1013 // after itself. This section is based on CreateAndSetDownloadsDirectory |
| 1014 // method defined in a few other source files with tests. |
| 1015 std::unique_ptr<base::ScopedTempDir> downloads_directory = |
| 1016 CreateAndSetDownloadsDirectory(browser()->profile()->GetPrefs()); |
| 1017 ASSERT_TRUE(downloads_directory); |
| 994 | 1018 |
| 995 // Disabled on Windows and Mac. See http://crbug.com/653856. | 1019 // Setup monitoring of the downloads. |
| 996 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 997 #define MAYBE_DownloadViaPost DISABLED_DownloadViaPost | |
| 998 #else | |
| 999 #define MAYBE_DownloadViaPost DownloadViaPost | |
| 1000 #endif | |
| 1001 | |
| 1002 IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest, | |
| 1003 MAYBE_DownloadViaPost) { | |
| 1004 content::DownloadTestObserverTerminal downloads_observer( | 1020 content::DownloadTestObserverTerminal downloads_observer( |
| 1005 content::BrowserContext::GetDownloadManager(browser()->profile()), | 1021 content::BrowserContext::GetDownloadManager(browser()->profile()), |
| 1006 1, // == wait_count (only waiting for "download-test3.gif"). | 1022 1, // == wait_count (only waiting for "download-test3.gif"). |
| 1007 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 1023 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 1008 | 1024 |
| 1009 // Navigate to a URL that replies with | 1025 // Navigate to a URL that replies with |
| 1010 // Content-Disposition: attachment; filename=... | 1026 // Content-Disposition: attachment; filename=... |
| 1011 // header. | 1027 // header. |
| 1012 GURL download_url( | 1028 GURL download_url( |
| 1013 embedded_test_server()->GetURL("foo.com", "/download-test3.gif")); | 1029 embedded_test_server()->GetURL("foo.com", "/download-test3.gif")); |
| 1014 TestPopupNavigationViaPost(download_url, EXPECTING_NAVIGATION_FAILURE); | 1030 TestPopupNavigationViaPost(download_url, EXPECTING_NAVIGATION_FAILURE); |
| 1015 | 1031 |
| 1016 // Verify that "download-test3.gif got downloaded. | 1032 // Verify that "download-test3.gif got downloaded. |
| 1017 downloads_observer.WaitForFinished(); | 1033 downloads_observer.WaitForFinished(); |
| 1018 EXPECT_EQ(0u, downloads_observer.NumDangerousDownloadsSeen()); | 1034 EXPECT_EQ(0u, downloads_observer.NumDangerousDownloadsSeen()); |
| 1019 EXPECT_EQ(1u, downloads_observer.NumDownloadsSeenInState( | 1035 EXPECT_EQ(1u, downloads_observer.NumDownloadsSeenInState( |
| 1020 content::DownloadItem::COMPLETE)); | 1036 content::DownloadItem::COMPLETE)); |
| 1037 EXPECT_TRUE(base::PathExists(downloads_directory->GetPath().AppendASCII( |
| 1038 "download-test3-attachment.gif"))); |
| 1021 | 1039 |
| 1022 // The test verification below is applicable only to scenarios where the | 1040 // The test verification below is applicable only to scenarios where the |
| 1023 // download shelf is supported - on ChromeOS, instead of the download shelf, | 1041 // download shelf is supported - on ChromeOS, instead of the download shelf, |
| 1024 // there is a download notification in the right-bottom corner of the screen. | 1042 // there is a download notification in the right-bottom corner of the screen. |
| 1025 #if !defined(OS_CHROMEOS) | 1043 #if !defined(OS_CHROMEOS) |
| 1026 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1044 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1027 #endif | 1045 #endif |
| 1028 } | 1046 } |
| 1029 | 1047 |
| 1030 } // namespace | 1048 } // namespace |
| 1031 } // namespace extensions | 1049 } // namespace extensions |
| OLD | NEW |