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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_cache_metadata_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698