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 "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 EXPECT_TRUE(IsPathInUse(path)); | 376 EXPECT_TRUE(IsPathInUse(path)); |
| 377 EXPECT_FALSE(IsPathInUse(uniquified_path)); | 377 EXPECT_FALSE(IsPathInUse(uniquified_path)); |
| 378 | 378 |
| 379 EXPECT_EQ(path.value(), reserved_path1.value()); | 379 EXPECT_EQ(path.value(), reserved_path1.value()); |
| 380 EXPECT_EQ(path.value(), reserved_path3.value()); | 380 EXPECT_EQ(path.value(), reserved_path3.value()); |
| 381 | 381 |
| 382 SetDownloadItemState(item1.get(), DownloadItem::COMPLETE); | 382 SetDownloadItemState(item1.get(), DownloadItem::COMPLETE); |
| 383 SetDownloadItemState(item3.get(), DownloadItem::COMPLETE); | 383 SetDownloadItemState(item3.get(), DownloadItem::COMPLETE); |
| 384 } | 384 } |
| 385 | 385 |
| 386 // Two active downloads shouldn't be able to reserve paths that only differ by | |
| 387 // case. | |
| 388 TEST_F(DownloadPathReservationTrackerTest, ConflictingCaseReservations) { | |
| 389 std::unique_ptr<MockDownloadItem> item1(CreateDownloadItem(1)); | |
| 390 std::unique_ptr<MockDownloadItem> item2(CreateDownloadItem(2)); | |
| 391 | |
| 392 base::FilePath path_foo = | |
| 393 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt")); | |
| 394 base::FilePath path_Foo = | |
| 395 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("Foo.txt")); | |
| 396 | |
| 397 base::FilePath first_reservation; | |
| 398 bool verified = false; | |
| 399 CallGetReservedPath(item1.get(), path_foo, false, | |
| 400 DownloadPathReservationTracker::UNIQUIFY, | |
| 401 &first_reservation, &verified); | |
| 402 EXPECT_TRUE(IsPathInUse(path_foo)); | |
| 403 EXPECT_TRUE(verified); | |
| 404 EXPECT_EQ(path_foo, first_reservation); | |
| 405 | |
| 406 // Foo should also be in use at this point. | |
| 407 EXPECT_TRUE(IsPathInUse(path_Foo)); | |
| 408 | |
| 409 base::FilePath second_reservation; | |
| 410 CallGetReservedPath(item2.get(), path_Foo, false, | |
| 411 DownloadPathReservationTracker::UNIQUIFY, | |
| 412 &second_reservation, &verified); | |
| 413 EXPECT_TRUE(verified); | |
| 414 EXPECT_EQ(GetPathInDownloadsDirectory(FILE_PATH_LITERAL("Foo (1).txt")), | |
|
svaldez
2016/07/11 15:40:52
Should the original path also be checked?
asanka
2016/07/11 16:27:50
That case is covered in ConflictingReservations te
| |
| 415 second_reservation); | |
| 416 SetDownloadItemState(item1.get(), DownloadItem::COMPLETE); | |
| 417 SetDownloadItemState(item2.get(), DownloadItem::COMPLETE); | |
| 418 } | |
| 419 | |
| 386 // If a unique path cannot be determined after trying kMaxUniqueFiles | 420 // If a unique path cannot be determined after trying kMaxUniqueFiles |
| 387 // uniquifiers, then the callback should notified that verification failed, and | 421 // uniquifiers, then the callback should notified that verification failed, and |
| 388 // the returned path should be set to the original requested path. | 422 // the returned path should be set to the original requested path. |
| 389 TEST_F(DownloadPathReservationTrackerTest, UnresolvedConflicts) { | 423 TEST_F(DownloadPathReservationTrackerTest, UnresolvedConflicts) { |
| 390 base::FilePath path( | 424 base::FilePath path( |
| 391 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt"))); | 425 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt"))); |
| 392 std::unique_ptr<MockDownloadItem> | 426 std::unique_ptr<MockDownloadItem> |
| 393 items[DownloadPathReservationTracker::kMaxUniqueFiles + 1]; | 427 items[DownloadPathReservationTracker::kMaxUniqueFiles + 1]; |
| 394 DownloadPathReservationTracker::FilenameConflictAction conflict_action = | 428 DownloadPathReservationTracker::FilenameConflictAction conflict_action = |
| 395 DownloadPathReservationTracker::UNIQUIFY; | 429 DownloadPathReservationTracker::UNIQUIFY; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 668 path, | 702 path, |
| 669 create_directory, | 703 create_directory, |
| 670 conflict_action, | 704 conflict_action, |
| 671 &reserved_path, | 705 &reserved_path, |
| 672 &verified); | 706 &verified); |
| 673 // We cannot truncate a path with very long extension. | 707 // We cannot truncate a path with very long extension. |
| 674 EXPECT_FALSE(verified); | 708 EXPECT_FALSE(verified); |
| 675 SetDownloadItemState(item.get(), DownloadItem::COMPLETE); | 709 SetDownloadItemState(item.get(), DownloadItem::COMPLETE); |
| 676 } | 710 } |
| 677 | 711 |
| 678 #endif | 712 #endif // Platforms that support filename truncation. |
| OLD | NEW |