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 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 scoped_ptr<ResourceMetadataStorage, | 51 scoped_ptr<ResourceMetadataStorage, |
52 test_util::DestroyHelperForTests> metadata_storage_; | 52 test_util::DestroyHelperForTests> metadata_storage_; |
53 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; | 53 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; |
54 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> | 54 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> |
55 resource_metadata_; | 55 resource_metadata_; |
56 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; | 56 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; |
57 }; | 57 }; |
58 | 58 |
59 TEST_F(RemoveStaleCacheFilesTest, RemoveStaleCacheFiles) { | 59 TEST_F(RemoveStaleCacheFilesTest, RemoveStaleCacheFiles) { |
60 base::FilePath dummy_file; | 60 base::FilePath dummy_file; |
61 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), | 61 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_file)); |
62 &dummy_file)); | |
63 std::string local_id("pdf:1a2b3c"); | 62 std::string local_id("pdf:1a2b3c"); |
64 std::string md5("abcdef0123456789"); | 63 std::string md5("abcdef0123456789"); |
65 | 64 |
66 // Create a stale cache file. | 65 // Create a stale cache file. |
67 EXPECT_EQ(FILE_ERROR_OK, | 66 EXPECT_EQ(FILE_ERROR_OK, |
68 cache_->Store(local_id, md5, dummy_file, | 67 cache_->Store(local_id, md5, dummy_file, |
69 FileCache::FILE_OPERATION_COPY)); | 68 FileCache::FILE_OPERATION_COPY)); |
70 | 69 |
71 // Verify that the cache entry exists. | 70 // Verify that the cache entry exists. |
72 FileCacheEntry cache_entry; | 71 FileCacheEntry cache_entry; |
73 EXPECT_TRUE(cache_->GetCacheEntry(local_id, &cache_entry)); | 72 EXPECT_TRUE(cache_->GetCacheEntry(local_id, &cache_entry)); |
74 | 73 |
75 ResourceEntry entry; | 74 ResourceEntry entry; |
76 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 75 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
77 resource_metadata_->GetResourceEntryById(local_id, &entry)); | 76 resource_metadata_->GetResourceEntryById(local_id, &entry)); |
78 | 77 |
79 // Remove stale cache files. | 78 // Remove stale cache files. |
80 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); | 79 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); |
81 | 80 |
82 // Verify that the cache entry is deleted. | 81 // Verify that the cache entry is deleted. |
83 EXPECT_FALSE(cache_->GetCacheEntry(local_id, &cache_entry)); | 82 EXPECT_FALSE(cache_->GetCacheEntry(local_id, &cache_entry)); |
84 } | 83 } |
85 | 84 |
86 TEST_F(RemoveStaleCacheFilesTest, DirtyCacheFiles) { | 85 TEST_F(RemoveStaleCacheFilesTest, DirtyCacheFiles) { |
87 base::FilePath dummy_file; | 86 base::FilePath dummy_file; |
88 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), | 87 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_file)); |
89 &dummy_file)); | |
90 | 88 |
91 // Dirty and deleted (= absent in resource_metada) cache entry. | 89 // Dirty and deleted (= absent in resource_metada) cache entry. |
92 std::string local_id_1("file:1"); | 90 std::string local_id_1("file:1"); |
93 std::string md5_1("abcdef0123456789"); | 91 std::string md5_1("abcdef0123456789"); |
94 EXPECT_EQ(FILE_ERROR_OK, | 92 EXPECT_EQ(FILE_ERROR_OK, |
95 cache_->Store(local_id_1, md5_1, dummy_file, | 93 cache_->Store(local_id_1, md5_1, dummy_file, |
96 FileCache::FILE_OPERATION_COPY)); | 94 FileCache::FILE_OPERATION_COPY)); |
97 EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(local_id_1)); | 95 EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(local_id_1)); |
98 | 96 |
99 // Dirty and mismatching-MD5 entry. | 97 // Dirty and mismatching-MD5 entry. |
(...skipping 18 matching lines...) Expand all Loading... |
118 | 116 |
119 // Dirty cache should be removed if and only if the entry does not exist in | 117 // Dirty cache should be removed if and only if the entry does not exist in |
120 // resource_metadata. | 118 // resource_metadata. |
121 FileCacheEntry cache_entry; | 119 FileCacheEntry cache_entry; |
122 EXPECT_FALSE(cache_->GetCacheEntry(local_id_1, &cache_entry)); | 120 EXPECT_FALSE(cache_->GetCacheEntry(local_id_1, &cache_entry)); |
123 EXPECT_TRUE(cache_->GetCacheEntry(local_id_2, &cache_entry)); | 121 EXPECT_TRUE(cache_->GetCacheEntry(local_id_2, &cache_entry)); |
124 } | 122 } |
125 | 123 |
126 } // namespace internal | 124 } // namespace internal |
127 } // namespace drive | 125 } // namespace drive |
OLD | NEW |