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

Side by Side Diff: chrome/browser/extensions/api/extension_action/browser_action_apitest.cc

Issue 2407513002: Using ScopedTempDir as the download directory used by the DownloadViaPost test. (Closed)
Patch Set: Inlined CreateAndSetDownloadsDirectory + added PathExists test assert. Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 // works: No navigation, but download shelf visible + download goes through. 989 // works: No navigation, but download shelf visible + download goes through.
985 // 990 //
986 // Note - there is no "...ViaGet" flavour of this test, because we don't care 991 // 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 992 // (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 993 // 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 994 // abandoing ShouldFork/OpenURL for all methods (not just for POST) [see comment
990 // about https://crbug.com/646261 in ChromeContentRendererClient::ShouldFork] 995 // about https://crbug.com/646261 in ChromeContentRendererClient::ShouldFork]
991 // GET should automagically start working for downloads. 996 // GET should automagically start working for downloads.
992 // TODO(lukasza): https://crbug.com/650694: Add a "Get" flavour of the test once 997 // TODO(lukasza): https://crbug.com/650694: Add a "Get" flavour of the test once
993 // the download works both for GET and POST requests. 998 // the download works both for GET and POST requests.
999 IN_PROC_BROWSER_TEST_F(NavigatingExtensionPopupBrowserTest, DownloadViaPost) {
1000 // Override the default downloads directory, so that the test can cleanup
1001 // after itself. This section is based on CreateAndSetDownloadsDirectory
1002 // method defined in a few other source files with tests.
1003 base::ScopedTempDir downloads_directory;
1004 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir());
1005 browser()->profile()->GetPrefs()->SetFilePath(
1006 prefs::kDownloadDefaultDirectory, downloads_directory.GetPath());
1007 browser()->profile()->GetPrefs()->SetFilePath(
1008 prefs::kSaveFileDefaultDirectory, downloads_directory.GetPath());
994 1009
995 // Disabled on Windows. See http://crbug.com/653856. 1010 // Setup monitoring of the downloads.
996 #if defined(OS_WIN)
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( 1011 content::DownloadTestObserverTerminal downloads_observer(
1005 content::BrowserContext::GetDownloadManager(browser()->profile()), 1012 content::BrowserContext::GetDownloadManager(browser()->profile()),
1006 1, // == wait_count (only waiting for "download-test3.gif"). 1013 1, // == wait_count (only waiting for "download-test3.gif").
1007 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 1014 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
1008 1015
1009 // Navigate to a URL that replies with 1016 // Navigate to a URL that replies with
1010 // Content-Disposition: attachment; filename=... 1017 // Content-Disposition: attachment; filename=...
1011 // header. 1018 // header.
1012 GURL download_url( 1019 GURL download_url(
1013 embedded_test_server()->GetURL("foo.com", "/download-test3.gif")); 1020 embedded_test_server()->GetURL("foo.com", "/download-test3.gif"));
1014 TestPopupNavigationViaPost(download_url, EXPECTING_NAVIGATION_FAILURE); 1021 TestPopupNavigationViaPost(download_url, EXPECTING_NAVIGATION_FAILURE);
1015 1022
1016 // Verify that "download-test3.gif got downloaded. 1023 // Verify that "download-test3.gif got downloaded.
1017 downloads_observer.WaitForFinished(); 1024 downloads_observer.WaitForFinished();
1018 EXPECT_EQ(0u, downloads_observer.NumDangerousDownloadsSeen()); 1025 EXPECT_EQ(0u, downloads_observer.NumDangerousDownloadsSeen());
1019 EXPECT_EQ(1u, downloads_observer.NumDownloadsSeenInState( 1026 EXPECT_EQ(1u, downloads_observer.NumDownloadsSeenInState(
1020 content::DownloadItem::COMPLETE)); 1027 content::DownloadItem::COMPLETE));
1028 EXPECT_TRUE(base::PathExists(downloads_directory.GetPath().AppendASCII(
1029 "download-test3-attachment.gif")));
Łukasz Anforowicz 2016/10/07 23:32:03 Inlining / having |downloads_directory| right here
1021 1030
1022 // The test verification below is applicable only to scenarios where the 1031 // The test verification below is applicable only to scenarios where the
1023 // download shelf is supported - on ChromeOS, instead of the download shelf, 1032 // 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. 1033 // there is a download notification in the right-bottom corner of the screen.
1025 #if !defined(OS_CHROMEOS) 1034 #if !defined(OS_CHROMEOS)
1026 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1035 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1027 #endif 1036 #endif
1028 } 1037 }
1029 1038
1030 } // namespace 1039 } // namespace
1031 } // namespace extensions 1040 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698