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

Side by Side Diff: content/browser/fileapi/file_system_operation_impl_unittest.cc

Issue 557273002: Use RunLoop::Run() instead of RunLoop::RunUntilIdle() in FileSystemOperationImplTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "webkit/browser/fileapi/file_system_operation_impl.h" 5 #include "webkit/browser/fileapi/file_system_operation_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 22 matching lines...) Expand all
33 using storage::FileSystemOperation; 33 using storage::FileSystemOperation;
34 using storage::FileSystemOperationContext; 34 using storage::FileSystemOperationContext;
35 using storage::FileSystemOperationRunner; 35 using storage::FileSystemOperationRunner;
36 using storage::FileSystemURL; 36 using storage::FileSystemURL;
37 using storage::QuotaManager; 37 using storage::QuotaManager;
38 using storage::QuotaManagerProxy; 38 using storage::QuotaManagerProxy;
39 using storage::ShareableFileReference; 39 using storage::ShareableFileReference;
40 40
41 namespace content { 41 namespace content {
42 42
43 namespace {
44
45 const int kFileOperationStatusNotSet = 1;
46
47 void AssertFileErrorEq(const tracked_objects::Location& from_here,
48 base::File::Error expected,
49 base::File::Error actual) {
50 ASSERT_EQ(expected, actual) << from_here.ToString();
51 }
52
53 void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here,
54 base::File::Error expected,
55 base::Closure closure,
56 base::File::Error actual) {
57 ASSERT_EQ(expected, actual) << from_here.ToString();
58 closure.Run();
59 }
60
61 } // namespace
62
63 // Test class for FileSystemOperationImpl. 43 // Test class for FileSystemOperationImpl.
64 class FileSystemOperationImplTest 44 class FileSystemOperationImplTest
65 : public testing::Test { 45 : public testing::Test {
66 public: 46 public:
67 FileSystemOperationImplTest() 47 FileSystemOperationImplTest() : weak_factory_(this) {}
68 : status_(kFileOperationStatusNotSet),
69 weak_factory_(this) {}
70 48
71 protected: 49 protected:
72 virtual void SetUp() OVERRIDE { 50 virtual void SetUp() OVERRIDE {
73 EXPECT_TRUE(base_.CreateUniqueTempDir()); 51 EXPECT_TRUE(base_.CreateUniqueTempDir());
74 change_observers_ = 52 change_observers_ =
75 storage::MockFileChangeObserver::CreateList(&change_observer_); 53 storage::MockFileChangeObserver::CreateList(&change_observer_);
76 54
77 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); 55 base::FilePath base_dir = base_.path().AppendASCII("filesystem");
78 quota_manager_ = 56 quota_manager_ =
79 new MockQuotaManager(false /* is_incognito */, 57 new MockQuotaManager(false /* is_incognito */,
(...skipping 12 matching lines...) Expand all
92 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); 70 quota_manager_proxy()->SimulateQuotaManagerDestroyed();
93 quota_manager_ = NULL; 71 quota_manager_ = NULL;
94 quota_manager_proxy_ = NULL; 72 quota_manager_proxy_ = NULL;
95 sandbox_file_system_.TearDown(); 73 sandbox_file_system_.TearDown();
96 } 74 }
97 75
98 FileSystemOperationRunner* operation_runner() { 76 FileSystemOperationRunner* operation_runner() {
99 return sandbox_file_system_.operation_runner(); 77 return sandbox_file_system_.operation_runner();
100 } 78 }
101 79
102 int status() const { return status_; }
103 const base::File::Info& info() const { return info_; } 80 const base::File::Info& info() const { return info_; }
104 const base::FilePath& path() const { return path_; } 81 const base::FilePath& path() const { return path_; }
105 const std::vector<storage::DirectoryEntry>& entries() const { 82 const std::vector<storage::DirectoryEntry>& entries() const {
106 return entries_; 83 return entries_;
107 } 84 }
108 85
109 const ShareableFileReference* shareable_file_ref() const { 86 const ShareableFileReference* shareable_file_ref() const {
110 return shareable_file_ref_.get(); 87 return shareable_file_ref_.get();
111 } 88 }
112 89
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return url; 150 return url;
174 } 151 }
175 152
176 int64 GetFileSize(const std::string& path) { 153 int64 GetFileSize(const std::string& path) {
177 base::File::Info info; 154 base::File::Info info;
178 EXPECT_TRUE(base::GetFileInfo(PlatformPath(path), &info)); 155 EXPECT_TRUE(base::GetFileInfo(PlatformPath(path), &info));
179 return info.size; 156 return info.size;
180 } 157 }
181 158
182 // Callbacks for recording test results. 159 // Callbacks for recording test results.
183 FileSystemOperation::StatusCallback RecordStatusCallback() { 160 FileSystemOperation::StatusCallback RecordStatusCallback(
161 const base::Closure& closure,
162 base::File::Error* status) {
184 return base::Bind(&FileSystemOperationImplTest::DidFinish, 163 return base::Bind(&FileSystemOperationImplTest::DidFinish,
185 weak_factory_.GetWeakPtr()); 164 weak_factory_.GetWeakPtr(),
165 closure,
166 status);
186 } 167 }
187 168
188 FileSystemOperation::ReadDirectoryCallback 169 FileSystemOperation::ReadDirectoryCallback RecordReadDirectoryCallback(
189 RecordReadDirectoryCallback() { 170 const base::Closure& closure,
171 base::File::Error* status) {
190 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory, 172 return base::Bind(&FileSystemOperationImplTest::DidReadDirectory,
191 weak_factory_.GetWeakPtr()); 173 weak_factory_.GetWeakPtr(),
174 closure,
175 status);
192 } 176 }
193 177
194 FileSystemOperation::GetMetadataCallback RecordMetadataCallback() { 178 FileSystemOperation::GetMetadataCallback RecordMetadataCallback(
179 const base::Closure& closure,
180 base::File::Error* status) {
195 return base::Bind(&FileSystemOperationImplTest::DidGetMetadata, 181 return base::Bind(&FileSystemOperationImplTest::DidGetMetadata,
196 weak_factory_.GetWeakPtr()); 182 weak_factory_.GetWeakPtr(),
183 closure,
184 status);
197 } 185 }
198 186
199 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() { 187 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback(
188 const base::Closure& closure,
189 base::File::Error* status) {
200 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, 190 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile,
201 weak_factory_.GetWeakPtr()); 191 weak_factory_.GetWeakPtr(),
192 closure,
193 status);
202 } 194 }
203 195
204 void DidFinish(base::File::Error status) { 196 void DidFinish(const base::Closure& closure,
205 status_ = status; 197 base::File::Error* status,
198 base::File::Error actual) {
199 *status = actual;
200 closure.Run();
206 } 201 }
207 202
208 void DidReadDirectory(base::File::Error status, 203 void DidReadDirectory(const base::Closure& closure,
204 base::File::Error* status,
205 base::File::Error actual,
209 const std::vector<storage::DirectoryEntry>& entries, 206 const std::vector<storage::DirectoryEntry>& entries,
210 bool /* has_more */) { 207 bool /* has_more */) {
211 entries_ = entries; 208 entries_ = entries;
212 status_ = status; 209 *status = actual;
210 closure.Run();
213 } 211 }
214 212
215 void DidGetMetadata(base::File::Error status, 213 void DidGetMetadata(const base::Closure& closure,
214 base::File::Error* status,
215 base::File::Error actual,
216 const base::File::Info& info) { 216 const base::File::Info& info) {
217 info_ = info; 217 info_ = info;
218 status_ = status; 218 *status = actual;
219 closure.Run();
219 } 220 }
220 221
221 void DidCreateSnapshotFile( 222 void DidCreateSnapshotFile(
222 base::File::Error status, 223 const base::Closure& closure,
224 base::File::Error* status,
225 base::File::Error actual,
223 const base::File::Info& info, 226 const base::File::Info& info,
224 const base::FilePath& platform_path, 227 const base::FilePath& platform_path,
225 const scoped_refptr<ShareableFileReference>& shareable_file_ref) { 228 const scoped_refptr<ShareableFileReference>& shareable_file_ref) {
226 info_ = info; 229 info_ = info;
227 path_ = platform_path; 230 path_ = platform_path;
228 status_ = status; 231 *status = actual;
229 shareable_file_ref_ = shareable_file_ref; 232 shareable_file_ref_ = shareable_file_ref;
233 closure.Run();
230 } 234 }
231 235
232 int64 GetDataSizeOnDisk() { 236 int64 GetDataSizeOnDisk() {
233 return sandbox_file_system_.ComputeCurrentOriginUsage() - 237 return sandbox_file_system_.ComputeCurrentOriginUsage() -
234 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage(); 238 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage();
235 } 239 }
236 240
237 void GetUsageAndQuota(int64* usage, int64* quota) { 241 void GetUsageAndQuota(int64* usage, int64* quota) {
238 storage::QuotaStatusCode status = 242 storage::QuotaStatusCode status =
239 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(), 243 AsyncFileTestHelper::GetUsageAndQuota(quota_manager_.get(),
240 sandbox_file_system_.origin(), 244 sandbox_file_system_.origin(),
241 sandbox_file_system_.type(), 245 sandbox_file_system_.type(),
242 usage, 246 usage,
243 quota); 247 quota);
244 base::RunLoop().RunUntilIdle(); 248 base::RunLoop().RunUntilIdle();
245 ASSERT_EQ(storage::kQuotaStatusOk, status); 249 ASSERT_EQ(storage::kQuotaStatusOk, status);
246 } 250 }
247 251
248 int64 ComputePathCost(const FileSystemURL& url) { 252 int64 ComputePathCost(const FileSystemURL& url) {
249 int64 base_usage; 253 int64 base_usage;
250 GetUsageAndQuota(&base_usage, NULL); 254 GetUsageAndQuota(&base_usage, NULL);
251 255
252 AsyncFileTestHelper::CreateFile( 256 AsyncFileTestHelper::CreateFile(
253 sandbox_file_system_.file_system_context(), url); 257 sandbox_file_system_.file_system_context(), url);
254 operation_runner()->Remove(url, false /* recursive */, 258 EXPECT_EQ(Remove(url, false /* recursive */), base::File::FILE_OK);
tzik 2014/09/11 06:19:53 Please put the expectation first.
iseki 2014/09/11 06:36:55 Done.
255 base::Bind(&AssertFileErrorEq, FROM_HERE, 259
256 base::File::FILE_OK));
257 base::RunLoop().RunUntilIdle();
258 change_observer()->ResetCount(); 260 change_observer()->ResetCount();
259 261
260 int64 total_usage; 262 int64 total_usage;
261 GetUsageAndQuota(&total_usage, NULL); 263 GetUsageAndQuota(&total_usage, NULL);
262 return total_usage - base_usage; 264 return total_usage - base_usage;
263 } 265 }
264 266
265 void GrantQuotaForCurrentUsage() { 267 void GrantQuotaForCurrentUsage() {
266 int64 usage; 268 int64 usage;
267 GetUsageAndQuota(&usage, NULL); 269 GetUsageAndQuota(&usage, NULL);
268 quota_manager()->SetQuota(sandbox_file_system_.origin(), 270 quota_manager()->SetQuota(sandbox_file_system_.origin(),
269 sandbox_file_system_.storage_type(), 271 sandbox_file_system_.storage_type(),
270 usage); 272 usage);
271 } 273 }
272 274
273 int64 GetUsage() { 275 int64 GetUsage() {
274 int64 usage = 0; 276 int64 usage = 0;
275 GetUsageAndQuota(&usage, NULL); 277 GetUsageAndQuota(&usage, NULL);
276 return usage; 278 return usage;
277 } 279 }
278 280
279 void AddQuota(int64 quota_delta) { 281 void AddQuota(int64 quota_delta) {
280 int64 quota; 282 int64 quota;
281 GetUsageAndQuota(NULL, &quota); 283 GetUsageAndQuota(NULL, &quota);
282 quota_manager()->SetQuota(sandbox_file_system_.origin(), 284 quota_manager()->SetQuota(sandbox_file_system_.origin(),
283 sandbox_file_system_.storage_type(), 285 sandbox_file_system_.storage_type(),
284 quota + quota_delta); 286 quota + quota_delta);
285 } 287 }
286 288
289 base::File::Error Move(
290 const FileSystemURL& src,
tzik 2014/09/11 06:19:54 could you pack this to the previous line?
iseki 2014/09/11 06:36:54 If pack this to the previous line, option is over
291 const FileSystemURL& dest,
292 storage::FileSystemOperation::CopyOrMoveOption option) {
293 base::File::Error status;
294 base::RunLoop run_loop;
295 operation_runner()->Move(
296 src,
297 dest,
298 option,
299 RecordStatusCallback(run_loop.QuitClosure(), &status));
300 run_loop.Run();
301 return status;
302 }
303
304 base::File::Error Copy(
305 const FileSystemURL& src,
tzik 2014/09/11 06:19:54 ditto
iseki 2014/09/11 06:36:54 The same reason.
306 const FileSystemURL& dest,
307 storage::FileSystemOperation::CopyOrMoveOption option) {
308 base::File::Error status;
309 base::RunLoop run_loop;
310 operation_runner()->Copy(
311 src,
312 dest,
313 option,
314 FileSystemOperationRunner::CopyProgressCallback(),
315 RecordStatusCallback(run_loop.QuitClosure(), &status));
316 run_loop.Run();
317 return status;
318 }
319
320 base::File::Error CopyInForeignFile(const base::FilePath& src,
321 const FileSystemURL& dest) {
tzik 2014/09/11 06:19:54 indent?
iseki 2014/09/11 06:36:55 Done.
322 base::File::Error status;
323 base::RunLoop run_loop;
324 operation_runner()->CopyInForeignFile(
325 src, dest, RecordStatusCallback(run_loop.QuitClosure(), &status));
326 run_loop.Run();
327 return status;
328 }
329
330 base::File::Error Truncate(const FileSystemURL& url, int size) {
331 base::File::Error status;
332 base::RunLoop run_loop;
333 operation_runner()->Truncate(
334 url, size, RecordStatusCallback(run_loop.QuitClosure(), &status));
335 run_loop.Run();
336 return status;
337 }
338
339 base::File::Error CreateFile(const FileSystemURL& url, bool exclusive) {
340 base::File::Error status;
341 base::RunLoop run_loop;
342 operation_runner()->CreateFile(
343 url, exclusive, RecordStatusCallback(run_loop.QuitClosure(), &status));
344 run_loop.Run();
345 return status;
346 }
347
348 base::File::Error Remove(const FileSystemURL& url, bool recursive) {
349 base::File::Error status;
350 base::RunLoop run_loop;
351 operation_runner()->Remove(
352 url, recursive, RecordStatusCallback(run_loop.QuitClosure(), &status));
353 run_loop.Run();
354 return status;
355 }
356
357 base::File::Error CreateDirectory(const FileSystemURL& url,
358 bool exclusive,
tzik 2014/09/11 06:19:53 indent?
iseki 2014/09/11 06:36:54 Done.
359 bool recursive) {
360 base::File::Error status;
361 base::RunLoop run_loop;
362 operation_runner()->CreateDirectory(
363 url,
364 exclusive,
365 recursive,
366 RecordStatusCallback(run_loop.QuitClosure(), &status));
367 run_loop.Run();
368 return status;
369 }
370
371 base::File::Error GetMetadata(const FileSystemURL& url) {
372 base::File::Error status;
373 base::RunLoop run_loop;
374 operation_runner()->GetMetadata(
375 url, RecordMetadataCallback(run_loop.QuitClosure(), &status));
376 run_loop.Run();
377 return status;
378 }
379
380 base::File::Error ReadDirectory(const FileSystemURL& url) {
381 base::File::Error status;
382 base::RunLoop run_loop;
383 operation_runner()->ReadDirectory(
384 url, RecordReadDirectoryCallback(run_loop.QuitClosure(), &status));
385 run_loop.Run();
386 return status;
387 }
388
389 base::File::Error CreateSnapshotFile(const FileSystemURL& url) {
390 base::File::Error status;
391 base::RunLoop run_loop;
392 operation_runner()->CreateSnapshotFile(
393 url, RecordSnapshotFileCallback(run_loop.QuitClosure(), &status));
394 run_loop.Run();
395 return status;
396 }
397
398 base::File::Error FileExists(const FileSystemURL& url) {
399 base::File::Error status;
400 base::RunLoop run_loop;
401 operation_runner()->FileExists(
402 url, RecordStatusCallback(run_loop.QuitClosure(), &status));
403 run_loop.Run();
404 return status;
405 }
406
407 base::File::Error DirectoryExists(const FileSystemURL& url) {
408 base::File::Error status;
409 base::RunLoop run_loop;
410 operation_runner()->DirectoryExists(
411 url, RecordStatusCallback(run_loop.QuitClosure(), &status));
412 run_loop.Run();
413 return status;
414 }
415
416 base::File::Error TouchFile(const FileSystemURL& url,
417 const base::Time& last_access_time,
tzik 2014/09/11 06:19:54 indent?
iseki 2014/09/11 06:36:54 Done.
418 const base::Time& last_modified_time) {
419 base::File::Error status;
420 base::RunLoop run_loop;
421 operation_runner()->TouchFile(
422 url,
423 last_access_time,
424 last_modified_time,
425 RecordStatusCallback(run_loop.QuitClosure(), &status));
426 run_loop.Run();
427 return status;
428 }
429
287 private: 430 private:
288 base::MessageLoopForIO message_loop_; 431 base::MessageLoopForIO message_loop_;
289 scoped_refptr<QuotaManager> quota_manager_; 432 scoped_refptr<QuotaManager> quota_manager_;
290 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; 433 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
291 434
292 // Common temp base for nondestructive uses. 435 // Common temp base for nondestructive uses.
293 base::ScopedTempDir base_; 436 base::ScopedTempDir base_;
294 437
295 SandboxFileSystemTestHelper sandbox_file_system_; 438 SandboxFileSystemTestHelper sandbox_file_system_;
296 439
297 // For post-operation status. 440 // For post-operation status.
298 int status_;
299 base::File::Info info_; 441 base::File::Info info_;
300 base::FilePath path_; 442 base::FilePath path_;
301 std::vector<storage::DirectoryEntry> entries_; 443 std::vector<storage::DirectoryEntry> entries_;
302 scoped_refptr<ShareableFileReference> shareable_file_ref_; 444 scoped_refptr<ShareableFileReference> shareable_file_ref_;
303 445
304 storage::MockFileChangeObserver change_observer_; 446 storage::MockFileChangeObserver change_observer_;
305 storage::ChangeObserverList change_observers_; 447 storage::ChangeObserverList change_observers_;
306 448
307 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; 449 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_;
308 450
309 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); 451 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest);
310 }; 452 };
311 453
312 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { 454 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) {
313 change_observer()->ResetCount(); 455 change_observer()->ResetCount();
314 operation_runner()->Move(URLForPath("a"), URLForPath("b"), 456 EXPECT_EQ(
315 FileSystemOperation::OPTION_NONE, 457 base::File::FILE_ERROR_NOT_FOUND,
316 RecordStatusCallback()); 458 Move(
317 base::RunLoop().RunUntilIdle(); 459 URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE));
tzik 2014/09/11 06:19:54 Just for my preference: Move(URLForPath("a"), URLF
iseki 2014/09/11 06:36:54 Done.
318 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
319 EXPECT_TRUE(change_observer()->HasNoChange()); 460 EXPECT_TRUE(change_observer()->HasNoChange());
320 } 461 }
321 462
322 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { 463 TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) {
323 FileSystemURL src_dir(CreateDirectory("src")); 464 FileSystemURL src_dir(CreateDirectory("src"));
324 FileSystemURL dest_dir(CreateDirectory("src/dest")); 465 FileSystemURL dest_dir(CreateDirectory("src/dest"));
325 466
326 operation_runner()->Move(src_dir, dest_dir, 467 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
327 FileSystemOperation::OPTION_NONE, 468 Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE));
328 RecordStatusCallback());
329 base::RunLoop().RunUntilIdle();
330 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
331 EXPECT_TRUE(change_observer()->HasNoChange()); 469 EXPECT_TRUE(change_observer()->HasNoChange());
332 } 470 }
333 471
334 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { 472 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) {
335 // Src exists and is dir. Dest is a file. 473 // Src exists and is dir. Dest is a file.
336 FileSystemURL src_dir(CreateDirectory("src")); 474 FileSystemURL src_dir(CreateDirectory("src"));
337 FileSystemURL dest_dir(CreateDirectory("dest")); 475 FileSystemURL dest_dir(CreateDirectory("dest"));
338 FileSystemURL dest_file(CreateFile("dest/file")); 476 FileSystemURL dest_file(CreateFile("dest/file"));
339 477
340 operation_runner()->Move(src_dir, dest_file, 478 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
341 FileSystemOperation::OPTION_NONE, 479 Move(src_dir, dest_file, FileSystemOperation::OPTION_NONE));
342 RecordStatusCallback());
343 base::RunLoop().RunUntilIdle();
344 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
345 EXPECT_TRUE(change_observer()->HasNoChange()); 480 EXPECT_TRUE(change_observer()->HasNoChange());
346 } 481 }
347 482
348 TEST_F(FileSystemOperationImplTest, 483 TEST_F(FileSystemOperationImplTest,
349 TestMoveFailureSrcFileExistsDestNonEmptyDir) { 484 TestMoveFailureSrcFileExistsDestNonEmptyDir) {
350 // Src exists and is a directory. Dest is a non-empty directory. 485 // Src exists and is a directory. Dest is a non-empty directory.
351 FileSystemURL src_dir(CreateDirectory("src")); 486 FileSystemURL src_dir(CreateDirectory("src"));
352 FileSystemURL dest_dir(CreateDirectory("dest")); 487 FileSystemURL dest_dir(CreateDirectory("dest"));
353 FileSystemURL dest_file(CreateFile("dest/file")); 488 FileSystemURL dest_file(CreateFile("dest/file"));
354 489
355 operation_runner()->Move(src_dir, dest_dir, 490 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY,
356 FileSystemOperation::OPTION_NONE, 491 Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE));
357 RecordStatusCallback());
358 base::RunLoop().RunUntilIdle();
359 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status());
360 EXPECT_TRUE(change_observer()->HasNoChange()); 492 EXPECT_TRUE(change_observer()->HasNoChange());
361 } 493 }
362 494
363 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { 495 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) {
364 // Src exists and is a file. Dest is a directory. 496 // Src exists and is a file. Dest is a directory.
365 FileSystemURL src_dir(CreateDirectory("src")); 497 FileSystemURL src_dir(CreateDirectory("src"));
366 FileSystemURL src_file(CreateFile("src/file")); 498 FileSystemURL src_file(CreateFile("src/file"));
367 FileSystemURL dest_dir(CreateDirectory("dest")); 499 FileSystemURL dest_dir(CreateDirectory("dest"));
368 500
369 operation_runner()->Move(src_file, dest_dir, 501 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
370 FileSystemOperation::OPTION_NONE, 502 Move(src_file, dest_dir, FileSystemOperation::OPTION_NONE));
371 RecordStatusCallback());
372 base::RunLoop().RunUntilIdle();
373 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
374 EXPECT_TRUE(change_observer()->HasNoChange()); 503 EXPECT_TRUE(change_observer()->HasNoChange());
375 } 504 }
376 505
377 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { 506 TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) {
378 // Dest. parent path does not exist. 507 // Dest. parent path does not exist.
379 FileSystemURL src_dir(CreateDirectory("src")); 508 FileSystemURL src_dir(CreateDirectory("src"));
380 operation_runner()->Move(src_dir, URLForPath("nonexistent/deset"), 509 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
381 FileSystemOperation::OPTION_NONE, 510 Move(src_dir,
382 RecordStatusCallback()); 511 URLForPath("nonexistent/deset"),
tzik 2014/09/11 06:19:54 indent?
iseki 2014/09/11 06:36:55 Done.
383 base::RunLoop().RunUntilIdle(); 512 FileSystemOperation::OPTION_NONE));
384 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
385 EXPECT_TRUE(change_observer()->HasNoChange()); 513 EXPECT_TRUE(change_observer()->HasNoChange());
386 } 514 }
387 515
388 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { 516 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) {
389 FileSystemURL src_file(CreateFile("src")); 517 FileSystemURL src_file(CreateFile("src"));
390 FileSystemURL dest_file(CreateFile("dest")); 518 FileSystemURL dest_file(CreateFile("dest"));
391 519
392 operation_runner()->Move(src_file, dest_file, 520 EXPECT_EQ(base::File::FILE_OK,
393 FileSystemOperation::OPTION_NONE, 521 Move(src_file, dest_file, FileSystemOperation::OPTION_NONE));
394 RecordStatusCallback());
395 base::RunLoop().RunUntilIdle();
396 EXPECT_EQ(base::File::FILE_OK, status());
397 EXPECT_TRUE(FileExists("dest")); 522 EXPECT_TRUE(FileExists("dest"));
398 523
399 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 524 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
400 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 525 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
401 EXPECT_TRUE(change_observer()->HasNoChange()); 526 EXPECT_TRUE(change_observer()->HasNoChange());
402 527
403 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); 528 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
404 } 529 }
405 530
406 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { 531 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) {
407 FileSystemURL src_file(CreateFile("src")); 532 FileSystemURL src_file(CreateFile("src"));
408 533
409 operation_runner()->Move(src_file, URLForPath("new"), 534 EXPECT_EQ(
410 FileSystemOperation::OPTION_NONE, 535 base::File::FILE_OK,
411 RecordStatusCallback()); 536 Move(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE));
412 base::RunLoop().RunUntilIdle();
413 EXPECT_EQ(base::File::FILE_OK, status());
414 EXPECT_TRUE(FileExists("new")); 537 EXPECT_TRUE(FileExists("new"));
415 538
416 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); 539 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count());
417 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 540 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
418 EXPECT_TRUE(change_observer()->HasNoChange()); 541 EXPECT_TRUE(change_observer()->HasNoChange());
419 } 542 }
420 543
421 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { 544 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) {
422 FileSystemURL src_dir(CreateDirectory("src")); 545 FileSystemURL src_dir(CreateDirectory("src"));
423 FileSystemURL dest_dir(CreateDirectory("dest")); 546 FileSystemURL dest_dir(CreateDirectory("dest"));
424 547
425 operation_runner()->Move(src_dir, dest_dir, 548 EXPECT_EQ(base::File::FILE_OK,
426 FileSystemOperation::OPTION_NONE, 549 Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE));
427 RecordStatusCallback());
428 base::RunLoop().RunUntilIdle();
429 EXPECT_EQ(base::File::FILE_OK, status());
430 EXPECT_FALSE(DirectoryExists("src")); 550 EXPECT_FALSE(DirectoryExists("src"));
431 551
432 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 552 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
433 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); 553 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count());
434 EXPECT_TRUE(change_observer()->HasNoChange()); 554 EXPECT_TRUE(change_observer()->HasNoChange());
435 555
436 // Make sure we've overwritten but not moved the source under the |dest_dir|. 556 // Make sure we've overwritten but not moved the source under the |dest_dir|.
437 EXPECT_TRUE(DirectoryExists("dest")); 557 EXPECT_TRUE(DirectoryExists("dest"));
438 EXPECT_FALSE(DirectoryExists("dest/src")); 558 EXPECT_FALSE(DirectoryExists("dest/src"));
439 } 559 }
440 560
441 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { 561 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) {
442 FileSystemURL src_dir(CreateDirectory("src")); 562 FileSystemURL src_dir(CreateDirectory("src"));
443 FileSystemURL dest_dir(CreateDirectory("dest")); 563 FileSystemURL dest_dir(CreateDirectory("dest"));
444 564
445 operation_runner()->Move(src_dir, URLForPath("dest/new"), 565 EXPECT_EQ(
446 FileSystemOperation::OPTION_NONE, 566 base::File::FILE_OK,
447 RecordStatusCallback()); 567 Move(
448 base::RunLoop().RunUntilIdle(); 568 src_dir, URLForPath("dest/new"), FileSystemOperation::OPTION_NONE));
449 EXPECT_EQ(base::File::FILE_OK, status());
450 EXPECT_FALSE(DirectoryExists("src")); 569 EXPECT_FALSE(DirectoryExists("src"));
451 EXPECT_TRUE(DirectoryExists("dest/new")); 570 EXPECT_TRUE(DirectoryExists("dest/new"));
452 571
453 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 572 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
454 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 573 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
455 EXPECT_TRUE(change_observer()->HasNoChange()); 574 EXPECT_TRUE(change_observer()->HasNoChange());
456 } 575 }
457 576
458 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { 577 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) {
459 FileSystemURL src_dir(CreateDirectory("src")); 578 FileSystemURL src_dir(CreateDirectory("src"));
460 CreateDirectory("src/dir"); 579 CreateDirectory("src/dir");
461 CreateFile("src/dir/sub"); 580 CreateFile("src/dir/sub");
462 581
463 FileSystemURL dest_dir(CreateDirectory("dest")); 582 FileSystemURL dest_dir(CreateDirectory("dest"));
464 583
465 operation_runner()->Move(src_dir, dest_dir, 584 EXPECT_EQ(base::File::FILE_OK,
466 FileSystemOperation::OPTION_NONE, 585 Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE));
467 RecordStatusCallback());
468 base::RunLoop().RunUntilIdle();
469 EXPECT_EQ(base::File::FILE_OK, status());
470 EXPECT_TRUE(DirectoryExists("dest/dir")); 586 EXPECT_TRUE(DirectoryExists("dest/dir"));
471 EXPECT_TRUE(FileExists("dest/dir/sub")); 587 EXPECT_TRUE(FileExists("dest/dir/sub"));
472 588
473 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count()); 589 EXPECT_EQ(3, change_observer()->get_and_reset_remove_directory_count());
474 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); 590 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
475 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 591 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
476 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); 592 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count());
477 EXPECT_TRUE(change_observer()->HasNoChange()); 593 EXPECT_TRUE(change_observer()->HasNoChange());
478 } 594 }
479 595
480 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { 596 TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) {
481 FileSystemURL src_dir(CreateDirectory("src")); 597 FileSystemURL src_dir(CreateDirectory("src"));
482 CreateDirectory("src/dir"); 598 CreateDirectory("src/dir");
483 CreateFile("src/dir/sub"); 599 CreateFile("src/dir/sub");
484 600
485 operation_runner()->Move(src_dir, src_dir, 601 EXPECT_EQ(base::File::FILE_OK,
486 FileSystemOperation::OPTION_NONE, 602 Move(src_dir, src_dir, FileSystemOperation::OPTION_NONE));
487 RecordStatusCallback());
488 base::RunLoop().RunUntilIdle();
489 EXPECT_EQ(base::File::FILE_OK, status());
490 EXPECT_TRUE(DirectoryExists("src/dir")); 603 EXPECT_TRUE(DirectoryExists("src/dir"));
491 EXPECT_TRUE(FileExists("src/dir/sub")); 604 EXPECT_TRUE(FileExists("src/dir/sub"));
492 605
493 EXPECT_EQ(0, change_observer()->get_and_reset_remove_directory_count()); 606 EXPECT_EQ(0, change_observer()->get_and_reset_remove_directory_count());
494 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); 607 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count());
495 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); 608 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count());
496 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); 609 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count());
497 EXPECT_TRUE(change_observer()->HasNoChange()); 610 EXPECT_TRUE(change_observer()->HasNoChange());
498 } 611 }
499 612
500 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { 613 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) {
501 operation_runner()->Copy(URLForPath("a"), URLForPath("b"), 614 EXPECT_EQ(
502 FileSystemOperation::OPTION_NONE, 615 base::File::FILE_ERROR_NOT_FOUND,
503 FileSystemOperationRunner::CopyProgressCallback(), 616 Copy(
504 RecordStatusCallback()); 617 URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE));
505 base::RunLoop().RunUntilIdle();
506 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
507 EXPECT_TRUE(change_observer()->HasNoChange()); 618 EXPECT_TRUE(change_observer()->HasNoChange());
508 } 619 }
509 620
510 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { 621 TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) {
511 FileSystemURL src_dir(CreateDirectory("src")); 622 FileSystemURL src_dir(CreateDirectory("src"));
512 FileSystemURL dest_dir(CreateDirectory("src/dir")); 623 FileSystemURL dest_dir(CreateDirectory("src/dir"));
513 624
514 operation_runner()->Copy(src_dir, dest_dir, 625 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
515 FileSystemOperation::OPTION_NONE, 626 Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE));
516 FileSystemOperationRunner::CopyProgressCallback(),
517 RecordStatusCallback());
518 base::RunLoop().RunUntilIdle();
519 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
520 EXPECT_TRUE(change_observer()->HasNoChange()); 627 EXPECT_TRUE(change_observer()->HasNoChange());
521 } 628 }
522 629
523 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { 630 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) {
524 // Src exists and is dir. Dest is a file. 631 // Src exists and is dir. Dest is a file.
525 FileSystemURL src_dir(CreateDirectory("src")); 632 FileSystemURL src_dir(CreateDirectory("src"));
526 FileSystemURL dest_dir(CreateDirectory("dest")); 633 FileSystemURL dest_dir(CreateDirectory("dest"));
527 FileSystemURL dest_file(CreateFile("dest/file")); 634 FileSystemURL dest_file(CreateFile("dest/file"));
528 635
529 operation_runner()->Copy(src_dir, dest_file, 636 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
530 FileSystemOperation::OPTION_NONE, 637 Copy(src_dir, dest_file, FileSystemOperation::OPTION_NONE));
531 FileSystemOperationRunner::CopyProgressCallback(),
532 RecordStatusCallback());
533 base::RunLoop().RunUntilIdle();
534 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
535 EXPECT_TRUE(change_observer()->HasNoChange()); 638 EXPECT_TRUE(change_observer()->HasNoChange());
536 } 639 }
537 640
538 TEST_F(FileSystemOperationImplTest, 641 TEST_F(FileSystemOperationImplTest,
539 TestCopyFailureSrcFileExistsDestNonEmptyDir) { 642 TestCopyFailureSrcFileExistsDestNonEmptyDir) {
540 // Src exists and is a directory. Dest is a non-empty directory. 643 // Src exists and is a directory. Dest is a non-empty directory.
541 FileSystemURL src_dir(CreateDirectory("src")); 644 FileSystemURL src_dir(CreateDirectory("src"));
542 FileSystemURL dest_dir(CreateDirectory("dest")); 645 FileSystemURL dest_dir(CreateDirectory("dest"));
543 FileSystemURL dest_file(CreateFile("dest/file")); 646 FileSystemURL dest_file(CreateFile("dest/file"));
544 647
545 operation_runner()->Copy(src_dir, dest_dir, 648 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY,
546 FileSystemOperation::OPTION_NONE, 649 Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE));
547 FileSystemOperationRunner::CopyProgressCallback(),
548 RecordStatusCallback());
549 base::RunLoop().RunUntilIdle();
550 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status());
551 EXPECT_TRUE(change_observer()->HasNoChange()); 650 EXPECT_TRUE(change_observer()->HasNoChange());
552 } 651 }
553 652
554 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { 653 TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) {
555 // Src exists and is a file. Dest is a directory. 654 // Src exists and is a file. Dest is a directory.
556 FileSystemURL src_file(CreateFile("src")); 655 FileSystemURL src_file(CreateFile("src"));
557 FileSystemURL dest_dir(CreateDirectory("dest")); 656 FileSystemURL dest_dir(CreateDirectory("dest"));
558 657
559 operation_runner()->Copy(src_file, dest_dir, 658 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION,
560 FileSystemOperation::OPTION_NONE, 659 Copy(src_file, dest_dir, FileSystemOperation::OPTION_NONE));
561 FileSystemOperationRunner::CopyProgressCallback(),
562 RecordStatusCallback());
563 base::RunLoop().RunUntilIdle();
564 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, status());
565 EXPECT_TRUE(change_observer()->HasNoChange()); 660 EXPECT_TRUE(change_observer()->HasNoChange());
566 } 661 }
567 662
568 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { 663 TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) {
569 // Dest. parent path does not exist. 664 // Dest. parent path does not exist.
570 FileSystemURL src_dir(CreateDirectory("src")); 665 FileSystemURL src_dir(CreateDirectory("src"));
571 666
572 operation_runner()->Copy(src_dir, URLForPath("nonexistent/dest"), 667 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
573 FileSystemOperation::OPTION_NONE, 668 Copy(src_dir,
574 FileSystemOperationRunner::CopyProgressCallback(), 669 URLForPath("nonexistent/dest"),
575 RecordStatusCallback()); 670 FileSystemOperation::OPTION_NONE));
576 base::RunLoop().RunUntilIdle();
577 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
578 EXPECT_TRUE(change_observer()->HasNoChange()); 671 EXPECT_TRUE(change_observer()->HasNoChange());
579 } 672 }
580 673
581 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { 674 TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) {
582 FileSystemURL src_dir(CreateDirectory("src")); 675 FileSystemURL src_dir(CreateDirectory("src"));
583 FileSystemURL src_file(CreateFile("src/file")); 676 FileSystemURL src_file(CreateFile("src/file"));
584 FileSystemURL dest_dir(CreateDirectory("dest")); 677 FileSystemURL dest_dir(CreateDirectory("dest"));
585 operation_runner()->Truncate(src_file, 6, RecordStatusCallback()); 678 EXPECT_EQ(base::File::FILE_OK, Truncate(src_file, 6));
586 base::RunLoop().RunUntilIdle();
587 EXPECT_EQ(base::File::FILE_OK, status());
588 EXPECT_EQ(6, GetFileSize("src/file")); 679 EXPECT_EQ(6, GetFileSize("src/file"));
589 680
590 FileSystemURL dest_file(URLForPath("dest/file")); 681 FileSystemURL dest_file(URLForPath("dest/file"));
591 int64 dest_path_cost = ComputePathCost(dest_file); 682 int64 dest_path_cost = ComputePathCost(dest_file);
592 GrantQuotaForCurrentUsage(); 683 GrantQuotaForCurrentUsage();
593 AddQuota(6 + dest_path_cost - 1); 684 AddQuota(6 + dest_path_cost - 1);
594 685
595 operation_runner()->Copy(src_file, dest_file, 686 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
596 FileSystemOperation::OPTION_NONE, 687 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE));
597 FileSystemOperationRunner::CopyProgressCallback(),
598 RecordStatusCallback());
599 base::RunLoop().RunUntilIdle();
600 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status());
601 EXPECT_FALSE(FileExists("dest/file")); 688 EXPECT_FALSE(FileExists("dest/file"));
602 } 689 }
603 690
604 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { 691 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) {
605 FileSystemURL src_file(CreateFile("src")); 692 FileSystemURL src_file(CreateFile("src"));
606 FileSystemURL dest_file(CreateFile("dest")); 693 FileSystemURL dest_file(CreateFile("dest"));
607 694
608 operation_runner()->Copy(src_file, dest_file, 695 EXPECT_EQ(base::File::FILE_OK,
609 FileSystemOperation::OPTION_NONE, 696 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE));
610 FileSystemOperationRunner::CopyProgressCallback(), 697
611 RecordStatusCallback());
612 base::RunLoop().RunUntilIdle();
613 EXPECT_EQ(base::File::FILE_OK, status());
614 EXPECT_TRUE(FileExists("dest")); 698 EXPECT_TRUE(FileExists("dest"));
615 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); 699 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count());
616 EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count()); 700 EXPECT_EQ(2, change_observer()->get_and_reset_modify_file_count());
617 701
618 EXPECT_TRUE(change_observer()->HasNoChange()); 702 EXPECT_TRUE(change_observer()->HasNoChange());
619 } 703 }
620 704
621 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { 705 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) {
622 FileSystemURL src_file(CreateFile("src")); 706 FileSystemURL src_file(CreateFile("src"));
623 707
624 operation_runner()->Copy(src_file, URLForPath("new"), 708 EXPECT_EQ(
625 FileSystemOperation::OPTION_NONE, 709 base::File::FILE_OK,
626 FileSystemOperationRunner::CopyProgressCallback(), 710 Copy(src_file, URLForPath("new"), FileSystemOperation::OPTION_NONE));
627 RecordStatusCallback());
628 base::RunLoop().RunUntilIdle();
629 EXPECT_EQ(base::File::FILE_OK, status());
630 EXPECT_TRUE(FileExists("new")); 711 EXPECT_TRUE(FileExists("new"));
631 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); 712 EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count());
632 713
633 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 714 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
634 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 715 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
635 EXPECT_TRUE(change_observer()->HasNoChange()); 716 EXPECT_TRUE(change_observer()->HasNoChange());
636 } 717 }
637 718
638 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { 719 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) {
639 FileSystemURL src_dir(CreateDirectory("src")); 720 FileSystemURL src_dir(CreateDirectory("src"));
640 FileSystemURL dest_dir(CreateDirectory("dest")); 721 FileSystemURL dest_dir(CreateDirectory("dest"));
641 722
642 operation_runner()->Copy(src_dir, dest_dir, 723 EXPECT_EQ(base::File::FILE_OK,
643 FileSystemOperation::OPTION_NONE, 724 Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE));
644 FileSystemOperationRunner::CopyProgressCallback(),
645 RecordStatusCallback());
646 base::RunLoop().RunUntilIdle();
647 EXPECT_EQ(base::File::FILE_OK, status());
648 725
649 // Make sure we've overwritten but not copied the source under the |dest_dir|. 726 // Make sure we've overwritten but not copied the source under the |dest_dir|.
650 EXPECT_TRUE(DirectoryExists("dest")); 727 EXPECT_TRUE(DirectoryExists("dest"));
651 EXPECT_FALSE(DirectoryExists("dest/src")); 728 EXPECT_FALSE(DirectoryExists("dest/src"));
652 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3); 729 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3);
653 730
654 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 731 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
655 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 732 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
656 EXPECT_TRUE(change_observer()->HasNoChange()); 733 EXPECT_TRUE(change_observer()->HasNoChange());
657 } 734 }
658 735
659 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { 736 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) {
660 FileSystemURL src_dir(CreateDirectory("src")); 737 FileSystemURL src_dir(CreateDirectory("src"));
661 FileSystemURL dest_dir_new(URLForPath("dest")); 738 FileSystemURL dest_dir_new(URLForPath("dest"));
662 739
663 operation_runner()->Copy(src_dir, dest_dir_new, 740 EXPECT_EQ(base::File::FILE_OK,
664 FileSystemOperation::OPTION_NONE, 741 Copy(src_dir, dest_dir_new, FileSystemOperation::OPTION_NONE));
665 FileSystemOperationRunner::CopyProgressCallback(),
666 RecordStatusCallback());
667 base::RunLoop().RunUntilIdle();
668 EXPECT_EQ(base::File::FILE_OK, status());
669 EXPECT_TRUE(DirectoryExists("dest")); 742 EXPECT_TRUE(DirectoryExists("dest"));
670 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); 743 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2);
671 744
672 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 745 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
673 EXPECT_TRUE(change_observer()->HasNoChange()); 746 EXPECT_TRUE(change_observer()->HasNoChange());
674 } 747 }
675 748
676 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { 749 TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) {
677 FileSystemURL src_dir(CreateDirectory("src")); 750 FileSystemURL src_dir(CreateDirectory("src"));
678 CreateDirectory("src/dir"); 751 CreateDirectory("src/dir");
679 CreateFile("src/dir/sub"); 752 CreateFile("src/dir/sub");
680 753
681 FileSystemURL dest_dir(CreateDirectory("dest")); 754 FileSystemURL dest_dir(CreateDirectory("dest"));
682 755
683 operation_runner()->Copy(src_dir, dest_dir, 756 EXPECT_EQ(base::File::FILE_OK,
684 FileSystemOperation::OPTION_NONE, 757 Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE));
685 FileSystemOperationRunner::CopyProgressCallback(),
686 RecordStatusCallback());
687 base::RunLoop().RunUntilIdle();
688 758
689 EXPECT_EQ(base::File::FILE_OK, status());
690 EXPECT_TRUE(DirectoryExists("dest/dir")); 759 EXPECT_TRUE(DirectoryExists("dest/dir"));
691 EXPECT_TRUE(FileExists("dest/dir/sub")); 760 EXPECT_TRUE(FileExists("dest/dir/sub"));
692 761
693 // For recursive copy we may record multiple read access. 762 // For recursive copy we may record multiple read access.
694 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1); 763 EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 1);
695 764
696 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); 765 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
697 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 766 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
698 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 767 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
699 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 768 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
700 EXPECT_TRUE(change_observer()->HasNoChange()); 769 EXPECT_TRUE(change_observer()->HasNoChange());
701 } 770 }
702 771
703 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { 772 TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) {
704 FileSystemURL src_dir(CreateDirectory("src")); 773 FileSystemURL src_dir(CreateDirectory("src"));
705 CreateDirectory("src/dir"); 774 CreateDirectory("src/dir");
706 CreateFile("src/dir/sub"); 775 CreateFile("src/dir/sub");
707 776
708 operation_runner()->Copy(src_dir, src_dir, 777 EXPECT_EQ(base::File::FILE_OK,
709 FileSystemOperation::OPTION_NONE, 778 Copy(src_dir, src_dir, FileSystemOperation::OPTION_NONE));
710 FileSystemOperationRunner::CopyProgressCallback(),
711 RecordStatusCallback());
712 base::RunLoop().RunUntilIdle();
713 779
714 EXPECT_EQ(base::File::FILE_OK, status());
715 EXPECT_TRUE(DirectoryExists("src/dir")); 780 EXPECT_TRUE(DirectoryExists("src/dir"));
716 EXPECT_TRUE(FileExists("src/dir/sub")); 781 EXPECT_TRUE(FileExists("src/dir/sub"));
717 782
718 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count()); 783 EXPECT_EQ(0, change_observer()->get_and_reset_create_directory_count());
719 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count()); 784 EXPECT_EQ(0, change_observer()->get_and_reset_remove_file_count());
720 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count()); 785 EXPECT_EQ(0, change_observer()->get_and_reset_create_file_from_count());
721 EXPECT_TRUE(change_observer()->HasNoChange()); 786 EXPECT_TRUE(change_observer()->HasNoChange());
722 } 787 }
723 788
724 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) { 789 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileSuccess) {
725 base::FilePath src_local_disk_file_path; 790 base::FilePath src_local_disk_file_path;
726 base::CreateTemporaryFile(&src_local_disk_file_path); 791 base::CreateTemporaryFile(&src_local_disk_file_path);
727 const char test_data[] = "foo"; 792 const char test_data[] = "foo";
728 int data_size = ARRAYSIZE_UNSAFE(test_data); 793 int data_size = ARRAYSIZE_UNSAFE(test_data);
729 base::WriteFile(src_local_disk_file_path, test_data, data_size); 794 base::WriteFile(src_local_disk_file_path, test_data, data_size);
730 795
731 FileSystemURL dest_dir(CreateDirectory("dest")); 796 FileSystemURL dest_dir(CreateDirectory("dest"));
732 797
733 int64 before_usage; 798 int64 before_usage;
734 GetUsageAndQuota(&before_usage, NULL); 799 GetUsageAndQuota(&before_usage, NULL);
735 800
736 // Check that the file copied and corresponding usage increased. 801 // Check that the file copied and corresponding usage increased.
737 operation_runner()->CopyInForeignFile(src_local_disk_file_path, 802 EXPECT_EQ(
738 URLForPath("dest/file"), 803 base::File::FILE_OK,
739 RecordStatusCallback()); 804 CopyInForeignFile(src_local_disk_file_path, URLForPath("dest/file")));
740 base::RunLoop().RunUntilIdle();
741 805
742 EXPECT_EQ(1, change_observer()->create_file_count()); 806 EXPECT_EQ(1, change_observer()->create_file_count());
743 EXPECT_EQ(base::File::FILE_OK, status());
744 EXPECT_TRUE(FileExists("dest/file")); 807 EXPECT_TRUE(FileExists("dest/file"));
745 int64 after_usage; 808 int64 after_usage;
746 GetUsageAndQuota(&after_usage, NULL); 809 GetUsageAndQuota(&after_usage, NULL);
747 EXPECT_GT(after_usage, before_usage); 810 EXPECT_GT(after_usage, before_usage);
748 811
749 // Compare contents of src and copied file. 812 // Compare contents of src and copied file.
750 char buffer[100]; 813 char buffer[100];
751 EXPECT_EQ(data_size, base::ReadFile(PlatformPath("dest/file"), 814 EXPECT_EQ(data_size, base::ReadFile(PlatformPath("dest/file"),
752 buffer, data_size)); 815 buffer, data_size));
753 for (int i = 0; i < data_size; ++i) 816 for (int i = 0; i < data_size; ++i)
754 EXPECT_EQ(test_data[i], buffer[i]); 817 EXPECT_EQ(test_data[i], buffer[i]);
755 } 818 }
756 819
757 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) { 820 TEST_F(FileSystemOperationImplTest, TestCopyInForeignFileFailureByQuota) {
758 base::FilePath src_local_disk_file_path; 821 base::FilePath src_local_disk_file_path;
759 base::CreateTemporaryFile(&src_local_disk_file_path); 822 base::CreateTemporaryFile(&src_local_disk_file_path);
760 const char test_data[] = "foo"; 823 const char test_data[] = "foo";
761 base::WriteFile(src_local_disk_file_path, test_data, 824 base::WriteFile(src_local_disk_file_path, test_data,
762 ARRAYSIZE_UNSAFE(test_data)); 825 ARRAYSIZE_UNSAFE(test_data));
763 826
764 FileSystemURL dest_dir(CreateDirectory("dest")); 827 FileSystemURL dest_dir(CreateDirectory("dest"));
765 828
766 GrantQuotaForCurrentUsage(); 829 GrantQuotaForCurrentUsage();
767 operation_runner()->CopyInForeignFile(src_local_disk_file_path, 830 EXPECT_EQ(
768 URLForPath("dest/file"), 831 base::File::FILE_ERROR_NO_SPACE,
769 RecordStatusCallback()); 832 CopyInForeignFile(src_local_disk_file_path, URLForPath("dest/file")));
770 base::RunLoop().RunUntilIdle();
771 833
772 EXPECT_FALSE(FileExists("dest/file")); 834 EXPECT_FALSE(FileExists("dest/file"));
773 EXPECT_EQ(0, change_observer()->create_file_count()); 835 EXPECT_EQ(0, change_observer()->create_file_count());
774 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status());
775 } 836 }
776 837
777 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) { 838 TEST_F(FileSystemOperationImplTest, TestCreateFileFailure) {
778 // Already existing file and exclusive true. 839 // Already existing file and exclusive true.
779 FileSystemURL file(CreateFile("file")); 840 FileSystemURL file(CreateFile("file"));
780 operation_runner()->CreateFile(file, true, RecordStatusCallback()); 841 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, CreateFile(file, true));
781 base::RunLoop().RunUntilIdle();
782 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status());
783 EXPECT_TRUE(change_observer()->HasNoChange()); 842 EXPECT_TRUE(change_observer()->HasNoChange());
784 } 843 }
785 844
786 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) { 845 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileExists) {
787 // Already existing file and exclusive false. 846 // Already existing file and exclusive false.
788 FileSystemURL file(CreateFile("file")); 847 FileSystemURL file(CreateFile("file"));
789 operation_runner()->CreateFile(file, false, RecordStatusCallback()); 848 EXPECT_EQ(base::File::FILE_OK, CreateFile(file, false));
790 base::RunLoop().RunUntilIdle();
791 EXPECT_EQ(base::File::FILE_OK, status());
792 EXPECT_TRUE(FileExists("file")); 849 EXPECT_TRUE(FileExists("file"));
793 850
794 // The file was already there; did nothing. 851 // The file was already there; did nothing.
795 EXPECT_TRUE(change_observer()->HasNoChange()); 852 EXPECT_TRUE(change_observer()->HasNoChange());
796 } 853 }
797 854
798 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) { 855 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessExclusive) {
799 // File doesn't exist but exclusive is true. 856 // File doesn't exist but exclusive is true.
800 operation_runner()->CreateFile(URLForPath("new"), true, 857 EXPECT_EQ(base::File::FILE_OK, CreateFile(URLForPath("new"), true));
801 RecordStatusCallback());
802 base::RunLoop().RunUntilIdle();
803 EXPECT_EQ(base::File::FILE_OK, status());
804 EXPECT_TRUE(FileExists("new")); 858 EXPECT_TRUE(FileExists("new"));
805 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 859 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
806 } 860 }
807 861
808 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) { 862 TEST_F(FileSystemOperationImplTest, TestCreateFileSuccessFileDoesntExist) {
809 // Non existing file. 863 // Non existing file.
810 operation_runner()->CreateFile(URLForPath("nonexistent"), false, 864 EXPECT_EQ(base::File::FILE_OK,
811 RecordStatusCallback()); 865 CreateFile(URLForPath("nonexistent"), false));
812 base::RunLoop().RunUntilIdle();
813 EXPECT_EQ(base::File::FILE_OK, status());
814 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count()); 866 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_count());
815 } 867 }
816 868
817 TEST_F(FileSystemOperationImplTest, 869 TEST_F(FileSystemOperationImplTest,
818 TestCreateDirFailureDestParentDoesntExist) { 870 TestCreateDirFailureDestParentDoesntExist) {
819 // Dest. parent path does not exist. 871 // Dest. parent path does not exist.
820 operation_runner()->CreateDirectory( 872 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
821 URLForPath("nonexistent/dir"), false, false, 873 CreateDirectory(URLForPath("nonexistent/dir"), false, false));
822 RecordStatusCallback());
823 base::RunLoop().RunUntilIdle();
824 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
825 EXPECT_TRUE(change_observer()->HasNoChange()); 874 EXPECT_TRUE(change_observer()->HasNoChange());
826 } 875 }
827 876
828 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) { 877 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureDirExists) {
829 // Exclusive and dir existing at path. 878 // Exclusive and dir existing at path.
830 FileSystemURL dir(CreateDirectory("dir")); 879 FileSystemURL dir(CreateDirectory("dir"));
831 operation_runner()->CreateDirectory(dir, true, false, 880 EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
832 RecordStatusCallback()); 881 CreateDirectory(dir, true, false));
833 base::RunLoop().RunUntilIdle();
834 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status());
835 EXPECT_TRUE(change_observer()->HasNoChange()); 882 EXPECT_TRUE(change_observer()->HasNoChange());
836 } 883 }
837 884
838 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) { 885 TEST_F(FileSystemOperationImplTest, TestCreateDirFailureFileExists) {
839 // Exclusive true and file existing at path. 886 // Exclusive true and file existing at path.
840 FileSystemURL file(CreateFile("file")); 887 FileSystemURL file(CreateFile("file"));
841 operation_runner()->CreateDirectory(file, true, false, 888 EXPECT_EQ(base::File::FILE_ERROR_EXISTS,
842 RecordStatusCallback()); 889 CreateDirectory(file, true, false));
843 base::RunLoop().RunUntilIdle();
844 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, status());
845 EXPECT_TRUE(change_observer()->HasNoChange()); 890 EXPECT_TRUE(change_observer()->HasNoChange());
846 } 891 }
847 892
848 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) { 893 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccess) {
849 // Dir exists and exclusive is false. 894 // Dir exists and exclusive is false.
850 FileSystemURL dir(CreateDirectory("dir")); 895 FileSystemURL dir(CreateDirectory("dir"));
851 operation_runner()->CreateDirectory(dir, false, false, 896 EXPECT_EQ(base::File::FILE_OK, CreateDirectory(dir, false, false));
852 RecordStatusCallback());
853 base::RunLoop().RunUntilIdle();
854 EXPECT_EQ(base::File::FILE_OK, status());
855 EXPECT_TRUE(change_observer()->HasNoChange()); 897 EXPECT_TRUE(change_observer()->HasNoChange());
856 898
857 // Dir doesn't exist. 899 // Dir doesn't exist.
858 operation_runner()->CreateDirectory(URLForPath("new"), false, false, 900 EXPECT_EQ(base::File::FILE_OK,
859 RecordStatusCallback()); 901 CreateDirectory(URLForPath("new"), false, false));
860 base::RunLoop().RunUntilIdle();
861 EXPECT_EQ(base::File::FILE_OK, status());
862 EXPECT_TRUE(DirectoryExists("new")); 902 EXPECT_TRUE(DirectoryExists("new"));
863 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 903 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
864 } 904 }
865 905
866 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) { 906 TEST_F(FileSystemOperationImplTest, TestCreateDirSuccessExclusive) {
867 // Dir doesn't exist. 907 // Dir doesn't exist.
868 operation_runner()->CreateDirectory(URLForPath("new"), true, false, 908 EXPECT_EQ(base::File::FILE_OK,
869 RecordStatusCallback()); 909 CreateDirectory(URLForPath("new"), true, false));
870 base::RunLoop().RunUntilIdle();
871 EXPECT_EQ(base::File::FILE_OK, status());
872 EXPECT_TRUE(DirectoryExists("new")); 910 EXPECT_TRUE(DirectoryExists("new"));
873 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 911 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
874 EXPECT_TRUE(change_observer()->HasNoChange()); 912 EXPECT_TRUE(change_observer()->HasNoChange());
875 } 913 }
876 914
877 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { 915 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) {
878 operation_runner()->GetMetadata(URLForPath("nonexistent"), 916 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
879 RecordMetadataCallback()); 917 GetMetadata(URLForPath("nonexistent")));
880 base::RunLoop().RunUntilIdle();
881 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
882 918
883 operation_runner()->FileExists(URLForPath("nonexistent"), 919 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
884 RecordStatusCallback()); 920 FileExists(URLForPath("nonexistent")));
885 base::RunLoop().RunUntilIdle();
886 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
887 921
888 operation_runner()->DirectoryExists(URLForPath("nonexistent"), 922 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
889 RecordStatusCallback()); 923 DirectoryExists(URLForPath("nonexistent")));
890 base::RunLoop().RunUntilIdle();
891 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
892 EXPECT_TRUE(change_observer()->HasNoChange()); 924 EXPECT_TRUE(change_observer()->HasNoChange());
893 } 925 }
894 926
895 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { 927 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) {
896 FileSystemURL dir(CreateDirectory("dir")); 928 FileSystemURL dir(CreateDirectory("dir"));
897 FileSystemURL file(CreateFile("dir/file")); 929 FileSystemURL file(CreateFile("dir/file"));
898 int read_access = 0; 930 int read_access = 0;
899 931
900 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); 932 EXPECT_EQ(base::File::FILE_OK, DirectoryExists(dir));
901 base::RunLoop().RunUntilIdle();
902 EXPECT_EQ(base::File::FILE_OK, status());
903 ++read_access; 933 ++read_access;
904 934
905 operation_runner()->GetMetadata(dir, RecordMetadataCallback()); 935 EXPECT_EQ(base::File::FILE_OK, GetMetadata(dir));
906 base::RunLoop().RunUntilIdle();
907 EXPECT_EQ(base::File::FILE_OK, status());
908 EXPECT_TRUE(info().is_directory); 936 EXPECT_TRUE(info().is_directory);
909 ++read_access; 937 ++read_access;
910 938
911 operation_runner()->FileExists(file, RecordStatusCallback()); 939 EXPECT_EQ(base::File::FILE_OK, FileExists(file));
912 base::RunLoop().RunUntilIdle();
913 EXPECT_EQ(base::File::FILE_OK, status());
914 ++read_access; 940 ++read_access;
915 941
916 operation_runner()->GetMetadata(file, RecordMetadataCallback()); 942 EXPECT_EQ(base::File::FILE_OK, GetMetadata(file));
917 base::RunLoop().RunUntilIdle();
918 EXPECT_EQ(base::File::FILE_OK, status());
919 EXPECT_FALSE(info().is_directory); 943 EXPECT_FALSE(info().is_directory);
920 ++read_access; 944 ++read_access;
921 945
922 EXPECT_EQ(read_access, 946 EXPECT_EQ(read_access,
923 quota_manager_proxy()->notify_storage_accessed_count()); 947 quota_manager_proxy()->notify_storage_accessed_count());
924 EXPECT_TRUE(change_observer()->HasNoChange()); 948 EXPECT_TRUE(change_observer()->HasNoChange());
925 } 949 }
926 950
927 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { 951 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) {
928 FileSystemURL dir(CreateDirectory("dir")); 952 FileSystemURL dir(CreateDirectory("dir"));
929 operation_runner()->FileExists(dir, RecordStatusCallback()); 953 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, FileExists(dir));
930 base::RunLoop().RunUntilIdle();
931 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, status());
932 954
933 FileSystemURL file(CreateFile("file")); 955 FileSystemURL file(CreateFile("file"));
934 operation_runner()->DirectoryExists(file, RecordStatusCallback()); 956 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, DirectoryExists(file));
935 base::RunLoop().RunUntilIdle();
936 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status());
937 } 957 }
938 958
939 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) { 959 TEST_F(FileSystemOperationImplTest, TestReadDirFailure) {
940 // Path doesn't exist 960 // Path doesn't exist
941 operation_runner()->ReadDirectory(URLForPath("nonexistent"), 961 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
942 RecordReadDirectoryCallback()); 962 ReadDirectory(URLForPath("nonexistent")));
943 base::RunLoop().RunUntilIdle();
944 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
945 963
946 // File exists. 964 // File exists.
947 FileSystemURL file(CreateFile("file")); 965 FileSystemURL file(CreateFile("file"));
948 operation_runner()->ReadDirectory(file, RecordReadDirectoryCallback()); 966 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, ReadDirectory(file));
949 base::RunLoop().RunUntilIdle();
950 EXPECT_EQ(base::File::FILE_ERROR_NOT_A_DIRECTORY, status());
951 EXPECT_TRUE(change_observer()->HasNoChange()); 967 EXPECT_TRUE(change_observer()->HasNoChange());
952 } 968 }
953 969
954 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) { 970 TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) {
955 // parent_dir 971 // parent_dir
956 // | | 972 // | |
957 // child_dir child_file 973 // child_dir child_file
958 // Verify reading parent_dir. 974 // Verify reading parent_dir.
959 FileSystemURL parent_dir(CreateDirectory("dir")); 975 FileSystemURL parent_dir(CreateDirectory("dir"));
960 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); 976 FileSystemURL child_dir(CreateDirectory("dir/child_dir"));
961 FileSystemURL child_file(CreateFile("dir/child_file")); 977 FileSystemURL child_file(CreateFile("dir/child_file"));
962 978
963 operation_runner()->ReadDirectory(parent_dir, RecordReadDirectoryCallback()); 979 EXPECT_EQ(base::File::FILE_OK, ReadDirectory(parent_dir));
964 base::RunLoop().RunUntilIdle();
965 EXPECT_EQ(base::File::FILE_OK, status());
966 EXPECT_EQ(2u, entries().size()); 980 EXPECT_EQ(2u, entries().size());
967 981
968 for (size_t i = 0; i < entries().size(); ++i) { 982 for (size_t i = 0; i < entries().size(); ++i) {
969 if (entries()[i].is_directory) 983 if (entries()[i].is_directory)
970 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name); 984 EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name);
971 else 985 else
972 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name); 986 EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name);
973 } 987 }
974 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); 988 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
975 EXPECT_TRUE(change_observer()->HasNoChange()); 989 EXPECT_TRUE(change_observer()->HasNoChange());
976 } 990 }
977 991
978 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) { 992 TEST_F(FileSystemOperationImplTest, TestRemoveFailure) {
979 // Path doesn't exist. 993 // Path doesn't exist.
980 operation_runner()->Remove(URLForPath("nonexistent"), false /* recursive */, 994 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
981 RecordStatusCallback()); 995 Remove(URLForPath("nonexistent"), false /* recursive */));
982 base::RunLoop().RunUntilIdle();
983 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, status());
984 996
985 // It's an error to try to remove a non-empty directory if recursive flag 997 // It's an error to try to remove a non-empty directory if recursive flag
986 // is false. 998 // is false.
987 // parent_dir 999 // parent_dir
988 // | | 1000 // | |
989 // child_dir child_file 1001 // child_dir child_file
990 // Verify deleting parent_dir. 1002 // Verify deleting parent_dir.
991 FileSystemURL parent_dir(CreateDirectory("dir")); 1003 FileSystemURL parent_dir(CreateDirectory("dir"));
992 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); 1004 FileSystemURL child_dir(CreateDirectory("dir/child_dir"));
993 FileSystemURL child_file(CreateFile("dir/child_file")); 1005 FileSystemURL child_file(CreateFile("dir/child_file"));
994 1006
995 operation_runner()->Remove(parent_dir, false /* recursive */, 1007 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY,
996 RecordStatusCallback()); 1008 Remove(parent_dir, false /* recursive */));
997 base::RunLoop().RunUntilIdle();
998 EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, status());
999 EXPECT_TRUE(change_observer()->HasNoChange()); 1009 EXPECT_TRUE(change_observer()->HasNoChange());
1000 } 1010 }
1001 1011
1002 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) { 1012 TEST_F(FileSystemOperationImplTest, TestRemoveSuccess) {
1003 FileSystemURL empty_dir(CreateDirectory("empty_dir")); 1013 FileSystemURL empty_dir(CreateDirectory("empty_dir"));
1004 EXPECT_TRUE(DirectoryExists("empty_dir")); 1014 EXPECT_TRUE(DirectoryExists("empty_dir"));
1005 operation_runner()->Remove(empty_dir, false /* recursive */, 1015 EXPECT_EQ(base::File::FILE_OK, Remove(empty_dir, false /* recursive */));
1006 RecordStatusCallback());
1007 base::RunLoop().RunUntilIdle();
1008 EXPECT_EQ(base::File::FILE_OK, status());
1009 EXPECT_FALSE(DirectoryExists("empty_dir")); 1016 EXPECT_FALSE(DirectoryExists("empty_dir"));
1010 1017
1011 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 1018 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
1012 EXPECT_TRUE(change_observer()->HasNoChange()); 1019 EXPECT_TRUE(change_observer()->HasNoChange());
1013 } 1020 }
1014 1021
1015 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) { 1022 TEST_F(FileSystemOperationImplTest, TestRemoveSuccessRecursive) {
1016 // Removing a non-empty directory with recursive flag == true should be ok. 1023 // Removing a non-empty directory with recursive flag == true should be ok.
1017 // parent_dir 1024 // parent_dir
1018 // | | 1025 // | |
1019 // child_dir child_files 1026 // child_dir child_files
1020 // | 1027 // |
1021 // child_files 1028 // child_files
1022 // 1029 //
1023 // Verify deleting parent_dir. 1030 // Verify deleting parent_dir.
1024 FileSystemURL parent_dir(CreateDirectory("dir")); 1031 FileSystemURL parent_dir(CreateDirectory("dir"));
1025 for (int i = 0; i < 8; ++i) 1032 for (int i = 0; i < 8; ++i)
1026 CreateFile(base::StringPrintf("dir/file-%d", i)); 1033 CreateFile(base::StringPrintf("dir/file-%d", i));
1027 FileSystemURL child_dir(CreateDirectory("dir/child_dir")); 1034 FileSystemURL child_dir(CreateDirectory("dir/child_dir"));
1028 for (int i = 0; i < 8; ++i) 1035 for (int i = 0; i < 8; ++i)
1029 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i)); 1036 CreateFile(base::StringPrintf("dir/child_dir/file-%d", i));
1030 1037
1031 operation_runner()->Remove(parent_dir, true /* recursive */, 1038 EXPECT_EQ(base::File::FILE_OK, Remove(parent_dir, true /* recursive */));
1032 RecordStatusCallback());
1033 base::RunLoop().RunUntilIdle();
1034 EXPECT_EQ(base::File::FILE_OK, status());
1035 EXPECT_FALSE(DirectoryExists("parent_dir")); 1039 EXPECT_FALSE(DirectoryExists("parent_dir"));
1036 1040
1037 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); 1041 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count());
1038 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count()); 1042 EXPECT_EQ(16, change_observer()->get_and_reset_remove_file_count());
1039 EXPECT_TRUE(change_observer()->HasNoChange()); 1043 EXPECT_TRUE(change_observer()->HasNoChange());
1040 } 1044 }
1041 1045
1042 TEST_F(FileSystemOperationImplTest, TestTruncate) { 1046 TEST_F(FileSystemOperationImplTest, TestTruncate) {
1043 FileSystemURL file(CreateFile("file")); 1047 FileSystemURL file(CreateFile("file"));
1044 base::FilePath platform_path = PlatformPath("file"); 1048 base::FilePath platform_path = PlatformPath("file");
1045 1049
1046 char test_data[] = "test data"; 1050 char test_data[] = "test data";
1047 int data_size = static_cast<int>(sizeof(test_data)); 1051 int data_size = static_cast<int>(sizeof(test_data));
1048 EXPECT_EQ(data_size, 1052 EXPECT_EQ(data_size,
1049 base::WriteFile(platform_path, test_data, data_size)); 1053 base::WriteFile(platform_path, test_data, data_size));
1050 1054
1051 // Check that its length is the size of the data written. 1055 // Check that its length is the size of the data written.
1052 operation_runner()->GetMetadata(file, RecordMetadataCallback()); 1056 EXPECT_EQ(base::File::FILE_OK, GetMetadata(file));
1053 base::RunLoop().RunUntilIdle();
1054 EXPECT_EQ(base::File::FILE_OK, status());
1055 EXPECT_FALSE(info().is_directory); 1057 EXPECT_FALSE(info().is_directory);
1056 EXPECT_EQ(data_size, info().size); 1058 EXPECT_EQ(data_size, info().size);
1057 1059
1058 // Extend the file by truncating it. 1060 // Extend the file by truncating it.
1059 int length = 17; 1061 int length = 17;
1060 operation_runner()->Truncate(file, length, RecordStatusCallback()); 1062 EXPECT_EQ(base::File::FILE_OK, Truncate(file, length));
1061 base::RunLoop().RunUntilIdle();
1062 EXPECT_EQ(base::File::FILE_OK, status());
1063 1063
1064 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 1064 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
1065 EXPECT_TRUE(change_observer()->HasNoChange()); 1065 EXPECT_TRUE(change_observer()->HasNoChange());
1066 1066
1067 // Check that its length is now 17 and that it's all zeroes after the test 1067 // Check that its length is now 17 and that it's all zeroes after the test
1068 // data. 1068 // data.
1069 EXPECT_EQ(length, GetFileSize("file")); 1069 EXPECT_EQ(length, GetFileSize("file"));
1070 char data[100]; 1070 char data[100];
1071 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); 1071 EXPECT_EQ(length, base::ReadFile(platform_path, data, length));
1072 for (int i = 0; i < length; ++i) { 1072 for (int i = 0; i < length; ++i) {
1073 if (i < static_cast<int>(sizeof(test_data))) 1073 if (i < static_cast<int>(sizeof(test_data)))
1074 EXPECT_EQ(test_data[i], data[i]); 1074 EXPECT_EQ(test_data[i], data[i]);
1075 else 1075 else
1076 EXPECT_EQ(0, data[i]); 1076 EXPECT_EQ(0, data[i]);
1077 } 1077 }
1078 1078
1079 // Shorten the file by truncating it. 1079 // Shorten the file by truncating it.
1080 length = 3; 1080 length = 3;
1081 operation_runner()->Truncate(file, length, RecordStatusCallback()); 1081 EXPECT_EQ(base::File::FILE_OK, Truncate(file, length));
1082 base::RunLoop().RunUntilIdle();
1083 EXPECT_EQ(base::File::FILE_OK, status());
1084 1082
1085 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 1083 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
1086 EXPECT_TRUE(change_observer()->HasNoChange()); 1084 EXPECT_TRUE(change_observer()->HasNoChange());
1087 1085
1088 // Check that its length is now 3 and that it contains only bits of test data. 1086 // Check that its length is now 3 and that it contains only bits of test data.
1089 EXPECT_EQ(length, GetFileSize("file")); 1087 EXPECT_EQ(length, GetFileSize("file"));
1090 EXPECT_EQ(length, base::ReadFile(platform_path, data, length)); 1088 EXPECT_EQ(length, base::ReadFile(platform_path, data, length));
1091 for (int i = 0; i < length; ++i) 1089 for (int i = 0; i < length; ++i)
1092 EXPECT_EQ(test_data[i], data[i]); 1090 EXPECT_EQ(test_data[i], data[i]);
1093 1091
1094 // Truncate is not a 'read' access. (Here expected access count is 1 1092 // Truncate is not a 'read' access. (Here expected access count is 1
1095 // since we made 1 read access for GetMetadata.) 1093 // since we made 1 read access for GetMetadata.)
1096 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); 1094 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
1097 } 1095 }
1098 1096
1099 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) { 1097 TEST_F(FileSystemOperationImplTest, TestTruncateFailureByQuota) {
1100 FileSystemURL dir(CreateDirectory("dir")); 1098 FileSystemURL dir(CreateDirectory("dir"));
1101 FileSystemURL file(CreateFile("dir/file")); 1099 FileSystemURL file(CreateFile("dir/file"));
1102 1100
1103 GrantQuotaForCurrentUsage(); 1101 GrantQuotaForCurrentUsage();
1104 AddQuota(10); 1102 AddQuota(10);
1105 1103
1106 operation_runner()->Truncate(file, 10, RecordStatusCallback()); 1104 EXPECT_EQ(base::File::FILE_OK, Truncate(file, 10));
1107 base::RunLoop().RunUntilIdle();
1108 EXPECT_EQ(base::File::FILE_OK, status());
1109 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 1105 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
1110 EXPECT_TRUE(change_observer()->HasNoChange()); 1106 EXPECT_TRUE(change_observer()->HasNoChange());
1111 1107
1112 EXPECT_EQ(10, GetFileSize("dir/file")); 1108 EXPECT_EQ(10, GetFileSize("dir/file"));
1113 1109
1114 operation_runner()->Truncate(file, 11, RecordStatusCallback()); 1110 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, Truncate(file, 11));
1115 base::RunLoop().RunUntilIdle();
1116 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, status());
1117 EXPECT_TRUE(change_observer()->HasNoChange()); 1111 EXPECT_TRUE(change_observer()->HasNoChange());
1118 1112
1119 EXPECT_EQ(10, GetFileSize("dir/file")); 1113 EXPECT_EQ(10, GetFileSize("dir/file"));
1120 } 1114 }
1121 1115
1122 TEST_F(FileSystemOperationImplTest, TestTouchFile) { 1116 TEST_F(FileSystemOperationImplTest, TestTouchFile) {
1123 FileSystemURL file(CreateFile("file")); 1117 FileSystemURL file(CreateFile("file"));
1124 base::FilePath platform_path = PlatformPath("file"); 1118 base::FilePath platform_path = PlatformPath("file");
1125 1119
1126 base::File::Info info; 1120 base::File::Info info;
1127 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); 1121 EXPECT_TRUE(base::GetFileInfo(platform_path, &info));
1128 EXPECT_FALSE(info.is_directory); 1122 EXPECT_FALSE(info.is_directory);
1129 EXPECT_EQ(0, info.size); 1123 EXPECT_EQ(0, info.size);
1130 const base::Time last_modified = info.last_modified; 1124 const base::Time last_modified = info.last_modified;
1131 const base::Time last_accessed = info.last_accessed; 1125 const base::Time last_accessed = info.last_accessed;
1132 1126
1133 const base::Time new_modified_time = base::Time::UnixEpoch(); 1127 const base::Time new_modified_time = base::Time::UnixEpoch();
1134 const base::Time new_accessed_time = new_modified_time + 1128 const base::Time new_accessed_time = new_modified_time +
1135 base::TimeDelta::FromHours(77); 1129 base::TimeDelta::FromHours(77);
1136 ASSERT_NE(last_modified, new_modified_time); 1130 ASSERT_NE(last_modified, new_modified_time);
1137 ASSERT_NE(last_accessed, new_accessed_time); 1131 ASSERT_NE(last_accessed, new_accessed_time);
1138 1132
1139 operation_runner()->TouchFile(file, new_accessed_time, new_modified_time, 1133 EXPECT_EQ(base::File::FILE_OK,
1140 RecordStatusCallback()); 1134 TouchFile(file, new_accessed_time, new_modified_time));
1141 base::RunLoop().RunUntilIdle();
1142 EXPECT_EQ(base::File::FILE_OK, status());
1143 EXPECT_TRUE(change_observer()->HasNoChange()); 1135 EXPECT_TRUE(change_observer()->HasNoChange());
1144 1136
1145 EXPECT_TRUE(base::GetFileInfo(platform_path, &info)); 1137 EXPECT_TRUE(base::GetFileInfo(platform_path, &info));
1146 // We compare as time_t here to lower our resolution, to avoid false 1138 // We compare as time_t here to lower our resolution, to avoid false
1147 // negatives caused by conversion to the local filesystem's native 1139 // negatives caused by conversion to the local filesystem's native
1148 // representation and back. 1140 // representation and back.
1149 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT()); 1141 EXPECT_EQ(new_modified_time.ToTimeT(), info.last_modified.ToTimeT());
1150 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT()); 1142 EXPECT_EQ(new_accessed_time.ToTimeT(), info.last_accessed.ToTimeT());
1151 } 1143 }
1152 1144
1153 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) { 1145 TEST_F(FileSystemOperationImplTest, TestCreateSnapshotFile) {
1154 FileSystemURL dir(CreateDirectory("dir")); 1146 FileSystemURL dir(CreateDirectory("dir"));
1155 1147
1156 // Create a file for the testing. 1148 // Create a file for the testing.
1157 operation_runner()->DirectoryExists(dir, RecordStatusCallback()); 1149 EXPECT_EQ(base::File::FILE_OK, DirectoryExists(dir));
1158 FileSystemURL file(CreateFile("dir/file")); 1150 FileSystemURL file(CreateFile("dir/file"));
1159 operation_runner()->FileExists(file, RecordStatusCallback()); 1151 EXPECT_EQ(base::File::FILE_OK, FileExists(file));
1160 base::RunLoop().RunUntilIdle();
1161 EXPECT_EQ(base::File::FILE_OK, status());
1162 1152
1163 // See if we can get a 'snapshot' file info for the file. 1153 // See if we can get a 'snapshot' file info for the file.
1164 // Since FileSystemOperationImpl assumes the file exists in the local 1154 // Since FileSystemOperationImpl assumes the file exists in the local
1165 // directory it should just returns the same metadata and platform_path 1155 // directory it should just returns the same metadata and platform_path
1166 // as the file itself. 1156 // as the file itself.
1167 operation_runner()->CreateSnapshotFile(file, RecordSnapshotFileCallback()); 1157 EXPECT_EQ(base::File::FILE_OK, CreateSnapshotFile(file));
1168 base::RunLoop().RunUntilIdle();
1169 EXPECT_EQ(base::File::FILE_OK, status());
1170 EXPECT_FALSE(info().is_directory); 1158 EXPECT_FALSE(info().is_directory);
1171 EXPECT_EQ(PlatformPath("dir/file"), path()); 1159 EXPECT_EQ(PlatformPath("dir/file"), path());
1172 EXPECT_TRUE(change_observer()->HasNoChange()); 1160 EXPECT_TRUE(change_observer()->HasNoChange());
1173 1161
1174 // The FileSystemOpration implementation does not create a 1162 // The FileSystemOpration implementation does not create a
1175 // shareable file reference. 1163 // shareable file reference.
1176 EXPECT_EQ(NULL, shareable_file_ref()); 1164 EXPECT_EQ(NULL, shareable_file_ref());
1177 } 1165 }
1178 1166
1179 TEST_F(FileSystemOperationImplTest, 1167 TEST_F(FileSystemOperationImplTest,
1180 TestMoveSuccessSrcDirRecursiveWithQuota) { 1168 TestMoveSuccessSrcDirRecursiveWithQuota) {
1181 FileSystemURL src(CreateDirectory("src")); 1169 FileSystemURL src(CreateDirectory("src"));
1182 int src_path_cost = GetUsage(); 1170 int src_path_cost = GetUsage();
1183 1171
1184 FileSystemURL dest(CreateDirectory("dest")); 1172 FileSystemURL dest(CreateDirectory("dest"));
1185 FileSystemURL child_file1(CreateFile("src/file1")); 1173 FileSystemURL child_file1(CreateFile("src/file1"));
1186 FileSystemURL child_file2(CreateFile("src/file2")); 1174 FileSystemURL child_file2(CreateFile("src/file2"));
1187 FileSystemURL child_dir(CreateDirectory("src/dir")); 1175 FileSystemURL child_dir(CreateDirectory("src/dir"));
1188 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); 1176 FileSystemURL grandchild_file1(CreateFile("src/dir/file1"));
1189 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); 1177 FileSystemURL grandchild_file2(CreateFile("src/dir/file2"));
1190 1178
1191 int total_path_cost = GetUsage(); 1179 int total_path_cost = GetUsage();
1192 EXPECT_EQ(0, GetDataSizeOnDisk()); 1180 EXPECT_EQ(0, GetDataSizeOnDisk());
1193 1181
1194 operation_runner()->Truncate( 1182 EXPECT_EQ(base::File::FILE_OK, Truncate(child_file1, 5000));
1195 child_file1, 5000, 1183 EXPECT_EQ(base::File::FILE_OK, Truncate(child_file2, 400));
1196 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); 1184 EXPECT_EQ(base::File::FILE_OK, Truncate(grandchild_file1, 30));
1197 operation_runner()->Truncate( 1185 EXPECT_EQ(base::File::FILE_OK, Truncate(grandchild_file2, 2));
1198 child_file2, 400,
1199 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1200 operation_runner()->Truncate(
1201 grandchild_file1, 30,
1202 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1203 operation_runner()->Truncate(
1204 grandchild_file2, 2,
1205 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1206 base::RunLoop().RunUntilIdle();
1207 1186
1208 const int64 all_file_size = 5000 + 400 + 30 + 2; 1187 const int64 all_file_size = 5000 + 400 + 30 + 2;
1209 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); 1188 EXPECT_EQ(all_file_size, GetDataSizeOnDisk());
1210 EXPECT_EQ(all_file_size + total_path_cost, GetUsage()); 1189 EXPECT_EQ(all_file_size + total_path_cost, GetUsage());
1211 1190
1212 operation_runner()->Move( 1191 EXPECT_EQ(base::File::FILE_OK,
1213 src, dest, FileSystemOperation::OPTION_NONE, 1192 Move(src, dest, FileSystemOperation::OPTION_NONE));
1214 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1215 base::RunLoop().RunUntilIdle();
1216 1193
1217 EXPECT_FALSE(DirectoryExists("src/dir")); 1194 EXPECT_FALSE(DirectoryExists("src/dir"));
1218 EXPECT_FALSE(FileExists("src/dir/file2")); 1195 EXPECT_FALSE(FileExists("src/dir/file2"));
1219 EXPECT_TRUE(DirectoryExists("dest/dir")); 1196 EXPECT_TRUE(DirectoryExists("dest/dir"));
1220 EXPECT_TRUE(FileExists("dest/dir/file2")); 1197 EXPECT_TRUE(FileExists("dest/dir/file2"));
1221 1198
1222 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); 1199 EXPECT_EQ(all_file_size, GetDataSizeOnDisk());
1223 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost, 1200 EXPECT_EQ(all_file_size + total_path_cost - src_path_cost,
1224 GetUsage()); 1201 GetUsage());
1225 } 1202 }
(...skipping 11 matching lines...) Expand all
1237 int64 child_path_cost = GetUsage() - usage; 1214 int64 child_path_cost = GetUsage() - usage;
1238 usage += child_path_cost; 1215 usage += child_path_cost;
1239 1216
1240 FileSystemURL grandchild_file1(CreateFile("src/dir/file1")); 1217 FileSystemURL grandchild_file1(CreateFile("src/dir/file1"));
1241 FileSystemURL grandchild_file2(CreateFile("src/dir/file2")); 1218 FileSystemURL grandchild_file2(CreateFile("src/dir/file2"));
1242 int64 total_path_cost = GetUsage(); 1219 int64 total_path_cost = GetUsage();
1243 int64 grandchild_path_cost = total_path_cost - usage; 1220 int64 grandchild_path_cost = total_path_cost - usage;
1244 1221
1245 EXPECT_EQ(0, GetDataSizeOnDisk()); 1222 EXPECT_EQ(0, GetDataSizeOnDisk());
1246 1223
1247 operation_runner()->Truncate( 1224 EXPECT_EQ(base::File::FILE_OK, Truncate(child_file1, 8000));
1248 child_file1, 8000, 1225 EXPECT_EQ(base::File::FILE_OK, Truncate(child_file2, 700));
1249 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK)); 1226 EXPECT_EQ(base::File::FILE_OK, Truncate(grandchild_file1, 60));
1250 operation_runner()->Truncate( 1227 EXPECT_EQ(base::File::FILE_OK, Truncate(grandchild_file2, 5));
1251 child_file2, 700,
1252 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1253 operation_runner()->Truncate(
1254 grandchild_file1, 60,
1255 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1256 operation_runner()->Truncate(
1257 grandchild_file2, 5,
1258 base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
1259 base::RunLoop().RunUntilIdle();
1260 1228
1261 const int64 child_file_size = 8000 + 700; 1229 const int64 child_file_size = 8000 + 700;
1262 const int64 grandchild_file_size = 60 + 5; 1230 const int64 grandchild_file_size = 60 + 5;
1263 const int64 all_file_size = child_file_size + grandchild_file_size; 1231 const int64 all_file_size = child_file_size + grandchild_file_size;
1264 int64 expected_usage = all_file_size + total_path_cost; 1232 int64 expected_usage = all_file_size + total_path_cost;
1265 1233
1266 usage = GetUsage(); 1234 usage = GetUsage();
1267 EXPECT_EQ(all_file_size, GetDataSizeOnDisk()); 1235 EXPECT_EQ(all_file_size, GetDataSizeOnDisk());
1268 EXPECT_EQ(expected_usage, usage); 1236 EXPECT_EQ(expected_usage, usage);
1269 1237
1270 { 1238 EXPECT_EQ(base::File::FILE_OK,
1271 base::RunLoop run_loop; 1239 Copy(src, dest1, FileSystemOperation::OPTION_NONE));
1272 // Copy src to dest1.
1273 operation_runner()->Copy(src,
1274 dest1,
1275 FileSystemOperation::OPTION_NONE,
1276 FileSystemOperationRunner::CopyProgressCallback(),
1277 base::Bind(&AssertFileErrorEqWithClosure,
1278 FROM_HERE,
1279 base::File::FILE_OK,
1280 run_loop.QuitClosure()));
1281 run_loop.Run();
1282 }
1283 1240
1284 expected_usage += all_file_size + child_path_cost + grandchild_path_cost; 1241 expected_usage += all_file_size + child_path_cost + grandchild_path_cost;
1285 EXPECT_TRUE(DirectoryExists("src/dir")); 1242 EXPECT_TRUE(DirectoryExists("src/dir"));
1286 EXPECT_TRUE(FileExists("src/dir/file2")); 1243 EXPECT_TRUE(FileExists("src/dir/file2"));
1287 EXPECT_TRUE(DirectoryExists("dest1/dir")); 1244 EXPECT_TRUE(DirectoryExists("dest1/dir"));
1288 EXPECT_TRUE(FileExists("dest1/dir/file2")); 1245 EXPECT_TRUE(FileExists("dest1/dir/file2"));
1289 1246
1290 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk()); 1247 EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk());
1291 EXPECT_EQ(expected_usage, GetUsage()); 1248 EXPECT_EQ(expected_usage, GetUsage());
1292 1249
1293 { 1250 EXPECT_EQ(base::File::FILE_OK,
1294 base::RunLoop run_loop; 1251 Copy(child_dir, dest2, FileSystemOperation::OPTION_NONE));
1295 // Copy src/dir to dest2.
1296 operation_runner()->Copy(child_dir,
1297 dest2,
1298 FileSystemOperation::OPTION_NONE,
1299 FileSystemOperationRunner::CopyProgressCallback(),
1300 base::Bind(&AssertFileErrorEqWithClosure,
1301 FROM_HERE,
1302 base::File::FILE_OK,
1303 run_loop.QuitClosure()));
1304 run_loop.Run();
1305 }
1306 1252
1307 expected_usage += grandchild_file_size + grandchild_path_cost; 1253 expected_usage += grandchild_file_size + grandchild_path_cost;
1308 usage = GetUsage(); 1254 usage = GetUsage();
1309 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, 1255 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size,
1310 GetDataSizeOnDisk()); 1256 GetDataSizeOnDisk());
1311 EXPECT_EQ(expected_usage, usage); 1257 EXPECT_EQ(expected_usage, usage);
1312 } 1258 }
1313 1259
1314 TEST_F(FileSystemOperationImplTest, 1260 TEST_F(FileSystemOperationImplTest,
1315 TestCopySuccessSrcFileWithDifferentFileSize) { 1261 TestCopySuccessSrcFileWithDifferentFileSize) {
1316 FileSystemURL src_file(CreateFile("src")); 1262 FileSystemURL src_file(CreateFile("src"));
1317 FileSystemURL dest_file(CreateFile("dest")); 1263 FileSystemURL dest_file(CreateFile("dest"));
1318 1264
1319 { 1265 EXPECT_EQ(base::File::FILE_OK, Truncate(dest_file, 6));
1320 base::RunLoop run_loop; 1266 EXPECT_EQ(base::File::FILE_OK,
1321 operation_runner()->Truncate( 1267 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE));
1322 dest_file, 6,
1323 base::Bind(&AssertFileErrorEqWithClosure,
1324 FROM_HERE,
1325 base::File::FILE_OK,
1326 run_loop.QuitClosure()));
1327 run_loop.Run();
1328 }
1329
1330 {
1331 base::RunLoop run_loop;
1332 operation_runner()->Copy(
1333 src_file, dest_file, FileSystemOperation::OPTION_NONE,
1334 FileSystemOperationRunner::CopyProgressCallback(),
1335 base::Bind(&AssertFileErrorEqWithClosure,
1336 FROM_HERE,
1337 base::File::FILE_OK,
1338 run_loop.QuitClosure()));
1339 run_loop.Run();
1340 }
1341 EXPECT_EQ(0, GetFileSize("dest")); 1268 EXPECT_EQ(0, GetFileSize("dest"));
1342 } 1269 }
1343 1270
1344 } // namespace content 1271 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698