| 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 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 // Creates a proto file representing a filesystem with directories: | 615 // Creates a proto file representing a filesystem with directories: |
| 616 // drive, drive/Dir1, drive/Dir1/SubDir2 | 616 // drive, drive/Dir1, drive/Dir1/SubDir2 |
| 617 // and files | 617 // and files |
| 618 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. | 618 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3. |
| 619 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321, | 619 // If |use_up_to_date_timestamp| is true, sets the changestamp to 654321, |
| 620 // equal to that of "account_metadata.json" test data, indicating the cache is | 620 // equal to that of "account_metadata.json" test data, indicating the cache is |
| 621 // holding the latest file system info. | 621 // holding the latest file system info. |
| 622 void SaveTestFileSystem(SaveTestFileSystemParam param) { | 622 void SaveTestFileSystem(SaveTestFileSystemParam param) { |
| 623 DriveRootDirectoryProto root; | 623 DriveRootDirectoryProto root; |
| 624 root.set_version(kProtoVersion); | 624 root.set_version(kProtoVersion); |
| 625 root.set_largest_changestamp(param == USE_SERVER_TIMESTAMP ? 654321 : 0); | 625 root.set_largest_changestamp(param == USE_SERVER_TIMESTAMP ? 654321 : 1); |
| 626 DriveDirectoryProto* root_dir = root.mutable_drive_directory(); | 626 DriveDirectoryProto* root_dir = root.mutable_drive_directory(); |
| 627 DriveEntryProto* dir_base = root_dir->mutable_drive_entry(); | 627 DriveEntryProto* dir_base = root_dir->mutable_drive_entry(); |
| 628 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); | 628 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); |
| 629 dir_base->set_title("drive"); | 629 dir_base->set_title("drive"); |
| 630 dir_base->set_resource_id(kDriveRootDirectoryResourceId); | 630 dir_base->set_resource_id(kDriveRootDirectoryResourceId); |
| 631 dir_base->set_upload_url("http://resumable-create-media/1"); | 631 dir_base->set_upload_url("http://resumable-create-media/1"); |
| 632 platform_info->set_is_directory(true); | 632 platform_info->set_is_directory(true); |
| 633 | 633 |
| 634 // drive/File1 | 634 // drive/File1 |
| 635 DriveEntryProto* file = root_dir->add_child_files(); | 635 DriveEntryProto* file = root_dir->add_child_files(); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2")))); | 1188 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2")))); |
| 1189 EXPECT_TRUE(EntryExists( | 1189 EXPECT_TRUE(EntryExists( |
| 1190 FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3")))); | 1190 FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3")))); |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 TEST_F(DriveFileSystemTest, CachedFeedLoadingThenServerFeedLoading) { | 1193 TEST_F(DriveFileSystemTest, CachedFeedLoadingThenServerFeedLoading) { |
| 1194 SaveTestFileSystem(USE_SERVER_TIMESTAMP); | 1194 SaveTestFileSystem(USE_SERVER_TIMESTAMP); |
| 1195 | 1195 |
| 1196 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, | 1196 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, |
| 1197 // so no request for new feeds (i.e., call to GetDocuments) should happen. | 1197 // so no request for new feeds (i.e., call to GetDocuments) should happen. |
| 1198 mock_drive_service_->set_account_metadata( | 1198 // Account metadata is already set up in MockDriveService's constructor. |
| 1199 google_apis::test_util::LoadJSONFile( | |
| 1200 "gdata/account_metadata.json").release()); | |
| 1201 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); | 1199 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); |
| 1202 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); | 1200 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
| 1203 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)).Times(0); | 1201 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)).Times(0); |
| 1204 | 1202 |
| 1205 // Kicks loading of cached file system and query for server update. | 1203 // Kicks loading of cached file system and query for server update. |
| 1206 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); | 1204 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); |
| 1207 | 1205 |
| 1208 // Since the file system has verified that it holds the latest snapshot, | 1206 // Since the file system has verified that it holds the latest snapshot, |
| 1209 // it should change its state to INITIALIZED, which admits periodic refresh. | 1207 // it should change its state to INITIALIZED, which admits periodic refresh. |
| 1210 // To test it, call CheckForUpdates and verify it does try to check updates. | 1208 // To test it, call CheckForUpdates and verify it does try to check updates. |
| 1211 mock_drive_service_->set_account_metadata( | 1209 mock_drive_service_->set_account_metadata( |
| 1212 google_apis::test_util::LoadJSONFile( | 1210 google_apis::test_util::LoadJSONFile( |
| 1213 "gdata/account_metadata.json").release()); | 1211 "gdata/account_metadata.json").release()); |
| 1214 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); | 1212 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); |
| 1215 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); | 1213 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
| 1216 | 1214 |
| 1217 file_system_->CheckForUpdates(); | 1215 file_system_->CheckForUpdates(); |
| 1218 google_apis::test_util::RunBlockingPoolTask(); | 1216 google_apis::test_util::RunBlockingPoolTask(); |
| 1219 } | 1217 } |
| 1220 | 1218 |
| 1221 TEST_F(DriveFileSystemTest, OfflineCachedFeedLoading) { | 1219 TEST_F(DriveFileSystemTest, OfflineCachedFeedLoading) { |
| 1222 SaveTestFileSystem(USE_OLD_TIMESTAMP); | 1220 SaveTestFileSystem(USE_OLD_TIMESTAMP); |
| 1223 | 1221 |
| 1224 mock_drive_service_->set_account_metadata( | 1222 // Account metadata is already set up in MockDriveService's constructor. |
| 1225 google_apis::test_util::LoadJSONFile( | |
| 1226 "gdata/account_metadata.json").release()); | |
| 1227 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); | 1223 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); |
| 1228 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); | 1224 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
| 1229 | 1225 |
| 1230 // Make GetDocuments fail for simulating offline situation. This will leave | 1226 // Make GetDocuments fail for simulating offline situation. This will leave |
| 1231 // the file system "loaded from cache, but not synced with server" state. | 1227 // the file system "loaded from cache, but not synced with server" state. |
| 1232 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)) | 1228 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)) |
| 1233 .WillOnce(MockFailingGetDocuments()); | 1229 .WillOnce(MockFailingGetDocuments()); |
| 1234 | 1230 |
| 1235 // Kicks loading of cached file system and query for server update. | 1231 // Kicks loading of cached file system and query for server update. |
| 1236 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); | 1232 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); |
| 1237 | 1233 |
| 1238 // Since the file system has at least succeeded to load cached snapshot, | 1234 // Since the file system has at least succeeded to load cached snapshot, |
| 1239 // the file system should be able to start periodic refresh. | 1235 // the file system should be able to start periodic refresh. |
| 1240 // To test it, call CheckForUpdates and verify it does try to check updates. | 1236 // To test it, call CheckForUpdates and verify it does try to check updates. |
| 1241 mock_drive_service_->set_account_metadata( | 1237 mock_drive_service_->set_account_metadata( |
| 1242 google_apis::test_util::LoadJSONFile( | 1238 google_apis::test_util::LoadJSONFile( |
| 1243 "gdata/account_metadata.json").release()); | 1239 "gdata/account_metadata.json").release()); |
| 1244 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); | 1240 EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1); |
| 1245 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); | 1241 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
| 1246 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)).Times(1); | 1242 EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)).Times(1); |
| 1247 | 1243 |
| 1248 file_system_->CheckForUpdates(); | 1244 file_system_->CheckForUpdates(); |
| 1245 // Expected value from reading gdata/basic_feed.json. |
| 1246 // See MockDriveService's |feed_data_|. |
| 1247 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_)).Times(2); |
| 1248 |
| 1249 google_apis::test_util::RunBlockingPoolTask(); | 1249 google_apis::test_util::RunBlockingPoolTask(); |
| 1250 } | 1250 } |
| 1251 | 1251 |
| 1252 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { | 1252 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { |
| 1253 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) | 1253 EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace()) |
| 1254 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); | 1254 .Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace)); |
| 1255 | 1255 |
| 1256 LoadRootFeedDocument("gdata/root_feed.json"); | 1256 LoadRootFeedDocument("gdata/root_feed.json"); |
| 1257 | 1257 |
| 1258 // We'll add a file to the Drive root directory. | 1258 // We'll add a file to the Drive root directory. |
| (...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2670 | 2670 |
| 2671 // Try to close the same file twice. | 2671 // Try to close the same file twice. |
| 2672 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2672 file_system_->CloseFile(kFileInRoot, close_file_callback); |
| 2673 message_loop_.Run(); | 2673 message_loop_.Run(); |
| 2674 | 2674 |
| 2675 // It must fail. | 2675 // It must fail. |
| 2676 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2676 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 2677 } | 2677 } |
| 2678 | 2678 |
| 2679 } // namespace drive | 2679 } // namespace drive |
| OLD | NEW |