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

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

Issue 15768004: drive: Rename drive::DriveFileSystemTest to drive::FileSystemTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 const int64 kLotsOfSpace = internal::kMinFreeSpace * 10; 45 const int64 kLotsOfSpace = internal::kMinFreeSpace * 10;
46 46
47 struct SearchResultPair { 47 struct SearchResultPair {
48 const char* path; 48 const char* path;
49 const bool is_directory; 49 const bool is_directory;
50 }; 50 };
51 51
52 // Callback to FileSystem::Search used in ContentSearch tests. 52 // Callback to FileSystem::Search used in ContentSearch tests.
53 // Verifies returned vector of results and next feed url. 53 // Verifies returned vector of results and next feed url.
54 void DriveSearchCallback( 54 void VerifySearchResult(
55 MessageLoop* message_loop, 55 MessageLoop* message_loop,
56 const SearchResultPair* expected_results, 56 const SearchResultPair* expected_results,
57 size_t expected_results_size, 57 size_t expected_results_size,
58 const GURL& expected_next_feed, 58 const GURL& expected_next_feed,
59 FileError error, 59 FileError error,
60 const GURL& next_feed, 60 const GURL& next_feed,
61 scoped_ptr<std::vector<SearchResultInfo> > results) { 61 scoped_ptr<std::vector<SearchResultInfo> > results) {
62 ASSERT_TRUE(results); 62 ASSERT_TRUE(results);
63 ASSERT_EQ(expected_results_size, results->size()); 63 ASSERT_EQ(expected_results_size, results->size());
64 64
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 void AppendContent(std::vector<std::string>* buffer, 105 void AppendContent(std::vector<std::string>* buffer,
106 google_apis::GDataErrorCode error, 106 google_apis::GDataErrorCode error,
107 scoped_ptr<std::string> content) { 107 scoped_ptr<std::string> content) {
108 DCHECK_EQ(error, google_apis::HTTP_SUCCESS); 108 DCHECK_EQ(error, google_apis::HTTP_SUCCESS);
109 buffer->push_back(*content); 109 buffer->push_back(*content);
110 } 110 }
111 111
112 } // namespace 112 } // namespace
113 113
114 class DriveFileSystemTest : public testing::Test { 114 class FileSystemTest : public testing::Test {
115 protected: 115 protected:
116 DriveFileSystemTest() 116 FileSystemTest()
117 : ui_thread_(content::BrowserThread::UI, &message_loop_), 117 : ui_thread_(content::BrowserThread::UI, &message_loop_),
118 // |root_feed_changestamp_| should be set to the largest changestamp in 118 // |root_feed_changestamp_| should be set to the largest changestamp in
119 // about resource feed. But we fake it by some non-zero positive 119 // about resource feed. But we fake it by some non-zero positive
120 // increasing value. See |LoadFeed()|. 120 // increasing value. See |LoadFeed()|.
121 root_feed_changestamp_(1) { 121 root_feed_changestamp_(1) {
122 } 122 }
123 123
124 virtual void SetUp() OVERRIDE { 124 virtual void SetUp() OVERRIDE {
125 profile_.reset(new TestingProfile); 125 profile_.reset(new TestingProfile);
126 126
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 scoped_ptr<JobScheduler> scheduler_; 444 scoped_ptr<JobScheduler> scheduler_;
445 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 445 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
446 resource_metadata_; 446 resource_metadata_;
447 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; 447 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
448 scoped_ptr<StrictMock<MockCacheObserver> > mock_cache_observer_; 448 scoped_ptr<StrictMock<MockCacheObserver> > mock_cache_observer_;
449 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_; 449 scoped_ptr<StrictMock<MockDirectoryChangeObserver> > mock_directory_observer_;
450 450
451 int root_feed_changestamp_; 451 int root_feed_changestamp_;
452 }; 452 };
453 453
454 TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) { 454 TEST_F(FileSystemTest, DuplicatedAsyncInitialization) {
455 // "Fast fetch" will fire an OnirectoryChanged event. 455 // "Fast fetch" will fire an OnirectoryChanged event.
456 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 456 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
457 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 457 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
458 458
459 int counter = 0; 459 int counter = 0;
460 const GetResourceEntryCallback& callback = base::Bind( 460 const GetResourceEntryCallback& callback = base::Bind(
461 &AsyncInitializationCallback, &counter, 2, &message_loop_); 461 &AsyncInitializationCallback, &counter, 2, &message_loop_);
462 462
463 file_system_->GetResourceEntryByPath( 463 file_system_->GetResourceEntryByPath(
464 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); 464 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback);
465 file_system_->GetResourceEntryByPath( 465 file_system_->GetResourceEntryByPath(
466 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback); 466 base::FilePath(FILE_PATH_LITERAL("drive/root")), callback);
467 message_loop_.Run(); // Wait to get our result 467 message_loop_.Run(); // Wait to get our result
468 EXPECT_EQ(2, counter); 468 EXPECT_EQ(2, counter);
469 469
470 // Although GetResourceEntryByPath() was called twice, the resource list 470 // Although GetResourceEntryByPath() was called twice, the resource list
471 // should only be loaded once. In the past, there was a bug that caused 471 // should only be loaded once. In the past, there was a bug that caused
472 // it to be loaded twice. 472 // it to be loaded twice.
473 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); 473 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
474 // See the comment in GetMyDriveRoot test case why this is 2. 474 // See the comment in GetMyDriveRoot test case why this is 2.
475 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count()); 475 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count());
476 } 476 }
477 477
478 TEST_F(DriveFileSystemTest, GetGrandRootEntry) { 478 TEST_F(FileSystemTest, GetGrandRootEntry) {
479 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive")); 479 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive"));
480 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 480 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
481 ASSERT_TRUE(entry); 481 ASSERT_TRUE(entry);
482 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry->resource_id()); 482 EXPECT_EQ(util::kDriveGrandRootSpecialResourceId, entry->resource_id());
483 483
484 // Getting the grand root entry should not cause the resource load to happen. 484 // Getting the grand root entry should not cause the resource load to happen.
485 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); 485 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count());
486 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); 486 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count());
487 } 487 }
488 488
489 TEST_F(DriveFileSystemTest, GetOtherDirEntry) { 489 TEST_F(FileSystemTest, GetOtherDirEntry) {
490 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/other")); 490 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/other"));
491 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 491 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
492 ASSERT_TRUE(entry); 492 ASSERT_TRUE(entry);
493 EXPECT_EQ(util::kDriveOtherDirSpecialResourceId, entry->resource_id()); 493 EXPECT_EQ(util::kDriveOtherDirSpecialResourceId, entry->resource_id());
494 494
495 // Getting the "other" directory entry should not cause the resource load to 495 // Getting the "other" directory entry should not cause the resource load to
496 // happen. 496 // happen.
497 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); 497 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count());
498 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); 498 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count());
499 } 499 }
500 500
501 TEST_F(DriveFileSystemTest, GetMyDriveRoot) { 501 TEST_F(FileSystemTest, GetMyDriveRoot) {
502 // "Fast fetch" will fire an OnirectoryChanged event. 502 // "Fast fetch" will fire an OnirectoryChanged event.
503 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 503 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
504 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 504 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
505 505
506 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root")); 506 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root"));
507 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 507 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
508 ASSERT_TRUE(entry); 508 ASSERT_TRUE(entry);
509 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id()); 509 EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id());
510 510
511 // Absence of "drive/root" in the local metadata triggers the "fast fetch" 511 // Absence of "drive/root" in the local metadata triggers the "fast fetch"
512 // of "drive" directory. Fetch of "drive" grand root directory has a special 512 // of "drive" directory. Fetch of "drive" grand root directory has a special
513 // implementation. Instead of normal GetResourceListInDirectory(), it is 513 // implementation. Instead of normal GetResourceListInDirectory(), it is
514 // emulated by calling GetAboutResource() so that the resource_id of 514 // emulated by calling GetAboutResource() so that the resource_id of
515 // "drive/root" is listed. 515 // "drive/root" is listed.
516 // Together with the normal GetAboutResource() call to retrieve the largest 516 // Together with the normal GetAboutResource() call to retrieve the largest
517 // changestamp, the method is called twice. 517 // changestamp, the method is called twice.
518 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count()); 518 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count());
519 519
520 // After "fast fetch" is done, full resource list is fetched. 520 // After "fast fetch" is done, full resource list is fetched.
521 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); 521 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
522 } 522 }
523 523
524 TEST_F(DriveFileSystemTest, GetExistingFile) { 524 TEST_F(FileSystemTest, GetExistingFile) {
525 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")); 525 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"));
526 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 526 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
527 ASSERT_TRUE(entry); 527 ASSERT_TRUE(entry);
528 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); 528 EXPECT_EQ("file:2_file_resource_id", entry->resource_id());
529 529
530 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 530 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
531 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count()); 531 EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
532 } 532 }
533 533
534 TEST_F(DriveFileSystemTest, GetExistingDocument) { 534 TEST_F(FileSystemTest, GetExistingDocument) {
535 const base::FilePath kFilePath( 535 const base::FilePath kFilePath(
536 FILE_PATH_LITERAL("drive/root/Document 1 excludeDir-test.gdoc")); 536 FILE_PATH_LITERAL("drive/root/Document 1 excludeDir-test.gdoc"));
537 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 537 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
538 ASSERT_TRUE(entry); 538 ASSERT_TRUE(entry);
539 EXPECT_EQ("document:5_document_resource_id", entry->resource_id()); 539 EXPECT_EQ("document:5_document_resource_id", entry->resource_id());
540 } 540 }
541 541
542 TEST_F(DriveFileSystemTest, GetNonExistingFile) { 542 TEST_F(FileSystemTest, GetNonExistingFile) {
543 const base::FilePath kFilePath( 543 const base::FilePath kFilePath(
544 FILE_PATH_LITERAL("drive/root/nonexisting.file")); 544 FILE_PATH_LITERAL("drive/root/nonexisting.file"));
545 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 545 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
546 EXPECT_FALSE(entry); 546 EXPECT_FALSE(entry);
547 } 547 }
548 548
549 TEST_F(DriveFileSystemTest, GetEncodedFileNames) { 549 TEST_F(FileSystemTest, GetEncodedFileNames) {
550 const base::FilePath kFilePath1( 550 const base::FilePath kFilePath1(
551 FILE_PATH_LITERAL("drive/root/Slash / in file 1.txt")); 551 FILE_PATH_LITERAL("drive/root/Slash / in file 1.txt"));
552 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath1); 552 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath1);
553 ASSERT_FALSE(entry); 553 ASSERT_FALSE(entry);
554 554
555 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe( 555 const base::FilePath kFilePath2 = base::FilePath::FromUTF8Unsafe(
556 "drive/root/Slash \xE2\x88\x95 in file 1.txt"); 556 "drive/root/Slash \xE2\x88\x95 in file 1.txt");
557 entry = GetResourceEntryByPathSync(kFilePath2); 557 entry = GetResourceEntryByPathSync(kFilePath2);
558 ASSERT_TRUE(entry); 558 ASSERT_TRUE(entry);
559 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id()); 559 EXPECT_EQ("file:slash_file_resource_id", entry->resource_id());
560 560
561 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe( 561 const base::FilePath kFilePath3 = base::FilePath::FromUTF8Unsafe(
562 "drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt"); 562 "drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt");
563 entry = GetResourceEntryByPathSync(kFilePath3); 563 entry = GetResourceEntryByPathSync(kFilePath3);
564 ASSERT_TRUE(entry); 564 ASSERT_TRUE(entry);
565 EXPECT_EQ("file:slash_subdir_file", entry->resource_id()); 565 EXPECT_EQ("file:slash_subdir_file", entry->resource_id());
566 } 566 }
567 567
568 TEST_F(DriveFileSystemTest, GetDuplicateNames) { 568 TEST_F(FileSystemTest, GetDuplicateNames) {
569 const base::FilePath kFilePath1( 569 const base::FilePath kFilePath1(
570 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); 570 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt"));
571 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath1); 571 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath1);
572 ASSERT_TRUE(entry); 572 ASSERT_TRUE(entry);
573 const std::string resource_id1 = entry->resource_id(); 573 const std::string resource_id1 = entry->resource_id();
574 574
575 const base::FilePath kFilePath2( 575 const base::FilePath kFilePath2(
576 FILE_PATH_LITERAL("drive/root/Duplicate Name (2).txt")); 576 FILE_PATH_LITERAL("drive/root/Duplicate Name (2).txt"));
577 entry = GetResourceEntryByPathSync(kFilePath2); 577 entry = GetResourceEntryByPathSync(kFilePath2);
578 ASSERT_TRUE(entry); 578 ASSERT_TRUE(entry);
579 const std::string resource_id2 = entry->resource_id(); 579 const std::string resource_id2 = entry->resource_id();
580 580
581 // The entries are de-duped non-deterministically, so we shouldn't rely on the 581 // The entries are de-duped non-deterministically, so we shouldn't rely on the
582 // names matching specific resource ids. 582 // names matching specific resource ids.
583 const std::string file3_resource_id = "file:3_file_resource_id"; 583 const std::string file3_resource_id = "file:3_file_resource_id";
584 const std::string file4_resource_id = "file:4_file_resource_id"; 584 const std::string file4_resource_id = "file:4_file_resource_id";
585 EXPECT_TRUE(file3_resource_id == resource_id1 || 585 EXPECT_TRUE(file3_resource_id == resource_id1 ||
586 file3_resource_id == resource_id2); 586 file3_resource_id == resource_id2);
587 EXPECT_TRUE(file4_resource_id == resource_id1 || 587 EXPECT_TRUE(file4_resource_id == resource_id1 ||
588 file4_resource_id == resource_id2); 588 file4_resource_id == resource_id2);
589 } 589 }
590 590
591 TEST_F(DriveFileSystemTest, GetExistingDirectory) { 591 TEST_F(FileSystemTest, GetExistingDirectory) {
592 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/Directory 1")); 592 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/Directory 1"));
593 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 593 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
594 ASSERT_TRUE(entry); 594 ASSERT_TRUE(entry);
595 ASSERT_EQ("folder:1_folder_resource_id", entry->resource_id()); 595 ASSERT_EQ("folder:1_folder_resource_id", entry->resource_id());
596 596
597 // The changestamp should be propagated to the directory. 597 // The changestamp should be propagated to the directory.
598 EXPECT_EQ(fake_drive_service_->largest_changestamp(), 598 EXPECT_EQ(fake_drive_service_->largest_changestamp(),
599 entry->directory_specific_info().changestamp()); 599 entry->directory_specific_info().changestamp());
600 } 600 }
601 601
602 TEST_F(DriveFileSystemTest, GetInSubSubdir) { 602 TEST_F(FileSystemTest, GetInSubSubdir) {
603 const base::FilePath kFilePath( 603 const base::FilePath kFilePath(
604 FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder/" 604 FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder/"
605 "Sub Sub Directory Folder")); 605 "Sub Sub Directory Folder"));
606 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 606 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
607 ASSERT_TRUE(entry); 607 ASSERT_TRUE(entry);
608 ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id()); 608 ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id());
609 } 609 }
610 610
611 TEST_F(DriveFileSystemTest, GetOrphanFile) { 611 TEST_F(FileSystemTest, GetOrphanFile) {
612 const base::FilePath kFilePath( 612 const base::FilePath kFilePath(
613 FILE_PATH_LITERAL("drive/other/Orphan File 1.txt")); 613 FILE_PATH_LITERAL("drive/other/Orphan File 1.txt"));
614 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath); 614 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(kFilePath);
615 ASSERT_TRUE(entry); 615 ASSERT_TRUE(entry);
616 EXPECT_EQ("file:1_orphanfile_resource_id", entry->resource_id()); 616 EXPECT_EQ("file:1_orphanfile_resource_id", entry->resource_id());
617 } 617 }
618 618
619 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_Root) { 619 TEST_F(FileSystemTest, ReadDirectoryByPath_Root) {
620 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 620 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
621 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 621 Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
622 622
623 // ReadDirectoryByPath() should kick off the resource list loading. 623 // ReadDirectoryByPath() should kick off the resource list loading.
624 scoped_ptr<ResourceEntryVector> entries( 624 scoped_ptr<ResourceEntryVector> entries(
625 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive"))); 625 ReadDirectoryByPathSync(base::FilePath::FromUTF8Unsafe("drive")));
626 // The root directory should be read correctly. 626 // The root directory should be read correctly.
627 ASSERT_TRUE(entries); 627 ASSERT_TRUE(entries);
628 ASSERT_EQ(2U, entries->size()); 628 ASSERT_EQ(2U, entries->size());
629 629
630 // The found two directories should be /drive/root and /drive/other. 630 // The found two directories should be /drive/root and /drive/other.
631 bool found_other = false; 631 bool found_other = false;
632 bool found_my_drive = false; 632 bool found_my_drive = false;
633 for (size_t i = 0; i < entries->size(); ++i) { 633 for (size_t i = 0; i < entries->size(); ++i) {
634 const base::FilePath title = 634 const base::FilePath title =
635 base::FilePath::FromUTF8Unsafe((*entries)[i].title()); 635 base::FilePath::FromUTF8Unsafe((*entries)[i].title());
636 if (title == base::FilePath(util::kDriveOtherDirName)) { 636 if (title == base::FilePath(util::kDriveOtherDirName)) {
637 found_other = true; 637 found_other = true;
638 } else if (title == base::FilePath(util::kDriveMyDriveRootDirName)) { 638 } else if (title == base::FilePath(util::kDriveMyDriveRootDirName)) {
639 found_my_drive = true; 639 found_my_drive = true;
640 } 640 }
641 } 641 }
642 642
643 EXPECT_TRUE(found_other); 643 EXPECT_TRUE(found_other);
644 EXPECT_TRUE(found_my_drive); 644 EXPECT_TRUE(found_my_drive);
645 } 645 }
646 646
647 TEST_F(DriveFileSystemTest, ReadDirectoryByPath_NonRootDirectory) { 647 TEST_F(FileSystemTest, ReadDirectoryByPath_NonRootDirectory) {
648 // ReadDirectoryByPath() should kick off the resource list loading. 648 // ReadDirectoryByPath() should kick off the resource list loading.
649 scoped_ptr<ResourceEntryVector> entries( 649 scoped_ptr<ResourceEntryVector> entries(
650 ReadDirectoryByPathSync( 650 ReadDirectoryByPathSync(
651 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); 651 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1")));
652 // The non root directory should also be read correctly. 652 // The non root directory should also be read correctly.
653 // There was a bug (crbug.com/181487), which broke this behavior. 653 // There was a bug (crbug.com/181487), which broke this behavior.
654 // Make sure this is fixed. 654 // Make sure this is fixed.
655 ASSERT_TRUE(entries); 655 ASSERT_TRUE(entries);
656 EXPECT_EQ(3U, entries->size()); 656 EXPECT_EQ(3U, entries->size());
657 } 657 }
658 658
659 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) { 659 TEST_F(FileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) {
660 ASSERT_TRUE(LoadRootFeedDocument()); 660 ASSERT_TRUE(LoadRootFeedDocument());
661 661
662 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 662 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
663 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2); 663 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2);
664 664
665 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_added_in_root.json")); 665 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_added_in_root.json"));
666 EXPECT_TRUE(EntryExists( 666 EXPECT_TRUE(EntryExists(
667 base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc")))); 667 base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc"))));
668 668
669 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_root.json")); 669 ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_root.json"));
670 EXPECT_FALSE(EntryExists( 670 EXPECT_FALSE(EntryExists(
671 base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc")))); 671 base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc"))));
672 } 672 }
673 673
674 TEST_F(DriveFileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) { 674 TEST_F(FileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) {
675 ASSERT_TRUE(LoadRootFeedDocument()); 675 ASSERT_TRUE(LoadRootFeedDocument());
676 676
677 EXPECT_TRUE( 677 EXPECT_TRUE(
678 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))); 678 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))));
679 679
680 // Add file to an existing directory. 680 // Add file to an existing directory.
681 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 681 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
682 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 682 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
683 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 683 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
684 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) 684 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
685 .Times(1); 685 .Times(1);
686 ASSERT_TRUE( 686 ASSERT_TRUE(
687 LoadChangeFeed("chromeos/gdata/delta_file_added_in_directory.json")); 687 LoadChangeFeed("chromeos/gdata/delta_file_added_in_directory.json"));
688 EXPECT_TRUE(EntryExists(base::FilePath( 688 EXPECT_TRUE(EntryExists(base::FilePath(
689 FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc")))); 689 FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc"))));
690 690
691 // Remove that file from the directory. 691 // Remove that file from the directory.
692 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 692 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
693 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) 693 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
694 .Times(1); 694 .Times(1);
695 ASSERT_TRUE( 695 ASSERT_TRUE(
696 LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_directory.json")); 696 LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_directory.json"));
697 EXPECT_TRUE( 697 EXPECT_TRUE(
698 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))); 698 EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))));
699 EXPECT_FALSE(EntryExists(base::FilePath( 699 EXPECT_FALSE(EntryExists(base::FilePath(
700 FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc")))); 700 FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc"))));
701 } 701 }
702 702
703 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewDirectory) { 703 TEST_F(FileSystemTest, ChangeFeed_AddFileToNewDirectory) {
704 ASSERT_TRUE(LoadRootFeedDocument()); 704 ASSERT_TRUE(LoadRootFeedDocument());
705 // Add file to a new directory. 705 // Add file to a new directory.
706 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 706 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
707 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 707 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
708 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 708 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
709 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Directory"))))) 709 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Directory")))))
710 .Times(1); 710 .Times(1);
711 711
712 ASSERT_TRUE( 712 ASSERT_TRUE(
713 LoadChangeFeed("chromeos/gdata/delta_file_added_in_new_directory.json")); 713 LoadChangeFeed("chromeos/gdata/delta_file_added_in_new_directory.json"));
714 714
715 EXPECT_TRUE( 715 EXPECT_TRUE(
716 EntryExists(base::FilePath( 716 EntryExists(base::FilePath(
717 FILE_PATH_LITERAL("drive/root/New Directory")))); 717 FILE_PATH_LITERAL("drive/root/New Directory"))));
718 EXPECT_TRUE(EntryExists(base::FilePath( 718 EXPECT_TRUE(EntryExists(base::FilePath(
719 FILE_PATH_LITERAL("drive/root/New Directory/File in new dir.gdoc")))); 719 FILE_PATH_LITERAL("drive/root/New Directory/File in new dir.gdoc"))));
720 } 720 }
721 721
722 TEST_F(DriveFileSystemTest, ChangeFeed_AddFileToNewButDeletedDirectory) { 722 TEST_F(FileSystemTest, ChangeFeed_AddFileToNewButDeletedDirectory) {
723 ASSERT_TRUE(LoadRootFeedDocument()); 723 ASSERT_TRUE(LoadRootFeedDocument());
724 724
725 // This feed contains the following updates: 725 // This feed contains the following updates:
726 // 1) A new PDF file is added to a new directory 726 // 1) A new PDF file is added to a new directory
727 // 2) but the new directory is marked "deleted" (i.e. moved to Trash) 727 // 2) but the new directory is marked "deleted" (i.e. moved to Trash)
728 // Hence, the PDF file should be just ignored. 728 // Hence, the PDF file should be just ignored.
729 ASSERT_TRUE(LoadChangeFeed( 729 ASSERT_TRUE(LoadChangeFeed(
730 "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json")); 730 "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json"));
731 } 731 }
732 732
733 TEST_F(DriveFileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) { 733 TEST_F(FileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) {
734 ASSERT_TRUE(LoadRootFeedDocument()); 734 ASSERT_TRUE(LoadRootFeedDocument());
735 735
736 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 736 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
737 "drive/root/Directory 2 excludeDir-test")))); 737 "drive/root/Directory 2 excludeDir-test"))));
738 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 738 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
739 "drive/root/Directory 1")))); 739 "drive/root/Directory 1"))));
740 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 740 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
741 "drive/root/Directory 1/SubDirectory File 1.txt")))); 741 "drive/root/Directory 1/SubDirectory File 1.txt"))));
742 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 742 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
743 "drive/root/Directory 1/Sub Directory Folder")))); 743 "drive/root/Directory 1/Sub Directory Folder"))));
(...skipping 27 matching lines...) Expand all
771 "drive/root/Directory 2 excludeDir-test/Directory 1/" 771 "drive/root/Directory 2 excludeDir-test/Directory 1/"
772 "SubDirectory File 1.txt")))); 772 "SubDirectory File 1.txt"))));
773 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 773 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
774 "drive/root/Directory 2 excludeDir-test/Directory 1/" 774 "drive/root/Directory 2 excludeDir-test/Directory 1/"
775 "Sub Directory Folder")))); 775 "Sub Directory Folder"))));
776 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 776 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
777 "drive/root/Directory 2 excludeDir-test/Directory 1/Sub Directory Folder/" 777 "drive/root/Directory 2 excludeDir-test/Directory 1/Sub Directory Folder/"
778 "Sub Sub Directory Folder")))); 778 "Sub Sub Directory Folder"))));
779 } 779 }
780 780
781 TEST_F(DriveFileSystemTest, ChangeFeed_FileMovedFromDirectoryToRoot) { 781 TEST_F(FileSystemTest, ChangeFeed_FileMovedFromDirectoryToRoot) {
782 ASSERT_TRUE(LoadRootFeedDocument()); 782 ASSERT_TRUE(LoadRootFeedDocument());
783 783
784 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 784 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
785 "drive/root/Directory 1")))); 785 "drive/root/Directory 1"))));
786 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 786 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
787 "drive/root/Directory 1/Sub Directory Folder")))); 787 "drive/root/Directory 1/Sub Directory Folder"))));
788 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 788 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
789 "drive/root/Directory 1/Sub Directory Folder/" 789 "drive/root/Directory 1/Sub Directory Folder/"
790 "Sub Sub Directory Folder")))); 790 "Sub Sub Directory Folder"))));
791 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 791 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
(...skipping 13 matching lines...) Expand all
805 "drive/root/Directory 1/Sub Directory Folder")))); 805 "drive/root/Directory 1/Sub Directory Folder"))));
806 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 806 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
807 "drive/root/Directory 1/Sub Directory Folder/" 807 "drive/root/Directory 1/Sub Directory Folder/"
808 "Sub Sub Directory Folder")))); 808 "Sub Sub Directory Folder"))));
809 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 809 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
810 "drive/root/Directory 1/SubDirectory File 1.txt")))); 810 "drive/root/Directory 1/SubDirectory File 1.txt"))));
811 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 811 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
812 "drive/root/SubDirectory File 1.txt")))); 812 "drive/root/SubDirectory File 1.txt"))));
813 } 813 }
814 814
815 TEST_F(DriveFileSystemTest, ChangeFeed_FileRenamedInDirectory) { 815 TEST_F(FileSystemTest, ChangeFeed_FileRenamedInDirectory) {
816 ASSERT_TRUE(LoadRootFeedDocument()); 816 ASSERT_TRUE(LoadRootFeedDocument());
817 817
818 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 818 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
819 "drive/root/Directory 1")))); 819 "drive/root/Directory 1"))));
820 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 820 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
821 "drive/root/Directory 1/SubDirectory File 1.txt")))); 821 "drive/root/Directory 1/SubDirectory File 1.txt"))));
822 822
823 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 823 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
824 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 824 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
825 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 825 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
826 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) 826 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
827 .Times(1); 827 .Times(1);
828 ASSERT_TRUE(LoadChangeFeed( 828 ASSERT_TRUE(LoadChangeFeed(
829 "chromeos/gdata/delta_file_renamed_in_directory.json")); 829 "chromeos/gdata/delta_file_renamed_in_directory.json"));
830 830
831 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 831 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
832 "drive/root/Directory 1")))); 832 "drive/root/Directory 1"))));
833 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 833 EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
834 "drive/root/Directory 1/SubDirectory File 1.txt")))); 834 "drive/root/Directory 1/SubDirectory File 1.txt"))));
835 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( 835 EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL(
836 "drive/root/Directory 1/New SubDirectory File 1.txt")))); 836 "drive/root/Directory 1/New SubDirectory File 1.txt"))));
837 } 837 }
838 838
839 TEST_F(DriveFileSystemTest, CachedFeedLoadingThenServerFeedLoading) { 839 TEST_F(FileSystemTest, CachedFeedLoadingThenServerFeedLoading) {
840 ASSERT_TRUE(SetUpTestFileSystem(USE_SERVER_TIMESTAMP)); 840 ASSERT_TRUE(SetUpTestFileSystem(USE_SERVER_TIMESTAMP));
841 841
842 // Kicks loading of cached file system and query for server update. 842 // Kicks loading of cached file system and query for server update.
843 EXPECT_TRUE(ReadDirectoryByPathSync(util::GetDriveMyDriveRootPath())); 843 EXPECT_TRUE(ReadDirectoryByPathSync(util::GetDriveMyDriveRootPath()));
844 844
845 // SetUpTestFileSystem and "account_metadata.json" have the same changestamp, 845 // SetUpTestFileSystem and "account_metadata.json" have the same changestamp,
846 // so no request for new feeds (i.e., call to GetResourceList) should happen. 846 // so no request for new feeds (i.e., call to GetResourceList) should happen.
847 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 847 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
848 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count()); 848 EXPECT_EQ(0, fake_drive_service_->resource_list_load_count());
849 849
850 // Since the file system has verified that it holds the latest snapshot, 850 // Since the file system has verified that it holds the latest snapshot,
851 // it should change its state to "loaded", which admits periodic refresh. 851 // it should change its state to "loaded", which admits periodic refresh.
852 // To test it, call CheckForUpdates and verify it does try to check updates. 852 // To test it, call CheckForUpdates and verify it does try to check updates.
853 file_system_->CheckForUpdates(); 853 file_system_->CheckForUpdates();
854 google_apis::test_util::RunBlockingPoolTask(); 854 google_apis::test_util::RunBlockingPoolTask();
855 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count()); 855 EXPECT_EQ(2, fake_drive_service_->about_resource_load_count());
856 } 856 }
857 857
858 TEST_F(DriveFileSystemTest, OfflineCachedFeedLoading) { 858 TEST_F(FileSystemTest, OfflineCachedFeedLoading) {
859 ASSERT_TRUE(SetUpTestFileSystem(USE_OLD_TIMESTAMP)); 859 ASSERT_TRUE(SetUpTestFileSystem(USE_OLD_TIMESTAMP));
860 860
861 // Make GetResourceList fail for simulating offline situation. This will leave 861 // Make GetResourceList fail for simulating offline situation. This will leave
862 // the file system "loaded from cache, but not synced with server" state. 862 // the file system "loaded from cache, but not synced with server" state.
863 fake_drive_service_->set_offline(true); 863 fake_drive_service_->set_offline(true);
864 864
865 // Kicks loading of cached file system and query for server update. 865 // Kicks loading of cached file system and query for server update.
866 EXPECT_TRUE(ReadDirectoryByPathSync(util::GetDriveMyDriveRootPath())); 866 EXPECT_TRUE(ReadDirectoryByPathSync(util::GetDriveMyDriveRootPath()));
867 // Loading of about resource should not happen as it's offline. 867 // Loading of about resource should not happen as it's offline.
868 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count()); 868 EXPECT_EQ(0, fake_drive_service_->about_resource_load_count());
(...skipping 18 matching lines...) Expand all
887 887
888 file_system_->CheckForUpdates(); 888 file_system_->CheckForUpdates();
889 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) 889 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
890 .Times(AtLeast(1)); 890 .Times(AtLeast(1));
891 891
892 google_apis::test_util::RunBlockingPoolTask(); 892 google_apis::test_util::RunBlockingPoolTask();
893 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 893 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
894 EXPECT_EQ(1, fake_drive_service_->change_list_load_count()); 894 EXPECT_EQ(1, fake_drive_service_->change_list_load_count());
895 } 895 }
896 896
897 TEST_F(DriveFileSystemTest, ReadDirectoryWhileRefreshing) { 897 TEST_F(FileSystemTest, ReadDirectoryWhileRefreshing) {
898 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) 898 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
899 .Times(AtLeast(1)); 899 .Times(AtLeast(1));
900 900
901 // Enter the "refreshing" state so the fast fetch will be performed. 901 // Enter the "refreshing" state so the fast fetch will be performed.
902 ASSERT_TRUE(SetUpTestFileSystem(USE_OLD_TIMESTAMP)); 902 ASSERT_TRUE(SetUpTestFileSystem(USE_OLD_TIMESTAMP));
903 file_system_->CheckForUpdates(); 903 file_system_->CheckForUpdates();
904 904
905 // The list of resources in "drive/root/Dir1" should be fetched. 905 // The list of resources in "drive/root/Dir1" should be fetched.
906 EXPECT_TRUE(ReadDirectoryByPathSync(base::FilePath( 906 EXPECT_TRUE(ReadDirectoryByPathSync(base::FilePath(
907 FILE_PATH_LITERAL("drive/root/Dir1")))); 907 FILE_PATH_LITERAL("drive/root/Dir1"))));
908 EXPECT_EQ(1, fake_drive_service_->directory_load_count()); 908 EXPECT_EQ(1, fake_drive_service_->directory_load_count());
909 } 909 }
910 910
911 TEST_F(DriveFileSystemTest, GetResourceEntryExistingWhileRefreshing) { 911 TEST_F(FileSystemTest, GetResourceEntryExistingWhileRefreshing) {
912 // Enter the "refreshing" state. 912 // Enter the "refreshing" state.
913 ASSERT_TRUE(SetUpTestFileSystem(USE_OLD_TIMESTAMP)); 913 ASSERT_TRUE(SetUpTestFileSystem(USE_OLD_TIMESTAMP));
914 file_system_->CheckForUpdates(); 914 file_system_->CheckForUpdates();
915 915
916 // If an entry is already found in local metadata, no directory fetch happens. 916 // If an entry is already found in local metadata, no directory fetch happens.
917 EXPECT_TRUE(GetResourceEntryByPathSync(base::FilePath( 917 EXPECT_TRUE(GetResourceEntryByPathSync(base::FilePath(
918 FILE_PATH_LITERAL("drive/root/Dir1/File2")))); 918 FILE_PATH_LITERAL("drive/root/Dir1/File2"))));
919 EXPECT_EQ(0, fake_drive_service_->directory_load_count()); 919 EXPECT_EQ(0, fake_drive_service_->directory_load_count());
920 } 920 }
921 921
922 TEST_F(DriveFileSystemTest, GetResourceEntryNonExistentWhileRefreshing) { 922 TEST_F(FileSystemTest, GetResourceEntryNonExistentWhileRefreshing) {
923 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)) 923 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
924 .Times(AtLeast(1)); 924 .Times(AtLeast(1));
925 925
926 // Enter the "refreshing" state so the fast fetch will be performed. 926 // Enter the "refreshing" state so the fast fetch will be performed.
927 ASSERT_TRUE(SetUpTestFileSystem(USE_OLD_TIMESTAMP)); 927 ASSERT_TRUE(SetUpTestFileSystem(USE_OLD_TIMESTAMP));
928 file_system_->CheckForUpdates(); 928 file_system_->CheckForUpdates();
929 929
930 // If an entry is not found, parent directory's resource list is fetched. 930 // If an entry is not found, parent directory's resource list is fetched.
931 EXPECT_FALSE(GetResourceEntryByPathSync(base::FilePath( 931 EXPECT_FALSE(GetResourceEntryByPathSync(base::FilePath(
932 FILE_PATH_LITERAL("drive/root/Dir1/NonExistentFile")))); 932 FILE_PATH_LITERAL("drive/root/Dir1/NonExistentFile"))));
933 EXPECT_EQ(1, fake_drive_service_->directory_load_count()); 933 EXPECT_EQ(1, fake_drive_service_->directory_load_count());
934 } 934 }
935 935
936 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { 936 TEST_F(FileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
937 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 937 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
938 938
939 ASSERT_TRUE(LoadRootFeedDocument()); 939 ASSERT_TRUE(LoadRootFeedDocument());
940 940
941 // We'll add a file to the Drive root directory. 941 // We'll add a file to the Drive root directory.
942 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 942 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
943 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 943 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
944 944
945 // Prepare a local file. 945 // Prepare a local file.
946 base::ScopedTempDir temp_dir; 946 base::ScopedTempDir temp_dir;
(...skipping 24 matching lines...) Expand all
971 remote_dest_file_path, 971 remote_dest_file_path,
972 google_apis::test_util::CreateCopyResultCallback(&error)); 972 google_apis::test_util::CreateCopyResultCallback(&error));
973 google_apis::test_util::RunBlockingPoolTask(); 973 google_apis::test_util::RunBlockingPoolTask();
974 974
975 EXPECT_EQ(FILE_ERROR_OK, error); 975 EXPECT_EQ(FILE_ERROR_OK, error);
976 976
977 // Now the remote file should exist. 977 // Now the remote file should exist.
978 EXPECT_TRUE(EntryExists(remote_dest_file_path)); 978 EXPECT_TRUE(EntryExists(remote_dest_file_path));
979 } 979 }
980 980
981 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) { 981 TEST_F(FileSystemTest, TransferFileFromLocalToRemote_HostedDocument) {
982 ASSERT_TRUE(LoadRootFeedDocument()); 982 ASSERT_TRUE(LoadRootFeedDocument());
983 983
984 // Prepare a local file, which is a json file of a hosted document, which 984 // Prepare a local file, which is a json file of a hosted document, which
985 // matches "Document 1" in root_feed.json. 985 // matches "Document 1" in root_feed.json.
986 base::ScopedTempDir temp_dir; 986 base::ScopedTempDir temp_dir;
987 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 987 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
988 const base::FilePath local_src_file_path = 988 const base::FilePath local_src_file_path =
989 temp_dir.path().AppendASCII("local.gdoc"); 989 temp_dir.path().AppendASCII("local.gdoc");
990 const std::string kEditUrl = 990 const std::string kEditUrl =
991 "https://3_document_self_link/document:5_document_resource_id"; 991 "https://3_document_self_link/document:5_document_resource_id";
(...skipping 22 matching lines...) Expand all
1014 remote_dest_file_path, 1014 remote_dest_file_path,
1015 google_apis::test_util::CreateCopyResultCallback(&error)); 1015 google_apis::test_util::CreateCopyResultCallback(&error));
1016 google_apis::test_util::RunBlockingPoolTask(); 1016 google_apis::test_util::RunBlockingPoolTask();
1017 1017
1018 EXPECT_EQ(FILE_ERROR_OK, error); 1018 EXPECT_EQ(FILE_ERROR_OK, error);
1019 1019
1020 // Now the remote file should exist. 1020 // Now the remote file should exist.
1021 EXPECT_TRUE(EntryExists(remote_dest_file_path)); 1021 EXPECT_TRUE(EntryExists(remote_dest_file_path));
1022 } 1022 }
1023 1023
1024 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { 1024 TEST_F(FileSystemTest, TransferFileFromRemoteToLocal_RegularFile) {
1025 ASSERT_TRUE(LoadRootFeedDocument()); 1025 ASSERT_TRUE(LoadRootFeedDocument());
1026 1026
1027 // The transfered file is cached and the change of "offline available" 1027 // The transfered file is cached and the change of "offline available"
1028 // attribute is notified. 1028 // attribute is notified.
1029 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1029 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1030 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 1030 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1031 1031
1032 base::ScopedTempDir temp_dir; 1032 base::ScopedTempDir temp_dir;
1033 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1033 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1034 base::FilePath local_dest_file_path = 1034 base::FilePath local_dest_file_path =
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 std::string cache_file_data; 1066 std::string cache_file_data;
1067 EXPECT_TRUE(file_util::ReadFileToString(cache_file_path, &cache_file_data)); 1067 EXPECT_TRUE(file_util::ReadFileToString(cache_file_path, &cache_file_data));
1068 EXPECT_EQ(kExpectedContent, cache_file_data); 1068 EXPECT_EQ(kExpectedContent, cache_file_data);
1069 1069
1070 std::string local_dest_file_data; 1070 std::string local_dest_file_data;
1071 EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path, 1071 EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path,
1072 &local_dest_file_data)); 1072 &local_dest_file_data));
1073 EXPECT_EQ(kExpectedContent, local_dest_file_data); 1073 EXPECT_EQ(kExpectedContent, local_dest_file_data);
1074 } 1074 }
1075 1075
1076 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { 1076 TEST_F(FileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) {
1077 ASSERT_TRUE(LoadRootFeedDocument()); 1077 ASSERT_TRUE(LoadRootFeedDocument());
1078 1078
1079 base::ScopedTempDir temp_dir; 1079 base::ScopedTempDir temp_dir;
1080 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1080 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1081 base::FilePath local_dest_file_path = 1081 base::FilePath local_dest_file_path =
1082 temp_dir.path().AppendASCII("local_copy.txt"); 1082 temp_dir.path().AppendASCII("local_copy.txt");
1083 base::FilePath remote_src_file_path( 1083 base::FilePath remote_src_file_path(
1084 FILE_PATH_LITERAL("drive/root/Document 1 excludeDir-test.gdoc")); 1084 FILE_PATH_LITERAL("drive/root/Document 1 excludeDir-test.gdoc"));
1085 FileError error = FILE_ERROR_FAILED; 1085 FileError error = FILE_ERROR_FAILED;
1086 file_system_->TransferFileFromRemoteToLocal( 1086 file_system_->TransferFileFromRemoteToLocal(
1087 remote_src_file_path, 1087 remote_src_file_path,
1088 local_dest_file_path, 1088 local_dest_file_path,
1089 google_apis::test_util::CreateCopyResultCallback(&error)); 1089 google_apis::test_util::CreateCopyResultCallback(&error));
1090 google_apis::test_util::RunBlockingPoolTask(); 1090 google_apis::test_util::RunBlockingPoolTask();
1091 1091
1092 EXPECT_EQ(FILE_ERROR_OK, error); 1092 EXPECT_EQ(FILE_ERROR_OK, error);
1093 1093
1094 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync( 1094 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(
1095 remote_src_file_path); 1095 remote_src_file_path);
1096 ASSERT_TRUE(entry); 1096 ASSERT_TRUE(entry);
1097 VerifyHostedDocumentJSONFile(*entry, local_dest_file_path); 1097 VerifyHostedDocumentJSONFile(*entry, local_dest_file_path);
1098 } 1098 }
1099 1099
1100 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { 1100 TEST_F(FileSystemTest, CopyNotExistingFile) {
1101 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); 1101 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
1102 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); 1102 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1103 1103
1104 ASSERT_TRUE(LoadRootFeedDocument()); 1104 ASSERT_TRUE(LoadRootFeedDocument());
1105 1105
1106 EXPECT_FALSE(EntryExists(src_file_path)); 1106 EXPECT_FALSE(EntryExists(src_file_path));
1107 1107
1108 FileError error = FILE_ERROR_OK; 1108 FileError error = FILE_ERROR_OK;
1109 file_system_->Copy( 1109 file_system_->Copy(
1110 src_file_path, 1110 src_file_path,
1111 dest_file_path, 1111 dest_file_path,
1112 google_apis::test_util::CreateCopyResultCallback(&error)); 1112 google_apis::test_util::CreateCopyResultCallback(&error));
1113 google_apis::test_util::RunBlockingPoolTask(); 1113 google_apis::test_util::RunBlockingPoolTask();
1114 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); 1114 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
1115 1115
1116 EXPECT_FALSE(EntryExists(src_file_path)); 1116 EXPECT_FALSE(EntryExists(src_file_path));
1117 EXPECT_FALSE(EntryExists(dest_file_path)); 1117 EXPECT_FALSE(EntryExists(dest_file_path));
1118 } 1118 }
1119 1119
1120 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { 1120 TEST_F(FileSystemTest, CopyFileToNonExistingDirectory) {
1121 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1121 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1122 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy")); 1122 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy"));
1123 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log")); 1123 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log"));
1124 1124
1125 ASSERT_TRUE(LoadRootFeedDocument()); 1125 ASSERT_TRUE(LoadRootFeedDocument());
1126 1126
1127 ASSERT_TRUE(EntryExists(src_file_path)); 1127 ASSERT_TRUE(EntryExists(src_file_path));
1128 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync( 1128 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync(
1129 src_file_path); 1129 src_file_path);
1130 ASSERT_TRUE(src_entry); 1130 ASSERT_TRUE(src_entry);
1131 std::string src_file_path_resource_id = src_entry->resource_id(); 1131 std::string src_file_path_resource_id = src_entry->resource_id();
1132 1132
1133 EXPECT_FALSE(EntryExists(dest_parent_path)); 1133 EXPECT_FALSE(EntryExists(dest_parent_path));
1134 1134
1135 FileError error = FILE_ERROR_OK; 1135 FileError error = FILE_ERROR_OK;
1136 file_system_->Copy( 1136 file_system_->Copy(
1137 src_file_path, 1137 src_file_path,
1138 dest_file_path, 1138 dest_file_path,
1139 google_apis::test_util::CreateCopyResultCallback(&error)); 1139 google_apis::test_util::CreateCopyResultCallback(&error));
1140 google_apis::test_util::RunBlockingPoolTask(); 1140 google_apis::test_util::RunBlockingPoolTask();
1141 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); 1141 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
1142 1142
1143 EXPECT_TRUE(EntryExists(src_file_path)); 1143 EXPECT_TRUE(EntryExists(src_file_path));
1144 EXPECT_FALSE(EntryExists(dest_parent_path)); 1144 EXPECT_FALSE(EntryExists(dest_parent_path));
1145 EXPECT_FALSE(EntryExists(dest_file_path)); 1145 EXPECT_FALSE(EntryExists(dest_file_path));
1146 } 1146 }
1147 1147
1148 // Test the case where the parent of |dest_file_path| is an existing file, 1148 // Test the case where the parent of |dest_file_path| is an existing file,
1149 // not a directory. 1149 // not a directory.
1150 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { 1150 TEST_F(FileSystemTest, CopyFileToInvalidPath) {
1151 base::FilePath src_file_path(FILE_PATH_LITERAL( 1151 base::FilePath src_file_path(FILE_PATH_LITERAL(
1152 "drive/root/Document 1 excludeDir-test.gdoc")); 1152 "drive/root/Document 1 excludeDir-test.gdoc"));
1153 base::FilePath dest_parent_path( 1153 base::FilePath dest_parent_path(
1154 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt")); 1154 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt"));
1155 base::FilePath dest_file_path(FILE_PATH_LITERAL( 1155 base::FilePath dest_file_path(FILE_PATH_LITERAL(
1156 "drive/root/Duplicate Name.txt/Document 1 excludeDir-test.gdoc")); 1156 "drive/root/Duplicate Name.txt/Document 1 excludeDir-test.gdoc"));
1157 1157
1158 ASSERT_TRUE(LoadRootFeedDocument()); 1158 ASSERT_TRUE(LoadRootFeedDocument());
1159 1159
1160 ASSERT_TRUE(EntryExists(src_file_path)); 1160 ASSERT_TRUE(EntryExists(src_file_path));
(...skipping 15 matching lines...) Expand all
1176 google_apis::test_util::RunBlockingPoolTask(); 1176 google_apis::test_util::RunBlockingPoolTask();
1177 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); 1177 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
1178 1178
1179 EXPECT_TRUE(EntryExists(src_file_path)); 1179 EXPECT_TRUE(EntryExists(src_file_path));
1180 EXPECT_TRUE(EntryExists(src_file_path)); 1180 EXPECT_TRUE(EntryExists(src_file_path));
1181 EXPECT_TRUE(EntryExists(dest_parent_path)); 1181 EXPECT_TRUE(EntryExists(dest_parent_path));
1182 1182
1183 EXPECT_FALSE(EntryExists(dest_file_path)); 1183 EXPECT_FALSE(EntryExists(dest_file_path));
1184 } 1184 }
1185 1185
1186 TEST_F(DriveFileSystemTest, RemoveEntries) { 1186 TEST_F(FileSystemTest, RemoveEntries) {
1187 ASSERT_TRUE(LoadRootFeedDocument()); 1187 ASSERT_TRUE(LoadRootFeedDocument());
1188 1188
1189 base::FilePath nonexisting_file( 1189 base::FilePath nonexisting_file(
1190 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); 1190 FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
1191 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1191 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1192 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/root/Directory 1")); 1192 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/root/Directory 1"));
1193 base::FilePath file_in_subdir( 1193 base::FilePath file_in_subdir(
1194 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); 1194 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1195 1195
1196 ASSERT_TRUE(EntryExists(file_in_root)); 1196 ASSERT_TRUE(EntryExists(file_in_root));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 // Try removing non-existing file. 1231 // Try removing non-existing file.
1232 EXPECT_FALSE(RemoveEntry(nonexisting_file)); 1232 EXPECT_FALSE(RemoveEntry(nonexisting_file));
1233 1233
1234 // Try removing root file element. 1234 // Try removing root file element.
1235 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive/root")))); 1235 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive/root"))));
1236 1236
1237 // Need this to ensure OnDirectoryChanged() is run. 1237 // Need this to ensure OnDirectoryChanged() is run.
1238 google_apis::test_util::RunBlockingPoolTask(); 1238 google_apis::test_util::RunBlockingPoolTask();
1239 } 1239 }
1240 1240
1241 TEST_F(DriveFileSystemTest, CreateDirectory) { 1241 TEST_F(FileSystemTest, CreateDirectory) {
1242 ASSERT_TRUE(LoadRootFeedDocument()); 1242 ASSERT_TRUE(LoadRootFeedDocument());
1243 1243
1244 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1244 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1245 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 1245 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1246 1246
1247 // Create directory in root. 1247 // Create directory in root.
1248 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); 1248 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1"));
1249 EXPECT_FALSE(EntryExists(dir_path)); 1249 EXPECT_FALSE(EntryExists(dir_path));
1250 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(dir_path)); 1250 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(dir_path));
1251 EXPECT_TRUE(EntryExists(dir_path)); 1251 EXPECT_TRUE(EntryExists(dir_path));
1252 1252
1253 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1253 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1254 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1"))))) 1254 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1")))))
1255 .Times(1); 1255 .Times(1);
1256 1256
1257 // Create directory in a sub directory. 1257 // Create directory in a sub directory.
1258 base::FilePath subdir_path( 1258 base::FilePath subdir_path(
1259 FILE_PATH_LITERAL("drive/root/New Folder 1/New Folder 2")); 1259 FILE_PATH_LITERAL("drive/root/New Folder 1/New Folder 2"));
1260 EXPECT_FALSE(EntryExists(subdir_path)); 1260 EXPECT_FALSE(EntryExists(subdir_path));
1261 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(subdir_path)); 1261 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(subdir_path));
1262 EXPECT_TRUE(EntryExists(subdir_path)); 1262 EXPECT_TRUE(EntryExists(subdir_path));
1263 } 1263 }
1264 1264
1265 TEST_F(DriveFileSystemTest, CreateDirectoryByImplicitLoad) { 1265 TEST_F(FileSystemTest, CreateDirectoryByImplicitLoad) {
1266 // Intentionally *not* calling LoadRootFeedDocument(), for testing that 1266 // Intentionally *not* calling LoadRootFeedDocument(), for testing that
1267 // CreateDirectory ensures feed loading before it runs. 1267 // CreateDirectory ensures feed loading before it runs.
1268 1268
1269 base::FilePath existing_directory( 1269 base::FilePath existing_directory(
1270 FILE_PATH_LITERAL("drive/root/Directory 1")); 1270 FILE_PATH_LITERAL("drive/root/Directory 1"));
1271 FileError error = FILE_ERROR_FAILED; 1271 FileError error = FILE_ERROR_FAILED;
1272 file_system_->CreateDirectory( 1272 file_system_->CreateDirectory(
1273 existing_directory, 1273 existing_directory,
1274 true, // is_exclusive 1274 true, // is_exclusive
1275 false, // is_recursive 1275 false, // is_recursive
1276 google_apis::test_util::CreateCopyResultCallback(&error)); 1276 google_apis::test_util::CreateCopyResultCallback(&error));
1277 google_apis::test_util::RunBlockingPoolTask(); 1277 google_apis::test_util::RunBlockingPoolTask();
1278 1278
1279 // It should fail because is_exclusive is set to true. 1279 // It should fail because is_exclusive is set to true.
1280 EXPECT_EQ(FILE_ERROR_EXISTS, error); 1280 EXPECT_EQ(FILE_ERROR_EXISTS, error);
1281 } 1281 }
1282 1282
1283 TEST_F(DriveFileSystemTest, PinAndUnpin) { 1283 TEST_F(FileSystemTest, PinAndUnpin) {
1284 ASSERT_TRUE(LoadRootFeedDocument()); 1284 ASSERT_TRUE(LoadRootFeedDocument());
1285 1285
1286 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1286 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1287 1287
1288 // Get the file info. 1288 // Get the file info.
1289 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_path)); 1289 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_path));
1290 ASSERT_TRUE(entry); 1290 ASSERT_TRUE(entry);
1291 1291
1292 // Pin the file. 1292 // Pin the file.
1293 FileError error = FILE_ERROR_FAILED; 1293 FileError error = FILE_ERROR_FAILED;
1294 EXPECT_CALL(*mock_cache_observer_, 1294 EXPECT_CALL(*mock_cache_observer_,
1295 OnCachePinned(entry->resource_id(), 1295 OnCachePinned(entry->resource_id(),
1296 entry->file_specific_info().file_md5())).Times(1); 1296 entry->file_specific_info().file_md5())).Times(1);
1297 file_system_->Pin(file_path, 1297 file_system_->Pin(file_path,
1298 google_apis::test_util::CreateCopyResultCallback(&error)); 1298 google_apis::test_util::CreateCopyResultCallback(&error));
1299 google_apis::test_util::RunBlockingPoolTask(); 1299 google_apis::test_util::RunBlockingPoolTask();
1300 EXPECT_EQ(FILE_ERROR_OK, error); 1300 EXPECT_EQ(FILE_ERROR_OK, error);
1301 1301
1302 // Unpin the file. 1302 // Unpin the file.
1303 error = FILE_ERROR_FAILED; 1303 error = FILE_ERROR_FAILED;
1304 EXPECT_CALL(*mock_cache_observer_, 1304 EXPECT_CALL(*mock_cache_observer_,
1305 OnCacheUnpinned(entry->resource_id(), 1305 OnCacheUnpinned(entry->resource_id(),
1306 entry->file_specific_info().file_md5())).Times(1); 1306 entry->file_specific_info().file_md5())).Times(1);
1307 file_system_->Unpin(file_path, 1307 file_system_->Unpin(file_path,
1308 google_apis::test_util::CreateCopyResultCallback(&error)); 1308 google_apis::test_util::CreateCopyResultCallback(&error));
1309 google_apis::test_util::RunBlockingPoolTask(); 1309 google_apis::test_util::RunBlockingPoolTask();
1310 EXPECT_EQ(FILE_ERROR_OK, error); 1310 EXPECT_EQ(FILE_ERROR_OK, error);
1311 } 1311 }
1312 1312
1313 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { 1313 TEST_F(FileSystemTest, GetFileByPath_FromGData_EnoughSpace) {
1314 ASSERT_TRUE(LoadRootFeedDocument()); 1314 ASSERT_TRUE(LoadRootFeedDocument());
1315 1315
1316 // The transfered file is cached and the change of "offline available" 1316 // The transfered file is cached and the change of "offline available"
1317 // attribute is notified. 1317 // attribute is notified.
1318 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1318 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1319 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 1319 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1320 1320
1321 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1321 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1322 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); 1322 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1323 const int64 file_size = entry->file_info().size(); 1323 const int64 file_size = entry->file_info().size();
(...skipping 16 matching lines...) Expand all
1340 1340
1341 // Verify that readable permission is set. 1341 // Verify that readable permission is set.
1342 int permission = 0; 1342 int permission = 0;
1343 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_path, &permission)); 1343 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_path, &permission));
1344 EXPECT_EQ(file_util::FILE_PERMISSION_READ_BY_USER | 1344 EXPECT_EQ(file_util::FILE_PERMISSION_READ_BY_USER |
1345 file_util::FILE_PERMISSION_WRITE_BY_USER | 1345 file_util::FILE_PERMISSION_WRITE_BY_USER |
1346 file_util::FILE_PERMISSION_READ_BY_GROUP | 1346 file_util::FILE_PERMISSION_READ_BY_GROUP |
1347 file_util::FILE_PERMISSION_READ_BY_OTHERS, permission); 1347 file_util::FILE_PERMISSION_READ_BY_OTHERS, permission);
1348 } 1348 }
1349 1349
1350 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { 1350 TEST_F(FileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) {
1351 ASSERT_TRUE(LoadRootFeedDocument()); 1351 ASSERT_TRUE(LoadRootFeedDocument());
1352 1352
1353 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1353 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1354 1354
1355 // Pretend we have no space at all. 1355 // Pretend we have no space at all.
1356 fake_free_disk_space_getter_->set_fake_free_disk_space(0); 1356 fake_free_disk_space_getter_->set_fake_free_disk_space(0);
1357 1357
1358 FileError error = FILE_ERROR_OK; 1358 FileError error = FILE_ERROR_OK;
1359 base::FilePath file_path; 1359 base::FilePath file_path;
1360 scoped_ptr<ResourceEntry> entry; 1360 scoped_ptr<ResourceEntry> entry;
1361 file_system_->GetFileByPath(file_in_root, 1361 file_system_->GetFileByPath(file_in_root,
1362 google_apis::test_util::CreateCopyResultCallback( 1362 google_apis::test_util::CreateCopyResultCallback(
1363 &error, &file_path, &entry)); 1363 &error, &file_path, &entry));
1364 google_apis::test_util::RunBlockingPoolTask(); 1364 google_apis::test_util::RunBlockingPoolTask();
1365 1365
1366 EXPECT_EQ(FILE_ERROR_NO_SPACE, error); 1366 EXPECT_EQ(FILE_ERROR_NO_SPACE, error);
1367 } 1367 }
1368 1368
1369 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { 1369 TEST_F(FileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) {
1370 ASSERT_TRUE(LoadRootFeedDocument()); 1370 ASSERT_TRUE(LoadRootFeedDocument());
1371 1371
1372 // The transfered file is cached and the change of "offline available" 1372 // The transfered file is cached and the change of "offline available"
1373 // attribute is notified. 1373 // attribute is notified.
1374 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1374 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1375 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 1375 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1376 1376
1377 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1377 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1378 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); 1378 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1379 const int64 file_size = entry->file_info().size(); 1379 const int64 file_size = entry->file_info().size();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 google_apis::test_util::RunBlockingPoolTask(); 1414 google_apis::test_util::RunBlockingPoolTask();
1415 1415
1416 EXPECT_EQ(FILE_ERROR_OK, error); 1416 EXPECT_EQ(FILE_ERROR_OK, error);
1417 ASSERT_TRUE(entry); 1417 ASSERT_TRUE(entry);
1418 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); 1418 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1419 1419
1420 // The cache entry should be removed in order to free up space. 1420 // The cache entry should be removed in order to free up space.
1421 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); 1421 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>"));
1422 } 1422 }
1423 1423
1424 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) { 1424 TEST_F(FileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) {
1425 ASSERT_TRUE(LoadRootFeedDocument()); 1425 ASSERT_TRUE(LoadRootFeedDocument());
1426 1426
1427 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1427 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1428 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); 1428 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1429 const int64 file_size = entry->file_info().size(); 1429 const int64 file_size = entry->file_info().size();
1430 1430
1431 // Pretend we have enough space first (checked before downloading a file), 1431 // Pretend we have enough space first (checked before downloading a file),
1432 // but then start reporting we have not enough space. This is to emulate that 1432 // but then start reporting we have not enough space. This is to emulate that
1433 // the disk space becomes full after the file is downloaded for some reason 1433 // the disk space becomes full after the file is downloaded for some reason
1434 // (ex. the actual file was larger than the expected size). 1434 // (ex. the actual file was larger than the expected size).
1435 fake_free_disk_space_getter_->set_fake_free_disk_space( 1435 fake_free_disk_space_getter_->set_fake_free_disk_space(
1436 file_size + internal::kMinFreeSpace); 1436 file_size + internal::kMinFreeSpace);
1437 fake_free_disk_space_getter_->set_fake_free_disk_space( 1437 fake_free_disk_space_getter_->set_fake_free_disk_space(
1438 internal::kMinFreeSpace - 1); 1438 internal::kMinFreeSpace - 1);
1439 fake_free_disk_space_getter_->set_fake_free_disk_space( 1439 fake_free_disk_space_getter_->set_fake_free_disk_space(
1440 internal::kMinFreeSpace - 1); 1440 internal::kMinFreeSpace - 1);
1441 1441
1442 FileError error = FILE_ERROR_OK; 1442 FileError error = FILE_ERROR_OK;
1443 base::FilePath file_path; 1443 base::FilePath file_path;
1444 entry.reset(); 1444 entry.reset();
1445 file_system_->GetFileByPath(file_in_root, 1445 file_system_->GetFileByPath(file_in_root,
1446 google_apis::test_util::CreateCopyResultCallback( 1446 google_apis::test_util::CreateCopyResultCallback(
1447 &error, &file_path, &entry)); 1447 &error, &file_path, &entry));
1448 google_apis::test_util::RunBlockingPoolTask(); 1448 google_apis::test_util::RunBlockingPoolTask();
1449 1449
1450 EXPECT_EQ(FILE_ERROR_NO_SPACE, error); 1450 EXPECT_EQ(FILE_ERROR_NO_SPACE, error);
1451 } 1451 }
1452 1452
1453 TEST_F(DriveFileSystemTest, GetFileByPath_FromCache) { 1453 TEST_F(FileSystemTest, GetFileByPath_FromCache) {
1454 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1454 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1455 1455
1456 ASSERT_TRUE(LoadRootFeedDocument()); 1456 ASSERT_TRUE(LoadRootFeedDocument());
1457 1457
1458 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1458 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1459 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); 1459 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1460 1460
1461 // Store something as cached version of this file. 1461 // Store something as cached version of this file.
1462 FileError error = FILE_ERROR_OK; 1462 FileError error = FILE_ERROR_OK;
1463 cache_->StoreOnUIThread( 1463 cache_->StoreOnUIThread(
(...skipping 10 matching lines...) Expand all
1474 file_system_->GetFileByPath(file_in_root, 1474 file_system_->GetFileByPath(file_in_root,
1475 google_apis::test_util::CreateCopyResultCallback( 1475 google_apis::test_util::CreateCopyResultCallback(
1476 &error, &file_path, &entry)); 1476 &error, &file_path, &entry));
1477 google_apis::test_util::RunBlockingPoolTask(); 1477 google_apis::test_util::RunBlockingPoolTask();
1478 1478
1479 EXPECT_EQ(FILE_ERROR_OK, error); 1479 EXPECT_EQ(FILE_ERROR_OK, error);
1480 ASSERT_TRUE(entry); 1480 ASSERT_TRUE(entry);
1481 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); 1481 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1482 } 1482 }
1483 1483
1484 TEST_F(DriveFileSystemTest, GetFileByPath_HostedDocument) { 1484 TEST_F(FileSystemTest, GetFileByPath_HostedDocument) {
1485 ASSERT_TRUE(LoadRootFeedDocument()); 1485 ASSERT_TRUE(LoadRootFeedDocument());
1486 1486
1487 base::FilePath file_in_root(FILE_PATH_LITERAL( 1487 base::FilePath file_in_root(FILE_PATH_LITERAL(
1488 "drive/root/Document 1 excludeDir-test.gdoc")); 1488 "drive/root/Document 1 excludeDir-test.gdoc"));
1489 scoped_ptr<ResourceEntry> src_entry = 1489 scoped_ptr<ResourceEntry> src_entry =
1490 GetResourceEntryByPathSync(file_in_root); 1490 GetResourceEntryByPathSync(file_in_root);
1491 ASSERT_TRUE(src_entry); 1491 ASSERT_TRUE(src_entry);
1492 1492
1493 FileError error = FILE_ERROR_FAILED; 1493 FileError error = FILE_ERROR_FAILED;
1494 base::FilePath file_path; 1494 base::FilePath file_path;
1495 scoped_ptr<ResourceEntry> entry; 1495 scoped_ptr<ResourceEntry> entry;
1496 file_system_->GetFileByPath(file_in_root, 1496 file_system_->GetFileByPath(file_in_root,
1497 google_apis::test_util::CreateCopyResultCallback( 1497 google_apis::test_util::CreateCopyResultCallback(
1498 &error, &file_path, &entry)); 1498 &error, &file_path, &entry));
1499 google_apis::test_util::RunBlockingPoolTask(); 1499 google_apis::test_util::RunBlockingPoolTask();
1500 1500
1501 EXPECT_EQ(FILE_ERROR_OK, error); 1501 EXPECT_EQ(FILE_ERROR_OK, error);
1502 ASSERT_TRUE(entry); 1502 ASSERT_TRUE(entry);
1503 EXPECT_TRUE(entry->file_specific_info().is_hosted_document()); 1503 EXPECT_TRUE(entry->file_specific_info().is_hosted_document());
1504 EXPECT_FALSE(file_path.empty()); 1504 EXPECT_FALSE(file_path.empty());
1505 1505
1506 ASSERT_TRUE(src_entry); 1506 ASSERT_TRUE(src_entry);
1507 VerifyHostedDocumentJSONFile(*src_entry, file_path); 1507 VerifyHostedDocumentJSONFile(*src_entry, file_path);
1508 } 1508 }
1509 1509
1510 TEST_F(DriveFileSystemTest, GetFileByResourceId) { 1510 TEST_F(FileSystemTest, GetFileByResourceId) {
1511 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1511 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1512 1512
1513 // The transfered file is cached and the change of "offline available" 1513 // The transfered file is cached and the change of "offline available"
1514 // attribute is notified. 1514 // attribute is notified.
1515 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1515 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1516 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 1516 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1517 1517
1518 ASSERT_TRUE(LoadRootFeedDocument()); 1518 ASSERT_TRUE(LoadRootFeedDocument());
1519 1519
1520 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1520 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1521 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); 1521 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1522 std::string resource_id = entry->resource_id(); 1522 std::string resource_id = entry->resource_id();
1523 1523
1524 FileError error = FILE_ERROR_OK; 1524 FileError error = FILE_ERROR_OK;
1525 base::FilePath file_path; 1525 base::FilePath file_path;
1526 entry.reset(); 1526 entry.reset();
1527 file_system_->GetFileByResourceId( 1527 file_system_->GetFileByResourceId(
1528 resource_id, 1528 resource_id,
1529 DriveClientContext(USER_INITIATED), 1529 DriveClientContext(USER_INITIATED),
1530 google_apis::test_util::CreateCopyResultCallback( 1530 google_apis::test_util::CreateCopyResultCallback(
1531 &error, &file_path, &entry), 1531 &error, &file_path, &entry),
1532 google_apis::GetContentCallback()); 1532 google_apis::GetContentCallback());
1533 google_apis::test_util::RunBlockingPoolTask(); 1533 google_apis::test_util::RunBlockingPoolTask();
1534 1534
1535 EXPECT_EQ(FILE_ERROR_OK, error); 1535 EXPECT_EQ(FILE_ERROR_OK, error);
1536 ASSERT_TRUE(entry); 1536 ASSERT_TRUE(entry);
1537 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); 1537 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1538 } 1538 }
1539 1539
1540 TEST_F(DriveFileSystemTest, GetFileContentByPath) { 1540 TEST_F(FileSystemTest, GetFileContentByPath) {
1541 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1541 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1542 1542
1543 // The transfered file is cached and the change of "offline available" 1543 // The transfered file is cached and the change of "offline available"
1544 // attribute is notified. 1544 // attribute is notified.
1545 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1545 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1546 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 1546 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1547 1547
1548 ASSERT_TRUE(LoadRootFeedDocument()); 1548 ASSERT_TRUE(LoadRootFeedDocument());
1549 1549
1550 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1550 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1609 EXPECT_TRUE(cancel_download.is_null()); 1609 EXPECT_TRUE(cancel_download.is_null());
1610 // The content is available from the cache file. 1610 // The content is available from the cache file.
1611 EXPECT_TRUE(content_buffer.empty()); 1611 EXPECT_TRUE(content_buffer.empty());
1612 int64 local_file_size = 0; 1612 int64 local_file_size = 0;
1613 file_util::GetFileSize(local_path, &local_file_size); 1613 file_util::GetFileSize(local_path, &local_file_size);
1614 EXPECT_EQ(entry->file_info().size(), local_file_size); 1614 EXPECT_EQ(entry->file_info().size(), local_file_size);
1615 EXPECT_EQ(FILE_ERROR_OK, completion_error); 1615 EXPECT_EQ(FILE_ERROR_OK, completion_error);
1616 } 1616 }
1617 } 1617 }
1618 1618
1619 TEST_F(DriveFileSystemTest, GetFileByResourceId_FromCache) { 1619 TEST_F(FileSystemTest, GetFileByResourceId_FromCache) {
1620 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1620 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1621 1621
1622 ASSERT_TRUE(LoadRootFeedDocument()); 1622 ASSERT_TRUE(LoadRootFeedDocument());
1623 1623
1624 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1624 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1625 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); 1625 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1626 1626
1627 // Store something as cached version of this file. 1627 // Store something as cached version of this file.
1628 FileError error = FILE_ERROR_FAILED; 1628 FileError error = FILE_ERROR_FAILED;
1629 cache_->StoreOnUIThread( 1629 cache_->StoreOnUIThread(
(...skipping 18 matching lines...) Expand all
1648 google_apis::test_util::CreateCopyResultCallback( 1648 google_apis::test_util::CreateCopyResultCallback(
1649 &error, &file_path, &entry), 1649 &error, &file_path, &entry),
1650 google_apis::GetContentCallback()); 1650 google_apis::GetContentCallback());
1651 google_apis::test_util::RunBlockingPoolTask(); 1651 google_apis::test_util::RunBlockingPoolTask();
1652 1652
1653 EXPECT_EQ(FILE_ERROR_OK, error); 1653 EXPECT_EQ(FILE_ERROR_OK, error);
1654 ASSERT_TRUE(entry); 1654 ASSERT_TRUE(entry);
1655 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); 1655 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1656 } 1656 }
1657 1657
1658 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) { 1658 TEST_F(FileSystemTest, UpdateFileByResourceId_PersistentFile) {
1659 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1659 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1660 1660
1661 ASSERT_TRUE(LoadRootFeedDocument()); 1661 ASSERT_TRUE(LoadRootFeedDocument());
1662 1662
1663 // This is a file defined in root_feed.json. 1663 // This is a file defined in root_feed.json.
1664 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1664 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1665 const std::string kResourceId("file:2_file_resource_id"); 1665 const std::string kResourceId("file:2_file_resource_id");
1666 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce"); 1666 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce");
1667 1667
1668 // Pin the file so it'll be store in "persistent" directory. 1668 // Pin the file so it'll be store in "persistent" directory.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 google_apis::test_util::CreateCopyResultCallback(&error)); 1720 google_apis::test_util::CreateCopyResultCallback(&error));
1721 google_apis::test_util::RunBlockingPoolTask(); 1721 google_apis::test_util::RunBlockingPoolTask();
1722 EXPECT_EQ(FILE_ERROR_OK, error); 1722 EXPECT_EQ(FILE_ERROR_OK, error);
1723 1723
1724 // Make sure that the number of files did not change (i.e. we updated an 1724 // Make sure that the number of files did not change (i.e. we updated an
1725 // existing file, rather than adding a new file. The number of files 1725 // existing file, rather than adding a new file. The number of files
1726 // increases if we don't handle the file update right). 1726 // increases if we don't handle the file update right).
1727 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); 1727 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries));
1728 } 1728 }
1729 1729
1730 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { 1730 TEST_F(FileSystemTest, UpdateFileByResourceId_NonexistentFile) {
1731 ASSERT_TRUE(LoadRootFeedDocument()); 1731 ASSERT_TRUE(LoadRootFeedDocument());
1732 1732
1733 // This is nonexistent in root_feed.json. 1733 // This is nonexistent in root_feed.json.
1734 const base::FilePath kFilePath( 1734 const base::FilePath kFilePath(
1735 FILE_PATH_LITERAL("drive/root/Nonexistent.txt")); 1735 FILE_PATH_LITERAL("drive/root/Nonexistent.txt"));
1736 const std::string kResourceId("file:nonexistent_resource_id"); 1736 const std::string kResourceId("file:nonexistent_resource_id");
1737 const std::string kMd5("nonexistent_md5"); 1737 const std::string kMd5("nonexistent_md5");
1738 1738
1739 // The callback will be called upon completion of 1739 // The callback will be called upon completion of
1740 // UpdateFileByResourceId(). 1740 // UpdateFileByResourceId().
1741 FileError error = FILE_ERROR_OK; 1741 FileError error = FILE_ERROR_OK;
1742 file_system_->UpdateFileByResourceId( 1742 file_system_->UpdateFileByResourceId(
1743 kResourceId, 1743 kResourceId,
1744 DriveClientContext(USER_INITIATED), 1744 DriveClientContext(USER_INITIATED),
1745 google_apis::test_util::CreateCopyResultCallback(&error)); 1745 google_apis::test_util::CreateCopyResultCallback(&error));
1746 google_apis::test_util::RunBlockingPoolTask(); 1746 google_apis::test_util::RunBlockingPoolTask();
1747 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); 1747 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
1748 } 1748 }
1749 1749
1750 TEST_F(DriveFileSystemTest, ContentSearch) { 1750 TEST_F(FileSystemTest, ContentSearch) {
1751 ASSERT_TRUE(LoadRootFeedDocument()); 1751 ASSERT_TRUE(LoadRootFeedDocument());
1752 1752
1753 const SearchResultPair kExpectedResults[] = { 1753 const SearchResultPair kExpectedResults[] = {
1754 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", 1754 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder",
1755 true }, 1755 true },
1756 { "drive/root/Directory 1/Sub Directory Folder", true }, 1756 { "drive/root/Directory 1/Sub Directory Folder", true },
1757 { "drive/root/Directory 1/SubDirectory File 1.txt", false }, 1757 { "drive/root/Directory 1/SubDirectory File 1.txt", false },
1758 { "drive/root/Directory 1", true }, 1758 { "drive/root/Directory 1", true },
1759 { "drive/root/Directory 2 excludeDir-test", true }, 1759 { "drive/root/Directory 2 excludeDir-test", true },
1760 }; 1760 };
1761 1761
1762 SearchCallback callback = base::Bind( 1762 SearchCallback callback = base::Bind(
1763 &DriveSearchCallback, 1763 &VerifySearchResult,
1764 &message_loop_, 1764 &message_loop_,
1765 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), 1765 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults),
1766 GURL()); 1766 GURL());
1767 1767
1768 file_system_->Search("Directory", GURL(), callback); 1768 file_system_->Search("Directory", GURL(), callback);
1769 google_apis::test_util::RunBlockingPoolTask(); 1769 google_apis::test_util::RunBlockingPoolTask();
1770 } 1770 }
1771 1771
1772 TEST_F(DriveFileSystemTest, ContentSearchWithNewEntry) { 1772 TEST_F(FileSystemTest, ContentSearchWithNewEntry) {
1773 ASSERT_TRUE(LoadRootFeedDocument()); 1773 ASSERT_TRUE(LoadRootFeedDocument());
1774 1774
1775 // Create a new directory in the drive service. 1775 // Create a new directory in the drive service.
1776 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; 1776 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
1777 scoped_ptr<google_apis::ResourceEntry> resource_entry; 1777 scoped_ptr<google_apis::ResourceEntry> resource_entry;
1778 fake_drive_service_->AddNewDirectory( 1778 fake_drive_service_->AddNewDirectory(
1779 fake_drive_service_->GetRootResourceId(), // Add to the root directory. 1779 fake_drive_service_->GetRootResourceId(), // Add to the root directory.
1780 "New Directory 1!", 1780 "New Directory 1!",
1781 google_apis::test_util::CreateCopyResultCallback( 1781 google_apis::test_util::CreateCopyResultCallback(
1782 &error, &resource_entry)); 1782 &error, &resource_entry));
1783 google_apis::test_util::RunBlockingPoolTask(); 1783 google_apis::test_util::RunBlockingPoolTask();
1784 1784
1785 // As the result of the first Search(), only entries in the current file 1785 // As the result of the first Search(), only entries in the current file
1786 // system snapshot are expected to be returned (i.e. "New Directory 1!" 1786 // system snapshot are expected to be returned (i.e. "New Directory 1!"
1787 // shouldn't be included in the search result even though it matches 1787 // shouldn't be included in the search result even though it matches
1788 // "Directory 1". 1788 // "Directory 1".
1789 const SearchResultPair kExpectedResults[] = { 1789 const SearchResultPair kExpectedResults[] = {
1790 { "drive/root/Directory 1", true } 1790 { "drive/root/Directory 1", true }
1791 }; 1791 };
1792 1792
1793 SearchCallback callback = base::Bind( 1793 SearchCallback callback = base::Bind(
1794 &DriveSearchCallback, 1794 &VerifySearchResult,
1795 &message_loop_, 1795 &message_loop_,
1796 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults), 1796 kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults),
1797 GURL()); 1797 GURL());
1798 1798
1799 file_system_->Search("\"Directory 1\"", GURL(), callback); 1799 file_system_->Search("\"Directory 1\"", GURL(), callback);
1800 google_apis::test_util::RunBlockingPoolTask(); 1800 google_apis::test_util::RunBlockingPoolTask();
1801 } 1801 }
1802 1802
1803 TEST_F(DriveFileSystemTest, ContentSearchEmptyResult) { 1803 TEST_F(FileSystemTest, ContentSearchEmptyResult) {
1804 ASSERT_TRUE(LoadRootFeedDocument()); 1804 ASSERT_TRUE(LoadRootFeedDocument());
1805 1805
1806 const SearchResultPair* expected_results = NULL; 1806 const SearchResultPair* expected_results = NULL;
1807 1807
1808 SearchCallback callback = base::Bind( 1808 SearchCallback callback = base::Bind(
1809 &DriveSearchCallback, 1809 &VerifySearchResult,
1810 &message_loop_, 1810 &message_loop_,
1811 expected_results, 1811 expected_results,
1812 0u, 1812 0u,
1813 GURL()); 1813 GURL());
1814 1814
1815 file_system_->Search("\"no-match query\"", GURL(), callback); 1815 file_system_->Search("\"no-match query\"", GURL(), callback);
1816 google_apis::test_util::RunBlockingPoolTask(); 1816 google_apis::test_util::RunBlockingPoolTask();
1817 } 1817 }
1818 1818
1819 TEST_F(DriveFileSystemTest, GetAvailableSpace) { 1819 TEST_F(FileSystemTest, GetAvailableSpace) {
1820 FileError error = FILE_ERROR_OK; 1820 FileError error = FILE_ERROR_OK;
1821 int64 bytes_total; 1821 int64 bytes_total;
1822 int64 bytes_used; 1822 int64 bytes_used;
1823 file_system_->GetAvailableSpace( 1823 file_system_->GetAvailableSpace(
1824 google_apis::test_util::CreateCopyResultCallback( 1824 google_apis::test_util::CreateCopyResultCallback(
1825 &error, &bytes_total, &bytes_used)); 1825 &error, &bytes_total, &bytes_used));
1826 google_apis::test_util::RunBlockingPoolTask(); 1826 google_apis::test_util::RunBlockingPoolTask();
1827 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used); 1827 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used);
1828 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total); 1828 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total);
1829 } 1829 }
1830 1830
1831 TEST_F(DriveFileSystemTest, RefreshDirectory) { 1831 TEST_F(FileSystemTest, RefreshDirectory) {
1832 ASSERT_TRUE(LoadRootFeedDocument()); 1832 ASSERT_TRUE(LoadRootFeedDocument());
1833 1833
1834 // We'll notify the directory change to the observer. 1834 // We'll notify the directory change to the observer.
1835 EXPECT_CALL(*mock_directory_observer_, 1835 EXPECT_CALL(*mock_directory_observer_,
1836 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath()))).Times(1); 1836 OnDirectoryChanged(Eq(util::GetDriveMyDriveRootPath()))).Times(1);
1837 1837
1838 FileError error = FILE_ERROR_FAILED; 1838 FileError error = FILE_ERROR_FAILED;
1839 file_system_->RefreshDirectory( 1839 file_system_->RefreshDirectory(
1840 util::GetDriveMyDriveRootPath(), 1840 util::GetDriveMyDriveRootPath(),
1841 google_apis::test_util::CreateCopyResultCallback(&error)); 1841 google_apis::test_util::CreateCopyResultCallback(&error));
1842 google_apis::test_util::RunBlockingPoolTask(); 1842 google_apis::test_util::RunBlockingPoolTask();
1843 EXPECT_EQ(FILE_ERROR_OK, error); 1843 EXPECT_EQ(FILE_ERROR_OK, error);
1844 } 1844 }
1845 1845
1846 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { 1846 TEST_F(FileSystemTest, OpenAndCloseFile) {
1847 ASSERT_TRUE(LoadRootFeedDocument()); 1847 ASSERT_TRUE(LoadRootFeedDocument());
1848 1848
1849 // The transfered file is cached and the change of "offline available" 1849 // The transfered file is cached and the change of "offline available"
1850 // attribute is notified. 1850 // attribute is notified.
1851 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1851 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1852 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); 1852 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1853 1853
1854 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1854 const base::FilePath kFileInRoot(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1855 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(kFileInRoot)); 1855 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(kFileInRoot));
1856 const int64 file_size = entry->file_info().size(); 1856 const int64 file_size = entry->file_info().size();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 // Try to close the same file twice. 1927 // Try to close the same file twice.
1928 file_system_->CloseFile( 1928 file_system_->CloseFile(
1929 kFileInRoot, 1929 kFileInRoot,
1930 google_apis::test_util::CreateCopyResultCallback(&error)); 1930 google_apis::test_util::CreateCopyResultCallback(&error));
1931 google_apis::test_util::RunBlockingPoolTask(); 1931 google_apis::test_util::RunBlockingPoolTask();
1932 1932
1933 // It must fail. 1933 // It must fail.
1934 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); 1934 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
1935 } 1935 }
1936 1936
1937 TEST_F(DriveFileSystemTest, MarkCacheFileAsMountedAndUnmounted) { 1937 TEST_F(FileSystemTest, MarkCacheFileAsMountedAndUnmounted) {
1938 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1938 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1939 ASSERT_TRUE(LoadRootFeedDocument()); 1939 ASSERT_TRUE(LoadRootFeedDocument());
1940 1940
1941 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1941 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1942 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); 1942 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1943 ASSERT_TRUE(entry); 1943 ASSERT_TRUE(entry);
1944 1944
1945 // Write to cache. 1945 // Write to cache.
1946 FileError error = FILE_ERROR_FAILED; 1946 FileError error = FILE_ERROR_FAILED;
1947 cache_->StoreOnUIThread( 1947 cache_->StoreOnUIThread(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 entry->resource_id(), 1986 entry->resource_id(),
1987 entry->file_specific_info().file_md5(), 1987 entry->file_specific_info().file_md5(),
1988 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); 1988 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry));
1989 google_apis::test_util::RunBlockingPoolTask(); 1989 google_apis::test_util::RunBlockingPoolTask();
1990 1990
1991 EXPECT_TRUE(success); 1991 EXPECT_TRUE(success);
1992 EXPECT_FALSE(cache_entry.is_mounted()); 1992 EXPECT_FALSE(cache_entry.is_mounted());
1993 } 1993 }
1994 1994
1995 } // namespace drive 1995 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698