| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 // Sets the changestamp to 654321, equal to that of "account_metadata.json" | 665 // Sets the changestamp to 654321, equal to that of "account_metadata.json" |
| 666 // test data, indicating the cache is holding the latest file system info. | 666 // test data, indicating the cache is holding the latest file system info. |
| 667 void SaveTestFileSystem() { | 667 void SaveTestFileSystem() { |
| 668 DriveRootDirectoryProto root; | 668 DriveRootDirectoryProto root; |
| 669 root.set_version(kProtoVersion); | 669 root.set_version(kProtoVersion); |
| 670 root.set_largest_changestamp(654321); | 670 root.set_largest_changestamp(654321); |
| 671 DriveDirectoryProto* root_dir = root.mutable_gdata_directory(); | 671 DriveDirectoryProto* root_dir = root.mutable_gdata_directory(); |
| 672 DriveEntryProto* dir_base = root_dir->mutable_gdata_entry(); | 672 DriveEntryProto* dir_base = root_dir->mutable_gdata_entry(); |
| 673 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); | 673 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); |
| 674 dir_base->set_title("drive"); | 674 dir_base->set_title("drive"); |
| 675 dir_base->set_resource_id(kGDataRootDirectoryResourceId); | 675 dir_base->set_resource_id(kDriveRootDirectoryResourceId); |
| 676 dir_base->set_upload_url("http://resumable-create-media/1"); | 676 dir_base->set_upload_url("http://resumable-create-media/1"); |
| 677 platform_info->set_is_directory(true); | 677 platform_info->set_is_directory(true); |
| 678 | 678 |
| 679 // drive/File1 | 679 // drive/File1 |
| 680 DriveEntryProto* file = root_dir->add_child_files(); | 680 DriveEntryProto* file = root_dir->add_child_files(); |
| 681 file->set_title("File1"); | 681 file->set_title("File1"); |
| 682 file->set_resource_id("resource_id:File1"); | 682 file->set_resource_id("resource_id:File1"); |
| 683 file->set_upload_url("http://resumable-edit-media/1"); | 683 file->set_upload_url("http://resumable-edit-media/1"); |
| 684 file->mutable_file_specific_info()->set_file_md5("md5"); | 684 file->mutable_file_specific_info()->set_file_md5("md5"); |
| 685 platform_info = file->mutable_file_info(); | 685 platform_info = file->mutable_file_info(); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 EXPECT_EQ(2, counter); | 908 EXPECT_EQ(2, counter); |
| 909 } | 909 } |
| 910 | 910 |
| 911 TEST_F(GDataFileSystemTest, SearchRootDirectory) { | 911 TEST_F(GDataFileSystemTest, SearchRootDirectory) { |
| 912 LoadRootFeedDocument("root_feed.json"); | 912 LoadRootFeedDocument("root_feed.json"); |
| 913 | 913 |
| 914 const FilePath kFilePath = FilePath(FILE_PATH_LITERAL("drive")); | 914 const FilePath kFilePath = FilePath(FILE_PATH_LITERAL("drive")); |
| 915 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync( | 915 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync( |
| 916 FilePath(FILE_PATH_LITERAL(kFilePath))); | 916 FilePath(FILE_PATH_LITERAL(kFilePath))); |
| 917 ASSERT_TRUE(entry.get()); | 917 ASSERT_TRUE(entry.get()); |
| 918 EXPECT_EQ(kGDataRootDirectoryResourceId, entry->resource_id()); | 918 EXPECT_EQ(kDriveRootDirectoryResourceId, entry->resource_id()); |
| 919 } | 919 } |
| 920 | 920 |
| 921 TEST_F(GDataFileSystemTest, SearchExistingFile) { | 921 TEST_F(GDataFileSystemTest, SearchExistingFile) { |
| 922 LoadRootFeedDocument("root_feed.json"); | 922 LoadRootFeedDocument("root_feed.json"); |
| 923 | 923 |
| 924 const FilePath kFilePath = FilePath( | 924 const FilePath kFilePath = FilePath( |
| 925 FILE_PATH_LITERAL("drive/File 1.txt")); | 925 FILE_PATH_LITERAL("drive/File 1.txt")); |
| 926 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); | 926 scoped_ptr<DriveEntryProto> entry = GetEntryInfoByPathSync(kFilePath); |
| 927 ASSERT_TRUE(entry.get()); | 927 ASSERT_TRUE(entry.get()); |
| 928 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); | 928 EXPECT_EQ("file:2_file_resource_id", entry->resource_id()); |
| (...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2404 "audio/mpeg", | 2404 "audio/mpeg", |
| 2405 _)) // callback | 2405 _)) // callback |
| 2406 .WillOnce(MockUploadExistingFile( | 2406 .WillOnce(MockUploadExistingFile( |
| 2407 GDATA_FILE_OK, | 2407 GDATA_FILE_OK, |
| 2408 FilePath::FromUTF8Unsafe("drive/File1"), | 2408 FilePath::FromUTF8Unsafe("drive/File1"), |
| 2409 dirty_cache_file_path, | 2409 dirty_cache_file_path, |
| 2410 document_entry)); | 2410 document_entry)); |
| 2411 | 2411 |
| 2412 // We'll notify the directory change to the observer upon completion. | 2412 // We'll notify the directory change to the observer upon completion. |
| 2413 EXPECT_CALL(*mock_directory_observer_, | 2413 EXPECT_CALL(*mock_directory_observer_, |
| 2414 OnDirectoryChanged(Eq(FilePath(kGDataRootDirectory)))).Times(1); | 2414 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); |
| 2415 | 2415 |
| 2416 // The callback will be called upon completion of | 2416 // The callback will be called upon completion of |
| 2417 // UpdateFileByResourceId(). | 2417 // UpdateFileByResourceId(). |
| 2418 FileOperationCallback callback = | 2418 FileOperationCallback callback = |
| 2419 base::Bind(&CallbackHelper::FileOperationCallback, | 2419 base::Bind(&CallbackHelper::FileOperationCallback, |
| 2420 callback_helper_.get()); | 2420 callback_helper_.get()); |
| 2421 | 2421 |
| 2422 // Check the number of files in the root directory. We'll compare the | 2422 // Check the number of files in the root directory. We'll compare the |
| 2423 // number after updating a file. | 2423 // number after updating a file. |
| 2424 scoped_ptr<DriveEntryProtoVector> root_directory_entries( | 2424 scoped_ptr<DriveEntryProtoVector> root_directory_entries( |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2539 test_util::RunBlockingPoolTask(); | 2539 test_util::RunBlockingPoolTask(); |
| 2540 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); | 2540 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); |
| 2541 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); | 2541 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); |
| 2542 } | 2542 } |
| 2543 | 2543 |
| 2544 TEST_F(GDataFileSystemTest, RequestDirectoryRefresh) { | 2544 TEST_F(GDataFileSystemTest, RequestDirectoryRefresh) { |
| 2545 LoadRootFeedDocument("root_feed.json"); | 2545 LoadRootFeedDocument("root_feed.json"); |
| 2546 | 2546 |
| 2547 // We'll fetch documents in the root directory with its resource ID. | 2547 // We'll fetch documents in the root directory with its resource ID. |
| 2548 EXPECT_CALL(*mock_drive_service_, | 2548 EXPECT_CALL(*mock_drive_service_, |
| 2549 GetDocuments(Eq(GURL()), _, _, kGDataRootDirectoryResourceId, _)) | 2549 GetDocuments(Eq(GURL()), _, _, kDriveRootDirectoryResourceId, _)) |
| 2550 .Times(1); | 2550 .Times(1); |
| 2551 // We'll notify the directory change to the observer. | 2551 // We'll notify the directory change to the observer. |
| 2552 EXPECT_CALL(*mock_directory_observer_, | 2552 EXPECT_CALL(*mock_directory_observer_, |
| 2553 OnDirectoryChanged(Eq(FilePath(kGDataRootDirectory)))).Times(1); | 2553 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); |
| 2554 | 2554 |
| 2555 file_system_->RequestDirectoryRefresh(FilePath(kGDataRootDirectory)); | 2555 file_system_->RequestDirectoryRefresh(FilePath(kDriveRootDirectory)); |
| 2556 test_util::RunBlockingPoolTask(); | 2556 test_util::RunBlockingPoolTask(); |
| 2557 } | 2557 } |
| 2558 | 2558 |
| 2559 TEST_F(GDataFileSystemTest, OpenAndCloseFile) { | 2559 TEST_F(GDataFileSystemTest, OpenAndCloseFile) { |
| 2560 LoadRootFeedDocument("root_feed.json"); | 2560 LoadRootFeedDocument("root_feed.json"); |
| 2561 | 2561 |
| 2562 OpenFileCallback callback = | 2562 OpenFileCallback callback = |
| 2563 base::Bind(&CallbackHelper::OpenFileCallback, | 2563 base::Bind(&CallbackHelper::OpenFileCallback, |
| 2564 callback_helper_.get()); | 2564 callback_helper_.get()); |
| 2565 FileOperationCallback close_file_callback = | 2565 FileOperationCallback close_file_callback = |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2640 | 2640 |
| 2641 // Try to close the same file twice. | 2641 // Try to close the same file twice. |
| 2642 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2642 file_system_->CloseFile(kFileInRoot, close_file_callback); |
| 2643 message_loop_.Run(); | 2643 message_loop_.Run(); |
| 2644 | 2644 |
| 2645 // It must fail. | 2645 // It must fail. |
| 2646 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2646 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 2647 } | 2647 } |
| 2648 | 2648 |
| 2649 } // namespace gdata | 2649 } // namespace gdata |
| OLD | NEW |