Add tests for sync performers about HTTP_FORBIDDEN handling

BUG=340933
TEST=unit_tests

Review URL: https://codereview.chromium.org/453843002

Cr-Commit-Position: refs/heads/master@{#288322}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288322 0039d316-1c4b-4281-b951-d872f2087c98
parent 2e3086bc
......@@ -551,5 +551,48 @@ TEST_F(EntryUpdatePerformerTest, UpdateEntry_CreateDirectory) {
EXPECT_TRUE(server_entry->IsDirectory());
}
TEST_F(EntryUpdatePerformerTest, UpdateEntry_InsufficientPermission) {
base::FilePath src_path(
FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
ResourceEntry src_entry;
EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(src_path, &src_entry));
// Update local entry.
ResourceEntry updated_entry(src_entry);
updated_entry.set_title("Moved" + src_entry.title());
updated_entry.set_metadata_edit_state(ResourceEntry::DIRTY);
FileError error = FILE_ERROR_FAILED;
base::PostTaskAndReplyWithResult(
blocking_task_runner(),
FROM_HERE,
base::Bind(&ResourceMetadata::RefreshEntry,
base::Unretained(metadata()),
updated_entry),
google_apis::test_util::CreateCopyResultCallback(&error));
content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Set user permission to forbid server side update.
EXPECT_EQ(google_apis::HTTP_SUCCESS, fake_service()->SetUserPermission(
src_entry.resource_id(), google_apis::drive::PERMISSION_ROLE_READER));
// Try to perform update.
error = FILE_ERROR_FAILED;
performer_->UpdateEntry(
src_entry.local_id(),
ClientContext(USER_INITIATED),
google_apis::test_util::CreateCopyResultCallback(&error));
content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// This should result in reverting the local change.
ResourceEntry result_entry;
EXPECT_EQ(FILE_ERROR_OK,
GetLocalResourceEntryById(src_entry.local_id(), &result_entry));
EXPECT_EQ(src_entry.title(), result_entry.title());
}
} // namespace internal
} // namespace drive
......@@ -148,5 +148,52 @@ TEST_F(RemovePerformerTest, RemoveLocallyCreatedFile) {
EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry));
}
TEST_F(RemovePerformerTest, Remove_InsufficientPermission) {
RemovePerformer performer(blocking_task_runner(), delegate(), scheduler(),
metadata());
base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
ResourceEntry src_entry;
ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry));
// Remove locally.
ResourceEntry updated_entry(src_entry);
updated_entry.set_parent_local_id(util::kDriveTrashDirLocalId);
FileError error = FILE_ERROR_FAILED;
base::PostTaskAndReplyWithResult(
blocking_task_runner(),
FROM_HERE,
base::Bind(&ResourceMetadata::RefreshEntry,
base::Unretained(metadata()),
updated_entry),
google_apis::test_util::CreateCopyResultCallback(&error));
content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// Set user permission to forbid server side update.
EXPECT_EQ(google_apis::HTTP_SUCCESS, fake_service()->SetUserPermission(
src_entry.resource_id(), google_apis::drive::PERMISSION_ROLE_READER));
// Try to perform remove.
error = FILE_ERROR_FAILED;
performer.Remove(src_entry.local_id(),
ClientContext(USER_INITIATED),
google_apis::test_util::CreateCopyResultCallback(&error));
content::RunAllBlockingPoolTasksUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
// This should result in reverting the local change.
ResourceEntry result_entry;
EXPECT_EQ(FILE_ERROR_OK,
GetLocalResourceEntryById(src_entry.local_id(), &result_entry));
EXPECT_EQ(src_entry.parent_local_id(), result_entry.parent_local_id());
ASSERT_EQ(1U, delegate()->drive_sync_errors().size());
EXPECT_EQ(file_system::DRIVE_SYNC_ERROR_DELETE_WITHOUT_PERMISSION,
delegate()->drive_sync_errors()[0]);
}
} // namespace internal
} // namespace drive
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment