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

Side by Side Diff: chrome/browser/download/download_target_determiner_unittest.cc

Issue 1229933010: move file access permission logic to DownloadResourceThrottle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 5 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
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 "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
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
54 using ::testing::AnyNumber; 50 using ::testing::AnyNumber;
55 using ::testing::Invoke; 51 using ::testing::Invoke;
56 using ::testing::Ref; 52 using ::testing::Ref;
57 using ::testing::Return; 53 using ::testing::Return;
58 using ::testing::ReturnRef; 54 using ::testing::ReturnRef;
59 using ::testing::ReturnRefOfCopy; 55 using ::testing::ReturnRefOfCopy;
60 using ::testing::Truly; 56 using ::testing::Truly;
61 using ::testing::WithArg; 57 using ::testing::WithArg;
62 using ::testing::_; 58 using ::testing::_;
63 using content::DownloadItem; 59 using content::DownloadItem;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 250 }
255 251
256 MockDownloadTargetDeterminerDelegate* delegate() { 252 MockDownloadTargetDeterminerDelegate* delegate() {
257 return &delegate_; 253 return &delegate_;
258 } 254 }
259 255
260 DownloadPrefs* download_prefs() { 256 DownloadPrefs* download_prefs() {
261 return download_prefs_.get(); 257 return download_prefs_.get();
262 } 258 }
263 259
264 #if defined(OS_ANDROID)
265 chrome::android::MockDownloadControllerAndroid* download_controller() {
266 return &download_controller_;
267 }
268 #endif
269
270 private: 260 private:
271 scoped_ptr<DownloadPrefs> download_prefs_; 261 scoped_ptr<DownloadPrefs> download_prefs_;
272 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; 262 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_;
273 NullWebContentsDelegate web_contents_delegate_; 263 NullWebContentsDelegate web_contents_delegate_;
274 base::ScopedTempDir test_download_dir_; 264 base::ScopedTempDir test_download_dir_;
275 base::FilePath test_virtual_dir_; 265 base::FilePath test_virtual_dir_;
276 #if defined(OS_ANDROID)
277 chrome::android::MockDownloadControllerAndroid download_controller_;
278 #endif
279 }; 266 };
280 267
281 void DownloadTargetDeterminerTest::SetUp() { 268 void DownloadTargetDeterminerTest::SetUp() {
282 ChromeRenderViewHostTestHarness::SetUp(); 269 ChromeRenderViewHostTestHarness::SetUp();
283 CHECK(profile()); 270 CHECK(profile());
284 download_prefs_.reset(new DownloadPrefs(profile())); 271 download_prefs_.reset(new DownloadPrefs(profile()));
285 web_contents()->SetDelegate(&web_contents_delegate_); 272 web_contents()->SetDelegate(&web_contents_delegate_);
286 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); 273 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir());
287 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); 274 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual"));
288 download_prefs_->SetDownloadPath(test_download_dir()); 275 download_prefs_->SetDownloadPath(test_download_dir());
289 delegate_.SetupDefaults(); 276 delegate_.SetupDefaults();
290 #if defined(OS_ANDROID)
291 content::DownloadControllerAndroid::SetDownloadControllerAndroid(
292 &download_controller_);
293 #endif
294 } 277 }
295 278
296 void DownloadTargetDeterminerTest::TearDown() { 279 void DownloadTargetDeterminerTest::TearDown() {
297 download_prefs_.reset(); 280 download_prefs_.reset();
298 #if defined(OS_ANDROID)
299 content::DownloadControllerAndroid::SetDownloadControllerAndroid(nullptr);
300 #endif
301 ChromeRenderViewHostTestHarness::TearDown(); 281 ChromeRenderViewHostTestHarness::TearDown();
302 } 282 }
303 283
304 content::MockDownloadItem* 284 content::MockDownloadItem*
305 DownloadTargetDeterminerTest::CreateActiveDownloadItem( 285 DownloadTargetDeterminerTest::CreateActiveDownloadItem(
306 int32 id, 286 int32 id,
307 const DownloadTestCase& test_case) { 287 const DownloadTestCase& test_case) {
308 content::MockDownloadItem* item = 288 content::MockDownloadItem* item =
309 new ::testing::NiceMock<content::MockDownloadItem>(); 289 new ::testing::NiceMock<content::MockDownloadItem>();
310 GURL download_url(test_case.url); 290 GURL download_url(test_case.url);
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 }, 1147 },
1168 }; 1148 };
1169 1149
1170 SetPromptForDownload(true); 1150 SetPromptForDownload(true);
1171 EnableAutoOpenBasedOnExtension( 1151 EnableAutoOpenBasedOnExtension(
1172 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); 1152 base::FilePath(FILE_PATH_LITERAL("dummy.dummy")));
1173 RunTestCasesWithActiveItem(kPromptingTestCases, 1153 RunTestCasesWithActiveItem(kPromptingTestCases,
1174 arraysize(kPromptingTestCases)); 1154 arraysize(kPromptingTestCases));
1175 } 1155 }
1176 1156
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
1201 #if defined(ENABLE_EXTENSIONS) 1157 #if defined(ENABLE_EXTENSIONS)
1202 // These test cases are run with "Prompt for download" user preference set to 1158 // These test cases are run with "Prompt for download" user preference set to
1203 // true. Automatic extension downloads shouldn't cause prompting. 1159 // true. Automatic extension downloads shouldn't cause prompting.
1204 // Android doesn't support extensions. 1160 // Android doesn't support extensions.
1205 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) { 1161 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) {
1206 const DownloadTestCase kPromptingTestCases[] = { 1162 const DownloadTestCase kPromptingTestCases[] = {
1207 { 1163 {
1208 // 0: Automatic Browser Extension download. - Shouldn't prompt for browser 1164 // 0: Automatic Browser Extension download. - Shouldn't prompt for browser
1209 // extension downloads even if "Prompt for download" preference is set. 1165 // extension downloads even if "Prompt for download" preference is set.
1210 AUTOMATIC, 1166 AUTOMATIC,
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path())) 2239 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(npapi_plugin.path()))
2284 .WillRepeatedly(Return(true)); 2240 .WillRepeatedly(Return(true));
2285 2241
2286 target_info = RunDownloadTargetDeterminer( 2242 target_info = RunDownloadTargetDeterminer(
2287 GetPathInDownloadDir(kInitialPath), item.get()); 2243 GetPathInDownloadDir(kInitialPath), item.get());
2288 EXPECT_FALSE(target_info->is_filetype_handled_safely); 2244 EXPECT_FALSE(target_info->is_filetype_handled_safely);
2289 } 2245 }
2290 #endif // defined(ENABLE_PLUGINS) 2246 #endif // defined(ENABLE_PLUGINS)
2291 2247
2292 } // namespace 2248 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698