| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/drive/drive_file_system.h" | 5 #include "chrome/browser/chromeos/drive/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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 using ::testing::AtLeast; | 42 using ::testing::AtLeast; |
| 43 using ::testing::Eq; | 43 using ::testing::Eq; |
| 44 using ::testing::NotNull; | 44 using ::testing::NotNull; |
| 45 using ::testing::Return; | 45 using ::testing::Return; |
| 46 using ::testing::StrictMock; | 46 using ::testing::StrictMock; |
| 47 using ::testing::_; | 47 using ::testing::_; |
| 48 | 48 |
| 49 namespace drive { | 49 namespace drive { |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 // The root directory resource ID for WAPI. |
| 53 // TODO(haruki): Make Drive API equivalent work. http://crbug.com/157114 |
| 54 const char kTestRootDirectoryResourceId[] = "folder:testroot"; |
| 55 |
| 52 const char kSymLinkToDevNull[] = "/dev/null"; | 56 const char kSymLinkToDevNull[] = "/dev/null"; |
| 53 | 57 |
| 54 const int64 kLotsOfSpace = kMinFreeSpace * 10; | 58 const int64 kLotsOfSpace = kMinFreeSpace * 10; |
| 55 | 59 |
| 56 struct SearchResultPair { | 60 struct SearchResultPair { |
| 57 const char* path; | 61 const char* path; |
| 58 const bool is_directory; | 62 const bool is_directory; |
| 59 }; | 63 }; |
| 60 | 64 |
| 61 // Callback to DriveFileSystem::Search used in ContentSearch tests. | 65 // Callback to DriveFileSystem::Search used in ContentSearch tests. |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 // equal to that of "account_metadata.json" test data, indicating the cache is | 621 // equal to that of "account_metadata.json" test data, indicating the cache is |
| 618 // holding the latest file system info. | 622 // holding the latest file system info. |
| 619 void SaveTestFileSystem(SaveTestFileSystemParam param) { | 623 void SaveTestFileSystem(SaveTestFileSystemParam param) { |
| 620 DriveRootDirectoryProto root; | 624 DriveRootDirectoryProto root; |
| 621 root.set_version(kProtoVersion); | 625 root.set_version(kProtoVersion); |
| 622 root.set_largest_changestamp(param == USE_SERVER_TIMESTAMP ? 654321 : 0); | 626 root.set_largest_changestamp(param == USE_SERVER_TIMESTAMP ? 654321 : 0); |
| 623 DriveDirectoryProto* root_dir = root.mutable_drive_directory(); | 627 DriveDirectoryProto* root_dir = root.mutable_drive_directory(); |
| 624 DriveEntryProto* dir_base = root_dir->mutable_drive_entry(); | 628 DriveEntryProto* dir_base = root_dir->mutable_drive_entry(); |
| 625 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); | 629 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); |
| 626 dir_base->set_title("drive"); | 630 dir_base->set_title("drive"); |
| 627 dir_base->set_resource_id(kDriveRootDirectoryResourceId); | 631 dir_base->set_resource_id(kTestRootDirectoryResourceId); |
| 628 dir_base->set_upload_url("http://resumable-create-media/1"); | 632 dir_base->set_upload_url("http://resumable-create-media/1"); |
| 629 platform_info->set_is_directory(true); | 633 platform_info->set_is_directory(true); |
| 630 | 634 |
| 631 // drive/File1 | 635 // drive/File1 |
| 632 DriveEntryProto* file = root_dir->add_child_files(); | 636 DriveEntryProto* file = root_dir->add_child_files(); |
| 633 file->set_title("File1"); | 637 file->set_title("File1"); |
| 634 file->set_resource_id("resource_id:File1"); | 638 file->set_resource_id("resource_id:File1"); |
| 635 file->set_upload_url("http://resumable-edit-media/1"); | 639 file->set_upload_url("http://resumable-edit-media/1"); |
| 636 file->mutable_file_specific_info()->set_file_md5("md5"); | 640 file->mutable_file_specific_info()->set_file_md5("md5"); |
| 637 platform_info = file->mutable_file_info(); | 641 platform_info = file->mutable_file_info(); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 EXPECT_EQ(2, counter); | 869 EXPECT_EQ(2, counter); |
| 866 } | 870 } |
| 867 | 871 |
| 868 TEST_F(DriveFileSystemTest, SearchRootDirectory) { | 872 TEST_F(DriveFileSystemTest, SearchRootDirectory) { |
| 869 LoadRootFeedDocument("gdata/root_feed.json"); | 873 LoadRootFeedDocument("gdata/root_feed.json"); |
| 870 | 874 |
| 871 const FilePath kFilePath = FilePath(FILE_PATH_LITERAL("drive")); | 875 const FilePath kFilePath = FilePath(FILE_PATH_LITERAL("drive")); |
| 872 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync( | 876 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync( |
| 873 FilePath(FILE_PATH_LITERAL(kFilePath))); | 877 FilePath(FILE_PATH_LITERAL(kFilePath))); |
| 874 ASSERT_TRUE(entry.get()); | 878 ASSERT_TRUE(entry.get()); |
| 875 EXPECT_EQ(kDriveRootDirectoryResourceId, entry->resource_id()); | 879 // We get kWAPIRootDirectoryResourceId instead of kTestRootDirectoryResourceId |
| 880 // here, as the root ID is set in DriveFeedLoader::UpdateFromFeed(). |
| 881 EXPECT_EQ(kWAPIRootDirectoryResourceId, entry->resource_id()); |
| 876 } | 882 } |
| 877 | 883 |
| 878 TEST_F(DriveFileSystemTest, SearchExistingFile) { | 884 TEST_F(DriveFileSystemTest, SearchExistingFile) { |
| 879 LoadRootFeedDocument("gdata/root_feed.json"); | 885 LoadRootFeedDocument("gdata/root_feed.json"); |
| 880 | 886 |
| 881 const FilePath kFilePath = FilePath( | 887 const FilePath kFilePath = FilePath( |
| 882 FILE_PATH_LITERAL("drive/File 1.txt")); | 888 FILE_PATH_LITERAL("drive/File 1.txt")); |
| 883 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 889 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 884 ASSERT_TRUE(entry.get()); | 890 ASSERT_TRUE(entry.get()); |
| 885 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); | 891 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); |
| (...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2564 file_system_->GetAvailableSpace(callback); | 2570 file_system_->GetAvailableSpace(callback); |
| 2565 google_apis::test_util::RunBlockingPoolTask(); | 2571 google_apis::test_util::RunBlockingPoolTask(); |
| 2566 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); | 2572 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); |
| 2567 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); | 2573 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); |
| 2568 } | 2574 } |
| 2569 | 2575 |
| 2570 TEST_F(DriveFileSystemTest, RequestDirectoryRefresh) { | 2576 TEST_F(DriveFileSystemTest, RequestDirectoryRefresh) { |
| 2571 LoadRootFeedDocument("gdata/root_feed.json"); | 2577 LoadRootFeedDocument("gdata/root_feed.json"); |
| 2572 | 2578 |
| 2573 // We'll fetch documents in the root directory with its resource ID. | 2579 // We'll fetch documents in the root directory with its resource ID. |
| 2580 // kWAPIRootDirectoryResourceId instead of kTestRootDirectoryResourceId |
| 2581 // is used here as the root ID is set in DriveFeedLoader::UpdateFromFeed(). |
| 2574 EXPECT_CALL(*mock_drive_service_, | 2582 EXPECT_CALL(*mock_drive_service_, |
| 2575 GetDocuments(Eq(GURL()), _, _, kDriveRootDirectoryResourceId, _)) | 2583 GetDocuments(Eq(GURL()), _, _, kWAPIRootDirectoryResourceId, _)) |
| 2576 .Times(1); | 2584 .Times(1); |
| 2577 // We'll notify the directory change to the observer. | 2585 // We'll notify the directory change to the observer. |
| 2578 EXPECT_CALL(*mock_directory_observer_, | 2586 EXPECT_CALL(*mock_directory_observer_, |
| 2579 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); | 2587 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); |
| 2580 | 2588 |
| 2581 file_system_->RequestDirectoryRefresh(FilePath(kDriveRootDirectory)); | 2589 file_system_->RequestDirectoryRefresh(FilePath(kDriveRootDirectory)); |
| 2582 google_apis::test_util::RunBlockingPoolTask(); | 2590 google_apis::test_util::RunBlockingPoolTask(); |
| 2583 } | 2591 } |
| 2584 | 2592 |
| 2585 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { | 2593 TEST_F(DriveFileSystemTest, OpenAndCloseFile) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2667 | 2675 |
| 2668 // Try to close the same file twice. | 2676 // Try to close the same file twice. |
| 2669 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2677 file_system_->CloseFile(kFileInRoot, close_file_callback); |
| 2670 message_loop_.Run(); | 2678 message_loop_.Run(); |
| 2671 | 2679 |
| 2672 // It must fail. | 2680 // It must fail. |
| 2673 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2681 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 2674 } | 2682 } |
| 2675 | 2683 |
| 2676 } // namespace drive | 2684 } // namespace drive |
| OLD | NEW |