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_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 void SetState(DownloadState state) { | 54 void SetState(DownloadState state) { |
55 state_ = state; | 55 state_ = state; |
56 UpdateObservers(); | 56 UpdateObservers(); |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 DownloadState state_; | 60 DownloadState state_; |
61 ObserverList<Observer> observers_; | 61 ObserverList<Observer> observers_; |
62 }; | 62 }; |
63 | 63 |
64 } // namespace | |
65 | |
66 class DownloadPathReservationTrackerTest : public testing::Test { | 64 class DownloadPathReservationTrackerTest : public testing::Test { |
67 public: | 65 public: |
68 DownloadPathReservationTrackerTest(); | 66 DownloadPathReservationTrackerTest(); |
69 | 67 |
70 // testing::Test | 68 // testing::Test |
71 virtual void SetUp() OVERRIDE; | 69 virtual void SetUp() OVERRIDE; |
72 virtual void TearDown() OVERRIDE; | 70 virtual void TearDown() OVERRIDE; |
73 | 71 |
74 FakeDownloadItem* CreateDownloadItem(int32 id); | 72 FakeDownloadItem* CreateDownloadItem(int32 id); |
75 FilePath GetPathInDownloadsDirectory(const FilePath::CharType* suffix); | 73 FilePath GetPathInDownloadsDirectory(const FilePath::CharType* suffix); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 .WillRepeatedly(ReturnRefOfCopy(FilePath())); | 120 .WillRepeatedly(ReturnRefOfCopy(FilePath())); |
123 return item; | 121 return item; |
124 } | 122 } |
125 | 123 |
126 FilePath DownloadPathReservationTrackerTest::GetPathInDownloadsDirectory( | 124 FilePath DownloadPathReservationTrackerTest::GetPathInDownloadsDirectory( |
127 const FilePath::CharType* suffix) { | 125 const FilePath::CharType* suffix) { |
128 return default_download_path().Append(suffix).NormalizePathSeparators(); | 126 return default_download_path().Append(suffix).NormalizePathSeparators(); |
129 } | 127 } |
130 | 128 |
131 bool DownloadPathReservationTrackerTest::IsPathInUse(const FilePath& path) { | 129 bool DownloadPathReservationTrackerTest::IsPathInUse(const FilePath& path) { |
132 return DownloadPathReservationTracker::GetInstance()->IsPathInUse(path); | 130 return DownloadPathReservationTracker::IsPathInUseForTesting(path); |
133 } | 131 } |
134 | 132 |
135 void DownloadPathReservationTrackerTest::CallGetReservedPath( | 133 void DownloadPathReservationTrackerTest::CallGetReservedPath( |
136 DownloadItem& download_item, | 134 DownloadItem& download_item, |
137 const FilePath& target_path, | 135 const FilePath& target_path, |
138 bool uniquify_path, | 136 bool uniquify_path, |
139 FilePath* return_path, | 137 FilePath* return_path, |
140 bool* return_verified) { | 138 bool* return_verified) { |
141 // Weak pointer factory to prevent the callback from running after this | 139 // Weak pointer factory to prevent the callback from running after this |
142 // function has returned. | 140 // function has returned. |
(...skipping 10 matching lines...) Expand all Loading... |
153 } | 151 } |
154 | 152 |
155 void DownloadPathReservationTrackerTest::TestReservedPathCallback( | 153 void DownloadPathReservationTrackerTest::TestReservedPathCallback( |
156 FilePath* return_path, bool* return_verified, bool* did_run_callback, | 154 FilePath* return_path, bool* return_verified, bool* did_run_callback, |
157 const FilePath& path, bool verified) { | 155 const FilePath& path, bool verified) { |
158 *did_run_callback = true; | 156 *did_run_callback = true; |
159 *return_path = path; | 157 *return_path = path; |
160 *return_verified = verified; | 158 *return_verified = verified; |
161 } | 159 } |
162 | 160 |
| 161 } // namespace |
| 162 |
163 // A basic reservation is acquired and committed. | 163 // A basic reservation is acquired and committed. |
164 TEST_F(DownloadPathReservationTrackerTest, BasicReservation) { | 164 TEST_F(DownloadPathReservationTrackerTest, BasicReservation) { |
165 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); | 165 scoped_ptr<FakeDownloadItem> item(CreateDownloadItem(1)); |
166 FilePath path(GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt"))); | 166 FilePath path(GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo.txt"))); |
167 ASSERT_FALSE(IsPathInUse(path)); | 167 ASSERT_FALSE(IsPathInUse(path)); |
168 | 168 |
169 FilePath reserved_path; | 169 FilePath reserved_path; |
170 bool verified = false; | 170 bool verified = false; |
171 CallGetReservedPath(*item, path, false, &reserved_path, &verified); | 171 CallGetReservedPath(*item, path, false, &reserved_path, &verified); |
172 EXPECT_TRUE(IsPathInUse(path)); | 172 EXPECT_TRUE(IsPathInUse(path)); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 item->UpdateObservers(); | 417 item->UpdateObservers(); |
418 message_loop_.RunAllPending(); | 418 message_loop_.RunAllPending(); |
419 EXPECT_FALSE(IsPathInUse(path)); | 419 EXPECT_FALSE(IsPathInUse(path)); |
420 EXPECT_TRUE(IsPathInUse(new_target_path)); | 420 EXPECT_TRUE(IsPathInUse(new_target_path)); |
421 | 421 |
422 // Destroying the item should release the reservation. | 422 // Destroying the item should release the reservation. |
423 item.reset(); | 423 item.reset(); |
424 message_loop_.RunAllPending(); | 424 message_loop_.RunAllPending(); |
425 EXPECT_FALSE(IsPathInUse(new_target_path)); | 425 EXPECT_FALSE(IsPathInUse(new_target_path)); |
426 } | 426 } |
OLD | NEW |