OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h" | 5 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h" |
6 | 6 |
7 #include "base/task_runner_util.h" | 7 #include "base/task_runner_util.h" |
| 8 #include "chrome/browser/chromeos/drive/file_change.h" |
8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 9 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
9 #include "chrome/browser/chromeos/drive/file_system_util.h" | 10 #include "chrome/browser/chromeos/drive/file_system_util.h" |
10 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 11 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
11 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 12 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
12 #include "chrome/browser/drive/fake_drive_service.h" | 13 #include "chrome/browser/drive/fake_drive_service.h" |
13 #include "google_apis/drive/test_util.h" | 14 #include "google_apis/drive/test_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace drive { | 17 namespace drive { |
17 namespace internal { | 18 namespace internal { |
18 | 19 |
19 class EntryRevertPerformerTest : public file_system::OperationTestBase { | 20 class EntryRevertPerformerTest : public file_system::OperationTestBase { |
20 protected: | 21 protected: |
21 virtual void SetUp() OVERRIDE { | 22 virtual void SetUp() OVERRIDE { |
22 OperationTestBase::SetUp(); | 23 OperationTestBase::SetUp(); |
23 performer_.reset(new EntryRevertPerformer(blocking_task_runner(), | 24 performer_.reset(new EntryRevertPerformer(blocking_task_runner(), |
24 observer(), | 25 observer(), |
25 scheduler(), | 26 scheduler(), |
26 metadata())); | 27 metadata())); |
27 } | 28 } |
28 | 29 |
29 scoped_ptr<EntryRevertPerformer> performer_; | 30 scoped_ptr<EntryRevertPerformer> performer_; |
30 }; | 31 }; |
31 | 32 |
32 TEST_F(EntryRevertPerformerTest, RevertEntry) { | 33 TEST_F(EntryRevertPerformerTest, RevertEntry) { |
33 base::FilePath path( | 34 base::FilePath path( |
34 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 35 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
| 36 base::FilePath updated_path(FILE_PATH_LITERAL( |
| 37 "drive/root/Directory 1/UpdatedSubDirectory File 1.txt")); |
35 | 38 |
36 ResourceEntry src_entry; | 39 ResourceEntry src_entry; |
37 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &src_entry)); | 40 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &src_entry)); |
38 | 41 |
39 // Update local entry. | 42 // Update local entry. |
40 ResourceEntry updated_entry = src_entry; | 43 ResourceEntry updated_entry = src_entry; |
41 updated_entry.set_title("Updated" + src_entry.title()); | 44 updated_entry.set_title("Updated" + src_entry.title()); |
42 updated_entry.set_metadata_edit_state(ResourceEntry::DIRTY); | 45 updated_entry.set_metadata_edit_state(ResourceEntry::DIRTY); |
43 | 46 |
44 FileError error = FILE_ERROR_FAILED; | 47 FileError error = FILE_ERROR_FAILED; |
(...skipping 15 matching lines...) Expand all Loading... |
60 test_util::RunBlockingPoolTask(); | 63 test_util::RunBlockingPoolTask(); |
61 EXPECT_EQ(FILE_ERROR_OK, error); | 64 EXPECT_EQ(FILE_ERROR_OK, error); |
62 | 65 |
63 // Verify local change is reverted. | 66 // Verify local change is reverted. |
64 ResourceEntry result_entry; | 67 ResourceEntry result_entry; |
65 EXPECT_EQ(FILE_ERROR_OK, | 68 EXPECT_EQ(FILE_ERROR_OK, |
66 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); | 69 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); |
67 EXPECT_EQ(src_entry.title(), result_entry.title()); | 70 EXPECT_EQ(src_entry.title(), result_entry.title()); |
68 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state()); | 71 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state()); |
69 | 72 |
70 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 73 EXPECT_EQ(2U, observer()->get_changed_files().size()); |
71 EXPECT_TRUE(observer()->get_changed_paths().count(path.DirName())); | 74 EXPECT_TRUE(observer()->get_changed_files().count(path)); |
| 75 EXPECT_TRUE(observer()->get_changed_files().count(updated_path)); |
72 } | 76 } |
73 | 77 |
74 TEST_F(EntryRevertPerformerTest, RevertEntry_NotFoundOnServer) { | 78 TEST_F(EntryRevertPerformerTest, RevertEntry_NotFoundOnServer) { |
75 ResourceEntry my_drive; | 79 ResourceEntry my_drive; |
76 EXPECT_EQ(FILE_ERROR_OK, | 80 EXPECT_EQ(FILE_ERROR_OK, |
77 GetLocalResourceEntry(util::GetDriveMyDriveRootPath(), &my_drive)); | 81 GetLocalResourceEntry(util::GetDriveMyDriveRootPath(), &my_drive)); |
78 | 82 |
79 // Add a new entry with a nonexistent resource ID. | 83 // Add a new entry with a nonexistent resource ID. |
80 ResourceEntry entry; | 84 ResourceEntry entry; |
81 entry.set_title("New File.txt"); | 85 entry.set_title("New File.txt"); |
(...skipping 16 matching lines...) Expand all Loading... |
98 performer_->RevertEntry( | 102 performer_->RevertEntry( |
99 local_id, | 103 local_id, |
100 ClientContext(USER_INITIATED), | 104 ClientContext(USER_INITIATED), |
101 google_apis::test_util::CreateCopyResultCallback(&error)); | 105 google_apis::test_util::CreateCopyResultCallback(&error)); |
102 test_util::RunBlockingPoolTask(); | 106 test_util::RunBlockingPoolTask(); |
103 EXPECT_EQ(FILE_ERROR_OK, error); | 107 EXPECT_EQ(FILE_ERROR_OK, error); |
104 | 108 |
105 // Verify the entry was deleted locally. | 109 // Verify the entry was deleted locally. |
106 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry)); | 110 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry)); |
107 | 111 |
108 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 112 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
109 EXPECT_TRUE(observer()->get_changed_paths().count( | 113 EXPECT_TRUE(observer()->get_changed_files().CountDirectory( |
110 util::GetDriveMyDriveRootPath())); | 114 util::GetDriveMyDriveRootPath())); |
111 } | 115 } |
112 | 116 |
113 TEST_F(EntryRevertPerformerTest, RevertEntry_TrashedOnServer) { | 117 TEST_F(EntryRevertPerformerTest, RevertEntry_TrashedOnServer) { |
114 base::FilePath path( | 118 base::FilePath path( |
115 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 119 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
116 | 120 |
117 ResourceEntry entry; | 121 ResourceEntry entry; |
118 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry)); | 122 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry)); |
119 | 123 |
(...skipping 11 matching lines...) Expand all Loading... |
131 entry.local_id(), | 135 entry.local_id(), |
132 ClientContext(USER_INITIATED), | 136 ClientContext(USER_INITIATED), |
133 google_apis::test_util::CreateCopyResultCallback(&error)); | 137 google_apis::test_util::CreateCopyResultCallback(&error)); |
134 test_util::RunBlockingPoolTask(); | 138 test_util::RunBlockingPoolTask(); |
135 EXPECT_EQ(FILE_ERROR_OK, error); | 139 EXPECT_EQ(FILE_ERROR_OK, error); |
136 | 140 |
137 // Verify the entry was deleted locally. | 141 // Verify the entry was deleted locally. |
138 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 142 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
139 GetLocalResourceEntryById(entry.local_id(), &entry)); | 143 GetLocalResourceEntryById(entry.local_id(), &entry)); |
140 | 144 |
141 EXPECT_EQ(1U, observer()->get_changed_paths().size()); | 145 EXPECT_EQ(1U, observer()->get_changed_files().size()); |
142 EXPECT_TRUE(observer()->get_changed_paths().count(path.DirName())); | 146 EXPECT_TRUE(observer()->get_changed_files().count(path)); |
143 } | 147 } |
144 | 148 |
145 } // namespace internal | 149 } // namespace internal |
146 } // namespace drive | 150 } // namespace drive |
OLD | NEW |