OLD | NEW |
---|---|
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 "storage/browser/fileapi/file_system_operation_impl.h" | 5 #include "storage/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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "content/browser/fileapi/mock_file_change_observer.h" | 15 #include "content/browser/fileapi/mock_file_change_observer.h" |
16 #include "content/browser/fileapi/mock_file_update_observer.h" | |
16 #include "content/browser/quota/mock_quota_manager.h" | 17 #include "content/browser/quota/mock_quota_manager.h" |
17 #include "content/browser/quota/mock_quota_manager_proxy.h" | 18 #include "content/browser/quota/mock_quota_manager_proxy.h" |
18 #include "content/public/test/async_file_test_helper.h" | 19 #include "content/public/test/async_file_test_helper.h" |
19 #include "content/public/test/sandbox_file_system_test_helper.h" | 20 #include "content/public/test/sandbox_file_system_test_helper.h" |
20 #include "storage/browser/fileapi/file_system_context.h" | 21 #include "storage/browser/fileapi/file_system_context.h" |
21 #include "storage/browser/fileapi/file_system_file_util.h" | 22 #include "storage/browser/fileapi/file_system_file_util.h" |
22 #include "storage/browser/fileapi/file_system_operation_context.h" | 23 #include "storage/browser/fileapi/file_system_operation_context.h" |
23 #include "storage/browser/fileapi/file_system_operation_runner.h" | 24 #include "storage/browser/fileapi/file_system_operation_runner.h" |
24 #include "storage/browser/fileapi/sandbox_file_system_backend.h" | 25 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
25 #include "storage/browser/quota/quota_manager.h" | 26 #include "storage/browser/quota/quota_manager.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
44 class FileSystemOperationImplTest | 45 class FileSystemOperationImplTest |
45 : public testing::Test { | 46 : public testing::Test { |
46 public: | 47 public: |
47 FileSystemOperationImplTest() : weak_factory_(this) {} | 48 FileSystemOperationImplTest() : weak_factory_(this) {} |
48 | 49 |
49 protected: | 50 protected: |
50 virtual void SetUp() OVERRIDE { | 51 virtual void SetUp() OVERRIDE { |
51 EXPECT_TRUE(base_.CreateUniqueTempDir()); | 52 EXPECT_TRUE(base_.CreateUniqueTempDir()); |
52 change_observers_ = | 53 change_observers_ = |
53 storage::MockFileChangeObserver::CreateList(&change_observer_); | 54 storage::MockFileChangeObserver::CreateList(&change_observer_); |
55 update_observers_ = | |
56 storage::MockFileUpdateObserver::CreateList(&update_observer_); | |
54 | 57 |
55 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); | 58 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); |
56 quota_manager_ = | 59 quota_manager_ = |
57 new MockQuotaManager(false /* is_incognito */, | 60 new MockQuotaManager(false /* is_incognito */, |
58 base_dir, | 61 base_dir, |
59 base::MessageLoopProxy::current().get(), | 62 base::MessageLoopProxy::current().get(), |
60 base::MessageLoopProxy::current().get(), | 63 base::MessageLoopProxy::current().get(), |
61 NULL /* special storage policy */); | 64 NULL /* special storage policy */); |
62 quota_manager_proxy_ = new MockQuotaManagerProxy( | 65 quota_manager_proxy_ = new MockQuotaManagerProxy( |
63 quota_manager(), base::MessageLoopProxy::current().get()); | 66 quota_manager(), base::MessageLoopProxy::current().get()); |
64 sandbox_file_system_.SetUp(base_dir, quota_manager_proxy_.get()); | 67 sandbox_file_system_.SetUp(base_dir, quota_manager_proxy_.get()); |
65 sandbox_file_system_.AddFileChangeObserver(&change_observer_); | 68 sandbox_file_system_.AddFileChangeObserver(&change_observer_); |
69 sandbox_file_system_.AddFileUpdateObserver(&update_observer_); | |
70 update_observer_.EndCount(); | |
tzik
2014/09/19 03:43:59
EndCount() looks a bit weird.
How about renaming i
iseki
2014/09/19 04:55:29
Done.
| |
66 } | 71 } |
67 | 72 |
68 virtual void TearDown() OVERRIDE { | 73 virtual void TearDown() OVERRIDE { |
69 // Let the client go away before dropping a ref of the quota manager proxy. | 74 // Let the client go away before dropping a ref of the quota manager proxy. |
70 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); | 75 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); |
71 quota_manager_ = NULL; | 76 quota_manager_ = NULL; |
72 quota_manager_proxy_ = NULL; | 77 quota_manager_proxy_ = NULL; |
73 sandbox_file_system_.TearDown(); | 78 sandbox_file_system_.TearDown(); |
74 } | 79 } |
75 | 80 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 sandbox_file_system_.storage_type(), | 290 sandbox_file_system_.storage_type(), |
286 quota + quota_delta); | 291 quota + quota_delta); |
287 } | 292 } |
288 | 293 |
289 base::File::Error Move( | 294 base::File::Error Move( |
290 const FileSystemURL& src, | 295 const FileSystemURL& src, |
291 const FileSystemURL& dest, | 296 const FileSystemURL& dest, |
292 storage::FileSystemOperation::CopyOrMoveOption option) { | 297 storage::FileSystemOperation::CopyOrMoveOption option) { |
293 base::File::Error status; | 298 base::File::Error status; |
294 base::RunLoop run_loop; | 299 base::RunLoop run_loop; |
300 update_observer_.StartCount(); | |
295 operation_runner()->Move( | 301 operation_runner()->Move( |
296 src, | 302 src, |
297 dest, | 303 dest, |
298 option, | 304 option, |
299 RecordStatusCallback(run_loop.QuitClosure(), &status)); | 305 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
300 run_loop.Run(); | 306 run_loop.Run(); |
307 update_observer_.EndCount(); | |
301 return status; | 308 return status; |
302 } | 309 } |
303 | 310 |
304 base::File::Error Copy( | 311 base::File::Error Copy( |
305 const FileSystemURL& src, | 312 const FileSystemURL& src, |
306 const FileSystemURL& dest, | 313 const FileSystemURL& dest, |
307 storage::FileSystemOperation::CopyOrMoveOption option) { | 314 storage::FileSystemOperation::CopyOrMoveOption option) { |
308 base::File::Error status; | 315 base::File::Error status; |
309 base::RunLoop run_loop; | 316 base::RunLoop run_loop; |
317 update_observer_.StartCount(); | |
310 operation_runner()->Copy( | 318 operation_runner()->Copy( |
311 src, | 319 src, |
312 dest, | 320 dest, |
313 option, | 321 option, |
314 FileSystemOperationRunner::CopyProgressCallback(), | 322 FileSystemOperationRunner::CopyProgressCallback(), |
315 RecordStatusCallback(run_loop.QuitClosure(), &status)); | 323 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
316 run_loop.Run(); | 324 run_loop.Run(); |
325 update_observer_.EndCount(); | |
317 return status; | 326 return status; |
318 } | 327 } |
319 | 328 |
320 base::File::Error CopyInForeignFile(const base::FilePath& src, | 329 base::File::Error CopyInForeignFile(const base::FilePath& src, |
321 const FileSystemURL& dest) { | 330 const FileSystemURL& dest) { |
322 base::File::Error status; | 331 base::File::Error status; |
323 base::RunLoop run_loop; | 332 base::RunLoop run_loop; |
333 update_observer_.StartCount(); | |
324 operation_runner()->CopyInForeignFile( | 334 operation_runner()->CopyInForeignFile( |
325 src, dest, RecordStatusCallback(run_loop.QuitClosure(), &status)); | 335 src, dest, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
326 run_loop.Run(); | 336 run_loop.Run(); |
337 update_observer_.EndCount(); | |
327 return status; | 338 return status; |
328 } | 339 } |
329 | 340 |
330 base::File::Error Truncate(const FileSystemURL& url, int size) { | 341 base::File::Error Truncate(const FileSystemURL& url, int size) { |
331 base::File::Error status; | 342 base::File::Error status; |
332 base::RunLoop run_loop; | 343 base::RunLoop run_loop; |
344 update_observer_.StartCount(); | |
333 operation_runner()->Truncate( | 345 operation_runner()->Truncate( |
334 url, size, RecordStatusCallback(run_loop.QuitClosure(), &status)); | 346 url, size, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
335 run_loop.Run(); | 347 run_loop.Run(); |
348 update_observer_.EndCount(); | |
336 return status; | 349 return status; |
337 } | 350 } |
338 | 351 |
339 base::File::Error CreateFile(const FileSystemURL& url, bool exclusive) { | 352 base::File::Error CreateFile(const FileSystemURL& url, bool exclusive) { |
340 base::File::Error status; | 353 base::File::Error status; |
341 base::RunLoop run_loop; | 354 base::RunLoop run_loop; |
355 update_observer_.StartCount(); | |
342 operation_runner()->CreateFile( | 356 operation_runner()->CreateFile( |
343 url, exclusive, RecordStatusCallback(run_loop.QuitClosure(), &status)); | 357 url, exclusive, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
344 run_loop.Run(); | 358 run_loop.Run(); |
359 update_observer_.EndCount(); | |
345 return status; | 360 return status; |
346 } | 361 } |
347 | 362 |
348 base::File::Error Remove(const FileSystemURL& url, bool recursive) { | 363 base::File::Error Remove(const FileSystemURL& url, bool recursive) { |
349 base::File::Error status; | 364 base::File::Error status; |
350 base::RunLoop run_loop; | 365 base::RunLoop run_loop; |
366 update_observer_.StartCount(); | |
351 operation_runner()->Remove( | 367 operation_runner()->Remove( |
352 url, recursive, RecordStatusCallback(run_loop.QuitClosure(), &status)); | 368 url, recursive, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
353 run_loop.Run(); | 369 run_loop.Run(); |
370 update_observer_.EndCount(); | |
354 return status; | 371 return status; |
355 } | 372 } |
356 | 373 |
357 base::File::Error CreateDirectory(const FileSystemURL& url, | 374 base::File::Error CreateDirectory(const FileSystemURL& url, |
358 bool exclusive, | 375 bool exclusive, |
359 bool recursive) { | 376 bool recursive) { |
360 base::File::Error status; | 377 base::File::Error status; |
361 base::RunLoop run_loop; | 378 base::RunLoop run_loop; |
379 update_observer_.StartCount(); | |
362 operation_runner()->CreateDirectory( | 380 operation_runner()->CreateDirectory( |
363 url, | 381 url, |
364 exclusive, | 382 exclusive, |
365 recursive, | 383 recursive, |
366 RecordStatusCallback(run_loop.QuitClosure(), &status)); | 384 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
367 run_loop.Run(); | 385 run_loop.Run(); |
386 update_observer_.EndCount(); | |
368 return status; | 387 return status; |
369 } | 388 } |
370 | 389 |
371 base::File::Error GetMetadata(const FileSystemURL& url) { | 390 base::File::Error GetMetadata(const FileSystemURL& url) { |
372 base::File::Error status; | 391 base::File::Error status; |
373 base::RunLoop run_loop; | 392 base::RunLoop run_loop; |
393 update_observer_.StartCount(); | |
374 operation_runner()->GetMetadata( | 394 operation_runner()->GetMetadata( |
375 url, RecordMetadataCallback(run_loop.QuitClosure(), &status)); | 395 url, RecordMetadataCallback(run_loop.QuitClosure(), &status)); |
376 run_loop.Run(); | 396 run_loop.Run(); |
397 update_observer_.EndCount(); | |
377 return status; | 398 return status; |
378 } | 399 } |
379 | 400 |
380 base::File::Error ReadDirectory(const FileSystemURL& url) { | 401 base::File::Error ReadDirectory(const FileSystemURL& url) { |
381 base::File::Error status; | 402 base::File::Error status; |
382 base::RunLoop run_loop; | 403 base::RunLoop run_loop; |
404 update_observer_.StartCount(); | |
383 operation_runner()->ReadDirectory( | 405 operation_runner()->ReadDirectory( |
384 url, RecordReadDirectoryCallback(run_loop.QuitClosure(), &status)); | 406 url, RecordReadDirectoryCallback(run_loop.QuitClosure(), &status)); |
385 run_loop.Run(); | 407 run_loop.Run(); |
408 update_observer_.EndCount(); | |
386 return status; | 409 return status; |
387 } | 410 } |
388 | 411 |
389 base::File::Error CreateSnapshotFile(const FileSystemURL& url) { | 412 base::File::Error CreateSnapshotFile(const FileSystemURL& url) { |
390 base::File::Error status; | 413 base::File::Error status; |
391 base::RunLoop run_loop; | 414 base::RunLoop run_loop; |
415 update_observer_.StartCount(); | |
392 operation_runner()->CreateSnapshotFile( | 416 operation_runner()->CreateSnapshotFile( |
393 url, RecordSnapshotFileCallback(run_loop.QuitClosure(), &status)); | 417 url, RecordSnapshotFileCallback(run_loop.QuitClosure(), &status)); |
394 run_loop.Run(); | 418 run_loop.Run(); |
419 update_observer_.EndCount(); | |
395 return status; | 420 return status; |
396 } | 421 } |
397 | 422 |
398 base::File::Error FileExists(const FileSystemURL& url) { | 423 base::File::Error FileExists(const FileSystemURL& url) { |
399 base::File::Error status; | 424 base::File::Error status; |
400 base::RunLoop run_loop; | 425 base::RunLoop run_loop; |
426 update_observer_.StartCount(); | |
401 operation_runner()->FileExists( | 427 operation_runner()->FileExists( |
402 url, RecordStatusCallback(run_loop.QuitClosure(), &status)); | 428 url, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
403 run_loop.Run(); | 429 run_loop.Run(); |
430 update_observer_.EndCount(); | |
404 return status; | 431 return status; |
405 } | 432 } |
406 | 433 |
407 base::File::Error DirectoryExists(const FileSystemURL& url) { | 434 base::File::Error DirectoryExists(const FileSystemURL& url) { |
408 base::File::Error status; | 435 base::File::Error status; |
409 base::RunLoop run_loop; | 436 base::RunLoop run_loop; |
437 update_observer_.StartCount(); | |
410 operation_runner()->DirectoryExists( | 438 operation_runner()->DirectoryExists( |
411 url, RecordStatusCallback(run_loop.QuitClosure(), &status)); | 439 url, RecordStatusCallback(run_loop.QuitClosure(), &status)); |
412 run_loop.Run(); | 440 run_loop.Run(); |
441 update_observer_.EndCount(); | |
413 return status; | 442 return status; |
414 } | 443 } |
415 | 444 |
416 base::File::Error TouchFile(const FileSystemURL& url, | 445 base::File::Error TouchFile(const FileSystemURL& url, |
417 const base::Time& last_access_time, | 446 const base::Time& last_access_time, |
418 const base::Time& last_modified_time) { | 447 const base::Time& last_modified_time) { |
419 base::File::Error status; | 448 base::File::Error status; |
420 base::RunLoop run_loop; | 449 base::RunLoop run_loop; |
450 update_observer_.StartCount(); | |
421 operation_runner()->TouchFile( | 451 operation_runner()->TouchFile( |
422 url, | 452 url, |
423 last_access_time, | 453 last_access_time, |
424 last_modified_time, | 454 last_modified_time, |
425 RecordStatusCallback(run_loop.QuitClosure(), &status)); | 455 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
426 run_loop.Run(); | 456 run_loop.Run(); |
457 update_observer_.EndCount(); | |
427 return status; | 458 return status; |
428 } | 459 } |
429 | 460 |
430 private: | 461 private: |
431 base::MessageLoopForIO message_loop_; | 462 base::MessageLoopForIO message_loop_; |
432 scoped_refptr<QuotaManager> quota_manager_; | 463 scoped_refptr<QuotaManager> quota_manager_; |
433 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; | 464 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; |
434 | 465 |
435 // Common temp base for nondestructive uses. | 466 // Common temp base for nondestructive uses. |
436 base::ScopedTempDir base_; | 467 base::ScopedTempDir base_; |
437 | 468 |
438 SandboxFileSystemTestHelper sandbox_file_system_; | 469 SandboxFileSystemTestHelper sandbox_file_system_; |
439 | 470 |
440 // For post-operation status. | 471 // For post-operation status. |
441 base::File::Info info_; | 472 base::File::Info info_; |
442 base::FilePath path_; | 473 base::FilePath path_; |
443 std::vector<storage::DirectoryEntry> entries_; | 474 std::vector<storage::DirectoryEntry> entries_; |
444 scoped_refptr<ShareableFileReference> shareable_file_ref_; | 475 scoped_refptr<ShareableFileReference> shareable_file_ref_; |
445 | 476 |
446 storage::MockFileChangeObserver change_observer_; | 477 storage::MockFileChangeObserver change_observer_; |
447 storage::ChangeObserverList change_observers_; | 478 storage::ChangeObserverList change_observers_; |
479 storage::MockFileUpdateObserver update_observer_; | |
480 storage::UpdateObserverList update_observers_; | |
448 | 481 |
449 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; | 482 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; |
450 | 483 |
451 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); | 484 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); |
452 }; | 485 }; |
453 | 486 |
454 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { | 487 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { |
455 change_observer()->ResetCount(); | 488 change_observer()->ResetCount(); |
456 EXPECT_EQ( | 489 EXPECT_EQ( |
457 base::File::FILE_ERROR_NOT_FOUND, | 490 base::File::FILE_ERROR_NOT_FOUND, |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 FileSystemURL src_file(CreateFile("src")); | 1289 FileSystemURL src_file(CreateFile("src")); |
1257 FileSystemURL dest_file(CreateFile("dest")); | 1290 FileSystemURL dest_file(CreateFile("dest")); |
1258 | 1291 |
1259 EXPECT_EQ(base::File::FILE_OK, Truncate(dest_file, 6)); | 1292 EXPECT_EQ(base::File::FILE_OK, Truncate(dest_file, 6)); |
1260 EXPECT_EQ(base::File::FILE_OK, | 1293 EXPECT_EQ(base::File::FILE_OK, |
1261 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); | 1294 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); |
1262 EXPECT_EQ(0, GetFileSize("dest")); | 1295 EXPECT_EQ(0, GetFileSize("dest")); |
1263 } | 1296 } |
1264 | 1297 |
1265 } // namespace content | 1298 } // namespace content |
OLD | NEW |