Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: chrome/browser/sync/profile_sync_service_startup_unittest.cc

Issue 11428125: [Sync] Fix auth error handling while the backend is initializing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 service_->SetSetupInProgress(true); 229 service_->SetSetupInProgress(true);
230 service_->signin()->StartSignIn("test_user", "", "", ""); 230 service_->signin()->StartSignIn("test_user", "", "", "");
231 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens. 231 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens.
232 token_service->LoadTokensFromDB(); 232 token_service->LoadTokensFromDB();
233 service_->SetSetupInProgress(false); 233 service_->SetSetupInProgress(false);
234 // Backend should initialize using a bogus GAIA token for credentials. 234 // Backend should initialize using a bogus GAIA token for credentials.
235 EXPECT_TRUE(service_->ShouldPushChanges()); 235 EXPECT_TRUE(service_->ShouldPushChanges());
236 } 236 }
237 237
238 TEST_F(ProfileSyncServiceStartupTest, StartInvalidCredentials) {
239 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
240 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
241 TokenService* token_service = static_cast<TokenService*>(
242 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
243 profile_.get(), BuildFakeTokenService));
244 token_service->LoadTokensFromDB();
245
246 // Tell the backend to stall while downloading control types (simulating an
247 // auth error).
248 service_->fail_initial_download();
249
250 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
251 service_->Initialize();
252 EXPECT_TRUE(service_->GetBackendForTest());
253 EXPECT_FALSE(service_->sync_initialized());
254 EXPECT_FALSE(service_->ShouldPushChanges());
255 Mock::VerifyAndClearExpectations(data_type_manager);
256
257 // Update the credentials, unstalling the backend.
258 EXPECT_CALL(*data_type_manager, Configure(_, _));
259 EXPECT_CALL(*data_type_manager, state()).
260 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
261 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
262 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
263 service_->SetSetupInProgress(true);
264 service_->signin()->StartSignIn("test_user", "", "", "");
265 token_service->IssueAuthTokenForTest(
266 GaiaConstants::kSyncService, "sync_token");
267 service_->SetSetupInProgress(false);
268 MessageLoop::current()->Run();
269
270 // Verify we successfully finish startup and configuration.
271 EXPECT_TRUE(service_->ShouldPushChanges());
272 }
273
238 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { 274 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) {
239 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _, _)).Times(0); 275 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _, _)).Times(0);
240 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); 276 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
241 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 277 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
242 TokenService* token_service = static_cast<TokenService*>( 278 TokenService* token_service = static_cast<TokenService*>(
243 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse( 279 TokenServiceFactory::GetInstance()->SetTestingFactoryAndUse(
244 profile_.get(), BuildFakeTokenService)); 280 profile_.get(), BuildFakeTokenService));
245 281
246 service_->Initialize(); 282 service_->Initialize();
247 // Sync should not start because there are no tokens yet. 283 // Sync should not start because there are no tokens yet.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 452
417 // Preload the tokens. 453 // Preload the tokens.
418 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 454 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
419 GaiaConstants::kSyncService, "sync_token"); 455 GaiaConstants::kSyncService, "sync_token");
420 service_->fail_initial_download(); 456 service_->fail_initial_download();
421 457
422 service_->Initialize(); 458 service_->Initialize();
423 EXPECT_FALSE(service_->sync_initialized()); 459 EXPECT_FALSE(service_->sync_initialized());
424 EXPECT_FALSE(service_->GetBackendForTest()); 460 EXPECT_FALSE(service_->GetBackendForTest());
425 } 461 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.cc ('k') | chrome/browser/sync/test_profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698