#include <vector>
#include "base/bind.h"
-#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "chrome/browser/chromeos/drive/change_list_loader.h"
#include "chrome/browser/chromeos/drive/drive.pb.h"
#include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
+#include "chrome/browser/chromeos/drive/file_change.h"
#include "chrome/browser/chromeos/drive/file_system_observer.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/job_scheduler.h"
changed_directories_.push_back(directory_path);
}
+ virtual void OnFileChanged(const FileChange& new_file_change) OVERRIDE {
+ changed_files_.Apply(new_file_change);
+ }
+
const std::vector<base::FilePath>& changed_directories() const {
return changed_directories_;
}
+ const FileChange& changed_files() const { return changed_files_; }
+
private:
std::vector<base::FilePath> changed_directories_;
+ FileChange changed_files_;
DISALLOW_COPY_AND_ASSIGN(MockDirectoryChangeObserver);
};
FileError error = FILE_ERROR_FAILED;
file_system_->change_list_loader_for_testing()->LoadIfNeeded(
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
return error == FILE_ERROR_OK;
}
file_system_->GetResourceEntry(
file_path,
google_apis::test_util::CreateCopyResultCallback(&error, &entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
return entry.Pass();
}
file_path,
base::Bind(&AccumulateReadDirectoryResult, entries.get()),
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
if (error != FILE_ERROR_OK)
entries.reset();
return entries.Pass();
dest_file_path,
false, // preserve_last_modified,
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Entry is added on the server.
fake_drive_service_->GetFileResource(
entry->resource_id(),
google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
ASSERT_TRUE(server_entry);
EXPECT_EQ(entry->title(), server_entry->title());
file_system_->Move(src_file_path,
dest_file_path,
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Entry is moved on the server.
fake_drive_service_->GetFileResource(
entry->resource_id(),
google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
ASSERT_TRUE(server_entry);
EXPECT_EQ(entry->title(), server_entry->title());
file_path,
false, // is_resursive
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Entry is removed on the server.
fake_drive_service_->GetFileResource(
entry->resource_id(),
google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
ASSERT_TRUE(server_entry);
EXPECT_TRUE(server_entry->labels().is_trashed());
true, // is_exclusive
false, // is_recursive
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Directory is created on the server.
fake_drive_service_->GetFileResource(
entry->resource_id(),
google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
ASSERT_TRUE(server_entry);
EXPECT_EQ(entry->title(), server_entry->title());
true, // is_exclusive
"text/plain",
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// File is created on the server.
fake_drive_service_->GetFileResource(
entry->resource_id(),
google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
ASSERT_TRUE(server_entry);
EXPECT_EQ(entry->title(), server_entry->title());
last_accessed,
last_modified,
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// File is touched on the server.
fake_drive_service_->GetFileResource(
entry->resource_id(),
google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
ASSERT_TRUE(server_entry);
EXPECT_EQ(last_accessed, server_entry->last_viewed_by_me_date());
file_path,
kLength,
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// File is touched on the server.
fake_drive_service_->GetFileResource(
entry->resource_id(),
google_apis::test_util::CreateCopyResultCallback(&status, &server_entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
ASSERT_TRUE(server_entry);
EXPECT_EQ(kLength, server_entry->file_size());
FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(kFilePath);
ASSERT_TRUE(entry);
- EXPECT_EQ("file:subdirectory_file_1_id", entry->resource_id());
+ EXPECT_EQ("subdirectory_file_1_id", entry->resource_id());
EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
EXPECT_EQ(2, fake_drive_service_->directory_load_count());
FILE_PATH_LITERAL("drive/root/Document 1 excludeDir-test.gdoc"));
scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(kFilePath);
ASSERT_TRUE(entry);
- EXPECT_EQ("document:5_document_resource_id", entry->resource_id());
+ EXPECT_EQ("5_document_resource_id", entry->resource_id());
}
TEST_F(FileSystemTest, GetNonExistingFile) {
"Sub Sub Directory Folder"));
scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(kFilePath);
ASSERT_TRUE(entry);
- ASSERT_EQ("folder:sub_sub_directory_folder_id", entry->resource_id());
+ ASSERT_EQ("sub_sub_directory_folder_id", entry->resource_id());
}
TEST_F(FileSystemTest, GetOrphanFile) {
FILE_PATH_LITERAL("drive/other/Orphan File 1.txt"));
scoped_ptr<ResourceEntry> entry = GetResourceEntrySync(kFilePath);
ASSERT_TRUE(entry);
- EXPECT_EQ("file:1_orphanfile_resource_id", entry->resource_id());
+ EXPECT_EQ("1_orphanfile_resource_id", entry->resource_id());
}
TEST_F(FileSystemTest, ReadDirectory_Root) {
const int about_resource_load_count_before =
fake_drive_service_->about_resource_load_count();
file_system_->CheckForUpdates();
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_LT(about_resource_load_count_before,
fake_drive_service_->about_resource_load_count());
}
file_system_->CheckForUpdates();
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
EXPECT_EQ(1, fake_drive_service_->change_list_load_count());
- ASSERT_LE(1u, mock_directory_observer_->changed_directories().size());
+ ASSERT_LE(0u, mock_directory_observer_->changed_directories().size());
+ ASSERT_LE(1u, mock_directory_observer_->changed_files().size());
}
TEST_F(FileSystemTest, ReadDirectoryWhileRefreshing) {
true, // is_exclusive
false, // is_recursive
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
// It should fail because is_exclusive is set to true.
EXPECT_EQ(FILE_ERROR_EXISTS, error);
true, // is_exclusive
true, // is_recursive
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_TRUE(entry->file_info().is_directory());
}
+TEST_F(FileSystemTest, ReadDirectoryAfterUpdateWhileLoading) {
+ // Simulate the situation that full feed fetching takes very long time,
+ // to test the recursive "fast fetch" feature is properly working.
+ fake_drive_service_->set_never_return_all_file_list(true);
+
+ // On the fake server, create the test directory.
+ scoped_ptr<google_apis::FileResource> parent;
+ {
+ google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
+ fake_drive_service_->AddNewDirectory(
+ fake_drive_service_->GetRootResourceId(),
+ "UpdateWhileLoadingTestDir",
+ DriveServiceInterface::AddNewDirectoryOptions(),
+ google_apis::test_util::CreateCopyResultCallback(&error, &parent));
+ base::RunLoop().RunUntilIdle();
+ ASSERT_EQ(google_apis::HTTP_CREATED, error);
+ }
+
+ // Fetch the directory. Currently it is empty.
+ scoped_ptr<ResourceEntryVector> before = ReadDirectorySync(base::FilePath(
+ FILE_PATH_LITERAL("drive/root/UpdateWhileLoadingTestDir")));
+ ASSERT_TRUE(before);
+ EXPECT_EQ(0u, before->size());
+
+ // Create a file in the test directory.
+ scoped_ptr<google_apis::FileResource> entry;
+ {
+ google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
+ fake_drive_service_->AddNewFile(
+ "text/plain",
+ "(dummy data)",
+ parent->file_id(),
+ "TestFile",
+ false, // shared_with_me
+ google_apis::test_util::CreateCopyResultCallback(&error, &entry));
+ base::RunLoop().RunUntilIdle();
+ ASSERT_EQ(google_apis::HTTP_CREATED, error);
+ }
+
+ // Notify the update to the file system.
+ file_system_->CheckForUpdates();
+
+ // Read the directory once again. Although the full feed fetching is not yet
+ // finished, the "fast fetch" of the directory works and the refreshed content
+ // is returned.
+ scoped_ptr<ResourceEntryVector> after = ReadDirectorySync(base::FilePath(
+ FILE_PATH_LITERAL("drive/root/UpdateWhileLoadingTestDir")));
+ ASSERT_TRUE(after);
+ EXPECT_EQ(1u, after->size());
+}
+
TEST_F(FileSystemTest, PinAndUnpin) {
ASSERT_TRUE(LoadFullResourceList());
FileError error = FILE_ERROR_FAILED;
file_system_->Pin(file_path,
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
entry = GetResourceEntrySync(file_path);
error = FILE_ERROR_FAILED;
file_system_->Unpin(file_path,
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
entry = GetResourceEntrySync(file_path);
EXPECT_FALSE(entry->file_specific_info().cache_state().is_pinned());
// Pinned file gets synced and it results in entry state changes.
- ASSERT_EQ(1u, mock_directory_observer_->changed_directories().size());
- EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("drive/root")),
- mock_directory_observer_->changed_directories()[0]);
+ ASSERT_EQ(0u, mock_directory_observer_->changed_directories().size());
+ ASSERT_EQ(1u, mock_directory_observer_->changed_files().size());
+ EXPECT_EQ(1u,
+ mock_directory_observer_->changed_files().CountDirectory(
+ base::FilePath(FILE_PATH_LITERAL("drive/root"))));
}
TEST_F(FileSystemTest, PinAndUnpin_NotSynced) {
file_path,
google_apis::test_util::CreateCopyResultCallback(&error_unpin));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error_pin);
EXPECT_EQ(FILE_ERROR_OK, error_unpin);
file_system_->GetAvailableSpace(
google_apis::test_util::CreateCopyResultCallback(
&error, &bytes_total, &bytes_used));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(6789012345LL, bytes_used);
EXPECT_EQ(9876543210LL, bytes_total);
}
file_in_root,
google_apis::test_util::CreateCopyResultCallback(
&error, &file_path, &entry));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Test for mounting.
file_system_->MarkCacheFileAsMounted(
file_in_root,
google_apis::test_util::CreateCopyResultCallback(&error, &file_path));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Cannot remove a cache entry while it's being mounted.
file_system_->MarkCacheFileAsUnmounted(
file_path,
google_apis::test_util::CreateCopyResultCallback(&error));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Now able to remove the cache entry.
kFileInRoot,
kEmbedOrigin,
google_apis::test_util::CreateCopyResultCallback(&error, &share_url));
- test_util::RunBlockingPoolTask();
+ content::RunAllBlockingPoolTasksUntilIdle();
// Verify the share url to the sharing dialog.
EXPECT_EQ(FILE_ERROR_OK, error);