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 "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 9 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 << ": " << target.value() << ": " << symlink.value(); | 109 << ": " << target.value() << ": " << symlink.value(); |
110 } | 110 } |
111 | 111 |
112 protected: | 112 protected: |
113 // Helper function to insert an item with key |resource_id| into |cache_map|. | 113 // Helper function to insert an item with key |resource_id| into |cache_map|. |
114 // |md5|, |sub_dir_type|, |cache_state| are used to create the value | 114 // |md5|, |sub_dir_type|, |cache_state| are used to create the value |
115 // CacheEntry. | 115 // CacheEntry. |
116 void InsertIntoMap(GDataCacheMetadataMap::CacheMap* cache_map, | 116 void InsertIntoMap(GDataCacheMetadataMap::CacheMap* cache_map, |
117 const std::string& resource_id, | 117 const std::string& resource_id, |
118 const std::string& md5, | 118 const std::string& md5, |
| 119 GDataCache::CacheSubDirectoryType sub_dir_type, |
119 int cache_state) { | 120 int cache_state) { |
120 cache_map->insert(std::make_pair( | 121 cache_map->insert(std::make_pair( |
121 resource_id, GDataCache::CacheEntry(md5, cache_state))); | 122 resource_id, GDataCache::CacheEntry(md5, sub_dir_type, cache_state))); |
122 } | 123 } |
123 | 124 |
124 ScopedTempDir temp_dir_; | 125 ScopedTempDir temp_dir_; |
125 scoped_ptr<GDataCacheMetadataMap> metadata_; | 126 scoped_ptr<GDataCacheMetadataMap> metadata_; |
126 std::vector<FilePath> cache_paths_; | 127 std::vector<FilePath> cache_paths_; |
127 FilePath persistent_directory_; | 128 FilePath persistent_directory_; |
128 FilePath tmp_directory_; | 129 FilePath tmp_directory_; |
129 FilePath pinned_directory_; | 130 FilePath pinned_directory_; |
130 FilePath outgoing_directory_; | 131 FilePath outgoing_directory_; |
131 }; | 132 }; |
132 | 133 |
133 // Test all the methods of GDataCacheMetadataMap except for | 134 // Test all the methods of GDataCacheMetadataMap except for |
134 // RemoveTemporaryFiles. | 135 // RemoveTemporaryFiles. |
135 TEST_F(GDataCacheMetadataMapTest, CacheTest) { | 136 TEST_F(GDataCacheMetadataMapTest, CacheTest) { |
136 SetUpCacheMetadata(); | 137 SetUpCacheMetadata(); |
137 | 138 |
138 // Save an initial entry. | 139 // Save an initial entry. |
139 std::string test_resource_id("test_resource_id"); | 140 std::string test_resource_id("test_resource_id"); |
140 std::string test_file_md5("test_file_md5"); | 141 std::string test_file_md5("test_file_md5"); |
141 GDataCache::CacheSubDirectoryType test_sub_dir_type = | 142 GDataCache::CacheSubDirectoryType test_sub_dir_type( |
142 GDataCache::CACHE_TYPE_PERSISTENT; | 143 GDataCache::CACHE_TYPE_PERSISTENT); |
143 int test_cache_state = (GDataCache::CACHE_STATE_PRESENT | | 144 int test_cache_state(GDataCache::CACHE_STATE_PRESENT); |
144 GDataCache::CACHE_STATE_PERSISTENT); | 145 metadata_->UpdateCache(test_resource_id, test_file_md5, |
145 metadata_->UpdateCache(test_resource_id, test_file_md5, test_cache_state); | 146 test_sub_dir_type, test_cache_state); |
146 | 147 |
147 // Test that the entry can be retrieved. | 148 // Test that the entry can be retrieved. |
148 scoped_ptr<GDataCache::CacheEntry> cache_entry = | 149 scoped_ptr<GDataCache::CacheEntry> cache_entry = |
149 metadata_->GetCacheEntry(test_resource_id, test_file_md5); | 150 metadata_->GetCacheEntry(test_resource_id, test_file_md5); |
150 ASSERT_TRUE(cache_entry.get()); | 151 ASSERT_TRUE(cache_entry.get()); |
151 EXPECT_EQ(test_file_md5, cache_entry->md5); | 152 EXPECT_EQ(test_file_md5, cache_entry->md5); |
152 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType()); | 153 EXPECT_EQ(test_sub_dir_type, cache_entry->sub_dir_type); |
153 EXPECT_EQ(test_cache_state, cache_entry->cache_state); | 154 EXPECT_EQ(test_cache_state, cache_entry->cache_state); |
154 | 155 |
155 // Empty md5 should also work. | 156 // Empty md5 should also work. |
156 cache_entry = | 157 cache_entry = |
157 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); | 158 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); |
158 ASSERT_TRUE(cache_entry.get()); | 159 ASSERT_TRUE(cache_entry.get()); |
159 EXPECT_EQ(test_file_md5, cache_entry->md5); | 160 EXPECT_EQ(test_file_md5, cache_entry->md5); |
160 | 161 |
161 // resource_id doesn't exist. | 162 // resource_id doesn't exist. |
162 cache_entry = metadata_->GetCacheEntry("not_found_resource_id", | 163 cache_entry = metadata_->GetCacheEntry("not_found_resource_id", |
163 std::string()).Pass(); | 164 std::string()).Pass(); |
164 EXPECT_FALSE(cache_entry.get()); | 165 EXPECT_FALSE(cache_entry.get()); |
165 | 166 |
166 // md5 doesn't match. | 167 // md5 doesn't match. |
167 cache_entry = | 168 cache_entry = |
168 metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass(); | 169 metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass(); |
169 EXPECT_FALSE(cache_entry.get()); | 170 EXPECT_FALSE(cache_entry.get()); |
170 | 171 |
171 // Update all attributes. | 172 // Update all attributes. |
172 test_file_md5 = "test_file_md5_2"; | 173 test_file_md5 = "test_file_md5_2"; |
173 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; | 174 test_sub_dir_type = GDataCache::CACHE_TYPE_PINNED; |
174 test_cache_state = GDataCache::CACHE_STATE_PINNED; | 175 test_cache_state = GDataCache::CACHE_STATE_PINNED; |
175 metadata_->UpdateCache(test_resource_id, test_file_md5, test_cache_state); | 176 metadata_->UpdateCache(test_resource_id, test_file_md5, test_sub_dir_type, |
| 177 test_cache_state); |
176 | 178 |
177 // Make sure the values took. | 179 // Make sure the values took. |
178 cache_entry = | 180 cache_entry = |
179 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); | 181 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); |
180 ASSERT_TRUE(cache_entry.get()); | 182 ASSERT_TRUE(cache_entry.get()); |
181 EXPECT_EQ(test_file_md5, cache_entry->md5); | 183 EXPECT_EQ(test_file_md5, cache_entry->md5); |
182 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType()); | 184 EXPECT_EQ(test_sub_dir_type, cache_entry->sub_dir_type); |
183 EXPECT_EQ(test_cache_state, cache_entry->cache_state); | 185 EXPECT_EQ(test_cache_state, cache_entry->cache_state); |
184 | 186 |
185 // Empty m5 should work. | 187 // Empty m5 should work. |
186 cache_entry = | 188 cache_entry = |
187 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); | 189 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); |
188 ASSERT_TRUE(cache_entry.get()); | 190 ASSERT_TRUE(cache_entry.get()); |
189 EXPECT_EQ(test_file_md5, cache_entry->md5); | 191 EXPECT_EQ(test_file_md5, cache_entry->md5); |
190 | 192 |
191 // Test dirty cache. | 193 // Test dirty cache. |
192 test_file_md5 = "test_file_md5_3"; | 194 test_file_md5 = "test_file_md5_3"; |
193 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; | 195 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; |
194 test_cache_state = GDataCache::CACHE_STATE_DIRTY; | 196 test_cache_state = GDataCache::CACHE_STATE_DIRTY; |
195 metadata_->UpdateCache(test_resource_id, test_file_md5, test_cache_state); | 197 metadata_->UpdateCache(test_resource_id, test_file_md5, test_sub_dir_type, |
| 198 test_cache_state); |
196 | 199 |
197 // Make sure the values took. | 200 // Make sure the values took. |
198 cache_entry = | 201 cache_entry = |
199 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); | 202 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); |
200 ASSERT_TRUE(cache_entry.get()); | 203 ASSERT_TRUE(cache_entry.get()); |
201 EXPECT_EQ(test_file_md5, cache_entry->md5); | 204 EXPECT_EQ(test_file_md5, cache_entry->md5); |
202 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType()); | 205 EXPECT_EQ(test_sub_dir_type, cache_entry->sub_dir_type); |
203 EXPECT_EQ(test_cache_state, cache_entry->cache_state); | 206 EXPECT_EQ(test_cache_state, cache_entry->cache_state); |
204 | 207 |
205 // Empty md5 should work. | 208 // Empty md5 should work. |
206 cache_entry = | 209 cache_entry = |
207 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); | 210 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); |
208 ASSERT_TRUE(cache_entry.get()); | 211 ASSERT_TRUE(cache_entry.get()); |
209 EXPECT_EQ(test_file_md5, cache_entry->md5); | 212 EXPECT_EQ(test_file_md5, cache_entry->md5); |
210 | 213 |
211 // Mismatched md5 should also work for dirty entries. | 214 // Mismatched md5 should also work for dirty entries. |
212 cache_entry = | 215 cache_entry = |
213 metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass(); | 216 metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass(); |
214 ASSERT_TRUE(cache_entry.get()); | 217 ASSERT_TRUE(cache_entry.get()); |
215 EXPECT_EQ(test_file_md5, cache_entry->md5); | 218 EXPECT_EQ(test_file_md5, cache_entry->md5); |
216 | 219 |
217 // Remove the entry. | 220 // Remove the entry. |
218 metadata_->RemoveFromCache(test_resource_id); | 221 metadata_->RemoveFromCache(test_resource_id); |
219 cache_entry = | 222 cache_entry = |
220 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); | 223 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); |
221 EXPECT_FALSE(cache_entry.get()); | 224 EXPECT_FALSE(cache_entry.get()); |
222 | 225 |
223 // Add another one. | 226 // Add another one. |
224 test_resource_id = "test_resource_id_2"; | 227 test_resource_id = "test_resource_id_2"; |
225 test_file_md5 = "test_file_md5_4"; | 228 test_file_md5 = "test_file_md5_4"; |
226 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; | 229 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; |
227 test_cache_state = GDataCache::CACHE_STATE_PRESENT; | 230 test_cache_state = GDataCache::CACHE_STATE_PRESENT; |
228 metadata_->UpdateCache(test_resource_id, test_file_md5, test_cache_state); | 231 metadata_->UpdateCache(test_resource_id, test_file_md5, test_sub_dir_type, |
| 232 test_cache_state); |
229 | 233 |
230 // Make sure the values took. | 234 // Make sure the values took. |
231 cache_entry = | 235 cache_entry = |
232 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); | 236 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); |
233 ASSERT_TRUE(cache_entry.get()); | 237 ASSERT_TRUE(cache_entry.get()); |
234 EXPECT_EQ(test_file_md5, cache_entry->md5); | 238 EXPECT_EQ(test_file_md5, cache_entry->md5); |
235 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType()); | 239 EXPECT_EQ(test_sub_dir_type, cache_entry->sub_dir_type); |
236 EXPECT_EQ(test_cache_state, cache_entry->cache_state); | 240 EXPECT_EQ(test_cache_state, cache_entry->cache_state); |
237 | 241 |
238 // Update with CACHE_STATE_NONE should evict the entry. | 242 // Update with CACHE_STATE_NONE should evict the entry. |
239 test_file_md5 = "test_file_md5_5"; | 243 test_file_md5 = "test_file_md5_5"; |
240 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; | 244 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; |
241 test_cache_state = GDataCache::CACHE_STATE_NONE; | 245 test_cache_state = GDataCache::CACHE_STATE_NONE; |
242 metadata_->UpdateCache(test_resource_id, test_file_md5, test_cache_state); | 246 metadata_->UpdateCache(test_resource_id, test_file_md5, test_sub_dir_type, |
| 247 test_cache_state); |
243 | 248 |
244 cache_entry = | 249 cache_entry = |
245 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); | 250 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); |
246 EXPECT_FALSE(cache_entry.get()); | 251 EXPECT_FALSE(cache_entry.get()); |
247 } | 252 } |
248 | 253 |
249 TEST_F(GDataCacheMetadataMapTest, Initialization) { | 254 TEST_F(GDataCacheMetadataMapTest, Initialization) { |
250 using file_util::PathExists; | 255 using file_util::PathExists; |
251 using file_util::IsLink; | 256 using file_util::IsLink; |
252 SetUpCacheWithVariousFiles(); | 257 SetUpCacheWithVariousFiles(); |
(...skipping 12 matching lines...) Expand all Loading... |
265 | 270 |
266 SetUpCacheMetadata(); | 271 SetUpCacheMetadata(); |
267 | 272 |
268 // Check contents in "persistent" directory. | 273 // Check contents in "persistent" directory. |
269 // | 274 // |
270 // "id_foo" is present and pinned. | 275 // "id_foo" is present and pinned. |
271 scoped_ptr<GDataCache::CacheEntry> cache_entry; | 276 scoped_ptr<GDataCache::CacheEntry> cache_entry; |
272 cache_entry = metadata_->GetCacheEntry("id_foo", "md5foo"); | 277 cache_entry = metadata_->GetCacheEntry("id_foo", "md5foo"); |
273 ASSERT_TRUE(cache_entry.get()); | 278 ASSERT_TRUE(cache_entry.get()); |
274 EXPECT_EQ("md5foo", cache_entry->md5); | 279 EXPECT_EQ("md5foo", cache_entry->md5); |
275 EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT, | 280 EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); |
276 cache_entry->GetSubDirectoryType()); | 281 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED, |
277 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | | |
278 GDataCache::CACHE_STATE_PERSISTENT, | |
279 cache_entry->cache_state); | 282 cache_entry->cache_state); |
280 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_foo.md5foo"))); | 283 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_foo.md5foo"))); |
281 EXPECT_TRUE(PathExists(pinned_directory_.AppendASCII("id_foo"))); | 284 EXPECT_TRUE(PathExists(pinned_directory_.AppendASCII("id_foo"))); |
282 // The invalid symlink in "outgoing" should be removed. | 285 // The invalid symlink in "outgoing" should be removed. |
283 EXPECT_FALSE(PathExists(outgoing_directory_.AppendASCII("id_foo"))); | 286 EXPECT_FALSE(PathExists(outgoing_directory_.AppendASCII("id_foo"))); |
284 | 287 |
285 // "id_bar" is present and dirty. | 288 // "id_bar" is present and dirty. |
286 cache_entry = metadata_->GetCacheEntry("id_bar", ""); | 289 cache_entry = metadata_->GetCacheEntry("id_bar", ""); |
287 ASSERT_TRUE(cache_entry.get()); | 290 ASSERT_TRUE(cache_entry.get()); |
288 EXPECT_EQ("local", cache_entry->md5); | 291 EXPECT_EQ("local", cache_entry->md5); |
289 EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT, | 292 EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT, cache_entry->sub_dir_type); |
290 cache_entry->GetSubDirectoryType()); | 293 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY, |
291 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY | | |
292 GDataCache::CACHE_STATE_PERSISTENT, | |
293 cache_entry->cache_state); | 294 cache_entry->cache_state); |
294 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_bar.local"))); | 295 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_bar.local"))); |
295 EXPECT_TRUE(PathExists(outgoing_directory_.AppendASCII("id_bar"))); | 296 EXPECT_TRUE(PathExists(outgoing_directory_.AppendASCII("id_bar"))); |
296 | 297 |
297 // "id_baz" should be removed during cache initialization. | 298 // "id_baz" should be removed during cache initialization. |
298 cache_entry = metadata_->GetCacheEntry("id_baz", ""); | 299 cache_entry = metadata_->GetCacheEntry("id_baz", ""); |
299 EXPECT_FALSE(cache_entry.get()); | 300 EXPECT_FALSE(cache_entry.get()); |
300 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_baz.local"))); | 301 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_baz.local"))); |
301 | 302 |
302 // "id_bad" should be removed during cache initialization. | 303 // "id_bad" should be removed during cache initialization. |
303 cache_entry = metadata_->GetCacheEntry("id_bad", "md5bad"); | 304 cache_entry = metadata_->GetCacheEntry("id_bad", "md5bad"); |
304 EXPECT_FALSE(cache_entry.get()); | 305 EXPECT_FALSE(cache_entry.get()); |
305 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_bad.md5bad"))); | 306 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_bad.md5bad"))); |
306 | 307 |
307 // "id_symlink" should be removed during cache initialization. | 308 // "id_symlink" should be removed during cache initialization. |
308 cache_entry = metadata_->GetCacheEntry("id_symlink", ""); | 309 cache_entry = metadata_->GetCacheEntry("id_symlink", ""); |
309 EXPECT_FALSE(cache_entry.get()); | 310 EXPECT_FALSE(cache_entry.get()); |
310 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_symlink"))); | 311 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_symlink"))); |
311 | 312 |
312 // Check contents in "tmp" directory. | 313 // Check contents in "tmp" directory. |
313 // | 314 // |
314 // "id_qux" is just present in tmp directory. | 315 // "id_qux" is just present in tmp directory. |
315 cache_entry = metadata_->GetCacheEntry("id_qux", "md5qux"); | 316 cache_entry = metadata_->GetCacheEntry("id_qux", "md5qux"); |
316 ASSERT_TRUE(cache_entry.get()); | 317 ASSERT_TRUE(cache_entry.get()); |
317 EXPECT_EQ("md5qux", cache_entry->md5); | 318 EXPECT_EQ("md5qux", cache_entry->md5); |
318 EXPECT_EQ(GDataCache::CACHE_TYPE_TMP, cache_entry->GetSubDirectoryType()); | 319 EXPECT_EQ(GDataCache::CACHE_TYPE_TMP, cache_entry->sub_dir_type); |
319 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry->cache_state); | 320 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry->cache_state); |
320 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux"))); | 321 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux"))); |
321 | 322 |
322 // "id_quux" should be removed during cache initialization. | 323 // "id_quux" should be removed during cache initialization. |
323 cache_entry = metadata_->GetCacheEntry("id_quux", "md5qux"); | 324 cache_entry = metadata_->GetCacheEntry("id_quux", "md5qux"); |
324 EXPECT_FALSE(cache_entry.get()); | 325 EXPECT_FALSE(cache_entry.get()); |
325 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_quux.local"))); | 326 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_quux.local"))); |
326 | 327 |
327 // "id_symlink_tmp" should be removed during cache initialization. | 328 // "id_symlink_tmp" should be removed during cache initialization. |
328 cache_entry = metadata_->GetCacheEntry("id_symlink_tmp", ""); | 329 cache_entry = metadata_->GetCacheEntry("id_symlink_tmp", ""); |
329 EXPECT_FALSE(cache_entry.get()); | 330 EXPECT_FALSE(cache_entry.get()); |
330 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_symlink_tmp"))); | 331 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_symlink_tmp"))); |
331 | 332 |
332 // Check contents in "pinned" directory. | 333 // Check contents in "pinned" directory. |
333 // | 334 // |
334 // "id_corge" is pinned but not present. | 335 // "id_corge" is pinned but not present. |
335 cache_entry = metadata_->GetCacheEntry("id_corge", ""); | 336 cache_entry = metadata_->GetCacheEntry("id_corge", ""); |
336 ASSERT_TRUE(cache_entry.get()); | 337 ASSERT_TRUE(cache_entry.get()); |
337 EXPECT_EQ("", cache_entry->md5); | 338 EXPECT_EQ("", cache_entry->md5); |
| 339 EXPECT_EQ(GDataCache::CACHE_TYPE_TMP, cache_entry->sub_dir_type); |
338 EXPECT_EQ(GDataCache::CACHE_STATE_PINNED, cache_entry->cache_state); | 340 EXPECT_EQ(GDataCache::CACHE_STATE_PINNED, cache_entry->cache_state); |
339 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_corge"))); | 341 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_corge"))); |
340 | 342 |
341 // "id_dangling" should be removed during cache initialization. | 343 // "id_dangling" should be removed during cache initialization. |
342 cache_entry = metadata_->GetCacheEntry("id_dangling", ""); | 344 cache_entry = metadata_->GetCacheEntry("id_dangling", ""); |
343 EXPECT_FALSE(cache_entry.get()); | 345 EXPECT_FALSE(cache_entry.get()); |
344 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_dangling"))); | 346 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_dangling"))); |
345 | 347 |
346 // "id_outside" should be removed during cache initialization. | 348 // "id_outside" should be removed during cache initialization. |
347 cache_entry = metadata_->GetCacheEntry("id_outside", ""); | 349 cache_entry = metadata_->GetCacheEntry("id_outside", ""); |
348 EXPECT_FALSE(cache_entry.get()); | 350 EXPECT_FALSE(cache_entry.get()); |
349 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_outside"))); | 351 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_outside"))); |
350 | 352 |
351 // "id_not_symlink" should be removed during cache initialization. | 353 // "id_not_symlink" should be removed during cache initialization. |
352 cache_entry = metadata_->GetCacheEntry("id_not_symlink", ""); | 354 cache_entry = metadata_->GetCacheEntry("id_not_symlink", ""); |
353 EXPECT_FALSE(cache_entry.get()); | 355 EXPECT_FALSE(cache_entry.get()); |
354 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_not_symlink"))); | 356 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_not_symlink"))); |
355 } | 357 } |
356 | 358 |
357 // Test GDataCacheMetadataMap::RemoveTemporaryFiles. | 359 // Test GDataCacheMetadataMap::RemoveTemporaryFiles. |
358 TEST_F(GDataCacheMetadataMapTest, RemoveTemporaryFilesTest) { | 360 TEST_F(GDataCacheMetadataMapTest, RemoveTemporaryFilesTest) { |
359 SetUpCacheMetadata(); | 361 SetUpCacheMetadata(); |
360 | 362 |
361 GDataCacheMetadataMap::CacheMap cache_map; | 363 GDataCacheMetadataMap::CacheMap cache_map; |
362 InsertIntoMap(&cache_map, | 364 InsertIntoMap(&cache_map, |
363 "<resource_id_1>", | 365 "<resource_id_1>", |
364 "<md5>", | 366 "<md5>", |
| 367 GDataCache::CACHE_TYPE_TMP, |
365 GDataCache::CACHE_STATE_PRESENT); | 368 GDataCache::CACHE_STATE_PRESENT); |
366 InsertIntoMap(&cache_map, | 369 InsertIntoMap(&cache_map, |
367 "<resource_id_2>", | 370 "<resource_id_2>", |
368 "<md5>", | 371 "<md5>", |
369 GDataCache::CACHE_STATE_PRESENT | | 372 GDataCache::CACHE_TYPE_PERSISTENT, |
370 GDataCache::CACHE_STATE_PERSISTENT); | 373 GDataCache::CACHE_STATE_PRESENT); |
371 InsertIntoMap(&cache_map, | 374 InsertIntoMap(&cache_map, |
372 "<resource_id_3>", | 375 "<resource_id_3>", |
373 "<md5>", | 376 "<md5>", |
374 GDataCache::CACHE_STATE_PRESENT | | 377 GDataCache::CACHE_TYPE_PERSISTENT, |
375 GDataCache::CACHE_STATE_PERSISTENT); | 378 GDataCache::CACHE_STATE_PRESENT); |
376 InsertIntoMap(&cache_map, | 379 InsertIntoMap(&cache_map, |
377 "<resource_id_4>", | 380 "<resource_id_4>", |
378 "<md5>", | 381 "<md5>", |
| 382 GDataCache::CACHE_TYPE_TMP, |
379 GDataCache::CACHE_STATE_PRESENT); | 383 GDataCache::CACHE_STATE_PRESENT); |
380 | 384 |
381 metadata_->cache_map_ = cache_map; | 385 metadata_->cache_map_ = cache_map; |
382 metadata_->RemoveTemporaryFiles(); | 386 metadata_->RemoveTemporaryFiles(); |
383 // resource 1 and 4 should be gone, as these are temporary. | 387 // resource 1 and 4 should be gone, as these are CACHE_TYPE_TMP. |
384 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_1>", "").get()); | 388 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_1>", "").get()); |
385 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_2>", "").get()); | 389 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_2>", "").get()); |
386 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_3>", "").get()); | 390 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_3>", "").get()); |
387 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_4>", "").get()); | 391 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_4>", "").get()); |
388 } | 392 } |
389 | 393 |
390 } // namespace gdata | 394 } // namespace gdata |
OLD | NEW |