Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service_mock_unittest.cc

Issue 14322009: Sync FileSystem: Add default mock expectation for MockDriveService::GetChangeList (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/StrictMock/NiceMock/ Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/google_apis/mock_drive_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/sync_file_system/drive_file_sync_service.h" 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 23 matching lines...) Expand all
34 #include "webkit/fileapi/syncable/sync_file_metadata.h" 34 #include "webkit/fileapi/syncable/sync_file_metadata.h"
35 #include "webkit/fileapi/syncable/syncable_file_system_util.h" 35 #include "webkit/fileapi/syncable/syncable_file_system_util.h"
36 36
37 #define FPL(x) FILE_PATH_LITERAL(x) 37 #define FPL(x) FILE_PATH_LITERAL(x)
38 38
39 using ::testing::AnyNumber; 39 using ::testing::AnyNumber;
40 using ::testing::AtLeast; 40 using ::testing::AtLeast;
41 using ::testing::AtMost; 41 using ::testing::AtMost;
42 using ::testing::InSequence; 42 using ::testing::InSequence;
43 using ::testing::Return; 43 using ::testing::Return;
44 using ::testing::NiceMock;
44 using ::testing::Sequence; 45 using ::testing::Sequence;
45 using ::testing::StrictMock; 46 using ::testing::StrictMock;
46 using ::testing::_; 47 using ::testing::_;
47 48
48 using google_apis::ResourceEntry; 49 using google_apis::ResourceEntry;
49 using google_apis::DriveServiceInterface; 50 using google_apis::DriveServiceInterface;
50 using google_apis::DriveUploaderInterface; 51 using google_apis::DriveUploaderInterface;
51 using google_apis::test_util::LoadJSONFile; 52 using google_apis::test_util::LoadJSONFile;
52 53
53 using extensions::Extension; 54 using extensions::Extension;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 ACTION(InvokeDidDownloadFile) { 198 ACTION(InvokeDidDownloadFile) {
198 base::MessageLoopProxy::current()->PostTask( 199 base::MessageLoopProxy::current()->PostTask(
199 FROM_HERE, base::Bind(arg3, google_apis::HTTP_SUCCESS, arg1)); 200 FROM_HERE, base::Bind(arg3, google_apis::HTTP_SUCCESS, arg1));
200 } 201 }
201 202
202 ACTION(InvokeDidApplyRemoteChange) { 203 ACTION(InvokeDidApplyRemoteChange) {
203 base::MessageLoopProxy::current()->PostTask( 204 base::MessageLoopProxy::current()->PostTask(
204 FROM_HERE, base::Bind(arg3, SYNC_STATUS_OK)); 205 FROM_HERE, base::Bind(arg3, SYNC_STATUS_OK));
205 } 206 }
206 207
207 ACTION(InvokeGetChangeListWithEmptyChange) {
208 scoped_ptr<google_apis::ResourceList> resource_list(
209 new google_apis::ResourceList());
210 base::MessageLoopProxy::current()->PostTask(
211 FROM_HERE, base::Bind(arg1, google_apis::HTTP_SUCCESS,
212 base::Passed(&resource_list)));
213 }
214
215 } // namespace 208 } // namespace
216 209
217 class MockRemoteServiceObserver : public RemoteFileSyncService::Observer { 210 class MockRemoteServiceObserver : public RemoteFileSyncService::Observer {
218 public: 211 public:
219 MockRemoteServiceObserver() {} 212 MockRemoteServiceObserver() {}
220 virtual ~MockRemoteServiceObserver() {} 213 virtual ~MockRemoteServiceObserver() {}
221 214
222 // LocalChangeProcessor override. 215 // LocalChangeProcessor override.
223 MOCK_METHOD1(OnRemoteChangeQueueUpdated, 216 MOCK_METHOD1(OnRemoteChangeQueueUpdated,
224 void(int64 pending_changes)); 217 void(int64 pending_changes));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 extension_system->CreateExtensionService( 250 extension_system->CreateExtensionService(
258 CommandLine::ForCurrentProcess(), base::FilePath(), false); 251 CommandLine::ForCurrentProcess(), base::FilePath(), false);
259 extension_service_ = extension_system->Get( 252 extension_service_ = extension_system->Get(
260 profile_.get())->extension_service(); 253 profile_.get())->extension_service();
261 254
262 AddTestExtension(extension_service_, FPL("example1")); 255 AddTestExtension(extension_service_, FPL("example1"));
263 AddTestExtension(extension_service_, FPL("example2")); 256 AddTestExtension(extension_service_, FPL("example2"));
264 257
265 ASSERT_TRUE(RegisterSyncableFileSystem(kServiceName)); 258 ASSERT_TRUE(RegisterSyncableFileSystem(kServiceName));
266 259
267 mock_drive_service_ = new StrictMock<google_apis::MockDriveService>; 260 mock_drive_service_ = new NiceMock<google_apis::MockDriveService>;
268 261
269 EXPECT_CALL(*mock_drive_service(), Initialize(profile_.get())); 262 EXPECT_CALL(*mock_drive_service(), Initialize(profile_.get()));
270 EXPECT_CALL(*mock_drive_service(), AddObserver(_)); 263 EXPECT_CALL(*mock_drive_service(), AddObserver(_));
271 264
272 // Expect to call GetRootResourceId and RemoveResourceFromDirectory to 265 // Expect to call GetRootResourceId and RemoveResourceFromDirectory to
273 // ensure the sync root directory is not in 'My Drive' directory. 266 // ensure the sync root directory is not in 'My Drive' directory.
274 EXPECT_CALL(*mock_drive_service(), GetRootResourceId()) 267 EXPECT_CALL(*mock_drive_service(), GetRootResourceId())
275 .WillRepeatedly(Return(kRootResourceId)); 268 .WillRepeatedly(Return(kRootResourceId));
276 EXPECT_CALL(*mock_drive_service(), 269 EXPECT_CALL(*mock_drive_service(),
277 RemoveResourceFromDirectory(kRootResourceId, _, _)) 270 RemoveResourceFromDirectory(kRootResourceId, _, _))
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 return sync_client_.get(); 423 return sync_client_.get();
431 return sync_service_->sync_client_.get(); 424 return sync_service_->sync_client_.get();
432 } 425 }
433 426
434 DriveMetadataStore* metadata_store() { 427 DriveMetadataStore* metadata_store() {
435 if (metadata_store_) 428 if (metadata_store_)
436 return metadata_store_.get(); 429 return metadata_store_.get();
437 return sync_service_->metadata_store_.get(); 430 return sync_service_->metadata_store_.get();
438 } 431 }
439 432
440 StrictMock<google_apis::MockDriveService>* mock_drive_service() { 433 NiceMock<google_apis::MockDriveService>* mock_drive_service() {
441 return mock_drive_service_; 434 return mock_drive_service_;
442 } 435 }
443 436
444 StrictMock<MockRemoteServiceObserver>* mock_remote_observer() { 437 StrictMock<MockRemoteServiceObserver>* mock_remote_observer() {
445 return &mock_remote_observer_; 438 return &mock_remote_observer_;
446 } 439 }
447 440
448 StrictMock<MockFileStatusObserver>* mock_file_status_observer() { 441 StrictMock<MockFileStatusObserver>* mock_file_status_observer() {
449 return &mock_file_status_observer_; 442 return &mock_file_status_observer_;
450 } 443 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 = google_apis::ResourceEntry::ExtractAndParse( 620 = google_apis::ResourceEntry::ExtractAndParse(
628 *origin_directory_created_value); 621 *origin_directory_created_value);
629 EXPECT_CALL(*mock_drive_service(), 622 EXPECT_CALL(*mock_drive_service(),
630 AddNewDirectory(parent_directory, directory_name, _)) 623 AddNewDirectory(parent_directory, directory_name, _))
631 .WillOnce(InvokeGetResourceEntryCallback2( 624 .WillOnce(InvokeGetResourceEntryCallback2(
632 google_apis::HTTP_SUCCESS, 625 google_apis::HTTP_SUCCESS,
633 base::Passed(&origin_directory_created))) 626 base::Passed(&origin_directory_created)))
634 .RetiresOnSaturation(); 627 .RetiresOnSaturation();
635 } 628 }
636 629
637 void SetUpDriveServiceExpectCallsForEmptyRemoteChange() {
638 EXPECT_CALL(*mock_drive_service(),
639 GetChangeList(_, _))
640 .WillOnce(InvokeGetChangeListWithEmptyChange())
641 .RetiresOnSaturation();
642 }
643
644 // End of mock setup helpers ----------------------------------------------- 630 // End of mock setup helpers -----------------------------------------------
645 631
646 private: 632 private:
647 MessageLoop message_loop_; 633 MessageLoop message_loop_;
648 content::TestBrowserThread ui_thread_; 634 content::TestBrowserThread ui_thread_;
649 content::TestBrowserThread file_thread_; 635 content::TestBrowserThread file_thread_;
650 636
651 base::ScopedTempDir base_dir_; 637 base::ScopedTempDir base_dir_;
652 scoped_ptr<TestingProfile> profile_; 638 scoped_ptr<TestingProfile> profile_;
653 639
654 scoped_ptr<DriveFileSyncService> sync_service_; 640 scoped_ptr<DriveFileSyncService> sync_service_;
655 641
656 // Not owned. 642 // Not owned.
657 ExtensionService* extension_service_; 643 ExtensionService* extension_service_;
658 644
659 // Owned by |sync_client_|. 645 // Owned by |sync_client_|.
660 StrictMock<google_apis::MockDriveService>* mock_drive_service_; 646 NiceMock<google_apis::MockDriveService>* mock_drive_service_;
661 647
662 StrictMock<MockRemoteServiceObserver> mock_remote_observer_; 648 StrictMock<MockRemoteServiceObserver> mock_remote_observer_;
663 StrictMock<MockFileStatusObserver> mock_file_status_observer_; 649 StrictMock<MockFileStatusObserver> mock_file_status_observer_;
664 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_; 650 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_;
665 651
666 scoped_ptr<DriveFileSyncClient> sync_client_; 652 scoped_ptr<DriveFileSyncClient> sync_client_;
667 scoped_ptr<DriveMetadataStore> metadata_store_; 653 scoped_ptr<DriveMetadataStore> metadata_store_;
668 654
669 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest); 655 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest);
670 }; 656 };
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin)); 740 DriveFileSyncClient::OriginToDirectoryTitle(kOrigin));
755 741
756 // Once the directory is created GetAboutResource should be called to get 742 // Once the directory is created GetAboutResource should be called to get
757 // the largest changestamp for the origin as a prepariation of the batch sync. 743 // the largest changestamp for the origin as a prepariation of the batch sync.
758 SetUpDriveServiceExpectCallsForGetAboutResource(); 744 SetUpDriveServiceExpectCallsForGetAboutResource();
759 745
760 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( 746 SetUpDriveServiceExpectCallsForGetResourceListInDirectory(
761 "chromeos/sync_file_system/listing_files_in_empty_directory.json", 747 "chromeos/sync_file_system/listing_files_in_empty_directory.json",
762 kDirectoryResourceId); 748 kDirectoryResourceId);
763 749
764 SetUpDriveServiceExpectCallsForEmptyRemoteChange();
765
766 SetUpDriveSyncService(true); 750 SetUpDriveSyncService(true);
767 bool done = false; 751 bool done = false;
768 sync_service()->RegisterOriginForTrackingChanges( 752 sync_service()->RegisterOriginForTrackingChanges(
769 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); 753 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
770 message_loop()->RunUntilIdle(); 754 message_loop()->RunUntilIdle();
771 EXPECT_TRUE(done); 755 EXPECT_TRUE(done);
772 756
773 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); 757 VerifySizeOfRegisteredOrigins(0u, 1u, 0u);
774 EXPECT_TRUE(pending_changes().empty()); 758 EXPECT_TRUE(pending_changes().empty());
775 } 759 }
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); 1286 entry->set_kind(google_apis::ENTRY_KIND_FOLDER);
1303 1287
1304 // Expect to drop this change for file. 1288 // Expect to drop this change for file.
1305 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( 1289 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry(
1306 kOrigin, *entry, 1)); 1290 kOrigin, *entry, 1));
1307 } 1291 }
1308 1292
1309 #endif // !defined(OS_ANDROID) 1293 #endif // !defined(OS_ANDROID)
1310 1294
1311 } // namespace sync_file_system 1295 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/mock_drive_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698