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

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

Issue 10698157: gdata: Make GDataCache::CacheEntry a struct (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 int test_cache_state = (GDataCache::CACHE_STATE_PRESENT | 143 int test_cache_state = (GDataCache::CACHE_STATE_PRESENT |
144 GDataCache::CACHE_STATE_PERSISTENT); 144 GDataCache::CACHE_STATE_PERSISTENT);
145 metadata_->UpdateCache( 145 metadata_->UpdateCache(
146 test_resource_id, 146 test_resource_id,
147 GDataCache::CacheEntry(test_file_md5, test_cache_state)); 147 GDataCache::CacheEntry(test_file_md5, test_cache_state));
148 148
149 // Test that the entry can be retrieved. 149 // Test that the entry can be retrieved.
150 scoped_ptr<GDataCache::CacheEntry> cache_entry = 150 scoped_ptr<GDataCache::CacheEntry> cache_entry =
151 metadata_->GetCacheEntry(test_resource_id, test_file_md5); 151 metadata_->GetCacheEntry(test_resource_id, test_file_md5);
152 ASSERT_TRUE(cache_entry.get()); 152 ASSERT_TRUE(cache_entry.get());
153 EXPECT_EQ(test_file_md5, cache_entry->md5); 153 EXPECT_EQ(test_file_md5, cache_entry->md5());
154 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType()); 154 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType());
155 EXPECT_EQ(test_cache_state, cache_entry->cache_state); 155 EXPECT_EQ(test_cache_state, cache_entry->cache_state());
156 156
157 // Empty md5 should also work. 157 // Empty md5 should also work.
158 cache_entry = 158 cache_entry =
159 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); 159 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass();
160 ASSERT_TRUE(cache_entry.get()); 160 ASSERT_TRUE(cache_entry.get());
161 EXPECT_EQ(test_file_md5, cache_entry->md5); 161 EXPECT_EQ(test_file_md5, cache_entry->md5());
162 162
163 // resource_id doesn't exist. 163 // resource_id doesn't exist.
164 cache_entry = metadata_->GetCacheEntry("not_found_resource_id", 164 cache_entry = metadata_->GetCacheEntry("not_found_resource_id",
165 std::string()).Pass(); 165 std::string()).Pass();
166 EXPECT_FALSE(cache_entry.get()); 166 EXPECT_FALSE(cache_entry.get());
167 167
168 // md5 doesn't match. 168 // md5 doesn't match.
169 cache_entry = 169 cache_entry =
170 metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass(); 170 metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass();
171 EXPECT_FALSE(cache_entry.get()); 171 EXPECT_FALSE(cache_entry.get());
172 172
173 // Update all attributes. 173 // Update all attributes.
174 test_file_md5 = "test_file_md5_2"; 174 test_file_md5 = "test_file_md5_2";
175 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; 175 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP;
176 test_cache_state = GDataCache::CACHE_STATE_PINNED; 176 test_cache_state = GDataCache::CACHE_STATE_PINNED;
177 metadata_->UpdateCache( 177 metadata_->UpdateCache(
178 test_resource_id, 178 test_resource_id,
179 GDataCache::CacheEntry(test_file_md5, test_cache_state)); 179 GDataCache::CacheEntry(test_file_md5, test_cache_state));
180 180
181 // Make sure the values took. 181 // Make sure the values took.
182 cache_entry = 182 cache_entry =
183 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); 183 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass();
184 ASSERT_TRUE(cache_entry.get()); 184 ASSERT_TRUE(cache_entry.get());
185 EXPECT_EQ(test_file_md5, cache_entry->md5); 185 EXPECT_EQ(test_file_md5, cache_entry->md5());
186 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType()); 186 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType());
187 EXPECT_EQ(test_cache_state, cache_entry->cache_state); 187 EXPECT_EQ(test_cache_state, cache_entry->cache_state());
188 188
189 // Empty m5 should work. 189 // Empty m5 should work.
190 cache_entry = 190 cache_entry =
191 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); 191 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass();
192 ASSERT_TRUE(cache_entry.get()); 192 ASSERT_TRUE(cache_entry.get());
193 EXPECT_EQ(test_file_md5, cache_entry->md5); 193 EXPECT_EQ(test_file_md5, cache_entry->md5());
194 194
195 // Test dirty cache. 195 // Test dirty cache.
196 test_file_md5 = "test_file_md5_3"; 196 test_file_md5 = "test_file_md5_3";
197 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; 197 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP;
198 test_cache_state = GDataCache::CACHE_STATE_DIRTY; 198 test_cache_state = GDataCache::CACHE_STATE_DIRTY;
199 metadata_->UpdateCache( 199 metadata_->UpdateCache(
200 test_resource_id, 200 test_resource_id,
201 GDataCache::CacheEntry(test_file_md5, test_cache_state)); 201 GDataCache::CacheEntry(test_file_md5, test_cache_state));
202 202
203 // Make sure the values took. 203 // Make sure the values took.
204 cache_entry = 204 cache_entry =
205 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); 205 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass();
206 ASSERT_TRUE(cache_entry.get()); 206 ASSERT_TRUE(cache_entry.get());
207 EXPECT_EQ(test_file_md5, cache_entry->md5); 207 EXPECT_EQ(test_file_md5, cache_entry->md5());
208 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType()); 208 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType());
209 EXPECT_EQ(test_cache_state, cache_entry->cache_state); 209 EXPECT_EQ(test_cache_state, cache_entry->cache_state());
210 210
211 // Empty md5 should work. 211 // Empty md5 should work.
212 cache_entry = 212 cache_entry =
213 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); 213 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass();
214 ASSERT_TRUE(cache_entry.get()); 214 ASSERT_TRUE(cache_entry.get());
215 EXPECT_EQ(test_file_md5, cache_entry->md5); 215 EXPECT_EQ(test_file_md5, cache_entry->md5());
216 216
217 // Mismatched md5 should also work for dirty entries. 217 // Mismatched md5 should also work for dirty entries.
218 cache_entry = 218 cache_entry =
219 metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass(); 219 metadata_->GetCacheEntry(test_resource_id, "mismatch_md5").Pass();
220 ASSERT_TRUE(cache_entry.get()); 220 ASSERT_TRUE(cache_entry.get());
221 EXPECT_EQ(test_file_md5, cache_entry->md5); 221 EXPECT_EQ(test_file_md5, cache_entry->md5());
222 222
223 // Remove the entry. 223 // Remove the entry.
224 metadata_->RemoveFromCache(test_resource_id); 224 metadata_->RemoveFromCache(test_resource_id);
225 cache_entry = 225 cache_entry =
226 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); 226 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass();
227 EXPECT_FALSE(cache_entry.get()); 227 EXPECT_FALSE(cache_entry.get());
228 228
229 // Add another one. 229 // Add another one.
230 test_resource_id = "test_resource_id_2"; 230 test_resource_id = "test_resource_id_2";
231 test_file_md5 = "test_file_md5_4"; 231 test_file_md5 = "test_file_md5_4";
232 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; 232 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP;
233 test_cache_state = GDataCache::CACHE_STATE_PRESENT; 233 test_cache_state = GDataCache::CACHE_STATE_PRESENT;
234 metadata_->UpdateCache( 234 metadata_->UpdateCache(
235 test_resource_id, 235 test_resource_id,
236 GDataCache::CacheEntry(test_file_md5, test_cache_state)); 236 GDataCache::CacheEntry(test_file_md5, test_cache_state));
237 237
238 // Make sure the values took. 238 // Make sure the values took.
239 cache_entry = 239 cache_entry =
240 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass(); 240 metadata_->GetCacheEntry(test_resource_id, test_file_md5).Pass();
241 ASSERT_TRUE(cache_entry.get()); 241 ASSERT_TRUE(cache_entry.get());
242 EXPECT_EQ(test_file_md5, cache_entry->md5); 242 EXPECT_EQ(test_file_md5, cache_entry->md5());
243 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType()); 243 EXPECT_EQ(test_sub_dir_type, cache_entry->GetSubDirectoryType());
244 EXPECT_EQ(test_cache_state, cache_entry->cache_state); 244 EXPECT_EQ(test_cache_state, cache_entry->cache_state());
245 245
246 // Update with CACHE_STATE_NONE should evict the entry. 246 // Update with CACHE_STATE_NONE should evict the entry.
247 test_file_md5 = "test_file_md5_5"; 247 test_file_md5 = "test_file_md5_5";
248 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP; 248 test_sub_dir_type = GDataCache::CACHE_TYPE_TMP;
249 test_cache_state = GDataCache::CACHE_STATE_NONE; 249 test_cache_state = GDataCache::CACHE_STATE_NONE;
250 metadata_->UpdateCache( 250 metadata_->UpdateCache(
251 test_resource_id, 251 test_resource_id,
252 GDataCache::CacheEntry(test_file_md5, test_cache_state)); 252 GDataCache::CacheEntry(test_file_md5, test_cache_state));
253 253
254 cache_entry = 254 cache_entry =
(...skipping 19 matching lines...) Expand all
274 EXPECT_TRUE(IsLink(tmp_directory_.AppendASCII("id_symlink_tmp"))); 274 EXPECT_TRUE(IsLink(tmp_directory_.AppendASCII("id_symlink_tmp")));
275 275
276 SetUpCacheMetadata(); 276 SetUpCacheMetadata();
277 277
278 // Check contents in "persistent" directory. 278 // Check contents in "persistent" directory.
279 // 279 //
280 // "id_foo" is present and pinned. 280 // "id_foo" is present and pinned.
281 scoped_ptr<GDataCache::CacheEntry> cache_entry; 281 scoped_ptr<GDataCache::CacheEntry> cache_entry;
282 cache_entry = metadata_->GetCacheEntry("id_foo", "md5foo"); 282 cache_entry = metadata_->GetCacheEntry("id_foo", "md5foo");
283 ASSERT_TRUE(cache_entry.get()); 283 ASSERT_TRUE(cache_entry.get());
284 EXPECT_EQ("md5foo", cache_entry->md5); 284 EXPECT_EQ("md5foo", cache_entry->md5());
285 EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT, 285 EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT,
286 cache_entry->GetSubDirectoryType()); 286 cache_entry->GetSubDirectoryType());
287 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | 287 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED |
288 GDataCache::CACHE_STATE_PERSISTENT, 288 GDataCache::CACHE_STATE_PERSISTENT,
289 cache_entry->cache_state); 289 cache_entry->cache_state());
290 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_foo.md5foo"))); 290 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_foo.md5foo")));
291 EXPECT_TRUE(PathExists(pinned_directory_.AppendASCII("id_foo"))); 291 EXPECT_TRUE(PathExists(pinned_directory_.AppendASCII("id_foo")));
292 // The invalid symlink in "outgoing" should be removed. 292 // The invalid symlink in "outgoing" should be removed.
293 EXPECT_FALSE(PathExists(outgoing_directory_.AppendASCII("id_foo"))); 293 EXPECT_FALSE(PathExists(outgoing_directory_.AppendASCII("id_foo")));
294 294
295 // "id_bar" is present and dirty. 295 // "id_bar" is present and dirty.
296 cache_entry = metadata_->GetCacheEntry("id_bar", ""); 296 cache_entry = metadata_->GetCacheEntry("id_bar", "");
297 ASSERT_TRUE(cache_entry.get()); 297 ASSERT_TRUE(cache_entry.get());
298 EXPECT_EQ("local", cache_entry->md5); 298 EXPECT_EQ("local", cache_entry->md5());
299 EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT, 299 EXPECT_EQ(GDataCache::CACHE_TYPE_PERSISTENT,
300 cache_entry->GetSubDirectoryType()); 300 cache_entry->GetSubDirectoryType());
301 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY | 301 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY |
302 GDataCache::CACHE_STATE_PERSISTENT, 302 GDataCache::CACHE_STATE_PERSISTENT,
303 cache_entry->cache_state); 303 cache_entry->cache_state());
304 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_bar.local"))); 304 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_bar.local")));
305 EXPECT_TRUE(PathExists(outgoing_directory_.AppendASCII("id_bar"))); 305 EXPECT_TRUE(PathExists(outgoing_directory_.AppendASCII("id_bar")));
306 306
307 // "id_baz" should be removed during cache initialization. 307 // "id_baz" should be removed during cache initialization.
308 cache_entry = metadata_->GetCacheEntry("id_baz", ""); 308 cache_entry = metadata_->GetCacheEntry("id_baz", "");
309 EXPECT_FALSE(cache_entry.get()); 309 EXPECT_FALSE(cache_entry.get());
310 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_baz.local"))); 310 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_baz.local")));
311 311
312 // "id_bad" should be removed during cache initialization. 312 // "id_bad" should be removed during cache initialization.
313 cache_entry = metadata_->GetCacheEntry("id_bad", "md5bad"); 313 cache_entry = metadata_->GetCacheEntry("id_bad", "md5bad");
314 EXPECT_FALSE(cache_entry.get()); 314 EXPECT_FALSE(cache_entry.get());
315 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_bad.md5bad"))); 315 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_bad.md5bad")));
316 316
317 // "id_symlink" should be removed during cache initialization. 317 // "id_symlink" should be removed during cache initialization.
318 cache_entry = metadata_->GetCacheEntry("id_symlink", ""); 318 cache_entry = metadata_->GetCacheEntry("id_symlink", "");
319 EXPECT_FALSE(cache_entry.get()); 319 EXPECT_FALSE(cache_entry.get());
320 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_symlink"))); 320 EXPECT_FALSE(PathExists(persistent_directory_.AppendASCII("id_symlink")));
321 321
322 // Check contents in "tmp" directory. 322 // Check contents in "tmp" directory.
323 // 323 //
324 // "id_qux" is just present in tmp directory. 324 // "id_qux" is just present in tmp directory.
325 cache_entry = metadata_->GetCacheEntry("id_qux", "md5qux"); 325 cache_entry = metadata_->GetCacheEntry("id_qux", "md5qux");
326 ASSERT_TRUE(cache_entry.get()); 326 ASSERT_TRUE(cache_entry.get());
327 EXPECT_EQ("md5qux", cache_entry->md5); 327 EXPECT_EQ("md5qux", cache_entry->md5());
328 EXPECT_EQ(GDataCache::CACHE_TYPE_TMP, cache_entry->GetSubDirectoryType()); 328 EXPECT_EQ(GDataCache::CACHE_TYPE_TMP, cache_entry->GetSubDirectoryType());
329 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry->cache_state); 329 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry->cache_state());
330 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux"))); 330 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux")));
331 331
332 // "id_quux" should be removed during cache initialization. 332 // "id_quux" should be removed during cache initialization.
333 cache_entry = metadata_->GetCacheEntry("id_quux", "md5qux"); 333 cache_entry = metadata_->GetCacheEntry("id_quux", "md5qux");
334 EXPECT_FALSE(cache_entry.get()); 334 EXPECT_FALSE(cache_entry.get());
335 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_quux.local"))); 335 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_quux.local")));
336 336
337 // "id_symlink_tmp" should be removed during cache initialization. 337 // "id_symlink_tmp" should be removed during cache initialization.
338 cache_entry = metadata_->GetCacheEntry("id_symlink_tmp", ""); 338 cache_entry = metadata_->GetCacheEntry("id_symlink_tmp", "");
339 EXPECT_FALSE(cache_entry.get()); 339 EXPECT_FALSE(cache_entry.get());
340 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_symlink_tmp"))); 340 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_symlink_tmp")));
341 341
342 // Check contents in "pinned" directory. 342 // Check contents in "pinned" directory.
343 // 343 //
344 // "id_corge" is pinned but not present. 344 // "id_corge" is pinned but not present.
345 cache_entry = metadata_->GetCacheEntry("id_corge", ""); 345 cache_entry = metadata_->GetCacheEntry("id_corge", "");
346 ASSERT_TRUE(cache_entry.get()); 346 ASSERT_TRUE(cache_entry.get());
347 EXPECT_EQ("", cache_entry->md5); 347 EXPECT_EQ("", cache_entry->md5());
348 EXPECT_EQ(GDataCache::CACHE_STATE_PINNED, cache_entry->cache_state); 348 EXPECT_EQ(GDataCache::CACHE_STATE_PINNED, cache_entry->cache_state());
349 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_corge"))); 349 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_corge")));
350 350
351 // "id_dangling" should be removed during cache initialization. 351 // "id_dangling" should be removed during cache initialization.
352 cache_entry = metadata_->GetCacheEntry("id_dangling", ""); 352 cache_entry = metadata_->GetCacheEntry("id_dangling", "");
353 EXPECT_FALSE(cache_entry.get()); 353 EXPECT_FALSE(cache_entry.get());
354 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_dangling"))); 354 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_dangling")));
355 355
356 // "id_outside" should be removed during cache initialization. 356 // "id_outside" should be removed during cache initialization.
357 cache_entry = metadata_->GetCacheEntry("id_outside", ""); 357 cache_entry = metadata_->GetCacheEntry("id_outside", "");
358 EXPECT_FALSE(cache_entry.get()); 358 EXPECT_FALSE(cache_entry.get());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 metadata_->cache_map_ = cache_map; 391 metadata_->cache_map_ = cache_map;
392 metadata_->RemoveTemporaryFiles(); 392 metadata_->RemoveTemporaryFiles();
393 // resource 1 and 4 should be gone, as these are temporary. 393 // resource 1 and 4 should be gone, as these are temporary.
394 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_1>", "").get()); 394 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_1>", "").get());
395 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_2>", "").get()); 395 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_2>", "").get());
396 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_3>", "").get()); 396 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_3>", "").get());
397 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_4>", "").get()); 397 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_4>", "").get());
398 } 398 }
399 399
400 } // namespace gdata 400 } // 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