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 "chrome/browser/android/download/mock_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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 254 } |
251 | 255 |
252 MockDownloadTargetDeterminerDelegate* delegate() { | 256 MockDownloadTargetDeterminerDelegate* delegate() { |
253 return &delegate_; | 257 return &delegate_; |
254 } | 258 } |
255 | 259 |
256 DownloadPrefs* download_prefs() { | 260 DownloadPrefs* download_prefs() { |
257 return download_prefs_.get(); | 261 return download_prefs_.get(); |
258 } | 262 } |
259 | 263 |
| 264 #if defined(OS_ANDROID) |
| 265 chrome::android::MockDownloadControllerAndroid* download_controller() { |
| 266 return &download_controller_; |
| 267 } |
| 268 #endif |
| 269 |
260 private: | 270 private: |
261 scoped_ptr<DownloadPrefs> download_prefs_; | 271 scoped_ptr<DownloadPrefs> download_prefs_; |
262 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; | 272 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; |
263 NullWebContentsDelegate web_contents_delegate_; | 273 NullWebContentsDelegate web_contents_delegate_; |
264 base::ScopedTempDir test_download_dir_; | 274 base::ScopedTempDir test_download_dir_; |
265 base::FilePath test_virtual_dir_; | 275 base::FilePath test_virtual_dir_; |
| 276 #if defined(OS_ANDROID) |
| 277 chrome::android::MockDownloadControllerAndroid download_controller_; |
| 278 #endif |
266 }; | 279 }; |
267 | 280 |
268 void DownloadTargetDeterminerTest::SetUp() { | 281 void DownloadTargetDeterminerTest::SetUp() { |
269 ChromeRenderViewHostTestHarness::SetUp(); | 282 ChromeRenderViewHostTestHarness::SetUp(); |
270 CHECK(profile()); | 283 CHECK(profile()); |
271 download_prefs_.reset(new DownloadPrefs(profile())); | 284 download_prefs_.reset(new DownloadPrefs(profile())); |
272 web_contents()->SetDelegate(&web_contents_delegate_); | 285 web_contents()->SetDelegate(&web_contents_delegate_); |
273 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 286 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
274 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); | 287 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); |
275 download_prefs_->SetDownloadPath(test_download_dir()); | 288 download_prefs_->SetDownloadPath(test_download_dir()); |
276 delegate_.SetupDefaults(); | 289 delegate_.SetupDefaults(); |
| 290 #if defined(OS_ANDROID) |
| 291 content::DownloadControllerAndroid::SetDownloadControllerAndroid( |
| 292 &download_controller_); |
| 293 #endif |
277 } | 294 } |
278 | 295 |
279 void DownloadTargetDeterminerTest::TearDown() { | 296 void DownloadTargetDeterminerTest::TearDown() { |
280 download_prefs_.reset(); | 297 download_prefs_.reset(); |
| 298 #if defined(OS_ANDROID) |
| 299 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr); |
| 300 #endif |
281 ChromeRenderViewHostTestHarness::TearDown(); | 301 ChromeRenderViewHostTestHarness::TearDown(); |
282 } | 302 } |
283 | 303 |
284 content::MockDownloadItem* | 304 content::MockDownloadItem* |
285 DownloadTargetDeterminerTest::CreateActiveDownloadItem( | 305 DownloadTargetDeterminerTest::CreateActiveDownloadItem( |
286 int32 id, | 306 int32 id, |
287 const DownloadTestCase& test_case) { | 307 const DownloadTestCase& test_case) { |
288 content::MockDownloadItem* item = | 308 content::MockDownloadItem* item = |
289 new ::testing::NiceMock<content::MockDownloadItem>(); | 309 new ::testing::NiceMock<content::MockDownloadItem>(); |
290 GURL download_url(test_case.url); | 310 GURL download_url(test_case.url); |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 }, | 1167 }, |
1148 }; | 1168 }; |
1149 | 1169 |
1150 SetPromptForDownload(true); | 1170 SetPromptForDownload(true); |
1151 EnableAutoOpenBasedOnExtension( | 1171 EnableAutoOpenBasedOnExtension( |
1152 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); | 1172 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); |
1153 RunTestCasesWithActiveItem(kPromptingTestCases, | 1173 RunTestCasesWithActiveItem(kPromptingTestCases, |
1154 arraysize(kPromptingTestCases)); | 1174 arraysize(kPromptingTestCases)); |
1155 } | 1175 } |
1156 | 1176 |
| 1177 #if defined(OS_ANDROID) |
| 1178 TEST_F(DownloadTargetDeterminerTest, |
| 1179 TargetDeterminer_DisapprovePromptForUserPermission) { |
| 1180 const DownloadTestCase kUserPermissionTestCases[] = { |
| 1181 { |
| 1182 // 0: Automatic Safe |
| 1183 AUTOMATIC, |
| 1184 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1185 "http://example.com/foo.txt", "text/plain", |
| 1186 FILE_PATH_LITERAL(""), |
| 1187 |
| 1188 FILE_PATH_LITERAL(""), |
| 1189 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1190 |
| 1191 EXPECT_LOCAL_PATH |
| 1192 }, |
| 1193 }; |
| 1194 content::DownloadControllerAndroid::Get()-> |
| 1195 SetApproveFileAccessRequestForTesting(false); |
| 1196 RunTestCasesWithActiveItem(kUserPermissionTestCases, |
| 1197 arraysize(kUserPermissionTestCases)); |
| 1198 } |
| 1199 #endif |
| 1200 |
1157 #if defined(ENABLE_EXTENSIONS) | 1201 #if defined(ENABLE_EXTENSIONS) |
1158 // These test cases are run with "Prompt for download" user preference set to | 1202 // These test cases are run with "Prompt for download" user preference set to |
1159 // true. Automatic extension downloads shouldn't cause prompting. | 1203 // true. Automatic extension downloads shouldn't cause prompting. |
1160 // Android doesn't support extensions. | 1204 // Android doesn't support extensions. |
1161 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) { | 1205 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) { |
1162 const DownloadTestCase kPromptingTestCases[] = { | 1206 const DownloadTestCase kPromptingTestCases[] = { |
1163 { | 1207 { |
1164 // 0: Automatic Browser Extension download. - Shouldn't prompt for browser | 1208 // 0: Automatic Browser Extension download. - Shouldn't prompt for browser |
1165 // extension downloads even if "Prompt for download" preference is set. | 1209 // extension downloads even if "Prompt for download" preference is set. |
1166 AUTOMATIC, | 1210 AUTOMATIC, |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2239 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) | 2283 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) |
2240 .WillRepeatedly(Return(true)); | 2284 .WillRepeatedly(Return(true)); |
2241 | 2285 |
2242 target_info = RunDownloadTargetDeterminer( | 2286 target_info = RunDownloadTargetDeterminer( |
2243 GetPathInDownloadDir(kInitialPath), item.get()); | 2287 GetPathInDownloadDir(kInitialPath), item.get()); |
2244 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2288 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
2245 } | 2289 } |
2246 #endif // defined(ENABLE_PLUGINS) | 2290 #endif // defined(ENABLE_PLUGINS) |
2247 | 2291 |
2248 } // namespace | 2292 } // namespace |
OLD | NEW |