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

Unified Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 14838003: Try fast-fetch rather than full fetch if drive::FileSystem::GetEntryInfo failed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added (and fixed) tests. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/drive/file_system_unittest.cc
diff --git a/chrome/browser/chromeos/drive/file_system_unittest.cc b/chrome/browser/chromeos/drive/file_system_unittest.cc
index 27a029e2d5000feeb22b45791b40d78e15801472..d9595a7e4a3300f40dd5aa2f33ad923c352125bd 100644
--- a/chrome/browser/chromeos/drive/file_system_unittest.cc
+++ b/chrome/browser/chromeos/drive/file_system_unittest.cc
@@ -461,6 +461,10 @@ class DriveFileSystemTest : public testing::Test {
};
TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) {
+ // "Fast fetch" will fire an OnirectoryChanged event.
+ EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
+ Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
+
int counter = 0;
const GetEntryInfoCallback& callback = base::Bind(
&AsyncInitializationCallback, &counter, 2, &message_loop_);
@@ -475,8 +479,9 @@ TEST_F(DriveFileSystemTest, DuplicatedAsyncInitialization) {
// Although GetEntryInfoByPath() was called twice, the account metadata
// should only be loaded once. In the past, there was a bug that caused
// it to be loaded twice.
- EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
+ // See the comment in GetMyDriveRoot test case why this is 2.
+ EXPECT_EQ(2, fake_drive_service_->about_resource_load_count());
}
TEST_F(DriveFileSystemTest, GetGrandRootEntry) {
@@ -503,18 +508,25 @@ TEST_F(DriveFileSystemTest, GetOtherDirEntry) {
}
TEST_F(DriveFileSystemTest, GetMyDriveRoot) {
+ // "Fast fetch" will fire an OnirectoryChanged event.
+ EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
+ Eq(base::FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
+
const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root"));
scoped_ptr<ResourceEntry> entry = GetEntryInfoByPathSync(kFilePath);
ASSERT_TRUE(entry);
EXPECT_EQ(fake_drive_service_->GetRootResourceId(), entry->resource_id());
- // The changestamp should be propagated to the root directory.
- EXPECT_EQ(fake_drive_service_->largest_changestamp(),
- entry->directory_specific_info().changestamp());
+ // Absence of "drive/root" in the local metadata triggers the "fast fetch"
+ // of "drive" directory. Fetch of "drive" grand root directory has a special
+ // implementation. Instead of normal GetResourceListInDirectory(), it is
+ // emulated by calling GetAboutResource() so that the resource_id of
+ // "drive/root" is listed.
+ // Together with the normal GetAboutResource() call to retrieve the largest
+ // changestamp, the method is called twice.
+ EXPECT_EQ(2, fake_drive_service_->about_resource_load_count());
- // The resource load should happen because "My Drive"'s root is not the grand
- // root entry and hence does not present until the initial loading.
- EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
+ // After "fast fetch" is done, full resource list is fetched.
EXPECT_EQ(1, fake_drive_service_->resource_list_load_count());
}
@@ -891,6 +903,45 @@ TEST_F(DriveFileSystemTest, OfflineCachedFeedLoading) {
EXPECT_EQ(1, fake_drive_service_->change_list_load_count());
}
+TEST_F(DriveFileSystemTest, ReadDirectoryWhileRefreshing) {
+ EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
+ .Times(AtLeast(1));
+
+ // Enter the "refreshing" state.
satorux1 2013/05/07 06:29:45 Enter the "refreshing" state so the fast fetch wil
hashimoto 2013/05/07 06:49:01 Done for ReadDirectoryWhileRefreshing and GetEntry
+ ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP));
+ file_system_->CheckForUpdates();
+
+ // The list of resources in "drive/root/Dir1" should be fetched.
+ EXPECT_TRUE(ReadDirectoryByPathSync(base::FilePath(
+ FILE_PATH_LITERAL("drive/root/Dir1"))));
+ EXPECT_EQ(1, fake_drive_service_->directory_load_count());
+}
+
+TEST_F(DriveFileSystemTest, GetEntryInfoExistingWhileRefreshing) {
+ // Enter the "refreshing" state.
+ ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP));
+ file_system_->CheckForUpdates();
+
+ // If an entry is already found in local metadata, no directory fetch happens.
+ EXPECT_TRUE(GetEntryInfoByPathSync(base::FilePath(
+ FILE_PATH_LITERAL("drive/root/Dir1/File2"))));
+ EXPECT_EQ(0, fake_drive_service_->directory_load_count());
+}
+
+TEST_F(DriveFileSystemTest, GetEntryInfoNonExistentWhileRefreshing) {
+ EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(_))
+ .Times(AtLeast(1));
+
+ // Enter the "refreshing" state.
+ ASSERT_TRUE(SaveTestFileSystem(USE_OLD_TIMESTAMP));
+ file_system_->CheckForUpdates();
+
+ // If an entry is not found, parent directory's resource list is fetched.
+ EXPECT_FALSE(GetEntryInfoByPathSync(base::FilePath(
+ FILE_PATH_LITERAL("drive/root/Dir1/NonExistentFile"))));
+ EXPECT_EQ(1, fake_drive_service_->directory_load_count());
+}
+
TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
« chrome/browser/chromeos/drive/file_system.cc ('K') | « chrome/browser/chromeos/drive/file_system.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698