diff options
-rw-r--r-- | chrome/browser/chromeos/drive/change_list_loader.cc | 60 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/change_list_loader.h | 27 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/change_list_processor_unittest.cc | 186 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/file_system_unittest.cc | 237 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/test_util.cc | 37 | ||||
-rw-r--r-- | chrome/browser/chromeos/drive/test_util.h | 12 |
6 files changed, 221 insertions, 338 deletions
diff --git a/chrome/browser/chromeos/drive/change_list_loader.cc b/chrome/browser/chromeos/drive/change_list_loader.cc index d699ba7..9af0783 100644 --- a/chrome/browser/chromeos/drive/change_list_loader.cc +++ b/chrome/browser/chromeos/drive/change_list_loader.cc @@ -113,36 +113,6 @@ void ChangeListLoader::LoadDirectoryFromServer( callback)); } -void ChangeListLoader::UpdateFromChangeList( - scoped_ptr<google_apis::AboutResource> about_resource, - ScopedVector<ChangeList> change_lists, - bool is_delta_update, - const base::Closure& callback) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - DCHECK(!callback.is_null()); - - ChangeListProcessor* change_list_processor = - new ChangeListProcessor(resource_metadata_); - // Don't send directory content change notification while performing - // the initial content retrieval. - const bool should_notify_changed_directories = is_delta_update; - - util::Log("Apply change lists (is delta: %d)", is_delta_update); - blocking_task_runner_->PostTaskAndReply( - FROM_HERE, - base::Bind(&ChangeListProcessor::Apply, - base::Unretained(change_list_processor), - base::Passed(&about_resource), - base::Passed(&change_lists), - is_delta_update), - base::Bind(&ChangeListLoader::UpdateFromChangeListAfterApply, - weak_ptr_factory_.GetWeakPtr(), - base::Owned(change_list_processor), - should_notify_changed_directories, - base::Time::Now(), - callback)); -} - void ChangeListLoader::Load(const DirectoryFetchInfo& directory_fetch_info, const FileOperationCallback& callback) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -681,6 +651,36 @@ void ChangeListLoader::DoLoadDirectoryFromServerAfterRefresh( } } +void ChangeListLoader::UpdateFromChangeList( + scoped_ptr<google_apis::AboutResource> about_resource, + ScopedVector<ChangeList> change_lists, + bool is_delta_update, + const base::Closure& callback) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(!callback.is_null()); + + ChangeListProcessor* change_list_processor = + new ChangeListProcessor(resource_metadata_); + // Don't send directory content change notification while performing + // the initial content retrieval. + const bool should_notify_changed_directories = is_delta_update; + + util::Log("Apply change lists (is delta: %d)", is_delta_update); + blocking_task_runner_->PostTaskAndReply( + FROM_HERE, + base::Bind(&ChangeListProcessor::Apply, + base::Unretained(change_list_processor), + base::Passed(&about_resource), + base::Passed(&change_lists), + is_delta_update), + base::Bind(&ChangeListLoader::UpdateFromChangeListAfterApply, + weak_ptr_factory_.GetWeakPtr(), + base::Owned(change_list_processor), + should_notify_changed_directories, + base::Time::Now(), + callback)); +} + void ChangeListLoader::UpdateFromChangeListAfterApply( ChangeListProcessor* change_list_processor, bool should_notify_changed_directories, diff --git a/chrome/browser/chromeos/drive/change_list_loader.h b/chrome/browser/chromeos/drive/change_list_loader.h index 6e93dbd..6845a04 100644 --- a/chrome/browser/chromeos/drive/change_list_loader.h +++ b/chrome/browser/chromeos/drive/change_list_loader.h @@ -106,19 +106,6 @@ class ChangeListLoader { void LoadDirectoryFromServer(const std::string& directory_resource_id, const FileOperationCallback& callback); - // TODO(satorux): Make this private. crbug.com/232208 - // Updates from the whole change list collected in |change_lists|. - // Record file statistics as UMA histograms. - // - // See comments at ChangeListProcessor::ApplyFeeds() for - // |about_resource| and |is_delta_update|. - // |callback| must not be null. - void UpdateFromChangeList( - scoped_ptr<google_apis::AboutResource> about_resource, - ScopedVector<ChangeList> change_lists, - bool is_delta_update, - const base::Closure& callback); - private: // Starts the resource metadata loading and calls |callback| when it's // done. |directory_fetch_info| is used for fast fetch. If there is already @@ -265,8 +252,20 @@ class ChangeListLoader { google_apis::GDataErrorCode status, scoped_ptr<google_apis::ResourceList> resource_list); + // Updates from the whole change list collected in |change_lists|. + // Record file statistics as UMA histograms. + // + // See comments at ChangeListProcessor::Apply() for + // |about_resource| and |is_delta_update|. + // |callback| must not be null. + void UpdateFromChangeList( + scoped_ptr<google_apis::AboutResource> about_resource, + ScopedVector<ChangeList> change_lists, + bool is_delta_update, + const base::Closure& callback); + // Part of UpdateFromChangeList(). - // Called when ChangeListProcessor::ApplyFeeds() is complete. + // Called when ChangeListProcessor::Apply() is complete. // Notifies directory changes per the result of the change list processing. void UpdateFromChangeListAfterApply( ChangeListProcessor* change_list_processor, diff --git a/chrome/browser/chromeos/drive/change_list_processor_unittest.cc b/chrome/browser/chromeos/drive/change_list_processor_unittest.cc index b488c77..35c3553 100644 --- a/chrome/browser/chromeos/drive/change_list_processor_unittest.cc +++ b/chrome/browser/chromeos/drive/change_list_processor_unittest.cc @@ -95,9 +95,9 @@ class ChangeListProcessorTest : public testing::Test { google_apis::test_util::RunBlockingPoolTask(); } - // Applies the |changes| to |metadata_| as a delta update. Delta changeslists + // Applies the |changes| to |metadata_| as a delta update. Delta changelists // should contain their changestamp in themselves. - void ApplyChangeList(ScopedVector<ChangeList> changes) { + std::set<base::FilePath> ApplyChangeList(ScopedVector<ChangeList> changes) { scoped_ptr<google_apis::AboutResource> null_about_resource; ChangeListProcessor processor(metadata_.get()); @@ -109,6 +109,7 @@ class ChangeListProcessorTest : public testing::Test { base::Passed(&changes), true)); // is_delta_update google_apis::test_util::RunBlockingPoolTask(); + return processor.changed_dirs(); } // Gets the resource entry for the path from |metadata_| synchronously. @@ -233,12 +234,19 @@ TEST_F(ChangeListProcessorTest, DeltaFileAddedInNewDirectory) { // Apply the changelist and check the effect. ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); - ApplyChangeList(ParseChangeList(kTestJson)); + std::set<base::FilePath> changed_dirs = + ApplyChangeList(ParseChangeList(kTestJson)); EXPECT_EQ(16730, GetChangestamp()); // the value is written in kTestJson. EXPECT_TRUE(GetResourceEntry("drive/root/New Directory")); EXPECT_TRUE(GetResourceEntry( "drive/root/New Directory/File in new dir.gdoc")); + + EXPECT_EQ(2U, changed_dirs.size()); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root"))); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root/New Directory"))); } TEST_F(ChangeListProcessorTest, DeltaDirMovedFromRootToDirectory) { @@ -260,12 +268,25 @@ TEST_F(ChangeListProcessorTest, DeltaDirMovedFromRootToDirectory) { // Apply the changelist and check the effect. ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); - ApplyChangeList(ParseChangeList(kTestJson)); + std::set<base::FilePath> changed_dirs = + ApplyChangeList(ParseChangeList(kTestJson)); EXPECT_EQ(16809, GetChangestamp()); // the value is written in kTestJson. EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1")); EXPECT_TRUE(GetResourceEntry( "drive/root/Directory 2 excludeDir-test/Directory 1")); + + EXPECT_EQ(4U, changed_dirs.size()); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root"))); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe( + "drive/root/Directory 2 excludeDir-test"))); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe( + "drive/root/Directory 2 excludeDir-test/Directory 1"))); } TEST_F(ChangeListProcessorTest, DeltaFileMovedFromDirectoryToRoot) { @@ -288,12 +309,19 @@ TEST_F(ChangeListProcessorTest, DeltaFileMovedFromDirectoryToRoot) { // Apply the changelist and check the effect. ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); - ApplyChangeList(ParseChangeList(kTestJson)); + std::set<base::FilePath> changed_dirs = + ApplyChangeList(ParseChangeList(kTestJson)); EXPECT_EQ(16815, GetChangestamp()); // the value is written in kTestJson. EXPECT_FALSE(GetResourceEntry( "drive/root/Directory 1/SubDirectory File 1.txt")); EXPECT_TRUE(GetResourceEntry("drive/root/SubDirectory File 1.txt")); + + EXPECT_EQ(2U, changed_dirs.size()); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root"))); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); } TEST_F(ChangeListProcessorTest, DeltaFileRenamedInDirectory) { @@ -317,17 +345,159 @@ TEST_F(ChangeListProcessorTest, DeltaFileRenamedInDirectory) { // Apply the changelist and check the effect. ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); - ApplyChangeList(ParseChangeList(kTestJson)); + std::set<base::FilePath> changed_dirs = + ApplyChangeList(ParseChangeList(kTestJson)); EXPECT_EQ(16767, GetChangestamp()); // the value is written in kTestJson. EXPECT_FALSE(GetResourceEntry( "drive/root/Directory 1/SubDirectory File 1.txt")); EXPECT_TRUE(GetResourceEntry( "drive/root/Directory 1/New SubDirectory File 1.txt")); + + EXPECT_EQ(2U, changed_dirs.size()); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root"))); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); +} + +TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileInRoot) { + const char kTestJsonAdd[] = + "chromeos/gdata/delta_file_added_in_root.json"; + const char kTestJsonDelete[] = + "chromeos/gdata/delta_file_deleted_in_root.json"; + + const std::string kParentId("fake_root"); + const std::string kFileId("document:added_in_root_id"); + + ChangeListProcessor::ResourceEntryMap entry_map; + + // Check the content of kTestJsonAdd. + ChangeListProcessor::ConvertToMap( + ParseChangeList(kTestJsonAdd), &entry_map, NULL); + EXPECT_EQ(1U, entry_map.size()); + EXPECT_TRUE(entry_map.count(kFileId)); + EXPECT_EQ(kParentId, entry_map[kFileId].parent_resource_id()); + EXPECT_EQ("Added file", entry_map[kFileId].title()); + EXPECT_FALSE(entry_map[kFileId].deleted()); + + // Apply. + ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); + std::set<base::FilePath> changed_dirs = + ApplyChangeList(ParseChangeList(kTestJsonAdd)); + EXPECT_EQ(16683, GetChangestamp()); + EXPECT_TRUE(GetResourceEntry("drive/root/Added file.gdoc")); + EXPECT_EQ(1U, changed_dirs.size()); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root"))); + + // Check the content of kTestJsonDelete. + entry_map.clear(); + ChangeListProcessor::ConvertToMap( + ParseChangeList(kTestJsonDelete), &entry_map, NULL); + EXPECT_EQ(1U, entry_map.size()); + EXPECT_TRUE(entry_map.count(kFileId)); + EXPECT_EQ(kParentId, entry_map[kFileId].parent_resource_id()); + EXPECT_EQ("Added file", entry_map[kFileId].title()); + EXPECT_TRUE(entry_map[kFileId].deleted()); + + // Apply. + changed_dirs = ApplyChangeList(ParseChangeList(kTestJsonDelete)); + EXPECT_EQ(16687, GetChangestamp()); + EXPECT_FALSE(GetResourceEntry("drive/root/Added file.gdoc")); + EXPECT_EQ(1U, changed_dirs.size()); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root"))); +} + + +TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileFromExistingDirectory) { + const char kTestJsonAdd[] = + "chromeos/gdata/delta_file_added_in_directory.json"; + const char kTestJsonDelete[] = + "chromeos/gdata/delta_file_deleted_in_directory.json"; + + const std::string kParentId("folder:1_folder_resource_id"); + const std::string kFileId("document:added_in_root_id"); + + ChangeListProcessor::ResourceEntryMap entry_map; + + // Check the content of kTestJsonAdd. + ChangeListProcessor::ConvertToMap( + ParseChangeList(kTestJsonAdd), &entry_map, NULL); + EXPECT_EQ(2U, entry_map.size()); + EXPECT_TRUE(entry_map.count(kFileId)); + EXPECT_TRUE(entry_map.count(kParentId)); + EXPECT_EQ(kParentId, entry_map[kFileId].parent_resource_id()); + EXPECT_EQ("Added file", entry_map[kFileId].title()); + EXPECT_FALSE(entry_map[kFileId].deleted()); + + // Apply. + ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); + std::set<base::FilePath> changed_dirs = + ApplyChangeList(ParseChangeList(kTestJsonAdd)); + EXPECT_EQ(16730, GetChangestamp()); + EXPECT_TRUE(GetResourceEntry("drive/root/Directory 1/Added file.gdoc")); + + EXPECT_EQ(2U, changed_dirs.size()); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root"))); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); + + // Check the content of kTestJsonDelete. + entry_map.clear(); + ChangeListProcessor::ConvertToMap( + ParseChangeList(kTestJsonDelete), &entry_map, NULL); + EXPECT_EQ(1U, entry_map.size()); + EXPECT_TRUE(entry_map.count(kFileId)); + EXPECT_EQ(kParentId, entry_map[kFileId].parent_resource_id()); + EXPECT_EQ("Added file", entry_map[kFileId].title()); + EXPECT_TRUE(entry_map[kFileId].deleted()); + + // Apply. + changed_dirs = ApplyChangeList(ParseChangeList(kTestJsonDelete)); + EXPECT_EQ(16770, GetChangestamp()); + EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1/Added file.gdoc")); + + EXPECT_EQ(1U, changed_dirs.size()); + EXPECT_TRUE(changed_dirs.count( + base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); } -// TODO(kinaba): add test for all patterns in test/data/chromeos/gdata -// http://crbug.com/147728. +TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) { + // This feed contains the following updates: + // 1) A new PDF file is added to a new directory + // 2) but the new directory is marked "deleted" (i.e. moved to Trash) + // Hence, the PDF file should be just ignored. + const char kTestJson[] = + "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json"; + + ChangeListProcessor::ResourceEntryMap entry_map; + ChangeListProcessor::ConvertToMap( + ParseChangeList(kTestJson), &entry_map, NULL); + + const std::string kRootId("fake_root"); + const std::string kDirId("folder:new_folder_resource_id"); + const std::string kFileId("pdf:file_added_in_deleted_dir_id"); + + // Check the content of parsed ResourceEntryMap. + EXPECT_EQ(2U, entry_map.size()); + EXPECT_TRUE(entry_map.count(kDirId)); + EXPECT_TRUE(entry_map.count(kFileId)); + EXPECT_EQ(kDirId, entry_map[kFileId].parent_resource_id()); + EXPECT_TRUE(entry_map[kDirId].deleted()); + + // Apply the changelist and check the effect. + ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); + std::set<base::FilePath> changed_dirs = + ApplyChangeList(ParseChangeList(kTestJson)); + + EXPECT_EQ(16730, GetChangestamp()); // the value is written in kTestJson. + EXPECT_FALSE(GetResourceEntry("drive/root/New Directory/new_pdf_file.pdf")); + + EXPECT_TRUE(changed_dirs.empty()); +} } // namespace internal } // namespace drive diff --git a/chrome/browser/chromeos/drive/file_system_unittest.cc b/chrome/browser/chromeos/drive/file_system_unittest.cc index ec29ab34..674151f 100644 --- a/chrome/browser/chromeos/drive/file_system_unittest.cc +++ b/chrome/browser/chromeos/drive/file_system_unittest.cc @@ -146,19 +146,6 @@ class FileSystemTest : public testing::Test { return error == FILE_ERROR_OK; } - bool LoadChangeFeed(const std::string& filename) { - if (!test_util::LoadChangeFeed(filename, - file_system_->change_list_loader(), - true, // is_delta_feed - fake_drive_service_->GetRootResourceId(), - root_feed_changestamp_)) { - return false; - } - root_feed_changestamp_++; - return true; - } - - // Gets resource entry by path synchronously. scoped_ptr<ResourceEntry> GetResourceEntryByPathSync( const base::FilePath& file_path) { @@ -561,230 +548,6 @@ TEST_F(FileSystemTest, ReadDirectoryByPath_NonRootDirectory) { EXPECT_EQ(3U, entries->size()); } -TEST_F(FileSystemTest, ChangeFeed_AddAndDeleteFileInRoot) { - ASSERT_TRUE(LoadRootFeedDocument()); - - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2); - - ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_added_in_root.json")); - EXPECT_TRUE(EntryExists( - base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc")))); - - ASSERT_TRUE(LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_root.json")); - EXPECT_FALSE(EntryExists( - base::FilePath(FILE_PATH_LITERAL("drive/root/Added file.gdoc")))); -} - -TEST_F(FileSystemTest, ChangeFeed_AddAndDeleteFileFromExistingDirectory) { - ASSERT_TRUE(LoadRootFeedDocument()); - - EXPECT_TRUE( - EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))); - - // Add file to an existing directory. - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) - .Times(1); - ASSERT_TRUE( - LoadChangeFeed("chromeos/gdata/delta_file_added_in_directory.json")); - EXPECT_TRUE(EntryExists(base::FilePath( - FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc")))); - - // Remove that file from the directory. - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) - .Times(1); - ASSERT_TRUE( - LoadChangeFeed("chromeos/gdata/delta_file_deleted_in_directory.json")); - EXPECT_TRUE( - EntryExists(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))); - EXPECT_FALSE(EntryExists(base::FilePath( - FILE_PATH_LITERAL("drive/root/Directory 1/Added file.gdoc")))); -} - -TEST_F(FileSystemTest, ChangeFeed_AddFileToNewDirectory) { - ASSERT_TRUE(LoadRootFeedDocument()); - ASSERT_FALSE(EntryExists(base::FilePath( - FILE_PATH_LITERAL("drive/root/New Directory/New File.txt")))); - - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Directory"))))) - .Times(1); - - // This adds "drive/root/New Directory" and then - // "drive/root/New Directory/New File.txt" on the server. - google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; - scoped_ptr<google_apis::ResourceEntry> entry; - fake_drive_service_->AddNewDirectory( - fake_drive_service_->GetRootResourceId(), - "New Directory", - google_apis::test_util::CreateCopyResultCallback(&error, &entry)); - google_apis::test_util::RunBlockingPoolTask(); - ASSERT_EQ(google_apis::HTTP_CREATED, error); - - error = google_apis::GDATA_OTHER_ERROR; - fake_drive_service_->AddNewFile( - "text/plain", - "hello world", - entry->resource_id(), - "New File.txt", - false, - google_apis::test_util::CreateCopyResultCallback(&error, &entry)); - google_apis::test_util::RunBlockingPoolTask(); - ASSERT_EQ(google_apis::HTTP_CREATED, error); - - // Load the change list. - file_system_->CheckForUpdates(); - google_apis::test_util::RunBlockingPoolTask(); - - // Verify that the update is reflected. - EXPECT_TRUE( - EntryExists(base::FilePath( - FILE_PATH_LITERAL("drive/root/New Directory")))); - EXPECT_TRUE(EntryExists(base::FilePath( - FILE_PATH_LITERAL("drive/root/New Directory/New File.txt")))); -} - -TEST_F(FileSystemTest, ChangeFeed_AddFileToNewButDeletedDirectory) { - ASSERT_TRUE(LoadRootFeedDocument()); - - // This feed contains the following updates: - // 1) A new PDF file is added to a new directory - // 2) but the new directory is marked "deleted" (i.e. moved to Trash) - // Hence, the PDF file should be just ignored. - ASSERT_TRUE(LoadChangeFeed( - "chromeos/gdata/delta_file_added_in_new_but_deleted_directory.json")); -} - -TEST_F(FileSystemTest, ChangeFeed_DirectoryMovedFromRootToDirectory) { - ASSERT_TRUE(LoadRootFeedDocument()); - ASSERT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 1")))); - - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) - .Times(1); - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 2 excludeDir-test"))))).Times(1); - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 2 excludeDir-test/Directory 1"))))).Times(1); - - // This will move "Directory 1" from "drive/root/" to - // "drive/root/Directory 2 excludeDir-test/" on the server. - google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; - fake_drive_service_->AddResourceToDirectory( - "folder:sub_dir_folder_2_self_link", - "folder:1_folder_resource_id", - google_apis::test_util::CreateCopyResultCallback(&error)); - google_apis::test_util::RunBlockingPoolTask(); - ASSERT_EQ(google_apis::HTTP_SUCCESS, error); - - error = google_apis::GDATA_OTHER_ERROR; - fake_drive_service_->RemoveResourceFromDirectory( - fake_drive_service_->GetRootResourceId(), - "folder:1_folder_resource_id", - google_apis::test_util::CreateCopyResultCallback(&error)); - google_apis::test_util::RunBlockingPoolTask(); - ASSERT_EQ(google_apis::HTTP_SUCCESS, error); - - // Load the change list. - file_system_->CheckForUpdates(); - google_apis::test_util::RunBlockingPoolTask(); - - // Verify that the update is reflected. - EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 1")))); - EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 2 excludeDir-test/Directory 1")))); - EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 2 excludeDir-test/Directory 1/" - "SubDirectory File 1.txt")))); - EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 2 excludeDir-test/Directory 1/" - "Sub Directory Folder")))); - EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 2 excludeDir-test/Directory 1/Sub Directory Folder/" - "Sub Sub Directory Folder")))); -} - -TEST_F(FileSystemTest, ChangeFeed_FileMovedFromDirectoryToRoot) { - ASSERT_TRUE(LoadRootFeedDocument()); - ASSERT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 1/SubDirectory File 1.txt")))); - - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) - .Times(1); - - // This will move "drive/root/Directory 1/SubDirectory File 1.txt" - // to "drive/root/SubDirectory File 1.txt" on the server. - google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; - fake_drive_service_->AddResourceToDirectory( - fake_drive_service_->GetRootResourceId(), - "file:subdirectory_file_1_id", - google_apis::test_util::CreateCopyResultCallback(&error)); - google_apis::test_util::RunBlockingPoolTask(); - ASSERT_EQ(google_apis::HTTP_SUCCESS, error); - - error = google_apis::GDATA_OTHER_ERROR; - fake_drive_service_->RemoveResourceFromDirectory( - "folder:1_folder_resource_id", - "file:subdirectory_file_1_id", - google_apis::test_util::CreateCopyResultCallback(&error)); - google_apis::test_util::RunBlockingPoolTask(); - ASSERT_EQ(google_apis::HTTP_SUCCESS, error); - - // Load the change list. - file_system_->CheckForUpdates(); - google_apis::test_util::RunBlockingPoolTask(); - - // Verify that the update is reflected. - EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 1/SubDirectory File 1.txt")))); - EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/SubDirectory File 1.txt")))); -} - -TEST_F(FileSystemTest, ChangeFeed_FileRenamedInDirectory) { - ASSERT_TRUE(LoadRootFeedDocument()); - ASSERT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 1/SubDirectory File 1.txt")))); - - EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( - Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) - .Times(1); - - // Rename on the server. - google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; - fake_drive_service_->RenameResource( - "file:subdirectory_file_1_id", - "New SubDirectory File 1.txt", - google_apis::test_util::CreateCopyResultCallback(&error)); - google_apis::test_util::RunBlockingPoolTask(); - ASSERT_EQ(google_apis::HTTP_SUCCESS, error); - - // Load the change list. - file_system_->CheckForUpdates(); - google_apis::test_util::RunBlockingPoolTask(); - - // Verify that the update is reflected. - EXPECT_FALSE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 1/SubDirectory File 1.txt")))); - EXPECT_TRUE(EntryExists(base::FilePath(FILE_PATH_LITERAL( - "drive/root/Directory 1/New SubDirectory File 1.txt")))); -} - TEST_F(FileSystemTest, CachedFeedLoadingThenServerFeedLoading) { ASSERT_TRUE(SetUpTestFileSystem(USE_SERVER_TIMESTAMP)); diff --git a/chrome/browser/chromeos/drive/test_util.cc b/chrome/browser/chromeos/drive/test_util.cc index 69c6411..4ec6351 100644 --- a/chrome/browser/chromeos/drive/test_util.cc +++ b/chrome/browser/chromeos/drive/test_util.cc @@ -11,8 +11,6 @@ #include "base/message_loop.h" #include "base/threading/worker_pool.h" #include "base/values.h" -#include "chrome/browser/chromeos/drive/change_list_loader.h" -#include "chrome/browser/chromeos/drive/change_list_processor.h" #include "chrome/browser/chromeos/drive/drive.pb.h" #include "chrome/browser/google_apis/drive_api_parser.h" @@ -95,41 +93,6 @@ bool CacheStatesEqual(const FileCacheEntry& a, const FileCacheEntry& b) { a.is_persistent() == b.is_persistent()); } -bool LoadChangeFeed(const std::string& relative_path, - internal::ChangeListLoader* change_list_loader, - bool is_delta_feed, - const std::string& root_resource_id, - int64 root_feed_changestamp) { - scoped_ptr<Value> document = - google_apis::test_util::LoadJSONFile(relative_path); - if (!document.get()) - return false; - if (document->GetType() != Value::TYPE_DICTIONARY) - return false; - - scoped_ptr<google_apis::ResourceList> document_feed( - google_apis::ResourceList::ExtractAndParse(*document)); - if (!document_feed.get()) - return false; - - ScopedVector<internal::ChangeList> change_lists; - change_lists.push_back(new internal::ChangeList(*document_feed)); - - scoped_ptr<google_apis::AboutResource> about_resource( - new google_apis::AboutResource); - about_resource->set_largest_change_id(root_feed_changestamp); - about_resource->set_root_folder_id(root_resource_id); - - change_list_loader->UpdateFromChangeList( - about_resource.Pass(), - change_lists.Pass(), - is_delta_feed, - base::Bind(&base::DoNothing)); - google_apis::test_util::RunBlockingPoolTask(); - - return true; -} - bool PrepareTestCacheResources( internal::FileCache* cache, const std::vector<TestCacheResource>& resources) { diff --git a/chrome/browser/chromeos/drive/test_util.h b/chrome/browser/chromeos/drive/test_util.h index 8fad787..c281c7b 100644 --- a/chrome/browser/chromeos/drive/test_util.h +++ b/chrome/browser/chromeos/drive/test_util.h @@ -20,10 +20,6 @@ class IOBuffer; namespace drive { -namespace internal { -class ChangeListLoader; -} // namespace internal - namespace test_util { // Disk space size used by FakeFreeDiskSpaceGetter. @@ -65,14 +61,6 @@ FileCacheEntry ToCacheEntry(int cache_state); // Returns true if the cache state of the given two cache entries are equal. bool CacheStatesEqual(const FileCacheEntry& a, const FileCacheEntry& b); -// Loads a test json file as root ("/drive") element from a test file stored -// under chrome/test/data/chromeos. Returns true on success. -bool LoadChangeFeed(const std::string& relative_path, - internal::ChangeListLoader* change_list_loader, - bool is_delta_feed, - const std::string& root_resource_id, - int64 root_feed_changestamp); - // Helper to destroy objects which needs Destroy() to be called on destruction. // Note: When using this helper, you should destruct objects before // BrowserThread. |