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

Side by Side Diff: chrome/browser/chromeos/drive/file_cache_unittest.cc

Issue 15060002: drive: Rename FileCache methods in a blocking pool centric manner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove virtual Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cache_resources); ++i) { 126 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cache_resources); ++i) {
127 const struct TestCacheResource& resource = test_cache_resources[i]; 127 const struct TestCacheResource& resource = test_cache_resources[i];
128 // Copy file from data dir to cache. 128 // Copy file from data dir to cache.
129 if (!std::string(resource.source_file).empty()) { 129 if (!std::string(resource.source_file).empty()) {
130 base::FilePath source_path = 130 base::FilePath source_path =
131 google_apis::test_util::GetTestFilePath( 131 google_apis::test_util::GetTestFilePath(
132 std::string("chromeos/") + resource.source_file); 132 std::string("chromeos/") + resource.source_file);
133 133
134 FileError error = FILE_ERROR_OK; 134 FileError error = FILE_ERROR_OK;
135 cache_->Store( 135 cache_->StoreOnUIThread(
136 resource.resource_id, 136 resource.resource_id,
137 resource.md5, 137 resource.md5,
138 source_path, 138 source_path,
139 FileCache::FILE_OPERATION_COPY, 139 FileCache::FILE_OPERATION_COPY,
140 google_apis::test_util::CreateCopyResultCallback(&error)); 140 google_apis::test_util::CreateCopyResultCallback(&error));
141 google_apis::test_util::RunBlockingPoolTask(); 141 google_apis::test_util::RunBlockingPoolTask();
142 EXPECT_EQ(FILE_ERROR_OK, error); 142 EXPECT_EQ(FILE_ERROR_OK, error);
143 } 143 }
144 // Pin. 144 // Pin.
145 if (resource.is_pinned) { 145 if (resource.is_pinned) {
146 FileError error = FILE_ERROR_OK; 146 FileError error = FILE_ERROR_OK;
147 EXPECT_CALL(*mock_cache_observer_, 147 EXPECT_CALL(*mock_cache_observer_,
148 OnCachePinned(resource.resource_id, resource.md5)).Times(1); 148 OnCachePinned(resource.resource_id, resource.md5)).Times(1);
149 cache_->Pin( 149 cache_->PinOnUIThread(
150 resource.resource_id, 150 resource.resource_id,
151 resource.md5, 151 resource.md5,
152 google_apis::test_util::CreateCopyResultCallback(&error)); 152 google_apis::test_util::CreateCopyResultCallback(&error));
153 google_apis::test_util::RunBlockingPoolTask(); 153 google_apis::test_util::RunBlockingPoolTask();
154 EXPECT_EQ(FILE_ERROR_OK, error); 154 EXPECT_EQ(FILE_ERROR_OK, error);
155 } 155 }
156 // Mark dirty. 156 // Mark dirty.
157 if (resource.is_dirty) { 157 if (resource.is_dirty) {
158 FileError error = FILE_ERROR_OK; 158 FileError error = FILE_ERROR_OK;
159 cache_->MarkDirty( 159 cache_->MarkDirtyOnUIThread(
160 resource.resource_id, 160 resource.resource_id,
161 resource.md5, 161 resource.md5,
162 google_apis::test_util::CreateCopyResultCallback(&error)); 162 google_apis::test_util::CreateCopyResultCallback(&error));
163 google_apis::test_util::RunBlockingPoolTask(); 163 google_apis::test_util::RunBlockingPoolTask();
164 EXPECT_EQ(FILE_ERROR_OK, error); 164 EXPECT_EQ(FILE_ERROR_OK, error);
165 165
166 EXPECT_CALL(*mock_cache_observer_, 166 EXPECT_CALL(*mock_cache_observer_,
167 OnCacheCommitted(resource.resource_id)).Times(1); 167 OnCacheCommitted(resource.resource_id)).Times(1);
168 cache_->CommitDirty( 168 cache_->CommitDirtyOnUIThread(
169 resource.resource_id, 169 resource.resource_id,
170 resource.md5, 170 resource.md5,
171 google_apis::test_util::CreateCopyResultCallback(&error)); 171 google_apis::test_util::CreateCopyResultCallback(&error));
172 google_apis::test_util::RunBlockingPoolTask(); 172 google_apis::test_util::RunBlockingPoolTask();
173 EXPECT_EQ(FILE_ERROR_OK, error); 173 EXPECT_EQ(FILE_ERROR_OK, error);
174 } 174 }
175 } 175 }
176 } 176 }
177 177
178 void TestGetFileFromCacheByResourceIdAndMd5( 178 void TestGetFileFromCacheByResourceIdAndMd5(
179 const std::string& resource_id, 179 const std::string& resource_id,
180 const std::string& md5, 180 const std::string& md5,
181 FileError expected_error, 181 FileError expected_error,
182 const std::string& expected_file_extension) { 182 const std::string& expected_file_extension) {
183 FileError error = FILE_ERROR_OK; 183 FileError error = FILE_ERROR_OK;
184 base::FilePath cache_file_path; 184 base::FilePath cache_file_path;
185 cache_->GetFile(resource_id, md5, 185 cache_->GetFileOnUIThread(resource_id, md5,
186 google_apis::test_util::CreateCopyResultCallback( 186 google_apis::test_util::CreateCopyResultCallback(
187 &error, &cache_file_path)); 187 &error, &cache_file_path));
188 google_apis::test_util::RunBlockingPoolTask(); 188 google_apis::test_util::RunBlockingPoolTask();
189 189
190 EXPECT_EQ(expected_error, error); 190 EXPECT_EQ(expected_error, error);
191 if (error == FILE_ERROR_OK) { 191 if (error == FILE_ERROR_OK) {
192 // Verify filename of |cache_file_path|. 192 // Verify filename of |cache_file_path|.
193 base::FilePath base_name = cache_file_path.BaseName(); 193 base::FilePath base_name = cache_file_path.BaseName();
194 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + 194 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
195 base::FilePath::kExtensionSeparator + 195 base::FilePath::kExtensionSeparator +
196 util::EscapeCacheFileName( 196 util::EscapeCacheFileName(
197 expected_file_extension.empty() ? 197 expected_file_extension.empty() ?
198 md5 : expected_file_extension), 198 md5 : expected_file_extension),
199 base_name.value()); 199 base_name.value());
200 } else { 200 } else {
201 EXPECT_TRUE(cache_file_path.empty()); 201 EXPECT_TRUE(cache_file_path.empty());
202 } 202 }
203 } 203 }
204 204
205 void TestStoreToCache( 205 void TestStoreToCache(
206 const std::string& resource_id, 206 const std::string& resource_id,
207 const std::string& md5, 207 const std::string& md5,
208 const base::FilePath& source_path, 208 const base::FilePath& source_path,
209 FileError expected_error, 209 FileError expected_error,
210 int expected_cache_state, 210 int expected_cache_state,
211 FileCache::CacheSubDirectoryType expected_sub_dir_type) { 211 FileCache::CacheSubDirectoryType expected_sub_dir_type) {
212 expected_error_ = expected_error; 212 expected_error_ = expected_error;
213 expected_cache_state_ = expected_cache_state; 213 expected_cache_state_ = expected_cache_state;
214 expected_sub_dir_type_ = expected_sub_dir_type; 214 expected_sub_dir_type_ = expected_sub_dir_type;
215 215
216 FileError error = FILE_ERROR_OK; 216 FileError error = FILE_ERROR_OK;
217 cache_->Store(resource_id, md5, source_path, 217 cache_->StoreOnUIThread(
218 FileCache::FILE_OPERATION_COPY, 218 resource_id, md5, source_path,
219 google_apis::test_util::CreateCopyResultCallback(&error)); 219 FileCache::FILE_OPERATION_COPY,
220 google_apis::test_util::CreateCopyResultCallback(&error));
220 google_apis::test_util::RunBlockingPoolTask(); 221 google_apis::test_util::RunBlockingPoolTask();
221 VerifyCacheFileState(error, resource_id, md5); 222 VerifyCacheFileState(error, resource_id, md5);
222 } 223 }
223 224
224 void TestStoreLocallyModifiedToCache( 225 void TestStoreLocallyModifiedToCache(
225 const std::string& resource_id, 226 const std::string& resource_id,
226 const std::string& md5, 227 const std::string& md5,
227 const base::FilePath& source_path, 228 const base::FilePath& source_path,
228 FileError expected_error, 229 FileError expected_error,
229 int expected_cache_state, 230 int expected_cache_state,
230 FileCache::CacheSubDirectoryType expected_sub_dir_type, 231 FileCache::CacheSubDirectoryType expected_sub_dir_type,
231 bool expected_outgoing_symlink) { 232 bool expected_outgoing_symlink) {
232 expected_error_ = expected_error; 233 expected_error_ = expected_error;
233 expected_cache_state_ = expected_cache_state; 234 expected_cache_state_ = expected_cache_state;
234 expected_sub_dir_type_ = expected_sub_dir_type; 235 expected_sub_dir_type_ = expected_sub_dir_type;
235 expect_outgoing_symlink_ = expected_outgoing_symlink; 236 expect_outgoing_symlink_ = expected_outgoing_symlink;
236 237
237 FileError error = FILE_ERROR_OK; 238 FileError error = FILE_ERROR_OK;
238 cache_->StoreLocallyModified( 239 cache_->StoreLocallyModifiedOnUIThread(
239 resource_id, md5, source_path, 240 resource_id, md5, source_path,
240 FileCache::FILE_OPERATION_COPY, 241 FileCache::FILE_OPERATION_COPY,
241 google_apis::test_util::CreateCopyResultCallback(&error)); 242 google_apis::test_util::CreateCopyResultCallback(&error));
242 google_apis::test_util::RunBlockingPoolTask(); 243 google_apis::test_util::RunBlockingPoolTask();
243 VerifyCacheFileState(error, resource_id, md5); 244 VerifyCacheFileState(error, resource_id, md5);
244 } 245 }
245 246
246 void TestRemoveFromCache(const std::string& resource_id, 247 void TestRemoveFromCache(const std::string& resource_id,
247 FileError expected_error) { 248 FileError expected_error) {
248 expected_error_ = expected_error; 249 expected_error_ = expected_error;
249 250
250 FileError error = FILE_ERROR_OK; 251 FileError error = FILE_ERROR_OK;
251 cache_->Remove( 252 cache_->RemoveOnUIThread(
252 resource_id, 253 resource_id,
253 google_apis::test_util::CreateCopyResultCallback(&error)); 254 google_apis::test_util::CreateCopyResultCallback(&error));
254 google_apis::test_util::RunBlockingPoolTask(); 255 google_apis::test_util::RunBlockingPoolTask();
255 VerifyRemoveFromCache(error, resource_id, ""); 256 VerifyRemoveFromCache(error, resource_id, "");
256 } 257 }
257 258
258 void VerifyRemoveFromCache(FileError error, 259 void VerifyRemoveFromCache(FileError error,
259 const std::string& resource_id, 260 const std::string& resource_id,
260 const std::string& md5) { 261 const std::string& md5) {
261 EXPECT_EQ(expected_error_, error); 262 EXPECT_EQ(expected_error_, error);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 const std::string& resource_id, 339 const std::string& resource_id,
339 const std::string& md5, 340 const std::string& md5,
340 FileError expected_error, 341 FileError expected_error,
341 int expected_cache_state, 342 int expected_cache_state,
342 FileCache::CacheSubDirectoryType expected_sub_dir_type) { 343 FileCache::CacheSubDirectoryType expected_sub_dir_type) {
343 expected_error_ = expected_error; 344 expected_error_ = expected_error;
344 expected_cache_state_ = expected_cache_state; 345 expected_cache_state_ = expected_cache_state;
345 expected_sub_dir_type_ = expected_sub_dir_type; 346 expected_sub_dir_type_ = expected_sub_dir_type;
346 347
347 FileError error = FILE_ERROR_OK; 348 FileError error = FILE_ERROR_OK;
348 cache_->Pin(resource_id, md5, 349 cache_->PinOnUIThread(
349 google_apis::test_util::CreateCopyResultCallback(&error)); 350 resource_id, md5,
351 google_apis::test_util::CreateCopyResultCallback(&error));
350 google_apis::test_util::RunBlockingPoolTask(); 352 google_apis::test_util::RunBlockingPoolTask();
351 VerifyCacheFileState(error, resource_id, md5); 353 VerifyCacheFileState(error, resource_id, md5);
352 } 354 }
353 355
354 void TestUnpin( 356 void TestUnpin(
355 const std::string& resource_id, 357 const std::string& resource_id,
356 const std::string& md5, 358 const std::string& md5,
357 FileError expected_error, 359 FileError expected_error,
358 int expected_cache_state, 360 int expected_cache_state,
359 FileCache::CacheSubDirectoryType expected_sub_dir_type) { 361 FileCache::CacheSubDirectoryType expected_sub_dir_type) {
360 expected_error_ = expected_error; 362 expected_error_ = expected_error;
361 expected_cache_state_ = expected_cache_state; 363 expected_cache_state_ = expected_cache_state;
362 expected_sub_dir_type_ = expected_sub_dir_type; 364 expected_sub_dir_type_ = expected_sub_dir_type;
363 365
364 FileError error = FILE_ERROR_OK; 366 FileError error = FILE_ERROR_OK;
365 cache_->Unpin(resource_id, md5, 367 cache_->UnpinOnUIThread(
366 google_apis::test_util::CreateCopyResultCallback(&error)); 368 resource_id, md5,
369 google_apis::test_util::CreateCopyResultCallback(&error));
367 google_apis::test_util::RunBlockingPoolTask(); 370 google_apis::test_util::RunBlockingPoolTask();
368 VerifyCacheFileState(error, resource_id, md5); 371 VerifyCacheFileState(error, resource_id, md5);
369 } 372 }
370 373
371 void TestMarkDirty(const std::string& resource_id, 374 void TestMarkDirty(const std::string& resource_id,
372 const std::string& md5, 375 const std::string& md5,
373 FileError expected_error, 376 FileError expected_error,
374 int expected_cache_state, 377 int expected_cache_state,
375 FileCache::CacheSubDirectoryType expected_sub_dir_type) { 378 FileCache::CacheSubDirectoryType expected_sub_dir_type) {
376 expected_error_ = expected_error; 379 expected_error_ = expected_error;
377 expected_cache_state_ = expected_cache_state; 380 expected_cache_state_ = expected_cache_state;
378 expected_sub_dir_type_ = expected_sub_dir_type; 381 expected_sub_dir_type_ = expected_sub_dir_type;
379 expect_outgoing_symlink_ = false; 382 expect_outgoing_symlink_ = false;
380 383
381 FileError error = FILE_ERROR_OK; 384 FileError error = FILE_ERROR_OK;
382 cache_->MarkDirty( 385 cache_->MarkDirtyOnUIThread(
383 resource_id, md5, 386 resource_id, md5,
384 google_apis::test_util::CreateCopyResultCallback(&error)); 387 google_apis::test_util::CreateCopyResultCallback(&error));
385 google_apis::test_util::RunBlockingPoolTask(); 388 google_apis::test_util::RunBlockingPoolTask();
386 389
387 VerifyCacheFileState(error, resource_id, md5); 390 VerifyCacheFileState(error, resource_id, md5);
388 391
389 // Verify filename. 392 // Verify filename.
390 if (error == FILE_ERROR_OK) { 393 if (error == FILE_ERROR_OK) {
391 base::FilePath cache_file_path; 394 base::FilePath cache_file_path;
392 cache_->GetFile(resource_id, md5, 395 cache_->GetFileOnUIThread(
393 google_apis::test_util::CreateCopyResultCallback( 396 resource_id, md5,
394 &error, &cache_file_path)); 397 google_apis::test_util::CreateCopyResultCallback(
398 &error, &cache_file_path));
395 google_apis::test_util::RunBlockingPoolTask(); 399 google_apis::test_util::RunBlockingPoolTask();
396 400
397 EXPECT_EQ(FILE_ERROR_OK, error); 401 EXPECT_EQ(FILE_ERROR_OK, error);
398 base::FilePath base_name = cache_file_path.BaseName(); 402 base::FilePath base_name = cache_file_path.BaseName();
399 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + 403 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
400 base::FilePath::kExtensionSeparator + 404 base::FilePath::kExtensionSeparator +
401 "local", 405 "local",
402 base_name.value()); 406 base_name.value());
403 } 407 }
404 } 408 }
405 409
406 void TestCommitDirty( 410 void TestCommitDirty(
407 const std::string& resource_id, 411 const std::string& resource_id,
408 const std::string& md5, 412 const std::string& md5,
409 FileError expected_error, 413 FileError expected_error,
410 int expected_cache_state, 414 int expected_cache_state,
411 FileCache::CacheSubDirectoryType expected_sub_dir_type) { 415 FileCache::CacheSubDirectoryType expected_sub_dir_type) {
412 expected_error_ = expected_error; 416 expected_error_ = expected_error;
413 expected_cache_state_ = expected_cache_state; 417 expected_cache_state_ = expected_cache_state;
414 expected_sub_dir_type_ = expected_sub_dir_type; 418 expected_sub_dir_type_ = expected_sub_dir_type;
415 expect_outgoing_symlink_ = true; 419 expect_outgoing_symlink_ = true;
416 420
417 FileError error = FILE_ERROR_OK; 421 FileError error = FILE_ERROR_OK;
418 cache_->CommitDirty( 422 cache_->CommitDirtyOnUIThread(
419 resource_id, md5, 423 resource_id, md5,
420 google_apis::test_util::CreateCopyResultCallback(&error)); 424 google_apis::test_util::CreateCopyResultCallback(&error));
421 google_apis::test_util::RunBlockingPoolTask(); 425 google_apis::test_util::RunBlockingPoolTask();
422 VerifyCacheFileState(error, resource_id, md5); 426 VerifyCacheFileState(error, resource_id, md5);
423 } 427 }
424 428
425 void TestClearDirty( 429 void TestClearDirty(
426 const std::string& resource_id, 430 const std::string& resource_id,
427 const std::string& md5, 431 const std::string& md5,
428 FileError expected_error, 432 FileError expected_error,
429 int expected_cache_state, 433 int expected_cache_state,
430 FileCache::CacheSubDirectoryType expected_sub_dir_type) { 434 FileCache::CacheSubDirectoryType expected_sub_dir_type) {
431 expected_error_ = expected_error; 435 expected_error_ = expected_error;
432 expected_cache_state_ = expected_cache_state; 436 expected_cache_state_ = expected_cache_state;
433 expected_sub_dir_type_ = expected_sub_dir_type; 437 expected_sub_dir_type_ = expected_sub_dir_type;
434 expect_outgoing_symlink_ = false; 438 expect_outgoing_symlink_ = false;
435 439
436 FileError error = FILE_ERROR_OK; 440 FileError error = FILE_ERROR_OK;
437 cache_->ClearDirty( 441 cache_->ClearDirtyOnUIThread(
438 resource_id, md5, 442 resource_id, md5,
439 google_apis::test_util::CreateCopyResultCallback(&error)); 443 google_apis::test_util::CreateCopyResultCallback(&error));
440 google_apis::test_util::RunBlockingPoolTask(); 444 google_apis::test_util::RunBlockingPoolTask();
441 VerifyCacheFileState(error, resource_id, md5); 445 VerifyCacheFileState(error, resource_id, md5);
442 } 446 }
443 447
444 void TestMarkAsMounted( 448 void TestMarkAsMounted(
445 const std::string& resource_id, 449 const std::string& resource_id,
446 const std::string& md5, 450 const std::string& md5,
447 FileError expected_error, 451 FileError expected_error,
448 int expected_cache_state, 452 int expected_cache_state,
449 FileCache::CacheSubDirectoryType expected_sub_dir_type) { 453 FileCache::CacheSubDirectoryType expected_sub_dir_type) {
450 expected_error_ = expected_error; 454 expected_error_ = expected_error;
451 expected_cache_state_ = expected_cache_state; 455 expected_cache_state_ = expected_cache_state;
452 expected_sub_dir_type_ = expected_sub_dir_type; 456 expected_sub_dir_type_ = expected_sub_dir_type;
453 expect_outgoing_symlink_ = false; 457 expect_outgoing_symlink_ = false;
454 458
455 FileError error = FILE_ERROR_OK; 459 FileError error = FILE_ERROR_OK;
456 base::FilePath cache_file_path; 460 base::FilePath cache_file_path;
457 cache_->MarkAsMounted(resource_id, md5, 461 cache_->MarkAsMountedOnUIThread(
458 google_apis::test_util::CreateCopyResultCallback( 462 resource_id, md5,
459 &error, &cache_file_path)); 463 google_apis::test_util::CreateCopyResultCallback(
464 &error, &cache_file_path));
460 google_apis::test_util::RunBlockingPoolTask(); 465 google_apis::test_util::RunBlockingPoolTask();
461 466
462 EXPECT_TRUE(file_util::PathExists(cache_file_path)); 467 EXPECT_TRUE(file_util::PathExists(cache_file_path));
463 EXPECT_EQ(cache_file_path, 468 EXPECT_EQ(cache_file_path,
464 cache_->GetCacheFilePath(resource_id, 469 cache_->GetCacheFilePath(resource_id,
465 md5, 470 md5,
466 expected_sub_dir_type_, 471 expected_sub_dir_type_,
467 FileCache::CACHED_FILE_MOUNTED)); 472 FileCache::CACHED_FILE_MOUNTED));
468 } 473 }
469 474
470 void TestMarkAsUnmounted( 475 void TestMarkAsUnmounted(
471 const std::string& resource_id, 476 const std::string& resource_id,
472 const std::string& md5, 477 const std::string& md5,
473 const base::FilePath& file_path, 478 const base::FilePath& file_path,
474 FileError expected_error, 479 FileError expected_error,
475 int expected_cache_state, 480 int expected_cache_state,
476 FileCache::CacheSubDirectoryType expected_sub_dir_type) { 481 FileCache::CacheSubDirectoryType expected_sub_dir_type) {
477 expected_error_ = expected_error; 482 expected_error_ = expected_error;
478 expected_cache_state_ = expected_cache_state; 483 expected_cache_state_ = expected_cache_state;
479 expected_sub_dir_type_ = expected_sub_dir_type; 484 expected_sub_dir_type_ = expected_sub_dir_type;
480 expect_outgoing_symlink_ = false; 485 expect_outgoing_symlink_ = false;
481 486
482 FileError error = FILE_ERROR_OK; 487 FileError error = FILE_ERROR_OK;
483 cache_->MarkAsUnmounted( 488 cache_->MarkAsUnmountedOnUIThread(
484 file_path, 489 file_path,
485 google_apis::test_util::CreateCopyResultCallback(&error)); 490 google_apis::test_util::CreateCopyResultCallback(&error));
486 google_apis::test_util::RunBlockingPoolTask(); 491 google_apis::test_util::RunBlockingPoolTask();
487 492
488 base::FilePath cache_file_path; 493 base::FilePath cache_file_path;
489 cache_->GetFile(resource_id, md5, 494 cache_->GetFileOnUIThread(
490 google_apis::test_util::CreateCopyResultCallback( 495 resource_id, md5,
491 &error, &cache_file_path)); 496 google_apis::test_util::CreateCopyResultCallback(
497 &error, &cache_file_path));
492 google_apis::test_util::RunBlockingPoolTask(); 498 google_apis::test_util::RunBlockingPoolTask();
493 EXPECT_EQ(FILE_ERROR_OK, error); 499 EXPECT_EQ(FILE_ERROR_OK, error);
494 500
495 EXPECT_TRUE(file_util::PathExists(cache_file_path)); 501 EXPECT_TRUE(file_util::PathExists(cache_file_path));
496 EXPECT_EQ(cache_file_path, 502 EXPECT_EQ(cache_file_path,
497 cache_->GetCacheFilePath(resource_id, 503 cache_->GetCacheFilePath(resource_id,
498 md5, 504 md5,
499 expected_sub_dir_type_, 505 expected_sub_dir_type_,
500 FileCache::CACHED_FILE_FROM_SERVER)); 506 FileCache::CACHED_FILE_FROM_SERVER));
501 } 507 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 FileCache::CachedFileOrigin file_origin) { 571 FileCache::CachedFileOrigin file_origin) {
566 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type, 572 return cache_->GetCacheFilePath(resource_id, md5, sub_dir_type,
567 file_origin); 573 file_origin);
568 } 574 }
569 575
570 // Helper function to call GetCacheEntry from origin thread. 576 // Helper function to call GetCacheEntry from origin thread.
571 bool GetCacheEntryFromOriginThread(const std::string& resource_id, 577 bool GetCacheEntryFromOriginThread(const std::string& resource_id,
572 const std::string& md5, 578 const std::string& md5,
573 FileCacheEntry* cache_entry) { 579 FileCacheEntry* cache_entry) {
574 bool result = false; 580 bool result = false;
575 cache_->GetCacheEntry(resource_id, md5, 581 cache_->GetCacheEntryOnUIThread(
576 google_apis::test_util::CreateCopyResultCallback( 582 resource_id, md5,
577 &result, cache_entry)); 583 google_apis::test_util::CreateCopyResultCallback(&result, cache_entry));
578 google_apis::test_util::RunBlockingPoolTask(); 584 google_apis::test_util::RunBlockingPoolTask();
579 return result; 585 return result;
580 } 586 }
581 587
582 // Returns true if the cache entry exists for the given resource ID and MD5. 588 // Returns true if the cache entry exists for the given resource ID and MD5.
583 bool CacheEntryExists(const std::string& resource_id, 589 bool CacheEntryExists(const std::string& resource_id,
584 const std::string& md5) { 590 const std::string& md5) {
585 FileCacheEntry cache_entry; 591 FileCacheEntry cache_entry;
586 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 592 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
587 } 593 }
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 FileCache::CACHE_TYPE_TMP); 1046 FileCache::CACHE_TYPE_TMP);
1041 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, 1047 TestMarkDirty(resource_id, md5, FILE_ERROR_OK,
1042 test_util::TEST_CACHE_STATE_PRESENT | 1048 test_util::TEST_CACHE_STATE_PRESENT |
1043 test_util::TEST_CACHE_STATE_DIRTY | 1049 test_util::TEST_CACHE_STATE_DIRTY |
1044 test_util::TEST_CACHE_STATE_PERSISTENT, 1050 test_util::TEST_CACHE_STATE_PERSISTENT,
1045 FileCache::CACHE_TYPE_PERSISTENT); 1051 FileCache::CACHE_TYPE_PERSISTENT);
1046 1052
1047 // Verifies dirty file exists. 1053 // Verifies dirty file exists.
1048 base::FilePath dirty_path; 1054 base::FilePath dirty_path;
1049 FileError error = FILE_ERROR_FAILED; 1055 FileError error = FILE_ERROR_FAILED;
1050 cache_->GetFile( 1056 cache_->GetFileOnUIThread(
1051 resource_id, md5, 1057 resource_id, md5,
1052 google_apis::test_util::CreateCopyResultCallback(&error, &dirty_path)); 1058 google_apis::test_util::CreateCopyResultCallback(&error, &dirty_path));
1053 google_apis::test_util::RunBlockingPoolTask(); 1059 google_apis::test_util::RunBlockingPoolTask();
1054 EXPECT_EQ(FILE_ERROR_OK, error); 1060 EXPECT_EQ(FILE_ERROR_OK, error);
1055 EXPECT_TRUE(file_util::PathExists(dirty_path)); 1061 EXPECT_TRUE(file_util::PathExists(dirty_path));
1056 1062
1057 // Pin the dirty file. 1063 // Pin the dirty file.
1058 TestPin(resource_id, md5, FILE_ERROR_OK, 1064 TestPin(resource_id, md5, FILE_ERROR_OK,
1059 test_util::TEST_CACHE_STATE_PRESENT | 1065 test_util::TEST_CACHE_STATE_PRESENT |
1060 test_util::TEST_CACHE_STATE_DIRTY | 1066 test_util::TEST_CACHE_STATE_DIRTY |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 FILE_ERROR_OK, 1263 FILE_ERROR_OK,
1258 test_util::TEST_CACHE_STATE_PRESENT | 1264 test_util::TEST_CACHE_STATE_PRESENT |
1259 test_util::TEST_CACHE_STATE_MOUNTED | 1265 test_util::TEST_CACHE_STATE_MOUNTED |
1260 test_util::TEST_CACHE_STATE_PERSISTENT, 1266 test_util::TEST_CACHE_STATE_PERSISTENT,
1261 FileCache::CACHE_TYPE_PERSISTENT); 1267 FileCache::CACHE_TYPE_PERSISTENT);
1262 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 1268 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1263 1269
1264 // Clear mounted state of the file. 1270 // Clear mounted state of the file.
1265 base::FilePath file_path; 1271 base::FilePath file_path;
1266 FileError error = FILE_ERROR_FAILED; 1272 FileError error = FILE_ERROR_FAILED;
1267 cache_->GetFile( 1273 cache_->GetFileOnUIThread(
1268 resource_id, md5, 1274 resource_id, md5,
1269 google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); 1275 google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
1270 google_apis::test_util::RunBlockingPoolTask(); 1276 google_apis::test_util::RunBlockingPoolTask();
1271 EXPECT_EQ(FILE_ERROR_OK, error); 1277 EXPECT_EQ(FILE_ERROR_OK, error);
1272 1278
1273 TestMarkAsUnmounted(resource_id, md5, file_path, 1279 TestMarkAsUnmounted(resource_id, md5, file_path,
1274 FILE_ERROR_OK, 1280 FILE_ERROR_OK,
1275 test_util::TEST_CACHE_STATE_PRESENT, 1281 test_util::TEST_CACHE_STATE_PRESENT,
1276 FileCache::CACHE_TYPE_TMP); 1282 FileCache::CACHE_TYPE_TMP);
1277 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 1283 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1278 1284
1279 // Try to remove the file. 1285 // Try to remove the file.
1280 TestRemoveFromCache(resource_id, FILE_ERROR_OK); 1286 TestRemoveFromCache(resource_id, FILE_ERROR_OK);
1281 } 1287 }
1282 1288
1283 TEST_F(FileCacheTest, Iterate) { 1289 TEST_F(FileCacheTest, Iterate) {
1284 PrepareTestCacheResources(); 1290 PrepareTestCacheResources();
1285 1291
1286 std::vector<std::string> resource_ids; 1292 std::vector<std::string> resource_ids;
1287 std::vector<FileCacheEntry> cache_entries; 1293 std::vector<FileCacheEntry> cache_entries;
1288 bool completed = false; 1294 bool completed = false;
1289 cache_->Iterate( 1295 cache_->IterateOnUIThread(
1290 base::Bind(&OnIterate, &resource_ids, &cache_entries), 1296 base::Bind(&OnIterate, &resource_ids, &cache_entries),
1291 base::Bind(&OnIterateCompleted, &completed)); 1297 base::Bind(&OnIterateCompleted, &completed));
1292 google_apis::test_util::RunBlockingPoolTask(); 1298 google_apis::test_util::RunBlockingPoolTask();
1293 1299
1294 ASSERT_TRUE(completed); 1300 ASSERT_TRUE(completed);
1295 1301
1296 sort(resource_ids.begin(), resource_ids.end()); 1302 sort(resource_ids.begin(), resource_ids.end());
1297 ASSERT_EQ(6U, resource_ids.size()); 1303 ASSERT_EQ(6U, resource_ids.size());
1298 EXPECT_EQ("dirty:existing", resource_ids[0]); 1304 EXPECT_EQ("dirty:existing", resource_ids[0]);
1299 EXPECT_EQ("dirty_and_pinned:existing", resource_ids[1]); 1305 EXPECT_EQ("dirty_and_pinned:existing", resource_ids[1]);
(...skipping 17 matching lines...) Expand all
1317 resource_id, md5, 1323 resource_id, md5,
1318 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"), 1324 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
1319 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT, 1325 FILE_ERROR_OK, test_util::TEST_CACHE_STATE_PRESENT,
1320 FileCache::CACHE_TYPE_TMP); 1326 FileCache::CACHE_TYPE_TMP);
1321 1327
1322 // Verify that there's only one cached file. 1328 // Verify that there's only one cached file.
1323 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); 1329 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
1324 1330
1325 // Clear cache. 1331 // Clear cache.
1326 bool success = false; 1332 bool success = false;
1327 cache_->ClearAll(google_apis::test_util::CreateCopyResultCallback(&success)); 1333 cache_->ClearAllOnUIThread(
1334 google_apis::test_util::CreateCopyResultCallback(&success));
1328 google_apis::test_util::RunBlockingPoolTask(); 1335 google_apis::test_util::RunBlockingPoolTask();
1329 EXPECT_TRUE(success); 1336 EXPECT_TRUE(success);
1330 1337
1331 // Verify that all the cache is removed. 1338 // Verify that all the cache is removed.
1332 expected_error_ = FILE_ERROR_OK; 1339 expected_error_ = FILE_ERROR_OK;
1333 VerifyRemoveFromCache(FILE_ERROR_OK, resource_id, md5); 1340 VerifyRemoveFromCache(FILE_ERROR_OK, resource_id, md5);
1334 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); 1341 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
1335 } 1342 }
1336 1343
1337 TEST_F(FileCacheTest, StoreToCacheNoSpace) { 1344 TEST_F(FileCacheTest, StoreToCacheNoSpace) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 google_apis::test_util::GetTestFilePath("chromeos/gdata/empty_feed.json"), 1412 google_apis::test_util::GetTestFilePath("chromeos/gdata/empty_feed.json"),
1406 FILE_ERROR_OK, 1413 FILE_ERROR_OK,
1407 test_util::TEST_CACHE_STATE_PRESENT | 1414 test_util::TEST_CACHE_STATE_PRESENT |
1408 test_util::TEST_CACHE_STATE_PINNED | 1415 test_util::TEST_CACHE_STATE_PINNED |
1409 test_util::TEST_CACHE_STATE_PERSISTENT, 1416 test_util::TEST_CACHE_STATE_PERSISTENT,
1410 FileCache::CACHE_TYPE_PERSISTENT); 1417 FileCache::CACHE_TYPE_PERSISTENT);
1411 } 1418 }
1412 1419
1413 } // namespace internal 1420 } // namespace internal
1414 } // namespace drive 1421 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_cache.cc ('k') | chrome/browser/chromeos/drive/file_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698