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

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

Issue 10434009: No longer trigger SyncCredentialsLost flow on cros. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update per review feedback Created 8 years, 7 months 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
« no previous file with comments | « chrome/browser/sync/profile_sync_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 157 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
158 GaiaConstants::kSyncService, "sync_token"); 158 GaiaConstants::kSyncService, "sync_token");
159 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 159 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
160 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 160 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
161 service_->set_setup_in_progress(false); 161 service_->set_setup_in_progress(false);
162 service_->OnUserChoseDatatypes( 162 service_->OnUserChoseDatatypes(
163 false, syncable::ModelTypeSet(syncable::BOOKMARKS)); 163 false, syncable::ModelTypeSet(syncable::BOOKMARKS));
164 EXPECT_TRUE(service_->ShouldPushChanges()); 164 EXPECT_TRUE(service_->ShouldPushChanges());
165 } 165 }
166 166
167 TEST_F(ProfileSyncServiceStartupTest, StartNoCredentials) {
168 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
169 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
170
171 // We've never completed startup.
172 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
173 // Make sure SigninManager doesn't think we're signed in (undoes the call to
174 // SetAuthenticatedUsername() in CreateSyncService()).
175 SigninManagerFactory::GetForProfile(profile_.get())->SignOut();
176
177 // Should not actually start, rather just clean things up and wait
178 // to be enabled.
179 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
180 service_->Initialize();
181 EXPECT_FALSE(service_->GetBackendForTest());
182
183 // Preferences should be back to defaults.
184 EXPECT_EQ(0, profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime));
185 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted));
186 Mock::VerifyAndClearExpectations(data_type_manager);
187
188 // Then start things up.
189 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1);
190 EXPECT_CALL(*data_type_manager, state()).
191 WillOnce(Return(DataTypeManager::CONFIGURED)).
192 WillOnce(Return(DataTypeManager::CONFIGURED));
193 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
194 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
195
196 service_->set_setup_in_progress(true);
197 service_->signin()->StartSignIn("test_user", "", "", "");
198 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens.
199 content::NotificationService::current()->Notify(
200 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
201 content::Source<TokenService>(
202 TokenServiceFactory::GetForProfile(profile_.get())),
203 content::NotificationService::NoDetails());
204 service_->set_setup_in_progress(false);
205 service_->OnUserChoseDatatypes(
206 false, syncable::ModelTypeSet(syncable::BOOKMARKS));
207 // Backend should initialize using a bogus GAIA token for credentials.
208 EXPECT_TRUE(service_->ShouldPushChanges());
209 }
210
211 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) {
212 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _)).Times(0);
213 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
214 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
215
216 service_->Initialize();
217 // Sync should not start because there are no tokens yet.
218 EXPECT_FALSE(service_->ShouldPushChanges());
219 EXPECT_FALSE(service_->GetBackendForTest());
220 content::NotificationService::current()->Notify(
221 chrome::NOTIFICATION_TOKEN_LOADING_FINISHED,
222 content::Source<TokenService>(
223 TokenServiceFactory::GetForProfile(profile_.get())),
224 content::NotificationService::NoDetails());
225 service_->set_setup_in_progress(false);
226 // Sync should not start because there are still no tokens.
227 EXPECT_FALSE(service_->ShouldPushChanges());
228 EXPECT_FALSE(service_->GetBackendForTest());
229 }
230
167 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { 231 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) {
168 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 232 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
169 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); 233 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
170 EXPECT_CALL(*data_type_manager, Configure(_, _)); 234 EXPECT_CALL(*data_type_manager, Configure(_, _));
171 EXPECT_CALL(*data_type_manager, state()). 235 EXPECT_CALL(*data_type_manager, state()).
172 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 236 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
173 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 237 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
174 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 238 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
175 239
176 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 240 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 402
339 // Preload the tokens. 403 // Preload the tokens.
340 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 404 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
341 GaiaConstants::kSyncService, "sync_token"); 405 GaiaConstants::kSyncService, "sync_token");
342 service_->fail_initial_download(); 406 service_->fail_initial_download();
343 407
344 service_->Initialize(); 408 service_->Initialize();
345 EXPECT_FALSE(service_->sync_initialized()); 409 EXPECT_FALSE(service_->sync_initialized());
346 EXPECT_FALSE(service_->GetBackendForTest()); 410 EXPECT_FALSE(service_->GetBackendForTest());
347 } 411 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698