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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #if defined(ENABLE_PLUGINS) | 40 #if defined(ENABLE_PLUGINS) |
41 #include "content/public/browser/plugin_service.h" | 41 #include "content/public/browser/plugin_service.h" |
42 #include "content/public/browser/plugin_service_filter.h" | 42 #include "content/public/browser/plugin_service_filter.h" |
43 #include "content/public/common/webplugininfo.h" | 43 #include "content/public/common/webplugininfo.h" |
44 #endif | 44 #endif |
45 | 45 |
46 #if defined(ENABLE_EXTENSIONS) | 46 #if defined(ENABLE_EXTENSIONS) |
47 #include "extensions/common/extension.h" | 47 #include "extensions/common/extension.h" |
48 #endif | 48 #endif |
49 | 49 |
| 50 #if defined(OS_ANDROID) |
| 51 #include "content/public/browser/android/download_controller_android.h" |
| 52 #endif |
| 53 |
50 using ::testing::AnyNumber; | 54 using ::testing::AnyNumber; |
51 using ::testing::Invoke; | 55 using ::testing::Invoke; |
52 using ::testing::Ref; | 56 using ::testing::Ref; |
53 using ::testing::Return; | 57 using ::testing::Return; |
54 using ::testing::ReturnRef; | 58 using ::testing::ReturnRef; |
55 using ::testing::ReturnRefOfCopy; | 59 using ::testing::ReturnRefOfCopy; |
56 using ::testing::Truly; | 60 using ::testing::Truly; |
57 using ::testing::WithArg; | 61 using ::testing::WithArg; |
58 using ::testing::_; | 62 using ::testing::_; |
59 using content::DownloadItem; | 63 using content::DownloadItem; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 271 |
268 void DownloadTargetDeterminerTest::SetUp() { | 272 void DownloadTargetDeterminerTest::SetUp() { |
269 ChromeRenderViewHostTestHarness::SetUp(); | 273 ChromeRenderViewHostTestHarness::SetUp(); |
270 CHECK(profile()); | 274 CHECK(profile()); |
271 download_prefs_.reset(new DownloadPrefs(profile())); | 275 download_prefs_.reset(new DownloadPrefs(profile())); |
272 web_contents()->SetDelegate(&web_contents_delegate_); | 276 web_contents()->SetDelegate(&web_contents_delegate_); |
273 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 277 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
274 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); | 278 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); |
275 download_prefs_->SetDownloadPath(test_download_dir()); | 279 download_prefs_->SetDownloadPath(test_download_dir()); |
276 delegate_.SetupDefaults(); | 280 delegate_.SetupDefaults(); |
| 281 #if defined(OS_ANDROID) |
| 282 content::DownloadControllerAndroid::UseMockControllerForTesting(true); |
| 283 #endif |
277 } | 284 } |
278 | 285 |
279 void DownloadTargetDeterminerTest::TearDown() { | 286 void DownloadTargetDeterminerTest::TearDown() { |
280 download_prefs_.reset(); | 287 download_prefs_.reset(); |
| 288 #if defined(OS_ANDROID) |
| 289 content::DownloadControllerAndroid::Get()-> |
| 290 SetApproveFileAccessRequestForTesting(true); |
| 291 content::DownloadControllerAndroid::UseMockControllerForTesting(false); |
| 292 #endif |
281 ChromeRenderViewHostTestHarness::TearDown(); | 293 ChromeRenderViewHostTestHarness::TearDown(); |
282 } | 294 } |
283 | 295 |
284 content::MockDownloadItem* | 296 content::MockDownloadItem* |
285 DownloadTargetDeterminerTest::CreateActiveDownloadItem( | 297 DownloadTargetDeterminerTest::CreateActiveDownloadItem( |
286 int32 id, | 298 int32 id, |
287 const DownloadTestCase& test_case) { | 299 const DownloadTestCase& test_case) { |
288 content::MockDownloadItem* item = | 300 content::MockDownloadItem* item = |
289 new ::testing::NiceMock<content::MockDownloadItem>(); | 301 new ::testing::NiceMock<content::MockDownloadItem>(); |
290 GURL download_url(test_case.url); | 302 GURL download_url(test_case.url); |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 }, | 1159 }, |
1148 }; | 1160 }; |
1149 | 1161 |
1150 SetPromptForDownload(true); | 1162 SetPromptForDownload(true); |
1151 EnableAutoOpenBasedOnExtension( | 1163 EnableAutoOpenBasedOnExtension( |
1152 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); | 1164 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); |
1153 RunTestCasesWithActiveItem(kPromptingTestCases, | 1165 RunTestCasesWithActiveItem(kPromptingTestCases, |
1154 arraysize(kPromptingTestCases)); | 1166 arraysize(kPromptingTestCases)); |
1155 } | 1167 } |
1156 | 1168 |
| 1169 #if defined(OS_ANDROID) |
| 1170 TEST_F(DownloadTargetDeterminerTest, |
| 1171 TargetDeterminer_DisapprovePromptForUserPermission) { |
| 1172 const DownloadTestCase kUserPermissionTestCases[] = { |
| 1173 { |
| 1174 // 0: Automatic Safe |
| 1175 AUTOMATIC, |
| 1176 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1177 "http://example.com/foo.txt", "text/plain", |
| 1178 FILE_PATH_LITERAL(""), |
| 1179 |
| 1180 FILE_PATH_LITERAL(""), |
| 1181 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1182 |
| 1183 EXPECT_LOCAL_PATH |
| 1184 }, |
| 1185 }; |
| 1186 content::DownloadControllerAndroid::Get()-> |
| 1187 SetApproveFileAccessRequestForTesting(false); |
| 1188 RunTestCasesWithActiveItem(kUserPermissionTestCases, |
| 1189 arraysize(kUserPermissionTestCases)); |
| 1190 } |
| 1191 #endif |
| 1192 |
1157 #if defined(ENABLE_EXTENSIONS) | 1193 #if defined(ENABLE_EXTENSIONS) |
1158 // These test cases are run with "Prompt for download" user preference set to | 1194 // These test cases are run with "Prompt for download" user preference set to |
1159 // true. Automatic extension downloads shouldn't cause prompting. | 1195 // true. Automatic extension downloads shouldn't cause prompting. |
1160 // Android doesn't support extensions. | 1196 // Android doesn't support extensions. |
1161 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) { | 1197 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) { |
1162 const DownloadTestCase kPromptingTestCases[] = { | 1198 const DownloadTestCase kPromptingTestCases[] = { |
1163 { | 1199 { |
1164 // 0: Automatic Browser Extension download. - Shouldn't prompt for browser | 1200 // 0: Automatic Browser Extension download. - Shouldn't prompt for browser |
1165 // extension downloads even if "Prompt for download" preference is set. | 1201 // extension downloads even if "Prompt for download" preference is set. |
1166 AUTOMATIC, | 1202 AUTOMATIC, |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2239 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) | 2275 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) |
2240 .WillRepeatedly(Return(true)); | 2276 .WillRepeatedly(Return(true)); |
2241 | 2277 |
2242 target_info = RunDownloadTargetDeterminer( | 2278 target_info = RunDownloadTargetDeterminer( |
2243 GetPathInDownloadDir(kInitialPath), item.get()); | 2279 GetPathInDownloadDir(kInitialPath), item.get()); |
2244 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2280 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
2245 } | 2281 } |
2246 #endif // defined(ENABLE_PLUGINS) | 2282 #endif // defined(ENABLE_PLUGINS) |
2247 | 2283 |
2248 } // namespace | 2284 } // namespace |
OLD | NEW |