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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 for (size_t i = 0; i < results->size(); i++) { | 68 for (size_t i = 0; i < results->size(); i++) { |
69 EXPECT_EQ(FilePath(expected_results[i].path), | 69 EXPECT_EQ(FilePath(expected_results[i].path), |
70 results->at(i).path); | 70 results->at(i).path); |
71 EXPECT_EQ(expected_results[i].is_directory, | 71 EXPECT_EQ(expected_results[i].is_directory, |
72 results->at(i).is_directory); | 72 results->at(i).is_directory); |
73 } | 73 } |
74 | 74 |
75 message_loop->Quit(); | 75 message_loop->Quit(); |
76 } | 76 } |
77 | 77 |
| 78 // Callback for GDataCache::StoreOnUIThread used in RemoveStaleCacheFiles test. |
| 79 // Verifies that the result is not an error. |
| 80 void VerifyCacheFileState(GDataFileError error, |
| 81 const std::string& resource_id, |
| 82 const std::string& md5) { |
| 83 EXPECT_EQ(GDATA_FILE_OK, error); |
| 84 } |
| 85 |
78 // Action used to set mock expectations for | 86 // Action used to set mock expectations for |
79 // DocumentsService::GetDocumentEntry(). | 87 // DocumentsService::GetDocumentEntry(). |
80 ACTION_P2(MockGetDocumentEntry, status, value) { | 88 ACTION_P2(MockGetDocumentEntry, status, value) { |
81 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 89 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
82 base::Bind(arg1, status, base::Passed(value))); | 90 base::Bind(arg1, status, base::Passed(value))); |
83 } | 91 } |
84 | 92 |
85 // Action used to set mock expectations for | 93 // Action used to set mock expectations for |
86 // GDataUploaderInterface::UploadExistingFile(). | 94 // GDataUploaderInterface::UploadExistingFile(). |
87 ACTION_P4(MockUploadExistingFile, | 95 ACTION_P4(MockUploadExistingFile, |
(...skipping 2548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2636 file_md5); | 2644 file_md5); |
2637 | 2645 |
2638 // Try to close the same file twice. | 2646 // Try to close the same file twice. |
2639 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2647 file_system_->CloseFile(kFileInRoot, close_file_callback); |
2640 message_loop_.Run(); | 2648 message_loop_.Run(); |
2641 | 2649 |
2642 // It must fail. | 2650 // It must fail. |
2643 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2651 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
2644 } | 2652 } |
2645 | 2653 |
| 2654 TEST_F(GDataFileSystemTest, RemoveStaleCacheFiles) { |
| 2655 FilePath dummy_file = GetTestFilePath("root_feed.json"); |
| 2656 std::string resource_id("pdf:1a2b"); |
| 2657 std::string md5("abcdef0123456789"); |
| 2658 |
| 2659 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
| 2660 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
| 2661 |
| 2662 // Create a stale cache file. |
| 2663 cache_->StoreOnUIThread(resource_id, md5, dummy_file, |
| 2664 GDataCache::FILE_OPERATION_COPY, |
| 2665 base::Bind(&gdata::VerifyCacheFileState)); |
| 2666 test_util::RunBlockingPoolTask(); |
| 2667 |
| 2668 // Verify that the cache file exists. |
| 2669 FilePath path = cache_->GetCacheFilePath(resource_id, |
| 2670 md5, |
| 2671 GDataCache::CACHE_TYPE_TMP, |
| 2672 GDataCache::CACHED_FILE_FROM_SERVER); |
| 2673 EXPECT_TRUE(file_util::PathExists(path)); |
| 2674 |
| 2675 // Verify that the corresponding file entry doesn't exist. |
| 2676 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); |
| 2677 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "", _, _)) |
| 2678 .Times(1); |
| 2679 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
| 2680 |
| 2681 scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(path); |
| 2682 ASSERT_FALSE(entry.get()); |
| 2683 |
| 2684 // Load a root feed. |
| 2685 LoadRootFeedDocument("root_feed.json"); |
| 2686 |
| 2687 // Wait for StaleCacheFilesRemover to finish cleaning up the stale file. |
| 2688 test_util::RunBlockingPoolTask(); |
| 2689 |
| 2690 // Verify that the cache file is deleted. |
| 2691 path = cache_->GetCacheFilePath(resource_id, |
| 2692 md5, |
| 2693 GDataCache::CACHE_TYPE_TMP, |
| 2694 GDataCache::CACHED_FILE_FROM_SERVER); |
| 2695 EXPECT_FALSE(file_util::PathExists(path)); |
| 2696 } |
| 2697 |
2646 } // namespace gdata | 2698 } // namespace gdata |
OLD | NEW |