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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "components/history/core/browser/history_types.h" | 30 #include "components/history/core/browser/history_types.h" |
31 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
32 #include "components/sync_preferences/testing_pref_service_syncable.h" | 32 #include "components/sync_preferences/testing_pref_service_syncable.h" |
33 #include "content/public/browser/download_interrupt_reasons.h" | 33 #include "content/public/browser/download_interrupt_reasons.h" |
34 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
36 #include "content/public/browser/web_contents_delegate.h" | 36 #include "content/public/browser/web_contents_delegate.h" |
37 #include "content/public/test/mock_download_item.h" | 37 #include "content/public/test/mock_download_item.h" |
38 #include "content/public/test/test_renderer_host.h" | 38 #include "content/public/test/test_renderer_host.h" |
39 #include "content/public/test/web_contents_tester.h" | 39 #include "content/public/test/web_contents_tester.h" |
| 40 #include "extensions/features/features.h" |
40 #include "net/base/mime_util.h" | 41 #include "net/base/mime_util.h" |
41 #include "testing/gmock/include/gmock/gmock.h" | 42 #include "testing/gmock/include/gmock/gmock.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
43 #include "url/origin.h" | 44 #include "url/origin.h" |
44 | 45 |
45 #if defined(ENABLE_PLUGINS) | 46 #if defined(ENABLE_PLUGINS) |
46 #include "content/public/browser/plugin_service.h" | 47 #include "content/public/browser/plugin_service.h" |
47 #include "content/public/browser/plugin_service_filter.h" | 48 #include "content/public/browser/plugin_service_filter.h" |
48 #include "content/public/common/webplugininfo.h" | 49 #include "content/public/common/webplugininfo.h" |
49 #endif | 50 #endif |
50 | 51 |
51 #if defined(ENABLE_EXTENSIONS) | 52 #if BUILDFLAG(ENABLE_EXTENSIONS) |
52 #include "extensions/common/extension.h" | 53 #include "extensions/common/extension.h" |
53 #endif | 54 #endif |
54 | 55 |
55 using ::testing::AnyNumber; | 56 using ::testing::AnyNumber; |
56 using ::testing::Invoke; | 57 using ::testing::Invoke; |
57 using ::testing::Ref; | 58 using ::testing::Ref; |
58 using ::testing::Return; | 59 using ::testing::Return; |
59 using ::testing::ReturnRef; | 60 using ::testing::ReturnRef; |
60 using ::testing::ReturnRefOfCopy; | 61 using ::testing::ReturnRefOfCopy; |
61 using ::testing::Truly; | 62 using ::testing::Truly; |
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 }; | 1207 }; |
1207 | 1208 |
1208 SetPromptForDownload(true); | 1209 SetPromptForDownload(true); |
1209 EnableAutoOpenBasedOnExtension( | 1210 EnableAutoOpenBasedOnExtension( |
1210 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); | 1211 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); |
1211 RunTestCasesWithActiveItem(kPromptingTestCases, | 1212 RunTestCasesWithActiveItem(kPromptingTestCases, |
1212 arraysize(kPromptingTestCases)); | 1213 arraysize(kPromptingTestCases)); |
1213 } | 1214 } |
1214 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | 1215 #endif // !BUILDFLAG(ANDROID_JAVA_UI) |
1215 | 1216 |
1216 #if defined(ENABLE_EXTENSIONS) | 1217 #if BUILDFLAG(ENABLE_EXTENSIONS) |
1217 // These test cases are run with "Prompt for download" user preference set to | 1218 // These test cases are run with "Prompt for download" user preference set to |
1218 // true. Automatic extension downloads shouldn't cause prompting. | 1219 // true. Automatic extension downloads shouldn't cause prompting. |
1219 // Android doesn't support extensions. | 1220 // Android doesn't support extensions. |
1220 TEST_F(DownloadTargetDeterminerTest, PromptAlways_Extension) { | 1221 TEST_F(DownloadTargetDeterminerTest, PromptAlways_Extension) { |
1221 const DownloadTestCase kPromptingTestCases[] = { | 1222 const DownloadTestCase kPromptingTestCases[] = { |
1222 {// 0: Automatic Browser Extension download. - Shouldn't prompt for browser | 1223 {// 0: Automatic Browser Extension download. - Shouldn't prompt for browser |
1223 // extension downloads even if "Prompt for download" preference is set. | 1224 // extension downloads even if "Prompt for download" preference is set. |
1224 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1225 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
1225 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", | 1226 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", |
1226 extensions::Extension::kMimeType, FILE_PATH_LITERAL(""), | 1227 extensions::Extension::kMimeType, FILE_PATH_LITERAL(""), |
(...skipping 25 matching lines...) Expand all Loading... |
1252 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1253 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
1253 | 1254 |
1254 EXPECT_CRDOWNLOAD}, | 1255 EXPECT_CRDOWNLOAD}, |
1255 #endif | 1256 #endif |
1256 }; | 1257 }; |
1257 | 1258 |
1258 SetPromptForDownload(true); | 1259 SetPromptForDownload(true); |
1259 RunTestCasesWithActiveItem(kPromptingTestCases, | 1260 RunTestCasesWithActiveItem(kPromptingTestCases, |
1260 arraysize(kPromptingTestCases)); | 1261 arraysize(kPromptingTestCases)); |
1261 } | 1262 } |
1262 #endif // defined(ENABLE_EXTENSIONS) | 1263 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
1263 | 1264 |
1264 // If the download path is managed, then we don't show any prompts. | 1265 // If the download path is managed, then we don't show any prompts. |
1265 // Note that if the download path is managed, then PromptForDownload() is false. | 1266 // Note that if the download path is managed, then PromptForDownload() is false. |
1266 TEST_F(DownloadTargetDeterminerTest, ManagedPath) { | 1267 TEST_F(DownloadTargetDeterminerTest, ManagedPath) { |
1267 const DownloadTestCase kManagedPathTestCases[] = { | 1268 const DownloadTestCase kManagedPathTestCases[] = { |
1268 {// 0: Automatic Safe | 1269 {// 0: Automatic Safe |
1269 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1270 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
1270 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1271 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
1271 "text/plain", FILE_PATH_LITERAL(""), | 1272 "text/plain", FILE_PATH_LITERAL(""), |
1272 | 1273 |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2158 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) | 2159 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) |
2159 .WillRepeatedly(Return(false)); | 2160 .WillRepeatedly(Return(false)); |
2160 target_info = RunDownloadTargetDeterminer( | 2161 target_info = RunDownloadTargetDeterminer( |
2161 GetPathInDownloadDir(kInitialPath), item.get()); | 2162 GetPathInDownloadDir(kInitialPath), item.get()); |
2162 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2163 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
2163 } | 2164 } |
2164 | 2165 |
2165 #endif // defined(ENABLE_PLUGINS) | 2166 #endif // defined(ENABLE_PLUGINS) |
2166 | 2167 |
2167 } // namespace | 2168 } // namespace |
OLD | NEW |