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

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

Issue 10836005: gdata: Periodic refresh should be active for file lists loaded from cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Typo fix. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <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 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // Loads serialized proto file from GCache, and makes sure the root 647 // Loads serialized proto file from GCache, and makes sure the root
648 // filesystem has a root at 'drive' 648 // filesystem has a root at 'drive'
649 void TestLoadMetadataFromCache() { 649 void TestLoadMetadataFromCache() {
650 file_system_->LoadRootFeedFromCacheForTesting(); 650 file_system_->LoadRootFeedFromCacheForTesting();
651 test_util::RunBlockingPoolTask(); 651 test_util::RunBlockingPoolTask();
652 } 652 }
653 653
654 // Creates a proto file representing a filesystem with directories: 654 // Creates a proto file representing a filesystem with directories:
655 // drive, drive/Dir1, drive/Dir1/SubDir2 655 // drive, drive/Dir1, drive/Dir1/SubDir2
656 // and files 656 // and files
657 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3 657 // drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3.
658 // Sets the changestamp to 654321, equal to that of "account_metadata.json"
659 // test data, indicating the cache is holding the latest file system info.
658 void SaveTestFileSystem() { 660 void SaveTestFileSystem() {
659 GDataRootDirectoryProto root; 661 GDataRootDirectoryProto root;
660 root.set_version(kProtoVersion); 662 root.set_version(kProtoVersion);
663 root.set_largest_changestamp(654321);
661 GDataDirectoryProto* root_dir = root.mutable_gdata_directory(); 664 GDataDirectoryProto* root_dir = root.mutable_gdata_directory();
662 GDataEntryProto* dir_base = root_dir->mutable_gdata_entry(); 665 GDataEntryProto* dir_base = root_dir->mutable_gdata_entry();
663 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info(); 666 PlatformFileInfoProto* platform_info = dir_base->mutable_file_info();
664 dir_base->set_title("drive"); 667 dir_base->set_title("drive");
665 dir_base->set_resource_id(kGDataRootDirectoryResourceId); 668 dir_base->set_resource_id(kGDataRootDirectoryResourceId);
666 dir_base->set_upload_url("http://resumable-create-media/1"); 669 dir_base->set_upload_url("http://resumable-create-media/1");
667 platform_info->set_is_directory(true); 670 platform_info->set_is_directory(true);
668 671
669 // drive/File1 672 // drive/File1
670 GDataEntryProto* file = root_dir->add_child_files(); 673 GDataEntryProto* file = root_dir->add_child_files();
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 TestLoadMetadataFromCache(); 1208 TestLoadMetadataFromCache();
1206 1209
1207 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); 1210 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1"))));
1208 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1")))); 1211 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1"))));
1209 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1/File2")))); 1212 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1/File2"))));
1210 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2")))); 1213 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2"))));
1211 EXPECT_TRUE(EntryExists( 1214 EXPECT_TRUE(EntryExists(
1212 FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3")))); 1215 FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3"))));
1213 } 1216 }
1214 1217
1218 TEST_F(GDataFileSystemTest, CachedFeadLoadingThenServerFeedLoading) {
1219 SaveTestFileSystem();
1220
1221 // SaveTestFileSystem and "account_metadata.json" have the same changestamp,
1222 // so no request for new feeds (i.e., call to GetDocuments) should happen.
1223 mock_doc_service_->set_account_metadata(
1224 LoadJSONFile("account_metadata.json"));
1225 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1);
1226 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1);
1227 EXPECT_CALL(*mock_doc_service_, GetDocuments(_, _, _, _, _)).Times(0);
1228
1229 // Kicks loading of cached file system and query for server update.
1230 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1"))));
1231
1232 // Since the file system has verified that it holds the latest snapshot,
1233 // it should change its state to FROM_SERVER, which admits periodic refresh.
1234 // To test it, call CheckForUpdates and verify it does try to check updates.
1235 mock_doc_service_->set_account_metadata(
1236 LoadJSONFile("account_metadata.json"));
1237 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1);
1238 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1);
1239
1240 file_system_->CheckForUpdates();
1241 test_util::RunBlockingPoolTask();
1242 }
1243
1215 TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { 1244 TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
1216 LoadRootFeedDocument("root_feed.json"); 1245 LoadRootFeedDocument("root_feed.json");
1217 1246
1218 // We'll add a file to the Drive root directory. 1247 // We'll add a file to the Drive root directory.
1219 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1248 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1220 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1249 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1221 1250
1222 FileOperationCallback callback = 1251 FileOperationCallback callback =
1223 base::Bind(&CallbackHelper::FileOperationCallback, 1252 base::Bind(&CallbackHelper::FileOperationCallback,
1224 callback_helper_.get()); 1253 callback_helper_.get());
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2556 2585
2557 // Try to close the same file twice. 2586 // Try to close the same file twice.
2558 file_system_->CloseFile(kFileInRoot, close_file_callback); 2587 file_system_->CloseFile(kFileInRoot, close_file_callback);
2559 message_loop_.Run(); 2588 message_loop_.Run();
2560 2589
2561 // It must fail. 2590 // It must fail.
2562 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2591 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2563 } 2592 }
2564 2593
2565 } // namespace gdata 2594 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.cc ('k') | chrome/browser/chromeos/gdata/mock_gdata_documents_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698