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

Unified Diff: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc

Issue 10832241: Drive: Removes unused cache files after the initial feed fetch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the memory leak. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
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 99efc62051736cfdf347044084edf7bd1c7fda80..13e82b6bba73ec7a30c1dc6c11a0d9902adaf40d 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
@@ -75,6 +75,14 @@ void DriveSearchCallback(
message_loop->Quit();
}
+// Callback for GDataCache::StoreOnUIThread used in RemoveStaleCacheFiles test.
+// 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) {
@@ -2643,4 +2651,48 @@ 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");
+
+ EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
+ .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
+
+ // 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(_)).Times(1);
+
+ scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(path);
+ ASSERT_FALSE(entry.get());
+
+ // Load a root feed.
+ LoadRootFeedDocument("root_feed.json");
+
+ // Wait for StaleCacheFilesRemover to finish cleaning up the stale file.
+ test_util::RunBlockingPoolTask();
+
+ // 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

Powered by Google App Engine
This is Rietveld 408576698