Skip to content

Commit

Permalink
gdata: Periodic refresh should be active for file lists loaded from c…
Browse files Browse the repository at this point in the history
…ache.

BUG=139561
TEST=manually tested that a file addition outside the Chromebook is reflected.

Review URL: https://chromiumcodereview.appspot.com/10836005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149343 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kinaba@chromium.org committed Aug 1, 2012
1 parent fb792f3 commit 8d3d7ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 4 additions & 1 deletion chrome/browser/chromeos/gdata/gdata_file_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,10 @@ void GDataFileSystem::OnGetAccountMetadata(
<< ", server = "
<< account_metadata->largest_changestamp();
}
directory_service_->set_origin(initial_origin);
// If our cache holds the latest state from the server, change the
// state to FROM_SERVER.
directory_service_->set_origin(
initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin);
changes_detected = false;
}

Expand Down
31 changes: 30 additions & 1 deletion chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,13 @@ class GDataFileSystemTest : public testing::Test {
// Creates a proto file representing a filesystem with directories:
// drive, drive/Dir1, drive/Dir1/SubDir2
// and files
// drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3
// drive/File1, drive/Dir1/File2, drive/Dir1/SubDir2/File3.
// Sets the changestamp to 654321, equal to that of "account_metadata.json"
// test data, indicating the cache is holding the latest file system info.
void SaveTestFileSystem() {
GDataRootDirectoryProto root;
root.set_version(kProtoVersion);
root.set_largest_changestamp(654321);
GDataDirectoryProto* root_dir = root.mutable_gdata_directory();
GDataEntryProto* dir_base = root_dir->mutable_gdata_entry();
PlatformFileInfoProto* platform_info = dir_base->mutable_file_info();
Expand Down Expand Up @@ -1211,6 +1214,32 @@ TEST_F(GDataFileSystemTest, CachedFeedLoading) {
FilePath(FILE_PATH_LITERAL("drive/Dir1/SubDir2/File3"))));
}

TEST_F(GDataFileSystemTest, CachedFeadLoadingThenServerFeedLoading) {
SaveTestFileSystem();

// SaveTestFileSystem and "account_metadata.json" have the same changestamp,
// so no request for new feeds (i.e., call to GetDocuments) should happen.
mock_doc_service_->set_account_metadata(
LoadJSONFile("account_metadata.json"));
EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1);
EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1);
EXPECT_CALL(*mock_doc_service_, GetDocuments(_, _, _, _, _)).Times(0);

// Kicks loading of cached file system and query for server update.
EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1"))));

// Since the file system has verified that it holds the latest snapshot,
// it should change its state to FROM_SERVER, which admits periodic refresh.
// To test it, call CheckForUpdates and verify it does try to check updates.
mock_doc_service_->set_account_metadata(
LoadJSONFile("account_metadata.json"));
EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1);
EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1);

file_system_->CheckForUpdates();
test_util::RunBlockingPoolTask();
}

TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
LoadRootFeedDocument("root_feed.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class MockDocumentsService : public DocumentsServiceInterface {
MOCK_CONST_METHOD0(HasRefreshToken, bool());

void set_account_metadata(base::Value* account_metadata) {
feed_data_.reset(account_metadata);
account_metadata_.reset(account_metadata);
}

void set_feed_data(base::Value* feed_data) {
Expand Down

0 comments on commit 8d3d7ea

Please sign in to comment.