OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/wifi_sync/wifi_credential_syncable_service.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "sync/api/fake_sync_change_processor.h" |
| 9 #include "sync/api/sync_error_factory_mock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace wifi_sync { |
| 13 |
| 14 class WifiCredentialSyncableServiceTest : public testing::Test { |
| 15 void SetUp() { |
| 16 syncable_service_.reset(new WifiCredentialSyncableService(nullptr)); |
| 17 sync_change_processor_ = nullptr; |
| 18 sync_error_factory_ = nullptr; |
| 19 } |
| 20 |
| 21 protected: |
| 22 void StartSyncing() { |
| 23 auto change_processor = |
| 24 make_scoped_ptr(new syncer::FakeSyncChangeProcessor()); |
| 25 auto error_factory = make_scoped_ptr(new syncer::SyncErrorFactoryMock()); |
| 26 sync_change_processor_ = change_processor.get(); |
| 27 sync_error_factory_ = error_factory.get(); |
| 28 syncable_service_->MergeDataAndStartSyncing( |
| 29 WifiCredentialSyncableService::kModelType, |
| 30 syncer::SyncDataList(), |
| 31 make_scoped_ptr(change_processor.release()), |
| 32 make_scoped_ptr(error_factory.release())); |
| 33 } |
| 34 |
| 35 void StopSyncing() { |
| 36 syncable_service_->StopSyncing(WifiCredentialSyncableService::kModelType); |
| 37 } |
| 38 |
| 39 const WifiCredentialSyncableService &GetSyncableService() { |
| 40 return *syncable_service_; |
| 41 } |
| 42 |
| 43 syncer::SyncChangeProcessor* GetSyncChangeProcessor() { |
| 44 return syncable_service_->sync_processor_.get(); |
| 45 } |
| 46 |
| 47 syncer::SyncErrorFactory* GetSyncErrorFactory() { |
| 48 return syncable_service_->sync_error_handler_.get(); |
| 49 } |
| 50 |
| 51 const syncer::FakeSyncChangeProcessor* sync_change_processor() const { |
| 52 return sync_change_processor_; |
| 53 } |
| 54 |
| 55 const syncer::SyncErrorFactoryMock* sync_error_factory() const { |
| 56 return sync_error_factory_; |
| 57 } |
| 58 |
| 59 private: |
| 60 scoped_ptr<WifiCredentialSyncableService> syncable_service_; |
| 61 // When non-null, |fake_sync_change_processor_| and |
| 62 // |sync_error_factory_mock_| are owned by |syncable_service_|. |
| 63 syncer::FakeSyncChangeProcessor* sync_change_processor_; |
| 64 syncer::SyncErrorFactoryMock* sync_error_factory_; |
| 65 }; |
| 66 |
| 67 TEST_F(WifiCredentialSyncableServiceTest, |
| 68 StartSyncingSetsChangeProcessorAndErrorHandler) { |
| 69 StartSyncing(); |
| 70 EXPECT_EQ(sync_change_processor(), GetSyncChangeProcessor()); |
| 71 EXPECT_EQ(sync_error_factory(), GetSyncErrorFactory()); |
| 72 } |
| 73 |
| 74 TEST_F(WifiCredentialSyncableServiceTest, StopSyncingClearsNonConstFields) { |
| 75 StartSyncing(); |
| 76 StopSyncing(); |
| 77 EXPECT_EQ(nullptr, GetSyncChangeProcessor()); |
| 78 EXPECT_EQ(nullptr, GetSyncErrorFactory()); |
| 79 } |
| 80 |
| 81 } // namespace wifi_sync |
OLD | NEW |