Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / sync / entry_revert_performer_unittest.cc
blob2ebd2f703394bf61771d496f0017bccdec124f0b
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h"
7 #include "base/task_runner_util.h"
8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
9 #include "components/drive/file_change.h"
10 #include "components/drive/file_system_core_util.h"
11 #include "components/drive/job_scheduler.h"
12 #include "components/drive/resource_metadata.h"
13 #include "components/drive/service/fake_drive_service.h"
14 #include "content/public/test/test_utils.h"
15 #include "google_apis/drive/test_util.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace drive {
19 namespace internal {
21 class EntryRevertPerformerTest : public file_system::OperationTestBase {
22 protected:
23 void SetUp() override {
24 OperationTestBase::SetUp();
25 performer_.reset(new EntryRevertPerformer(blocking_task_runner(),
26 delegate(),
27 scheduler(),
28 metadata()));
31 scoped_ptr<EntryRevertPerformer> performer_;
34 TEST_F(EntryRevertPerformerTest, RevertEntry) {
35 base::FilePath path(
36 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
37 base::FilePath updated_path(FILE_PATH_LITERAL(
38 "drive/root/Directory 1/UpdatedSubDirectory File 1.txt"));
40 ResourceEntry src_entry;
41 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &src_entry));
43 // Update local entry.
44 ResourceEntry updated_entry = src_entry;
45 updated_entry.set_title("Updated" + src_entry.title());
46 updated_entry.set_metadata_edit_state(ResourceEntry::DIRTY);
48 FileError error = FILE_ERROR_FAILED;
49 base::PostTaskAndReplyWithResult(
50 blocking_task_runner(),
51 FROM_HERE,
52 base::Bind(&ResourceMetadata::RefreshEntry,
53 base::Unretained(metadata()), updated_entry),
54 google_apis::test_util::CreateCopyResultCallback(&error));
55 content::RunAllBlockingPoolTasksUntilIdle();
56 EXPECT_EQ(FILE_ERROR_OK, error);
58 // Revert local change.
59 error = FILE_ERROR_FAILED;
60 performer_->RevertEntry(
61 src_entry.local_id(),
62 ClientContext(USER_INITIATED),
63 google_apis::test_util::CreateCopyResultCallback(&error));
64 content::RunAllBlockingPoolTasksUntilIdle();
65 EXPECT_EQ(FILE_ERROR_OK, error);
67 // Verify local change is reverted.
68 ResourceEntry result_entry;
69 EXPECT_EQ(FILE_ERROR_OK,
70 GetLocalResourceEntryById(src_entry.local_id(), &result_entry));
71 EXPECT_EQ(src_entry.title(), result_entry.title());
72 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state());
74 EXPECT_EQ(2U, delegate()->get_changed_files().size());
75 EXPECT_TRUE(delegate()->get_changed_files().count(path));
76 EXPECT_TRUE(delegate()->get_changed_files().count(updated_path));
79 TEST_F(EntryRevertPerformerTest, RevertEntry_NotFoundOnServer) {
80 ResourceEntry my_drive;
81 EXPECT_EQ(FILE_ERROR_OK,
82 GetLocalResourceEntry(util::GetDriveMyDriveRootPath(), &my_drive));
84 // Add a new entry with a nonexistent resource ID.
85 ResourceEntry entry;
86 entry.set_title("New File.txt");
87 entry.set_resource_id("non-existent-resource-id");
88 entry.set_parent_local_id(my_drive.local_id());
90 FileError error = FILE_ERROR_FAILED;
91 std::string local_id;
92 base::PostTaskAndReplyWithResult(
93 blocking_task_runner(),
94 FROM_HERE,
95 base::Bind(&ResourceMetadata::AddEntry,
96 base::Unretained(metadata()), entry, &local_id),
97 google_apis::test_util::CreateCopyResultCallback(&error));
98 content::RunAllBlockingPoolTasksUntilIdle();
99 EXPECT_EQ(FILE_ERROR_OK, error);
101 // Revert local change. The added entry should be removed.
102 error = FILE_ERROR_FAILED;
103 performer_->RevertEntry(
104 local_id,
105 ClientContext(USER_INITIATED),
106 google_apis::test_util::CreateCopyResultCallback(&error));
107 content::RunAllBlockingPoolTasksUntilIdle();
108 EXPECT_EQ(FILE_ERROR_OK, error);
110 // Verify the entry was deleted locally.
111 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry));
113 EXPECT_EQ(1U, delegate()->get_changed_files().size());
114 EXPECT_TRUE(delegate()->get_changed_files().CountDirectory(
115 util::GetDriveMyDriveRootPath()));
118 TEST_F(EntryRevertPerformerTest, RevertEntry_TrashedOnServer) {
119 base::FilePath path(
120 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
122 ResourceEntry entry;
123 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry));
125 // Trash the entry on the server.
126 google_apis::DriveApiErrorCode gdata_error = google_apis::DRIVE_OTHER_ERROR;
127 fake_service()->TrashResource(
128 entry.resource_id(),
129 google_apis::test_util::CreateCopyResultCallback(&gdata_error));
130 content::RunAllBlockingPoolTasksUntilIdle();
131 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error);
133 // Revert local change. The entry should be removed.
134 FileError error = FILE_ERROR_FAILED;
135 performer_->RevertEntry(
136 entry.local_id(),
137 ClientContext(USER_INITIATED),
138 google_apis::test_util::CreateCopyResultCallback(&error));
139 content::RunAllBlockingPoolTasksUntilIdle();
140 EXPECT_EQ(FILE_ERROR_OK, error);
142 // Verify the entry was deleted locally.
143 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
144 GetLocalResourceEntryById(entry.local_id(), &entry));
146 EXPECT_EQ(1U, delegate()->get_changed_files().size());
147 EXPECT_TRUE(delegate()->get_changed_files().count(path));
150 } // namespace internal
151 } // namespace drive