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

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