| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/sync/sync_startup_tracker.h" | 5 #include "chrome/browser/sync/sync_startup_tracker.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "chrome/browser/sync/profile_sync_service_factory.h" | 9 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 10 #include "chrome/browser/sync/profile_sync_test_util.h" | 10 #include "chrome/browser/sync/profile_sync_test_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 MOCK_METHOD0(SyncStartupFailed, void(void)); | 27 MOCK_METHOD0(SyncStartupFailed, void(void)); |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 class SyncStartupTrackerTest : public testing::Test { | 30 class SyncStartupTrackerTest : public testing::Test { |
| 31 public: | 31 public: |
| 32 SyncStartupTrackerTest() : | 32 SyncStartupTrackerTest() : |
| 33 no_error_(GoogleServiceAuthError::NONE) { | 33 no_error_(GoogleServiceAuthError::NONE) { |
| 34 } | 34 } |
| 35 void SetUp() override { | 35 void SetUp() override { |
| 36 profile_.reset(new TestingProfile()); | 36 profile_.reset(new TestingProfile()); |
| 37 mock_pss_ = static_cast<ProfileSyncServiceMock*>( | 37 mock_pss_ = static_cast<browser_sync::ProfileSyncServiceMock*>( |
| 38 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 38 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 39 profile_.get(), BuildMockProfileSyncService)); | 39 profile_.get(), BuildMockProfileSyncService)); |
| 40 | 40 |
| 41 // Make gmock not spam the output with information about these uninteresting | 41 // Make gmock not spam the output with information about these uninteresting |
| 42 // calls. | 42 // calls. |
| 43 EXPECT_CALL(*mock_pss_, AddObserver(_)).Times(AnyNumber()); | 43 EXPECT_CALL(*mock_pss_, AddObserver(_)).Times(AnyNumber()); |
| 44 EXPECT_CALL(*mock_pss_, RemoveObserver(_)).Times(AnyNumber()); | 44 EXPECT_CALL(*mock_pss_, RemoveObserver(_)).Times(AnyNumber()); |
| 45 EXPECT_CALL(*mock_pss_, GetAuthError()). | 45 EXPECT_CALL(*mock_pss_, GetAuthError()). |
| 46 WillRepeatedly(ReturnRef(no_error_)); | 46 WillRepeatedly(ReturnRef(no_error_)); |
| 47 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) | 47 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) |
| 48 .WillByDefault(Return(syncer::ModelTypeSet())); | 48 .WillByDefault(Return(syncer::ModelTypeSet())); |
| 49 mock_pss_->Initialize(); | 49 mock_pss_->Initialize(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void TearDown() override { profile_.reset(); } | 52 void TearDown() override { profile_.reset(); } |
| 53 | 53 |
| 54 void SetupNonInitializedPSS() { | 54 void SetupNonInitializedPSS() { |
| 55 EXPECT_CALL(*mock_pss_, GetAuthError()) | 55 EXPECT_CALL(*mock_pss_, GetAuthError()) |
| 56 .WillRepeatedly(ReturnRef(no_error_)); | 56 .WillRepeatedly(ReturnRef(no_error_)); |
| 57 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) | 57 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) |
| 58 .WillRepeatedly(Return(false)); | 58 .WillRepeatedly(Return(false)); |
| 59 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 59 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 60 .WillRepeatedly(Return(false)); | 60 .WillRepeatedly(Return(false)); |
| 61 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 61 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 content::TestBrowserThreadBundle thread_bundle_; | 64 content::TestBrowserThreadBundle thread_bundle_; |
| 65 GoogleServiceAuthError no_error_; | 65 GoogleServiceAuthError no_error_; |
| 66 std::unique_ptr<TestingProfile> profile_; | 66 std::unique_ptr<TestingProfile> profile_; |
| 67 ProfileSyncServiceMock* mock_pss_; | 67 browser_sync::ProfileSyncServiceMock* mock_pss_; |
| 68 MockObserver observer_; | 68 MockObserver observer_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 TEST_F(SyncStartupTrackerTest, SyncAlreadyInitialized) { | 71 TEST_F(SyncStartupTrackerTest, SyncAlreadyInitialized) { |
| 72 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(true)); | 72 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(true)); |
| 73 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 73 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 74 EXPECT_CALL(observer_, SyncStartupCompleted()); | 74 EXPECT_CALL(observer_, SyncStartupCompleted()); |
| 75 SyncStartupTracker tracker(profile_.get(), &observer_); | 75 SyncStartupTracker tracker(profile_.get(), &observer_); |
| 76 } | 76 } |
| 77 | 77 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 141 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); |
| 142 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 142 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 143 GoogleServiceAuthError error( | 143 GoogleServiceAuthError error( |
| 144 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 144 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 145 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 145 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
| 146 EXPECT_CALL(observer_, SyncStartupFailed()); | 146 EXPECT_CALL(observer_, SyncStartupFailed()); |
| 147 tracker.OnStateChanged(); | 147 tracker.OnStateChanged(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace | 150 } // namespace |
| OLD | NEW |