| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 493 } |
| 494 item->SetState(DownloadItem::COMPLETE); | 494 item->SetState(DownloadItem::COMPLETE); |
| 495 } | 495 } |
| 496 | 496 |
| 497 // If the default download directory doesn't exist, then it should be | 497 // If the default download directory doesn't exist, then it should be |
| 498 // created. But only if we are actually going to create the download path there. | 498 // created. But only if we are actually going to create the download path there. |
| 499 TEST_F(DownloadPathReservationTrackerTest, CreateDefaultDownloadPath) { | 499 TEST_F(DownloadPathReservationTrackerTest, CreateDefaultDownloadPath) { |
| 500 base::FilePath path( | 500 base::FilePath path( |
| 501 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo/foo.txt"))); | 501 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo/foo.txt"))); |
| 502 base::FilePath dir(path.DirName()); | 502 base::FilePath dir(path.DirName()); |
| 503 ASSERT_FALSE(file_util::DirectoryExists(dir)); | 503 ASSERT_FALSE(base::DirectoryExists(dir)); |
| 504 DownloadPathReservationTracker::FilenameConflictAction conflict_action = | 504 DownloadPathReservationTracker::FilenameConflictAction conflict_action = |
| 505 DownloadPathReservationTracker::OVERWRITE; | 505 DownloadPathReservationTracker::OVERWRITE; |
| 506 bool create_directory = false; | 506 bool create_directory = false; |
| 507 | 507 |
| 508 { | 508 { |
| 509 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); | 509 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); |
| 510 base::FilePath reserved_path; | 510 base::FilePath reserved_path; |
| 511 bool verified = true; | 511 bool verified = true; |
| 512 CallGetReservedPath( | 512 CallGetReservedPath( |
| 513 item.get(), | 513 item.get(), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 528 set_default_download_path(dir); | 528 set_default_download_path(dir); |
| 529 CallGetReservedPath( | 529 CallGetReservedPath( |
| 530 item.get(), | 530 item.get(), |
| 531 path, | 531 path, |
| 532 create_directory, | 532 create_directory, |
| 533 conflict_action, | 533 conflict_action, |
| 534 &reserved_path, | 534 &reserved_path, |
| 535 &verified); | 535 &verified); |
| 536 // Verification succeeds because the directory is created. | 536 // Verification succeeds because the directory is created. |
| 537 EXPECT_TRUE(verified); | 537 EXPECT_TRUE(verified); |
| 538 EXPECT_TRUE(file_util::DirectoryExists(dir)); | 538 EXPECT_TRUE(base::DirectoryExists(dir)); |
| 539 item->SetState(DownloadItem::COMPLETE); | 539 item->SetState(DownloadItem::COMPLETE); |
| 540 } | 540 } |
| 541 } | 541 } |
| 542 | 542 |
| 543 // If the target path of the download item changes, the reservation should be | 543 // If the target path of the download item changes, the reservation should be |
| 544 // updated to match. | 544 // updated to match. |
| 545 TEST_F(DownloadPathReservationTrackerTest, UpdatesToTargetPath) { | 545 TEST_F(DownloadPathReservationTrackerTest, UpdatesToTargetPath) { |
| 546 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); | 546 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); |
| 547 base::FilePath path( | 547 base::FilePath path( |
| 548 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt"))); | 548 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt"))); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 create_directory, | 691 create_directory, |
| 692 conflict_action, | 692 conflict_action, |
| 693 &reserved_path, | 693 &reserved_path, |
| 694 &verified); | 694 &verified); |
| 695 // We cannot truncate a path with very long extension. | 695 // We cannot truncate a path with very long extension. |
| 696 EXPECT_FALSE(verified); | 696 EXPECT_FALSE(verified); |
| 697 item->SetState(DownloadItem::COMPLETE); | 697 item->SetState(DownloadItem::COMPLETE); |
| 698 } | 698 } |
| 699 | 699 |
| 700 #endif | 700 #endif |
| OLD | NEW |