Chromium Code Reviews| 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 <string> | |
| 9 #include <vector> | |
| 10 | |
| 8 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 9 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/location.h" | 14 #include "base/location.h" |
| 12 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | |
| 13 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 14 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 15 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 16 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 17 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/value_conversions.h" | 23 #include "base/value_conversions.h" |
| 20 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 25 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 26 #include "chrome/browser/download/download_confirmation_result.h" | |
| 22 #include "chrome/browser/download/download_prefs.h" | 27 #include "chrome/browser/download/download_prefs.h" |
| 23 #include "chrome/browser/download/download_target_determiner.h" | 28 #include "chrome/browser/download/download_target_determiner.h" |
| 24 #include "chrome/browser/download/download_target_info.h" | 29 #include "chrome/browser/download/download_target_info.h" |
| 25 #include "chrome/browser/history/history_service_factory.h" | 30 #include "chrome/browser/history/history_service_factory.h" |
| 31 #include "chrome/common/features.h" | |
| 26 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/safe_browsing/file_type_policies.h" | 33 #include "chrome/common/safe_browsing/file_type_policies.h" |
| 34 #include "chrome/common/safe_browsing/file_type_policies_test_util.h" | |
| 28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 35 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 29 #include "chrome/test/base/testing_profile.h" | 36 #include "chrome/test/base/testing_profile.h" |
| 30 #include "components/history/core/browser/history_service.h" | 37 #include "components/history/core/browser/history_service.h" |
| 31 #include "components/history/core/browser/history_types.h" | 38 #include "components/history/core/browser/history_types.h" |
| 32 #include "components/prefs/pref_service.h" | 39 #include "components/prefs/pref_service.h" |
| 33 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 40 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 34 #include "content/public/browser/download_interrupt_reasons.h" | 41 #include "content/public/browser/download_interrupt_reasons.h" |
| 35 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/browser/web_contents_delegate.h" | 44 #include "content/public/browser/web_contents_delegate.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 SAVE_AS, | 111 SAVE_AS, |
| 105 AUTOMATIC, | 112 AUTOMATIC, |
| 106 FORCED // Requires that forced_file_path be non-empty. | 113 FORCED // Requires that forced_file_path be non-empty. |
| 107 }; | 114 }; |
| 108 | 115 |
| 109 // Used with DownloadTestCase. Type of intermediate filename to expect. | 116 // Used with DownloadTestCase. Type of intermediate filename to expect. |
| 110 enum TestCaseExpectIntermediate { | 117 enum TestCaseExpectIntermediate { |
| 111 EXPECT_CRDOWNLOAD, // Expect path/to/target.crdownload. | 118 EXPECT_CRDOWNLOAD, // Expect path/to/target.crdownload. |
| 112 EXPECT_UNCONFIRMED, // Expect path/to/Unconfirmed xxx.crdownload. | 119 EXPECT_UNCONFIRMED, // Expect path/to/Unconfirmed xxx.crdownload. |
| 113 EXPECT_LOCAL_PATH, // Expect target path. | 120 EXPECT_LOCAL_PATH, // Expect target path. |
| 121 EXPECT_EMPTY, // Expect empty path. Only for downloads which will be marked | |
|
svaldez
2016/10/28 17:29:36
Align comments?
asanka
2016/11/07 19:50:15
Done. The former was what clang-format did on its
| |
| 122 // interrupted or cancelled. | |
| 114 }; | 123 }; |
| 115 | 124 |
| 116 // Typical download test case. Used with | 125 // Typical download test case. Used with |
| 117 // DownloadTargetDeterminerTest::RunTestCase(). | 126 // DownloadTargetDeterminerTest::RunTestCase(). |
| 118 struct DownloadTestCase { | 127 struct DownloadTestCase { |
| 119 // Type of test. | 128 // Type of test. |
| 120 TestCaseType test_type; | 129 TestCaseType test_type; |
| 121 | 130 |
| 122 // Expected danger type. Verified at the end of target determination. | 131 // Expected danger type. Verified at the end of target determination. |
| 123 content::DownloadDangerType expected_danger_type; | 132 content::DownloadDangerType expected_danger_type; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 148 | 157 |
| 149 class MockDownloadTargetDeterminerDelegate | 158 class MockDownloadTargetDeterminerDelegate |
| 150 : public DownloadTargetDeterminerDelegate { | 159 : public DownloadTargetDeterminerDelegate { |
| 151 public: | 160 public: |
| 152 MOCK_METHOD3(CheckDownloadUrl, | 161 MOCK_METHOD3(CheckDownloadUrl, |
| 153 void(content::DownloadItem*, const base::FilePath&, | 162 void(content::DownloadItem*, const base::FilePath&, |
| 154 const CheckDownloadUrlCallback&)); | 163 const CheckDownloadUrlCallback&)); |
| 155 MOCK_METHOD3(NotifyExtensions, | 164 MOCK_METHOD3(NotifyExtensions, |
| 156 void(content::DownloadItem*, const base::FilePath&, | 165 void(content::DownloadItem*, const base::FilePath&, |
| 157 const NotifyExtensionsCallback&)); | 166 const NotifyExtensionsCallback&)); |
| 158 MOCK_METHOD3(PromptUserForDownloadPath, | 167 MOCK_METHOD4(RequestConfirmation, |
| 159 void(content::DownloadItem*, const base::FilePath&, | 168 void(content::DownloadItem*, |
| 169 const base::FilePath&, | |
| 170 DownloadConfirmationReason, | |
| 160 const FileSelectedCallback&)); | 171 const FileSelectedCallback&)); |
| 161 MOCK_METHOD3(DetermineLocalPath, | 172 MOCK_METHOD3(DetermineLocalPath, |
| 162 void(DownloadItem*, const base::FilePath&, | 173 void(DownloadItem*, const base::FilePath&, |
| 163 const LocalPathCallback&)); | 174 const LocalPathCallback&)); |
| 164 MOCK_METHOD5(ReserveVirtualPath, | 175 MOCK_METHOD5(ReserveVirtualPath, |
| 165 void(DownloadItem*, const base::FilePath&, bool, | 176 void(DownloadItem*, const base::FilePath&, bool, |
| 166 DownloadPathReservationTracker::FilenameConflictAction, | 177 DownloadPathReservationTracker::FilenameConflictAction, |
| 167 const ReservedPathCallback&)); | 178 const ReservedPathCallback&)); |
| 168 MOCK_METHOD2(GetFileMimeType, | 179 MOCK_METHOD2(GetFileMimeType, |
| 169 void(const base::FilePath&, | 180 void(const base::FilePath&, |
| 170 const GetFileMimeTypeCallback&)); | 181 const GetFileMimeTypeCallback&)); |
| 171 | 182 |
| 172 void SetupDefaults() { | 183 void SetupDefaults() { |
| 173 ON_CALL(*this, CheckDownloadUrl(_, _, _)) | 184 ON_CALL(*this, CheckDownloadUrl(_, _, _)) |
| 174 .WillByDefault(WithArg<2>( | 185 .WillByDefault(WithArg<2>( |
| 175 ScheduleCallback(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS))); | 186 ScheduleCallback(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS))); |
| 176 ON_CALL(*this, NotifyExtensions(_, _, _)) | 187 ON_CALL(*this, NotifyExtensions(_, _, _)) |
| 177 .WillByDefault(WithArg<2>( | 188 .WillByDefault(WithArg<2>( |
| 178 ScheduleCallback2(base::FilePath(), | 189 ScheduleCallback2(base::FilePath(), |
| 179 DownloadPathReservationTracker::UNIQUIFY))); | 190 DownloadPathReservationTracker::UNIQUIFY))); |
| 180 ON_CALL(*this, ReserveVirtualPath(_, _, _, _, _)) | 191 ON_CALL(*this, ReserveVirtualPath(_, _, _, _, _)) |
| 181 .WillByDefault(Invoke( | 192 .WillByDefault(Invoke( |
| 182 &MockDownloadTargetDeterminerDelegate::NullReserveVirtualPath)); | 193 &MockDownloadTargetDeterminerDelegate::NullReserveVirtualPath)); |
| 183 ON_CALL(*this, PromptUserForDownloadPath(_, _, _)) | 194 ON_CALL(*this, RequestConfirmation(_, _, _, _)) |
| 184 .WillByDefault(Invoke( | 195 .WillByDefault( |
| 185 &MockDownloadTargetDeterminerDelegate::NullPromptUser)); | 196 Invoke(&MockDownloadTargetDeterminerDelegate::NullPromptUser)); |
| 186 ON_CALL(*this, DetermineLocalPath(_, _, _)) | 197 ON_CALL(*this, DetermineLocalPath(_, _, _)) |
| 187 .WillByDefault(Invoke( | 198 .WillByDefault(Invoke( |
| 188 &MockDownloadTargetDeterminerDelegate::NullDetermineLocalPath)); | 199 &MockDownloadTargetDeterminerDelegate::NullDetermineLocalPath)); |
| 189 ON_CALL(*this, GetFileMimeType(_, _)) | 200 ON_CALL(*this, GetFileMimeType(_, _)) |
| 190 .WillByDefault(WithArg<1>( | 201 .WillByDefault(WithArg<1>( |
| 191 ScheduleCallback(""))); | 202 ScheduleCallback(""))); |
| 192 } | 203 } |
| 193 private: | 204 private: |
| 194 static void NullReserveVirtualPath( | 205 static void NullReserveVirtualPath( |
| 195 DownloadItem* download, | 206 DownloadItem* download, |
| 196 const base::FilePath& virtual_path, | 207 const base::FilePath& virtual_path, |
| 197 bool create_directory, | 208 bool create_directory, |
| 198 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 209 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
| 199 const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback); | 210 const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback); |
| 200 static void NullPromptUser( | 211 static void NullPromptUser(DownloadItem* download, |
| 201 DownloadItem* download, const base::FilePath& suggested_path, | 212 const base::FilePath& suggested_path, |
| 202 const FileSelectedCallback& callback); | 213 DownloadConfirmationReason reason, |
| 214 const FileSelectedCallback& callback); | |
| 203 static void NullDetermineLocalPath( | 215 static void NullDetermineLocalPath( |
| 204 DownloadItem* download, const base::FilePath& virtual_path, | 216 DownloadItem* download, const base::FilePath& virtual_path, |
| 205 const LocalPathCallback& callback); | 217 const LocalPathCallback& callback); |
| 206 }; | 218 }; |
| 207 | 219 |
| 208 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { | 220 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { |
| 209 public: | 221 public: |
| 210 // ::testing::Test | 222 // ::testing::Test |
| 211 void SetUp() override; | 223 void SetUp() override; |
| 212 void TearDown() override; | 224 void TearDown() override; |
| 213 | 225 |
| 214 // Creates MockDownloadItem and sets up default expectations. | 226 // Creates MockDownloadItem and sets up default expectations. |
| 215 content::MockDownloadItem* CreateActiveDownloadItem( | 227 std::unique_ptr<content::MockDownloadItem> CreateActiveDownloadItem( |
| 216 int32_t id, | 228 int32_t id, |
| 217 const DownloadTestCase& test_case); | 229 const DownloadTestCase& test_case); |
| 218 | 230 |
| 219 // Sets the AutoOpenBasedOnExtension user preference for |path|. | 231 // Sets the AutoOpenBasedOnExtension user preference for |path|. |
| 220 void EnableAutoOpenBasedOnExtension(const base::FilePath& path); | 232 void EnableAutoOpenBasedOnExtension(const base::FilePath& path); |
| 221 | 233 |
| 222 // Set the kDownloadDefaultDirectory managed preference to |path|. | 234 // Set the kDownloadDefaultDirectory managed preference to |path|. |
| 223 void SetManagedDownloadPath(const base::FilePath& path); | 235 void SetManagedDownloadPath(const base::FilePath& path); |
| 224 | 236 |
| 225 // Set the kPromptForDownload user preference to |prompt|. | 237 // Set the kPromptForDownload user preference to |prompt|. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 } | 273 } |
| 262 | 274 |
| 263 MockDownloadTargetDeterminerDelegate* delegate() { | 275 MockDownloadTargetDeterminerDelegate* delegate() { |
| 264 return &delegate_; | 276 return &delegate_; |
| 265 } | 277 } |
| 266 | 278 |
| 267 DownloadPrefs* download_prefs() { | 279 DownloadPrefs* download_prefs() { |
| 268 return download_prefs_.get(); | 280 return download_prefs_.get(); |
| 269 } | 281 } |
| 270 | 282 |
| 271 // Shortcut | 283 private: |
| 272 const FileTypePolicies* Policies() const { | 284 void SetUpFileTypePolicies(); |
| 273 return FileTypePolicies::GetInstance(); | |
| 274 } | |
| 275 | 285 |
| 276 private: | |
| 277 std::unique_ptr<DownloadPrefs> download_prefs_; | 286 std::unique_ptr<DownloadPrefs> download_prefs_; |
| 278 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; | 287 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; |
| 279 NullWebContentsDelegate web_contents_delegate_; | 288 NullWebContentsDelegate web_contents_delegate_; |
| 280 base::ScopedTempDir test_download_dir_; | 289 base::ScopedTempDir test_download_dir_; |
| 281 base::FilePath test_virtual_dir_; | 290 base::FilePath test_virtual_dir_; |
| 291 safe_browsing::FileTypePoliciesTestOverlay file_type_configuration_; | |
| 282 }; | 292 }; |
| 283 | 293 |
| 284 void DownloadTargetDeterminerTest::SetUp() { | 294 void DownloadTargetDeterminerTest::SetUp() { |
| 285 ChromeRenderViewHostTestHarness::SetUp(); | 295 ChromeRenderViewHostTestHarness::SetUp(); |
| 286 CHECK(profile()); | 296 CHECK(profile()); |
| 287 download_prefs_.reset(new DownloadPrefs(profile())); | 297 download_prefs_.reset(new DownloadPrefs(profile())); |
| 288 web_contents()->SetDelegate(&web_contents_delegate_); | 298 web_contents()->SetDelegate(&web_contents_delegate_); |
| 289 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 299 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
| 290 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); | 300 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); |
| 291 download_prefs_->SetDownloadPath(test_download_dir()); | 301 download_prefs_->SetDownloadPath(test_download_dir()); |
| 292 delegate_.SetupDefaults(); | 302 delegate_.SetupDefaults(); |
| 303 SetUpFileTypePolicies(); | |
| 293 } | 304 } |
| 294 | 305 |
| 295 void DownloadTargetDeterminerTest::TearDown() { | 306 void DownloadTargetDeterminerTest::TearDown() { |
| 296 download_prefs_.reset(); | 307 download_prefs_.reset(); |
| 297 ChromeRenderViewHostTestHarness::TearDown(); | 308 ChromeRenderViewHostTestHarness::TearDown(); |
| 298 } | 309 } |
| 299 | 310 |
| 300 content::MockDownloadItem* | 311 std::unique_ptr<content::MockDownloadItem> |
| 301 DownloadTargetDeterminerTest::CreateActiveDownloadItem( | 312 DownloadTargetDeterminerTest::CreateActiveDownloadItem( |
| 302 int32_t id, | 313 int32_t id, |
| 303 const DownloadTestCase& test_case) { | 314 const DownloadTestCase& test_case) { |
| 304 content::MockDownloadItem* item = | 315 std::unique_ptr<content::MockDownloadItem> item = |
| 305 new ::testing::NiceMock<content::MockDownloadItem>(); | 316 base::MakeUnique<::testing::NiceMock<content::MockDownloadItem>>(); |
| 306 GURL download_url(test_case.url); | 317 GURL download_url(test_case.url); |
| 307 std::vector<GURL> url_chain; | 318 std::vector<GURL> url_chain; |
| 308 url_chain.push_back(download_url); | 319 url_chain.push_back(download_url); |
| 309 base::FilePath forced_file_path = | 320 base::FilePath forced_file_path = |
| 310 GetPathInDownloadDir(test_case.forced_file_path); | 321 GetPathInDownloadDir(test_case.forced_file_path); |
| 311 DownloadItem::TargetDisposition initial_disposition = | 322 DownloadItem::TargetDisposition initial_disposition = |
| 312 (test_case.test_type == SAVE_AS) ? | 323 (test_case.test_type == SAVE_AS) ? |
| 313 DownloadItem::TARGET_DISPOSITION_PROMPT : | 324 DownloadItem::TARGET_DISPOSITION_PROMPT : |
| 314 DownloadItem::TARGET_DISPOSITION_OVERWRITE; | 325 DownloadItem::TARGET_DISPOSITION_OVERWRITE; |
| 315 EXPECT_EQ(test_case.test_type == FORCED, | 326 EXPECT_EQ(test_case.test_type == FORCED, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 409 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); |
| 399 } | 410 } |
| 400 | 411 |
| 401 std::unique_ptr<DownloadTargetInfo> | 412 std::unique_ptr<DownloadTargetInfo> |
| 402 DownloadTargetDeterminerTest::RunDownloadTargetDeterminer( | 413 DownloadTargetDeterminerTest::RunDownloadTargetDeterminer( |
| 403 const base::FilePath& initial_virtual_path, | 414 const base::FilePath& initial_virtual_path, |
| 404 content::MockDownloadItem* item) { | 415 content::MockDownloadItem* item) { |
| 405 std::unique_ptr<DownloadTargetInfo> target_info; | 416 std::unique_ptr<DownloadTargetInfo> target_info; |
| 406 base::RunLoop run_loop; | 417 base::RunLoop run_loop; |
| 407 DownloadTargetDeterminer::Start( | 418 DownloadTargetDeterminer::Start( |
| 408 item, initial_virtual_path, download_prefs_.get(), delegate(), | 419 item, initial_virtual_path, DownloadPathReservationTracker::UNIQUIFY, |
| 409 base::Bind(&CompletionCallbackWrapper, | 420 download_prefs_.get(), delegate(), |
| 410 run_loop.QuitClosure(), | 421 base::Bind(&CompletionCallbackWrapper, run_loop.QuitClosure(), |
| 411 &target_info)); | 422 &target_info)); |
| 412 run_loop.Run(); | 423 run_loop.Run(); |
| 413 ::testing::Mock::VerifyAndClearExpectations(delegate()); | 424 ::testing::Mock::VerifyAndClearExpectations(delegate()); |
| 414 return target_info; | 425 return target_info; |
| 415 } | 426 } |
| 416 | 427 |
| 417 void DownloadTargetDeterminerTest::RunTestCasesWithActiveItem( | 428 void DownloadTargetDeterminerTest::RunTestCasesWithActiveItem( |
| 418 const DownloadTestCase test_cases[], | 429 const DownloadTestCase test_cases[], |
| 419 size_t test_case_count) { | 430 size_t test_case_count) { |
| 420 for (size_t i = 0; i < test_case_count; ++i) { | 431 for (size_t i = 0; i < test_case_count; ++i) { |
| 421 std::unique_ptr<content::MockDownloadItem> item( | 432 std::unique_ptr<content::MockDownloadItem> item = |
| 422 CreateActiveDownloadItem(i, test_cases[i])); | 433 CreateActiveDownloadItem(i, test_cases[i]); |
| 423 SCOPED_TRACE(testing::Message() << "Running test case " << i); | 434 SCOPED_TRACE(testing::Message() << "Running test case " << i); |
| 424 RunTestCase(test_cases[i], base::FilePath(), item.get()); | 435 RunTestCase(test_cases[i], base::FilePath(), item.get()); |
| 425 } | 436 } |
| 426 } | 437 } |
| 427 | 438 |
| 428 void DownloadTargetDeterminerTest::VerifyDownloadTarget( | 439 void DownloadTargetDeterminerTest::VerifyDownloadTarget( |
| 429 const DownloadTestCase& test_case, | 440 const DownloadTestCase& test_case, |
| 430 const DownloadTargetInfo* target_info) { | 441 const DownloadTargetInfo* target_info) { |
| 431 base::FilePath expected_local_path( | 442 base::FilePath expected_local_path( |
| 432 GetPathInDownloadDir(test_case.expected_local_path)); | 443 GetPathInDownloadDir(test_case.expected_local_path)); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 458 FILE_PATH_LITERAL(".crdownload"))); | 469 FILE_PATH_LITERAL(".crdownload"))); |
| 459 EXPECT_EQ(0u, | 470 EXPECT_EQ(0u, |
| 460 target_info->intermediate_path.BaseName().value().find( | 471 target_info->intermediate_path.BaseName().value().find( |
| 461 FILE_PATH_LITERAL("Unconfirmed "))); | 472 FILE_PATH_LITERAL("Unconfirmed "))); |
| 462 break; | 473 break; |
| 463 | 474 |
| 464 case EXPECT_LOCAL_PATH: | 475 case EXPECT_LOCAL_PATH: |
| 465 EXPECT_EQ(expected_local_path.value(), | 476 EXPECT_EQ(expected_local_path.value(), |
| 466 target_info->intermediate_path.value()); | 477 target_info->intermediate_path.value()); |
| 467 break; | 478 break; |
| 479 | |
| 480 case EXPECT_EMPTY: | |
| 481 EXPECT_TRUE(target_info->intermediate_path.empty()); | |
| 482 break; | |
| 468 } | 483 } |
| 469 } | 484 } |
| 470 | 485 |
| 486 void DownloadTargetDeterminerTest::SetUpFileTypePolicies() { | |
| 487 std::unique_ptr<safe_browsing::DownloadFileTypeConfig> fake_file_type_config = | |
| 488 base::MakeUnique<safe_browsing::DownloadFileTypeConfig>(); | |
| 489 auto file_type = fake_file_type_config->mutable_default_file_type(); | |
| 490 file_type->set_uma_value(-1); | |
| 491 auto platform_settings = file_type->add_platform_settings(); | |
| 492 platform_settings->set_danger_level(DownloadFileType::NOT_DANGEROUS); | |
| 493 platform_settings->set_auto_open_hint(DownloadFileType::ALLOW_AUTO_OPEN); | |
| 494 | |
| 495 file_type = fake_file_type_config->add_file_types(); | |
| 496 file_type->set_extension("kindabad"); | |
| 497 file_type->set_uma_value(-1); | |
| 498 platform_settings = file_type->add_platform_settings(); | |
| 499 platform_settings->set_danger_level(DownloadFileType::ALLOW_ON_USER_GESTURE); | |
| 500 platform_settings->set_auto_open_hint(DownloadFileType::ALLOW_AUTO_OPEN); | |
| 501 | |
| 502 file_type = fake_file_type_config->add_file_types(); | |
| 503 file_type->set_extension("bad"); | |
| 504 file_type->set_uma_value(-1); | |
| 505 platform_settings = file_type->add_platform_settings(); | |
| 506 platform_settings->set_danger_level(DownloadFileType::DANGEROUS); | |
| 507 platform_settings->set_auto_open_hint(DownloadFileType::DISALLOW_AUTO_OPEN); | |
| 508 | |
| 509 file_type_configuration_.SwapConfig(fake_file_type_config); | |
| 510 } | |
| 511 | |
| 471 // static | 512 // static |
| 472 void MockDownloadTargetDeterminerDelegate::NullReserveVirtualPath( | 513 void MockDownloadTargetDeterminerDelegate::NullReserveVirtualPath( |
| 473 DownloadItem* download, | 514 DownloadItem* download, |
| 474 const base::FilePath& virtual_path, | 515 const base::FilePath& virtual_path, |
| 475 bool create_directory, | 516 bool create_directory, |
| 476 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 517 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
| 477 const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback) { | 518 const DownloadTargetDeterminerDelegate::ReservedPathCallback& callback) { |
| 478 callback.Run(virtual_path, true); | 519 callback.Run(virtual_path, DownloadTargetResult::SUCCESS); |
| 479 } | 520 } |
| 480 | 521 |
| 481 // static | 522 // static |
| 482 void MockDownloadTargetDeterminerDelegate::NullPromptUser( | 523 void MockDownloadTargetDeterminerDelegate::NullPromptUser( |
| 483 DownloadItem* download, const base::FilePath& suggested_path, | 524 DownloadItem* download, |
| 525 const base::FilePath& suggested_path, | |
| 526 DownloadConfirmationReason reason, | |
| 484 const FileSelectedCallback& callback) { | 527 const FileSelectedCallback& callback) { |
| 485 callback.Run(suggested_path); | 528 callback.Run(DownloadConfirmationResult::CONFIRMED, suggested_path); |
| 486 } | 529 } |
| 487 | 530 |
| 488 // static | 531 // static |
| 489 void MockDownloadTargetDeterminerDelegate::NullDetermineLocalPath( | 532 void MockDownloadTargetDeterminerDelegate::NullDetermineLocalPath( |
| 490 DownloadItem* download, const base::FilePath& virtual_path, | 533 DownloadItem* download, const base::FilePath& virtual_path, |
| 491 const LocalPathCallback& callback) { | 534 const LocalPathCallback& callback) { |
| 492 callback.Run(virtual_path); | 535 callback.Run(virtual_path); |
| 493 } | 536 } |
| 494 | 537 |
| 495 // NotifyExtensions implementation that overrides the path so that the target | 538 // NotifyExtensions implementation that overrides the path so that the target |
| 496 // file is in a subdirectory called 'overridden'. If the extension is '.remove', | 539 // file is in a subdirectory called 'overridden'. If the extension is '.remove', |
| 497 // the extension is removed. | 540 // the extension is removed. |
| 498 void NotifyExtensionsOverridePath( | 541 void NotifyExtensionsOverridePath( |
| 499 content::DownloadItem* download, | 542 content::DownloadItem* download, |
| 500 const base::FilePath& path, | 543 const base::FilePath& path, |
| 501 const DownloadTargetDeterminerDelegate::NotifyExtensionsCallback& | 544 const DownloadTargetDeterminerDelegate::NotifyExtensionsCallback& |
| 502 callback) { | 545 callback) { |
| 503 base::FilePath new_path = | 546 base::FilePath new_path = |
| 504 base::FilePath() | 547 base::FilePath() |
| 505 .AppendASCII("overridden") | 548 .AppendASCII("overridden") |
| 506 .Append(path.BaseName()); | 549 .Append(path.BaseName()); |
| 507 if (new_path.MatchesExtension(FILE_PATH_LITERAL(".remove"))) | 550 if (new_path.MatchesExtension(FILE_PATH_LITERAL(".remove"))) |
| 508 new_path = new_path.RemoveExtension(); | 551 new_path = new_path.RemoveExtension(); |
| 509 callback.Run(new_path, DownloadPathReservationTracker::UNIQUIFY); | 552 callback.Run(new_path, DownloadPathReservationTracker::UNIQUIFY); |
| 510 } | 553 } |
| 511 | 554 |
| 512 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_Basic) { | 555 TEST_F(DownloadTargetDeterminerTest, Basic) { |
| 513 const DownloadTestCase kBasicTestCases[] = { | 556 const DownloadTestCase kBasicTestCases[] = { |
| 514 {// 0: Automatic Safe | 557 {// Automatic Safe |
| 515 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 558 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 516 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 559 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 517 "text/plain", FILE_PATH_LITERAL(""), | 560 "text/plain", FILE_PATH_LITERAL(""), |
| 518 | 561 |
| 519 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 562 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 520 | 563 |
| 521 EXPECT_CRDOWNLOAD}, | 564 EXPECT_CRDOWNLOAD}, |
| 522 | 565 |
| 523 #if !BUILDFLAG(ANDROID_JAVA_UI) | 566 {// Save_As Safe |
| 524 {// 1: Save_As Safe | |
| 525 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 567 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 526 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 568 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 527 "text/plain", FILE_PATH_LITERAL(""), | 569 "text/plain", FILE_PATH_LITERAL(""), |
| 528 | 570 |
| 529 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 571 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 530 | 572 |
| 531 EXPECT_CRDOWNLOAD}, | 573 EXPECT_CRDOWNLOAD}, |
| 532 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 533 | 574 |
| 534 {// 2: Automatic Dangerous | 575 {// Automatic Dangerous |
| 535 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 576 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 536 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", | 577 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 537 "", FILE_PATH_LITERAL(""), | 578 "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""), |
| 538 | 579 |
| 539 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 580 FILE_PATH_LITERAL("foo.kindabad"), |
| 581 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 540 | 582 |
| 541 EXPECT_UNCONFIRMED}, | 583 EXPECT_UNCONFIRMED}, |
| 542 | 584 |
| 543 {// 3: Forced Safe | 585 {// Forced Safe |
| 544 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 586 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 545 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "", | 587 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "", |
| 546 FILE_PATH_LITERAL("forced-foo.txt"), | 588 FILE_PATH_LITERAL("forced-foo.txt"), |
| 547 | 589 |
| 548 FILE_PATH_LITERAL("forced-foo.txt"), | 590 FILE_PATH_LITERAL("forced-foo.txt"), |
| 549 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 591 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 550 | 592 |
| 551 EXPECT_LOCAL_PATH}, | 593 EXPECT_LOCAL_PATH}, |
| 552 }; | 594 }; |
| 553 | 595 |
| 554 // The test assumes that .crx files have a danger level of | 596 // The test assumes that .kindabad files have a danger level of |
| 555 // ALLOW_ON_USER_GESTURE. | 597 // ALLOW_ON_USER_GESTURE. |
| 556 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, | 598 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 557 Policies()->GetFileDangerLevel( | 599 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 558 base::FilePath(FILE_PATH_LITERAL("foo.crx")))); | 600 base::FilePath(FILE_PATH_LITERAL("foo.kindabad")))); |
| 559 RunTestCasesWithActiveItem(kBasicTestCases, arraysize(kBasicTestCases)); | 601 RunTestCasesWithActiveItem(kBasicTestCases, arraysize(kBasicTestCases)); |
| 560 } | 602 } |
| 561 | 603 |
| 562 #if !BUILDFLAG(ANDROID_JAVA_UI) | 604 TEST_F(DownloadTargetDeterminerTest, CancelSaveAs) { |
| 563 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_CancelSaveAs) { | |
| 564 const DownloadTestCase kCancelSaveAsTestCases[] = { | 605 const DownloadTestCase kCancelSaveAsTestCases[] = { |
| 565 {// 0: Save_As Safe, Cancelled. | 606 {// 0: Save_As Safe, Cancelled. |
| 566 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 607 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 567 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 608 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 568 "text/plain", FILE_PATH_LITERAL(""), | 609 "text/plain", FILE_PATH_LITERAL(""), |
| 569 | 610 |
| 570 FILE_PATH_LITERAL(""), DownloadItem::TARGET_DISPOSITION_PROMPT, | 611 FILE_PATH_LITERAL(""), DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 571 | 612 |
| 572 EXPECT_LOCAL_PATH}}; | 613 EXPECT_LOCAL_PATH}}; |
| 573 ON_CALL(*delegate(), PromptUserForDownloadPath(_, _, _)) | 614 ON_CALL(*delegate(), RequestConfirmation(_, _, _, _)) |
| 574 .WillByDefault(WithArg<2>(ScheduleCallback(base::FilePath()))); | 615 .WillByDefault(WithArg<3>(ScheduleCallback2( |
| 616 DownloadConfirmationResult::CANCELED, base::FilePath()))); | |
| 575 RunTestCasesWithActiveItem(kCancelSaveAsTestCases, | 617 RunTestCasesWithActiveItem(kCancelSaveAsTestCases, |
| 576 arraysize(kCancelSaveAsTestCases)); | 618 arraysize(kCancelSaveAsTestCases)); |
| 577 } | 619 } |
| 578 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 579 | 620 |
| 580 // The SafeBrowsing check is performed early. Make sure that a download item | 621 // The SafeBrowsing check is performed early. Make sure that a download item |
| 581 // that has been marked as DANGEROUS_URL behaves correctly. | 622 // that has been marked as DANGEROUS_URL behaves correctly. |
| 582 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DangerousUrl) { | 623 TEST_F(DownloadTargetDeterminerTest, DangerousUrl) { |
| 583 const DownloadTestCase kSafeBrowsingTestCases[] = { | 624 const DownloadTestCase kSafeBrowsingTestCases[] = { |
| 584 {// 0: Automatic Dangerous URL | 625 {// 0: Automatic Dangerous URL |
| 585 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, | 626 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
| 586 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.txt", | 627 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.txt", |
| 587 "", FILE_PATH_LITERAL(""), | 628 "", FILE_PATH_LITERAL(""), |
| 588 | 629 |
| 589 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 630 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 590 | 631 |
| 591 EXPECT_UNCONFIRMED}, | 632 EXPECT_UNCONFIRMED}, |
| 592 | 633 |
| 593 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 594 {// 1: Save As Dangerous URL | 634 {// 1: Save As Dangerous URL |
| 595 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, | 635 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
| 596 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.txt", | 636 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.txt", |
| 597 "", FILE_PATH_LITERAL(""), | 637 "", FILE_PATH_LITERAL(""), |
| 598 | 638 |
| 599 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 639 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 600 | 640 |
| 601 EXPECT_UNCONFIRMED}, | 641 EXPECT_UNCONFIRMED}, |
| 602 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 603 | 642 |
| 604 {// 2: Forced Dangerous URL | 643 {// 2: Forced Dangerous URL |
| 605 FORCED, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, | 644 FORCED, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
| 606 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.txt", | 645 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.txt", |
| 607 "", FILE_PATH_LITERAL("forced-foo.txt"), | 646 "", FILE_PATH_LITERAL("forced-foo.txt"), |
| 608 | 647 |
| 609 FILE_PATH_LITERAL("forced-foo.txt"), | 648 FILE_PATH_LITERAL("forced-foo.txt"), |
| 610 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 649 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 611 | 650 |
| 612 EXPECT_UNCONFIRMED}, | 651 EXPECT_UNCONFIRMED}, |
| 613 | 652 |
| 614 {// 3: Automatic Dangerous URL + Dangerous file. Dangerous URL takes | 653 {// 3: Automatic Dangerous URL + Dangerous file. Dangerous URL takes |
| 615 // precedence. | 654 // precedence. |
| 616 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, | 655 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
| 617 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.html", | 656 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.html", |
| 618 "", FILE_PATH_LITERAL(""), | 657 "", FILE_PATH_LITERAL(""), |
| 619 | 658 |
| 620 FILE_PATH_LITERAL("foo.html"), | 659 FILE_PATH_LITERAL("foo.html"), |
| 621 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 660 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 622 | 661 |
| 623 EXPECT_UNCONFIRMED}, | 662 EXPECT_UNCONFIRMED}, |
| 624 | 663 |
| 625 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 626 {// 4: Save As Dangerous URL + Dangerous file | 664 {// 4: Save As Dangerous URL + Dangerous file |
| 627 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, | 665 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
| 628 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.html", | 666 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.html", |
| 629 "", FILE_PATH_LITERAL(""), | 667 "", FILE_PATH_LITERAL(""), |
| 630 | 668 |
| 631 FILE_PATH_LITERAL("foo.html"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 669 FILE_PATH_LITERAL("foo.html"), DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 632 | 670 |
| 633 EXPECT_UNCONFIRMED}, | 671 EXPECT_UNCONFIRMED}, |
| 634 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 635 | 672 |
| 636 {// 5: Forced Dangerous URL + Dangerous file | 673 {// 5: Forced Dangerous URL + Dangerous file |
| 637 FORCED, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, | 674 FORCED, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, |
| 638 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.html", | 675 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.html", |
| 639 "", FILE_PATH_LITERAL("forced-foo.html"), | 676 "", FILE_PATH_LITERAL("forced-foo.html"), |
| 640 | 677 |
| 641 FILE_PATH_LITERAL("forced-foo.html"), | 678 FILE_PATH_LITERAL("forced-foo.html"), |
| 642 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 679 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 643 | 680 |
| 644 EXPECT_UNCONFIRMED}, | 681 EXPECT_UNCONFIRMED}, |
| 645 }; | 682 }; |
| 646 | 683 |
| 647 ON_CALL(*delegate(), CheckDownloadUrl(_, _, _)) | 684 ON_CALL(*delegate(), CheckDownloadUrl(_, _, _)) |
| 648 .WillByDefault(WithArg<2>(ScheduleCallback( | 685 .WillByDefault(WithArg<2>(ScheduleCallback( |
| 649 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL))); | 686 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL))); |
| 650 RunTestCasesWithActiveItem(kSafeBrowsingTestCases, | 687 RunTestCasesWithActiveItem(kSafeBrowsingTestCases, |
| 651 arraysize(kSafeBrowsingTestCases)); | 688 arraysize(kSafeBrowsingTestCases)); |
| 652 } | 689 } |
| 653 | 690 |
| 654 // The SafeBrowsing check is performed early. Make sure that a download item | 691 // The SafeBrowsing check is performed early. Make sure that a download item |
| 655 // that has been marked as MAYBE_DANGEROUS_CONTENT behaves correctly. | 692 // that has been marked as MAYBE_DANGEROUS_CONTENT behaves correctly. |
| 656 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_MaybeDangerousContent) { | 693 TEST_F(DownloadTargetDeterminerTest, MaybeDangerousContent) { |
| 657 const DownloadTestCase kSafeBrowsingTestCases[] = { | 694 const DownloadTestCase kSafeBrowsingTestCases[] = { |
| 658 {// 0: Automatic Maybe dangerous content | 695 {// 0: Automatic Maybe dangerous content |
| 659 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 696 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 660 DownloadFileType::ALLOW_ON_USER_GESTURE, | 697 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 661 "http://phishing.example.com/foo.crx", "", FILE_PATH_LITERAL(""), | 698 "http://phishing.example.com/foo.kindabad", "", FILE_PATH_LITERAL(""), |
| 662 | 699 |
| 663 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 700 FILE_PATH_LITERAL("foo.kindabad"), |
| 701 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 664 | 702 |
| 665 EXPECT_UNCONFIRMED}, | 703 EXPECT_UNCONFIRMED}, |
| 666 | 704 |
| 667 {// 1: Automatic Maybe dangerous content with DANGEROUS type. | 705 {// 1: Automatic Maybe dangerous content with DANGEROUS type. |
| 668 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 706 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 669 DownloadFileType::DANGEROUS, "http://phishing.example.com/foo.swf", "", | 707 DownloadFileType::DANGEROUS, "http://phishing.example.com/foo.bad", "", |
| 670 FILE_PATH_LITERAL(""), | 708 FILE_PATH_LITERAL(""), |
| 671 | 709 |
| 672 FILE_PATH_LITERAL("foo.swf"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 710 FILE_PATH_LITERAL("foo.bad"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 673 | 711 |
| 674 EXPECT_UNCONFIRMED}, | 712 EXPECT_UNCONFIRMED}, |
| 675 | 713 |
| 676 | |
| 677 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 678 {// 2: Save As Maybe dangerous content | 714 {// 2: Save As Maybe dangerous content |
| 679 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 715 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 680 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.crx", | 716 DownloadFileType::NOT_DANGEROUS, |
| 681 "", FILE_PATH_LITERAL(""), | 717 "http://phishing.example.com/foo.kindabad", "", FILE_PATH_LITERAL(""), |
| 682 | 718 |
| 683 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 719 FILE_PATH_LITERAL("foo.kindabad"), |
| 720 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
| 684 | 721 |
| 685 EXPECT_UNCONFIRMED}, | 722 EXPECT_UNCONFIRMED}, |
| 686 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 687 | 723 |
| 688 {// 3: Forced Maybe dangerous content | 724 {// 3: Forced Maybe dangerous content |
| 689 FORCED, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 725 FORCED, content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 690 DownloadFileType::NOT_DANGEROUS, "http://phishing.example.com/foo.crx", | 726 DownloadFileType::NOT_DANGEROUS, |
| 691 "", FILE_PATH_LITERAL("forced-foo.crx"), | 727 "http://phishing.example.com/foo.kindabad", "", |
| 728 FILE_PATH_LITERAL("forced-foo.kindabad"), | |
| 692 | 729 |
| 693 FILE_PATH_LITERAL("forced-foo.crx"), | 730 FILE_PATH_LITERAL("forced-foo.kindabad"), |
| 694 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 731 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 695 | 732 |
| 696 EXPECT_UNCONFIRMED}, | 733 EXPECT_UNCONFIRMED}, |
| 697 }; | 734 }; |
| 698 | 735 |
| 699 // Test assumptions: | 736 // Test assumptions: |
| 700 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, | 737 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 701 Policies()->GetFileDangerLevel( | 738 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 702 base::FilePath(FILE_PATH_LITERAL("foo.crx")))); | 739 base::FilePath(FILE_PATH_LITERAL("foo.kindabad")))); |
| 703 ASSERT_EQ(DownloadFileType::DANGEROUS, | 740 ASSERT_EQ(DownloadFileType::DANGEROUS, |
| 704 Policies()->GetFileDangerLevel( | 741 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 705 base::FilePath(FILE_PATH_LITERAL("foo.swf")))); | 742 base::FilePath(FILE_PATH_LITERAL("foo.bad")))); |
| 706 | 743 |
| 707 ON_CALL(*delegate(), CheckDownloadUrl(_, _, _)) | 744 ON_CALL(*delegate(), CheckDownloadUrl(_, _, _)) |
| 708 .WillByDefault(WithArg<2>(ScheduleCallback( | 745 .WillByDefault(WithArg<2>(ScheduleCallback( |
| 709 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT))); | 746 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT))); |
| 710 RunTestCasesWithActiveItem(kSafeBrowsingTestCases, | 747 RunTestCasesWithActiveItem(kSafeBrowsingTestCases, |
| 711 arraysize(kSafeBrowsingTestCases)); | 748 arraysize(kSafeBrowsingTestCases)); |
| 712 } | 749 } |
| 713 | 750 |
| 714 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 715 // Test whether the last saved directory is used for 'Save As' downloads. | 751 // Test whether the last saved directory is used for 'Save As' downloads. |
| 716 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LastSavePath) { | 752 TEST_F(DownloadTargetDeterminerTest, LastSavePath) { |
| 717 const DownloadTestCase kLastSavePathTestCasesPre[] = { | 753 const DownloadTestCase kLastSavePathTestCasesPre[] = { |
| 718 {// 0: If the last save path is empty, then the default download directory | 754 {// 0: If the last save path is empty, then the default download directory |
| 719 // should be used. | 755 // should be used. |
| 720 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 756 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 721 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 757 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 722 "text/plain", FILE_PATH_LITERAL(""), | 758 "text/plain", FILE_PATH_LITERAL(""), |
| 723 | 759 |
| 724 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 760 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 725 | 761 |
| 726 EXPECT_CRDOWNLOAD}}; | 762 EXPECT_CRDOWNLOAD}}; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 760 FILE_PATH_LITERAL("bar.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 796 FILE_PATH_LITERAL("bar.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 761 | 797 |
| 762 EXPECT_LOCAL_PATH}, | 798 EXPECT_LOCAL_PATH}, |
| 763 }; | 799 }; |
| 764 | 800 |
| 765 { | 801 { |
| 766 SCOPED_TRACE(testing::Message() | 802 SCOPED_TRACE(testing::Message() |
| 767 << "Running with default download path"); | 803 << "Running with default download path"); |
| 768 base::FilePath prompt_path = | 804 base::FilePath prompt_path = |
| 769 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.txt")); | 805 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.txt")); |
| 770 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, prompt_path, _)); | 806 EXPECT_CALL(*delegate(), |
| 807 RequestConfirmation(_, prompt_path, | |
| 808 DownloadConfirmationReason::SAVE_AS, _)); | |
| 771 RunTestCasesWithActiveItem(kLastSavePathTestCasesPre, | 809 RunTestCasesWithActiveItem(kLastSavePathTestCasesPre, |
| 772 arraysize(kLastSavePathTestCasesPre)); | 810 arraysize(kLastSavePathTestCasesPre)); |
| 773 } | 811 } |
| 774 | 812 |
| 775 // Try with a non-empty last save path. | 813 // Try with a non-empty last save path. |
| 776 { | 814 { |
| 777 SCOPED_TRACE(testing::Message() | 815 SCOPED_TRACE(testing::Message() |
| 778 << "Running with local last_selected_directory"); | 816 << "Running with local last_selected_directory"); |
| 779 download_prefs()->SetSaveFilePath(test_download_dir().AppendASCII("foo")); | 817 download_prefs()->SetSaveFilePath(test_download_dir().AppendASCII("foo")); |
| 780 base::FilePath prompt_path = | 818 base::FilePath prompt_path = |
| 781 GetPathInDownloadDir(FILE_PATH_LITERAL("foo/foo.txt")); | 819 GetPathInDownloadDir(FILE_PATH_LITERAL("foo/foo.txt")); |
| 782 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, prompt_path, _)); | 820 EXPECT_CALL(*delegate(), |
| 821 RequestConfirmation(_, prompt_path, | |
| 822 DownloadConfirmationReason::SAVE_AS, _)); | |
| 783 RunTestCasesWithActiveItem(kLastSavePathTestCasesPost, | 823 RunTestCasesWithActiveItem(kLastSavePathTestCasesPost, |
| 784 arraysize(kLastSavePathTestCasesPost)); | 824 arraysize(kLastSavePathTestCasesPost)); |
| 785 } | 825 } |
| 786 | 826 |
| 787 // And again, but this time use a virtual directory. | 827 // And again, but this time use a virtual directory. |
| 788 { | 828 { |
| 789 SCOPED_TRACE(testing::Message() | 829 SCOPED_TRACE(testing::Message() |
| 790 << "Running with virtual last_selected_directory"); | 830 << "Running with virtual last_selected_directory"); |
| 791 base::FilePath last_selected_dir = test_virtual_dir().AppendASCII("foo"); | 831 base::FilePath last_selected_dir = test_virtual_dir().AppendASCII("foo"); |
| 792 base::FilePath virtual_path = last_selected_dir.AppendASCII("foo.txt"); | 832 base::FilePath virtual_path = last_selected_dir.AppendASCII("foo.txt"); |
| 793 download_prefs()->SetSaveFilePath(last_selected_dir); | 833 download_prefs()->SetSaveFilePath(last_selected_dir); |
| 794 EXPECT_CALL(*delegate(), PromptUserForDownloadPath( | 834 EXPECT_CALL(*delegate(), |
| 795 _, last_selected_dir.AppendASCII("foo.txt"), _)); | 835 RequestConfirmation(_, last_selected_dir.AppendASCII("foo.txt"), |
| 836 DownloadConfirmationReason::SAVE_AS, _)); | |
| 796 EXPECT_CALL(*delegate(), DetermineLocalPath(_, virtual_path, _)) | 837 EXPECT_CALL(*delegate(), DetermineLocalPath(_, virtual_path, _)) |
| 797 .WillOnce(WithArg<2>(ScheduleCallback( | 838 .WillOnce(WithArg<2>(ScheduleCallback( |
| 798 GetPathInDownloadDir(FILE_PATH_LITERAL("bar.txt"))))); | 839 GetPathInDownloadDir(FILE_PATH_LITERAL("bar.txt"))))); |
| 799 RunTestCasesWithActiveItem(kLastSavePathTestCasesVirtual, | 840 RunTestCasesWithActiveItem(kLastSavePathTestCasesVirtual, |
| 800 arraysize(kLastSavePathTestCasesVirtual)); | 841 arraysize(kLastSavePathTestCasesVirtual)); |
| 801 } | 842 } |
| 802 } | 843 } |
| 803 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 804 | 844 |
| 805 // These tests are run with the default downloads folder set to a virtual | 845 // These tests are run with the default downloads folder set to a virtual |
| 806 // directory. | 846 // directory. |
| 807 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_DefaultVirtual) { | 847 TEST_F(DownloadTargetDeterminerTest, DefaultVirtual) { |
| 808 // The default download directory is the virutal path. | 848 // The default download directory is the virutal path. |
| 809 download_prefs()->SetDownloadPath(test_virtual_dir()); | 849 download_prefs()->SetDownloadPath(test_virtual_dir()); |
| 810 | 850 |
| 811 { | 851 { |
| 812 SCOPED_TRACE(testing::Message() << "Automatic Safe Download"); | 852 SCOPED_TRACE(testing::Message() << "Automatic Safe Download"); |
| 813 const DownloadTestCase kAutomaticDownloadToVirtualDir = { | 853 const DownloadTestCase kAutomaticDownloadToVirtualDir = { |
| 814 AUTOMATIC, | 854 AUTOMATIC, |
| 815 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 855 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 816 DownloadFileType::NOT_DANGEROUS, | 856 DownloadFileType::NOT_DANGEROUS, |
| 817 "http://example.com/foo.txt", | 857 "http://example.com/foo.txt", |
| 818 "text/plain", | 858 "text/plain", |
| 819 FILE_PATH_LITERAL(""), | 859 FILE_PATH_LITERAL(""), |
| 820 | 860 |
| 821 FILE_PATH_LITERAL("foo-local.txt"), | 861 FILE_PATH_LITERAL("foo-local.txt"), |
| 822 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 862 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 823 | 863 |
| 824 EXPECT_LOCAL_PATH}; | 864 EXPECT_LOCAL_PATH}; |
| 825 EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)) | 865 EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)) |
| 826 .WillOnce(WithArg<2>(ScheduleCallback( | 866 .WillOnce(WithArg<2>(ScheduleCallback( |
| 827 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-local.txt"))))); | 867 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-local.txt"))))); |
| 828 RunTestCasesWithActiveItem(&kAutomaticDownloadToVirtualDir, 1); | 868 RunTestCasesWithActiveItem(&kAutomaticDownloadToVirtualDir, 1); |
| 829 } | 869 } |
| 830 | 870 |
| 831 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 832 { | 871 { |
| 833 SCOPED_TRACE(testing::Message() << "Save As to virtual directory"); | 872 SCOPED_TRACE(testing::Message() << "Save As to virtual directory"); |
| 834 const DownloadTestCase kSaveAsToVirtualDir = { | 873 const DownloadTestCase kSaveAsToVirtualDir = { |
| 835 SAVE_AS, | 874 SAVE_AS, |
| 836 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 875 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 837 DownloadFileType::NOT_DANGEROUS, | 876 DownloadFileType::NOT_DANGEROUS, |
| 838 "http://example.com/bar.txt", | 877 "http://example.com/bar.txt", |
| 839 "text/plain", | 878 "text/plain", |
| 840 FILE_PATH_LITERAL(""), | 879 FILE_PATH_LITERAL(""), |
| 841 | 880 |
| 842 FILE_PATH_LITERAL("foo-local.txt"), | 881 FILE_PATH_LITERAL("foo-local.txt"), |
| 843 DownloadItem::TARGET_DISPOSITION_PROMPT, | 882 DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 844 | 883 |
| 845 EXPECT_LOCAL_PATH}; | 884 EXPECT_LOCAL_PATH}; |
| 846 EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)) | 885 EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)) |
| 847 .WillOnce(WithArg<2>(ScheduleCallback( | 886 .WillOnce(WithArg<2>(ScheduleCallback( |
| 848 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-local.txt"))))); | 887 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-local.txt"))))); |
| 849 EXPECT_CALL(*delegate(), PromptUserForDownloadPath( | 888 EXPECT_CALL(*delegate(), RequestConfirmation( |
| 850 _, test_virtual_dir().AppendASCII("bar.txt"), _)) | 889 _, test_virtual_dir().AppendASCII("bar.txt"), |
| 851 .WillOnce(WithArg<2>(ScheduleCallback( | 890 DownloadConfirmationReason::SAVE_AS, _)) |
| 852 test_virtual_dir().AppendASCII("prompted.txt")))); | 891 .WillOnce(WithArg<3>( |
| 892 ScheduleCallback2(DownloadConfirmationResult::CONFIRMED, | |
| 893 test_virtual_dir().AppendASCII("prompted.txt")))); | |
| 853 RunTestCasesWithActiveItem(&kSaveAsToVirtualDir, 1); | 894 RunTestCasesWithActiveItem(&kSaveAsToVirtualDir, 1); |
| 854 } | 895 } |
| 855 | 896 |
| 897 // "Save as" is not supported on Android. | |
|
svaldez
2016/10/28 17:29:36
Should this move up one test?
asanka
2016/11/07 19:50:15
Should be removed. At the DTD layer, Android deals
| |
| 856 { | 898 { |
| 857 SCOPED_TRACE(testing::Message() << "Save As to local directory"); | 899 SCOPED_TRACE(testing::Message() << "Save As to local directory"); |
| 858 const DownloadTestCase kSaveAsToLocalDir = { | 900 const DownloadTestCase kSaveAsToLocalDir = { |
| 859 SAVE_AS, | 901 SAVE_AS, |
| 860 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 902 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 861 DownloadFileType::NOT_DANGEROUS, | 903 DownloadFileType::NOT_DANGEROUS, |
| 862 "http://example.com/bar.txt", | 904 "http://example.com/bar.txt", |
| 863 "text/plain", | 905 "text/plain", |
| 864 FILE_PATH_LITERAL(""), | 906 FILE_PATH_LITERAL(""), |
| 865 | 907 |
| 866 FILE_PATH_LITERAL("foo-x.txt"), | 908 FILE_PATH_LITERAL("foo-x.txt"), |
| 867 DownloadItem::TARGET_DISPOSITION_PROMPT, | 909 DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 868 | 910 |
| 869 EXPECT_CRDOWNLOAD}; | 911 EXPECT_CRDOWNLOAD}; |
| 870 EXPECT_CALL(*delegate(), PromptUserForDownloadPath( | 912 EXPECT_CALL(*delegate(), RequestConfirmation( |
| 871 _, test_virtual_dir().AppendASCII("bar.txt"), _)) | 913 _, test_virtual_dir().AppendASCII("bar.txt"), |
| 872 .WillOnce(WithArg<2>(ScheduleCallback( | 914 DownloadConfirmationReason::SAVE_AS, _)) |
| 915 .WillOnce(WithArg<3>(ScheduleCallback2( | |
| 916 DownloadConfirmationResult::CONFIRMED, | |
| 873 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-x.txt"))))); | 917 GetPathInDownloadDir(FILE_PATH_LITERAL("foo-x.txt"))))); |
| 874 RunTestCasesWithActiveItem(&kSaveAsToLocalDir, 1); | 918 RunTestCasesWithActiveItem(&kSaveAsToLocalDir, 1); |
| 875 } | 919 } |
| 876 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 877 | 920 |
| 878 { | 921 { |
| 879 SCOPED_TRACE(testing::Message() << "Forced safe download"); | 922 SCOPED_TRACE(testing::Message() << "Forced safe download"); |
| 880 const DownloadTestCase kForcedSafe = { | 923 const DownloadTestCase kForcedSafe = { |
| 881 FORCED, | 924 FORCED, |
| 882 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 925 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 883 DownloadFileType::NOT_DANGEROUS, | 926 DownloadFileType::NOT_DANGEROUS, |
| 884 "http://example.com/foo.txt", | 927 "http://example.com/foo.txt", |
| 885 "", | 928 "", |
| 886 FILE_PATH_LITERAL("forced-foo.txt"), | 929 FILE_PATH_LITERAL("forced-foo.txt"), |
| 887 | 930 |
| 888 FILE_PATH_LITERAL("forced-foo.txt"), | 931 FILE_PATH_LITERAL("forced-foo.txt"), |
| 889 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 932 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 890 | 933 |
| 891 EXPECT_LOCAL_PATH}; | 934 EXPECT_LOCAL_PATH}; |
| 892 RunTestCasesWithActiveItem(&kForcedSafe, 1); | 935 RunTestCasesWithActiveItem(&kForcedSafe, 1); |
| 893 } | 936 } |
| 894 } | 937 } |
| 895 | 938 |
| 896 // Test that an inactive download will still get a virtual or local download | 939 // Test that an inactive download will still get a virtual or local download |
| 897 // path. | 940 // path. |
| 898 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_InactiveDownload) { | 941 TEST_F(DownloadTargetDeterminerTest, InactiveDownload) { |
| 899 const DownloadTestCase kInactiveTestCases[] = { | 942 const DownloadTestCase kInactiveTestCases[] = { |
| 900 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 943 {AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 901 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 944 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 902 "text/plain", FILE_PATH_LITERAL(""), | 945 "text/plain", FILE_PATH_LITERAL(""), |
| 903 | 946 |
| 904 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 947 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 905 | 948 |
| 906 EXPECT_CRDOWNLOAD}, | 949 EXPECT_CRDOWNLOAD}, |
| 907 | 950 |
| 908 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 909 {SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 951 {SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 910 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 952 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 911 "text/plain", FILE_PATH_LITERAL(""), | 953 "text/plain", FILE_PATH_LITERAL(""), |
| 912 | 954 |
| 913 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 955 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 914 | 956 |
| 915 EXPECT_CRDOWNLOAD} | 957 EXPECT_CRDOWNLOAD}}; |
|
svaldez
2016/10/28 17:29:36
Extra whitespace?
asanka
2016/11/07 19:50:15
Reformatted.
| |
| 916 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 917 }; | |
| 918 | 958 |
| 919 for (size_t i = 0; i < arraysize(kInactiveTestCases); ++i) { | 959 for (size_t i = 0; i < arraysize(kInactiveTestCases); ++i) { |
| 920 SCOPED_TRACE(testing::Message() << "Running test case " << i); | 960 SCOPED_TRACE(testing::Message() << "Running test case " << i); |
| 921 const DownloadTestCase& test_case = kInactiveTestCases[i]; | 961 const DownloadTestCase& test_case = kInactiveTestCases[i]; |
| 922 std::unique_ptr<content::MockDownloadItem> item( | 962 std::unique_ptr<content::MockDownloadItem> item = |
| 923 CreateActiveDownloadItem(i, test_case)); | 963 CreateActiveDownloadItem(i, test_case); |
| 924 EXPECT_CALL(*item.get(), GetState()) | 964 EXPECT_CALL(*item.get(), GetState()) |
| 925 .WillRepeatedly(Return(content::DownloadItem::CANCELLED)); | 965 .WillRepeatedly(Return(content::DownloadItem::CANCELLED)); |
| 926 | 966 |
| 927 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, _, _)).Times(0); | 967 EXPECT_CALL(*delegate(), RequestConfirmation(_, _, _, _)).Times(0); |
| 928 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)).Times(0); | 968 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)).Times(0); |
| 929 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, _, _, _, _)).Times(0); | 969 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, _, _, _, _)).Times(0); |
| 930 EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)).Times(1); | 970 EXPECT_CALL(*delegate(), DetermineLocalPath(_, _, _)).Times(1); |
| 931 RunTestCase(test_case, base::FilePath(), item.get()); | 971 RunTestCase(test_case, base::FilePath(), item.get()); |
| 932 } | 972 } |
| 933 } | 973 } |
| 934 | 974 |
| 975 namespace { | |
| 976 | |
| 977 // TODO(asanka): Once we can use C++14, make this a constexpr and use | |
| 978 // static_assert where ASSERT* is used. Once we can use C++17 switch to using | |
| 979 // reflection. | |
| 980 size_t CountDownloadTargetResultValues() { | |
|
svaldez
2016/10/28 17:29:36
Seems excessive since if we forget to add a test c
asanka
2016/11/07 19:50:15
This one fails to compile if we forget to add an e
| |
| 981 size_t count = 0; | |
| 982 DownloadTargetResult result = DownloadTargetResult::SUCCESS; | |
| 983 switch (result) { | |
| 984 case DownloadTargetResult::SUCCESS: | |
| 985 count++; | |
| 986 case DownloadTargetResult::USER_CANCELED: | |
| 987 count++; | |
| 988 case DownloadTargetResult::UNEXPECTED: | |
| 989 count++; | |
| 990 case DownloadTargetResult::NAME_TOO_LONG: | |
| 991 count++; | |
| 992 case DownloadTargetResult::CONFLICT: | |
| 993 count++; | |
| 994 case DownloadTargetResult::PATH_NOT_WRITEABLE: | |
| 995 count++; | |
| 996 // Oh you added a new |DownloadTargetResult| type? Add a case here for | |
| 997 // your new value and increment |count|. Don't forget to update the tests | |
| 998 // below. If not, the try bots will remind you. | |
| 999 } | |
| 1000 return count; | |
| 1001 } | |
| 1002 | |
| 1003 } // namespace | |
| 1004 | |
| 935 // If the reserved path could not be verified, then the user should see a | 1005 // If the reserved path could not be verified, then the user should see a |
| 936 // prompt. | 1006 // prompt. |
| 937 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ReservationFailed) { | 1007 TEST_F(DownloadTargetDeterminerTest, ReservationFailed_Confirmation) { |
| 938 const DownloadTestCase kReservationFailedCases[] = { | 1008 DownloadTestCase download_test_case = { |
| 939 {// 0: Automatic download. Since the reservation fails, the disposition of | 1009 // 0: Automatic download. Since the reservation fails, the disposition of |
| 940 // the target is to prompt, but the returned path is used. | 1010 // the target is to prompt, but the returned path is used. |
| 941 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1011 AUTOMATIC, |
| 942 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1012 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 943 "text/plain", FILE_PATH_LITERAL(""), | 1013 DownloadFileType::NOT_DANGEROUS, |
| 1014 "http://example.com/foo.txt", | |
| 1015 "text/plain", | |
| 1016 FILE_PATH_LITERAL(""), | |
| 944 | 1017 |
| 945 FILE_PATH_LITERAL("bar.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 1018 FILE_PATH_LITERAL("bar.txt"), |
| 1019 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
| 946 | 1020 |
| 947 EXPECT_CRDOWNLOAD}, | 1021 EXPECT_CRDOWNLOAD}; |
| 1022 | |
| 1023 struct { | |
| 1024 DownloadTargetResult result; | |
| 1025 DownloadConfirmationReason expected_confirmation_reason; | |
| 1026 } kTestCases[] = { | |
| 1027 // Reservation succeeded. No confirmation needed. | |
| 1028 {DownloadTargetResult::SUCCESS, DownloadConfirmationReason::NONE}, | |
| 1029 | |
| 1030 // User cancelled the reservation. No further confirmation needed. | |
| 1031 {DownloadTargetResult::USER_CANCELED, DownloadConfirmationReason::NONE}, | |
| 1032 | |
| 1033 // An unexpected error occurred. The download will be marked as | |
| 1034 // interrupted. No confirmation needed. | |
| 1035 {DownloadTargetResult::UNEXPECTED, DownloadConfirmationReason::NONE}, | |
| 1036 | |
| 1037 // The name was too long. Need to confirm with user. | |
| 1038 {DownloadTargetResult::NAME_TOO_LONG, | |
| 1039 DownloadConfirmationReason::NAME_TOO_LONG}, | |
| 1040 | |
| 1041 // Pathname conflict. User confirmation needed. | |
| 1042 {DownloadTargetResult::CONFLICT, | |
| 1043 DownloadConfirmationReason::TARGET_CONFLICT}, | |
| 1044 | |
| 1045 // The path is not writeable. Prompt user for a new path. | |
| 1046 {DownloadTargetResult::PATH_NOT_WRITEABLE, | |
| 1047 DownloadConfirmationReason::TARGET_NOT_WRITEABLE}, | |
| 948 }; | 1048 }; |
| 949 | 1049 |
| 950 // Setup ReserveVirtualPath() to fail. | 1050 ASSERT_EQ(CountDownloadTargetResultValues(), arraysize(kTestCases)) |
|
svaldez
2016/10/28 17:29:36
This seems kind of fragile. Maybe something like:
asanka
2016/11/07 19:50:15
Hmm. I tried something like that here. Better?
| |
| 951 ON_CALL(*delegate(), ReserveVirtualPath(_, _, _, _, _)) | 1051 << "All enumeration values for DownloadTargetResult must be tested"; |
| 952 .WillByDefault(WithArg<4>(ScheduleCallback2( | 1052 |
| 953 GetPathInDownloadDir(FILE_PATH_LITERAL("bar.txt")), false))); | 1053 for (auto& test_case : kTestCases) { |
| 954 RunTestCasesWithActiveItem(kReservationFailedCases, | 1054 SCOPED_TRACE(::testing::Message() << "DownloadTargetResult " |
| 955 arraysize(kReservationFailedCases)); | 1055 << static_cast<int>(test_case.result)); |
| 1056 ON_CALL(*delegate(), ReserveVirtualPath(_, _, _, _, _)) | |
| 1057 .WillByDefault(WithArg<4>(ScheduleCallback2( | |
| 1058 GetPathInDownloadDir(FILE_PATH_LITERAL("bar.txt")), | |
| 1059 test_case.result))); | |
| 1060 if (test_case.expected_confirmation_reason != | |
| 1061 DownloadConfirmationReason::NONE) { | |
| 1062 EXPECT_CALL( | |
| 1063 *delegate(), | |
| 1064 RequestConfirmation(_, _, test_case.expected_confirmation_reason, _)); | |
| 1065 } else { | |
| 1066 EXPECT_CALL(*delegate(), RequestConfirmation(_, _, _, _)).Times(0); | |
| 1067 } | |
| 1068 | |
| 1069 download_test_case.expected_disposition = | |
| 1070 test_case.expected_confirmation_reason == | |
| 1071 DownloadConfirmationReason::NONE | |
| 1072 ? content::DownloadItem::TARGET_DISPOSITION_OVERWRITE | |
| 1073 : content::DownloadItem::TARGET_DISPOSITION_PROMPT; | |
| 1074 std::unique_ptr<content::MockDownloadItem> item = CreateActiveDownloadItem( | |
| 1075 static_cast<int>(test_case.result), download_test_case); | |
| 1076 RunTestCase(download_test_case, base::FilePath(), item.get()); | |
| 1077 } | |
| 956 } | 1078 } |
| 957 | 1079 |
| 958 // If the local path could not be determined, the download should be cancelled. | 1080 // If the local path could not be determined, the download should be cancelled. |
| 959 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_LocalPathFailed) { | 1081 TEST_F(DownloadTargetDeterminerTest, LocalPathFailed) { |
| 960 const DownloadTestCase kLocalPathFailedCases[] = { | 1082 const DownloadTestCase kLocalPathFailedCases[] = { |
| 961 {// 0: Automatic download. | 1083 {// 0: Automatic download. |
| 962 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1084 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 963 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1085 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 964 "text/plain", FILE_PATH_LITERAL(""), | 1086 "text/plain", FILE_PATH_LITERAL(""), |
| 965 | 1087 |
| 966 FILE_PATH_LITERAL(""), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1088 FILE_PATH_LITERAL(""), DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 967 | 1089 |
| 968 EXPECT_LOCAL_PATH}, | 1090 EXPECT_LOCAL_PATH}, |
| 969 }; | 1091 }; |
| 970 | 1092 |
| 971 // The default download directory is the virtual path. | 1093 // The default download directory is the virtual path. |
| 972 download_prefs()->SetDownloadPath(test_virtual_dir()); | 1094 download_prefs()->SetDownloadPath(test_virtual_dir()); |
| 973 // Simulate failed call to DetermineLocalPath. | 1095 // Simulate failed call to DetermineLocalPath. |
| 974 EXPECT_CALL(*delegate(), DetermineLocalPath( | 1096 EXPECT_CALL(*delegate(), DetermineLocalPath( |
| 975 _, GetPathInDownloadDir(FILE_PATH_LITERAL("virtual/foo.txt")), _)) | 1097 _, GetPathInDownloadDir(FILE_PATH_LITERAL("virtual/foo.txt")), _)) |
| 976 .WillOnce(WithArg<2>(ScheduleCallback(base::FilePath()))); | 1098 .WillOnce(WithArg<2>(ScheduleCallback(base::FilePath()))); |
| 977 RunTestCasesWithActiveItem(kLocalPathFailedCases, | 1099 RunTestCasesWithActiveItem(kLocalPathFailedCases, |
| 978 arraysize(kLocalPathFailedCases)); | 1100 arraysize(kLocalPathFailedCases)); |
| 979 } | 1101 } |
| 980 | 1102 |
| 981 // Downloads that have a danger level of ALLOW_ON_USER_GESTURE should be marked | 1103 // Downloads that have a danger level of ALLOW_ON_USER_GESTURE should be marked |
| 982 // as safe depending on whether there was a user gesture associated with the | 1104 // as safe depending on whether there was a user gesture associated with the |
| 983 // download and whether the referrer was visited prior to today. | 1105 // download and whether the referrer was visited prior to today. |
| 984 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_VisitedReferrer) { | 1106 TEST_F(DownloadTargetDeterminerTest, VisitedReferrer) { |
| 985 const DownloadTestCase kVisitedReferrerCases[] = { | 1107 const DownloadTestCase kVisitedReferrerCases[] = { |
| 986 // http://visited.example.com/ is added to the history as a visit that | 1108 // http://visited.example.com/ is added to the history as a visit that |
| 987 // happened prior to today. | 1109 // happened prior to today. |
| 988 {// 0: Safe download due to visiting referrer before. | 1110 {// 0: Safe download due to visiting referrer before. |
| 989 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1111 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 990 DownloadFileType::NOT_DANGEROUS, "http://visited.example.com/foo.crx", | 1112 DownloadFileType::NOT_DANGEROUS, |
| 991 "application/xml", FILE_PATH_LITERAL(""), | 1113 "http://visited.example.com/foo.kindabad", "application/xml", |
| 1114 FILE_PATH_LITERAL(""), | |
| 992 | 1115 |
| 993 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1116 FILE_PATH_LITERAL("foo.kindabad"), |
| 1117 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 994 | 1118 |
| 995 EXPECT_CRDOWNLOAD}, | 1119 EXPECT_CRDOWNLOAD}, |
| 996 | 1120 |
| 997 {// 1: Dangerous due to not having visited referrer before. | 1121 {// 1: Dangerous due to not having visited referrer before. |
| 998 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1122 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 999 DownloadFileType::ALLOW_ON_USER_GESTURE, | 1123 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1000 "http://not-visited.example.com/foo.crx", "application/xml", | 1124 "http://not-visited.example.com/foo.kindabad", "application/xml", |
| 1001 FILE_PATH_LITERAL(""), | 1125 FILE_PATH_LITERAL(""), |
| 1002 | 1126 |
| 1003 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1127 FILE_PATH_LITERAL("foo.kindabad"), |
| 1128 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1004 | 1129 |
| 1005 EXPECT_UNCONFIRMED}, | 1130 EXPECT_UNCONFIRMED}, |
| 1006 | 1131 |
| 1007 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 1008 {// 2: Safe because the user is being prompted. | 1132 {// 2: Safe because the user is being prompted. |
| 1009 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1133 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1010 DownloadFileType::NOT_DANGEROUS, | 1134 DownloadFileType::NOT_DANGEROUS, |
| 1011 "http://not-visited.example.com/foo.crx", "application/xml", | 1135 "http://not-visited.example.com/foo.kindabad", "application/xml", |
| 1012 FILE_PATH_LITERAL(""), | 1136 FILE_PATH_LITERAL(""), |
| 1013 | 1137 |
| 1014 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 1138 FILE_PATH_LITERAL("foo.kindabad"), |
| 1139 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
| 1015 | 1140 |
| 1016 EXPECT_CRDOWNLOAD}, | 1141 EXPECT_CRDOWNLOAD}, |
| 1017 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 1018 | 1142 |
| 1019 {// 3: Safe because of forced path. | 1143 {// 3: Safe because of forced path. |
| 1020 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1144 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1021 DownloadFileType::NOT_DANGEROUS, | 1145 DownloadFileType::NOT_DANGEROUS, |
| 1022 "http://not-visited.example.com/foo.crx", "application/xml", | 1146 "http://not-visited.example.com/foo.kindabad", "application/xml", |
| 1023 FILE_PATH_LITERAL("foo.crx"), | 1147 FILE_PATH_LITERAL("foo.kindabad"), |
| 1024 | 1148 |
| 1025 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1149 FILE_PATH_LITERAL("foo.kindabad"), |
| 1150 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1026 | 1151 |
| 1027 EXPECT_LOCAL_PATH}, | 1152 EXPECT_LOCAL_PATH}, |
| 1028 }; | 1153 }; |
| 1029 | 1154 |
| 1030 // This test assumes that the danger level of .crx files is | 1155 // This test assumes that the danger level of .kindabad files is |
| 1031 // ALLOW_ON_USER_GESTURE. | 1156 // ALLOW_ON_USER_GESTURE. |
| 1032 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, | 1157 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1033 Policies()->GetFileDangerLevel( | 1158 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 1034 base::FilePath(FILE_PATH_LITERAL("foo.crx")))); | 1159 base::FilePath(FILE_PATH_LITERAL("foo.kindabad")))); |
| 1035 | 1160 |
| 1036 // First the history service must exist. | 1161 // First the history service must exist. |
| 1037 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); | 1162 ASSERT_TRUE(profile()->CreateHistoryService(false, false)); |
| 1038 | 1163 |
| 1039 GURL url("http://visited.example.com/visited-link.html"); | 1164 GURL url("http://visited.example.com/visited-link.html"); |
| 1040 // The time of visit is picked to be several seconds prior to the most recent | 1165 // The time of visit is picked to be several seconds prior to the most recent |
| 1041 // midnight. | 1166 // midnight. |
| 1042 base::Time time_of_visit( | 1167 base::Time time_of_visit( |
| 1043 base::Time::Now().LocalMidnight() - base::TimeDelta::FromSeconds(10)); | 1168 base::Time::Now().LocalMidnight() - base::TimeDelta::FromSeconds(10)); |
| 1044 history::HistoryService* history_service = | 1169 history::HistoryService* history_service = |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1062 | 1187 |
| 1063 FILE_PATH_LITERAL("foo.txt"), | 1188 FILE_PATH_LITERAL("foo.txt"), |
| 1064 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1189 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1065 | 1190 |
| 1066 EXPECT_CRDOWNLOAD}; | 1191 EXPECT_CRDOWNLOAD}; |
| 1067 | 1192 |
| 1068 const DownloadTestCase kAllowOnUserGesture = { | 1193 const DownloadTestCase kAllowOnUserGesture = { |
| 1069 AUTOMATIC, | 1194 AUTOMATIC, |
| 1070 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1195 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1071 DownloadFileType::ALLOW_ON_USER_GESTURE, | 1196 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1072 "http://example.com/foo.crx", | 1197 "http://example.com/foo.kindabad", |
| 1073 "application/octet-stream", | 1198 "application/octet-stream", |
| 1074 FILE_PATH_LITERAL(""), | 1199 FILE_PATH_LITERAL(""), |
| 1075 | 1200 |
| 1076 FILE_PATH_LITERAL("foo.crx"), | 1201 FILE_PATH_LITERAL("foo.kindabad"), |
| 1077 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1202 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1078 | 1203 |
| 1079 EXPECT_UNCONFIRMED}; | 1204 EXPECT_UNCONFIRMED}; |
| 1080 | 1205 |
| 1081 const DownloadTestCase kDangerousFile = { | 1206 const DownloadTestCase kDangerousFile = { |
| 1082 AUTOMATIC, | 1207 AUTOMATIC, |
| 1083 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1208 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1084 DownloadFileType::DANGEROUS, | 1209 DownloadFileType::DANGEROUS, |
| 1085 "http://example.com/foo.swf", | 1210 "http://example.com/foo.bad", |
| 1086 "application/octet-stream", | 1211 "application/octet-stream", |
| 1087 FILE_PATH_LITERAL(""), | 1212 FILE_PATH_LITERAL(""), |
| 1088 | 1213 |
| 1089 FILE_PATH_LITERAL("foo.swf"), | 1214 FILE_PATH_LITERAL("foo.bad"), |
| 1090 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1215 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1091 | 1216 |
| 1092 EXPECT_UNCONFIRMED}; | 1217 EXPECT_UNCONFIRMED}; |
| 1093 | 1218 |
| 1094 const struct { | 1219 const struct { |
| 1095 ui::PageTransition page_transition; | 1220 ui::PageTransition page_transition; |
| 1096 content::DownloadDangerType expected_danger_type; | 1221 content::DownloadDangerType expected_danger_type; |
| 1097 const DownloadTestCase& template_download_test_case; | 1222 const DownloadTestCase& template_download_test_case; |
| 1098 } kTestCases[] = { | 1223 } kTestCases[] = { |
| 1099 {// Benign file type. Results in a danger type of NOT_DANGEROUS. Page | 1224 {// Benign file type. Results in a danger type of NOT_DANGEROUS. Page |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1132 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, kAllowOnUserGesture}, | 1257 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, kAllowOnUserGesture}, |
| 1133 | 1258 |
| 1134 {// File type is DANGEROUS. PageTransition is irrelevant. | 1259 {// File type is DANGEROUS. PageTransition is irrelevant. |
| 1135 static_cast<ui::PageTransition>(ui::PAGE_TRANSITION_TYPED | | 1260 static_cast<ui::PageTransition>(ui::PAGE_TRANSITION_TYPED | |
| 1136 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR), | 1261 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR), |
| 1137 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, kDangerousFile}, | 1262 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, kDangerousFile}, |
| 1138 }; | 1263 }; |
| 1139 | 1264 |
| 1140 // Test assumptions: | 1265 // Test assumptions: |
| 1141 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, | 1266 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1142 Policies()->GetFileDangerLevel( | 1267 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 1143 base::FilePath(FILE_PATH_LITERAL("foo.crx")))); | 1268 base::FilePath(FILE_PATH_LITERAL("foo.kindabad")))); |
| 1144 ASSERT_EQ(DownloadFileType::DANGEROUS, | 1269 ASSERT_EQ(DownloadFileType::DANGEROUS, |
| 1145 Policies()->GetFileDangerLevel( | 1270 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 1146 base::FilePath(FILE_PATH_LITERAL("foo.swf")))); | 1271 base::FilePath(FILE_PATH_LITERAL("foo.bad")))); |
| 1147 ASSERT_EQ(DownloadFileType::NOT_DANGEROUS, | 1272 ASSERT_EQ(DownloadFileType::NOT_DANGEROUS, |
| 1148 Policies()->GetFileDangerLevel( | 1273 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 1149 base::FilePath(FILE_PATH_LITERAL("foo.txt")))); | 1274 base::FilePath(FILE_PATH_LITERAL("foo.txt")))); |
| 1150 | 1275 |
| 1151 for (const auto& test_case : kTestCases) { | 1276 for (const auto& test_case : kTestCases) { |
| 1152 // The template download test case describes what to expect if the page | 1277 // The template download test case describes what to expect if the page |
| 1153 // transition was LINK. If the expectation is that the page transition type | 1278 // transition was LINK. If the expectation is that the page transition type |
| 1154 // causes the download to be considered safe, then download_test_case needs | 1279 // causes the download to be considered safe, then download_test_case needs |
| 1155 // to be adjusted accordingly. | 1280 // to be adjusted accordingly. |
| 1156 DownloadTestCase download_test_case = test_case.template_download_test_case; | 1281 DownloadTestCase download_test_case = test_case.template_download_test_case; |
| 1157 download_test_case.expected_danger_type = test_case.expected_danger_type; | 1282 download_test_case.expected_danger_type = test_case.expected_danger_type; |
| 1158 if (test_case.expected_danger_type == | 1283 if (test_case.expected_danger_type == |
| 1159 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { | 1284 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
| 1160 download_test_case.expected_danger_level = | 1285 download_test_case.expected_danger_level = |
| 1161 DownloadFileType::NOT_DANGEROUS; | 1286 DownloadFileType::NOT_DANGEROUS; |
| 1162 download_test_case.expected_intermediate = EXPECT_CRDOWNLOAD; | 1287 download_test_case.expected_intermediate = EXPECT_CRDOWNLOAD; |
| 1163 } | 1288 } |
| 1164 | 1289 |
| 1165 std::unique_ptr<content::MockDownloadItem> item( | 1290 std::unique_ptr<content::MockDownloadItem> item = |
| 1166 CreateActiveDownloadItem(1, download_test_case)); | 1291 CreateActiveDownloadItem(1, download_test_case); |
| 1167 EXPECT_CALL(*item, GetTransitionType()) | 1292 EXPECT_CALL(*item, GetTransitionType()) |
| 1168 .WillRepeatedly(Return(test_case.page_transition)); | 1293 .WillRepeatedly(Return(test_case.page_transition)); |
| 1169 RunTestCase(download_test_case, base::FilePath(), item.get()); | 1294 RunTestCase(download_test_case, base::FilePath(), item.get()); |
| 1170 } | 1295 } |
| 1171 } | 1296 } |
| 1172 | 1297 |
| 1173 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 1174 // These test cases are run with "Prompt for download" user preference set to | 1298 // These test cases are run with "Prompt for download" user preference set to |
| 1175 // true. | 1299 // true. |
| 1176 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways) { | 1300 TEST_F(DownloadTargetDeterminerTest, PromptAlways_SafeAutomatic) { |
| 1301 const DownloadTestCase kSafeAutomatic = { | |
| 1302 // 0: Safe Automatic - Should prompt because of "Prompt for download" | |
| 1303 // preference setting. | |
| 1304 AUTOMATIC, | |
| 1305 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1306 DownloadFileType::NOT_DANGEROUS, | |
| 1307 "http://example.com/automatic.txt", | |
| 1308 "text/plain", | |
| 1309 FILE_PATH_LITERAL(""), | |
| 1310 | |
| 1311 FILE_PATH_LITERAL("automatic.txt"), | |
| 1312 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
| 1313 | |
| 1314 EXPECT_CRDOWNLOAD}; | |
| 1315 | |
| 1316 SetPromptForDownload(true); | |
| 1317 EXPECT_CALL(*delegate(), | |
| 1318 RequestConfirmation( | |
| 1319 _, GetPathInDownloadDir(FILE_PATH_LITERAL("automatic.txt")), | |
| 1320 DownloadConfirmationReason::PREFERENCE, _)); | |
| 1321 RunTestCasesWithActiveItem(&kSafeAutomatic, 1); | |
| 1322 } | |
| 1323 | |
| 1324 TEST_F(DownloadTargetDeterminerTest, PromptAlways_SafeSaveAs) { | |
| 1325 const DownloadTestCase kSafeSaveAs = { | |
| 1326 // 1: Safe Save As - Should prompt because of "Save as" invocation. | |
| 1327 SAVE_AS, | |
| 1328 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1329 DownloadFileType::NOT_DANGEROUS, | |
| 1330 "http://example.com/save-as.txt", | |
| 1331 "text/plain", | |
| 1332 FILE_PATH_LITERAL(""), | |
| 1333 | |
| 1334 FILE_PATH_LITERAL("save-as.txt"), | |
| 1335 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
| 1336 | |
| 1337 EXPECT_CRDOWNLOAD}; | |
| 1338 | |
| 1339 SetPromptForDownload(true); | |
| 1340 EXPECT_CALL(*delegate(), | |
| 1341 RequestConfirmation( | |
| 1342 _, GetPathInDownloadDir(FILE_PATH_LITERAL("save-as.txt")), | |
| 1343 DownloadConfirmationReason::SAVE_AS, _)); | |
| 1344 RunTestCasesWithActiveItem(&kSafeSaveAs, 1); | |
| 1345 } | |
| 1346 | |
| 1347 TEST_F(DownloadTargetDeterminerTest, PromptAlways_SafeForced) { | |
| 1348 const DownloadTestCase kSafeForced = { | |
| 1349 // 2: Safe Forced - Shouldn't prompt. | |
| 1350 FORCED, | |
| 1351 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1352 DownloadFileType::NOT_DANGEROUS, | |
| 1353 "http://example.com/foo.txt", | |
| 1354 "text/plain", | |
| 1355 FILE_PATH_LITERAL("foo.txt"), | |
| 1356 | |
| 1357 FILE_PATH_LITERAL("foo.txt"), | |
| 1358 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1359 | |
| 1360 EXPECT_LOCAL_PATH}; | |
| 1361 | |
| 1362 SetPromptForDownload(true); | |
| 1363 RunTestCasesWithActiveItem(&kSafeForced, 1); | |
| 1364 } | |
| 1365 | |
| 1366 TEST_F(DownloadTargetDeterminerTest, PromptAlways_AutoOpen) { | |
| 1367 const DownloadTestCase kAutoOpen = { | |
| 1368 // 3: Automatic - The filename extension is marked as one that we will | |
| 1369 // open automatically. Shouldn't prompt. | |
| 1370 AUTOMATIC, | |
| 1371 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1372 DownloadFileType::NOT_DANGEROUS, | |
| 1373 "http://example.com/foo.dummy", | |
| 1374 "", | |
| 1375 FILE_PATH_LITERAL(""), | |
| 1376 | |
| 1377 FILE_PATH_LITERAL("foo.dummy"), | |
| 1378 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1379 | |
| 1380 EXPECT_CRDOWNLOAD}; | |
| 1381 SetPromptForDownload(true); | |
| 1382 EnableAutoOpenBasedOnExtension( | |
| 1383 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); | |
| 1384 RunTestCasesWithActiveItem(&kAutoOpen, 1); | |
| 1385 } | |
| 1386 | |
| 1387 // If an embedder responds to a RequestConfirmation with a new path and a | |
| 1388 // CONTINUE_WITHOUT_CONFIRMATION, then we shouldn't consider the file as safe. | |
| 1389 TEST_F(DownloadTargetDeterminerTest, ContinueWithoutConfirmation_SaveAs) { | |
| 1390 const DownloadTestCase kTestCase = { | |
| 1391 SAVE_AS, | |
| 1392 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | |
| 1393 DownloadFileType::ALLOW_ON_USER_GESTURE, | |
| 1394 "http://example.com/save-as.kindabad", | |
| 1395 "text/plain", | |
| 1396 FILE_PATH_LITERAL(""), | |
| 1397 | |
| 1398 FILE_PATH_LITERAL("foo.kindabad"), | |
| 1399 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1400 | |
| 1401 EXPECT_UNCONFIRMED}; | |
| 1402 | |
| 1403 EXPECT_CALL(*delegate(), | |
| 1404 RequestConfirmation(_, GetPathInDownloadDir( | |
| 1405 FILE_PATH_LITERAL("save-as.kindabad")), | |
| 1406 DownloadConfirmationReason::SAVE_AS, _)) | |
| 1407 .WillOnce(WithArg<3>(ScheduleCallback2( | |
| 1408 DownloadConfirmationResult::CONTINUE_WITHOUT_CONFIRMATION, | |
| 1409 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.kindabad"))))); | |
| 1410 RunTestCasesWithActiveItem(&kTestCase, 1); | |
| 1411 } | |
| 1412 | |
| 1413 // Same as ContinueWithoutConfirmation_SaveAs, but the embedder response | |
| 1414 // indicates that the user confirmed the path. Hence the danger level of the | |
| 1415 // download and the disposition should be updated accordingly. | |
| 1416 TEST_F(DownloadTargetDeterminerTest, ContinueWithConfirmation_SaveAs) { | |
| 1417 const DownloadTestCase kTestCase = { | |
| 1418 SAVE_AS, | |
| 1419 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1420 DownloadFileType::NOT_DANGEROUS, | |
| 1421 "http://example.com/save-as.kindabad", | |
| 1422 "text/plain", | |
| 1423 FILE_PATH_LITERAL(""), | |
| 1424 | |
| 1425 FILE_PATH_LITERAL("foo.kindabad"), | |
| 1426 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
| 1427 | |
| 1428 EXPECT_CRDOWNLOAD}; | |
| 1429 | |
| 1430 EXPECT_CALL(*delegate(), | |
| 1431 RequestConfirmation(_, GetPathInDownloadDir( | |
| 1432 FILE_PATH_LITERAL("save-as.kindabad")), | |
| 1433 DownloadConfirmationReason::SAVE_AS, _)) | |
| 1434 .WillOnce(WithArg<3>(ScheduleCallback2( | |
| 1435 DownloadConfirmationResult::CONFIRMED, | |
| 1436 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.kindabad"))))); | |
| 1437 RunTestCasesWithActiveItem(&kTestCase, 1); | |
| 1438 } | |
| 1439 | |
| 1440 #if defined(ENABLE_EXTENSIONS) | |
| 1441 // These test cases are run with "Prompt for download" user preference set to | |
| 1442 // true. Automatic extension downloads shouldn't cause prompting. | |
| 1443 // Android doesn't support extensions. | |
| 1444 TEST_F(DownloadTargetDeterminerTest, PromptAlways_Extension) { | |
| 1177 const DownloadTestCase kPromptingTestCases[] = { | 1445 const DownloadTestCase kPromptingTestCases[] = { |
| 1178 {// 0: Safe Automatic - Should prompt because of "Prompt for download" | 1446 {// 0: Automatic Browser Extension download. - Shouldn't prompt for |
| 1179 // preference setting. | 1447 // browser |
| 1180 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1448 // extension downloads even if "Prompt for download" preference is |
| 1181 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1449 // set. |
| 1182 "text/plain", FILE_PATH_LITERAL(""), | 1450 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1183 | 1451 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1184 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, | 1452 "http://example.com/foo.kindabad", extensions::Extension::kMimeType, |
| 1185 | |
| 1186 EXPECT_CRDOWNLOAD}, | |
| 1187 | |
| 1188 {// 1: Safe Forced - Shouldn't prompt. | |
| 1189 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1190 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | |
| 1191 "text/plain", FILE_PATH_LITERAL("foo.txt"), | |
| 1192 | |
| 1193 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1194 | |
| 1195 EXPECT_LOCAL_PATH}, | |
| 1196 | |
| 1197 {// 2: Automatic - The filename extension is marked as one that we will | |
| 1198 // open automatically. Shouldn't prompt. | |
| 1199 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1200 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.dummy", "", | |
| 1201 FILE_PATH_LITERAL(""), | 1453 FILE_PATH_LITERAL(""), |
| 1202 | 1454 |
| 1203 FILE_PATH_LITERAL("foo.dummy"), | 1455 FILE_PATH_LITERAL("foo.kindabad"), |
| 1456 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1457 | |
| 1458 EXPECT_UNCONFIRMED}, | |
| 1459 | |
| 1460 {// 1: Automatic User Script - Shouldn't prompt for user script downloads | |
| 1461 // even if "Prompt for download" preference is set. | |
| 1462 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1463 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.user.js", "", | |
| 1464 FILE_PATH_LITERAL(""), | |
| 1465 | |
| 1466 FILE_PATH_LITERAL("foo.user.js"), | |
| 1204 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1467 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1205 | 1468 |
| 1206 EXPECT_CRDOWNLOAD}, | 1469 EXPECT_CRDOWNLOAD}, |
| 1207 }; | 1470 }; |
| 1208 | 1471 |
| 1209 SetPromptForDownload(true); | 1472 SetPromptForDownload(true); |
| 1210 EnableAutoOpenBasedOnExtension( | |
| 1211 base::FilePath(FILE_PATH_LITERAL("dummy.dummy"))); | |
| 1212 RunTestCasesWithActiveItem(kPromptingTestCases, | |
| 1213 arraysize(kPromptingTestCases)); | |
| 1214 } | |
| 1215 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 1216 | |
| 1217 #if defined(ENABLE_EXTENSIONS) | |
| 1218 // These test cases are run with "Prompt for download" user preference set to | |
| 1219 // true. Automatic extension downloads shouldn't cause prompting. | |
| 1220 // Android doesn't support extensions. | |
| 1221 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_PromptAlways_Extension) { | |
| 1222 const DownloadTestCase kPromptingTestCases[] = { | |
| 1223 {// 0: Automatic Browser Extension download. - Shouldn't prompt for browser | |
| 1224 // extension downloads even if "Prompt for download" preference is set. | |
| 1225 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | |
| 1226 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", | |
| 1227 extensions::Extension::kMimeType, FILE_PATH_LITERAL(""), | |
| 1228 | |
| 1229 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1230 | |
| 1231 EXPECT_UNCONFIRMED}, | |
| 1232 | |
| 1233 #if defined(OS_WIN) | |
| 1234 {// 1: Automatic User Script - Shouldn't prompt for user script downloads | |
| 1235 // even if "Prompt for download" preference is set. ".js" files are | |
| 1236 // considered dangerous on Windows. | |
| 1237 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | |
| 1238 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.user.js", "", | |
| 1239 FILE_PATH_LITERAL(""), | |
| 1240 | |
| 1241 FILE_PATH_LITERAL("foo.user.js"), | |
| 1242 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1243 | |
| 1244 EXPECT_UNCONFIRMED}, | |
| 1245 #else | |
| 1246 {// 1: Automatic User Script - Shouldn't prompt for user script downloads | |
| 1247 // even if "Prompt for download" preference is set. | |
| 1248 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1249 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.user.js", "", | |
| 1250 FILE_PATH_LITERAL(""), | |
| 1251 | |
| 1252 FILE_PATH_LITERAL("foo.user.js"), | |
| 1253 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1254 | |
| 1255 EXPECT_CRDOWNLOAD}, | |
| 1256 #endif | |
| 1257 }; | |
| 1258 | |
| 1259 SetPromptForDownload(true); | |
| 1260 RunTestCasesWithActiveItem(kPromptingTestCases, | 1473 RunTestCasesWithActiveItem(kPromptingTestCases, |
| 1261 arraysize(kPromptingTestCases)); | 1474 arraysize(kPromptingTestCases)); |
| 1262 } | 1475 } |
| 1263 #endif // defined(ENABLE_EXTENSIONS) | 1476 #endif // defined(ENABLE_EXTENSIONS) |
| 1264 | 1477 |
| 1265 // If the download path is managed, then we don't show any prompts. | 1478 // If the download path is managed, then we don't show any prompts. |
| 1266 // Note that if the download path is managed, then PromptForDownload() is false. | 1479 // Note that if the download path is managed, then PromptForDownload() is false. |
| 1267 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ManagedPath) { | 1480 TEST_F(DownloadTargetDeterminerTest, ManagedPath) { |
| 1268 const DownloadTestCase kManagedPathTestCases[] = { | 1481 const DownloadTestCase kManagedPathTestCases[] = { |
| 1269 {// 0: Automatic Safe | 1482 {// 0: Automatic Safe |
| 1270 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1483 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1271 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1484 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1272 "text/plain", FILE_PATH_LITERAL(""), | 1485 "text/plain", FILE_PATH_LITERAL(""), |
| 1273 | 1486 |
| 1274 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1487 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1275 | 1488 |
| 1276 EXPECT_CRDOWNLOAD}, | 1489 EXPECT_CRDOWNLOAD}, |
| 1277 | 1490 |
| 1278 {// 1: Save_As Safe | 1491 {// 1: Save_As Safe |
| 1279 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1492 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1280 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1493 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1281 "text/plain", FILE_PATH_LITERAL(""), | 1494 "text/plain", FILE_PATH_LITERAL(""), |
| 1282 | 1495 |
| 1283 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1496 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1284 | 1497 |
| 1285 EXPECT_CRDOWNLOAD}, | 1498 EXPECT_CRDOWNLOAD}, |
| 1286 }; | 1499 }; |
| 1287 | 1500 |
| 1288 SetManagedDownloadPath(test_download_dir()); | 1501 SetManagedDownloadPath(test_download_dir()); |
| 1289 ASSERT_TRUE(download_prefs()->IsDownloadPathManaged()); | 1502 ASSERT_TRUE(download_prefs()->IsDownloadPathManaged()); |
| 1290 RunTestCasesWithActiveItem(kManagedPathTestCases, | 1503 RunTestCasesWithActiveItem(kManagedPathTestCases, |
| 1291 arraysize(kManagedPathTestCases)); | 1504 arraysize(kManagedPathTestCases)); |
| 1292 } | 1505 } |
| 1293 | 1506 |
| 1294 // Test basic functionality supporting extensions that want to override download | 1507 // Test basic functionality supporting extensions that want to override download |
| 1295 // filenames. | 1508 // filenames. |
| 1296 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsSafe) { | 1509 TEST_F(DownloadTargetDeterminerTest, NotifyExtensionsSafe) { |
| 1297 const DownloadTestCase kNotifyExtensionsTestCases[] = { | 1510 const DownloadTestCase kNotifyExtensionsTestCases[] = { |
| 1298 {// 0: Automatic Safe | 1511 {// 0: Automatic Safe |
| 1299 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1512 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1300 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1513 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1301 "text/plain", FILE_PATH_LITERAL(""), | 1514 "text/plain", FILE_PATH_LITERAL(""), |
| 1302 | 1515 |
| 1303 FILE_PATH_LITERAL("overridden/foo.txt"), | 1516 FILE_PATH_LITERAL("overridden/foo.txt"), |
| 1304 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1517 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1305 | 1518 |
| 1306 EXPECT_CRDOWNLOAD}, | 1519 EXPECT_CRDOWNLOAD}, |
| 1307 | 1520 |
| 1308 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 1309 {// 1: Save_As Safe | 1521 {// 1: Save_As Safe |
| 1310 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1522 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1311 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1523 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1312 "text/plain", FILE_PATH_LITERAL(""), | 1524 "text/plain", FILE_PATH_LITERAL(""), |
| 1313 | 1525 |
| 1314 FILE_PATH_LITERAL("overridden/foo.txt"), | 1526 FILE_PATH_LITERAL("overridden/foo.txt"), |
| 1315 DownloadItem::TARGET_DISPOSITION_PROMPT, | 1527 DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 1316 | 1528 |
| 1317 EXPECT_CRDOWNLOAD}, | 1529 EXPECT_CRDOWNLOAD}, |
| 1318 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 1319 | 1530 |
| 1320 {// 2: Automatic Dangerous | 1531 {// 2: Automatic Dangerous |
| 1321 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1532 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1322 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", | 1533 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1323 "", FILE_PATH_LITERAL(""), | 1534 "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""), |
| 1324 | 1535 |
| 1325 FILE_PATH_LITERAL("overridden/foo.crx"), | 1536 FILE_PATH_LITERAL("overridden/foo.kindabad"), |
| 1326 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1537 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1327 | 1538 |
| 1328 EXPECT_UNCONFIRMED}, | 1539 EXPECT_UNCONFIRMED}, |
| 1329 | 1540 |
| 1330 {// 3: Forced Safe | 1541 {// 3: Forced Safe |
| 1331 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1542 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1332 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "", | 1543 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "", |
| 1333 FILE_PATH_LITERAL("forced-foo.txt"), | 1544 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1334 | 1545 |
| 1335 FILE_PATH_LITERAL("forced-foo.txt"), | 1546 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1336 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1547 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1337 | 1548 |
| 1338 EXPECT_LOCAL_PATH}, | 1549 EXPECT_LOCAL_PATH}, |
| 1339 }; | 1550 }; |
| 1340 | 1551 |
| 1341 ON_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1552 ON_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1342 .WillByDefault(Invoke(&NotifyExtensionsOverridePath)); | 1553 .WillByDefault(Invoke(&NotifyExtensionsOverridePath)); |
| 1343 RunTestCasesWithActiveItem(kNotifyExtensionsTestCases, | 1554 RunTestCasesWithActiveItem(kNotifyExtensionsTestCases, |
| 1344 arraysize(kNotifyExtensionsTestCases)); | 1555 arraysize(kNotifyExtensionsTestCases)); |
| 1345 } | 1556 } |
| 1346 | 1557 |
| 1347 // Test that filenames provided by extensions are passed into SafeBrowsing | 1558 // Test that filenames provided by extensions are passed into SafeBrowsing |
| 1348 // checks and dangerous download checks. | 1559 // checks and dangerous download checks. |
| 1349 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_NotifyExtensionsUnsafe) { | 1560 TEST_F(DownloadTargetDeterminerTest, NotifyExtensionsUnsafe) { |
| 1350 const DownloadTestCase kNotHandledBySafeBrowsing = { | 1561 const DownloadTestCase kNotHandledBySafeBrowsing = { |
| 1351 AUTOMATIC, | 1562 AUTOMATIC, |
| 1352 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1563 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1353 DownloadFileType::ALLOW_ON_USER_GESTURE, | 1564 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1354 "http://example.com/foo.crx.remove", | 1565 "http://example.com/foo.kindabad.remove", |
| 1355 "text/plain", | 1566 "text/plain", |
| 1356 FILE_PATH_LITERAL(""), | 1567 FILE_PATH_LITERAL(""), |
| 1357 | 1568 |
| 1358 FILE_PATH_LITERAL("overridden/foo.crx"), | 1569 FILE_PATH_LITERAL("overridden/foo.kindabad"), |
| 1359 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1570 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1360 | 1571 |
| 1361 EXPECT_UNCONFIRMED}; | 1572 EXPECT_UNCONFIRMED}; |
| 1362 | 1573 |
| 1363 const DownloadTestCase kHandledBySafeBrowsing = { | 1574 const DownloadTestCase kHandledBySafeBrowsing = { |
| 1364 AUTOMATIC, | 1575 AUTOMATIC, |
| 1365 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 1576 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 1366 DownloadFileType::ALLOW_ON_USER_GESTURE, | 1577 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1367 "http://example.com/foo.crx.remove", | 1578 "http://example.com/foo.kindabad.remove", |
| 1368 "text/plain", | 1579 "text/plain", |
| 1369 FILE_PATH_LITERAL(""), | 1580 FILE_PATH_LITERAL(""), |
| 1370 | 1581 |
| 1371 FILE_PATH_LITERAL("overridden/foo.crx"), | 1582 FILE_PATH_LITERAL("overridden/foo.kindabad"), |
| 1372 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1583 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1373 | 1584 |
| 1374 EXPECT_UNCONFIRMED}; | 1585 EXPECT_UNCONFIRMED}; |
| 1375 | 1586 |
| 1376 ON_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1587 ON_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1377 .WillByDefault(Invoke(&NotifyExtensionsOverridePath)); | 1588 .WillByDefault(Invoke(&NotifyExtensionsOverridePath)); |
| 1378 RunTestCasesWithActiveItem(&kNotHandledBySafeBrowsing, 1); | 1589 RunTestCasesWithActiveItem(&kNotHandledBySafeBrowsing, 1); |
| 1379 | 1590 |
| 1380 ON_CALL(*delegate(), CheckDownloadUrl(_, _, _)) | 1591 ON_CALL(*delegate(), CheckDownloadUrl(_, _, _)) |
| 1381 .WillByDefault(WithArg<2>(ScheduleCallback( | 1592 .WillByDefault(WithArg<2>(ScheduleCallback( |
| 1382 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT))); | 1593 content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT))); |
| 1383 RunTestCasesWithActiveItem(&kHandledBySafeBrowsing, 1); | 1594 RunTestCasesWithActiveItem(&kHandledBySafeBrowsing, 1); |
| 1384 } | 1595 } |
| 1385 | 1596 |
| 1386 // Test that conflict actions set by extensions are passed correctly into | 1597 // Test that conflict actions set by extensions are passed correctly into |
| 1387 // ReserveVirtualPath. | 1598 // ReserveVirtualPath. |
| 1388 TEST_F(DownloadTargetDeterminerTest, | 1599 TEST_F(DownloadTargetDeterminerTest, NotifyExtensionsConflict) { |
| 1389 TargetDeterminer_NotifyExtensionsConflict) { | |
| 1390 const DownloadTestCase kNotifyExtensionsTestCase = { | 1600 const DownloadTestCase kNotifyExtensionsTestCase = { |
| 1391 AUTOMATIC, | 1601 AUTOMATIC, |
| 1392 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1602 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1393 DownloadFileType::NOT_DANGEROUS, | 1603 DownloadFileType::NOT_DANGEROUS, |
| 1394 "http://example.com/foo.txt", | 1604 "http://example.com/foo.txt", |
| 1395 "text/plain", | 1605 "text/plain", |
| 1396 FILE_PATH_LITERAL(""), | 1606 FILE_PATH_LITERAL(""), |
| 1397 | 1607 |
| 1398 FILE_PATH_LITERAL("overridden/foo.txt"), | 1608 FILE_PATH_LITERAL("overridden/foo.txt"), |
| 1399 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1609 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1400 | 1610 |
| 1401 EXPECT_CRDOWNLOAD}; | 1611 EXPECT_CRDOWNLOAD}; |
| 1402 | 1612 |
| 1403 const DownloadTestCase& test_case = kNotifyExtensionsTestCase; | 1613 const DownloadTestCase& test_case = kNotifyExtensionsTestCase; |
| 1404 std::unique_ptr<content::MockDownloadItem> item( | 1614 std::unique_ptr<content::MockDownloadItem> item = |
| 1405 CreateActiveDownloadItem(0, test_case)); | 1615 CreateActiveDownloadItem(0, test_case); |
| 1406 base::FilePath overridden_path(FILE_PATH_LITERAL("overridden/foo.txt")); | 1616 base::FilePath overridden_path(FILE_PATH_LITERAL("overridden/foo.txt")); |
| 1407 base::FilePath full_overridden_path = | 1617 base::FilePath full_overridden_path = |
| 1408 GetPathInDownloadDir(overridden_path.value()); | 1618 GetPathInDownloadDir(overridden_path.value()); |
| 1409 | 1619 |
| 1410 // First case: An extension sets the conflict_action to OVERWRITE. | 1620 // First case: An extension sets the conflict_action to OVERWRITE. |
| 1411 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1621 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1412 .WillOnce(WithArg<2>( | 1622 .WillOnce(WithArg<2>( |
| 1413 ScheduleCallback2(overridden_path, | 1623 ScheduleCallback2(overridden_path, |
| 1414 DownloadPathReservationTracker::OVERWRITE))); | 1624 DownloadPathReservationTracker::OVERWRITE))); |
| 1415 EXPECT_CALL(*delegate(), ReserveVirtualPath( | 1625 EXPECT_CALL(*delegate(), |
| 1416 _, full_overridden_path, true, DownloadPathReservationTracker::OVERWRITE, | 1626 ReserveVirtualPath(_, full_overridden_path, true, |
| 1417 _)).WillOnce(WithArg<4>( | 1627 DownloadPathReservationTracker::OVERWRITE, _)) |
| 1418 ScheduleCallback2(full_overridden_path, true))); | 1628 .WillOnce(WithArg<4>(ScheduleCallback2(full_overridden_path, |
| 1629 DownloadTargetResult::SUCCESS))); | |
| 1419 | 1630 |
| 1420 RunTestCase(test_case, base::FilePath(), item.get()); | 1631 RunTestCase(test_case, base::FilePath(), item.get()); |
| 1421 | 1632 |
| 1422 // Second case: An extension sets the conflict_action to PROMPT. | 1633 // Second case: An extension sets the conflict_action to PROMPT. |
| 1423 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1634 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1424 .WillOnce(WithArg<2>( | 1635 .WillOnce(WithArg<2>( |
| 1425 ScheduleCallback2(overridden_path, | 1636 ScheduleCallback2(overridden_path, |
| 1426 DownloadPathReservationTracker::PROMPT))); | 1637 DownloadPathReservationTracker::PROMPT))); |
| 1427 EXPECT_CALL(*delegate(), ReserveVirtualPath( | 1638 EXPECT_CALL(*delegate(), |
| 1428 _, full_overridden_path, true, DownloadPathReservationTracker::PROMPT, _)) | 1639 ReserveVirtualPath(_, full_overridden_path, true, |
| 1429 .WillOnce(WithArg<4>( | 1640 DownloadPathReservationTracker::PROMPT, _)) |
| 1430 ScheduleCallback2(full_overridden_path, true))); | 1641 .WillOnce(WithArg<4>(ScheduleCallback2(full_overridden_path, |
| 1642 DownloadTargetResult::SUCCESS))); | |
| 1431 RunTestCase(test_case, base::FilePath(), item.get()); | 1643 RunTestCase(test_case, base::FilePath(), item.get()); |
| 1432 } | 1644 } |
| 1433 | 1645 |
| 1434 #if !BUILDFLAG(ANDROID_JAVA_UI) | |
| 1435 // Test that relative paths returned by extensions are always relative to the | 1646 // Test that relative paths returned by extensions are always relative to the |
| 1436 // default downloads path. | 1647 // default downloads path. |
| 1437 TEST_F(DownloadTargetDeterminerTest, | 1648 TEST_F(DownloadTargetDeterminerTest, NotifyExtensionsDefaultPath) { |
| 1438 TargetDeterminer_NotifyExtensionsDefaultPath) { | |
| 1439 const DownloadTestCase kNotifyExtensionsTestCase = { | 1649 const DownloadTestCase kNotifyExtensionsTestCase = { |
| 1440 SAVE_AS, | 1650 AUTOMATIC, |
| 1441 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1651 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1442 DownloadFileType::NOT_DANGEROUS, | 1652 DownloadFileType::NOT_DANGEROUS, |
| 1443 "http://example.com/foo.txt", | 1653 "http://example.com/foo.txt", |
| 1444 "text/plain", | 1654 "text/plain", |
| 1445 FILE_PATH_LITERAL(""), | 1655 FILE_PATH_LITERAL(""), |
| 1446 | 1656 |
| 1447 FILE_PATH_LITERAL("overridden/foo.txt"), | 1657 FILE_PATH_LITERAL("overridden/foo.txt"), |
| 1448 DownloadItem::TARGET_DISPOSITION_PROMPT, | 1658 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1449 | 1659 |
| 1450 EXPECT_CRDOWNLOAD}; | 1660 EXPECT_CRDOWNLOAD}; |
| 1451 | 1661 |
| 1452 const DownloadTestCase& test_case = kNotifyExtensionsTestCase; | 1662 const DownloadTestCase& test_case = kNotifyExtensionsTestCase; |
| 1453 std::unique_ptr<content::MockDownloadItem> item( | 1663 std::unique_ptr<content::MockDownloadItem> item = |
| 1454 CreateActiveDownloadItem(0, test_case)); | 1664 CreateActiveDownloadItem(0, test_case); |
| 1455 base::FilePath overridden_path(FILE_PATH_LITERAL("overridden/foo.txt")); | 1665 base::FilePath overridden_path(FILE_PATH_LITERAL("overridden/foo.txt")); |
| 1456 base::FilePath full_overridden_path = | 1666 base::FilePath full_overridden_path = |
| 1457 GetPathInDownloadDir(overridden_path.value()); | 1667 GetPathInDownloadDir(overridden_path.value()); |
| 1458 | 1668 |
| 1459 download_prefs()->SetSaveFilePath(GetPathInDownloadDir( | 1669 download_prefs()->SetSaveFilePath(GetPathInDownloadDir( |
| 1460 FILE_PATH_LITERAL("last_selected"))); | 1670 FILE_PATH_LITERAL("last_selected"))); |
| 1461 | 1671 |
| 1462 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1672 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1463 .WillOnce(WithArg<2>( | 1673 .WillOnce(WithArg<2>( |
| 1464 ScheduleCallback2(overridden_path, | 1674 ScheduleCallback2(overridden_path, |
| 1465 DownloadPathReservationTracker::UNIQUIFY))); | 1675 DownloadPathReservationTracker::UNIQUIFY))); |
| 1466 EXPECT_CALL(*delegate(), | |
| 1467 PromptUserForDownloadPath(_, full_overridden_path, _)) | |
| 1468 .WillOnce(WithArg<2>( | |
| 1469 ScheduleCallback(full_overridden_path))); | |
| 1470 RunTestCase(test_case, base::FilePath(), item.get()); | 1676 RunTestCase(test_case, base::FilePath(), item.get()); |
| 1471 } | 1677 } |
| 1472 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | |
| 1473 | 1678 |
| 1474 TEST_F(DownloadTargetDeterminerTest, | 1679 TEST_F(DownloadTargetDeterminerTest, InitialVirtualPathUnsafe) { |
| 1475 TargetDeterminer_InitialVirtualPathUnsafe) { | |
| 1476 const base::FilePath::CharType* kInitialPath = | 1680 const base::FilePath::CharType* kInitialPath = |
| 1477 FILE_PATH_LITERAL("some_path/bar.html"); | 1681 FILE_PATH_LITERAL("some_path/bar.html"); |
| 1478 | 1682 |
| 1479 const DownloadTestCase kInitialPathTestCase = { | 1683 const DownloadTestCase kInitialPathTestCase = { |
| 1480 // 0: Save As Save. The path generated based on the DownloadItem is safe, | 1684 // 0: Save As Save. The path generated based on the DownloadItem is safe, |
| 1481 // but the initial path is unsafe. However, the download is not considered | 1685 // but the initial path is unsafe. However, the download is not considered |
| 1482 // dangerous since the user has been prompted. | 1686 // dangerous since the user has been prompted. |
| 1483 SAVE_AS, | 1687 SAVE_AS, |
| 1484 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1688 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1485 DownloadFileType::NOT_DANGEROUS, | 1689 DownloadFileType::NOT_DANGEROUS, |
| 1486 "http://example.com/foo.txt", | 1690 "http://example.com/foo.txt", |
| 1487 "text/plain", | 1691 "text/plain", |
| 1488 FILE_PATH_LITERAL(""), | 1692 FILE_PATH_LITERAL(""), |
| 1489 | 1693 |
| 1490 kInitialPath, | 1694 kInitialPath, |
| 1491 DownloadItem::TARGET_DISPOSITION_PROMPT, | 1695 DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 1492 | 1696 |
| 1493 EXPECT_CRDOWNLOAD}; | 1697 EXPECT_CRDOWNLOAD}; |
| 1494 | 1698 |
| 1495 const DownloadTestCase& test_case = kInitialPathTestCase; | 1699 const DownloadTestCase& test_case = kInitialPathTestCase; |
| 1496 std::unique_ptr<content::MockDownloadItem> item( | 1700 std::unique_ptr<content::MockDownloadItem> item = |
| 1497 CreateActiveDownloadItem(1, test_case)); | 1701 CreateActiveDownloadItem(1, test_case); |
| 1498 EXPECT_CALL(*item, GetLastReason()) | 1702 EXPECT_CALL(*item, GetLastReason()) |
| 1499 .WillRepeatedly(Return( | 1703 .WillRepeatedly(Return( |
| 1500 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED)); | 1704 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED)); |
| 1501 EXPECT_CALL(*item, GetTargetDisposition()) | 1705 EXPECT_CALL(*item, GetTargetDisposition()) |
| 1502 .WillRepeatedly(Return(DownloadItem::TARGET_DISPOSITION_PROMPT)); | 1706 .WillRepeatedly(Return(DownloadItem::TARGET_DISPOSITION_PROMPT)); |
| 1503 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); | 1707 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); |
| 1504 } | 1708 } |
| 1505 | 1709 |
| 1506 // Prompting behavior for resumed downloads is based on the last interrupt | 1710 // Prompting behavior for resumed downloads is based on the last interrupt |
| 1507 // reason. If the reason indicates that the target path may not be suitable for | 1711 // reason. If the reason indicates that the target path may not be suitable for |
| 1508 // the download (ACCESS_DENIED, NO_SPACE, etc..), then the user should be | 1712 // the download (ACCESS_DENIED, NO_SPACE, etc..), then the user should be |
| 1509 // prompted, and not otherwise. These test cases shouldn't result in prompting | 1713 // prompted, and not otherwise. These test cases shouldn't result in prompting |
| 1510 // since the error is set to NETWORK_FAILED. | 1714 // since the error is set to NETWORK_FAILED. |
| 1511 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedNoPrompt) { | 1715 TEST_F(DownloadTargetDeterminerTest, ResumedNoPrompt) { |
| 1512 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital | 1716 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital |
| 1513 // path. | 1717 // path. |
| 1514 const base::FilePath::CharType* kInitialPath = | 1718 const base::FilePath::CharType* kInitialPath = |
| 1515 FILE_PATH_LITERAL("some_path/bar.txt"); | 1719 FILE_PATH_LITERAL("some_path/bar.txt"); |
| 1516 | 1720 |
| 1517 const DownloadTestCase kResumedTestCases[] = { | 1721 const DownloadTestCase kResumedTestCases[] = { |
| 1518 {// 0: Automatic Safe: Initial path is ignored since the user has not been | 1722 {// 0: Automatic Safe: Initial path is ignored since the user has not been |
| 1519 // prompted before. | 1723 // prompted before. |
| 1520 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1724 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1521 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "text/plai n", | 1725 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1522 FILE_PATH_LITERAL(""), | 1726 "text/plain", FILE_PATH_LITERAL(""), |
| 1523 | 1727 |
| 1524 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1728 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1525 | 1729 |
| 1526 EXPECT_CRDOWNLOAD}, | 1730 EXPECT_CRDOWNLOAD}, |
| 1527 | 1731 |
| 1528 {// 1: Save_As Safe: Initial path used. | 1732 {// 1: Save_As Safe: Initial path used. |
| 1529 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1733 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1530 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "text/plai n", | 1734 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1531 FILE_PATH_LITERAL(""), | 1735 "text/plain", FILE_PATH_LITERAL(""), |
| 1532 | 1736 |
| 1533 kInitialPath, DownloadItem::TARGET_DISPOSITION_PROMPT, | 1737 kInitialPath, DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 1534 | 1738 |
| 1535 EXPECT_CRDOWNLOAD}, | 1739 EXPECT_CRDOWNLOAD}, |
| 1536 | 1740 |
| 1537 {// 2: Automatic Dangerous: Initial path is ignored since the user hasn't | 1741 {// 2: Automatic Dangerous: Initial path is ignored since the user hasn't |
| 1538 // been prompted before. | 1742 // been prompted before. |
| 1539 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1743 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1540 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", "" , | 1744 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1541 FILE_PATH_LITERAL(""), | 1745 "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""), |
| 1542 | 1746 |
| 1543 FILE_PATH_LITERAL("foo.crx"), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1747 FILE_PATH_LITERAL("foo.kindabad"), |
| 1748 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1544 | 1749 |
| 1545 EXPECT_UNCONFIRMED}, | 1750 EXPECT_UNCONFIRMED}, |
| 1546 | 1751 |
| 1547 {// 3: Forced Safe: Initial path is ignored due to the forced path. | 1752 {// 3: Forced Safe: Initial path is ignored due to the forced path. |
| 1548 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1753 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1549 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "", | 1754 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "", |
| 1550 FILE_PATH_LITERAL("forced-foo.txt"), | 1755 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1551 | 1756 |
| 1552 FILE_PATH_LITERAL("forced-foo.txt"), | 1757 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1553 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1758 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1554 | 1759 |
| 1555 EXPECT_LOCAL_PATH}, | 1760 EXPECT_LOCAL_PATH}, |
| 1556 }; | 1761 }; |
| 1557 | 1762 |
| 1558 // The test assumes that .crx files have a danger level of | 1763 // The test assumes that .kindabad files have a danger level of |
| 1559 // ALLOW_ON_USER_GESTURE. | 1764 // ALLOW_ON_USER_GESTURE. |
| 1560 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, | 1765 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1561 Policies()->GetFileDangerLevel( | 1766 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 1562 base::FilePath(FILE_PATH_LITERAL("foo.crx")))); | 1767 base::FilePath(FILE_PATH_LITERAL("foo.kindabad")))); |
| 1563 for (size_t i = 0; i < arraysize(kResumedTestCases); ++i) { | 1768 for (size_t i = 0; i < arraysize(kResumedTestCases); ++i) { |
| 1564 SCOPED_TRACE(testing::Message() << "Running test case " << i); | 1769 SCOPED_TRACE(testing::Message() << "Running test case " << i); |
| 1565 const DownloadTestCase& test_case = kResumedTestCases[i]; | 1770 const DownloadTestCase& test_case = kResumedTestCases[i]; |
| 1566 std::unique_ptr<content::MockDownloadItem> item( | 1771 std::unique_ptr<content::MockDownloadItem> item = |
| 1567 CreateActiveDownloadItem(i, test_case)); | 1772 CreateActiveDownloadItem(i, test_case); |
| 1568 base::FilePath expected_path = | 1773 base::FilePath expected_path = |
| 1569 GetPathInDownloadDir(test_case.expected_local_path); | 1774 GetPathInDownloadDir(test_case.expected_local_path); |
| 1570 ON_CALL(*item.get(), GetLastReason()) | 1775 ON_CALL(*item.get(), GetLastReason()) |
| 1571 .WillByDefault(Return( | 1776 .WillByDefault(Return( |
| 1572 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED)); | 1777 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED)); |
| 1573 // Extensions should be notified if a new path is being generated and there | 1778 // Extensions should be notified if a new path is being generated and there |
| 1574 // is no forced path. In the test cases above, this is true for tests with | 1779 // is no forced path. In the test cases above, this is true for tests with |
| 1575 // type == AUTOMATIC. | 1780 // type == AUTOMATIC. |
| 1576 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1781 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1577 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); | 1782 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); |
| 1578 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); | 1783 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); |
| 1579 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _)) | 1784 EXPECT_CALL(*delegate(), RequestConfirmation(_, expected_path, _, _)) |
| 1580 .Times(0); | 1785 .Times(0); |
| 1581 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); | 1786 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); |
| 1582 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); | 1787 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); |
| 1583 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); | 1788 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); |
| 1584 } | 1789 } |
| 1585 } | 1790 } |
| 1586 | 1791 |
| 1587 // Test that a forced download doesn't prompt, even if the interrupt reason | 1792 // Test that a forced download doesn't prompt, even if the interrupt reason |
| 1588 // suggests that the target path may not be suitable for downloads. | 1793 // suggests that the target path may not be suitable for downloads. |
| 1589 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedForcedDownload) { | 1794 TEST_F(DownloadTargetDeterminerTest, ResumedForcedDownload) { |
| 1590 const base::FilePath::CharType* kInitialPath = | 1795 const base::FilePath::CharType* kInitialPath = |
| 1591 FILE_PATH_LITERAL("some_path/bar.txt"); | 1796 FILE_PATH_LITERAL("some_path/bar.txt"); |
| 1592 const DownloadTestCase kResumedForcedDownload = { | 1797 const DownloadTestCase kResumedForcedDownload = { |
| 1593 // 3: Forced Safe | 1798 // 3: Forced Safe |
| 1594 FORCED, | 1799 FORCED, |
| 1595 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1800 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1596 DownloadFileType::NOT_DANGEROUS, | 1801 DownloadFileType::NOT_DANGEROUS, |
| 1597 "http://example.com/foo.txt", | 1802 "http://example.com/foo.txt", |
| 1598 "", | 1803 "", |
| 1599 FILE_PATH_LITERAL("forced-foo.txt"), | 1804 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1600 | 1805 |
| 1601 FILE_PATH_LITERAL("forced-foo.txt"), | 1806 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1602 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1807 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1603 | 1808 |
| 1604 EXPECT_LOCAL_PATH}; | 1809 EXPECT_LOCAL_PATH}; |
| 1605 | 1810 |
| 1606 const DownloadTestCase& test_case = kResumedForcedDownload; | 1811 const DownloadTestCase& test_case = kResumedForcedDownload; |
| 1607 base::FilePath expected_path = | 1812 base::FilePath expected_path = |
| 1608 GetPathInDownloadDir(test_case.expected_local_path); | 1813 GetPathInDownloadDir(test_case.expected_local_path); |
| 1609 std::unique_ptr<content::MockDownloadItem> item( | 1814 std::unique_ptr<content::MockDownloadItem> item = |
| 1610 CreateActiveDownloadItem(0, test_case)); | 1815 CreateActiveDownloadItem(0, test_case); |
| 1611 ON_CALL(*item.get(), GetLastReason()) | 1816 ON_CALL(*item.get(), GetLastReason()) |
| 1612 .WillByDefault(Return(content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE)); | 1817 .WillByDefault(Return(content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE)); |
| 1613 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1818 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1614 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); | 1819 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); |
| 1615 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); | 1820 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); |
| 1616 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, _, _)) | 1821 EXPECT_CALL(*delegate(), RequestConfirmation(_, _, _, _)).Times(0); |
| 1617 .Times(0); | |
| 1618 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); | 1822 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); |
| 1619 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); | 1823 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); |
| 1620 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); | 1824 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); |
| 1621 } | 1825 } |
| 1622 | 1826 |
| 1623 // Prompting behavior for resumed downloads is based on the last interrupt | 1827 // Prompting behavior for resumed downloads is based on the last interrupt |
| 1624 // reason. If the reason indicates that the target path may not be suitable for | 1828 // reason. If the reason indicates that the target path may not be suitable for |
| 1625 // the download (ACCESS_DENIED, NO_SPACE, etc..), then the user should be | 1829 // the download (ACCESS_DENIED, NO_SPACE, etc..), then the user should be |
| 1626 // prompted, and not otherwise. These test cases result in prompting since the | 1830 // prompted, and not otherwise. These test cases result in prompting since the |
| 1627 // error is set to NO_SPACE. | 1831 // error is set to NO_SPACE. |
| 1628 TEST_F(DownloadTargetDeterminerTest, TargetDeterminer_ResumedWithPrompt) { | 1832 TEST_F(DownloadTargetDeterminerTest, ResumedWithPrompt) { |
| 1629 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital | 1833 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital |
| 1630 // path. | 1834 // path. |
| 1631 const base::FilePath::CharType* kInitialPath = | 1835 const base::FilePath::CharType* kInitialPath = |
| 1632 FILE_PATH_LITERAL("some_path/bar.txt"); | 1836 FILE_PATH_LITERAL("some_path/bar.txt"); |
| 1633 | 1837 |
| 1634 const DownloadTestCase kResumedTestCases[] = { | 1838 const DownloadTestCase kResumedTestCases[] = { |
| 1635 {// 0: Automatic Safe | 1839 {// 0: Automatic Safe |
| 1636 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1840 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1637 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1841 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1638 "text/plain", FILE_PATH_LITERAL(""), | 1842 "text/plain", FILE_PATH_LITERAL(""), |
| 1639 | 1843 |
| 1640 FILE_PATH_LITERAL("foo.txt"), | 1844 FILE_PATH_LITERAL("foo.txt"), DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 1641 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 1642 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1643 #else | |
| 1644 DownloadItem::TARGET_DISPOSITION_PROMPT, | |
| 1645 #endif | |
| 1646 EXPECT_CRDOWNLOAD}, | 1845 EXPECT_CRDOWNLOAD}, |
| 1647 | 1846 |
| 1648 {// 1: Save_As Safe | 1847 {// 1: Save_As Safe |
| 1649 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1848 SAVE_AS, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1650 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", | 1849 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", |
| 1651 "text/plain", FILE_PATH_LITERAL(""), | 1850 "text/plain", FILE_PATH_LITERAL(""), |
| 1652 | 1851 |
| 1653 kInitialPath, DownloadItem::TARGET_DISPOSITION_PROMPT, | 1852 kInitialPath, DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 1654 | 1853 |
| 1655 EXPECT_CRDOWNLOAD}, | 1854 EXPECT_CRDOWNLOAD}, |
| 1656 | 1855 |
| 1657 { | 1856 { |
| 1658 // 2: Automatic Dangerous | 1857 // 2: Automatic Dangerous |
| 1659 AUTOMATIC, | 1858 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1660 #if BUILDFLAG(ANDROID_JAVA_UI) | 1859 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.kindabad", |
|
svaldez
2016/10/28 17:29:36
Should this be ".bad"?
asanka
2016/11/07 19:50:15
Added another test case for .bad. The semantics ar
| |
| 1661 // If we don't prompt user, the file will be treated as dangerous. | 1860 "", FILE_PATH_LITERAL(""), |
| 1662 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | |
| 1663 DownloadFileType::ALLOW_ON_USER_GESTURE, | |
| 1664 #else | |
| 1665 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1666 DownloadFileType::NOT_DANGEROUS, | |
| 1667 #endif | |
| 1668 "http://example.com/foo.crx", "", FILE_PATH_LITERAL(""), | |
| 1669 | 1861 |
| 1670 FILE_PATH_LITERAL("foo.crx"), | 1862 FILE_PATH_LITERAL("foo.kindabad"), |
| 1671 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 1672 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1673 // Dangerous download will have an unconfirmed intermediate file name. | |
| 1674 EXPECT_UNCONFIRMED, | |
| 1675 #else | |
| 1676 DownloadItem::TARGET_DISPOSITION_PROMPT, EXPECT_CRDOWNLOAD, | 1863 DownloadItem::TARGET_DISPOSITION_PROMPT, EXPECT_CRDOWNLOAD, |
| 1677 #endif | |
| 1678 }, | 1864 }, |
| 1679 }; | 1865 }; |
| 1680 | 1866 |
| 1681 // The test assumes that .xml files have a danger level of | |
| 1682 // ALLOW_ON_USER_GESTURE. | |
| 1683 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, | 1867 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1684 Policies()->GetFileDangerLevel( | 1868 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 1685 base::FilePath(FILE_PATH_LITERAL("foo.crx")))); | 1869 base::FilePath(FILE_PATH_LITERAL("foo.kindabad")))); |
| 1686 for (size_t i = 0; i < arraysize(kResumedTestCases); ++i) { | 1870 for (size_t i = 0; i < arraysize(kResumedTestCases); ++i) { |
| 1687 SCOPED_TRACE(testing::Message() << "Running test case " << i); | 1871 SCOPED_TRACE(testing::Message() << "Running test case " << i); |
| 1688 download_prefs()->SetSaveFilePath(test_download_dir()); | 1872 download_prefs()->SetSaveFilePath(test_download_dir()); |
| 1689 const DownloadTestCase& test_case = kResumedTestCases[i]; | 1873 const DownloadTestCase& test_case = kResumedTestCases[i]; |
| 1690 base::FilePath expected_path = | 1874 base::FilePath expected_path = |
| 1691 GetPathInDownloadDir(test_case.expected_local_path); | 1875 GetPathInDownloadDir(test_case.expected_local_path); |
| 1692 std::unique_ptr<content::MockDownloadItem> item( | 1876 std::unique_ptr<content::MockDownloadItem> item = |
| 1693 CreateActiveDownloadItem(i, test_case)); | 1877 CreateActiveDownloadItem(i, test_case); |
| 1694 ON_CALL(*item.get(), GetLastReason()) | 1878 ON_CALL(*item.get(), GetLastReason()) |
| 1695 .WillByDefault(Return( | 1879 .WillByDefault(Return( |
| 1696 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE)); | 1880 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE)); |
| 1697 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) | 1881 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _)) |
| 1698 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); | 1882 .Times(test_case.test_type == AUTOMATIC ? 1 : 0); |
| 1699 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); | 1883 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _)); |
| 1700 #if BUILDFLAG(ANDROID_JAVA_UI) | 1884 EXPECT_CALL(*delegate(), RequestConfirmation(_, expected_path, _, _)); |
| 1701 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _)) | |
| 1702 .Times(0); | |
| 1703 #else | |
| 1704 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _)); | |
| 1705 #endif | |
| 1706 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); | 1885 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _)); |
| 1707 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); | 1886 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)); |
| 1708 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); | 1887 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get()); |
| 1709 } | 1888 } |
| 1710 } | 1889 } |
| 1711 | 1890 |
| 1712 // Test intermediate filename generation for resumed downloads. | 1891 // Test intermediate filename generation for resumed downloads. |
| 1713 TEST_F(DownloadTargetDeterminerTest, | 1892 TEST_F(DownloadTargetDeterminerTest, IntermediateNameForResumed) { |
| 1714 TargetDeterminer_IntermediateNameForResumed) { | |
| 1715 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital | 1893 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital |
| 1716 // path. | 1894 // path. |
| 1717 const base::FilePath::CharType kInitialPath[] = | 1895 const base::FilePath::CharType kInitialPath[] = |
| 1718 FILE_PATH_LITERAL("some_path/bar.txt"); | 1896 FILE_PATH_LITERAL("some_path/bar.txt"); |
| 1719 | 1897 |
| 1720 struct IntermediateNameTestCase { | 1898 struct IntermediateNameTestCase { |
| 1721 // General test case settings. | 1899 // General test case settings. |
| 1722 DownloadTestCase general; | 1900 DownloadTestCase general; |
| 1723 | 1901 |
| 1724 // Value of DownloadItem::GetFullPath() during test run, relative | 1902 // Value of DownloadItem::GetFullPath() during test run, relative |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1747 "text/plain", FILE_PATH_LITERAL(""), | 1925 "text/plain", FILE_PATH_LITERAL(""), |
| 1748 | 1926 |
| 1749 kInitialPath, DownloadItem::TARGET_DISPOSITION_PROMPT, | 1927 kInitialPath, DownloadItem::TARGET_DISPOSITION_PROMPT, |
| 1750 | 1928 |
| 1751 EXPECT_CRDOWNLOAD}, | 1929 EXPECT_CRDOWNLOAD}, |
| 1752 FILE_PATH_LITERAL("foo.txt.crdownload"), | 1930 FILE_PATH_LITERAL("foo.txt.crdownload"), |
| 1753 FILE_PATH_LITERAL("some_path/bar.txt.crdownload")}, | 1931 FILE_PATH_LITERAL("some_path/bar.txt.crdownload")}, |
| 1754 | 1932 |
| 1755 {{// 2: Automatic Dangerous | 1933 {{// 2: Automatic Dangerous |
| 1756 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1934 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1757 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", | 1935 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1758 "", FILE_PATH_LITERAL(""), | 1936 "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""), |
| 1759 | 1937 |
| 1760 FILE_PATH_LITERAL("foo.crx"), | 1938 FILE_PATH_LITERAL("foo.kindabad"), |
| 1761 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1939 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1762 | 1940 |
| 1763 EXPECT_UNCONFIRMED}, | 1941 EXPECT_UNCONFIRMED}, |
| 1764 FILE_PATH_LITERAL("Unconfirmed abcd.crdownload"), | 1942 FILE_PATH_LITERAL("Unconfirmed abcd.crdownload"), |
| 1765 FILE_PATH_LITERAL("Unconfirmed abcd.crdownload")}, | 1943 FILE_PATH_LITERAL("Unconfirmed abcd.crdownload")}, |
| 1766 | 1944 |
| 1767 {{// 3: Automatic Dangerous | 1945 {{// 3: Automatic Dangerous |
| 1768 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 1946 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 1769 DownloadFileType::ALLOW_ON_USER_GESTURE, "http://example.com/foo.crx", | 1947 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1770 "", FILE_PATH_LITERAL(""), | 1948 "http://example.com/foo.kindabad", "", FILE_PATH_LITERAL(""), |
| 1771 | 1949 |
| 1772 FILE_PATH_LITERAL("foo.crx"), | 1950 FILE_PATH_LITERAL("foo.kindabad"), |
| 1773 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1951 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1774 | 1952 |
| 1775 EXPECT_UNCONFIRMED}, | 1953 EXPECT_UNCONFIRMED}, |
| 1776 FILE_PATH_LITERAL("other_path/Unconfirmed abcd.crdownload"), | 1954 FILE_PATH_LITERAL("other_path/Unconfirmed abcd.crdownload"), |
| 1777 // Rely on the EXPECT_UNCONFIRMED check in the general test settings. A | 1955 // Rely on the EXPECT_UNCONFIRMED check in the general test settings. A |
| 1778 // new intermediate path of the form "Unconfirmed <number>.crdownload" | 1956 // new intermediate path of the form "Unconfirmed <number>.crdownload" |
| 1779 // should be generated for this case since the initial intermediate path | 1957 // should be generated for this case since the initial intermediate path |
| 1780 // is in the wrong directory. | 1958 // is in the wrong directory. |
| 1781 FILE_PATH_LITERAL("")}, | 1959 FILE_PATH_LITERAL("")}, |
| 1782 | 1960 |
| 1783 {{// 3: Forced Safe: Initial path is ignored due to the forced path. | 1961 {{// 3: Forced Safe: Initial path is ignored due to the forced path. |
| 1784 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1962 FORCED, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1785 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "", | 1963 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.txt", "", |
| 1786 FILE_PATH_LITERAL("forced-foo.txt"), | 1964 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1787 | 1965 |
| 1788 FILE_PATH_LITERAL("forced-foo.txt"), | 1966 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1789 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1967 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1790 | 1968 |
| 1791 EXPECT_LOCAL_PATH}, | 1969 EXPECT_LOCAL_PATH}, |
| 1792 FILE_PATH_LITERAL("forced-foo.txt"), | 1970 FILE_PATH_LITERAL("forced-foo.txt"), |
| 1793 FILE_PATH_LITERAL("forced-foo.txt")}, | 1971 FILE_PATH_LITERAL("forced-foo.txt")}, |
| 1794 }; | 1972 }; |
| 1795 | 1973 |
| 1796 // The test assumes that .crx files have a danger level of | 1974 // The test assumes that .kindabad files have a danger level of |
| 1797 // ALLOW_ON_USER_GESTURE. | 1975 // ALLOW_ON_USER_GESTURE. |
| 1798 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, | 1976 ASSERT_EQ(DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 1799 Policies()->GetFileDangerLevel( | 1977 safe_browsing::FileTypePolicies::GetInstance()->GetFileDangerLevel( |
| 1800 base::FilePath(FILE_PATH_LITERAL("foo.crx")))); | 1978 base::FilePath(FILE_PATH_LITERAL("foo.kindabad")))); |
| 1801 | 1979 |
| 1802 for (size_t i = 0; i < arraysize(kIntermediateNameTestCases); ++i) { | 1980 for (size_t i = 0; i < arraysize(kIntermediateNameTestCases); ++i) { |
| 1803 SCOPED_TRACE(testing::Message() << "Running test case " << i); | 1981 SCOPED_TRACE(testing::Message() << "Running test case " << i); |
| 1804 const IntermediateNameTestCase& test_case = kIntermediateNameTestCases[i]; | 1982 const IntermediateNameTestCase& test_case = kIntermediateNameTestCases[i]; |
| 1805 std::unique_ptr<content::MockDownloadItem> item( | 1983 std::unique_ptr<content::MockDownloadItem> item = |
| 1806 CreateActiveDownloadItem(i, test_case.general)); | 1984 CreateActiveDownloadItem(i, test_case.general); |
| 1807 | 1985 |
| 1808 ON_CALL(*item.get(), GetLastReason()) | 1986 ON_CALL(*item.get(), GetLastReason()) |
| 1809 .WillByDefault(Return( | 1987 .WillByDefault(Return( |
| 1810 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED)); | 1988 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED)); |
| 1811 ON_CALL(*item.get(), GetFullPath()) | 1989 ON_CALL(*item.get(), GetFullPath()) |
| 1812 .WillByDefault(ReturnRefOfCopy( | 1990 .WillByDefault(ReturnRefOfCopy( |
| 1813 GetPathInDownloadDir(test_case.initial_intermediate_path))); | 1991 GetPathInDownloadDir(test_case.initial_intermediate_path))); |
| 1814 ON_CALL(*item.get(), GetDangerType()) | 1992 ON_CALL(*item.get(), GetDangerType()) |
| 1815 .WillByDefault(Return(test_case.general.expected_danger_type)); | 1993 .WillByDefault(Return(test_case.general.expected_danger_type)); |
| 1816 | 1994 |
| 1817 std::unique_ptr<DownloadTargetInfo> target_info = | 1995 std::unique_ptr<DownloadTargetInfo> target_info = |
| 1818 RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath), | 1996 RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath), |
| 1819 item.get()); | 1997 item.get()); |
| 1820 VerifyDownloadTarget(test_case.general, target_info.get()); | 1998 VerifyDownloadTarget(test_case.general, target_info.get()); |
| 1821 base::FilePath expected_intermediate_path = | 1999 base::FilePath expected_intermediate_path = |
| 1822 GetPathInDownloadDir(test_case.expected_intermediate_path); | 2000 GetPathInDownloadDir(test_case.expected_intermediate_path); |
| 1823 if (!expected_intermediate_path.empty()) | 2001 if (!expected_intermediate_path.empty()) |
| 1824 EXPECT_EQ(expected_intermediate_path, target_info->intermediate_path); | 2002 EXPECT_EQ(expected_intermediate_path, target_info->intermediate_path); |
| 1825 } | 2003 } |
| 1826 } | 2004 } |
| 1827 | 2005 |
| 1828 // Test MIME type determination based on the target filename. | 2006 // Test MIME type determination based on the target filename. |
| 1829 TEST_F(DownloadTargetDeterminerTest, | 2007 TEST_F(DownloadTargetDeterminerTest, MIMETypeDetermination) { |
| 1830 TargetDeterminer_MIMETypeDetermination) { | |
| 1831 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital | 2008 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital |
| 1832 // path. | 2009 // path. |
| 1833 const base::FilePath::CharType kInitialPath[] = | 2010 const base::FilePath::CharType kInitialPath[] = |
| 1834 FILE_PATH_LITERAL("some_path/bar.txt"); | 2011 FILE_PATH_LITERAL("some_path/bar.txt"); |
| 1835 | 2012 |
| 1836 struct MIMETypeTestCase { | 2013 struct MIMETypeTestCase { |
| 1837 // General test case settings. | 2014 // General test case settings. |
| 1838 DownloadTestCase general; | 2015 DownloadTestCase general; |
| 1839 | 2016 |
| 1840 // Expected MIME type for test case. | 2017 // Expected MIME type for test case. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1893 {{// 5: x-x509-user-cert mime-type. | 2070 {{// 5: x-x509-user-cert mime-type. |
| 1894 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 2071 AUTOMATIC, content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1895 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.notarealext", | 2072 DownloadFileType::NOT_DANGEROUS, "http://example.com/foo.notarealext", |
| 1896 "application/x-x509-user-cert", FILE_PATH_LITERAL(""), | 2073 "application/x-x509-user-cert", FILE_PATH_LITERAL(""), |
| 1897 | 2074 |
| 1898 FILE_PATH_LITERAL("user.crt"), | 2075 FILE_PATH_LITERAL("user.crt"), |
| 1899 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 2076 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1900 | 2077 |
| 1901 EXPECT_CRDOWNLOAD}, | 2078 EXPECT_CRDOWNLOAD}, |
| 1902 ""}, | 2079 ""}, |
| 1903 | |
| 1904 }; | 2080 }; |
| 1905 | 2081 |
| 1906 ON_CALL(*delegate(), GetFileMimeType( | 2082 ON_CALL(*delegate(), GetFileMimeType( |
| 1907 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.png")), _)) | 2083 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.png")), _)) |
| 1908 .WillByDefault(WithArg<1>( | 2084 .WillByDefault(WithArg<1>( |
| 1909 ScheduleCallback("image/png"))); | 2085 ScheduleCallback("image/png"))); |
| 1910 | 2086 |
| 1911 for (size_t i = 0; i < arraysize(kMIMETypeTestCases); ++i) { | 2087 for (size_t i = 0; i < arraysize(kMIMETypeTestCases); ++i) { |
| 1912 SCOPED_TRACE(testing::Message() << "Running test case " << i); | 2088 SCOPED_TRACE(testing::Message() << "Running test case " << i); |
| 1913 const MIMETypeTestCase& test_case = kMIMETypeTestCases[i]; | 2089 const MIMETypeTestCase& test_case = kMIMETypeTestCases[i]; |
| 1914 std::unique_ptr<content::MockDownloadItem> item( | 2090 std::unique_ptr<content::MockDownloadItem> item = |
| 1915 CreateActiveDownloadItem(i, test_case.general)); | 2091 CreateActiveDownloadItem(i, test_case.general); |
| 1916 std::unique_ptr<DownloadTargetInfo> target_info = | 2092 std::unique_ptr<DownloadTargetInfo> target_info = |
| 1917 RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath), | 2093 RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath), |
| 1918 item.get()); | 2094 item.get()); |
| 1919 EXPECT_EQ(test_case.expected_mime_type, target_info->mime_type); | 2095 EXPECT_EQ(test_case.expected_mime_type, target_info->mime_type); |
| 1920 } | 2096 } |
| 1921 } | 2097 } |
| 1922 | 2098 |
| 1923 #if defined(ENABLE_PLUGINS) | 2099 #if defined(ENABLE_PLUGINS) |
| 1924 | 2100 |
| 1925 void DummyGetPluginsCallback( | 2101 void DummyGetPluginsCallback( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2026 | 2202 |
| 2027 protected: | 2203 protected: |
| 2028 content::PluginServiceFilter* old_plugin_service_filter_; | 2204 content::PluginServiceFilter* old_plugin_service_filter_; |
| 2029 testing::StrictMock<MockPluginServiceFilter> mock_plugin_filter_; | 2205 testing::StrictMock<MockPluginServiceFilter> mock_plugin_filter_; |
| 2030 // The ShadowingAtExitManager destroys the tainted PluginService instance. | 2206 // The ShadowingAtExitManager destroys the tainted PluginService instance. |
| 2031 base::ShadowingAtExitManager at_exit_manager_; | 2207 base::ShadowingAtExitManager at_exit_manager_; |
| 2032 }; | 2208 }; |
| 2033 | 2209 |
| 2034 // Check if secure handling of filetypes is determined correctly for PPAPI | 2210 // Check if secure handling of filetypes is determined correctly for PPAPI |
| 2035 // plugins. | 2211 // plugins. |
| 2036 TEST_F(DownloadTargetDeterminerTestWithPlugin, | 2212 TEST_F(DownloadTargetDeterminerTestWithPlugin, CheckForSecureHandling_PPAPI) { |
| 2037 TargetDeterminer_CheckForSecureHandling_PPAPI) { | |
| 2038 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital | 2213 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital |
| 2039 // path. | 2214 // path. |
| 2040 const base::FilePath::CharType kInitialPath[] = | 2215 const base::FilePath::CharType kInitialPath[] = |
| 2041 FILE_PATH_LITERAL("some_path/bar.txt"); | 2216 FILE_PATH_LITERAL("some_path/bar.txt"); |
| 2042 const char kTestMIMEType[] = "application/x-example-should-not-exist"; | 2217 const char kTestMIMEType[] = "application/x-example-should-not-exist"; |
| 2043 | 2218 |
| 2044 DownloadTestCase kSecureHandlingTestCase = { | 2219 DownloadTestCase kSecureHandlingTestCase = { |
| 2045 AUTOMATIC, | 2220 AUTOMATIC, |
| 2046 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 2221 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 2047 DownloadFileType::NOT_DANGEROUS, | 2222 DownloadFileType::NOT_DANGEROUS, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2064 ASSERT_FALSE(plugin_service->GetPluginInfoArray( | 2239 ASSERT_FALSE(plugin_service->GetPluginInfoArray( |
| 2065 GURL(), kTestMIMEType, false, &info, NULL)); | 2240 GURL(), kTestMIMEType, false, &info, NULL)); |
| 2066 ASSERT_EQ(0u, info.size()) | 2241 ASSERT_EQ(0u, info.size()) |
| 2067 << "Name: " << info[0].name << ", Path: " << info[0].path.value(); | 2242 << "Name: " << info[0].name << ", Path: " << info[0].path.value(); |
| 2068 } | 2243 } |
| 2069 | 2244 |
| 2070 ON_CALL(*delegate(), GetFileMimeType( | 2245 ON_CALL(*delegate(), GetFileMimeType( |
| 2071 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.fakeext")), _)) | 2246 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.fakeext")), _)) |
| 2072 .WillByDefault(WithArg<1>( | 2247 .WillByDefault(WithArg<1>( |
| 2073 ScheduleCallback(kTestMIMEType))); | 2248 ScheduleCallback(kTestMIMEType))); |
| 2074 std::unique_ptr<content::MockDownloadItem> item( | 2249 std::unique_ptr<content::MockDownloadItem> item = |
| 2075 CreateActiveDownloadItem(1, kSecureHandlingTestCase)); | 2250 CreateActiveDownloadItem(1, kSecureHandlingTestCase); |
| 2076 std::unique_ptr<DownloadTargetInfo> target_info = RunDownloadTargetDeterminer( | 2251 std::unique_ptr<DownloadTargetInfo> target_info = RunDownloadTargetDeterminer( |
| 2077 GetPathInDownloadDir(kInitialPath), item.get()); | 2252 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2078 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2253 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2079 | 2254 |
| 2080 // Register a PPAPI plugin. This should count as handling the filetype | 2255 // Register a PPAPI plugin. This should count as handling the filetype |
| 2081 // securely. | 2256 // securely. |
| 2082 ScopedRegisterInternalPlugin ppapi_plugin( | 2257 ScopedRegisterInternalPlugin ppapi_plugin( |
| 2083 plugin_service, | 2258 plugin_service, |
| 2084 content::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS, | 2259 content::WebPluginInfo::PLUGIN_TYPE_PEPPER_OUT_OF_PROCESS, |
| 2085 test_download_dir().AppendASCII("ppapi"), | 2260 test_download_dir().AppendASCII("ppapi"), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2096 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(ppapi_plugin.path())) | 2271 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(ppapi_plugin.path())) |
| 2097 .WillRepeatedly(Return(false)); | 2272 .WillRepeatedly(Return(false)); |
| 2098 target_info = RunDownloadTargetDeterminer( | 2273 target_info = RunDownloadTargetDeterminer( |
| 2099 GetPathInDownloadDir(kInitialPath), item.get()); | 2274 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2100 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2275 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2101 } | 2276 } |
| 2102 | 2277 |
| 2103 // Check if secure handling of filetypes is determined correctly for | 2278 // Check if secure handling of filetypes is determined correctly for |
| 2104 // BrowserPlugins. | 2279 // BrowserPlugins. |
| 2105 TEST_F(DownloadTargetDeterminerTestWithPlugin, | 2280 TEST_F(DownloadTargetDeterminerTestWithPlugin, |
| 2106 TargetDeterminer_CheckForSecureHandling_BrowserPlugin) { | 2281 CheckForSecureHandling_BrowserPlugin) { |
| 2107 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital | 2282 // All test cases run with GetPathInDownloadDir(kInitialPath) as the inital |
| 2108 // path. | 2283 // path. |
| 2109 const base::FilePath::CharType kInitialPath[] = | 2284 const base::FilePath::CharType kInitialPath[] = |
| 2110 FILE_PATH_LITERAL("some_path/bar.txt"); | 2285 FILE_PATH_LITERAL("some_path/bar.txt"); |
| 2111 const char kTestMIMEType[] = "application/x-example-should-not-exist"; | 2286 const char kTestMIMEType[] = "application/x-example-should-not-exist"; |
| 2112 | 2287 |
| 2113 DownloadTestCase kSecureHandlingTestCase = { | 2288 DownloadTestCase kSecureHandlingTestCase = { |
| 2114 AUTOMATIC, | 2289 AUTOMATIC, |
| 2115 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 2290 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 2116 DownloadFileType::NOT_DANGEROUS, | 2291 DownloadFileType::NOT_DANGEROUS, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2133 ASSERT_FALSE(plugin_service->GetPluginInfoArray( | 2308 ASSERT_FALSE(plugin_service->GetPluginInfoArray( |
| 2134 GURL(), kTestMIMEType, false, &info, NULL)); | 2309 GURL(), kTestMIMEType, false, &info, NULL)); |
| 2135 ASSERT_EQ(0u, info.size()) | 2310 ASSERT_EQ(0u, info.size()) |
| 2136 << "Name: " << info[0].name << ", Path: " << info[0].path.value(); | 2311 << "Name: " << info[0].name << ", Path: " << info[0].path.value(); |
| 2137 } | 2312 } |
| 2138 | 2313 |
| 2139 ON_CALL(*delegate(), GetFileMimeType( | 2314 ON_CALL(*delegate(), GetFileMimeType( |
| 2140 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.fakeext")), _)) | 2315 GetPathInDownloadDir(FILE_PATH_LITERAL("foo.fakeext")), _)) |
| 2141 .WillByDefault(WithArg<1>( | 2316 .WillByDefault(WithArg<1>( |
| 2142 ScheduleCallback(kTestMIMEType))); | 2317 ScheduleCallback(kTestMIMEType))); |
| 2143 std::unique_ptr<content::MockDownloadItem> item( | 2318 std::unique_ptr<content::MockDownloadItem> item = |
| 2144 CreateActiveDownloadItem(1, kSecureHandlingTestCase)); | 2319 CreateActiveDownloadItem(1, kSecureHandlingTestCase); |
| 2145 std::unique_ptr<DownloadTargetInfo> target_info = RunDownloadTargetDeterminer( | 2320 std::unique_ptr<DownloadTargetInfo> target_info = RunDownloadTargetDeterminer( |
| 2146 GetPathInDownloadDir(kInitialPath), item.get()); | 2321 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2147 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2322 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2148 | 2323 |
| 2149 // Register a BrowserPlugin. This should count as handling the filetype | 2324 // Register a BrowserPlugin. This should count as handling the filetype |
| 2150 // securely. | 2325 // securely. |
| 2151 ScopedRegisterInternalPlugin browser_plugin( | 2326 ScopedRegisterInternalPlugin browser_plugin( |
| 2152 plugin_service, | 2327 plugin_service, |
| 2153 content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN, | 2328 content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN, |
| 2154 test_download_dir().AppendASCII("browser_plugin"), | 2329 test_download_dir().AppendASCII("browser_plugin"), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2165 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) | 2340 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) |
| 2166 .WillRepeatedly(Return(false)); | 2341 .WillRepeatedly(Return(false)); |
| 2167 target_info = RunDownloadTargetDeterminer( | 2342 target_info = RunDownloadTargetDeterminer( |
| 2168 GetPathInDownloadDir(kInitialPath), item.get()); | 2343 GetPathInDownloadDir(kInitialPath), item.get()); |
| 2169 EXPECT_FALSE(target_info->is_filetype_handled_safely); | 2344 EXPECT_FALSE(target_info->is_filetype_handled_safely); |
| 2170 } | 2345 } |
| 2171 | 2346 |
| 2172 #endif // defined(ENABLE_PLUGINS) | 2347 #endif // defined(ENABLE_PLUGINS) |
| 2173 | 2348 |
| 2174 } // namespace | 2349 } // namespace |
| OLD | NEW |