Chromium Code Reviews| 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/drive/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 *out_is_called = true; | 39 *out_is_called = true; |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 // Tests FileCache methods from UI thread. It internally uses a real blocking | 44 // Tests FileCache methods from UI thread. It internally uses a real blocking |
| 45 // pool and tests the interaction among threads. | 45 // pool and tests the interaction among threads. |
| 46 // TODO(hashimoto): remove this class. crbug.com/231221. | 46 // TODO(hashimoto): remove this class. crbug.com/231221. |
| 47 class FileCacheTestOnUIThread : public testing::Test { | 47 class FileCacheTestOnUIThread : public testing::Test { |
| 48 protected: | 48 protected: |
| 49 FileCacheTestOnUIThread() | 49 FileCacheTestOnUIThread() : expected_error_(FILE_ERROR_OK), |
| 50 : expected_error_(FILE_ERROR_OK), | 50 expected_cache_state_(0) { |
| 51 expected_cache_state_(0), | |
| 52 expected_sub_dir_type_(FileCache::CACHE_TYPE_META), | |
| 53 expected_success_(true) { | |
| 54 } | 51 } |
| 55 | 52 |
| 56 virtual void SetUp() OVERRIDE { | 53 virtual void SetUp() OVERRIDE { |
| 57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 54 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 58 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), | 55 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), |
| 59 &dummy_file_path_)); | 56 &dummy_file_path_)); |
| 60 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); | 57 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); |
| 61 | 58 |
| 62 scoped_refptr<base::SequencedWorkerPool> pool = | 59 scoped_refptr<base::SequencedWorkerPool> pool = |
| 63 content::BrowserThread::GetBlockingPool(); | 60 content::BrowserThread::GetBlockingPool(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 base::FilePath::kExtensionSeparator + | 95 base::FilePath::kExtensionSeparator + |
| 99 util::EscapeCacheFileName( | 96 util::EscapeCacheFileName( |
| 100 expected_file_extension.empty() ? | 97 expected_file_extension.empty() ? |
| 101 md5 : expected_file_extension), | 98 md5 : expected_file_extension), |
| 102 base_name.value()); | 99 base_name.value()); |
| 103 } else { | 100 } else { |
| 104 EXPECT_TRUE(cache_file_path.empty()); | 101 EXPECT_TRUE(cache_file_path.empty()); |
| 105 } | 102 } |
| 106 } | 103 } |
| 107 | 104 |
| 108 void TestStoreToCache( | 105 void TestStoreToCache(const std::string& resource_id, |
| 109 const std::string& resource_id, | 106 const std::string& md5, |
| 110 const std::string& md5, | 107 const base::FilePath& source_path, |
| 111 const base::FilePath& source_path, | 108 FileError expected_error, |
| 112 FileError expected_error, | 109 int expected_cache_state) { |
| 113 int expected_cache_state, | |
| 114 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
| 115 expected_error_ = expected_error; | 110 expected_error_ = expected_error; |
| 116 expected_cache_state_ = expected_cache_state; | 111 expected_cache_state_ = expected_cache_state; |
| 117 expected_sub_dir_type_ = expected_sub_dir_type; | |
| 118 | 112 |
| 119 FileError error = FILE_ERROR_OK; | 113 FileError error = FILE_ERROR_OK; |
| 120 cache_->StoreOnUIThread( | 114 cache_->StoreOnUIThread( |
| 121 resource_id, md5, source_path, | 115 resource_id, md5, source_path, |
| 122 FileCache::FILE_OPERATION_COPY, | 116 FileCache::FILE_OPERATION_COPY, |
| 123 google_apis::test_util::CreateCopyResultCallback(&error)); | 117 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 124 google_apis::test_util::RunBlockingPoolTask(); | 118 google_apis::test_util::RunBlockingPoolTask(); |
| 125 VerifyCacheFileState(error, resource_id, md5); | 119 VerifyCacheFileState(error, resource_id, md5); |
| 126 } | 120 } |
| 127 | 121 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 156 EXPECT_EQ(expected_error_, error); | 150 EXPECT_EQ(expected_error_, error); |
| 157 | 151 |
| 158 // Verify cache map. | 152 // Verify cache map. |
| 159 FileCacheEntry cache_entry; | 153 FileCacheEntry cache_entry; |
| 160 const bool cache_entry_found = | 154 const bool cache_entry_found = |
| 161 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); | 155 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); |
| 162 if (cache_entry_found) | 156 if (cache_entry_found) |
| 163 EXPECT_TRUE(cache_entry.is_dirty()); | 157 EXPECT_TRUE(cache_entry.is_dirty()); |
| 164 | 158 |
| 165 // If entry doesn't exist, verify that no files with "<resource_id>.*" | 159 // If entry doesn't exist, verify that no files with "<resource_id>.*" |
| 166 // exist in persistent and tmp dirs. | 160 // exist. |
| 167 const base::FilePath path_pattern_tmp = | 161 const base::FilePath path_pattern = cache_->GetCacheFilePath( |
| 168 cache_->GetCacheFilePath(resource_id, "*", | 162 resource_id, "*", FileCache::CACHED_FILE_FROM_SERVER); |
|
kinaba
2013/06/14 01:59:33
"*" => util::kWildCard?
hashimoto
2013/06/14 04:04:46
Done.
| |
| 169 FileCache::CACHE_TYPE_TMP, | |
| 170 FileCache::CACHED_FILE_FROM_SERVER); | |
| 171 const base::FilePath path_pattern_persistent = | |
| 172 cache_->GetCacheFilePath(resource_id, "*", | |
| 173 FileCache::CACHE_TYPE_PERSISTENT, | |
| 174 FileCache::CACHED_FILE_FROM_SERVER); | |
| 175 | |
| 176 EXPECT_EQ(0, CountFilesWithPathPattern(path_pattern_tmp)); | |
| 177 if (!cache_entry_found) { | 163 if (!cache_entry_found) { |
| 178 EXPECT_EQ(0, CountFilesWithPathPattern(path_pattern_persistent)); | 164 EXPECT_EQ(0, CountFilesWithPathPattern(path_pattern)); |
| 179 } else { | 165 } else { |
| 180 // Entry is dirty, verify that only 1 "<resource_id>.local" exists in | 166 // Entry is dirty, verify that only 1 "<resource_id>.local" exists. |
| 181 // persistent dir. | 167 EXPECT_EQ(1, CountFilesWithPathPattern(path_pattern)); |
| 182 EXPECT_EQ(1, CountFilesWithPathPattern(path_pattern_persistent)); | |
| 183 EXPECT_TRUE(file_util::PathExists( | 168 EXPECT_TRUE(file_util::PathExists( |
| 184 GetCacheFilePath(resource_id, | 169 GetCacheFilePath(resource_id, std::string(), |
| 185 std::string(), | |
| 186 FileCache::CACHE_TYPE_PERSISTENT, | |
| 187 FileCache::CACHED_FILE_LOCALLY_MODIFIED))); | 170 FileCache::CACHED_FILE_LOCALLY_MODIFIED))); |
| 188 } | 171 } |
| 189 } | 172 } |
| 190 | 173 |
| 191 void TestPin( | 174 void TestPin(const std::string& resource_id, |
| 192 const std::string& resource_id, | 175 const std::string& md5, |
| 193 const std::string& md5, | 176 FileError expected_error, |
| 194 FileError expected_error, | 177 int expected_cache_state) { |
| 195 int expected_cache_state, | |
| 196 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
| 197 expected_error_ = expected_error; | 178 expected_error_ = expected_error; |
| 198 expected_cache_state_ = expected_cache_state; | 179 expected_cache_state_ = expected_cache_state; |
| 199 expected_sub_dir_type_ = expected_sub_dir_type; | |
| 200 | 180 |
| 201 FileError error = FILE_ERROR_OK; | 181 FileError error = FILE_ERROR_OK; |
| 202 cache_->PinOnUIThread( | 182 cache_->PinOnUIThread( |
| 203 resource_id, md5, | 183 resource_id, md5, |
| 204 google_apis::test_util::CreateCopyResultCallback(&error)); | 184 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 205 google_apis::test_util::RunBlockingPoolTask(); | 185 google_apis::test_util::RunBlockingPoolTask(); |
| 206 VerifyCacheFileState(error, resource_id, md5); | 186 VerifyCacheFileState(error, resource_id, md5); |
| 207 } | 187 } |
| 208 | 188 |
| 209 void TestUnpin( | 189 void TestUnpin(const std::string& resource_id, |
| 210 const std::string& resource_id, | 190 const std::string& md5, |
| 211 const std::string& md5, | 191 FileError expected_error, |
| 212 FileError expected_error, | 192 int expected_cache_state) { |
| 213 int expected_cache_state, | |
| 214 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
| 215 expected_error_ = expected_error; | 193 expected_error_ = expected_error; |
| 216 expected_cache_state_ = expected_cache_state; | 194 expected_cache_state_ = expected_cache_state; |
| 217 expected_sub_dir_type_ = expected_sub_dir_type; | |
| 218 | 195 |
| 219 FileError error = FILE_ERROR_OK; | 196 FileError error = FILE_ERROR_OK; |
| 220 cache_->UnpinOnUIThread( | 197 cache_->UnpinOnUIThread( |
| 221 resource_id, md5, | 198 resource_id, md5, |
| 222 google_apis::test_util::CreateCopyResultCallback(&error)); | 199 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 223 google_apis::test_util::RunBlockingPoolTask(); | 200 google_apis::test_util::RunBlockingPoolTask(); |
| 224 VerifyCacheFileState(error, resource_id, md5); | 201 VerifyCacheFileState(error, resource_id, md5); |
| 225 } | 202 } |
| 226 | 203 |
| 227 void TestMarkDirty(const std::string& resource_id, | 204 void TestMarkDirty(const std::string& resource_id, |
| 228 const std::string& md5, | 205 const std::string& md5, |
| 229 FileError expected_error, | 206 FileError expected_error, |
| 230 int expected_cache_state, | 207 int expected_cache_state) { |
| 231 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
| 232 expected_error_ = expected_error; | 208 expected_error_ = expected_error; |
| 233 expected_cache_state_ = expected_cache_state; | 209 expected_cache_state_ = expected_cache_state; |
| 234 expected_sub_dir_type_ = expected_sub_dir_type; | |
| 235 | 210 |
| 236 FileError error = FILE_ERROR_OK; | 211 FileError error = FILE_ERROR_OK; |
| 237 cache_->MarkDirtyOnUIThread( | 212 cache_->MarkDirtyOnUIThread( |
| 238 resource_id, md5, | 213 resource_id, md5, |
| 239 google_apis::test_util::CreateCopyResultCallback(&error)); | 214 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 240 google_apis::test_util::RunBlockingPoolTask(); | 215 google_apis::test_util::RunBlockingPoolTask(); |
| 241 | 216 |
| 242 VerifyCacheFileState(error, resource_id, md5); | 217 VerifyCacheFileState(error, resource_id, md5); |
| 243 | 218 |
| 244 // Verify filename. | 219 // Verify filename. |
| 245 if (error == FILE_ERROR_OK) { | 220 if (error == FILE_ERROR_OK) { |
| 246 base::FilePath cache_file_path; | 221 base::FilePath cache_file_path; |
| 247 cache_->GetFileOnUIThread( | 222 cache_->GetFileOnUIThread( |
| 248 resource_id, md5, | 223 resource_id, md5, |
| 249 google_apis::test_util::CreateCopyResultCallback( | 224 google_apis::test_util::CreateCopyResultCallback( |
| 250 &error, &cache_file_path)); | 225 &error, &cache_file_path)); |
| 251 google_apis::test_util::RunBlockingPoolTask(); | 226 google_apis::test_util::RunBlockingPoolTask(); |
| 252 | 227 |
| 253 EXPECT_EQ(FILE_ERROR_OK, error); | 228 EXPECT_EQ(FILE_ERROR_OK, error); |
| 254 base::FilePath base_name = cache_file_path.BaseName(); | 229 base::FilePath base_name = cache_file_path.BaseName(); |
| 255 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + | 230 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + |
| 256 base::FilePath::kExtensionSeparator + | 231 base::FilePath::kExtensionSeparator + |
| 257 "local", | 232 "local", |
| 258 base_name.value()); | 233 base_name.value()); |
| 259 } | 234 } |
| 260 } | 235 } |
| 261 | 236 |
| 262 void TestClearDirty( | 237 void TestClearDirty(const std::string& resource_id, |
| 263 const std::string& resource_id, | 238 const std::string& md5, |
| 264 const std::string& md5, | 239 FileError expected_error, |
| 265 FileError expected_error, | 240 int expected_cache_state) { |
| 266 int expected_cache_state, | |
| 267 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
| 268 expected_error_ = expected_error; | 241 expected_error_ = expected_error; |
| 269 expected_cache_state_ = expected_cache_state; | 242 expected_cache_state_ = expected_cache_state; |
| 270 expected_sub_dir_type_ = expected_sub_dir_type; | |
| 271 | 243 |
| 272 FileError error = FILE_ERROR_OK; | 244 FileError error = FILE_ERROR_OK; |
| 273 PostTaskAndReplyWithResult( | 245 PostTaskAndReplyWithResult( |
| 274 blocking_task_runner_, | 246 blocking_task_runner_, |
| 275 FROM_HERE, | 247 FROM_HERE, |
| 276 base::Bind(&FileCache::ClearDirty, | 248 base::Bind(&FileCache::ClearDirty, |
| 277 base::Unretained(cache_.get()), | 249 base::Unretained(cache_.get()), |
| 278 resource_id, md5), | 250 resource_id, md5), |
| 279 google_apis::test_util::CreateCopyResultCallback(&error)); | 251 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 280 google_apis::test_util::RunBlockingPoolTask(); | 252 google_apis::test_util::RunBlockingPoolTask(); |
| 281 VerifyCacheFileState(error, resource_id, md5); | 253 VerifyCacheFileState(error, resource_id, md5); |
| 282 } | 254 } |
| 283 | 255 |
| 284 void TestMarkAsMounted( | 256 void TestMarkAsMounted(const std::string& resource_id, |
| 285 const std::string& resource_id, | 257 FileError expected_error, |
| 286 FileError expected_error, | 258 int expected_cache_state) { |
| 287 int expected_cache_state, | |
| 288 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
| 289 expected_error_ = expected_error; | 259 expected_error_ = expected_error; |
| 290 expected_cache_state_ = expected_cache_state; | 260 expected_cache_state_ = expected_cache_state; |
| 291 expected_sub_dir_type_ = expected_sub_dir_type; | |
| 292 | 261 |
| 293 FileCacheEntry entry; | 262 FileCacheEntry entry; |
| 294 EXPECT_TRUE(GetCacheEntryFromOriginThread(resource_id, std::string(), | 263 EXPECT_TRUE(GetCacheEntryFromOriginThread(resource_id, std::string(), |
| 295 &entry)); | 264 &entry)); |
| 296 | 265 |
| 297 FileError error = FILE_ERROR_OK; | 266 FileError error = FILE_ERROR_OK; |
| 298 base::FilePath cache_file_path; | 267 base::FilePath cache_file_path; |
| 299 cache_->MarkAsMountedOnUIThread( | 268 cache_->MarkAsMountedOnUIThread( |
| 300 resource_id, | 269 resource_id, |
| 301 google_apis::test_util::CreateCopyResultCallback( | 270 google_apis::test_util::CreateCopyResultCallback( |
| 302 &error, &cache_file_path)); | 271 &error, &cache_file_path)); |
| 303 google_apis::test_util::RunBlockingPoolTask(); | 272 google_apis::test_util::RunBlockingPoolTask(); |
| 304 | 273 |
| 305 EXPECT_TRUE(file_util::PathExists(cache_file_path)); | 274 EXPECT_TRUE(file_util::PathExists(cache_file_path)); |
| 306 EXPECT_EQ(cache_file_path, | 275 EXPECT_EQ(cache_file_path, |
| 307 cache_->GetCacheFilePath(resource_id, | 276 cache_->GetCacheFilePath(resource_id, entry.md5(), |
| 308 entry.md5(), | |
| 309 expected_sub_dir_type_, | |
| 310 FileCache::CACHED_FILE_MOUNTED)); | 277 FileCache::CACHED_FILE_MOUNTED)); |
| 311 } | 278 } |
| 312 | 279 |
| 313 void TestMarkAsUnmounted( | 280 void TestMarkAsUnmounted(const std::string& resource_id, |
| 314 const std::string& resource_id, | 281 const std::string& md5, |
| 315 const std::string& md5, | 282 const base::FilePath& file_path, |
| 316 const base::FilePath& file_path, | 283 FileError expected_error, |
| 317 FileError expected_error, | 284 int expected_cache_state) { |
| 318 int expected_cache_state, | |
| 319 FileCache::CacheSubDirectoryType expected_sub_dir_type) { | |
| 320 expected_error_ = expected_error; | 285 expected_error_ = expected_error; |
| 321 expected_cache_state_ = expected_cache_state; | 286 expected_cache_state_ = expected_cache_state; |
| 322 expected_sub_dir_type_ = expected_sub_dir_type; | |
| 323 | 287 |
| 324 FileError error = FILE_ERROR_OK; | 288 FileError error = FILE_ERROR_OK; |
| 325 cache_->MarkAsUnmountedOnUIThread( | 289 cache_->MarkAsUnmountedOnUIThread( |
| 326 file_path, | 290 file_path, |
| 327 google_apis::test_util::CreateCopyResultCallback(&error)); | 291 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 328 google_apis::test_util::RunBlockingPoolTask(); | 292 google_apis::test_util::RunBlockingPoolTask(); |
| 329 | 293 |
| 330 base::FilePath cache_file_path; | 294 base::FilePath cache_file_path; |
| 331 cache_->GetFileOnUIThread( | 295 cache_->GetFileOnUIThread( |
| 332 resource_id, md5, | 296 resource_id, md5, |
| 333 google_apis::test_util::CreateCopyResultCallback( | 297 google_apis::test_util::CreateCopyResultCallback( |
| 334 &error, &cache_file_path)); | 298 &error, &cache_file_path)); |
| 335 google_apis::test_util::RunBlockingPoolTask(); | 299 google_apis::test_util::RunBlockingPoolTask(); |
| 336 EXPECT_EQ(FILE_ERROR_OK, error); | 300 EXPECT_EQ(FILE_ERROR_OK, error); |
| 337 | 301 |
| 338 EXPECT_TRUE(file_util::PathExists(cache_file_path)); | 302 EXPECT_TRUE(file_util::PathExists(cache_file_path)); |
| 339 EXPECT_EQ(cache_file_path, | 303 EXPECT_EQ(cache_file_path, |
| 340 cache_->GetCacheFilePath(resource_id, | 304 cache_->GetCacheFilePath(resource_id, md5, |
| 341 md5, | |
| 342 expected_sub_dir_type_, | |
| 343 FileCache::CACHED_FILE_FROM_SERVER)); | 305 FileCache::CACHED_FILE_FROM_SERVER)); |
| 344 } | 306 } |
| 345 | 307 |
| 346 void VerifyCacheFileState(FileError error, | 308 void VerifyCacheFileState(FileError error, |
| 347 const std::string& resource_id, | 309 const std::string& resource_id, |
| 348 const std::string& md5) { | 310 const std::string& md5) { |
| 349 EXPECT_EQ(expected_error_, error); | 311 EXPECT_EQ(expected_error_, error); |
| 350 | 312 |
| 351 // Verify cache map. | 313 // Verify cache map. |
| 352 FileCacheEntry cache_entry; | 314 FileCacheEntry cache_entry; |
| 353 const bool cache_entry_found = | 315 const bool cache_entry_found = |
| 354 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); | 316 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); |
| 355 if (test_util::ToCacheEntry(expected_cache_state_).is_present() || | 317 if (test_util::ToCacheEntry(expected_cache_state_).is_present() || |
| 356 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) { | 318 test_util::ToCacheEntry(expected_cache_state_).is_pinned()) { |
| 357 ASSERT_TRUE(cache_entry_found); | 319 ASSERT_TRUE(cache_entry_found); |
| 358 EXPECT_TRUE(test_util::CacheStatesEqual( | 320 EXPECT_TRUE(test_util::CacheStatesEqual( |
| 359 test_util::ToCacheEntry(expected_cache_state_), | 321 test_util::ToCacheEntry(expected_cache_state_), cache_entry)); |
| 360 cache_entry)); | |
| 361 EXPECT_EQ(expected_sub_dir_type_, | |
| 362 FileCache::GetSubDirectoryType(cache_entry)); | |
| 363 } else { | 322 } else { |
| 364 EXPECT_FALSE(cache_entry_found); | 323 EXPECT_FALSE(cache_entry_found); |
| 365 } | 324 } |
| 366 | 325 |
| 367 // Verify actual cache file. | 326 // Verify actual cache file. |
| 368 base::FilePath dest_path = cache_->GetCacheFilePath( | 327 base::FilePath dest_path = cache_->GetCacheFilePath( |
| 369 resource_id, | 328 resource_id, |
| 370 md5, | 329 md5, |
| 371 test_util::ToCacheEntry(expected_cache_state_).is_pinned() || | |
| 372 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ? | |
| 373 FileCache::CACHE_TYPE_PERSISTENT : | |
| 374 FileCache::CACHE_TYPE_TMP, | |
| 375 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ? | 330 test_util::ToCacheEntry(expected_cache_state_).is_dirty() ? |
| 376 FileCache::CACHED_FILE_LOCALLY_MODIFIED : | 331 FileCache::CACHED_FILE_LOCALLY_MODIFIED : |
| 377 FileCache::CACHED_FILE_FROM_SERVER); | 332 FileCache::CACHED_FILE_FROM_SERVER); |
| 378 bool exists = file_util::PathExists(dest_path); | 333 bool exists = file_util::PathExists(dest_path); |
| 379 if (test_util::ToCacheEntry(expected_cache_state_).is_present()) | 334 if (test_util::ToCacheEntry(expected_cache_state_).is_present()) |
| 380 EXPECT_TRUE(exists); | 335 EXPECT_TRUE(exists); |
| 381 else | 336 else |
| 382 EXPECT_FALSE(exists); | 337 EXPECT_FALSE(exists); |
| 383 } | 338 } |
| 384 | 339 |
| 385 base::FilePath GetCacheFilePath(const std::string& resource_id, | 340 base::FilePath GetCacheFilePath(const std::string& resource_id, |
| 386 const std::string& md5, | 341 const std::string& md5, |
| 387 FileCache::CacheSubDirectoryType sub_dir_type, | 342 FileCache::CachedFileOrigin file_origin) { |
| 388 FileCache::CachedFileOrigin file_origin) { | 343 return cache_->GetCacheFilePath(resource_id, md5, file_origin); |
| 389 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type, | |
| 390 file_origin); | |
| 391 } | 344 } |
| 392 | 345 |
| 393 // Helper function to call GetCacheEntry from origin thread. | 346 // Helper function to call GetCacheEntry from origin thread. |
| 394 bool GetCacheEntryFromOriginThread(const std::string& resource_id, | 347 bool GetCacheEntryFromOriginThread(const std::string& resource_id, |
| 395 const std::string& md5, | 348 const std::string& md5, |
| 396 FileCacheEntry* cache_entry) { | 349 FileCacheEntry* cache_entry) { |
| 397 bool result = false; | 350 bool result = false; |
| 398 cache_->GetCacheEntryOnUIThread( | 351 cache_->GetCacheEntryOnUIThread( |
| 399 resource_id, md5, | 352 resource_id, md5, |
| 400 google_apis::test_util::CreateCopyResultCallback(&result, cache_entry)); | 353 google_apis::test_util::CreateCopyResultCallback(&result, cache_entry)); |
| 401 google_apis::test_util::RunBlockingPoolTask(); | 354 google_apis::test_util::RunBlockingPoolTask(); |
| 402 return result; | 355 return result; |
| 403 } | 356 } |
| 404 | 357 |
| 405 // Returns true if the cache entry exists for the given resource ID and MD5. | 358 // Returns true if the cache entry exists for the given resource ID and MD5. |
| 406 bool CacheEntryExists(const std::string& resource_id, | 359 bool CacheEntryExists(const std::string& resource_id, |
| 407 const std::string& md5) { | 360 const std::string& md5) { |
| 408 FileCacheEntry cache_entry; | 361 FileCacheEntry cache_entry; |
| 409 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); | 362 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); |
| 410 } | 363 } |
| 411 | 364 |
| 412 void TestGetCacheFilePath(const std::string& resource_id, | 365 void TestGetCacheFilePath(const std::string& resource_id, |
| 413 const std::string& md5, | 366 const std::string& md5, |
| 414 const std::string& expected_filename) { | 367 const std::string& expected_filename) { |
| 415 base::FilePath actual_path = cache_->GetCacheFilePath( | 368 base::FilePath actual_path = cache_->GetCacheFilePath( |
| 416 resource_id, | 369 resource_id, md5, FileCache::CACHED_FILE_FROM_SERVER); |
| 417 md5, | |
| 418 FileCache::CACHE_TYPE_TMP, | |
| 419 FileCache::CACHED_FILE_FROM_SERVER); | |
| 420 base::FilePath expected_path = | 370 base::FilePath expected_path = |
| 421 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_TMP); | 371 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_FILES); |
| 422 expected_path = expected_path.Append( | 372 expected_path = expected_path.Append( |
| 423 base::FilePath::FromUTF8Unsafe(expected_filename)); | 373 base::FilePath::FromUTF8Unsafe(expected_filename)); |
| 424 EXPECT_EQ(expected_path, actual_path); | 374 EXPECT_EQ(expected_path, actual_path); |
| 425 | 375 |
| 426 base::FilePath base_name = actual_path.BaseName(); | 376 base::FilePath base_name = actual_path.BaseName(); |
| 427 | 377 |
| 428 // base::FilePath::Extension returns ".", so strip it. | 378 // base::FilePath::Extension returns ".", so strip it. |
| 429 std::string unescaped_md5 = util::UnescapeCacheFileName( | 379 std::string unescaped_md5 = util::UnescapeCacheFileName( |
| 430 base_name.Extension().substr(1)); | 380 base_name.Extension().substr(1)); |
| 431 EXPECT_EQ(md5, unescaped_md5); | 381 EXPECT_EQ(md5, unescaped_md5); |
| 432 std::string unescaped_resource_id = util::UnescapeCacheFileName( | 382 std::string unescaped_resource_id = util::UnescapeCacheFileName( |
| 433 base_name.RemoveExtension().value()); | 383 base_name.RemoveExtension().value()); |
| 434 EXPECT_EQ(resource_id, unescaped_resource_id); | 384 EXPECT_EQ(resource_id, unescaped_resource_id); |
| 435 } | 385 } |
| 436 | 386 |
| 437 // Returns the number of the cache files with name <resource_id>, and Confirm | 387 // Returns the number of the cache files with name <resource_id>, and Confirm |
| 438 // that they have the <md5>. This should return 1 or 0. | 388 // that they have the <md5>. This should return 1 or 0. |
| 439 size_t CountCacheFiles(const std::string& resource_id, | 389 size_t CountCacheFiles(const std::string& resource_id, |
| 440 const std::string& md5) { | 390 const std::string& md5) { |
| 441 base::FilePath path = GetCacheFilePath( | 391 base::FilePath path = GetCacheFilePath( |
| 442 resource_id, "*", | 392 resource_id, "*", FileCache::CACHED_FILE_FROM_SERVER); |
| 443 (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ? | |
| 444 FileCache::CACHE_TYPE_PERSISTENT : | |
| 445 FileCache::CACHE_TYPE_TMP), | |
| 446 FileCache::CACHED_FILE_FROM_SERVER); | |
| 447 base::FileEnumerator enumerator(path.DirName(), false, | 393 base::FileEnumerator enumerator(path.DirName(), false, |
| 448 base::FileEnumerator::FILES, | 394 base::FileEnumerator::FILES, |
| 449 path.BaseName().value()); | 395 path.BaseName().value()); |
| 450 size_t num_files_found = 0; | 396 size_t num_files_found = 0; |
| 451 for (base::FilePath current = enumerator.Next(); !current.empty(); | 397 for (base::FilePath current = enumerator.Next(); !current.empty(); |
| 452 current = enumerator.Next()) { | 398 current = enumerator.Next()) { |
| 453 ++num_files_found; | 399 ++num_files_found; |
| 454 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + | 400 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + |
| 455 base::FilePath::kExtensionSeparator + | 401 base::FilePath::kExtensionSeparator + |
| 456 util::EscapeCacheFileName(md5), | 402 util::EscapeCacheFileName(md5), |
| 457 current.BaseName().value()); | 403 current.BaseName().value()); |
| 458 } | 404 } |
| 459 return num_files_found; | 405 return num_files_found; |
| 460 } | 406 } |
| 461 | 407 |
| 462 content::TestBrowserThreadBundle thread_bundle_; | 408 content::TestBrowserThreadBundle thread_bundle_; |
| 463 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 409 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 464 base::ScopedTempDir temp_dir_; | 410 base::ScopedTempDir temp_dir_; |
| 465 base::FilePath dummy_file_path_; | 411 base::FilePath dummy_file_path_; |
| 466 | 412 |
| 467 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; | 413 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; |
| 468 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; | 414 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; |
| 469 | 415 |
| 470 FileError expected_error_; | 416 FileError expected_error_; |
| 471 int expected_cache_state_; | 417 int expected_cache_state_; |
| 472 FileCache::CacheSubDirectoryType expected_sub_dir_type_; | |
| 473 bool expected_success_; | |
| 474 std::string expected_file_extension_; | 418 std::string expected_file_extension_; |
| 475 }; | 419 }; |
| 476 | 420 |
| 477 TEST_F(FileCacheTestOnUIThread, GetCacheFilePath) { | 421 TEST_F(FileCacheTestOnUIThread, GetCacheFilePath) { |
| 478 // Use alphanumeric characters for resource id. | 422 // Use alphanumeric characters for resource id. |
| 479 std::string resource_id("pdf:1a2b"); | 423 std::string resource_id("pdf:1a2b"); |
| 480 std::string md5("abcdef0123456789"); | 424 std::string md5("abcdef0123456789"); |
| 481 TestGetCacheFilePath(resource_id, md5, | 425 TestGetCacheFilePath(resource_id, md5, |
| 482 resource_id + base::FilePath::kExtensionSeparator + md5); | 426 resource_id + base::FilePath::kExtensionSeparator + md5); |
| 483 | 427 |
| 484 // Use non-alphanumeric characters for resource id, including '.' which is an | 428 // Use non-alphanumeric characters for resource id, including '.' which is an |
| 485 // extension separator, to test that the characters are escaped and unescaped | 429 // extension separator, to test that the characters are escaped and unescaped |
| 486 // correctly, and '.' doesn't mess up the filename format and operations. | 430 // correctly, and '.' doesn't mess up the filename format and operations. |
| 487 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; | 431 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; |
| 488 std::string escaped_resource_id = util::EscapeCacheFileName(resource_id); | 432 std::string escaped_resource_id = util::EscapeCacheFileName(resource_id); |
| 489 std::string escaped_md5 = util::EscapeCacheFileName(md5); | 433 std::string escaped_md5 = util::EscapeCacheFileName(md5); |
| 490 TestGetCacheFilePath( | 434 TestGetCacheFilePath(resource_id, md5, escaped_resource_id + |
| 491 resource_id, md5, escaped_resource_id + | 435 base::FilePath::kExtensionSeparator + escaped_md5); |
| 492 base::FilePath::kExtensionSeparator + escaped_md5); | |
| 493 } | 436 } |
| 494 | 437 |
| 495 TEST_F(FileCacheTestOnUIThread, StoreToCacheSimple) { | 438 TEST_F(FileCacheTestOnUIThread, StoreToCacheSimple) { |
| 496 std::string resource_id("pdf:1a2b"); | 439 std::string resource_id("pdf:1a2b"); |
| 497 std::string md5("abcdef0123456789"); | 440 std::string md5("abcdef0123456789"); |
| 498 | 441 |
| 499 // Store an existing file. | 442 // Store an existing file. |
| 500 TestStoreToCache(resource_id, md5, dummy_file_path_, | 443 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 501 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 444 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 502 FileCache::CACHE_TYPE_TMP); | |
| 503 | 445 |
| 504 // Store a non-existent file to the same |resource_id| and |md5|. | 446 // Store a non-existent file to the same |resource_id| and |md5|. |
| 505 TestStoreToCache(resource_id, md5, | 447 TestStoreToCache(resource_id, md5, |
| 506 base::FilePath::FromUTF8Unsafe("non_existent_file"), | 448 base::FilePath::FromUTF8Unsafe("non_existent_file"), |
| 507 FILE_ERROR_FAILED, | 449 FILE_ERROR_FAILED, |
| 508 test_util::TEST_CACHE_STATE_PRESENT, | 450 test_util::TEST_CACHE_STATE_PRESENT); |
| 509 FileCache::CACHE_TYPE_TMP); | |
| 510 | 451 |
| 511 // Store a different existing file to the same |resource_id| but different | 452 // Store a different existing file to the same |resource_id| but different |
| 512 // |md5|. | 453 // |md5|. |
| 513 md5 = "new_md5"; | 454 md5 = "new_md5"; |
| 514 TestStoreToCache(resource_id, md5, dummy_file_path_, | 455 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 515 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 456 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 516 FileCache::CACHE_TYPE_TMP); | |
| 517 | 457 |
| 518 // Verify that there's only one file with name <resource_id>, i.e. previously | 458 // Verify that there's only one file with name <resource_id>, i.e. previously |
| 519 // cached file with the different md5 should be deleted. | 459 // cached file with the different md5 should be deleted. |
| 520 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); | 460 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); |
| 521 } | 461 } |
| 522 | 462 |
| 523 | 463 |
| 524 TEST_F(FileCacheTestOnUIThread, GetFromCacheSimple) { | 464 TEST_F(FileCacheTestOnUIThread, GetFromCacheSimple) { |
| 525 std::string resource_id("pdf:1a2b"); | 465 std::string resource_id("pdf:1a2b"); |
| 526 std::string md5("abcdef0123456789"); | 466 std::string md5("abcdef0123456789"); |
| 527 // First store a file to cache. | 467 // First store a file to cache. |
| 528 TestStoreToCache(resource_id, md5, dummy_file_path_, | 468 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 529 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 469 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 530 FileCache::CACHE_TYPE_TMP); | |
| 531 | 470 |
| 532 // Then try to get the existing file from cache. | 471 // Then try to get the existing file from cache. |
| 533 TestGetFileFromCacheByResourceIdAndMd5( | 472 TestGetFileFromCacheByResourceIdAndMd5( |
| 534 resource_id, md5, FILE_ERROR_OK, md5); | 473 resource_id, md5, FILE_ERROR_OK, md5); |
| 535 | 474 |
| 536 // Get file from cache with same resource id as existing file but different | 475 // Get file from cache with same resource id as existing file but different |
| 537 // md5. | 476 // md5. |
| 538 TestGetFileFromCacheByResourceIdAndMd5( | 477 TestGetFileFromCacheByResourceIdAndMd5( |
| 539 resource_id, "9999", FILE_ERROR_NOT_FOUND, md5); | 478 resource_id, "9999", FILE_ERROR_NOT_FOUND, md5); |
| 540 | 479 |
| 541 // Get file from cache with different resource id from existing file but same | 480 // Get file from cache with different resource id from existing file but same |
| 542 // md5. | 481 // md5. |
| 543 resource_id = "document:1a2b"; | 482 resource_id = "document:1a2b"; |
| 544 TestGetFileFromCacheByResourceIdAndMd5( | 483 TestGetFileFromCacheByResourceIdAndMd5( |
| 545 resource_id, md5, FILE_ERROR_NOT_FOUND, md5); | 484 resource_id, md5, FILE_ERROR_NOT_FOUND, md5); |
| 546 } | 485 } |
| 547 | 486 |
| 548 TEST_F(FileCacheTestOnUIThread, RemoveFromCacheSimple) { | 487 TEST_F(FileCacheTestOnUIThread, RemoveFromCacheSimple) { |
| 549 // Use alphanumeric characters for resource id. | 488 // Use alphanumeric characters for resource id. |
| 550 std::string resource_id("pdf:1a2b"); | 489 std::string resource_id("pdf:1a2b"); |
| 551 std::string md5("abcdef0123456789"); | 490 std::string md5("abcdef0123456789"); |
| 552 // First store a file to cache. | 491 // First store a file to cache. |
| 553 TestStoreToCache(resource_id, md5, dummy_file_path_, | 492 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 554 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 493 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 555 FileCache::CACHE_TYPE_TMP); | |
| 556 | 494 |
| 557 // Then try to remove existing file from cache. | 495 // Then try to remove existing file from cache. |
| 558 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 496 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
| 559 | 497 |
| 560 // Repeat using non-alphanumeric characters for resource id, including '.' | 498 // Repeat using non-alphanumeric characters for resource id, including '.' |
| 561 // which is an extension separator. | 499 // which is an extension separator. |
| 562 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; | 500 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; |
| 563 TestStoreToCache(resource_id, md5, dummy_file_path_, | 501 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 564 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 502 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 565 FileCache::CACHE_TYPE_TMP); | |
| 566 | 503 |
| 567 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 504 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
| 568 } | 505 } |
| 569 | 506 |
| 570 TEST_F(FileCacheTestOnUIThread, PinAndUnpin) { | 507 TEST_F(FileCacheTestOnUIThread, PinAndUnpin) { |
| 571 std::string resource_id("pdf:1a2b"); | 508 std::string resource_id("pdf:1a2b"); |
| 572 std::string md5("abcdef0123456789"); | 509 std::string md5("abcdef0123456789"); |
| 573 | 510 |
| 574 // First store a file to cache. | 511 // First store a file to cache. |
| 575 TestStoreToCache(resource_id, md5, dummy_file_path_, | 512 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 576 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 513 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 577 FileCache::CACHE_TYPE_TMP); | |
| 578 | 514 |
| 579 // Pin the existing file in cache. | 515 // Pin the existing file in cache. |
| 580 TestPin(resource_id, md5, FILE_ERROR_OK, | 516 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 581 test_util::TEST_CACHE_STATE_PRESENT | | 517 test_util::TEST_CACHE_STATE_PRESENT | |
| 582 test_util::TEST_CACHE_STATE_PINNED | | 518 test_util::TEST_CACHE_STATE_PINNED); |
| 583 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 584 FileCache::CACHE_TYPE_PERSISTENT); | |
| 585 | 519 |
| 586 // Unpin the existing file in cache. | 520 // Unpin the existing file in cache. |
| 587 TestUnpin(resource_id, md5, FILE_ERROR_OK, | 521 TestUnpin(resource_id, md5, FILE_ERROR_OK, |
| 588 test_util::TEST_CACHE_STATE_PRESENT, | 522 test_util::TEST_CACHE_STATE_PRESENT); |
| 589 FileCache::CACHE_TYPE_TMP); | |
| 590 | 523 |
| 591 // Pin back the same existing file in cache. | 524 // Pin back the same existing file in cache. |
| 592 TestPin(resource_id, md5, FILE_ERROR_OK, | 525 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 593 test_util::TEST_CACHE_STATE_PRESENT | | 526 test_util::TEST_CACHE_STATE_PRESENT | |
| 594 test_util::TEST_CACHE_STATE_PINNED | | 527 test_util::TEST_CACHE_STATE_PINNED); |
| 595 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 596 FileCache::CACHE_TYPE_PERSISTENT); | |
| 597 | 528 |
| 598 // Pin a non-existent file in cache. | 529 // Pin a non-existent file in cache. |
| 599 resource_id = "document:1a2b"; | 530 resource_id = "document:1a2b"; |
| 600 | 531 |
| 601 TestPin(resource_id, md5, FILE_ERROR_OK, | 532 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 602 test_util::TEST_CACHE_STATE_PINNED, | 533 test_util::TEST_CACHE_STATE_PINNED); |
| 603 FileCache::CACHE_TYPE_TMP); | |
| 604 | 534 |
| 605 // Unpin the previously pinned non-existent file in cache. | 535 // Unpin the previously pinned non-existent file in cache. |
| 606 TestUnpin(resource_id, md5, FILE_ERROR_OK, | 536 TestUnpin(resource_id, md5, FILE_ERROR_OK, |
| 607 test_util::TEST_CACHE_STATE_NONE, | 537 test_util::TEST_CACHE_STATE_NONE); |
| 608 FileCache::CACHE_TYPE_TMP); | |
| 609 | 538 |
| 610 // Unpin a file that doesn't exist in cache and is not pinned, i.e. cache | 539 // Unpin a file that doesn't exist in cache and is not pinned, i.e. cache |
| 611 // has zero knowledge of the file. | 540 // has zero knowledge of the file. |
| 612 resource_id = "not-in-cache:1a2b"; | 541 resource_id = "not-in-cache:1a2b"; |
| 613 | 542 |
| 614 TestUnpin(resource_id, md5, FILE_ERROR_NOT_FOUND, | 543 TestUnpin(resource_id, md5, FILE_ERROR_NOT_FOUND, |
| 615 test_util::TEST_CACHE_STATE_NONE, | 544 test_util::TEST_CACHE_STATE_NONE); |
| 616 FileCache::CACHE_TYPE_TMP /* non-applicable */); | |
| 617 } | 545 } |
| 618 | 546 |
| 619 TEST_F(FileCacheTestOnUIThread, StoreToCachePinned) { | 547 TEST_F(FileCacheTestOnUIThread, StoreToCachePinned) { |
| 620 std::string resource_id("pdf:1a2b"); | 548 std::string resource_id("pdf:1a2b"); |
| 621 std::string md5("abcdef0123456789"); | 549 std::string md5("abcdef0123456789"); |
| 622 | 550 |
| 623 // Pin a non-existent file. | 551 // Pin a non-existent file. |
| 624 TestPin(resource_id, md5, FILE_ERROR_OK, | 552 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 625 test_util::TEST_CACHE_STATE_PINNED, | 553 test_util::TEST_CACHE_STATE_PINNED); |
| 626 FileCache::CACHE_TYPE_TMP); | |
| 627 | 554 |
| 628 // Store an existing file to a previously pinned file. | 555 // Store an existing file to a previously pinned file. |
| 629 TestStoreToCache(resource_id, md5, dummy_file_path_, | 556 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 630 FILE_ERROR_OK, | 557 FILE_ERROR_OK, |
| 631 test_util::TEST_CACHE_STATE_PRESENT | | 558 test_util::TEST_CACHE_STATE_PRESENT | |
| 632 test_util::TEST_CACHE_STATE_PINNED | | 559 test_util::TEST_CACHE_STATE_PINNED); |
| 633 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 634 FileCache::CACHE_TYPE_PERSISTENT); | |
| 635 | 560 |
| 636 // Store a non-existent file to a previously pinned and stored file. | 561 // Store a non-existent file to a previously pinned and stored file. |
| 637 TestStoreToCache(resource_id, md5, | 562 TestStoreToCache(resource_id, md5, |
| 638 base::FilePath::FromUTF8Unsafe("non_existent_file"), | 563 base::FilePath::FromUTF8Unsafe("non_existent_file"), |
| 639 FILE_ERROR_FAILED, | 564 FILE_ERROR_FAILED, |
| 640 test_util::TEST_CACHE_STATE_PRESENT | | 565 test_util::TEST_CACHE_STATE_PRESENT | |
| 641 test_util::TEST_CACHE_STATE_PINNED | | 566 test_util::TEST_CACHE_STATE_PINNED); |
| 642 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 643 FileCache::CACHE_TYPE_PERSISTENT); | |
| 644 } | 567 } |
| 645 | 568 |
| 646 TEST_F(FileCacheTestOnUIThread, GetFromCachePinned) { | 569 TEST_F(FileCacheTestOnUIThread, GetFromCachePinned) { |
| 647 std::string resource_id("pdf:1a2b"); | 570 std::string resource_id("pdf:1a2b"); |
| 648 std::string md5("abcdef0123456789"); | 571 std::string md5("abcdef0123456789"); |
| 649 | 572 |
| 650 // Pin a non-existent file. | 573 // Pin a non-existent file. |
| 651 TestPin(resource_id, md5, FILE_ERROR_OK, | 574 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 652 test_util::TEST_CACHE_STATE_PINNED, | 575 test_util::TEST_CACHE_STATE_PINNED); |
| 653 FileCache::CACHE_TYPE_TMP); | |
| 654 | 576 |
| 655 // Get the non-existent pinned file from cache. | 577 // Get the non-existent pinned file from cache. |
| 656 TestGetFileFromCacheByResourceIdAndMd5( | 578 TestGetFileFromCacheByResourceIdAndMd5( |
| 657 resource_id, md5, FILE_ERROR_NOT_FOUND, md5); | 579 resource_id, md5, FILE_ERROR_NOT_FOUND, md5); |
| 658 | 580 |
| 659 // Store an existing file to the previously pinned non-existent file. | 581 // Store an existing file to the previously pinned non-existent file. |
| 660 TestStoreToCache(resource_id, md5, dummy_file_path_, | 582 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 661 FILE_ERROR_OK, | 583 FILE_ERROR_OK, |
| 662 test_util::TEST_CACHE_STATE_PRESENT | | 584 test_util::TEST_CACHE_STATE_PRESENT | |
| 663 test_util::TEST_CACHE_STATE_PINNED | | 585 test_util::TEST_CACHE_STATE_PINNED); |
| 664 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 665 FileCache::CACHE_TYPE_PERSISTENT); | |
| 666 | 586 |
| 667 // Get the previously pinned and stored file from cache. | 587 // Get the previously pinned and stored file from cache. |
| 668 TestGetFileFromCacheByResourceIdAndMd5( | 588 TestGetFileFromCacheByResourceIdAndMd5( |
| 669 resource_id, md5, FILE_ERROR_OK, md5); | 589 resource_id, md5, FILE_ERROR_OK, md5); |
| 670 } | 590 } |
| 671 | 591 |
| 672 TEST_F(FileCacheTestOnUIThread, RemoveFromCachePinned) { | 592 TEST_F(FileCacheTestOnUIThread, RemoveFromCachePinned) { |
| 673 // Use alphanumeric characters for resource_id. | 593 // Use alphanumeric characters for resource_id. |
| 674 std::string resource_id("pdf:1a2b"); | 594 std::string resource_id("pdf:1a2b"); |
| 675 std::string md5("abcdef0123456789"); | 595 std::string md5("abcdef0123456789"); |
| 676 | 596 |
| 677 // Store a file to cache, and pin it. | 597 // Store a file to cache, and pin it. |
| 678 TestStoreToCache(resource_id, md5, dummy_file_path_, | 598 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 679 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 599 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 680 FileCache::CACHE_TYPE_TMP); | |
| 681 TestPin(resource_id, md5, FILE_ERROR_OK, | 600 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 682 test_util::TEST_CACHE_STATE_PRESENT | | 601 test_util::TEST_CACHE_STATE_PRESENT | |
| 683 test_util::TEST_CACHE_STATE_PINNED | | 602 test_util::TEST_CACHE_STATE_PINNED); |
| 684 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 685 FileCache::CACHE_TYPE_PERSISTENT); | |
| 686 | 603 |
| 687 // Remove |resource_id| from cache. | 604 // Remove |resource_id| from cache. |
| 688 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 605 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
| 689 | 606 |
| 690 // Repeat using non-alphanumeric characters for resource id, including '.' | 607 // Repeat using non-alphanumeric characters for resource id, including '.' |
| 691 // which is an extension separator. | 608 // which is an extension separator. |
| 692 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; | 609 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; |
| 693 | 610 |
| 694 TestStoreToCache(resource_id, md5, dummy_file_path_, | 611 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 695 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 612 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 696 FileCache::CACHE_TYPE_TMP); | |
| 697 TestPin(resource_id, md5, FILE_ERROR_OK, | 613 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 698 test_util::TEST_CACHE_STATE_PRESENT | | 614 test_util::TEST_CACHE_STATE_PRESENT | |
| 699 test_util::TEST_CACHE_STATE_PINNED | | 615 test_util::TEST_CACHE_STATE_PINNED); |
| 700 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 701 FileCache::CACHE_TYPE_PERSISTENT); | |
| 702 | 616 |
| 703 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 617 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
| 704 } | 618 } |
| 705 | 619 |
| 706 TEST_F(FileCacheTestOnUIThread, DirtyCacheSimple) { | 620 TEST_F(FileCacheTestOnUIThread, DirtyCacheSimple) { |
| 707 std::string resource_id("pdf:1a2b"); | 621 std::string resource_id("pdf:1a2b"); |
| 708 std::string md5("abcdef0123456789"); | 622 std::string md5("abcdef0123456789"); |
| 709 | 623 |
| 710 // First store a file to cache. | 624 // First store a file to cache. |
| 711 TestStoreToCache(resource_id, md5, dummy_file_path_, | 625 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 712 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 626 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 713 FileCache::CACHE_TYPE_TMP); | |
| 714 | 627 |
| 715 // Mark the file dirty. | 628 // Mark the file dirty. |
| 716 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 629 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
| 717 test_util::TEST_CACHE_STATE_PRESENT | | 630 test_util::TEST_CACHE_STATE_PRESENT | |
| 718 test_util::TEST_CACHE_STATE_DIRTY | | 631 test_util::TEST_CACHE_STATE_DIRTY); |
| 719 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 720 FileCache::CACHE_TYPE_PERSISTENT); | |
| 721 | 632 |
| 722 // Clear dirty state of the file. | 633 // Clear dirty state of the file. |
| 723 TestClearDirty(resource_id, md5, FILE_ERROR_OK, | 634 TestClearDirty(resource_id, md5, FILE_ERROR_OK, |
| 724 test_util::TEST_CACHE_STATE_PRESENT, | 635 test_util::TEST_CACHE_STATE_PRESENT); |
| 725 FileCache::CACHE_TYPE_TMP); | |
| 726 } | 636 } |
| 727 | 637 |
| 728 TEST_F(FileCacheTestOnUIThread, DirtyCachePinned) { | 638 TEST_F(FileCacheTestOnUIThread, DirtyCachePinned) { |
| 729 std::string resource_id("pdf:1a2b"); | 639 std::string resource_id("pdf:1a2b"); |
| 730 std::string md5("abcdef0123456789"); | 640 std::string md5("abcdef0123456789"); |
| 731 | 641 |
| 732 // First store a file to cache and pin it. | 642 // First store a file to cache and pin it. |
| 733 TestStoreToCache(resource_id, md5, dummy_file_path_, | 643 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 734 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 644 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 735 FileCache::CACHE_TYPE_TMP); | |
| 736 TestPin(resource_id, md5, FILE_ERROR_OK, | 645 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 737 test_util::TEST_CACHE_STATE_PRESENT | | 646 test_util::TEST_CACHE_STATE_PRESENT | |
| 738 test_util::TEST_CACHE_STATE_PINNED | | 647 test_util::TEST_CACHE_STATE_PINNED); |
| 739 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 740 FileCache::CACHE_TYPE_PERSISTENT); | |
| 741 | 648 |
| 742 // Mark the file dirty. | 649 // Mark the file dirty. |
| 743 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 650 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
| 744 test_util::TEST_CACHE_STATE_PRESENT | | 651 test_util::TEST_CACHE_STATE_PRESENT | |
| 745 test_util::TEST_CACHE_STATE_DIRTY | | 652 test_util::TEST_CACHE_STATE_DIRTY | |
| 746 test_util::TEST_CACHE_STATE_PINNED | | 653 test_util::TEST_CACHE_STATE_PINNED); |
| 747 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 748 FileCache::CACHE_TYPE_PERSISTENT); | |
| 749 | 654 |
| 750 // Clear dirty state of the file. | 655 // Clear dirty state of the file. |
| 751 TestClearDirty(resource_id, md5, FILE_ERROR_OK, | 656 TestClearDirty(resource_id, md5, FILE_ERROR_OK, |
| 752 test_util::TEST_CACHE_STATE_PRESENT | | 657 test_util::TEST_CACHE_STATE_PRESENT | |
| 753 test_util::TEST_CACHE_STATE_PINNED | | 658 test_util::TEST_CACHE_STATE_PINNED); |
| 754 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 755 FileCache::CACHE_TYPE_PERSISTENT); | |
| 756 } | 659 } |
| 757 | 660 |
| 758 TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) { | 661 TEST_F(FileCacheTestOnUIThread, PinAndUnpinDirtyCache) { |
| 759 std::string resource_id("pdf:1a2b"); | 662 std::string resource_id("pdf:1a2b"); |
| 760 std::string md5("abcdef0123456789"); | 663 std::string md5("abcdef0123456789"); |
| 761 | 664 |
| 762 // First store a file to cache and mark it as dirty. | 665 // First store a file to cache and mark it as dirty. |
| 763 TestStoreToCache(resource_id, md5, dummy_file_path_, | 666 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 764 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 667 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 765 FileCache::CACHE_TYPE_TMP); | |
| 766 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 668 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
| 767 test_util::TEST_CACHE_STATE_PRESENT | | 669 test_util::TEST_CACHE_STATE_PRESENT | |
| 768 test_util::TEST_CACHE_STATE_DIRTY | | 670 test_util::TEST_CACHE_STATE_DIRTY); |
| 769 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 770 FileCache::CACHE_TYPE_PERSISTENT); | |
| 771 | 671 |
| 772 // Verifies dirty file exists. | 672 // Verifies dirty file exists. |
| 773 base::FilePath dirty_path; | 673 base::FilePath dirty_path; |
| 774 FileError error = FILE_ERROR_FAILED; | 674 FileError error = FILE_ERROR_FAILED; |
| 775 cache_->GetFileOnUIThread( | 675 cache_->GetFileOnUIThread( |
| 776 resource_id, md5, | 676 resource_id, md5, |
| 777 google_apis::test_util::CreateCopyResultCallback(&error, &dirty_path)); | 677 google_apis::test_util::CreateCopyResultCallback(&error, &dirty_path)); |
| 778 google_apis::test_util::RunBlockingPoolTask(); | 678 google_apis::test_util::RunBlockingPoolTask(); |
| 779 EXPECT_EQ(FILE_ERROR_OK, error); | 679 EXPECT_EQ(FILE_ERROR_OK, error); |
| 780 EXPECT_TRUE(file_util::PathExists(dirty_path)); | 680 EXPECT_TRUE(file_util::PathExists(dirty_path)); |
| 781 | 681 |
| 782 // Pin the dirty file. | 682 // Pin the dirty file. |
| 783 TestPin(resource_id, md5, FILE_ERROR_OK, | 683 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 784 test_util::TEST_CACHE_STATE_PRESENT | | 684 test_util::TEST_CACHE_STATE_PRESENT | |
| 785 test_util::TEST_CACHE_STATE_DIRTY | | 685 test_util::TEST_CACHE_STATE_DIRTY | |
| 786 test_util::TEST_CACHE_STATE_PINNED | | 686 test_util::TEST_CACHE_STATE_PINNED); |
| 787 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 788 FileCache::CACHE_TYPE_PERSISTENT); | |
| 789 | 687 |
| 790 // Verify dirty file still exist at the same pathname. | 688 // Verify dirty file still exist at the same pathname. |
| 791 EXPECT_TRUE(file_util::PathExists(dirty_path)); | 689 EXPECT_TRUE(file_util::PathExists(dirty_path)); |
| 792 | 690 |
| 793 // Unpin the dirty file. | 691 // Unpin the dirty file. |
| 794 TestUnpin(resource_id, md5, FILE_ERROR_OK, | 692 TestUnpin(resource_id, md5, FILE_ERROR_OK, |
| 795 test_util::TEST_CACHE_STATE_PRESENT | | 693 test_util::TEST_CACHE_STATE_PRESENT | |
| 796 test_util::TEST_CACHE_STATE_DIRTY | | 694 test_util::TEST_CACHE_STATE_DIRTY); |
| 797 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 798 FileCache::CACHE_TYPE_PERSISTENT); | |
| 799 | 695 |
| 800 // Verify dirty file still exist at the same pathname. | 696 // Verify dirty file still exist at the same pathname. |
| 801 EXPECT_TRUE(file_util::PathExists(dirty_path)); | 697 EXPECT_TRUE(file_util::PathExists(dirty_path)); |
| 802 } | 698 } |
| 803 | 699 |
| 804 TEST_F(FileCacheTestOnUIThread, DirtyCacheRepetitive) { | 700 TEST_F(FileCacheTestOnUIThread, DirtyCacheRepetitive) { |
| 805 std::string resource_id("pdf:1a2b"); | 701 std::string resource_id("pdf:1a2b"); |
| 806 std::string md5("abcdef0123456789"); | 702 std::string md5("abcdef0123456789"); |
| 807 | 703 |
| 808 // First store a file to cache. | 704 // First store a file to cache. |
| 809 TestStoreToCache(resource_id, md5, dummy_file_path_, | 705 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 810 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 706 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 811 FileCache::CACHE_TYPE_TMP); | |
| 812 | 707 |
| 813 // Mark the file dirty. | 708 // Mark the file dirty. |
| 814 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 709 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
| 815 test_util::TEST_CACHE_STATE_PRESENT | | 710 test_util::TEST_CACHE_STATE_PRESENT | |
| 816 test_util::TEST_CACHE_STATE_DIRTY | | 711 test_util::TEST_CACHE_STATE_DIRTY); |
| 817 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 818 FileCache::CACHE_TYPE_PERSISTENT); | |
| 819 | 712 |
| 820 // Again, mark the file dirty. Nothing should change. | 713 // Again, mark the file dirty. Nothing should change. |
| 821 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 714 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
| 822 test_util::TEST_CACHE_STATE_PRESENT | | 715 test_util::TEST_CACHE_STATE_PRESENT | |
| 823 test_util::TEST_CACHE_STATE_DIRTY | | 716 test_util::TEST_CACHE_STATE_DIRTY); |
| 824 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 825 FileCache::CACHE_TYPE_PERSISTENT); | |
| 826 | 717 |
| 827 // Clear dirty state of the file. | 718 // Clear dirty state of the file. |
| 828 TestClearDirty(resource_id, md5, FILE_ERROR_OK, | 719 TestClearDirty(resource_id, md5, FILE_ERROR_OK, |
| 829 test_util::TEST_CACHE_STATE_PRESENT, | 720 test_util::TEST_CACHE_STATE_PRESENT); |
| 830 FileCache::CACHE_TYPE_TMP); | |
| 831 | 721 |
| 832 // Again, clear dirty state of the file, which is no longer dirty. | 722 // Again, clear dirty state of the file, which is no longer dirty. |
| 833 TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION, | 723 TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION, |
| 834 test_util::TEST_CACHE_STATE_PRESENT, | 724 test_util::TEST_CACHE_STATE_PRESENT); |
| 835 FileCache::CACHE_TYPE_TMP); | |
| 836 } | 725 } |
| 837 | 726 |
| 838 TEST_F(FileCacheTestOnUIThread, DirtyCacheInvalid) { | 727 TEST_F(FileCacheTestOnUIThread, DirtyCacheInvalid) { |
| 839 std::string resource_id("pdf:1a2b"); | 728 std::string resource_id("pdf:1a2b"); |
| 840 std::string md5("abcdef0123456789"); | 729 std::string md5("abcdef0123456789"); |
| 841 | 730 |
| 842 // Mark a non-existent file dirty. | 731 // Mark a non-existent file dirty. |
| 843 TestMarkDirty(resource_id, md5, FILE_ERROR_NOT_FOUND, | 732 TestMarkDirty(resource_id, md5, FILE_ERROR_NOT_FOUND, |
| 844 test_util::TEST_CACHE_STATE_NONE, | 733 test_util::TEST_CACHE_STATE_NONE); |
| 845 FileCache::CACHE_TYPE_TMP); | |
| 846 | 734 |
| 847 // Clear dirty state of a non-existent file. | 735 // Clear dirty state of a non-existent file. |
| 848 TestClearDirty(resource_id, md5, FILE_ERROR_NOT_FOUND, | 736 TestClearDirty(resource_id, md5, FILE_ERROR_NOT_FOUND, |
| 849 test_util::TEST_CACHE_STATE_NONE, | 737 test_util::TEST_CACHE_STATE_NONE); |
| 850 FileCache::CACHE_TYPE_TMP); | |
| 851 | 738 |
| 852 // Store a file to cache. | 739 // Store a file to cache. |
| 853 TestStoreToCache(resource_id, md5, dummy_file_path_, | 740 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 854 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 741 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 855 FileCache::CACHE_TYPE_TMP); | |
| 856 | 742 |
| 857 // Clear dirty state of a non-dirty existing file. | 743 // Clear dirty state of a non-dirty existing file. |
| 858 TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION, | 744 TestClearDirty(resource_id, md5, FILE_ERROR_INVALID_OPERATION, |
| 859 test_util::TEST_CACHE_STATE_PRESENT, | 745 test_util::TEST_CACHE_STATE_PRESENT); |
| 860 FileCache::CACHE_TYPE_TMP); | |
| 861 | 746 |
| 862 // Mark an existing file dirty, then store a new file to the same resource id | 747 // Mark an existing file dirty, then store a new file to the same resource id |
| 863 // but different md5, which should fail. | 748 // but different md5, which should fail. |
| 864 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 749 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
| 865 test_util::TEST_CACHE_STATE_PRESENT | | 750 test_util::TEST_CACHE_STATE_PRESENT | |
| 866 test_util::TEST_CACHE_STATE_DIRTY | | 751 test_util::TEST_CACHE_STATE_DIRTY); |
| 867 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 868 FileCache::CACHE_TYPE_PERSISTENT); | |
| 869 md5 = "new_md5"; | 752 md5 = "new_md5"; |
| 870 TestStoreToCache(resource_id, md5, dummy_file_path_, | 753 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 871 FILE_ERROR_IN_USE, | 754 FILE_ERROR_IN_USE, |
| 872 test_util::TEST_CACHE_STATE_PRESENT | | 755 test_util::TEST_CACHE_STATE_PRESENT | |
| 873 test_util::TEST_CACHE_STATE_DIRTY | | 756 test_util::TEST_CACHE_STATE_DIRTY); |
| 874 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 875 FileCache::CACHE_TYPE_PERSISTENT); | |
| 876 } | 757 } |
| 877 | 758 |
| 878 TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) { | 759 TEST_F(FileCacheTestOnUIThread, RemoveFromDirtyCache) { |
| 879 std::string resource_id("pdf:1a2b"); | 760 std::string resource_id("pdf:1a2b"); |
| 880 std::string md5("abcdef0123456789"); | 761 std::string md5("abcdef0123456789"); |
| 881 | 762 |
| 882 // Store a file to cache, pin it, mark it dirty and commit it. | 763 // Store a file to cache, pin it, mark it dirty and commit it. |
| 883 TestStoreToCache(resource_id, md5, dummy_file_path_, | 764 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 884 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 765 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 885 FileCache::CACHE_TYPE_TMP); | |
| 886 TestPin(resource_id, md5, FILE_ERROR_OK, | 766 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 887 test_util::TEST_CACHE_STATE_PRESENT | | 767 test_util::TEST_CACHE_STATE_PRESENT | |
| 888 test_util::TEST_CACHE_STATE_PINNED | | 768 test_util::TEST_CACHE_STATE_PINNED); |
| 889 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 890 FileCache::CACHE_TYPE_PERSISTENT); | |
| 891 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 769 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
| 892 test_util::TEST_CACHE_STATE_PRESENT | | 770 test_util::TEST_CACHE_STATE_PRESENT | |
| 893 test_util::TEST_CACHE_STATE_PINNED | | 771 test_util::TEST_CACHE_STATE_PINNED | |
| 894 test_util::TEST_CACHE_STATE_DIRTY | | 772 test_util::TEST_CACHE_STATE_DIRTY); |
| 895 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 896 FileCache::CACHE_TYPE_PERSISTENT); | |
| 897 | 773 |
| 898 // Try to remove the file. Since file is dirty, it should not be removed. | 774 // Try to remove the file. Since file is dirty, it should not be removed. |
| 899 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 775 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
| 900 } | 776 } |
| 901 | 777 |
| 902 TEST_F(FileCacheTestOnUIThread, MountUnmount) { | 778 TEST_F(FileCacheTestOnUIThread, MountUnmount) { |
| 903 std::string resource_id("pdf:1a2b"); | 779 std::string resource_id("pdf:1a2b"); |
| 904 std::string md5("abcdef0123456789"); | 780 std::string md5("abcdef0123456789"); |
| 905 | 781 |
| 906 // First store a file to cache in the tmp subdir. | 782 // First store a file to cache. |
| 907 TestStoreToCache(resource_id, md5, dummy_file_path_, | 783 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 908 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 784 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 909 FileCache::CACHE_TYPE_TMP); | |
| 910 | 785 |
| 911 // Mark the file mounted. | 786 // Mark the file mounted. |
| 912 TestMarkAsMounted(resource_id, | 787 TestMarkAsMounted(resource_id, |
| 913 FILE_ERROR_OK, | 788 FILE_ERROR_OK, |
| 914 test_util::TEST_CACHE_STATE_PRESENT | | 789 test_util::TEST_CACHE_STATE_PRESENT | |
| 915 test_util::TEST_CACHE_STATE_MOUNTED | | 790 test_util::TEST_CACHE_STATE_MOUNTED); |
| 916 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 917 FileCache::CACHE_TYPE_PERSISTENT); | |
| 918 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); | 791 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); |
| 919 | 792 |
| 920 // Clear mounted state of the file. | 793 // Clear mounted state of the file. |
| 921 base::FilePath file_path; | 794 base::FilePath file_path; |
| 922 FileError error = FILE_ERROR_FAILED; | 795 FileError error = FILE_ERROR_FAILED; |
| 923 cache_->GetFileOnUIThread( | 796 cache_->GetFileOnUIThread( |
| 924 resource_id, md5, | 797 resource_id, md5, |
| 925 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); | 798 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
| 926 google_apis::test_util::RunBlockingPoolTask(); | 799 google_apis::test_util::RunBlockingPoolTask(); |
| 927 EXPECT_EQ(FILE_ERROR_OK, error); | 800 EXPECT_EQ(FILE_ERROR_OK, error); |
| 928 | 801 |
| 929 TestMarkAsUnmounted(resource_id, md5, file_path, | 802 TestMarkAsUnmounted(resource_id, md5, file_path, |
| 930 FILE_ERROR_OK, | 803 FILE_ERROR_OK, |
| 931 test_util::TEST_CACHE_STATE_PRESENT, | 804 test_util::TEST_CACHE_STATE_PRESENT); |
| 932 FileCache::CACHE_TYPE_TMP); | |
| 933 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); | 805 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); |
| 934 | 806 |
| 935 // Try to remove the file. | 807 // Try to remove the file. |
| 936 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 808 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
| 937 } | 809 } |
| 938 | 810 |
| 939 TEST_F(FileCacheTestOnUIThread, Iterate) { | 811 TEST_F(FileCacheTestOnUIThread, Iterate) { |
| 940 const std::vector<test_util::TestCacheResource> cache_resources( | 812 const std::vector<test_util::TestCacheResource> cache_resources( |
| 941 test_util::GetDefaultTestCacheResources()); | 813 test_util::GetDefaultTestCacheResources()); |
| 942 ASSERT_TRUE(test_util::PrepareTestCacheResources(cache_.get(), | 814 ASSERT_TRUE(test_util::PrepareTestCacheResources(cache_.get(), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 963 | 835 |
| 964 ASSERT_EQ(6U, cache_entries.size()); | 836 ASSERT_EQ(6U, cache_entries.size()); |
| 965 } | 837 } |
| 966 | 838 |
| 967 TEST_F(FileCacheTestOnUIThread, ClearAll) { | 839 TEST_F(FileCacheTestOnUIThread, ClearAll) { |
| 968 std::string resource_id("pdf:1a2b"); | 840 std::string resource_id("pdf:1a2b"); |
| 969 std::string md5("abcdef0123456789"); | 841 std::string md5("abcdef0123456789"); |
| 970 | 842 |
| 971 // Store an existing file. | 843 // Store an existing file. |
| 972 TestStoreToCache(resource_id, md5, dummy_file_path_, | 844 TestStoreToCache(resource_id, md5, dummy_file_path_, |
| 973 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, | 845 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT); |
| 974 FileCache::CACHE_TYPE_TMP); | |
| 975 | 846 |
| 976 // Verify that there's only one cached file. | 847 // Verify that there's only one cached file. |
| 977 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); | 848 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); |
| 978 | 849 |
| 979 // Clear cache. | 850 // Clear cache. |
| 980 bool success = false; | 851 bool success = false; |
| 981 cache_->ClearAllOnUIThread( | 852 cache_->ClearAllOnUIThread( |
| 982 google_apis::test_util::CreateCopyResultCallback(&success)); | 853 google_apis::test_util::CreateCopyResultCallback(&success)); |
| 983 google_apis::test_util::RunBlockingPoolTask(); | 854 google_apis::test_util::RunBlockingPoolTask(); |
| 984 EXPECT_TRUE(success); | 855 EXPECT_TRUE(success); |
| 985 | 856 |
| 986 // Verify that all the cache is removed. | 857 // Verify that all the cache is removed. |
| 987 expected_error_ = FILE_ERROR_OK; | 858 expected_error_ = FILE_ERROR_OK; |
| 988 VerifyRemoveFromCache(FILE_ERROR_OK, resource_id, md5); | 859 VerifyRemoveFromCache(FILE_ERROR_OK, resource_id, md5); |
| 989 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); | 860 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); |
| 990 } | 861 } |
| 991 | 862 |
| 992 TEST_F(FileCacheTestOnUIThread, StoreToCacheNoSpace) { | 863 TEST_F(FileCacheTestOnUIThread, StoreToCacheNoSpace) { |
| 993 fake_free_disk_space_getter_->set_default_value(0); | 864 fake_free_disk_space_getter_->set_default_value(0); |
| 994 | 865 |
| 995 std::string resource_id("pdf:1a2b"); | 866 std::string resource_id("pdf:1a2b"); |
| 996 std::string md5("abcdef0123456789"); | 867 std::string md5("abcdef0123456789"); |
| 997 | 868 |
| 998 // Try to store an existing file. | 869 // Try to store an existing file. |
| 999 TestStoreToCache(resource_id, md5, dummy_file_path_, | 870 TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_NO_SPACE, |
| 1000 FILE_ERROR_NO_SPACE, | 871 test_util::TEST_CACHE_STATE_NONE); |
| 1001 test_util::TEST_CACHE_STATE_NONE, | |
| 1002 FileCache::CACHE_TYPE_TMP); | |
| 1003 | 872 |
| 1004 // Verify that there's no files added. | 873 // Verify that there's no files added. |
| 1005 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); | 874 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); |
| 1006 } | 875 } |
| 1007 | 876 |
| 1008 // Don't use TEST_F, as we don't want SetUp() and TearDown() for this test. | 877 // Don't use TEST_F, as we don't want SetUp() and TearDown() for this test. |
| 1009 TEST(FileCacheExtraTest, InitializationFailure) { | 878 TEST(FileCacheExtraTest, InitializationFailure) { |
| 1010 content::TestBrowserThreadBundle thread_bundle; | 879 content::TestBrowserThreadBundle thread_bundle; |
| 1011 | 880 |
| 1012 // Set the cache root to a non existent path, so the initialization fails. | 881 // Set the cache root to a non existent path, so the initialization fails. |
| 1013 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache(new FileCache( | 882 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache(new FileCache( |
| 1014 base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/blah"), | 883 base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/blah"), |
| 1015 base::MessageLoopProxy::current(), | 884 base::MessageLoopProxy::current(), |
| 1016 NULL /* free_disk_space_getter */)); | 885 NULL /* free_disk_space_getter */)); |
| 1017 | 886 |
| 1018 bool success = true; | 887 bool success = true; |
| 1019 cache->RequestInitialize( | 888 cache->RequestInitialize( |
| 1020 google_apis::test_util::CreateCopyResultCallback(&success)); | 889 google_apis::test_util::CreateCopyResultCallback(&success)); |
| 1021 base::RunLoop().RunUntilIdle(); | 890 base::RunLoop().RunUntilIdle(); |
| 1022 EXPECT_FALSE(success); | 891 EXPECT_FALSE(success); |
| 1023 } | 892 } |
| 1024 | 893 |
| 1025 TEST_F(FileCacheTestOnUIThread, UpdatePinnedCache) { | 894 TEST_F(FileCacheTestOnUIThread, UpdatePinnedCache) { |
| 1026 std::string resource_id("pdf:1a2b"); | 895 std::string resource_id("pdf:1a2b"); |
| 1027 std::string md5("abcdef0123456789"); | 896 std::string md5("abcdef0123456789"); |
| 1028 std::string md5_modified("aaaaaa0000000000"); | 897 std::string md5_modified("aaaaaa0000000000"); |
| 1029 | 898 |
| 1030 // Store an existing file. | 899 // Store an existing file. |
| 1031 TestStoreToCache(resource_id, md5, dummy_file_path_, | 900 TestStoreToCache(resource_id, md5, dummy_file_path_, FILE_ERROR_OK, |
| 1032 FILE_ERROR_OK, | 901 test_util::TEST_CACHE_STATE_PRESENT); |
| 1033 test_util::TEST_CACHE_STATE_PRESENT, | |
| 1034 FileCache::CACHE_TYPE_TMP); | |
| 1035 | 902 |
| 1036 // Pin the file. | 903 // Pin the file. |
| 1037 TestPin(resource_id, md5, | 904 TestPin(resource_id, md5, FILE_ERROR_OK, |
| 1038 FILE_ERROR_OK, | |
| 1039 test_util::TEST_CACHE_STATE_PRESENT | | 905 test_util::TEST_CACHE_STATE_PRESENT | |
| 1040 test_util::TEST_CACHE_STATE_PINNED | | 906 test_util::TEST_CACHE_STATE_PINNED); |
| 1041 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 1042 FileCache::CACHE_TYPE_PERSISTENT); | |
| 1043 | 907 |
| 1044 // Store the file with a modified content and md5. It should stay pinned. | 908 // Store the file with a modified content and md5. It should stay pinned. |
| 1045 TestStoreToCache(resource_id, md5_modified, dummy_file_path_, | 909 TestStoreToCache(resource_id, md5_modified, dummy_file_path_, FILE_ERROR_OK, |
| 1046 FILE_ERROR_OK, | |
| 1047 test_util::TEST_CACHE_STATE_PRESENT | | 910 test_util::TEST_CACHE_STATE_PRESENT | |
| 1048 test_util::TEST_CACHE_STATE_PINNED | | 911 test_util::TEST_CACHE_STATE_PINNED); |
| 1049 test_util::TEST_CACHE_STATE_PERSISTENT, | |
| 1050 FileCache::CACHE_TYPE_PERSISTENT); | |
| 1051 } | 912 } |
| 1052 | 913 |
| 1053 // Tests FileCache methods working with the blocking task runner. | 914 // Tests FileCache methods working with the blocking task runner. |
| 1054 class FileCacheTest : public testing::Test { | 915 class FileCacheTest : public testing::Test { |
| 1055 protected: | 916 protected: |
| 1056 virtual void SetUp() OVERRIDE { | 917 virtual void SetUp() OVERRIDE { |
| 1057 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 918 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 1058 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); | 919 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); |
| 1059 | 920 |
| 1060 cache_.reset(new FileCache(temp_dir_.path(), | 921 cache_.reset(new FileCache(temp_dir_.path(), |
| 1061 base::MessageLoopProxy::current(), | 922 base::MessageLoopProxy::current(), |
| 1062 fake_free_disk_space_getter_.get())); | 923 fake_free_disk_space_getter_.get())); |
| 1063 | 924 |
| 1064 bool success = false; | 925 bool success = false; |
| 1065 cache_->RequestInitialize( | 926 cache_->RequestInitialize( |
| 1066 google_apis::test_util::CreateCopyResultCallback(&success)); | 927 google_apis::test_util::CreateCopyResultCallback(&success)); |
| 1067 base::RunLoop().RunUntilIdle(); | 928 base::RunLoop().RunUntilIdle(); |
| 1068 ASSERT_TRUE(success); | 929 ASSERT_TRUE(success); |
| 1069 } | 930 } |
| 1070 | 931 |
| 1071 virtual void TearDown() OVERRIDE { | 932 virtual void TearDown() OVERRIDE { |
| 1072 cache_.reset(); | 933 cache_.reset(); |
| 1073 } | 934 } |
| 1074 | 935 |
| 936 static void MigrateFilesFromOldDirectories(FileCache* cache) { | |
| 937 cache->MigrateFilesFromOldDirectories(); | |
| 938 } | |
| 939 | |
| 1075 content::TestBrowserThreadBundle thread_bundle_; | 940 content::TestBrowserThreadBundle thread_bundle_; |
| 1076 base::ScopedTempDir temp_dir_; | 941 base::ScopedTempDir temp_dir_; |
| 1077 | 942 |
| 1078 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; | 943 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; |
| 1079 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; | 944 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; |
| 1080 }; | 945 }; |
| 1081 | 946 |
| 947 TEST_F(FileCacheTest, MigrateFilesFromOldDirectories) { | |
| 948 const base::FilePath persistent_directory = | |
| 949 temp_dir_.path().AppendASCII("persistent"); | |
| 950 const base::FilePath tmp_directory = temp_dir_.path().AppendASCII("tmp"); | |
| 951 const base::FilePath files_directory = | |
| 952 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_FILES); | |
| 953 | |
| 954 // Prepare directories with previously used names. | |
| 955 ASSERT_TRUE(file_util::CreateDirectory(persistent_directory)); | |
| 956 ASSERT_TRUE(file_util::CreateDirectory(tmp_directory)); | |
| 957 | |
| 958 // Put some files. | |
| 959 ASSERT_TRUE(google_apis::test_util::WriteStringToFile( | |
| 960 persistent_directory.AppendASCII("foo.abc"), "foo")); | |
| 961 ASSERT_TRUE(google_apis::test_util::WriteStringToFile( | |
| 962 tmp_directory.AppendASCII("bar.123"), "bar")); | |
| 963 | |
| 964 // Delete the existing directory. | |
| 965 ASSERT_TRUE(file_util::Delete(files_directory, true /* recursive */)); | |
| 966 | |
| 967 // Migrate. | |
| 968 MigrateFilesFromOldDirectories(cache_.get()); | |
| 969 | |
| 970 EXPECT_FALSE(file_util::PathExists(persistent_directory)); | |
| 971 EXPECT_FALSE(file_util::PathExists(tmp_directory)); | |
| 972 EXPECT_TRUE(file_util::PathExists(files_directory)); | |
| 973 EXPECT_TRUE(file_util::PathExists(files_directory.AppendASCII("foo.abc"))); | |
| 974 EXPECT_TRUE(file_util::PathExists(files_directory.AppendASCII("bar.123"))); | |
| 975 } | |
| 976 | |
| 1082 TEST_F(FileCacheTest, ScanCacheFile) { | 977 TEST_F(FileCacheTest, ScanCacheFile) { |
| 1083 // Set up files in cache directories. | 978 // Set up files in the cache directory. |
| 1084 const base::FilePath persistent_directory = | 979 const base::FilePath directory = |
| 1085 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_PERSISTENT); | 980 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_FILES); |
| 1086 ASSERT_TRUE(google_apis::test_util::WriteStringToFile( | 981 ASSERT_TRUE(google_apis::test_util::WriteStringToFile( |
| 1087 persistent_directory.AppendASCII("id_foo.md5foo"), "foo")); | 982 directory.AppendASCII("id_foo.md5foo"), "foo")); |
| 1088 ASSERT_TRUE(google_apis::test_util::WriteStringToFile( | 983 ASSERT_TRUE(google_apis::test_util::WriteStringToFile( |
| 1089 persistent_directory.AppendASCII("id_bar.local"), "bar")); | 984 directory.AppendASCII("id_bar.local"), "bar")); |
| 1090 | |
| 1091 const base::FilePath tmp_directory = | |
| 1092 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_TMP); | |
| 1093 ASSERT_TRUE(google_apis::test_util::WriteStringToFile( | |
| 1094 tmp_directory.AppendASCII("id_qux.md5qux"), "qux")); | |
| 1095 ASSERT_TRUE(google_apis::test_util::WriteStringToFile( | |
| 1096 tmp_directory.AppendASCII("id_quux.local"), "quux")); | |
| 1097 | 985 |
| 1098 // Remove the existing DB. | 986 // Remove the existing DB. |
| 1099 ASSERT_TRUE(file_util::Delete( | 987 ASSERT_TRUE(file_util::Delete( |
| 1100 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_META), | 988 cache_->GetCacheDirectoryPath(FileCache::CACHE_TYPE_META), |
| 1101 true /* recursive */)); | 989 true /* recursive */)); |
| 1102 | 990 |
| 1103 // Create a new cache and initialize it. | 991 // Create a new cache and initialize it. |
| 1104 cache_.reset(new FileCache(temp_dir_.path(), | 992 cache_.reset(new FileCache(temp_dir_.path(), |
| 1105 base::MessageLoopProxy::current(), | 993 base::MessageLoopProxy::current(), |
| 1106 fake_free_disk_space_getter_.get())); | 994 fake_free_disk_space_getter_.get())); |
| 1107 bool success = false; | 995 bool success = false; |
| 1108 cache_->RequestInitialize( | 996 cache_->RequestInitialize( |
| 1109 google_apis::test_util::CreateCopyResultCallback(&success)); | 997 google_apis::test_util::CreateCopyResultCallback(&success)); |
| 1110 base::RunLoop().RunUntilIdle(); | 998 base::RunLoop().RunUntilIdle(); |
| 1111 ASSERT_TRUE(success); | 999 ASSERT_TRUE(success); |
| 1112 | 1000 |
| 1113 // Check contents of the cache. | 1001 // Check contents of the cache. |
| 1114 FileCacheEntry cache_entry; | 1002 FileCacheEntry cache_entry; |
| 1115 EXPECT_TRUE(cache_->GetCacheEntry("id_foo", std::string(), &cache_entry)); | 1003 EXPECT_TRUE(cache_->GetCacheEntry("id_foo", std::string(), &cache_entry)); |
| 1116 EXPECT_TRUE(cache_entry.is_present()); | 1004 EXPECT_TRUE(cache_entry.is_present()); |
| 1117 EXPECT_EQ("md5foo", cache_entry.md5()); | 1005 EXPECT_EQ("md5foo", cache_entry.md5()); |
| 1118 | 1006 |
| 1119 EXPECT_TRUE(cache_->GetCacheEntry("id_bar", std::string(), &cache_entry)); | 1007 EXPECT_TRUE(cache_->GetCacheEntry("id_bar", std::string(), &cache_entry)); |
| 1120 EXPECT_TRUE(cache_entry.is_present()); | 1008 EXPECT_TRUE(cache_entry.is_present()); |
| 1121 EXPECT_TRUE(cache_entry.is_dirty()); | 1009 EXPECT_TRUE(cache_entry.is_dirty()); |
| 1122 | |
| 1123 EXPECT_TRUE(cache_->GetCacheEntry("id_qux", std::string(), &cache_entry)); | |
| 1124 EXPECT_EQ("md5qux", cache_entry.md5()); | |
| 1125 | |
| 1126 EXPECT_FALSE(cache_->GetCacheEntry("id_quux", std::string(), &cache_entry)); | |
| 1127 | |
| 1128 } | 1010 } |
| 1129 | 1011 |
| 1130 TEST_F(FileCacheTest, FreeDiskSpaceIfNeededFor) { | 1012 TEST_F(FileCacheTest, FreeDiskSpaceIfNeededFor) { |
| 1131 base::FilePath src_file; | 1013 base::FilePath src_file; |
| 1132 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), &src_file)); | 1014 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), &src_file)); |
| 1133 | 1015 |
| 1134 // Store a file as a 'temporary' file and remember the path. | 1016 // Store a file as a 'temporary' file and remember the path. |
| 1135 const std::string resource_id_tmp = "id_tmp", md5_tmp = "md5_tmp"; | 1017 const std::string resource_id_tmp = "id_tmp", md5_tmp = "md5_tmp"; |
| 1136 ASSERT_EQ(FILE_ERROR_OK, | 1018 ASSERT_EQ(FILE_ERROR_OK, |
| 1137 cache_->Store(resource_id_tmp, md5_tmp, src_file, | 1019 cache_->Store(resource_id_tmp, md5_tmp, src_file, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1164 EXPECT_TRUE(cache_->GetCacheEntry(resource_id_pinned, md5_pinned, &entry)); | 1046 EXPECT_TRUE(cache_->GetCacheEntry(resource_id_pinned, md5_pinned, &entry)); |
| 1165 EXPECT_TRUE(file_util::PathExists(pinned_path)); | 1047 EXPECT_TRUE(file_util::PathExists(pinned_path)); |
| 1166 | 1048 |
| 1167 // Returns false when disk space cannot be freed. | 1049 // Returns false when disk space cannot be freed. |
| 1168 fake_free_disk_space_getter_->set_default_value(0); | 1050 fake_free_disk_space_getter_->set_default_value(0); |
| 1169 EXPECT_FALSE(cache_->FreeDiskSpaceIfNeededFor(kNeededBytes)); | 1051 EXPECT_FALSE(cache_->FreeDiskSpaceIfNeededFor(kNeededBytes)); |
| 1170 } | 1052 } |
| 1171 | 1053 |
| 1172 } // namespace internal | 1054 } // namespace internal |
| 1173 } // namespace drive | 1055 } // namespace drive |
| OLD | NEW |