Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc |
| index c9413b99475da0afbf240e0cf047ec868e4ce826..3a44668c16aff9c12b5d0f61ccbaa5d75b4a9c71 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop.h" |
| #include "base/path_service.h" |
| +#include "base/run_loop.h" |
| #include "base/scoped_temp_dir.h" |
| #include "base/stringprintf.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| @@ -73,6 +74,14 @@ void DriveSearchCallback( |
| message_loop->Quit(); |
| } |
| +// Callback to GDataCache::StoreOnUIThread used in RemoveStaleCacheFiles test. |
|
satorux1
2012/08/17 10:38:41
Callback for
yoshiki
2012/08/18 03:31:51
Done.
|
| +// Verifies that the result is not an error. |
| +void VerifyCacheFileState(GDataFileError error, |
| + const std::string& resource_id, |
| + const std::string& md5) { |
| + EXPECT_EQ(GDATA_FILE_OK, error); |
| +} |
| + |
| // Action used to set mock expectations for |
| // DocumentsService::GetDocumentEntry(). |
| ACTION_P2(MockGetDocumentEntry, status, value) { |
| @@ -2622,4 +2631,45 @@ TEST_F(GDataFileSystemTest, OpenAndCloseFile) { |
| EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| } |
| +TEST_F(GDataFileSystemTest, RemoveStaleCacheFiles) { |
| + FilePath dummy_file = GetTestFilePath("root_feed.json"); |
| + std::string resource_id("pdf:1a2b"); |
| + std::string md5("abcdef0123456789"); |
| + |
| + // Create a stale cache file. |
| + cache_->StoreOnUIThread(resource_id, md5, dummy_file, |
| + GDataCache::FILE_OPERATION_COPY, |
| + base::Bind(&gdata::VerifyCacheFileState)); |
| + test_util::RunBlockingPoolTask(); |
| + |
| + // Verify that the cache file exists. |
| + FilePath path = cache_->GetCacheFilePath(resource_id, |
| + md5, |
| + GDataCache::CACHE_TYPE_TMP, |
| + GDataCache::CACHED_FILE_FROM_SERVER); |
| + EXPECT_TRUE(file_util::PathExists(path)); |
| + |
| + // Verify that the corresponding file entry doesn't exist. |
| + EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); |
| + EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "", _, _)) |
| + .Times(1); |
| + EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1); |
| + |
| + scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(path); |
| + ASSERT_FALSE(entry.get()); |
| + |
| + // Load a root feed. |
| + LoadRootFeedDocument("root_feed.json"); |
| + |
| + base::RunLoop run_loop; |
| + run_loop.RunUntilIdle(); |
| + |
| + // Verify that the cache file is deleted. |
| + path = cache_->GetCacheFilePath(resource_id, |
| + md5, |
| + GDataCache::CACHE_TYPE_TMP, |
| + GDataCache::CACHED_FILE_FROM_SERVER); |
| + EXPECT_FALSE(file_util::PathExists(path)); |
| +} |
| + |
| } // namespace gdata |