| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 int cache_state) { | 119 int cache_state) { |
| 120 cache_map->insert(std::make_pair( | 120 cache_map->insert(std::make_pair( |
| 121 resource_id, GDataCache::CacheEntry(md5, cache_state))); | 121 resource_id, GDataCacheEntry(md5, cache_state))); |
| 122 } | 122 } |
| 123 | 123 |
| 124 ScopedTempDir temp_dir_; | 124 ScopedTempDir temp_dir_; |
| 125 scoped_ptr<GDataCacheMetadataMap> metadata_; | 125 scoped_ptr<GDataCacheMetadataMap> metadata_; |
| 126 std::vector<FilePath> cache_paths_; | 126 std::vector<FilePath> cache_paths_; |
| 127 FilePath persistent_directory_; | 127 FilePath persistent_directory_; |
| 128 FilePath tmp_directory_; | 128 FilePath tmp_directory_; |
| 129 FilePath pinned_directory_; | 129 FilePath pinned_directory_; |
| 130 FilePath outgoing_directory_; | 130 FilePath outgoing_directory_; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 // Test all the methods of GDataCacheMetadataMap except for | 133 // Test all the methods of GDataCacheMetadataMap except for |
| 134 // RemoveTemporaryFiles. | 134 // RemoveTemporaryFiles. |
| 135 TEST_F(GDataCacheMetadataMapTest, CacheTest) { | 135 TEST_F(GDataCacheMetadataMapTest, CacheTest) { |
| 136 SetUpCacheMetadata(); | 136 SetUpCacheMetadata(); |
| 137 | 137 |
| 138 // Save an initial entry. | 138 // Save an initial entry. |
| 139 std::string test_resource_id("test_resource_id"); | 139 std::string test_resource_id("test_resource_id"); |
| 140 std::string test_file_md5("test_file_md5"); | 140 std::string test_file_md5("test_file_md5"); |
| 141 GDataCache::CacheSubDirectoryType test_sub_dir_type = | 141 GDataCache::CacheSubDirectoryType test_sub_dir_type = |
| 142 GDataCache::CACHE_TYPE_PERSISTENT; | 142 GDataCache::CACHE_TYPE_PERSISTENT; |
| 143 int test_cache_state = (GDataCache::CACHE_STATE_PRESENT | | 143 int test_cache_state = (CACHE_STATE_PRESENT | |
| 144 GDataCache::CACHE_STATE_PERSISTENT); | 144 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 GDataCacheEntry(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<GDataCacheEntry> 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, GDataCache::GetSubDirectoryType(*cache_entry)); |
| 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 = 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 GDataCacheEntry(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, GDataCache::GetSubDirectoryType(*cache_entry)); |
| 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 = 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 GDataCacheEntry(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, GDataCache::GetSubDirectoryType(*cache_entry)); |
| 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 = 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 GDataCacheEntry(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, GDataCache::GetSubDirectoryType(*cache_entry)); |
| 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 = 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 GDataCacheEntry(test_file_md5, test_cache_state)); |
| 253 | 253 |
| 254 cache_entry = | 254 cache_entry = |
| 255 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); | 255 metadata_->GetCacheEntry(test_resource_id, std::string()).Pass(); |
| 256 EXPECT_FALSE(cache_entry.get()); | 256 EXPECT_FALSE(cache_entry.get()); |
| 257 } | 257 } |
| 258 | 258 |
| 259 TEST_F(GDataCacheMetadataMapTest, Initialization) { | 259 TEST_F(GDataCacheMetadataMapTest, Initialization) { |
| 260 using file_util::PathExists; | 260 using file_util::PathExists; |
| 261 using file_util::IsLink; | 261 using file_util::IsLink; |
| 262 SetUpCacheWithVariousFiles(); | 262 SetUpCacheWithVariousFiles(); |
| 263 | 263 |
| 264 // Some files are removed during cache initialization. Make sure these | 264 // Some files are removed during cache initialization. Make sure these |
| 265 // exist beforehand. | 265 // exist beforehand. |
| 266 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_baz.local"))); | 266 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_baz.local"))); |
| 267 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_bad.md5bad"))); | 267 EXPECT_TRUE(PathExists(persistent_directory_.AppendASCII("id_bad.md5bad"))); |
| 268 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_quux.local"))); | 268 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_quux.local"))); |
| 269 EXPECT_TRUE(PathExists(pinned_directory_.AppendASCII("id_not_symlink"))); | 269 EXPECT_TRUE(PathExists(pinned_directory_.AppendASCII("id_not_symlink"))); |
| 270 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_dangling"))); | 270 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_dangling"))); |
| 271 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_outside"))); | 271 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_outside"))); |
| 272 EXPECT_TRUE(IsLink(outgoing_directory_.AppendASCII("id_foo"))); | 272 EXPECT_TRUE(IsLink(outgoing_directory_.AppendASCII("id_foo"))); |
| 273 EXPECT_TRUE(IsLink(persistent_directory_.AppendASCII("id_symlink"))); | 273 EXPECT_TRUE(IsLink(persistent_directory_.AppendASCII("id_symlink"))); |
| 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<GDataCacheEntry> 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 GDataCache::GetSubDirectoryType(*cache_entry)); |
| 287 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_PINNED | | 287 EXPECT_EQ(CACHE_STATE_PRESENT | CACHE_STATE_PINNED | |
| 288 GDataCache::CACHE_STATE_PERSISTENT, | 288 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 GDataCache::GetSubDirectoryType(*cache_entry)); |
| 301 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT | GDataCache::CACHE_STATE_DIRTY | | 301 EXPECT_EQ(CACHE_STATE_PRESENT | CACHE_STATE_DIRTY | |
| 302 GDataCache::CACHE_STATE_PERSISTENT, | 302 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, |
| 329 EXPECT_EQ(GDataCache::CACHE_STATE_PRESENT, cache_entry->cache_state()); | 329 GDataCache::GetSubDirectoryType(*cache_entry)); |
| 330 EXPECT_EQ(CACHE_STATE_PRESENT, cache_entry->cache_state()); |
| 330 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux"))); | 331 EXPECT_TRUE(PathExists(tmp_directory_.AppendASCII("id_qux.md5qux"))); |
| 331 | 332 |
| 332 // "id_quux" should be removed during cache initialization. | 333 // "id_quux" should be removed during cache initialization. |
| 333 cache_entry = metadata_->GetCacheEntry("id_quux", "md5qux"); | 334 cache_entry = metadata_->GetCacheEntry("id_quux", "md5qux"); |
| 334 EXPECT_FALSE(cache_entry.get()); | 335 EXPECT_FALSE(cache_entry.get()); |
| 335 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_quux.local"))); | 336 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_quux.local"))); |
| 336 | 337 |
| 337 // "id_symlink_tmp" should be removed during cache initialization. | 338 // "id_symlink_tmp" should be removed during cache initialization. |
| 338 cache_entry = metadata_->GetCacheEntry("id_symlink_tmp", ""); | 339 cache_entry = metadata_->GetCacheEntry("id_symlink_tmp", ""); |
| 339 EXPECT_FALSE(cache_entry.get()); | 340 EXPECT_FALSE(cache_entry.get()); |
| 340 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_symlink_tmp"))); | 341 EXPECT_FALSE(PathExists(pinned_directory_.AppendASCII("id_symlink_tmp"))); |
| 341 | 342 |
| 342 // Check contents in "pinned" directory. | 343 // Check contents in "pinned" directory. |
| 343 // | 344 // |
| 344 // "id_corge" is pinned but not present. | 345 // "id_corge" is pinned but not present. |
| 345 cache_entry = metadata_->GetCacheEntry("id_corge", ""); | 346 cache_entry = metadata_->GetCacheEntry("id_corge", ""); |
| 346 ASSERT_TRUE(cache_entry.get()); | 347 ASSERT_TRUE(cache_entry.get()); |
| 347 EXPECT_EQ("", cache_entry->md5()); | 348 EXPECT_EQ("", cache_entry->md5()); |
| 348 EXPECT_EQ(GDataCache::CACHE_STATE_PINNED, cache_entry->cache_state()); | 349 EXPECT_EQ(CACHE_STATE_PINNED, cache_entry->cache_state()); |
| 349 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_corge"))); | 350 EXPECT_TRUE(IsLink(pinned_directory_.AppendASCII("id_corge"))); |
| 350 | 351 |
| 351 // "id_dangling" should be removed during cache initialization. | 352 // "id_dangling" should be removed during cache initialization. |
| 352 cache_entry = metadata_->GetCacheEntry("id_dangling", ""); | 353 cache_entry = metadata_->GetCacheEntry("id_dangling", ""); |
| 353 EXPECT_FALSE(cache_entry.get()); | 354 EXPECT_FALSE(cache_entry.get()); |
| 354 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_dangling"))); | 355 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_dangling"))); |
| 355 | 356 |
| 356 // "id_outside" should be removed during cache initialization. | 357 // "id_outside" should be removed during cache initialization. |
| 357 cache_entry = metadata_->GetCacheEntry("id_outside", ""); | 358 cache_entry = metadata_->GetCacheEntry("id_outside", ""); |
| 358 EXPECT_FALSE(cache_entry.get()); | 359 EXPECT_FALSE(cache_entry.get()); |
| 359 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_outside"))); | 360 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_outside"))); |
| 360 | 361 |
| 361 // "id_not_symlink" should be removed during cache initialization. | 362 // "id_not_symlink" should be removed during cache initialization. |
| 362 cache_entry = metadata_->GetCacheEntry("id_not_symlink", ""); | 363 cache_entry = metadata_->GetCacheEntry("id_not_symlink", ""); |
| 363 EXPECT_FALSE(cache_entry.get()); | 364 EXPECT_FALSE(cache_entry.get()); |
| 364 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_not_symlink"))); | 365 EXPECT_FALSE(IsLink(pinned_directory_.AppendASCII("id_not_symlink"))); |
| 365 } | 366 } |
| 366 | 367 |
| 367 // Test GDataCacheMetadataMap::RemoveTemporaryFiles. | 368 // Test GDataCacheMetadataMap::RemoveTemporaryFiles. |
| 368 TEST_F(GDataCacheMetadataMapTest, RemoveTemporaryFilesTest) { | 369 TEST_F(GDataCacheMetadataMapTest, RemoveTemporaryFilesTest) { |
| 369 SetUpCacheMetadata(); | 370 SetUpCacheMetadata(); |
| 370 | 371 |
| 371 GDataCacheMetadataMap::CacheMap cache_map; | 372 GDataCacheMetadataMap::CacheMap cache_map; |
| 372 InsertIntoMap(&cache_map, | 373 InsertIntoMap(&cache_map, |
| 373 "<resource_id_1>", | 374 "<resource_id_1>", |
| 374 "<md5>", | 375 "<md5>", |
| 375 GDataCache::CACHE_STATE_PRESENT); | 376 CACHE_STATE_PRESENT); |
| 376 InsertIntoMap(&cache_map, | 377 InsertIntoMap(&cache_map, |
| 377 "<resource_id_2>", | 378 "<resource_id_2>", |
| 378 "<md5>", | 379 "<md5>", |
| 379 GDataCache::CACHE_STATE_PRESENT | | 380 CACHE_STATE_PRESENT | |
| 380 GDataCache::CACHE_STATE_PERSISTENT); | 381 CACHE_STATE_PERSISTENT); |
| 381 InsertIntoMap(&cache_map, | 382 InsertIntoMap(&cache_map, |
| 382 "<resource_id_3>", | 383 "<resource_id_3>", |
| 383 "<md5>", | 384 "<md5>", |
| 384 GDataCache::CACHE_STATE_PRESENT | | 385 CACHE_STATE_PRESENT | |
| 385 GDataCache::CACHE_STATE_PERSISTENT); | 386 CACHE_STATE_PERSISTENT); |
| 386 InsertIntoMap(&cache_map, | 387 InsertIntoMap(&cache_map, |
| 387 "<resource_id_4>", | 388 "<resource_id_4>", |
| 388 "<md5>", | 389 "<md5>", |
| 389 GDataCache::CACHE_STATE_PRESENT); | 390 CACHE_STATE_PRESENT); |
| 390 | 391 |
| 391 metadata_->cache_map_ = cache_map; | 392 metadata_->cache_map_ = cache_map; |
| 392 metadata_->RemoveTemporaryFiles(); | 393 metadata_->RemoveTemporaryFiles(); |
| 393 // resource 1 and 4 should be gone, as these are temporary. | 394 // resource 1 and 4 should be gone, as these are temporary. |
| 394 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_1>", "").get()); | 395 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_1>", "").get()); |
| 395 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_2>", "").get()); | 396 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_2>", "").get()); |
| 396 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_3>", "").get()); | 397 EXPECT_TRUE(metadata_->GetCacheEntry("<resource_id_3>", "").get()); |
| 397 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_4>", "").get()); | 398 EXPECT_FALSE(metadata_->GetCacheEntry("<resource_id_4>", "").get()); |
| 398 } | 399 } |
| 399 | 400 |
| 400 } // namespace gdata | 401 } // namespace gdata |
| OLD | NEW |