| 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 "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/signin/signin_manager.h" | 10 #include "chrome/browser/signin/signin_manager.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); | 182 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); |
| 183 EXPECT_CALL(*data_type_manager, state()). | 183 EXPECT_CALL(*data_type_manager, state()). |
| 184 WillOnce(Return(DataTypeManager::CONFIGURED)). | 184 WillOnce(Return(DataTypeManager::CONFIGURED)). |
| 185 WillOnce(Return(DataTypeManager::CONFIGURED)); | 185 WillOnce(Return(DataTypeManager::CONFIGURED)); |
| 186 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 186 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
| 187 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 187 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 188 | 188 |
| 189 // Create some tokens in the token service; the service will startup when | 189 // Create some tokens in the token service; the service will startup when |
| 190 // it is notified that tokens are available. | 190 // it is notified that tokens are available. |
| 191 sync_->SetSetupInProgress(true); | 191 sync_->SetSetupInProgress(true); |
| 192 sync_->signin()->StartSignIn("test_user", "", "", ""); | 192 sync_->signin() |
| 193 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 193 ->StartSignIn("test_user", std::string(), std::string(), std::string()); |
| 194 GaiaConstants::kSyncService, "sync_token"); | 194 TokenServiceFactory::GetForProfile(profile_.get()) |
| 195 ->IssueAuthTokenForTest(GaiaConstants::kSyncService, "sync_token"); |
| 195 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 196 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 196 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 197 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
| 197 sync_->SetSetupInProgress(false); | 198 sync_->SetSetupInProgress(false); |
| 198 EXPECT_TRUE(sync_->ShouldPushChanges()); | 199 EXPECT_TRUE(sync_->ShouldPushChanges()); |
| 199 } | 200 } |
| 200 | 201 |
| 201 ProfileKeyedService* BuildFakeTokenService(Profile* profile) { | 202 ProfileKeyedService* BuildFakeTokenService(Profile* profile) { |
| 202 return new FakeTokenService(); | 203 return new FakeTokenService(); |
| 203 } | 204 } |
| 204 | 205 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 228 | 229 |
| 229 // Then start things up. | 230 // Then start things up. |
| 230 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); | 231 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); |
| 231 EXPECT_CALL(*data_type_manager, state()). | 232 EXPECT_CALL(*data_type_manager, state()). |
| 232 WillOnce(Return(DataTypeManager::CONFIGURED)). | 233 WillOnce(Return(DataTypeManager::CONFIGURED)). |
| 233 WillOnce(Return(DataTypeManager::CONFIGURED)); | 234 WillOnce(Return(DataTypeManager::CONFIGURED)); |
| 234 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 235 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
| 235 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 236 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 236 | 237 |
| 237 sync_->SetSetupInProgress(true); | 238 sync_->SetSetupInProgress(true); |
| 238 sync_->signin()->StartSignIn("test_user", "", "", ""); | 239 sync_->signin() |
| 240 ->StartSignIn("test_user", std::string(), std::string(), std::string()); |
| 239 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens. | 241 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens. |
| 240 token_service->LoadTokensFromDB(); | 242 token_service->LoadTokensFromDB(); |
| 241 sync_->SetSetupInProgress(false); | 243 sync_->SetSetupInProgress(false); |
| 242 // Backend should initialize using a bogus GAIA token for credentials. | 244 // Backend should initialize using a bogus GAIA token for credentials. |
| 243 EXPECT_TRUE(sync_->ShouldPushChanges()); | 245 EXPECT_TRUE(sync_->ShouldPushChanges()); |
| 244 } | 246 } |
| 245 | 247 |
| 246 TEST_F(ProfileSyncServiceStartupTest, StartInvalidCredentials) { | 248 TEST_F(ProfileSyncServiceStartupTest, StartInvalidCredentials) { |
| 247 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 249 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
| 248 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); | 250 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 262 EXPECT_FALSE(sync_->ShouldPushChanges()); | 264 EXPECT_FALSE(sync_->ShouldPushChanges()); |
| 263 Mock::VerifyAndClearExpectations(data_type_manager); | 265 Mock::VerifyAndClearExpectations(data_type_manager); |
| 264 | 266 |
| 265 // Update the credentials, unstalling the backend. | 267 // Update the credentials, unstalling the backend. |
| 266 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 268 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
| 267 EXPECT_CALL(*data_type_manager, state()). | 269 EXPECT_CALL(*data_type_manager, state()). |
| 268 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 270 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
| 269 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 271 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
| 270 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 272 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 271 sync_->SetSetupInProgress(true); | 273 sync_->SetSetupInProgress(true); |
| 272 sync_->signin()->StartSignIn("test_user", "", "", ""); | 274 sync_->signin() |
| 273 token_service->IssueAuthTokenForTest( | 275 ->StartSignIn("test_user", std::string(), std::string(), std::string()); |
| 274 GaiaConstants::kSyncService, "sync_token"); | 276 token_service->IssueAuthTokenForTest(GaiaConstants::kSyncService, |
| 277 "sync_token"); |
| 275 sync_->SetSetupInProgress(false); | 278 sync_->SetSetupInProgress(false); |
| 276 MessageLoop::current()->Run(); | 279 MessageLoop::current()->Run(); |
| 277 | 280 |
| 278 // Verify we successfully finish startup and configuration. | 281 // Verify we successfully finish startup and configuration. |
| 279 EXPECT_TRUE(sync_->ShouldPushChanges()); | 282 EXPECT_TRUE(sync_->ShouldPushChanges()); |
| 280 } | 283 } |
| 281 | 284 |
| 282 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { | 285 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { |
| 283 EXPECT_CALL(*sync_->components_factory_mock(), | 286 EXPECT_CALL(*sync_->components_factory_mock(), |
| 284 CreateDataTypeManager(_, _, _, _, _)).Times(0); | 287 CreateDataTypeManager(_, _, _, _, _)).Times(0); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 | 467 |
| 465 // Preload the tokens. | 468 // Preload the tokens. |
| 466 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 469 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 467 GaiaConstants::kSyncService, "sync_token"); | 470 GaiaConstants::kSyncService, "sync_token"); |
| 468 sync_->fail_initial_download(); | 471 sync_->fail_initial_download(); |
| 469 | 472 |
| 470 sync_->Initialize(); | 473 sync_->Initialize(); |
| 471 EXPECT_FALSE(sync_->sync_initialized()); | 474 EXPECT_FALSE(sync_->sync_initialized()); |
| 472 EXPECT_FALSE(sync_->GetBackendForTest()); | 475 EXPECT_FALSE(sync_->GetBackendForTest()); |
| 473 } | 476 } |
| OLD | NEW |