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_change.h" |
9 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" | 9 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" |
10 #include "chrome/browser/chromeos/drive/file_system_util.h" | 10 #include "chrome/browser/chromeos/drive/file_system_util.h" |
11 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 11 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
12 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 12 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
13 #include "chrome/browser/drive/fake_drive_service.h" | 13 #include "chrome/browser/drive/fake_drive_service.h" |
14 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
15 #include "google_apis/drive/test_util.h" | 15 #include "google_apis/drive/test_util.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace drive { | 18 namespace drive { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 class EntryRevertPerformerTest : public file_system::OperationTestBase { | 21 class EntryRevertPerformerTest : public file_system::OperationTestBase { |
22 protected: | 22 protected: |
23 virtual void SetUp() OVERRIDE { | 23 virtual void SetUp() OVERRIDE { |
24 OperationTestBase::SetUp(); | 24 OperationTestBase::SetUp(); |
25 performer_.reset(new EntryRevertPerformer(blocking_task_runner(), | 25 performer_.reset(new EntryRevertPerformer(blocking_task_runner(), |
26 observer(), | 26 delegate(), |
27 scheduler(), | 27 scheduler(), |
28 metadata())); | 28 metadata())); |
29 } | 29 } |
30 | 30 |
31 scoped_ptr<EntryRevertPerformer> performer_; | 31 scoped_ptr<EntryRevertPerformer> performer_; |
32 }; | 32 }; |
33 | 33 |
34 TEST_F(EntryRevertPerformerTest, RevertEntry) { | 34 TEST_F(EntryRevertPerformerTest, RevertEntry) { |
35 base::FilePath path( | 35 base::FilePath path( |
36 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 36 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
(...skipping 27 matching lines...) Expand all Loading... |
64 content::RunAllBlockingPoolTasksUntilIdle(); | 64 content::RunAllBlockingPoolTasksUntilIdle(); |
65 EXPECT_EQ(FILE_ERROR_OK, error); | 65 EXPECT_EQ(FILE_ERROR_OK, error); |
66 | 66 |
67 // Verify local change is reverted. | 67 // Verify local change is reverted. |
68 ResourceEntry result_entry; | 68 ResourceEntry result_entry; |
69 EXPECT_EQ(FILE_ERROR_OK, | 69 EXPECT_EQ(FILE_ERROR_OK, |
70 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); | 70 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); |
71 EXPECT_EQ(src_entry.title(), result_entry.title()); | 71 EXPECT_EQ(src_entry.title(), result_entry.title()); |
72 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state()); | 72 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state()); |
73 | 73 |
74 EXPECT_EQ(2U, observer()->get_changed_files().size()); | 74 EXPECT_EQ(2U, delegate()->get_changed_files().size()); |
75 EXPECT_TRUE(observer()->get_changed_files().count(path)); | 75 EXPECT_TRUE(delegate()->get_changed_files().count(path)); |
76 EXPECT_TRUE(observer()->get_changed_files().count(updated_path)); | 76 EXPECT_TRUE(delegate()->get_changed_files().count(updated_path)); |
77 } | 77 } |
78 | 78 |
79 TEST_F(EntryRevertPerformerTest, RevertEntry_NotFoundOnServer) { | 79 TEST_F(EntryRevertPerformerTest, RevertEntry_NotFoundOnServer) { |
80 ResourceEntry my_drive; | 80 ResourceEntry my_drive; |
81 EXPECT_EQ(FILE_ERROR_OK, | 81 EXPECT_EQ(FILE_ERROR_OK, |
82 GetLocalResourceEntry(util::GetDriveMyDriveRootPath(), &my_drive)); | 82 GetLocalResourceEntry(util::GetDriveMyDriveRootPath(), &my_drive)); |
83 | 83 |
84 // Add a new entry with a nonexistent resource ID. | 84 // Add a new entry with a nonexistent resource ID. |
85 ResourceEntry entry; | 85 ResourceEntry entry; |
86 entry.set_title("New File.txt"); | 86 entry.set_title("New File.txt"); |
(...skipping 16 matching lines...) Expand all Loading... |
103 performer_->RevertEntry( | 103 performer_->RevertEntry( |
104 local_id, | 104 local_id, |
105 ClientContext(USER_INITIATED), | 105 ClientContext(USER_INITIATED), |
106 google_apis::test_util::CreateCopyResultCallback(&error)); | 106 google_apis::test_util::CreateCopyResultCallback(&error)); |
107 content::RunAllBlockingPoolTasksUntilIdle(); | 107 content::RunAllBlockingPoolTasksUntilIdle(); |
108 EXPECT_EQ(FILE_ERROR_OK, error); | 108 EXPECT_EQ(FILE_ERROR_OK, error); |
109 | 109 |
110 // Verify the entry was deleted locally. | 110 // Verify the entry was deleted locally. |
111 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry)); | 111 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry)); |
112 | 112 |
113 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 113 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
114 EXPECT_TRUE(observer()->get_changed_files().CountDirectory( | 114 EXPECT_TRUE(delegate()->get_changed_files().CountDirectory( |
115 util::GetDriveMyDriveRootPath())); | 115 util::GetDriveMyDriveRootPath())); |
116 } | 116 } |
117 | 117 |
118 TEST_F(EntryRevertPerformerTest, RevertEntry_TrashedOnServer) { | 118 TEST_F(EntryRevertPerformerTest, RevertEntry_TrashedOnServer) { |
119 base::FilePath path( | 119 base::FilePath path( |
120 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | 120 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); |
121 | 121 |
122 ResourceEntry entry; | 122 ResourceEntry entry; |
123 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry)); | 123 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry)); |
124 | 124 |
(...skipping 11 matching lines...) Expand all Loading... |
136 entry.local_id(), | 136 entry.local_id(), |
137 ClientContext(USER_INITIATED), | 137 ClientContext(USER_INITIATED), |
138 google_apis::test_util::CreateCopyResultCallback(&error)); | 138 google_apis::test_util::CreateCopyResultCallback(&error)); |
139 content::RunAllBlockingPoolTasksUntilIdle(); | 139 content::RunAllBlockingPoolTasksUntilIdle(); |
140 EXPECT_EQ(FILE_ERROR_OK, error); | 140 EXPECT_EQ(FILE_ERROR_OK, error); |
141 | 141 |
142 // Verify the entry was deleted locally. | 142 // Verify the entry was deleted locally. |
143 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 143 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
144 GetLocalResourceEntryById(entry.local_id(), &entry)); | 144 GetLocalResourceEntryById(entry.local_id(), &entry)); |
145 | 145 |
146 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 146 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
147 EXPECT_TRUE(observer()->get_changed_files().count(path)); | 147 EXPECT_TRUE(delegate()->get_changed_files().count(path)); |
148 } | 148 } |
149 | 149 |
150 } // namespace internal | 150 } // namespace internal |
151 } // namespace drive | 151 } // namespace drive |
OLD | NEW |