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

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

Issue 10824132: Avoid LazyInstance in DownloadPathReservationTracker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_path_reservation_tracker.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/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
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
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
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 ASSERT_EQ(0, file_util::WriteFile(download_util::GetCrDownloadPath(path1), 231 ASSERT_EQ(0, file_util::WriteFile(download_util::GetCrDownloadPath(path1),
232 "", 0)); 232 "", 0));
233 ASSERT_TRUE(IsPathInUse(path)); 233 ASSERT_TRUE(IsPathInUse(path));
234 234
235 FilePath reserved_path; 235 FilePath reserved_path;
236 bool verified = false; 236 bool verified = false;
237 CallGetReservedPath(*item, path, true, &reserved_path, &verified); 237 CallGetReservedPath(*item, path, true, &reserved_path, &verified);
238 EXPECT_TRUE(IsPathInUse(path)); 238 EXPECT_TRUE(IsPathInUse(path));
239 EXPECT_TRUE(IsPathInUse(reserved_path)); 239 EXPECT_TRUE(IsPathInUse(reserved_path));
240 EXPECT_TRUE(verified); 240 EXPECT_TRUE(verified);
241 // The path should be uniquified, skipping over foo.txt and 241 // The path should be uniquified, skipping over foo.txt but not over
242 // "foo (1).txt.crdownload" 242 // "foo (1).txt.crdownload"
243 EXPECT_EQ( 243 EXPECT_EQ(
244 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo (2).txt")).value(), 244 GetPathInDownloadsDirectory(FILE_PATH_LITERAL("foo (1).txt")).value(),
245 reserved_path.value()); 245 reserved_path.value());
246 246
247 item.reset(); 247 item.reset();
248 message_loop_.RunAllPending(); 248 message_loop_.RunAllPending();
249 EXPECT_TRUE(IsPathInUse(path)); 249 EXPECT_TRUE(IsPathInUse(path));
250 EXPECT_FALSE(IsPathInUse(reserved_path)); 250 EXPECT_FALSE(IsPathInUse(reserved_path));
251 } 251 }
252 252
253 // Multiple reservations for the same path should uniquify around each other. 253 // Multiple reservations for the same path should uniquify around each other.
254 TEST_F(DownloadPathReservationTrackerTest, ConflictingReservations) { 254 TEST_F(DownloadPathReservationTrackerTest, ConflictingReservations) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_path_reservation_tracker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698