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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_, IsEngineInitialized()).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(mock_pss_); |
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_, IsEngineInitialized()).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(mock_pss_); |
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_, IsEngineInitialized()).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(mock_pss_); |
149 } | 149 } |
150 | 150 |
151 } // namespace | 151 } // namespace |
OLD | NEW |