OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_client.h" | 5 #include "chrome/browser/chromeos/drive/sync_client.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // Action used to set mock expectations for GetFileByResourceId(). | 34 // Action used to set mock expectations for GetFileByResourceId(). |
35 ACTION_P2(MockGetFileByResourceId, error, local_path) { | 35 ACTION_P2(MockGetFileByResourceId, error, local_path) { |
36 arg2.Run(error, local_path, scoped_ptr<ResourceEntry>(new ResourceEntry)); | 36 arg2.Run(error, local_path, scoped_ptr<ResourceEntry>(new ResourceEntry)); |
37 } | 37 } |
38 | 38 |
39 // Action used to set mock expectations for UpdateFileByResourceId(). | 39 // Action used to set mock expectations for UpdateFileByResourceId(). |
40 ACTION_P(MockUpdateFileByResourceId, error) { | 40 ACTION_P(MockUpdateFileByResourceId, error) { |
41 arg2.Run(error); | 41 arg2.Run(error); |
42 } | 42 } |
43 | 43 |
44 // Action used to set mock expectations for GetFileInfoByResourceId(). | 44 // Action used to set mock expectations for GetResourceEntryById(). |
45 ACTION_P2(MockUpdateFileByResourceId, error, md5) { | 45 ACTION_P2(MockGetResourceEntryById, error, md5) { |
46 scoped_ptr<ResourceEntry> entry(new ResourceEntry); | 46 scoped_ptr<ResourceEntry> entry(new ResourceEntry); |
47 entry->mutable_file_specific_info()->set_file_md5(md5); | 47 entry->mutable_file_specific_info()->set_file_md5(md5); |
48 arg1.Run(error, base::FilePath(), entry.Pass()); | 48 arg1.Run(error, entry.Pass()); |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 class SyncClientTest : public testing::Test { | 53 class SyncClientTest : public testing::Test { |
54 public: | 54 public: |
55 SyncClientTest() | 55 SyncClientTest() |
56 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 56 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
57 mock_file_system_(new StrictMock<MockFileSystem>) { | 57 mock_file_system_(new StrictMock<MockFileSystem>) { |
58 } | 58 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 cache_->CommitDirtyOnUIThread( | 154 cache_->CommitDirtyOnUIThread( |
155 resource_id_dirty, md5_dirty, | 155 resource_id_dirty, md5_dirty, |
156 google_apis::test_util::CreateCopyResultCallback(&error)); | 156 google_apis::test_util::CreateCopyResultCallback(&error)); |
157 google_apis::test_util::RunBlockingPoolTask(); | 157 google_apis::test_util::RunBlockingPoolTask(); |
158 EXPECT_EQ(FILE_ERROR_OK, error); | 158 EXPECT_EQ(FILE_ERROR_OK, error); |
159 } | 159 } |
160 | 160 |
161 // Sets the expectation for MockFileSystem::GetFileByResourceId(), | 161 // Sets the expectation for MockFileSystem::GetFileByResourceId(), |
162 // that simulates successful retrieval of a file for the given resource ID. | 162 // that simulates successful retrieval of a file for the given resource ID. |
163 void SetExpectationForGetFileByResourceId(const std::string& resource_id) { | 163 void SetExpectationForGetFileByResourceId(const std::string& resource_id) { |
164 EXPECT_CALL(*mock_file_system_, | 164 EXPECT_CALL(*mock_file_system_, GetFileByResourceId(resource_id, _, _, _)) |
165 GetFileByResourceId(resource_id, _, _, _)) | |
166 .WillOnce( | 165 .WillOnce( |
167 MockGetFileByResourceId( | 166 MockGetFileByResourceId( |
168 FILE_ERROR_OK, | 167 FILE_ERROR_OK, |
169 base::FilePath::FromUTF8Unsafe("local_path_does_not_matter"))); | 168 base::FilePath::FromUTF8Unsafe("local_path_does_not_matter"))); |
170 } | 169 } |
171 | 170 |
172 // Sets the expectation for MockFileSystem::UpdateFileByResourceId(), | 171 // Sets the expectation for MockFileSystem::UpdateFileByResourceId(), |
173 // that simulates successful uploading of a file for the given resource ID. | 172 // that simulates successful uploading of a file for the given resource ID. |
174 void SetExpectationForUpdateFileByResourceId( | 173 void SetExpectationForUpdateFileByResourceId(const std::string& resource_id) { |
175 const std::string& resource_id) { | 174 EXPECT_CALL(*mock_file_system_, UpdateFileByResourceId(resource_id, _, _)) |
176 EXPECT_CALL(*mock_file_system_, | |
177 UpdateFileByResourceId(resource_id, _, _)) | |
178 .WillOnce(MockUpdateFileByResourceId(FILE_ERROR_OK)); | 175 .WillOnce(MockUpdateFileByResourceId(FILE_ERROR_OK)); |
179 } | 176 } |
180 | 177 |
181 // Sets the expectation for MockFileSystem::GetFileInfoByResourceId(), | 178 // Sets the expectation for MockFileSystem::GetResourceEntryById(), |
182 // that simulates successful retrieval of file info for the given resource | 179 // that simulates successful retrieval of file info for the given resource |
183 // ID. | 180 // ID. |
184 // | 181 // |
185 // This is used for testing StartCheckingExistingPinnedFiles(), hence we | 182 // This is used for testing StartCheckingExistingPinnedFiles(), hence we |
186 // are only interested in the MD5 value in ResourceEntry. | 183 // are only interested in the MD5 value in ResourceEntry. |
187 void SetExpectationForGetFileInfoByResourceId( | 184 void SetExpectationForGetFileInfoByResourceId(const std::string& resource_id, |
188 const std::string& resource_id, | 185 const std::string& new_md5) { |
189 const std::string& new_md5) { | 186 EXPECT_CALL(*mock_file_system_, GetResourceEntryById(resource_id, _)) |
190 EXPECT_CALL(*mock_file_system_, | 187 .WillOnce(MockGetResourceEntryById(FILE_ERROR_OK, new_md5)); |
191 GetResourceEntryById(resource_id, _)) | |
192 .WillOnce(MockUpdateFileByResourceId( | |
193 FILE_ERROR_OK, | |
194 new_md5)); | |
195 } | 188 } |
196 | 189 |
197 // Returns the resource IDs in the queue to be fetched. | 190 // Returns the resource IDs in the queue to be fetched. |
198 std::vector<std::string> GetResourceIdsToBeFetched() { | 191 std::vector<std::string> GetResourceIdsToBeFetched() { |
199 return sync_client_->GetResourceIdsForTesting(SyncClient::FETCH); | 192 return sync_client_->GetResourceIdsForTesting(SyncClient::FETCH); |
200 } | 193 } |
201 | 194 |
202 // Returns the resource IDs in the queue to be uploaded. | 195 // Returns the resource IDs in the queue to be uploaded. |
203 std::vector<std::string> GetResourceIdsToBeUploaded() { | 196 std::vector<std::string> GetResourceIdsToBeUploaded() { |
204 return sync_client_->GetResourceIdsForTesting(SyncClient::UPLOAD); | 197 return sync_client_->GetResourceIdsForTesting(SyncClient::UPLOAD); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 // IDs of pinned files, with stale local cache files. | 287 // IDs of pinned files, with stale local cache files. |
295 sync_client_->StartCheckingExistingPinnedFiles(); | 288 sync_client_->StartCheckingExistingPinnedFiles(); |
296 | 289 |
297 SetExpectationForGetFileByResourceId("resource_id_fetched"); | 290 SetExpectationForGetFileByResourceId("resource_id_fetched"); |
298 | 291 |
299 google_apis::test_util::RunBlockingPoolTask(); | 292 google_apis::test_util::RunBlockingPoolTask(); |
300 } | 293 } |
301 | 294 |
302 } // namespace internal | 295 } // namespace internal |
303 } // namespace drive | 296 } // namespace drive |
OLD | NEW |