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

Side by Side Diff: chrome/browser/chromeos/drive/file_cache_metadata_unittest.cc

Issue 15690021: drive: Move temporary file removal responsiblity to FileCache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_metadata.h" 5 #include "chrome/browser/chromeos/drive/file_cache_metadata.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "chrome/browser/chromeos/drive/drive.pb.h" 9 #include "chrome/browser/chromeos/drive/drive.pb.h"
10 #include "chrome/browser/chromeos/drive/file_cache.h" 10 #include "chrome/browser/chromeos/drive/file_cache.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 FileCache::GetSubDirectoryType(cache_entry)); 225 FileCache::GetSubDirectoryType(cache_entry));
226 EXPECT_TRUE(test_util::CacheStatesEqual( 226 EXPECT_TRUE(test_util::CacheStatesEqual(
227 test_util::ToCacheEntry(test_util::TEST_CACHE_STATE_PRESENT), 227 test_util::ToCacheEntry(test_util::TEST_CACHE_STATE_PRESENT),
228 cache_entry)); 228 cache_entry));
229 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux"))); 229 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux")));
230 230
231 // "id_quux" should be removed during cache initialization. 231 // "id_quux" should be removed during cache initialization.
232 EXPECT_FALSE(metadata_->GetCacheEntry("id_quux", "md5qux", &cache_entry)); 232 EXPECT_FALSE(metadata_->GetCacheEntry("id_quux", "md5qux", &cache_entry));
233 } 233 }
234 234
235 // Test FileCacheMetadata::RemoveTemporaryFiles.
236 TEST_F(FileCacheMetadataTest, RemoveTemporaryFiles) {
237 SetUpCacheMetadata();
238
239 {
240 FileCacheEntry cache_entry;
241 cache_entry.set_md5("<md5>");
242 cache_entry.set_is_present(true);
243 metadata_->AddOrUpdateCacheEntry("<resource_id_1>", cache_entry);
244 }
245 {
246 FileCacheEntry cache_entry;
247 cache_entry.set_md5("<md5>");
248 cache_entry.set_is_present(true);
249 cache_entry.set_is_persistent(true);
250 metadata_->AddOrUpdateCacheEntry("<resource_id_2>", cache_entry);
251 }
252 {
253 FileCacheEntry cache_entry;
254 cache_entry.set_md5("<md5>");
255 cache_entry.set_is_present(true);
256 cache_entry.set_is_persistent(true);
257 metadata_->AddOrUpdateCacheEntry("<resource_id_3>", cache_entry);
258 }
259 {
260 FileCacheEntry cache_entry;
261 cache_entry.set_md5("<md5>");
262 cache_entry.set_is_present(true);
263 metadata_->AddOrUpdateCacheEntry("<resource_id_4>", cache_entry);
264 }
265
266 metadata_->RemoveTemporaryFiles();
267 // resource 1 and 4 should be gone, as these are temporary.
268 FileCacheEntry cache_entry;
269 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_1>", "", &cache_entry));
270 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_2>", "", &cache_entry));
271 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_3>", "", &cache_entry));
272 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_4>", "", &cache_entry));
273 }
274
275 // Don't use TEST_F, as we don't want SetUp() and TearDown() for this test. 235 // Don't use TEST_F, as we don't want SetUp() and TearDown() for this test.
276 TEST(FileCacheMetadataExtraTest, CannotOpenDB) { 236 TEST(FileCacheMetadataExtraTest, CannotOpenDB) {
277 // Create nonexistent cache paths, so the initialization fails due to the 237 // Create nonexistent cache paths, so the initialization fails due to the
278 // failure of opening the DB. 238 // failure of opening the DB.
279 std::vector<base::FilePath> cache_paths = 239 std::vector<base::FilePath> cache_paths =
280 FileCache::GetCachePaths( 240 FileCache::GetCachePaths(
281 base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent")); 241 base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent"));
282 242
283 scoped_ptr<FileCacheMetadata> metadata(new FileCacheMetadata(NULL)); 243 scoped_ptr<FileCacheMetadata> metadata(new FileCacheMetadata(NULL));
284 EXPECT_FALSE(metadata->Initialize(cache_paths)); 244 EXPECT_FALSE(metadata->Initialize(cache_paths));
285 } 245 }
286 246
287 } // namespace internal 247 } // namespace internal
288 } // namespace drive 248 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_cache_metadata.cc ('k') | chrome/browser/chromeos/drive/file_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698