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/gdata/gdata_sync_client.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 dirty_file_path, | 216 dirty_file_path, |
217 pinned_dir.AppendASCII("resource_id_dirty"))); | 217 pinned_dir.AppendASCII("resource_id_dirty"))); |
218 } | 218 } |
219 | 219 |
220 // Sets the expectation for MockGDataFileSystem::GetFileByResourceId(), | 220 // Sets the expectation for MockGDataFileSystem::GetFileByResourceId(), |
221 // that simulates successful retrieval of a file for the given resource ID. | 221 // that simulates successful retrieval of a file for the given resource ID. |
222 void SetExpectationForGetFileByResourceId(const std::string& resource_id) { | 222 void SetExpectationForGetFileByResourceId(const std::string& resource_id) { |
223 EXPECT_CALL(*mock_file_system_, | 223 EXPECT_CALL(*mock_file_system_, |
224 GetFileByResourceId(resource_id, _, _)) | 224 GetFileByResourceId(resource_id, _, _)) |
225 .WillOnce(MockGetFileByResourceId( | 225 .WillOnce(MockGetFileByResourceId( |
226 GDATA_FILE_OK, | 226 DRIVE_FILE_OK, |
227 FilePath::FromUTF8Unsafe("local_path_does_not_matter"), | 227 FilePath::FromUTF8Unsafe("local_path_does_not_matter"), |
228 std::string("mime_type_does_not_matter"), | 228 std::string("mime_type_does_not_matter"), |
229 REGULAR_FILE)); | 229 REGULAR_FILE)); |
230 } | 230 } |
231 | 231 |
232 // Sets the expectation for MockGDataFileSystem::UpdateFileByResourceId(), | 232 // Sets the expectation for MockGDataFileSystem::UpdateFileByResourceId(), |
233 // that simulates successful uploading of a file for the given resource ID. | 233 // that simulates successful uploading of a file for the given resource ID. |
234 void SetExpectationForUpdateFileByResourceId( | 234 void SetExpectationForUpdateFileByResourceId( |
235 const std::string& resource_id) { | 235 const std::string& resource_id) { |
236 EXPECT_CALL(*mock_file_system_, | 236 EXPECT_CALL(*mock_file_system_, |
237 UpdateFileByResourceId(resource_id, _)) | 237 UpdateFileByResourceId(resource_id, _)) |
238 .WillOnce(MockUpdateFileByResourceId(GDATA_FILE_OK)); | 238 .WillOnce(MockUpdateFileByResourceId(DRIVE_FILE_OK)); |
239 } | 239 } |
240 | 240 |
241 // Sets the expectation for MockGDataFileSystem::GetFileInfoByResourceId(), | 241 // Sets the expectation for MockGDataFileSystem::GetFileInfoByResourceId(), |
242 // that simulates successful retrieval of file info for the given resource | 242 // that simulates successful retrieval of file info for the given resource |
243 // ID. | 243 // ID. |
244 // | 244 // |
245 // This is used for testing StartCheckingExistingPinnedFiles(), hence we | 245 // This is used for testing StartCheckingExistingPinnedFiles(), hence we |
246 // are only interested in the MD5 value in DriveEntryProto. | 246 // are only interested in the MD5 value in DriveEntryProto. |
247 void SetExpectationForGetFileInfoByResourceId( | 247 void SetExpectationForGetFileInfoByResourceId( |
248 const std::string& resource_id, | 248 const std::string& resource_id, |
249 const std::string& new_md5) { | 249 const std::string& new_md5) { |
250 EXPECT_CALL(*mock_file_system_, | 250 EXPECT_CALL(*mock_file_system_, |
251 GetEntryInfoByResourceId(resource_id, _)) | 251 GetEntryInfoByResourceId(resource_id, _)) |
252 .WillOnce(MockUpdateFileByResourceId( | 252 .WillOnce(MockUpdateFileByResourceId( |
253 GDATA_FILE_OK, | 253 DRIVE_FILE_OK, |
254 new_md5)); | 254 new_md5)); |
255 } | 255 } |
256 | 256 |
257 // Returns the resource IDs in the queue to be fetched. | 257 // Returns the resource IDs in the queue to be fetched. |
258 std::vector<std::string> GetResourceIdsToBeFetched() { | 258 std::vector<std::string> GetResourceIdsToBeFetched() { |
259 return sync_client_->GetResourceIdsForTesting( | 259 return sync_client_->GetResourceIdsForTesting( |
260 GDataSyncClient::FETCH); | 260 GDataSyncClient::FETCH); |
261 } | 261 } |
262 | 262 |
263 // Returns the resource IDs in the queue to be uploaded. | 263 // Returns the resource IDs in the queue to be uploaded. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 FilePath::FromUTF8Unsafe("local_path_does_not_matter")); | 361 FilePath::FromUTF8Unsafe("local_path_does_not_matter")); |
362 const std::string mime_type("mime_type_does_not_matter"); | 362 const std::string mime_type("mime_type_does_not_matter"); |
363 SetUpTestFiles(); | 363 SetUpTestFiles(); |
364 ConnectToWifi(); | 364 ConnectToWifi(); |
365 AddResourceIdToFetch(resource_id); | 365 AddResourceIdToFetch(resource_id); |
366 | 366 |
367 // Disconnect from network on fetch try. | 367 // Disconnect from network on fetch try. |
368 EXPECT_CALL(*mock_file_system_, GetFileByResourceId(resource_id, _, _)) | 368 EXPECT_CALL(*mock_file_system_, GetFileByResourceId(resource_id, _, _)) |
369 .WillOnce(DoAll( | 369 .WillOnce(DoAll( |
370 InvokeWithoutArgs(this, &GDataSyncClientTest::ConnectToNone), | 370 InvokeWithoutArgs(this, &GDataSyncClientTest::ConnectToNone), |
371 MockGetFileByResourceId(GDATA_FILE_ERROR_NO_CONNECTION, | 371 MockGetFileByResourceId(DRIVE_FILE_ERROR_NO_CONNECTION, |
372 file_path, | 372 file_path, |
373 mime_type, | 373 mime_type, |
374 REGULAR_FILE))); | 374 REGULAR_FILE))); |
375 | 375 |
376 sync_client_->StartSyncLoop(); | 376 sync_client_->StartSyncLoop(); |
377 | 377 |
378 // Expect fetch retry on network reconnection. | 378 // Expect fetch retry on network reconnection. |
379 EXPECT_CALL(*mock_file_system_, GetFileByResourceId(resource_id, _, _)) | 379 EXPECT_CALL(*mock_file_system_, GetFileByResourceId(resource_id, _, _)) |
380 .WillOnce(MockGetFileByResourceId( | 380 .WillOnce(MockGetFileByResourceId( |
381 GDATA_FILE_OK, file_path, mime_type, REGULAR_FILE)); | 381 DRIVE_FILE_OK, file_path, mime_type, REGULAR_FILE)); |
382 | 382 |
383 ConnectToWifi(); | 383 ConnectToWifi(); |
384 } | 384 } |
385 | 385 |
386 TEST_F(GDataSyncClientTest, StartSyncLoop_CelluarDisabled) { | 386 TEST_F(GDataSyncClientTest, StartSyncLoop_CelluarDisabled) { |
387 SetUpTestFiles(); | 387 SetUpTestFiles(); |
388 ConnectToWifi(); // First connect to Wifi. | 388 ConnectToWifi(); // First connect to Wifi. |
389 | 389 |
390 AddResourceIdToFetch("resource_id_not_fetched_foo"); | 390 AddResourceIdToFetch("resource_id_not_fetched_foo"); |
391 AddResourceIdToFetch("resource_id_not_fetched_bar"); | 391 AddResourceIdToFetch("resource_id_not_fetched_bar"); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 ASSERT_EQ(1U, resource_ids.size()); | 565 ASSERT_EQ(1U, resource_ids.size()); |
566 EXPECT_EQ("resource_id_fetched", resource_ids[0]); | 566 EXPECT_EQ("resource_id_fetched", resource_ids[0]); |
567 // resource_id_dirty is not collected in the queue. | 567 // resource_id_dirty is not collected in the queue. |
568 | 568 |
569 // Check the contents of the queue for uploading. | 569 // Check the contents of the queue for uploading. |
570 resource_ids = GetResourceIdsToBeUploaded(); | 570 resource_ids = GetResourceIdsToBeUploaded(); |
571 ASSERT_TRUE(resource_ids.empty()); | 571 ASSERT_TRUE(resource_ids.empty()); |
572 } | 572 } |
573 | 573 |
574 } // namespace gdata | 574 } // namespace gdata |
OLD | NEW |