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_system/operation_test_base.h" | 8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
9 #include "chrome/browser/chromeos/drive/file_system_util.h" | 9 #include "chrome/browser/chromeos/drive/file_system_util.h" |
10 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 10 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
11 #include "chrome/browser/drive/fake_drive_service.h" | 11 #include "chrome/browser/drive/fake_drive_service.h" |
12 #include "google_apis/drive/test_util.h" | 12 #include "google_apis/drive/test_util.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace drive { | 15 namespace drive { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 class EntryRevertPerformerTest : public file_system::OperationTestBase { | 18 class EntryRevertPerformerTest : public file_system::OperationTestBase { |
19 protected: | 19 protected: |
20 virtual void SetUp() OVERRIDE { | 20 virtual void SetUp() OVERRIDE { |
21 OperationTestBase::SetUp(); | 21 OperationTestBase::SetUp(); |
22 performer_.reset(new EntryRevertPerformer(blocking_task_runner(), | 22 performer_.reset(new EntryRevertPerformer(blocking_task_runner(), |
| 23 observer(), |
23 scheduler(), | 24 scheduler(), |
24 metadata())); | 25 metadata())); |
25 } | 26 } |
26 | 27 |
27 scoped_ptr<EntryRevertPerformer> performer_; | 28 scoped_ptr<EntryRevertPerformer> performer_; |
28 }; | 29 }; |
29 | 30 |
30 TEST_F(EntryRevertPerformerTest, RevertEntry) { | 31 TEST_F(EntryRevertPerformerTest, RevertEntry) { |
31 base::FilePath path( | 32 base::FilePath path( |
32 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 33 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
(...skipping 23 matching lines...) Expand all Loading... |
56 google_apis::test_util::CreateCopyResultCallback(&error)); | 57 google_apis::test_util::CreateCopyResultCallback(&error)); |
57 test_util::RunBlockingPoolTask(); | 58 test_util::RunBlockingPoolTask(); |
58 EXPECT_EQ(FILE_ERROR_OK, error); | 59 EXPECT_EQ(FILE_ERROR_OK, error); |
59 | 60 |
60 // Verify local change is reverted. | 61 // Verify local change is reverted. |
61 ResourceEntry result_entry; | 62 ResourceEntry result_entry; |
62 EXPECT_EQ(FILE_ERROR_OK, | 63 EXPECT_EQ(FILE_ERROR_OK, |
63 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); | 64 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); |
64 EXPECT_EQ(src_entry.title(), result_entry.title()); | 65 EXPECT_EQ(src_entry.title(), result_entry.title()); |
65 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state()); | 66 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state()); |
| 67 |
| 68 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 69 EXPECT_TRUE(observer()->get_changed_paths().count(path.DirName())); |
66 } | 70 } |
67 | 71 |
68 TEST_F(EntryRevertPerformerTest, RevertEntry_NotFoundOnServer) { | 72 TEST_F(EntryRevertPerformerTest, RevertEntry_NotFoundOnServer) { |
69 ResourceEntry my_drive; | 73 ResourceEntry my_drive; |
70 EXPECT_EQ(FILE_ERROR_OK, | 74 EXPECT_EQ(FILE_ERROR_OK, |
71 GetLocalResourceEntry(util::GetDriveMyDriveRootPath(), &my_drive)); | 75 GetLocalResourceEntry(util::GetDriveMyDriveRootPath(), &my_drive)); |
72 | 76 |
73 // Add a new entry with a nonexistent resource ID. | 77 // Add a new entry with a nonexistent resource ID. |
74 ResourceEntry entry; | 78 ResourceEntry entry; |
75 entry.set_title("New File.txt"); | 79 entry.set_title("New File.txt"); |
(...skipping 14 matching lines...) Expand all Loading... |
90 // Revert local change. The added entry should be removed. | 94 // Revert local change. The added entry should be removed. |
91 error = FILE_ERROR_FAILED; | 95 error = FILE_ERROR_FAILED; |
92 performer_->RevertEntry( | 96 performer_->RevertEntry( |
93 local_id, | 97 local_id, |
94 google_apis::test_util::CreateCopyResultCallback(&error)); | 98 google_apis::test_util::CreateCopyResultCallback(&error)); |
95 test_util::RunBlockingPoolTask(); | 99 test_util::RunBlockingPoolTask(); |
96 EXPECT_EQ(FILE_ERROR_OK, error); | 100 EXPECT_EQ(FILE_ERROR_OK, error); |
97 | 101 |
98 // Verify the entry was deleted locally. | 102 // Verify the entry was deleted locally. |
99 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry)); | 103 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry)); |
| 104 |
| 105 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 106 EXPECT_TRUE(observer()->get_changed_paths().count( |
| 107 util::GetDriveMyDriveRootPath())); |
100 } | 108 } |
101 | 109 |
102 TEST_F(EntryRevertPerformerTest, RevertEntry_DeletedOnServer) { | 110 TEST_F(EntryRevertPerformerTest, RevertEntry_DeletedOnServer) { |
103 base::FilePath path( | 111 base::FilePath path( |
104 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 112 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
105 | 113 |
106 ResourceEntry entry; | 114 ResourceEntry entry; |
107 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry)); | 115 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry)); |
108 | 116 |
109 // Delete the entry on the server. | 117 // Delete the entry on the server. |
110 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; | 118 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; |
111 fake_service()->DeleteResource( | 119 fake_service()->DeleteResource( |
112 entry.resource_id(), | 120 entry.resource_id(), |
113 std::string(), // etag | 121 std::string(), // etag |
114 google_apis::test_util::CreateCopyResultCallback(&gdata_error)); | 122 google_apis::test_util::CreateCopyResultCallback(&gdata_error)); |
115 test_util::RunBlockingPoolTask(); | 123 test_util::RunBlockingPoolTask(); |
116 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error); | 124 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error); |
117 | 125 |
118 // Revert local change. The entry should be removed. | 126 // Revert local change. The entry should be removed. |
119 FileError error = FILE_ERROR_FAILED; | 127 FileError error = FILE_ERROR_FAILED; |
120 performer_->RevertEntry( | 128 performer_->RevertEntry( |
121 entry.local_id(), | 129 entry.local_id(), |
122 google_apis::test_util::CreateCopyResultCallback(&error)); | 130 google_apis::test_util::CreateCopyResultCallback(&error)); |
123 test_util::RunBlockingPoolTask(); | 131 test_util::RunBlockingPoolTask(); |
124 EXPECT_EQ(FILE_ERROR_OK, error); | 132 EXPECT_EQ(FILE_ERROR_OK, error); |
125 | 133 |
126 // Verify the entry was deleted locally. | 134 // Verify the entry was deleted locally. |
127 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 135 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
128 GetLocalResourceEntryById(entry.local_id(), &entry)); | 136 GetLocalResourceEntryById(entry.local_id(), &entry)); |
| 137 |
| 138 EXPECT_EQ(1U, observer()->get_changed_paths().size()); |
| 139 EXPECT_TRUE(observer()->get_changed_paths().count(path.DirName())); |
129 } | 140 } |
130 | 141 |
131 } // namespace internal | 142 } // namespace internal |
132 } // namespace drive | 143 } // namespace drive |
OLD | NEW |