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

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

Issue 10877006: Rename GDataErrorCode to DriveErrorCode, GDataFileError to DriveFileError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor local variable name fix. Created 8 years, 4 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 *out_to_upload = to_upload; 108 *out_to_upload = to_upload;
109 } 109 }
110 110
111 // Copies results from GetResourceIdsCallback. 111 // Copies results from GetResourceIdsCallback.
112 void OnGetResourceIds(std::vector<std::string>* out_resource_ids, 112 void OnGetResourceIds(std::vector<std::string>* out_resource_ids,
113 const std::vector<std::string>& resource_ids) { 113 const std::vector<std::string>& resource_ids) {
114 *out_resource_ids = resource_ids; 114 *out_resource_ids = resource_ids;
115 } 115 }
116 116
117 // Copies results from ClearAllOnUIThread. 117 // Copies results from ClearAllOnUIThread.
118 void OnClearAll(GDataFileError* out_error, 118 void OnClearAll(DriveFileError* out_error,
119 FilePath* out_file_path, 119 FilePath* out_file_path,
120 GDataFileError error, 120 DriveFileError error,
121 const FilePath& file_path) { 121 const FilePath& file_path) {
122 *out_file_path = file_path; 122 *out_file_path = file_path;
123 *out_error = error; 123 *out_error = error;
124 } 124 }
125 125
126 } // namespace 126 } // namespace
127 127
128 class DriveCacheTest : public testing::Test { 128 class DriveCacheTest : public testing::Test {
129 protected: 129 protected:
130 DriveCacheTest() 130 DriveCacheTest()
131 : ui_thread_(content::BrowserThread::UI, &message_loop_), 131 : ui_thread_(content::BrowserThread::UI, &message_loop_),
132 io_thread_(content::BrowserThread::IO), 132 io_thread_(content::BrowserThread::IO),
133 cache_(NULL), 133 cache_(NULL),
134 num_callback_invocations_(0), 134 num_callback_invocations_(0),
135 expected_error_(GDATA_FILE_OK), 135 expected_error_(DRIVE_FILE_OK),
136 expected_cache_state_(0), 136 expected_cache_state_(0),
137 expected_sub_dir_type_(DriveCache::CACHE_TYPE_META), 137 expected_sub_dir_type_(DriveCache::CACHE_TYPE_META),
138 expected_success_(true), 138 expected_success_(true),
139 expect_outgoing_symlink_(false), 139 expect_outgoing_symlink_(false),
140 root_feed_changestamp_(0) { 140 root_feed_changestamp_(0) {
141 } 141 }
142 142
143 virtual void SetUp() OVERRIDE { 143 virtual void SetUp() OVERRIDE {
144 io_thread_.StartIOThread(); 144 io_thread_.StartIOThread();
145 145
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 void TestInitializeCache() { 242 void TestInitializeCache() {
243 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) { 243 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(initial_cache_resources); ++i) {
244 const struct InitialCacheResource& resource = initial_cache_resources[i]; 244 const struct InitialCacheResource& resource = initial_cache_resources[i];
245 // Check cache file. 245 // Check cache file.
246 num_callback_invocations_ = 0; 246 num_callback_invocations_ = 0;
247 TestGetFileFromCacheByResourceIdAndMd5( 247 TestGetFileFromCacheByResourceIdAndMd5(
248 resource.resource_id, 248 resource.resource_id,
249 resource.md5, 249 resource.md5,
250 test_util::ToCacheEntry(resource.cache_state).is_present() ? 250 test_util::ToCacheEntry(resource.cache_state).is_present() ?
251 GDATA_FILE_OK : 251 DRIVE_FILE_OK :
252 GDATA_FILE_ERROR_NOT_FOUND, 252 DRIVE_FILE_ERROR_NOT_FOUND,
253 resource.expected_file_extension); 253 resource.expected_file_extension);
254 EXPECT_EQ(1, num_callback_invocations_); 254 EXPECT_EQ(1, num_callback_invocations_);
255 255
256 // Verify cache state. 256 // Verify cache state.
257 std::string md5; 257 std::string md5;
258 if (test_util::ToCacheEntry(resource.cache_state).is_present()) 258 if (test_util::ToCacheEntry(resource.cache_state).is_present())
259 md5 = resource.md5; 259 md5 = resource.md5;
260 DriveCacheEntry cache_entry; 260 DriveCacheEntry cache_entry;
261 ASSERT_TRUE(GetCacheEntryFromOriginThread( 261 ASSERT_TRUE(GetCacheEntryFromOriginThread(
262 resource.resource_id, md5, &cache_entry)); 262 resource.resource_id, md5, &cache_entry));
263 EXPECT_TRUE(test_util::CacheStatesEqual( 263 EXPECT_TRUE(test_util::CacheStatesEqual(
264 test_util::ToCacheEntry(resource.cache_state), 264 test_util::ToCacheEntry(resource.cache_state),
265 cache_entry)); 265 cache_entry));
266 EXPECT_EQ(resource.expected_sub_dir_type, 266 EXPECT_EQ(resource.expected_sub_dir_type,
267 DriveCache::GetSubDirectoryType(cache_entry)); 267 DriveCache::GetSubDirectoryType(cache_entry));
268 } 268 }
269 } 269 }
270 270
271 void TestGetFileFromCacheByResourceIdAndMd5( 271 void TestGetFileFromCacheByResourceIdAndMd5(
272 const std::string& resource_id, 272 const std::string& resource_id,
273 const std::string& md5, 273 const std::string& md5,
274 GDataFileError expected_error, 274 DriveFileError expected_error,
275 const std::string& expected_file_extension) { 275 const std::string& expected_file_extension) {
276 expected_error_ = expected_error; 276 expected_error_ = expected_error;
277 expected_file_extension_ = expected_file_extension; 277 expected_file_extension_ = expected_file_extension;
278 278
279 cache_->GetFileOnUIThread( 279 cache_->GetFileOnUIThread(
280 resource_id, md5, 280 resource_id, md5,
281 base::Bind(&DriveCacheTest::VerifyGetFromCache, 281 base::Bind(&DriveCacheTest::VerifyGetFromCache,
282 base::Unretained(this))); 282 base::Unretained(this)));
283 283
284 test_util::RunBlockingPoolTask(); 284 test_util::RunBlockingPoolTask();
285 } 285 }
286 286
287 void TestStoreToCache( 287 void TestStoreToCache(
288 const std::string& resource_id, 288 const std::string& resource_id,
289 const std::string& md5, 289 const std::string& md5,
290 const FilePath& source_path, 290 const FilePath& source_path,
291 GDataFileError expected_error, 291 DriveFileError expected_error,
292 int expected_cache_state, 292 int expected_cache_state,
293 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { 293 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
294 expected_error_ = expected_error; 294 expected_error_ = expected_error;
295 expected_cache_state_ = expected_cache_state; 295 expected_cache_state_ = expected_cache_state;
296 expected_sub_dir_type_ = expected_sub_dir_type; 296 expected_sub_dir_type_ = expected_sub_dir_type;
297 297
298 cache_->StoreOnUIThread( 298 cache_->StoreOnUIThread(
299 resource_id, md5, source_path, 299 resource_id, md5, source_path,
300 DriveCache::FILE_OPERATION_COPY, 300 DriveCache::FILE_OPERATION_COPY,
301 base::Bind(&DriveCacheTest::VerifyCacheFileState, 301 base::Bind(&DriveCacheTest::VerifyCacheFileState,
302 base::Unretained(this))); 302 base::Unretained(this)));
303 303
304 test_util::RunBlockingPoolTask(); 304 test_util::RunBlockingPoolTask();
305 } 305 }
306 306
307 void VerifyGetFromCache(GDataFileError error, 307 void VerifyGetFromCache(DriveFileError error,
308 const std::string& resource_id, 308 const std::string& resource_id,
309 const std::string& md5, 309 const std::string& md5,
310 const FilePath& cache_file_path) { 310 const FilePath& cache_file_path) {
311 ++num_callback_invocations_; 311 ++num_callback_invocations_;
312 312
313 EXPECT_EQ(expected_error_, error); 313 EXPECT_EQ(expected_error_, error);
314 314
315 if (error == GDATA_FILE_OK) { 315 if (error == DRIVE_FILE_OK) {
316 // Verify filename of |cache_file_path|. 316 // Verify filename of |cache_file_path|.
317 FilePath base_name = cache_file_path.BaseName(); 317 FilePath base_name = cache_file_path.BaseName();
318 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + 318 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
319 FilePath::kExtensionSeparator + 319 FilePath::kExtensionSeparator +
320 util::EscapeCacheFileName( 320 util::EscapeCacheFileName(
321 expected_file_extension_.empty() ? 321 expected_file_extension_.empty() ?
322 md5 : expected_file_extension_), 322 md5 : expected_file_extension_),
323 base_name.value()); 323 base_name.value());
324 } else { 324 } else {
325 EXPECT_TRUE(cache_file_path.empty()); 325 EXPECT_TRUE(cache_file_path.empty());
326 } 326 }
327 } 327 }
328 328
329 void TestRemoveFromCache(const std::string& resource_id, 329 void TestRemoveFromCache(const std::string& resource_id,
330 GDataFileError expected_error) { 330 DriveFileError expected_error) {
331 expected_error_ = expected_error; 331 expected_error_ = expected_error;
332 332
333 cache_->RemoveOnUIThread( 333 cache_->RemoveOnUIThread(
334 resource_id, 334 resource_id,
335 base::Bind(&DriveCacheTest::VerifyRemoveFromCache, 335 base::Bind(&DriveCacheTest::VerifyRemoveFromCache,
336 base::Unretained(this))); 336 base::Unretained(this)));
337 337
338 test_util::RunBlockingPoolTask(); 338 test_util::RunBlockingPoolTask();
339 } 339 }
340 340
341 void VerifyRemoveFromCache(GDataFileError error, 341 void VerifyRemoveFromCache(DriveFileError error,
342 const std::string& resource_id, 342 const std::string& resource_id,
343 const std::string& md5) { 343 const std::string& md5) {
344 ++num_callback_invocations_; 344 ++num_callback_invocations_;
345 345
346 EXPECT_EQ(expected_error_, error); 346 EXPECT_EQ(expected_error_, error);
347 347
348 // Verify cache map. 348 // Verify cache map.
349 DriveCacheEntry cache_entry; 349 DriveCacheEntry cache_entry;
350 const bool cache_entry_found = 350 const bool cache_entry_found =
351 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 351 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 EXPECT_EQ(0U, num_files_found); 429 EXPECT_EQ(0U, num_files_found);
430 else 430 else
431 EXPECT_EQ(1U, num_files_found); 431 EXPECT_EQ(1U, num_files_found);
432 } 432 }
433 } 433 }
434 } 434 }
435 435
436 void TestPin( 436 void TestPin(
437 const std::string& resource_id, 437 const std::string& resource_id,
438 const std::string& md5, 438 const std::string& md5,
439 GDataFileError expected_error, 439 DriveFileError expected_error,
440 int expected_cache_state, 440 int expected_cache_state,
441 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { 441 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
442 expected_error_ = expected_error; 442 expected_error_ = expected_error;
443 expected_cache_state_ = expected_cache_state; 443 expected_cache_state_ = expected_cache_state;
444 expected_sub_dir_type_ = expected_sub_dir_type; 444 expected_sub_dir_type_ = expected_sub_dir_type;
445 445
446 cache_->PinOnUIThread( 446 cache_->PinOnUIThread(
447 resource_id, md5, 447 resource_id, md5,
448 base::Bind(&DriveCacheTest::VerifyCacheFileState, 448 base::Bind(&DriveCacheTest::VerifyCacheFileState,
449 base::Unretained(this))); 449 base::Unretained(this)));
450 450
451 test_util::RunBlockingPoolTask(); 451 test_util::RunBlockingPoolTask();
452 } 452 }
453 453
454 void TestUnpin( 454 void TestUnpin(
455 const std::string& resource_id, 455 const std::string& resource_id,
456 const std::string& md5, 456 const std::string& md5,
457 GDataFileError expected_error, 457 DriveFileError expected_error,
458 int expected_cache_state, 458 int expected_cache_state,
459 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { 459 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
460 expected_error_ = expected_error; 460 expected_error_ = expected_error;
461 expected_cache_state_ = expected_cache_state; 461 expected_cache_state_ = expected_cache_state;
462 expected_sub_dir_type_ = expected_sub_dir_type; 462 expected_sub_dir_type_ = expected_sub_dir_type;
463 463
464 cache_->UnpinOnUIThread( 464 cache_->UnpinOnUIThread(
465 resource_id, md5, 465 resource_id, md5,
466 base::Bind(&DriveCacheTest::VerifyCacheFileState, 466 base::Bind(&DriveCacheTest::VerifyCacheFileState,
467 base::Unretained(this))); 467 base::Unretained(this)));
468 468
469 test_util::RunBlockingPoolTask(); 469 test_util::RunBlockingPoolTask();
470 } 470 }
471 471
472 void TestMarkDirty( 472 void TestMarkDirty(
473 const std::string& resource_id, 473 const std::string& resource_id,
474 const std::string& md5, 474 const std::string& md5,
475 GDataFileError expected_error, 475 DriveFileError expected_error,
476 int expected_cache_state, 476 int expected_cache_state,
477 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { 477 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
478 expected_error_ = expected_error; 478 expected_error_ = expected_error;
479 expected_cache_state_ = expected_cache_state; 479 expected_cache_state_ = expected_cache_state;
480 expected_sub_dir_type_ = expected_sub_dir_type; 480 expected_sub_dir_type_ = expected_sub_dir_type;
481 expect_outgoing_symlink_ = false; 481 expect_outgoing_symlink_ = false;
482 482
483 cache_->MarkDirtyOnUIThread( 483 cache_->MarkDirtyOnUIThread(
484 resource_id, md5, 484 resource_id, md5,
485 base::Bind(&DriveCacheTest::VerifyMarkDirty, 485 base::Bind(&DriveCacheTest::VerifyMarkDirty,
486 base::Unretained(this))); 486 base::Unretained(this)));
487 487
488 test_util::RunBlockingPoolTask(); 488 test_util::RunBlockingPoolTask();
489 } 489 }
490 490
491 void VerifyMarkDirty(GDataFileError error, 491 void VerifyMarkDirty(DriveFileError error,
492 const std::string& resource_id, 492 const std::string& resource_id,
493 const std::string& md5, 493 const std::string& md5,
494 const FilePath& cache_file_path) { 494 const FilePath& cache_file_path) {
495 VerifyCacheFileState(error, resource_id, md5); 495 VerifyCacheFileState(error, resource_id, md5);
496 496
497 // Verify filename of |cache_file_path|. 497 // Verify filename of |cache_file_path|.
498 if (error == GDATA_FILE_OK) { 498 if (error == DRIVE_FILE_OK) {
499 FilePath base_name = cache_file_path.BaseName(); 499 FilePath base_name = cache_file_path.BaseName();
500 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + 500 EXPECT_EQ(util::EscapeCacheFileName(resource_id) +
501 FilePath::kExtensionSeparator + 501 FilePath::kExtensionSeparator +
502 "local", 502 "local",
503 base_name.value()); 503 base_name.value());
504 } else { 504 } else {
505 EXPECT_TRUE(cache_file_path.empty()); 505 EXPECT_TRUE(cache_file_path.empty());
506 } 506 }
507 } 507 }
508 508
509 void TestCommitDirty( 509 void TestCommitDirty(
510 const std::string& resource_id, 510 const std::string& resource_id,
511 const std::string& md5, 511 const std::string& md5,
512 GDataFileError expected_error, 512 DriveFileError expected_error,
513 int expected_cache_state, 513 int expected_cache_state,
514 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { 514 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
515 expected_error_ = expected_error; 515 expected_error_ = expected_error;
516 expected_cache_state_ = expected_cache_state; 516 expected_cache_state_ = expected_cache_state;
517 expected_sub_dir_type_ = expected_sub_dir_type; 517 expected_sub_dir_type_ = expected_sub_dir_type;
518 expect_outgoing_symlink_ = true; 518 expect_outgoing_symlink_ = true;
519 519
520 cache_->CommitDirtyOnUIThread( 520 cache_->CommitDirtyOnUIThread(
521 resource_id, md5, 521 resource_id, md5,
522 base::Bind(&DriveCacheTest::VerifyCacheFileState, 522 base::Bind(&DriveCacheTest::VerifyCacheFileState,
523 base::Unretained(this))); 523 base::Unretained(this)));
524 524
525 test_util::RunBlockingPoolTask(); 525 test_util::RunBlockingPoolTask();
526 } 526 }
527 527
528 void TestClearDirty( 528 void TestClearDirty(
529 const std::string& resource_id, 529 const std::string& resource_id,
530 const std::string& md5, 530 const std::string& md5,
531 GDataFileError expected_error, 531 DriveFileError expected_error,
532 int expected_cache_state, 532 int expected_cache_state,
533 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { 533 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
534 expected_error_ = expected_error; 534 expected_error_ = expected_error;
535 expected_cache_state_ = expected_cache_state; 535 expected_cache_state_ = expected_cache_state;
536 expected_sub_dir_type_ = expected_sub_dir_type; 536 expected_sub_dir_type_ = expected_sub_dir_type;
537 expect_outgoing_symlink_ = false; 537 expect_outgoing_symlink_ = false;
538 538
539 cache_->ClearDirtyOnUIThread(resource_id, md5, 539 cache_->ClearDirtyOnUIThread(resource_id, md5,
540 base::Bind(&DriveCacheTest::VerifyCacheFileState, 540 base::Bind(&DriveCacheTest::VerifyCacheFileState,
541 base::Unretained(this))); 541 base::Unretained(this)));
542 542
543 test_util::RunBlockingPoolTask(); 543 test_util::RunBlockingPoolTask();
544 } 544 }
545 545
546 void TestSetMountedState( 546 void TestSetMountedState(
547 const std::string& resource_id, 547 const std::string& resource_id,
548 const std::string& md5, 548 const std::string& md5,
549 const FilePath& file_path, 549 const FilePath& file_path,
550 bool to_mount, 550 bool to_mount,
551 GDataFileError expected_error, 551 DriveFileError expected_error,
552 int expected_cache_state, 552 int expected_cache_state,
553 DriveCache::CacheSubDirectoryType expected_sub_dir_type) { 553 DriveCache::CacheSubDirectoryType expected_sub_dir_type) {
554 expected_error_ = expected_error; 554 expected_error_ = expected_error;
555 expected_cache_state_ = expected_cache_state; 555 expected_cache_state_ = expected_cache_state;
556 expected_sub_dir_type_ = expected_sub_dir_type; 556 expected_sub_dir_type_ = expected_sub_dir_type;
557 expect_outgoing_symlink_ = false; 557 expect_outgoing_symlink_ = false;
558 558
559 cache_->SetMountedStateOnUIThread(file_path, to_mount, 559 cache_->SetMountedStateOnUIThread(file_path, to_mount,
560 base::Bind(&DriveCacheTest::VerifySetMountedState, 560 base::Bind(&DriveCacheTest::VerifySetMountedState,
561 base::Unretained(this), resource_id, md5, to_mount)); 561 base::Unretained(this), resource_id, md5, to_mount));
562 562
563 test_util::RunBlockingPoolTask(); 563 test_util::RunBlockingPoolTask();
564 } 564 }
565 565
566 void VerifySetMountedState(const std::string& resource_id, 566 void VerifySetMountedState(const std::string& resource_id,
567 const std::string& md5, 567 const std::string& md5,
568 bool to_mount, 568 bool to_mount,
569 GDataFileError error, 569 DriveFileError error,
570 const FilePath& file_path) { 570 const FilePath& file_path) {
571 ++num_callback_invocations_; 571 ++num_callback_invocations_;
572 EXPECT_TRUE(file_util::PathExists(file_path)); 572 EXPECT_TRUE(file_util::PathExists(file_path));
573 EXPECT_TRUE(file_path == cache_->GetCacheFilePath( 573 EXPECT_TRUE(file_path == cache_->GetCacheFilePath(
574 resource_id, 574 resource_id,
575 md5, 575 md5,
576 expected_sub_dir_type_, 576 expected_sub_dir_type_,
577 to_mount ? 577 to_mount ?
578 DriveCache::CACHED_FILE_MOUNTED : 578 DriveCache::CACHED_FILE_MOUNTED :
579 DriveCache::CACHED_FILE_FROM_SERVER)); 579 DriveCache::CACHED_FILE_FROM_SERVER));
580 } 580 }
581 581
582 void VerifyCacheFileState(GDataFileError error, 582 void VerifyCacheFileState(DriveFileError error,
583 const std::string& resource_id, 583 const std::string& resource_id,
584 const std::string& md5) { 584 const std::string& md5) {
585 ++num_callback_invocations_; 585 ++num_callback_invocations_;
586 586
587 EXPECT_EQ(expected_error_, error); 587 EXPECT_EQ(expected_error_, error);
588 588
589 // Verify cache map. 589 // Verify cache map.
590 DriveCacheEntry cache_entry; 590 DriveCacheEntry cache_entry;
591 const bool cache_entry_found = 591 const bool cache_entry_found =
592 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); 592 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 // See also content/browser/browser_thread_imple.cc. 767 // See also content/browser/browser_thread_imple.cc.
768 content::TestBrowserThread ui_thread_; 768 content::TestBrowserThread ui_thread_;
769 content::TestBrowserThread io_thread_; 769 content::TestBrowserThread io_thread_;
770 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 770 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
771 scoped_ptr<TestingProfile> profile_; 771 scoped_ptr<TestingProfile> profile_;
772 DriveCache* cache_; 772 DriveCache* cache_;
773 MockFreeDiskSpaceGetter* mock_free_disk_space_checker_; 773 MockFreeDiskSpaceGetter* mock_free_disk_space_checker_;
774 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; 774 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_;
775 775
776 int num_callback_invocations_; 776 int num_callback_invocations_;
777 GDataFileError expected_error_; 777 DriveFileError expected_error_;
778 int expected_cache_state_; 778 int expected_cache_state_;
779 DriveCache::CacheSubDirectoryType expected_sub_dir_type_; 779 DriveCache::CacheSubDirectoryType expected_sub_dir_type_;
780 bool expected_success_; 780 bool expected_success_;
781 bool expect_outgoing_symlink_; 781 bool expect_outgoing_symlink_;
782 std::string expected_file_extension_; 782 std::string expected_file_extension_;
783 int root_feed_changestamp_; 783 int root_feed_changestamp_;
784 }; 784 };
785 785
786 TEST_F(DriveCacheTest, InitializeCache) { 786 TEST_F(DriveCacheTest, InitializeCache) {
787 PrepareForInitCacheTest(); 787 PrepareForInitCacheTest();
(...skipping 23 matching lines...) Expand all
811 811
812 TEST_F(DriveCacheTest, StoreToCacheSimple) { 812 TEST_F(DriveCacheTest, StoreToCacheSimple) {
813 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 813 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
814 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 814 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
815 815
816 std::string resource_id("pdf:1a2b"); 816 std::string resource_id("pdf:1a2b");
817 std::string md5("abcdef0123456789"); 817 std::string md5("abcdef0123456789");
818 818
819 // Store an existing file. 819 // Store an existing file.
820 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 820 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
821 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 821 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
822 DriveCache::CACHE_TYPE_TMP); 822 DriveCache::CACHE_TYPE_TMP);
823 EXPECT_EQ(1, num_callback_invocations_); 823 EXPECT_EQ(1, num_callback_invocations_);
824 824
825 // Store a non-existent file to the same |resource_id| and |md5|. 825 // Store a non-existent file to the same |resource_id| and |md5|.
826 num_callback_invocations_ = 0; 826 num_callback_invocations_ = 0;
827 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"), 827 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"),
828 GDATA_FILE_ERROR_FAILED, 828 DRIVE_FILE_ERROR_FAILED,
829 test_util::TEST_CACHE_STATE_PRESENT, 829 test_util::TEST_CACHE_STATE_PRESENT,
830 DriveCache::CACHE_TYPE_TMP); 830 DriveCache::CACHE_TYPE_TMP);
831 EXPECT_EQ(1, num_callback_invocations_); 831 EXPECT_EQ(1, num_callback_invocations_);
832 832
833 // Store a different existing file to the same |resource_id| but different 833 // Store a different existing file to the same |resource_id| but different
834 // |md5|. 834 // |md5|.
835 md5 = "new_md5"; 835 md5 = "new_md5";
836 num_callback_invocations_ = 0; 836 num_callback_invocations_ = 0;
837 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"), 837 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"),
838 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 838 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
839 DriveCache::CACHE_TYPE_TMP); 839 DriveCache::CACHE_TYPE_TMP);
840 EXPECT_EQ(1, num_callback_invocations_); 840 EXPECT_EQ(1, num_callback_invocations_);
841 841
842 // Verify that there's only one file with name <resource_id>, i.e. previously 842 // Verify that there's only one file with name <resource_id>, i.e. previously
843 // cached file with the different md5 should be deleted. 843 // cached file with the different md5 should be deleted.
844 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); 844 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
845 } 845 }
846 846
847 TEST_F(DriveCacheTest, GetFromCacheSimple) { 847 TEST_F(DriveCacheTest, GetFromCacheSimple) {
848 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 848 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
849 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 849 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
850 850
851 std::string resource_id("pdf:1a2b"); 851 std::string resource_id("pdf:1a2b");
852 std::string md5("abcdef0123456789"); 852 std::string md5("abcdef0123456789");
853 // First store a file to cache. 853 // First store a file to cache.
854 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 854 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
855 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 855 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
856 DriveCache::CACHE_TYPE_TMP); 856 DriveCache::CACHE_TYPE_TMP);
857 857
858 // Then try to get the existing file from cache. 858 // Then try to get the existing file from cache.
859 num_callback_invocations_ = 0; 859 num_callback_invocations_ = 0;
860 TestGetFileFromCacheByResourceIdAndMd5( 860 TestGetFileFromCacheByResourceIdAndMd5(
861 resource_id, md5, GDATA_FILE_OK, md5); 861 resource_id, md5, DRIVE_FILE_OK, md5);
862 EXPECT_EQ(1, num_callback_invocations_); 862 EXPECT_EQ(1, num_callback_invocations_);
863 863
864 // Get file from cache with same resource id as existing file but different 864 // Get file from cache with same resource id as existing file but different
865 // md5. 865 // md5.
866 num_callback_invocations_ = 0; 866 num_callback_invocations_ = 0;
867 TestGetFileFromCacheByResourceIdAndMd5( 867 TestGetFileFromCacheByResourceIdAndMd5(
868 resource_id, "9999", GDATA_FILE_ERROR_NOT_FOUND, md5); 868 resource_id, "9999", DRIVE_FILE_ERROR_NOT_FOUND, md5);
869 EXPECT_EQ(1, num_callback_invocations_); 869 EXPECT_EQ(1, num_callback_invocations_);
870 870
871 // Get file from cache with different resource id from existing file but same 871 // Get file from cache with different resource id from existing file but same
872 // md5. 872 // md5.
873 num_callback_invocations_ = 0; 873 num_callback_invocations_ = 0;
874 resource_id = "document:1a2b"; 874 resource_id = "document:1a2b";
875 TestGetFileFromCacheByResourceIdAndMd5( 875 TestGetFileFromCacheByResourceIdAndMd5(
876 resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, md5); 876 resource_id, md5, DRIVE_FILE_ERROR_NOT_FOUND, md5);
877 EXPECT_EQ(1, num_callback_invocations_); 877 EXPECT_EQ(1, num_callback_invocations_);
878 } 878 }
879 879
880 TEST_F(DriveCacheTest, RemoveFromCacheSimple) { 880 TEST_F(DriveCacheTest, RemoveFromCacheSimple) {
881 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 881 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
882 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 882 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
883 883
884 // Use alphanumeric characters for resource id. 884 // Use alphanumeric characters for resource id.
885 std::string resource_id("pdf:1a2b"); 885 std::string resource_id("pdf:1a2b");
886 std::string md5("abcdef0123456789"); 886 std::string md5("abcdef0123456789");
887 // First store a file to cache. 887 // First store a file to cache.
888 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 888 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
889 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 889 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
890 DriveCache::CACHE_TYPE_TMP); 890 DriveCache::CACHE_TYPE_TMP);
891 891
892 // Then try to remove existing file from cache. 892 // Then try to remove existing file from cache.
893 num_callback_invocations_ = 0; 893 num_callback_invocations_ = 0;
894 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 894 TestRemoveFromCache(resource_id, DRIVE_FILE_OK);
895 EXPECT_EQ(1, num_callback_invocations_); 895 EXPECT_EQ(1, num_callback_invocations_);
896 896
897 // Repeat using non-alphanumeric characters for resource id, including '.' 897 // Repeat using non-alphanumeric characters for resource id, including '.'
898 // which is an extension separator. 898 // which is an extension separator.
899 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; 899 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
900 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 900 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
901 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 901 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
902 DriveCache::CACHE_TYPE_TMP); 902 DriveCache::CACHE_TYPE_TMP);
903 903
904 num_callback_invocations_ = 0; 904 num_callback_invocations_ = 0;
905 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 905 TestRemoveFromCache(resource_id, DRIVE_FILE_OK);
906 EXPECT_EQ(1, num_callback_invocations_); 906 EXPECT_EQ(1, num_callback_invocations_);
907 } 907 }
908 908
909 TEST_F(DriveCacheTest, PinAndUnpin) { 909 TEST_F(DriveCacheTest, PinAndUnpin) {
910 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 910 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
911 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 911 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
912 912
913 std::string resource_id("pdf:1a2b"); 913 std::string resource_id("pdf:1a2b");
914 std::string md5("abcdef0123456789"); 914 std::string md5("abcdef0123456789");
915 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(2); 915 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(2);
916 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5)) 916 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5))
917 .Times(1); 917 .Times(1);
918 918
919 // First store a file to cache. 919 // First store a file to cache.
920 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 920 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
921 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 921 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
922 DriveCache::CACHE_TYPE_TMP); 922 DriveCache::CACHE_TYPE_TMP);
923 923
924 // Pin the existing file in cache. 924 // Pin the existing file in cache.
925 num_callback_invocations_ = 0; 925 num_callback_invocations_ = 0;
926 TestPin(resource_id, md5, GDATA_FILE_OK, 926 TestPin(resource_id, md5, DRIVE_FILE_OK,
927 test_util::TEST_CACHE_STATE_PRESENT | 927 test_util::TEST_CACHE_STATE_PRESENT |
928 test_util::TEST_CACHE_STATE_PINNED | 928 test_util::TEST_CACHE_STATE_PINNED |
929 test_util::TEST_CACHE_STATE_PERSISTENT, 929 test_util::TEST_CACHE_STATE_PERSISTENT,
930 DriveCache::CACHE_TYPE_PERSISTENT); 930 DriveCache::CACHE_TYPE_PERSISTENT);
931 EXPECT_EQ(1, num_callback_invocations_); 931 EXPECT_EQ(1, num_callback_invocations_);
932 932
933 // Unpin the existing file in cache. 933 // Unpin the existing file in cache.
934 num_callback_invocations_ = 0; 934 num_callback_invocations_ = 0;
935 TestUnpin(resource_id, md5, GDATA_FILE_OK, 935 TestUnpin(resource_id, md5, DRIVE_FILE_OK,
936 test_util::TEST_CACHE_STATE_PRESENT, 936 test_util::TEST_CACHE_STATE_PRESENT,
937 DriveCache::CACHE_TYPE_TMP); 937 DriveCache::CACHE_TYPE_TMP);
938 EXPECT_EQ(1, num_callback_invocations_); 938 EXPECT_EQ(1, num_callback_invocations_);
939 939
940 // Pin back the same existing file in cache. 940 // Pin back the same existing file in cache.
941 num_callback_invocations_ = 0; 941 num_callback_invocations_ = 0;
942 TestPin(resource_id, md5, GDATA_FILE_OK, 942 TestPin(resource_id, md5, DRIVE_FILE_OK,
943 test_util::TEST_CACHE_STATE_PRESENT | 943 test_util::TEST_CACHE_STATE_PRESENT |
944 test_util::TEST_CACHE_STATE_PINNED | 944 test_util::TEST_CACHE_STATE_PINNED |
945 test_util::TEST_CACHE_STATE_PERSISTENT, 945 test_util::TEST_CACHE_STATE_PERSISTENT,
946 DriveCache::CACHE_TYPE_PERSISTENT); 946 DriveCache::CACHE_TYPE_PERSISTENT);
947 EXPECT_EQ(1, num_callback_invocations_); 947 EXPECT_EQ(1, num_callback_invocations_);
948 948
949 // Pin a non-existent file in cache. 949 // Pin a non-existent file in cache.
950 resource_id = "document:1a2b"; 950 resource_id = "document:1a2b";
951 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 951 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
952 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5)) 952 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5))
953 .Times(1); 953 .Times(1);
954 954
955 num_callback_invocations_ = 0; 955 num_callback_invocations_ = 0;
956 TestPin(resource_id, md5, GDATA_FILE_OK, 956 TestPin(resource_id, md5, DRIVE_FILE_OK,
957 test_util::TEST_CACHE_STATE_PINNED, 957 test_util::TEST_CACHE_STATE_PINNED,
958 DriveCache::CACHE_TYPE_TMP); 958 DriveCache::CACHE_TYPE_TMP);
959 EXPECT_EQ(1, num_callback_invocations_); 959 EXPECT_EQ(1, num_callback_invocations_);
960 960
961 // Unpin the previously pinned non-existent file in cache. 961 // Unpin the previously pinned non-existent file in cache.
962 num_callback_invocations_ = 0; 962 num_callback_invocations_ = 0;
963 TestUnpin(resource_id, md5, GDATA_FILE_OK, 963 TestUnpin(resource_id, md5, DRIVE_FILE_OK,
964 test_util::TEST_CACHE_STATE_NONE, 964 test_util::TEST_CACHE_STATE_NONE,
965 DriveCache::CACHE_TYPE_TMP); 965 DriveCache::CACHE_TYPE_TMP);
966 EXPECT_EQ(1, num_callback_invocations_); 966 EXPECT_EQ(1, num_callback_invocations_);
967 967
968 // Unpin a file that doesn't exist in cache and is not pinned, i.e. cache 968 // Unpin a file that doesn't exist in cache and is not pinned, i.e. cache
969 // has zero knowledge of the file. 969 // has zero knowledge of the file.
970 resource_id = "not-in-cache:1a2b"; 970 resource_id = "not-in-cache:1a2b";
971 // Because unpinning will fail, OnCacheUnpinned() won't be run. 971 // Because unpinning will fail, OnCacheUnpinned() won't be run.
972 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5)) 972 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5))
973 .Times(0); 973 .Times(0);
974 974
975 num_callback_invocations_ = 0; 975 num_callback_invocations_ = 0;
976 TestUnpin(resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, 976 TestUnpin(resource_id, md5, DRIVE_FILE_ERROR_NOT_FOUND,
977 test_util::TEST_CACHE_STATE_NONE, 977 test_util::TEST_CACHE_STATE_NONE,
978 DriveCache::CACHE_TYPE_TMP /* non-applicable */); 978 DriveCache::CACHE_TYPE_TMP /* non-applicable */);
979 EXPECT_EQ(1, num_callback_invocations_); 979 EXPECT_EQ(1, num_callback_invocations_);
980 } 980 }
981 981
982 TEST_F(DriveCacheTest, StoreToCachePinned) { 982 TEST_F(DriveCacheTest, StoreToCachePinned) {
983 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 983 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
984 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 984 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
985 985
986 std::string resource_id("pdf:1a2b"); 986 std::string resource_id("pdf:1a2b");
987 std::string md5("abcdef0123456789"); 987 std::string md5("abcdef0123456789");
988 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 988 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
989 989
990 // Pin a non-existent file. 990 // Pin a non-existent file.
991 TestPin(resource_id, md5, GDATA_FILE_OK, 991 TestPin(resource_id, md5, DRIVE_FILE_OK,
992 test_util::TEST_CACHE_STATE_PINNED, 992 test_util::TEST_CACHE_STATE_PINNED,
993 DriveCache::CACHE_TYPE_TMP); 993 DriveCache::CACHE_TYPE_TMP);
994 994
995 // Store an existing file to a previously pinned file. 995 // Store an existing file to a previously pinned file.
996 num_callback_invocations_ = 0; 996 num_callback_invocations_ = 0;
997 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 997 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
998 GDATA_FILE_OK, 998 DRIVE_FILE_OK,
999 test_util::TEST_CACHE_STATE_PRESENT | 999 test_util::TEST_CACHE_STATE_PRESENT |
1000 test_util::TEST_CACHE_STATE_PINNED | 1000 test_util::TEST_CACHE_STATE_PINNED |
1001 test_util::TEST_CACHE_STATE_PERSISTENT, 1001 test_util::TEST_CACHE_STATE_PERSISTENT,
1002 DriveCache::CACHE_TYPE_PERSISTENT); 1002 DriveCache::CACHE_TYPE_PERSISTENT);
1003 EXPECT_EQ(1, num_callback_invocations_); 1003 EXPECT_EQ(1, num_callback_invocations_);
1004 1004
1005 // Store a non-existent file to a previously pinned and stored file. 1005 // Store a non-existent file to a previously pinned and stored file.
1006 num_callback_invocations_ = 0; 1006 num_callback_invocations_ = 0;
1007 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"), 1007 TestStoreToCache(resource_id, md5, FilePath("./non_existent.json"),
1008 GDATA_FILE_ERROR_FAILED, 1008 DRIVE_FILE_ERROR_FAILED,
1009 test_util::TEST_CACHE_STATE_PRESENT | 1009 test_util::TEST_CACHE_STATE_PRESENT |
1010 test_util::TEST_CACHE_STATE_PINNED | 1010 test_util::TEST_CACHE_STATE_PINNED |
1011 test_util::TEST_CACHE_STATE_PERSISTENT, 1011 test_util::TEST_CACHE_STATE_PERSISTENT,
1012 DriveCache::CACHE_TYPE_PERSISTENT); 1012 DriveCache::CACHE_TYPE_PERSISTENT);
1013 EXPECT_EQ(1, num_callback_invocations_); 1013 EXPECT_EQ(1, num_callback_invocations_);
1014 } 1014 }
1015 1015
1016 TEST_F(DriveCacheTest, GetFromCachePinned) { 1016 TEST_F(DriveCacheTest, GetFromCachePinned) {
1017 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1017 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1018 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1018 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1019 1019
1020 std::string resource_id("pdf:1a2b"); 1020 std::string resource_id("pdf:1a2b");
1021 std::string md5("abcdef0123456789"); 1021 std::string md5("abcdef0123456789");
1022 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1022 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1023 1023
1024 // Pin a non-existent file. 1024 // Pin a non-existent file.
1025 TestPin(resource_id, md5, GDATA_FILE_OK, 1025 TestPin(resource_id, md5, DRIVE_FILE_OK,
1026 test_util::TEST_CACHE_STATE_PINNED, 1026 test_util::TEST_CACHE_STATE_PINNED,
1027 DriveCache::CACHE_TYPE_TMP); 1027 DriveCache::CACHE_TYPE_TMP);
1028 1028
1029 // Get the non-existent pinned file from cache. 1029 // Get the non-existent pinned file from cache.
1030 num_callback_invocations_ = 0; 1030 num_callback_invocations_ = 0;
1031 TestGetFileFromCacheByResourceIdAndMd5( 1031 TestGetFileFromCacheByResourceIdAndMd5(
1032 resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, md5); 1032 resource_id, md5, DRIVE_FILE_ERROR_NOT_FOUND, md5);
1033 EXPECT_EQ(1, num_callback_invocations_); 1033 EXPECT_EQ(1, num_callback_invocations_);
1034 1034
1035 // Store an existing file to the previously pinned non-existent file. 1035 // Store an existing file to the previously pinned non-existent file.
1036 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1036 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1037 GDATA_FILE_OK, 1037 DRIVE_FILE_OK,
1038 test_util::TEST_CACHE_STATE_PRESENT | 1038 test_util::TEST_CACHE_STATE_PRESENT |
1039 test_util::TEST_CACHE_STATE_PINNED | 1039 test_util::TEST_CACHE_STATE_PINNED |
1040 test_util::TEST_CACHE_STATE_PERSISTENT, 1040 test_util::TEST_CACHE_STATE_PERSISTENT,
1041 DriveCache::CACHE_TYPE_PERSISTENT); 1041 DriveCache::CACHE_TYPE_PERSISTENT);
1042 1042
1043 // Get the previously pinned and stored file from cache. 1043 // Get the previously pinned and stored file from cache.
1044 num_callback_invocations_ = 0; 1044 num_callback_invocations_ = 0;
1045 TestGetFileFromCacheByResourceIdAndMd5( 1045 TestGetFileFromCacheByResourceIdAndMd5(
1046 resource_id, md5, GDATA_FILE_OK, md5); 1046 resource_id, md5, DRIVE_FILE_OK, md5);
1047 EXPECT_EQ(1, num_callback_invocations_); 1047 EXPECT_EQ(1, num_callback_invocations_);
1048 } 1048 }
1049 1049
1050 TEST_F(DriveCacheTest, RemoveFromCachePinned) { 1050 TEST_F(DriveCacheTest, RemoveFromCachePinned) {
1051 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1051 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1052 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1052 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1053 1053
1054 // Use alphanumeric characters for resource_id. 1054 // Use alphanumeric characters for resource_id.
1055 std::string resource_id("pdf:1a2b"); 1055 std::string resource_id("pdf:1a2b");
1056 std::string md5("abcdef0123456789"); 1056 std::string md5("abcdef0123456789");
1057 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1057 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1058 1058
1059 // Store a file to cache, and pin it. 1059 // Store a file to cache, and pin it.
1060 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1060 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1061 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1061 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1062 DriveCache::CACHE_TYPE_TMP); 1062 DriveCache::CACHE_TYPE_TMP);
1063 TestPin(resource_id, md5, GDATA_FILE_OK, 1063 TestPin(resource_id, md5, DRIVE_FILE_OK,
1064 test_util::TEST_CACHE_STATE_PRESENT | 1064 test_util::TEST_CACHE_STATE_PRESENT |
1065 test_util::TEST_CACHE_STATE_PINNED | 1065 test_util::TEST_CACHE_STATE_PINNED |
1066 test_util::TEST_CACHE_STATE_PERSISTENT, 1066 test_util::TEST_CACHE_STATE_PERSISTENT,
1067 DriveCache::CACHE_TYPE_PERSISTENT); 1067 DriveCache::CACHE_TYPE_PERSISTENT);
1068 1068
1069 // Remove |resource_id| from cache. 1069 // Remove |resource_id| from cache.
1070 num_callback_invocations_ = 0; 1070 num_callback_invocations_ = 0;
1071 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 1071 TestRemoveFromCache(resource_id, DRIVE_FILE_OK);
1072 EXPECT_EQ(1, num_callback_invocations_); 1072 EXPECT_EQ(1, num_callback_invocations_);
1073 1073
1074 // Repeat using non-alphanumeric characters for resource id, including '.' 1074 // Repeat using non-alphanumeric characters for resource id, including '.'
1075 // which is an extension separator. 1075 // which is an extension separator.
1076 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?"; 1076 resource_id = "pdf:`~!@#$%^&*()-_=+[{|]}\\;',<.>/?";
1077 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1077 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1078 1078
1079 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1079 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1080 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1080 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1081 DriveCache::CACHE_TYPE_TMP); 1081 DriveCache::CACHE_TYPE_TMP);
1082 TestPin(resource_id, md5, GDATA_FILE_OK, 1082 TestPin(resource_id, md5, DRIVE_FILE_OK,
1083 test_util::TEST_CACHE_STATE_PRESENT | 1083 test_util::TEST_CACHE_STATE_PRESENT |
1084 test_util::TEST_CACHE_STATE_PINNED | 1084 test_util::TEST_CACHE_STATE_PINNED |
1085 test_util::TEST_CACHE_STATE_PERSISTENT, 1085 test_util::TEST_CACHE_STATE_PERSISTENT,
1086 DriveCache::CACHE_TYPE_PERSISTENT); 1086 DriveCache::CACHE_TYPE_PERSISTENT);
1087 1087
1088 num_callback_invocations_ = 0; 1088 num_callback_invocations_ = 0;
1089 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 1089 TestRemoveFromCache(resource_id, DRIVE_FILE_OK);
1090 EXPECT_EQ(1, num_callback_invocations_); 1090 EXPECT_EQ(1, num_callback_invocations_);
1091 } 1091 }
1092 1092
1093 TEST_F(DriveCacheTest, DirtyCacheSimple) { 1093 TEST_F(DriveCacheTest, DirtyCacheSimple) {
1094 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1094 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1095 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1095 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1096 1096
1097 std::string resource_id("pdf:1a2b"); 1097 std::string resource_id("pdf:1a2b");
1098 std::string md5("abcdef0123456789"); 1098 std::string md5("abcdef0123456789");
1099 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); 1099 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
1100 1100
1101 // First store a file to cache. 1101 // First store a file to cache.
1102 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1102 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1103 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1103 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1104 DriveCache::CACHE_TYPE_TMP); 1104 DriveCache::CACHE_TYPE_TMP);
1105 1105
1106 // Mark the file dirty. 1106 // Mark the file dirty.
1107 num_callback_invocations_ = 0; 1107 num_callback_invocations_ = 0;
1108 TestMarkDirty(resource_id, md5, GDATA_FILE_OK, 1108 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK,
1109 test_util::TEST_CACHE_STATE_PRESENT | 1109 test_util::TEST_CACHE_STATE_PRESENT |
1110 test_util::TEST_CACHE_STATE_DIRTY | 1110 test_util::TEST_CACHE_STATE_DIRTY |
1111 test_util::TEST_CACHE_STATE_PERSISTENT, 1111 test_util::TEST_CACHE_STATE_PERSISTENT,
1112 DriveCache::CACHE_TYPE_PERSISTENT); 1112 DriveCache::CACHE_TYPE_PERSISTENT);
1113 EXPECT_EQ(1, num_callback_invocations_); 1113 EXPECT_EQ(1, num_callback_invocations_);
1114 1114
1115 // Commit the file dirty. 1115 // Commit the file dirty.
1116 num_callback_invocations_ = 0; 1116 num_callback_invocations_ = 0;
1117 TestCommitDirty(resource_id, md5, GDATA_FILE_OK, 1117 TestCommitDirty(resource_id, md5, DRIVE_FILE_OK,
1118 test_util::TEST_CACHE_STATE_PRESENT | 1118 test_util::TEST_CACHE_STATE_PRESENT |
1119 test_util::TEST_CACHE_STATE_DIRTY | 1119 test_util::TEST_CACHE_STATE_DIRTY |
1120 test_util::TEST_CACHE_STATE_PERSISTENT, 1120 test_util::TEST_CACHE_STATE_PERSISTENT,
1121 DriveCache::CACHE_TYPE_PERSISTENT); 1121 DriveCache::CACHE_TYPE_PERSISTENT);
1122 EXPECT_EQ(1, num_callback_invocations_); 1122 EXPECT_EQ(1, num_callback_invocations_);
1123 1123
1124 // Clear dirty state of the file. 1124 // Clear dirty state of the file.
1125 num_callback_invocations_ = 0; 1125 num_callback_invocations_ = 0;
1126 TestClearDirty(resource_id, md5, GDATA_FILE_OK, 1126 TestClearDirty(resource_id, md5, DRIVE_FILE_OK,
1127 test_util::TEST_CACHE_STATE_PRESENT, 1127 test_util::TEST_CACHE_STATE_PRESENT,
1128 DriveCache::CACHE_TYPE_TMP); 1128 DriveCache::CACHE_TYPE_TMP);
1129 EXPECT_EQ(1, num_callback_invocations_); 1129 EXPECT_EQ(1, num_callback_invocations_);
1130 } 1130 }
1131 1131
1132 TEST_F(DriveCacheTest, DirtyCachePinned) { 1132 TEST_F(DriveCacheTest, DirtyCachePinned) {
1133 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1133 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1134 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1134 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1135 1135
1136 std::string resource_id("pdf:1a2b"); 1136 std::string resource_id("pdf:1a2b");
1137 std::string md5("abcdef0123456789"); 1137 std::string md5("abcdef0123456789");
1138 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1138 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1139 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); 1139 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
1140 1140
1141 // First store a file to cache and pin it. 1141 // First store a file to cache and pin it.
1142 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1142 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1143 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1143 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1144 DriveCache::CACHE_TYPE_TMP); 1144 DriveCache::CACHE_TYPE_TMP);
1145 TestPin(resource_id, md5, GDATA_FILE_OK, 1145 TestPin(resource_id, md5, DRIVE_FILE_OK,
1146 test_util::TEST_CACHE_STATE_PRESENT | 1146 test_util::TEST_CACHE_STATE_PRESENT |
1147 test_util::TEST_CACHE_STATE_PINNED | 1147 test_util::TEST_CACHE_STATE_PINNED |
1148 test_util::TEST_CACHE_STATE_PERSISTENT, 1148 test_util::TEST_CACHE_STATE_PERSISTENT,
1149 DriveCache::CACHE_TYPE_PERSISTENT); 1149 DriveCache::CACHE_TYPE_PERSISTENT);
1150 1150
1151 // Mark the file dirty. 1151 // Mark the file dirty.
1152 num_callback_invocations_ = 0; 1152 num_callback_invocations_ = 0;
1153 TestMarkDirty(resource_id, md5, GDATA_FILE_OK, 1153 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK,
1154 test_util::TEST_CACHE_STATE_PRESENT | 1154 test_util::TEST_CACHE_STATE_PRESENT |
1155 test_util::TEST_CACHE_STATE_DIRTY | 1155 test_util::TEST_CACHE_STATE_DIRTY |
1156 test_util::TEST_CACHE_STATE_PINNED | 1156 test_util::TEST_CACHE_STATE_PINNED |
1157 test_util::TEST_CACHE_STATE_PERSISTENT, 1157 test_util::TEST_CACHE_STATE_PERSISTENT,
1158 DriveCache::CACHE_TYPE_PERSISTENT); 1158 DriveCache::CACHE_TYPE_PERSISTENT);
1159 EXPECT_EQ(1, num_callback_invocations_); 1159 EXPECT_EQ(1, num_callback_invocations_);
1160 1160
1161 // Commit the file dirty. 1161 // Commit the file dirty.
1162 num_callback_invocations_ = 0; 1162 num_callback_invocations_ = 0;
1163 TestCommitDirty(resource_id, md5, GDATA_FILE_OK, 1163 TestCommitDirty(resource_id, md5, DRIVE_FILE_OK,
1164 test_util::TEST_CACHE_STATE_PRESENT | 1164 test_util::TEST_CACHE_STATE_PRESENT |
1165 test_util::TEST_CACHE_STATE_DIRTY | 1165 test_util::TEST_CACHE_STATE_DIRTY |
1166 test_util::TEST_CACHE_STATE_PINNED | 1166 test_util::TEST_CACHE_STATE_PINNED |
1167 test_util::TEST_CACHE_STATE_PERSISTENT, 1167 test_util::TEST_CACHE_STATE_PERSISTENT,
1168 DriveCache::CACHE_TYPE_PERSISTENT); 1168 DriveCache::CACHE_TYPE_PERSISTENT);
1169 EXPECT_EQ(1, num_callback_invocations_); 1169 EXPECT_EQ(1, num_callback_invocations_);
1170 1170
1171 // Clear dirty state of the file. 1171 // Clear dirty state of the file.
1172 num_callback_invocations_ = 0; 1172 num_callback_invocations_ = 0;
1173 TestClearDirty(resource_id, md5, GDATA_FILE_OK, 1173 TestClearDirty(resource_id, md5, DRIVE_FILE_OK,
1174 test_util::TEST_CACHE_STATE_PRESENT | 1174 test_util::TEST_CACHE_STATE_PRESENT |
1175 test_util::TEST_CACHE_STATE_PINNED | 1175 test_util::TEST_CACHE_STATE_PINNED |
1176 test_util::TEST_CACHE_STATE_PERSISTENT, 1176 test_util::TEST_CACHE_STATE_PERSISTENT,
1177 DriveCache::CACHE_TYPE_PERSISTENT); 1177 DriveCache::CACHE_TYPE_PERSISTENT);
1178 EXPECT_EQ(1, num_callback_invocations_); 1178 EXPECT_EQ(1, num_callback_invocations_);
1179 } 1179 }
1180 1180
1181 // Test is disabled because it is flaky (http://crbug.com/134146) 1181 // Test is disabled because it is flaky (http://crbug.com/134146)
1182 TEST_F(DriveCacheTest, PinAndUnpinDirtyCache) { 1182 TEST_F(DriveCacheTest, PinAndUnpinDirtyCache) {
1183 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1183 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1184 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1184 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1185 1185
1186 std::string resource_id("pdf:1a2b"); 1186 std::string resource_id("pdf:1a2b");
1187 std::string md5("abcdef0123456789"); 1187 std::string md5("abcdef0123456789");
1188 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1188 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1189 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5)) 1189 EXPECT_CALL(*mock_cache_observer_, OnCacheUnpinned(resource_id, md5))
1190 .Times(1); 1190 .Times(1);
1191 1191
1192 // First store a file to cache and mark it as dirty. 1192 // First store a file to cache and mark it as dirty.
1193 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1193 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1194 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1194 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1195 DriveCache::CACHE_TYPE_TMP); 1195 DriveCache::CACHE_TYPE_TMP);
1196 TestMarkDirty(resource_id, md5, GDATA_FILE_OK, 1196 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK,
1197 test_util::TEST_CACHE_STATE_PRESENT | 1197 test_util::TEST_CACHE_STATE_PRESENT |
1198 test_util::TEST_CACHE_STATE_DIRTY | 1198 test_util::TEST_CACHE_STATE_DIRTY |
1199 test_util::TEST_CACHE_STATE_PERSISTENT, 1199 test_util::TEST_CACHE_STATE_PERSISTENT,
1200 DriveCache::CACHE_TYPE_PERSISTENT); 1200 DriveCache::CACHE_TYPE_PERSISTENT);
1201 1201
1202 // Verifies dirty file exists. 1202 // Verifies dirty file exists.
1203 FilePath dirty_path = GetCacheFilePath( 1203 FilePath dirty_path = GetCacheFilePath(
1204 resource_id, 1204 resource_id,
1205 md5, 1205 md5,
1206 DriveCache::CACHE_TYPE_PERSISTENT, 1206 DriveCache::CACHE_TYPE_PERSISTENT,
1207 DriveCache::CACHED_FILE_LOCALLY_MODIFIED); 1207 DriveCache::CACHED_FILE_LOCALLY_MODIFIED);
1208 EXPECT_TRUE(file_util::PathExists(dirty_path)); 1208 EXPECT_TRUE(file_util::PathExists(dirty_path));
1209 1209
1210 // Pin the dirty file. 1210 // Pin the dirty file.
1211 TestPin(resource_id, md5, GDATA_FILE_OK, 1211 TestPin(resource_id, md5, DRIVE_FILE_OK,
1212 test_util::TEST_CACHE_STATE_PRESENT | 1212 test_util::TEST_CACHE_STATE_PRESENT |
1213 test_util::TEST_CACHE_STATE_DIRTY | 1213 test_util::TEST_CACHE_STATE_DIRTY |
1214 test_util::TEST_CACHE_STATE_PINNED | 1214 test_util::TEST_CACHE_STATE_PINNED |
1215 test_util::TEST_CACHE_STATE_PERSISTENT, 1215 test_util::TEST_CACHE_STATE_PERSISTENT,
1216 DriveCache::CACHE_TYPE_PERSISTENT); 1216 DriveCache::CACHE_TYPE_PERSISTENT);
1217 1217
1218 // Verify dirty file still exist at the same pathname. 1218 // Verify dirty file still exist at the same pathname.
1219 EXPECT_TRUE(file_util::PathExists(dirty_path)); 1219 EXPECT_TRUE(file_util::PathExists(dirty_path));
1220 1220
1221 // Unpin the dirty file. 1221 // Unpin the dirty file.
1222 TestUnpin(resource_id, md5, GDATA_FILE_OK, 1222 TestUnpin(resource_id, md5, DRIVE_FILE_OK,
1223 test_util::TEST_CACHE_STATE_PRESENT | 1223 test_util::TEST_CACHE_STATE_PRESENT |
1224 test_util::TEST_CACHE_STATE_DIRTY | 1224 test_util::TEST_CACHE_STATE_DIRTY |
1225 test_util::TEST_CACHE_STATE_PERSISTENT, 1225 test_util::TEST_CACHE_STATE_PERSISTENT,
1226 DriveCache::CACHE_TYPE_PERSISTENT); 1226 DriveCache::CACHE_TYPE_PERSISTENT);
1227 1227
1228 // Verify dirty file still exist at the same pathname. 1228 // Verify dirty file still exist at the same pathname.
1229 EXPECT_TRUE(file_util::PathExists(dirty_path)); 1229 EXPECT_TRUE(file_util::PathExists(dirty_path));
1230 } 1230 }
1231 1231
1232 TEST_F(DriveCacheTest, DirtyCacheRepetitive) { 1232 TEST_F(DriveCacheTest, DirtyCacheRepetitive) {
1233 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1233 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1234 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1234 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1235 1235
1236 std::string resource_id("pdf:1a2b"); 1236 std::string resource_id("pdf:1a2b");
1237 std::string md5("abcdef0123456789"); 1237 std::string md5("abcdef0123456789");
1238 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(3); 1238 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(3);
1239 1239
1240 // First store a file to cache. 1240 // First store a file to cache.
1241 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1241 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1242 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1242 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1243 DriveCache::CACHE_TYPE_TMP); 1243 DriveCache::CACHE_TYPE_TMP);
1244 1244
1245 // Mark the file dirty. 1245 // Mark the file dirty.
1246 num_callback_invocations_ = 0; 1246 num_callback_invocations_ = 0;
1247 TestMarkDirty(resource_id, md5, GDATA_FILE_OK, 1247 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK,
1248 test_util::TEST_CACHE_STATE_PRESENT | 1248 test_util::TEST_CACHE_STATE_PRESENT |
1249 test_util::TEST_CACHE_STATE_DIRTY | 1249 test_util::TEST_CACHE_STATE_DIRTY |
1250 test_util::TEST_CACHE_STATE_PERSISTENT, 1250 test_util::TEST_CACHE_STATE_PERSISTENT,
1251 DriveCache::CACHE_TYPE_PERSISTENT); 1251 DriveCache::CACHE_TYPE_PERSISTENT);
1252 EXPECT_EQ(1, num_callback_invocations_); 1252 EXPECT_EQ(1, num_callback_invocations_);
1253 1253
1254 // Again, mark the file dirty. Nothing should change. 1254 // Again, mark the file dirty. Nothing should change.
1255 num_callback_invocations_ = 0; 1255 num_callback_invocations_ = 0;
1256 TestMarkDirty(resource_id, md5, GDATA_FILE_OK, 1256 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK,
1257 test_util::TEST_CACHE_STATE_PRESENT | 1257 test_util::TEST_CACHE_STATE_PRESENT |
1258 test_util::TEST_CACHE_STATE_DIRTY | 1258 test_util::TEST_CACHE_STATE_DIRTY |
1259 test_util::TEST_CACHE_STATE_PERSISTENT, 1259 test_util::TEST_CACHE_STATE_PERSISTENT,
1260 DriveCache::CACHE_TYPE_PERSISTENT); 1260 DriveCache::CACHE_TYPE_PERSISTENT);
1261 EXPECT_EQ(1, num_callback_invocations_); 1261 EXPECT_EQ(1, num_callback_invocations_);
1262 1262
1263 // Commit the file dirty. Outgoing symlink should be created. 1263 // Commit the file dirty. Outgoing symlink should be created.
1264 num_callback_invocations_ = 0; 1264 num_callback_invocations_ = 0;
1265 TestCommitDirty(resource_id, md5, GDATA_FILE_OK, 1265 TestCommitDirty(resource_id, md5, DRIVE_FILE_OK,
1266 test_util::TEST_CACHE_STATE_PRESENT | 1266 test_util::TEST_CACHE_STATE_PRESENT |
1267 test_util::TEST_CACHE_STATE_DIRTY | 1267 test_util::TEST_CACHE_STATE_DIRTY |
1268 test_util::TEST_CACHE_STATE_PERSISTENT, 1268 test_util::TEST_CACHE_STATE_PERSISTENT,
1269 DriveCache::CACHE_TYPE_PERSISTENT); 1269 DriveCache::CACHE_TYPE_PERSISTENT);
1270 EXPECT_EQ(1, num_callback_invocations_); 1270 EXPECT_EQ(1, num_callback_invocations_);
1271 1271
1272 // Again, commit the file dirty. Nothing should change. 1272 // Again, commit the file dirty. Nothing should change.
1273 num_callback_invocations_ = 0; 1273 num_callback_invocations_ = 0;
1274 TestCommitDirty(resource_id, md5, GDATA_FILE_OK, 1274 TestCommitDirty(resource_id, md5, DRIVE_FILE_OK,
1275 test_util::TEST_CACHE_STATE_PRESENT | 1275 test_util::TEST_CACHE_STATE_PRESENT |
1276 test_util::TEST_CACHE_STATE_DIRTY | 1276 test_util::TEST_CACHE_STATE_DIRTY |
1277 test_util::TEST_CACHE_STATE_PERSISTENT, 1277 test_util::TEST_CACHE_STATE_PERSISTENT,
1278 DriveCache::CACHE_TYPE_PERSISTENT); 1278 DriveCache::CACHE_TYPE_PERSISTENT);
1279 EXPECT_EQ(1, num_callback_invocations_); 1279 EXPECT_EQ(1, num_callback_invocations_);
1280 1280
1281 // Mark the file dirty agian after it's being committed. Outgoing symlink 1281 // Mark the file dirty agian after it's being committed. Outgoing symlink
1282 // should be deleted. 1282 // should be deleted.
1283 num_callback_invocations_ = 0; 1283 num_callback_invocations_ = 0;
1284 TestMarkDirty(resource_id, md5, GDATA_FILE_OK, 1284 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK,
1285 test_util::TEST_CACHE_STATE_PRESENT | 1285 test_util::TEST_CACHE_STATE_PRESENT |
1286 test_util::TEST_CACHE_STATE_DIRTY | 1286 test_util::TEST_CACHE_STATE_DIRTY |
1287 test_util::TEST_CACHE_STATE_PERSISTENT, 1287 test_util::TEST_CACHE_STATE_PERSISTENT,
1288 DriveCache::CACHE_TYPE_PERSISTENT); 1288 DriveCache::CACHE_TYPE_PERSISTENT);
1289 EXPECT_EQ(1, num_callback_invocations_); 1289 EXPECT_EQ(1, num_callback_invocations_);
1290 1290
1291 // Commit the file dirty. Outgoing symlink should be created again. 1291 // Commit the file dirty. Outgoing symlink should be created again.
1292 num_callback_invocations_ = 0; 1292 num_callback_invocations_ = 0;
1293 TestCommitDirty(resource_id, md5, GDATA_FILE_OK, 1293 TestCommitDirty(resource_id, md5, DRIVE_FILE_OK,
1294 test_util::TEST_CACHE_STATE_PRESENT | 1294 test_util::TEST_CACHE_STATE_PRESENT |
1295 test_util::TEST_CACHE_STATE_DIRTY | 1295 test_util::TEST_CACHE_STATE_DIRTY |
1296 test_util::TEST_CACHE_STATE_PERSISTENT, 1296 test_util::TEST_CACHE_STATE_PERSISTENT,
1297 DriveCache::CACHE_TYPE_PERSISTENT); 1297 DriveCache::CACHE_TYPE_PERSISTENT);
1298 EXPECT_EQ(1, num_callback_invocations_); 1298 EXPECT_EQ(1, num_callback_invocations_);
1299 1299
1300 // Clear dirty state of the file. 1300 // Clear dirty state of the file.
1301 num_callback_invocations_ = 0; 1301 num_callback_invocations_ = 0;
1302 TestClearDirty(resource_id, md5, GDATA_FILE_OK, 1302 TestClearDirty(resource_id, md5, DRIVE_FILE_OK,
1303 test_util::TEST_CACHE_STATE_PRESENT, 1303 test_util::TEST_CACHE_STATE_PRESENT,
1304 DriveCache::CACHE_TYPE_TMP); 1304 DriveCache::CACHE_TYPE_TMP);
1305 EXPECT_EQ(1, num_callback_invocations_); 1305 EXPECT_EQ(1, num_callback_invocations_);
1306 1306
1307 // Again, clear dirty state of the file, which is no longer dirty. 1307 // Again, clear dirty state of the file, which is no longer dirty.
1308 num_callback_invocations_ = 0; 1308 num_callback_invocations_ = 0;
1309 TestClearDirty(resource_id, md5, GDATA_FILE_ERROR_INVALID_OPERATION, 1309 TestClearDirty(resource_id, md5, DRIVE_FILE_ERROR_INVALID_OPERATION,
1310 test_util::TEST_CACHE_STATE_PRESENT, 1310 test_util::TEST_CACHE_STATE_PRESENT,
1311 DriveCache::CACHE_TYPE_TMP); 1311 DriveCache::CACHE_TYPE_TMP);
1312 EXPECT_EQ(1, num_callback_invocations_); 1312 EXPECT_EQ(1, num_callback_invocations_);
1313 } 1313 }
1314 1314
1315 TEST_F(DriveCacheTest, DirtyCacheInvalid) { 1315 TEST_F(DriveCacheTest, DirtyCacheInvalid) {
1316 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1316 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1317 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1317 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1318 1318
1319 std::string resource_id("pdf:1a2b"); 1319 std::string resource_id("pdf:1a2b");
1320 std::string md5("abcdef0123456789"); 1320 std::string md5("abcdef0123456789");
1321 1321
1322 // Mark a non-existent file dirty. 1322 // Mark a non-existent file dirty.
1323 num_callback_invocations_ = 0; 1323 num_callback_invocations_ = 0;
1324 TestMarkDirty(resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, 1324 TestMarkDirty(resource_id, md5, DRIVE_FILE_ERROR_NOT_FOUND,
1325 test_util::TEST_CACHE_STATE_NONE, 1325 test_util::TEST_CACHE_STATE_NONE,
1326 DriveCache::CACHE_TYPE_TMP); 1326 DriveCache::CACHE_TYPE_TMP);
1327 EXPECT_EQ(1, num_callback_invocations_); 1327 EXPECT_EQ(1, num_callback_invocations_);
1328 1328
1329 // Commit a non-existent file dirty. 1329 // Commit a non-existent file dirty.
1330 num_callback_invocations_ = 0; 1330 num_callback_invocations_ = 0;
1331 TestCommitDirty(resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, 1331 TestCommitDirty(resource_id, md5, DRIVE_FILE_ERROR_NOT_FOUND,
1332 test_util::TEST_CACHE_STATE_NONE, 1332 test_util::TEST_CACHE_STATE_NONE,
1333 DriveCache::CACHE_TYPE_TMP); 1333 DriveCache::CACHE_TYPE_TMP);
1334 EXPECT_EQ(1, num_callback_invocations_); 1334 EXPECT_EQ(1, num_callback_invocations_);
1335 1335
1336 // Clear dirty state of a non-existent file. 1336 // Clear dirty state of a non-existent file.
1337 num_callback_invocations_ = 0; 1337 num_callback_invocations_ = 0;
1338 TestClearDirty(resource_id, md5, GDATA_FILE_ERROR_NOT_FOUND, 1338 TestClearDirty(resource_id, md5, DRIVE_FILE_ERROR_NOT_FOUND,
1339 test_util::TEST_CACHE_STATE_NONE, 1339 test_util::TEST_CACHE_STATE_NONE,
1340 DriveCache::CACHE_TYPE_TMP); 1340 DriveCache::CACHE_TYPE_TMP);
1341 EXPECT_EQ(1, num_callback_invocations_); 1341 EXPECT_EQ(1, num_callback_invocations_);
1342 1342
1343 // Store a file to cache. 1343 // Store a file to cache.
1344 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1344 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1345 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1345 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1346 DriveCache::CACHE_TYPE_TMP); 1346 DriveCache::CACHE_TYPE_TMP);
1347 1347
1348 // Commit a non-dirty existing file dirty. 1348 // Commit a non-dirty existing file dirty.
1349 num_callback_invocations_ = 0; 1349 num_callback_invocations_ = 0;
1350 TestCommitDirty(resource_id, md5, GDATA_FILE_ERROR_INVALID_OPERATION, 1350 TestCommitDirty(resource_id, md5, DRIVE_FILE_ERROR_INVALID_OPERATION,
1351 test_util::TEST_CACHE_STATE_PRESENT, 1351 test_util::TEST_CACHE_STATE_PRESENT,
1352 DriveCache::CACHE_TYPE_TMP); 1352 DriveCache::CACHE_TYPE_TMP);
1353 EXPECT_EQ(1, num_callback_invocations_); 1353 EXPECT_EQ(1, num_callback_invocations_);
1354 1354
1355 // Clear dirty state of a non-dirty existing file. 1355 // Clear dirty state of a non-dirty existing file.
1356 num_callback_invocations_ = 0; 1356 num_callback_invocations_ = 0;
1357 TestClearDirty(resource_id, md5, GDATA_FILE_ERROR_INVALID_OPERATION, 1357 TestClearDirty(resource_id, md5, DRIVE_FILE_ERROR_INVALID_OPERATION,
1358 test_util::TEST_CACHE_STATE_PRESENT, 1358 test_util::TEST_CACHE_STATE_PRESENT,
1359 DriveCache::CACHE_TYPE_TMP); 1359 DriveCache::CACHE_TYPE_TMP);
1360 EXPECT_EQ(1, num_callback_invocations_); 1360 EXPECT_EQ(1, num_callback_invocations_);
1361 1361
1362 // Mark an existing file dirty, then store a new file to the same resource id 1362 // Mark an existing file dirty, then store a new file to the same resource id
1363 // but different md5, which should fail. 1363 // but different md5, which should fail.
1364 TestMarkDirty(resource_id, md5, GDATA_FILE_OK, 1364 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK,
1365 test_util::TEST_CACHE_STATE_PRESENT | 1365 test_util::TEST_CACHE_STATE_PRESENT |
1366 test_util::TEST_CACHE_STATE_DIRTY | 1366 test_util::TEST_CACHE_STATE_DIRTY |
1367 test_util::TEST_CACHE_STATE_PERSISTENT, 1367 test_util::TEST_CACHE_STATE_PERSISTENT,
1368 DriveCache::CACHE_TYPE_PERSISTENT); 1368 DriveCache::CACHE_TYPE_PERSISTENT);
1369 num_callback_invocations_ = 0; 1369 num_callback_invocations_ = 0;
1370 md5 = "new_md5"; 1370 md5 = "new_md5";
1371 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"), 1371 TestStoreToCache(resource_id, md5, GetTestFilePath("subdir_feed.json"),
1372 GDATA_FILE_ERROR_IN_USE, 1372 DRIVE_FILE_ERROR_IN_USE,
1373 test_util::TEST_CACHE_STATE_PRESENT | 1373 test_util::TEST_CACHE_STATE_PRESENT |
1374 test_util::TEST_CACHE_STATE_DIRTY | 1374 test_util::TEST_CACHE_STATE_DIRTY |
1375 test_util::TEST_CACHE_STATE_PERSISTENT, 1375 test_util::TEST_CACHE_STATE_PERSISTENT,
1376 DriveCache::CACHE_TYPE_PERSISTENT); 1376 DriveCache::CACHE_TYPE_PERSISTENT);
1377 EXPECT_EQ(1, num_callback_invocations_); 1377 EXPECT_EQ(1, num_callback_invocations_);
1378 } 1378 }
1379 1379
1380 TEST_F(DriveCacheTest, RemoveFromDirtyCache) { 1380 TEST_F(DriveCacheTest, RemoveFromDirtyCache) {
1381 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1381 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1382 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1382 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1383 1383
1384 std::string resource_id("pdf:1a2b"); 1384 std::string resource_id("pdf:1a2b");
1385 std::string md5("abcdef0123456789"); 1385 std::string md5("abcdef0123456789");
1386 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1); 1386 EXPECT_CALL(*mock_cache_observer_, OnCachePinned(resource_id, md5)).Times(1);
1387 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1); 1387 EXPECT_CALL(*mock_cache_observer_, OnCacheCommitted(resource_id)).Times(1);
1388 1388
1389 // Store a file to cache, pin it, mark it dirty and commit it. 1389 // Store a file to cache, pin it, mark it dirty and commit it.
1390 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1390 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1391 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1391 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1392 DriveCache::CACHE_TYPE_TMP); 1392 DriveCache::CACHE_TYPE_TMP);
1393 TestPin(resource_id, md5, GDATA_FILE_OK, 1393 TestPin(resource_id, md5, DRIVE_FILE_OK,
1394 test_util::TEST_CACHE_STATE_PRESENT | 1394 test_util::TEST_CACHE_STATE_PRESENT |
1395 test_util::TEST_CACHE_STATE_PINNED | 1395 test_util::TEST_CACHE_STATE_PINNED |
1396 test_util::TEST_CACHE_STATE_PERSISTENT, 1396 test_util::TEST_CACHE_STATE_PERSISTENT,
1397 DriveCache::CACHE_TYPE_PERSISTENT); 1397 DriveCache::CACHE_TYPE_PERSISTENT);
1398 TestMarkDirty(resource_id, md5, GDATA_FILE_OK, 1398 TestMarkDirty(resource_id, md5, DRIVE_FILE_OK,
1399 test_util::TEST_CACHE_STATE_PRESENT | 1399 test_util::TEST_CACHE_STATE_PRESENT |
1400 test_util::TEST_CACHE_STATE_PINNED | 1400 test_util::TEST_CACHE_STATE_PINNED |
1401 test_util::TEST_CACHE_STATE_DIRTY | 1401 test_util::TEST_CACHE_STATE_DIRTY |
1402 test_util::TEST_CACHE_STATE_PERSISTENT, 1402 test_util::TEST_CACHE_STATE_PERSISTENT,
1403 DriveCache::CACHE_TYPE_PERSISTENT); 1403 DriveCache::CACHE_TYPE_PERSISTENT);
1404 TestCommitDirty(resource_id, md5, GDATA_FILE_OK, 1404 TestCommitDirty(resource_id, md5, DRIVE_FILE_OK,
1405 test_util::TEST_CACHE_STATE_PRESENT | 1405 test_util::TEST_CACHE_STATE_PRESENT |
1406 test_util::TEST_CACHE_STATE_PINNED | 1406 test_util::TEST_CACHE_STATE_PINNED |
1407 test_util::TEST_CACHE_STATE_DIRTY | 1407 test_util::TEST_CACHE_STATE_DIRTY |
1408 test_util::TEST_CACHE_STATE_PERSISTENT, 1408 test_util::TEST_CACHE_STATE_PERSISTENT,
1409 DriveCache::CACHE_TYPE_PERSISTENT); 1409 DriveCache::CACHE_TYPE_PERSISTENT);
1410 1410
1411 // Try to remove the file. Since file is dirty, it and the corresponding 1411 // Try to remove the file. Since file is dirty, it and the corresponding
1412 // pinned and outgoing symlinks should not be removed. 1412 // pinned and outgoing symlinks should not be removed.
1413 num_callback_invocations_ = 0; 1413 num_callback_invocations_ = 0;
1414 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 1414 TestRemoveFromCache(resource_id, DRIVE_FILE_OK);
1415 EXPECT_EQ(1, num_callback_invocations_); 1415 EXPECT_EQ(1, num_callback_invocations_);
1416 } 1416 }
1417 1417
1418 TEST_F(DriveCacheTest, MountUnmount) { 1418 TEST_F(DriveCacheTest, MountUnmount) {
1419 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1419 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1420 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1420 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1421 1421
1422 FilePath file_path; 1422 FilePath file_path;
1423 std::string resource_id("pdf:1a2b"); 1423 std::string resource_id("pdf:1a2b");
1424 std::string md5("abcdef0123456789"); 1424 std::string md5("abcdef0123456789");
1425 1425
1426 // First store a file to cache in the tmp subdir. 1426 // First store a file to cache in the tmp subdir.
1427 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1427 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1428 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1428 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1429 DriveCache::CACHE_TYPE_TMP); 1429 DriveCache::CACHE_TYPE_TMP);
1430 1430
1431 // Mark the file mounted. 1431 // Mark the file mounted.
1432 num_callback_invocations_ = 0; 1432 num_callback_invocations_ = 0;
1433 file_path = cache_->GetCacheFilePath(resource_id, md5, 1433 file_path = cache_->GetCacheFilePath(resource_id, md5,
1434 DriveCache::CACHE_TYPE_TMP, 1434 DriveCache::CACHE_TYPE_TMP,
1435 DriveCache::CACHED_FILE_FROM_SERVER); 1435 DriveCache::CACHED_FILE_FROM_SERVER);
1436 TestSetMountedState(resource_id, md5, file_path, true, 1436 TestSetMountedState(resource_id, md5, file_path, true,
1437 GDATA_FILE_OK, 1437 DRIVE_FILE_OK,
1438 test_util::TEST_CACHE_STATE_PRESENT | 1438 test_util::TEST_CACHE_STATE_PRESENT |
1439 test_util::TEST_CACHE_STATE_MOUNTED | 1439 test_util::TEST_CACHE_STATE_MOUNTED |
1440 test_util::TEST_CACHE_STATE_PERSISTENT, 1440 test_util::TEST_CACHE_STATE_PERSISTENT,
1441 DriveCache::CACHE_TYPE_PERSISTENT); 1441 DriveCache::CACHE_TYPE_PERSISTENT);
1442 EXPECT_EQ(1, num_callback_invocations_); 1442 EXPECT_EQ(1, num_callback_invocations_);
1443 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 1443 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1444 1444
1445 // Clear mounted state of the file. 1445 // Clear mounted state of the file.
1446 num_callback_invocations_ = 0; 1446 num_callback_invocations_ = 0;
1447 file_path = cache_->GetCacheFilePath(resource_id, 1447 file_path = cache_->GetCacheFilePath(resource_id,
1448 md5, 1448 md5,
1449 DriveCache::CACHE_TYPE_PERSISTENT, 1449 DriveCache::CACHE_TYPE_PERSISTENT,
1450 DriveCache::CACHED_FILE_MOUNTED); 1450 DriveCache::CACHED_FILE_MOUNTED);
1451 TestSetMountedState(resource_id, md5, file_path, false, 1451 TestSetMountedState(resource_id, md5, file_path, false,
1452 GDATA_FILE_OK, 1452 DRIVE_FILE_OK,
1453 test_util::TEST_CACHE_STATE_PRESENT, 1453 test_util::TEST_CACHE_STATE_PRESENT,
1454 DriveCache::CACHE_TYPE_TMP); 1454 DriveCache::CACHE_TYPE_TMP);
1455 EXPECT_EQ(1, num_callback_invocations_); 1455 EXPECT_EQ(1, num_callback_invocations_);
1456 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); 1456 EXPECT_TRUE(CacheEntryExists(resource_id, md5));
1457 1457
1458 // Try to remove the file. 1458 // Try to remove the file.
1459 num_callback_invocations_ = 0; 1459 num_callback_invocations_ = 0;
1460 TestRemoveFromCache(resource_id, GDATA_FILE_OK); 1460 TestRemoveFromCache(resource_id, DRIVE_FILE_OK);
1461 EXPECT_EQ(1, num_callback_invocations_); 1461 EXPECT_EQ(1, num_callback_invocations_);
1462 } 1462 }
1463 1463
1464 TEST_F(DriveCacheTest, GetResourceIdsOfBacklogOnUIThread) { 1464 TEST_F(DriveCacheTest, GetResourceIdsOfBacklogOnUIThread) {
1465 PrepareForInitCacheTest(); 1465 PrepareForInitCacheTest();
1466 1466
1467 std::vector<std::string> to_fetch; 1467 std::vector<std::string> to_fetch;
1468 std::vector<std::string> to_upload; 1468 std::vector<std::string> to_upload;
1469 cache_->GetResourceIdsOfBacklogOnUIThread( 1469 cache_->GetResourceIdsOfBacklogOnUIThread(
1470 base::Bind(&OnGetResourceIdsOfBacklog, &to_fetch, &to_upload)); 1470 base::Bind(&OnGetResourceIdsOfBacklog, &to_fetch, &to_upload));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 PrepareForInitCacheTest(); 1517 PrepareForInitCacheTest();
1518 1518
1519 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1519 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1520 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); 1520 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
1521 1521
1522 std::string resource_id("pdf:1a2b"); 1522 std::string resource_id("pdf:1a2b");
1523 std::string md5("abcdef0123456789"); 1523 std::string md5("abcdef0123456789");
1524 1524
1525 // Store an existing file. 1525 // Store an existing file.
1526 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1526 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1527 GDATA_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT, 1527 DRIVE_FILE_OK, test_util::TEST_CACHE_STATE_PRESENT,
1528 DriveCache::CACHE_TYPE_TMP); 1528 DriveCache::CACHE_TYPE_TMP);
1529 EXPECT_EQ(1, num_callback_invocations_); 1529 EXPECT_EQ(1, num_callback_invocations_);
1530 1530
1531 // Verify that there's only one cached file. 1531 // Verify that there's only one cached file.
1532 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5)); 1532 EXPECT_EQ(1U, CountCacheFiles(resource_id, md5));
1533 1533
1534 // Clear cache. 1534 // Clear cache.
1535 GDataFileError error = GDATA_FILE_OK; 1535 DriveFileError error = DRIVE_FILE_OK;
1536 FilePath file_path; 1536 FilePath file_path;
1537 cache_->ClearAllOnUIThread(base::Bind(&OnClearAll, 1537 cache_->ClearAllOnUIThread(base::Bind(&OnClearAll,
1538 &error, 1538 &error,
1539 &file_path)); 1539 &file_path));
1540 test_util::RunBlockingPoolTask(); 1540 test_util::RunBlockingPoolTask();
1541 EXPECT_EQ(GDATA_FILE_OK, error); 1541 EXPECT_EQ(DRIVE_FILE_OK, error);
1542 1542
1543 // Verify that all the cache is removed. 1543 // Verify that all the cache is removed.
1544 VerifyRemoveFromCache(error, resource_id, md5); 1544 VerifyRemoveFromCache(error, resource_id, md5);
1545 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); 1545 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
1546 } 1546 }
1547 1547
1548 TEST_F(DriveCacheTest, StoreToCacheNoSpace) { 1548 TEST_F(DriveCacheTest, StoreToCacheNoSpace) {
1549 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) 1549 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
1550 .Times(AtLeast(1)).WillRepeatedly(Return(0)); 1550 .Times(AtLeast(1)).WillRepeatedly(Return(0));
1551 1551
1552 std::string resource_id("pdf:1a2b"); 1552 std::string resource_id("pdf:1a2b");
1553 std::string md5("abcdef0123456789"); 1553 std::string md5("abcdef0123456789");
1554 1554
1555 // Try to store an existing file. 1555 // Try to store an existing file.
1556 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"), 1556 TestStoreToCache(resource_id, md5, GetTestFilePath("root_feed.json"),
1557 GDATA_FILE_ERROR_NO_SPACE, 1557 DRIVE_FILE_ERROR_NO_SPACE,
1558 test_util::TEST_CACHE_STATE_NONE, 1558 test_util::TEST_CACHE_STATE_NONE,
1559 DriveCache::CACHE_TYPE_TMP); 1559 DriveCache::CACHE_TYPE_TMP);
1560 EXPECT_EQ(1, num_callback_invocations_); 1560 EXPECT_EQ(1, num_callback_invocations_);
1561 1561
1562 // Verify that there's no files added. 1562 // Verify that there's no files added.
1563 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5)); 1563 EXPECT_EQ(0U, CountCacheFiles(resource_id, md5));
1564 } 1564 }
1565 1565
1566 1566
1567 } // namespace gdata 1567 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/drive_cache.cc ('k') | chrome/browser/chromeos/gdata/drive_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698