| 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 "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/sync/profile_sync_service_factory.h" | 10 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) | 48 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) |
| 49 .WillByDefault(Return(syncer::ModelTypeSet())); | 49 .WillByDefault(Return(syncer::ModelTypeSet())); |
| 50 mock_pss_->Initialize(); | 50 mock_pss_->Initialize(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void TearDown() override { profile_.reset(); } | 53 void TearDown() override { profile_.reset(); } |
| 54 | 54 |
| 55 void SetupNonInitializedPSS() { | 55 void SetupNonInitializedPSS() { |
| 56 EXPECT_CALL(*mock_pss_, GetAuthError()) | 56 EXPECT_CALL(*mock_pss_, GetAuthError()) |
| 57 .WillRepeatedly(ReturnRef(no_error_)); | 57 .WillRepeatedly(ReturnRef(no_error_)); |
| 58 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) | 58 EXPECT_CALL(*mock_pss_, IsEngineInitialized()) |
| 59 .WillRepeatedly(Return(false)); | 59 .WillRepeatedly(Return(false)); |
| 60 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) | 60 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) |
| 61 .WillRepeatedly(Return(false)); | 61 .WillRepeatedly(Return(false)); |
| 62 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 62 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 content::TestBrowserThreadBundle thread_bundle_; | 65 content::TestBrowserThreadBundle thread_bundle_; |
| 66 GoogleServiceAuthError no_error_; | 66 GoogleServiceAuthError no_error_; |
| 67 std::unique_ptr<TestingProfile> profile_; | 67 std::unique_ptr<TestingProfile> profile_; |
| 68 browser_sync::ProfileSyncServiceMock* mock_pss_; | 68 browser_sync::ProfileSyncServiceMock* mock_pss_; |
| 69 MockObserver observer_; | 69 MockObserver observer_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 TEST_F(SyncStartupTrackerTest, SyncAlreadyInitialized) { | 72 TEST_F(SyncStartupTrackerTest, SyncAlreadyInitialized) { |
| 73 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(true)); | 73 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(true)); |
| 74 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 74 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 75 EXPECT_CALL(observer_, SyncStartupCompleted()); | 75 EXPECT_CALL(observer_, SyncStartupCompleted()); |
| 76 SyncStartupTracker tracker(profile_.get(), &observer_); | 76 SyncStartupTracker tracker(profile_.get(), &observer_); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST_F(SyncStartupTrackerTest, SyncNotSignedIn) { | 79 TEST_F(SyncStartupTrackerTest, SyncNotSignedIn) { |
| 80 // Make sure that we get a SyncStartupFailed() callback if sync is not logged | 80 // Make sure that we get a SyncStartupFailed() callback if sync is not logged |
| 81 // in. | 81 // in. |
| 82 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 82 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); |
| 83 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); | 83 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); |
| 84 EXPECT_CALL(observer_, SyncStartupFailed()); | 84 EXPECT_CALL(observer_, SyncStartupFailed()); |
| 85 SyncStartupTracker tracker(profile_.get(), &observer_); | 85 SyncStartupTracker tracker(profile_.get(), &observer_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 TEST_F(SyncStartupTrackerTest, SyncAuthError) { | 88 TEST_F(SyncStartupTrackerTest, SyncAuthError) { |
| 89 // Make sure that we get a SyncStartupFailed() callback if sync gets an auth | 89 // Make sure that we get a SyncStartupFailed() callback if sync gets an auth |
| 90 // error. | 90 // error. |
| 91 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 91 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); |
| 92 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 92 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 93 GoogleServiceAuthError error( | 93 GoogleServiceAuthError error( |
| 94 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 94 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 95 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 95 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
| 96 EXPECT_CALL(observer_, SyncStartupFailed()); | 96 EXPECT_CALL(observer_, SyncStartupFailed()); |
| 97 SyncStartupTracker tracker(profile_.get(), &observer_); | 97 SyncStartupTracker tracker(profile_.get(), &observer_); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(SyncStartupTrackerTest, SyncDelayedInitialization) { | 100 TEST_F(SyncStartupTrackerTest, SyncDelayedInitialization) { |
| 101 // Non-initialized PSS should result in no callbacks to the observer. | 101 // Non-initialized PSS should result in no callbacks to the observer. |
| 102 SetupNonInitializedPSS(); | 102 SetupNonInitializedPSS(); |
| 103 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0); | 103 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0); |
| 104 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0); | 104 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0); |
| 105 SyncStartupTracker tracker(profile_.get(), &observer_); | 105 SyncStartupTracker tracker(profile_.get(), &observer_); |
| 106 Mock::VerifyAndClearExpectations(&observer_); | 106 Mock::VerifyAndClearExpectations(&observer_); |
| 107 // Now, mark the PSS as initialized. | 107 // Now, mark the PSS as initialized. |
| 108 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(true)); | 108 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(true)); |
| 109 EXPECT_CALL(observer_, SyncStartupCompleted()); | 109 EXPECT_CALL(observer_, SyncStartupCompleted()); |
| 110 tracker.OnStateChanged(); | 110 tracker.OnStateChanged(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 TEST_F(SyncStartupTrackerTest, SyncDelayedAuthError) { | 113 TEST_F(SyncStartupTrackerTest, SyncDelayedAuthError) { |
| 114 // Non-initialized PSS should result in no callbacks to the observer. | 114 // Non-initialized PSS should result in no callbacks to the observer. |
| 115 SetupNonInitializedPSS(); | 115 SetupNonInitializedPSS(); |
| 116 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0); | 116 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0); |
| 117 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0); | 117 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0); |
| 118 SyncStartupTracker tracker(profile_.get(), &observer_); | 118 SyncStartupTracker tracker(profile_.get(), &observer_); |
| 119 Mock::VerifyAndClearExpectations(&observer_); | 119 Mock::VerifyAndClearExpectations(&observer_); |
| 120 Mock::VerifyAndClearExpectations(mock_pss_); | 120 Mock::VerifyAndClearExpectations(mock_pss_); |
| 121 | 121 |
| 122 // Now, mark the PSS as having an auth error. | 122 // Now, mark the PSS as having an auth error. |
| 123 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 123 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); |
| 124 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 124 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 125 GoogleServiceAuthError error( | 125 GoogleServiceAuthError error( |
| 126 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 126 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 127 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 127 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
| 128 EXPECT_CALL(observer_, SyncStartupFailed()); | 128 EXPECT_CALL(observer_, SyncStartupFailed()); |
| 129 tracker.OnStateChanged(); | 129 tracker.OnStateChanged(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 TEST_F(SyncStartupTrackerTest, SyncDelayedUnrecoverableError) { | 132 TEST_F(SyncStartupTrackerTest, SyncDelayedUnrecoverableError) { |
| 133 // Non-initialized PSS should result in no callbacks to the observer. | 133 // Non-initialized PSS should result in no callbacks to the observer. |
| 134 SetupNonInitializedPSS(); | 134 SetupNonInitializedPSS(); |
| 135 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0); | 135 EXPECT_CALL(observer_, SyncStartupCompleted()).Times(0); |
| 136 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0); | 136 EXPECT_CALL(observer_, SyncStartupFailed()).Times(0); |
| 137 SyncStartupTracker tracker(profile_.get(), &observer_); | 137 SyncStartupTracker tracker(profile_.get(), &observer_); |
| 138 Mock::VerifyAndClearExpectations(&observer_); | 138 Mock::VerifyAndClearExpectations(&observer_); |
| 139 Mock::VerifyAndClearExpectations(mock_pss_); | 139 Mock::VerifyAndClearExpectations(mock_pss_); |
| 140 | 140 |
| 141 // Now, mark the PSS as having an unrecoverable error. | 141 // Now, mark the PSS as having an unrecoverable error. |
| 142 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); | 142 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); |
| 143 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); | 143 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); |
| 144 GoogleServiceAuthError error( | 144 GoogleServiceAuthError error( |
| 145 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 145 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 146 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); | 146 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error)); |
| 147 EXPECT_CALL(observer_, SyncStartupFailed()); | 147 EXPECT_CALL(observer_, SyncStartupFailed()); |
| 148 tracker.OnStateChanged(); | 148 tracker.OnStateChanged(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace | 151 } // namespace |
| OLD | NEW |