OLD | NEW |
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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/signin/signin_manager.h" | 10 #include "chrome/browser/signin/signin_manager.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 155 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
156 GaiaConstants::kSyncService, "sync_token"); | 156 GaiaConstants::kSyncService, "sync_token"); |
157 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 157 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
158 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 158 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
159 service_->set_setup_in_progress(false); | 159 service_->set_setup_in_progress(false); |
160 service_->OnUserChoseDatatypes( | 160 service_->OnUserChoseDatatypes( |
161 false, syncable::ModelTypeSet(syncable::BOOKMARKS)); | 161 false, syncable::ModelTypeSet(syncable::BOOKMARKS)); |
162 EXPECT_TRUE(service_->ShouldPushChanges()); | 162 EXPECT_TRUE(service_->ShouldPushChanges()); |
163 } | 163 } |
164 | 164 |
| 165 TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) { |
| 166 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
| 167 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); |
| 168 |
| 169 // We've never completed startup. |
| 170 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); |
| 171 // Make sure SigninManager doesn't think we're signed in (undoes the call to |
| 172 // SetAuthenticatedUsername() in CreateSyncService()). |
| 173 SigninManagerFactory::GetForProfile(profile_.get())->SignOut(); |
| 174 |
| 175 // Should not actually start, rather just clean things up and wait |
| 176 // to be enabled. |
| 177 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 178 service_->Initialize(); |
| 179 EXPECT_FALSE(service_->GetBackendForTest()); |
| 180 |
| 181 // Preferences should be back to defaults. |
| 182 EXPECT_EQ(0, profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); |
| 183 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)); |
| 184 Mock::VerifyAndClearExpectations(data_type_manager); |
| 185 |
| 186 // Then start things up. |
| 187 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); |
| 188 EXPECT_CALL(*data_type_manager, state()). |
| 189 WillOnce(Return(DataTypeManager::CONFIGURED)). |
| 190 WillOnce(Return(DataTypeManager::CONFIGURED)); |
| 191 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
| 192 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 193 |
| 194 service_->set_setup_in_progress(true); |
| 195 service_->signin()->StartSignIn("test_user", "", "", ""); |
| 196 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens. |
| 197 content::NotificationService::current()->Notify( |
| 198 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
| 199 content::Source<TokenService>( |
| 200 TokenServiceFactory::GetForProfile(profile_.get())), |
| 201 content::NotificationService::NoDetails()); |
| 202 service_->set_setup_in_progress(false); |
| 203 service_->OnUserChoseDatatypes( |
| 204 false, syncable::ModelTypeSet(syncable::BOOKMARKS)); |
| 205 // Backend should initialize using a bogus GAIA token for credentials. |
| 206 EXPECT_TRUE(service_->ShouldPushChanges()); |
| 207 } |
| 208 |
| 209 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { |
| 210 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _)).Times(0); |
| 211 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); |
| 212 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 213 |
| 214 service_->Initialize(); |
| 215 // Sync should not start because there are no tokens yet. |
| 216 EXPECT_FALSE(service_->ShouldPushChanges()); |
| 217 EXPECT_FALSE(service_->GetBackendForTest()); |
| 218 content::NotificationService::current()->Notify( |
| 219 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED, |
| 220 content::Source<TokenService>( |
| 221 TokenServiceFactory::GetForProfile(profile_.get())), |
| 222 content::NotificationService::NoDetails()); |
| 223 service_->set_setup_in_progress(false); |
| 224 // Sync should not start because there are still no tokens. |
| 225 EXPECT_FALSE(service_->ShouldPushChanges()); |
| 226 EXPECT_FALSE(service_->GetBackendForTest()); |
| 227 } |
| 228 |
165 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { | 229 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { |
166 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 230 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
167 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); | 231 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); |
168 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 232 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
169 EXPECT_CALL(*data_type_manager, state()). | 233 EXPECT_CALL(*data_type_manager, state()). |
170 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 234 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
171 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 235 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
172 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 236 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
173 | 237 |
174 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 238 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 400 |
337 // Preload the tokens. | 401 // Preload the tokens. |
338 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 402 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
339 GaiaConstants::kSyncService, "sync_token"); | 403 GaiaConstants::kSyncService, "sync_token"); |
340 service_->fail_initial_download(); | 404 service_->fail_initial_download(); |
341 | 405 |
342 service_->Initialize(); | 406 service_->Initialize(); |
343 EXPECT_FALSE(service_->sync_initialized()); | 407 EXPECT_FALSE(service_->sync_initialized()); |
344 EXPECT_FALSE(service_->GetBackendForTest()); | 408 EXPECT_FALSE(service_->GetBackendForTest()); |
345 } | 409 } |
OLD | NEW |