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

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

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

Powered by Google App Engine
This is Rietveld 408576698