OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); | 374 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); |
375 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); | 375 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); |
376 | 376 |
377 // Open (2). | 377 // Open (2). |
378 scoped_ptr<base::ScopedClosureRunner> file_closer2; | 378 scoped_ptr<base::ScopedClosureRunner> file_closer2; |
379 EXPECT_EQ(FILE_ERROR_OK, cache_->OpenForWrite(id, &file_closer2)); | 379 EXPECT_EQ(FILE_ERROR_OK, cache_->OpenForWrite(id, &file_closer2)); |
380 EXPECT_TRUE(cache_->IsOpenedForWrite(id)); | 380 EXPECT_TRUE(cache_->IsOpenedForWrite(id)); |
381 | 381 |
382 // Close (1). | 382 // Close (1). |
383 file_closer1.reset(); | 383 file_closer1.reset(); |
| 384 base::RunLoop().RunUntilIdle(); |
384 EXPECT_TRUE(cache_->IsOpenedForWrite(id)); | 385 EXPECT_TRUE(cache_->IsOpenedForWrite(id)); |
385 | 386 |
386 // last_modified is updated. | 387 // last_modified is updated. |
387 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); | 388 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); |
388 EXPECT_NE(0, entry.file_info().last_modified()); | 389 EXPECT_NE(0, entry.file_info().last_modified()); |
389 | 390 |
390 // Close (2). | 391 // Close (2). |
391 file_closer2.reset(); | 392 file_closer2.reset(); |
| 393 base::RunLoop().RunUntilIdle(); |
392 EXPECT_FALSE(cache_->IsOpenedForWrite(id)); | 394 EXPECT_FALSE(cache_->IsOpenedForWrite(id)); |
393 | 395 |
394 // Try to open non-existent file. | 396 // Try to open non-existent file. |
395 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 397 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
396 cache_->OpenForWrite("nonexistent_id", &file_closer1)); | 398 cache_->OpenForWrite("nonexistent_id", &file_closer1)); |
397 } | 399 } |
398 | 400 |
399 TEST_F(FileCacheTest, UpdateMd5) { | 401 TEST_F(FileCacheTest, UpdateMd5) { |
400 // Store test data. | 402 // Store test data. |
401 const base::FilePath src_file_path = temp_dir_.path().Append("test.dat"); | 403 const base::FilePath src_file_path = temp_dir_.path().Append("test.dat"); |
(...skipping 15 matching lines...) Expand all Loading... |
417 EXPECT_EQ(FILE_ERROR_OK, cache_->GetFile(id, &cache_file_path)); | 419 EXPECT_EQ(FILE_ERROR_OK, cache_->GetFile(id, &cache_file_path)); |
418 const std::string contents_after = "after"; | 420 const std::string contents_after = "after"; |
419 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(cache_file_path, | 421 EXPECT_TRUE(google_apis::test_util::WriteStringToFile(cache_file_path, |
420 contents_after)); | 422 contents_after)); |
421 | 423 |
422 // Cannot update MD5 of an opend file. | 424 // Cannot update MD5 of an opend file. |
423 EXPECT_EQ(FILE_ERROR_IN_USE, cache_->UpdateMd5(id)); | 425 EXPECT_EQ(FILE_ERROR_IN_USE, cache_->UpdateMd5(id)); |
424 | 426 |
425 // Close file. | 427 // Close file. |
426 file_closer.reset(); | 428 file_closer.reset(); |
| 429 base::RunLoop().RunUntilIdle(); |
427 | 430 |
428 // MD5 was cleared by OpenForWrite(). | 431 // MD5 was cleared by OpenForWrite(). |
429 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); | 432 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); |
430 EXPECT_TRUE(entry.file_specific_info().cache_state().md5().empty()); | 433 EXPECT_TRUE(entry.file_specific_info().cache_state().md5().empty()); |
431 | 434 |
432 // Update MD5. | 435 // Update MD5. |
433 EXPECT_EQ(FILE_ERROR_OK, cache_->UpdateMd5(id)); | 436 EXPECT_EQ(FILE_ERROR_OK, cache_->UpdateMd5(id)); |
434 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); | 437 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); |
435 EXPECT_EQ(base::MD5String(contents_after), | 438 EXPECT_EQ(base::MD5String(contents_after), |
436 entry.file_specific_info().cache_state().md5()); | 439 entry.file_specific_info().cache_state().md5()); |
(...skipping 17 matching lines...) Expand all Loading... |
454 | 457 |
455 // Entry is dirty. | 458 // Entry is dirty. |
456 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); | 459 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); |
457 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); | 460 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); |
458 | 461 |
459 // Cannot clear the dirty bit of an opened entry. | 462 // Cannot clear the dirty bit of an opened entry. |
460 EXPECT_EQ(FILE_ERROR_IN_USE, cache_->ClearDirty(id)); | 463 EXPECT_EQ(FILE_ERROR_IN_USE, cache_->ClearDirty(id)); |
461 | 464 |
462 // Close the file and clear the dirty bit. | 465 // Close the file and clear the dirty bit. |
463 file_closer.reset(); | 466 file_closer.reset(); |
| 467 base::RunLoop().RunUntilIdle(); |
464 EXPECT_EQ(FILE_ERROR_OK, cache_->ClearDirty(id)); | 468 EXPECT_EQ(FILE_ERROR_OK, cache_->ClearDirty(id)); |
465 | 469 |
466 // Entry is not dirty. | 470 // Entry is not dirty. |
467 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); | 471 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); |
468 EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); | 472 EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); |
469 } | 473 } |
470 | 474 |
471 TEST_F(FileCacheTest, Remove) { | 475 TEST_F(FileCacheTest, Remove) { |
472 const base::FilePath src_file_path = temp_dir_.path().Append("test.dat"); | 476 const base::FilePath src_file_path = temp_dir_.path().Append("test.dat"); |
473 const std::string src_contents = "test"; | 477 const std::string src_contents = "test"; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 551 |
548 // Clear cache. | 552 // Clear cache. |
549 EXPECT_TRUE(cache_->ClearAll()); | 553 EXPECT_TRUE(cache_->ClearAll()); |
550 | 554 |
551 // Verify that the cache is removed. | 555 // Verify that the cache is removed. |
552 EXPECT_TRUE(base::IsDirectoryEmpty(cache_files_dir_)); | 556 EXPECT_TRUE(base::IsDirectoryEmpty(cache_files_dir_)); |
553 } | 557 } |
554 | 558 |
555 } // namespace internal | 559 } // namespace internal |
556 } // namespace drive | 560 } // namespace drive |
OLD | NEW |