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

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

Issue 11347054: [Sync] Unrevert fix for bug 154940 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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"
11 #include "chrome/browser/signin/signin_manager_factory.h" 11 #include "chrome/browser/signin/signin_manager_factory.h"
12 #include "chrome/browser/signin/signin_manager_fake.h" 12 #include "chrome/browser/signin/signin_manager_fake.h"
13 #include "chrome/browser/signin/token_service.h" 13 #include "chrome/browser/signin/token_service.h"
14 #include "chrome/browser/signin/token_service_factory.h" 14 #include "chrome/browser/signin/token_service_factory.h"
15 #include "chrome/browser/sync/glue/data_type_manager.h" 15 #include "chrome/browser/sync/glue/data_type_manager.h"
16 #include "chrome/browser/sync/glue/data_type_manager_mock.h" 16 #include "chrome/browser/sync/glue/data_type_manager_mock.h"
17 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 17 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
18 #include "chrome/browser/sync/profile_sync_test_util.h" 18 #include "chrome/browser/sync/profile_sync_test_util.h"
19 #include "chrome/browser/sync/sync_prefs.h"
19 #include "chrome/browser/sync/test_profile_sync_service.h" 20 #include "chrome/browser/sync/test_profile_sync_service.h"
20 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/test/test_browser_thread.h" 24 #include "content/public/test/test_browser_thread.h"
24 #include "google_apis/gaia/gaia_auth_consumer.h" 25 #include "google_apis/gaia/gaia_auth_consumer.h"
25 #include "google_apis/gaia/gaia_constants.h" 26 #include "google_apis/gaia/gaia_constants.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 28
28 using browser_sync::DataTypeManager; 29 using browser_sync::DataTypeManager;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 262
262 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 263 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
263 264
264 // Pre load the tokens 265 // Pre load the tokens
265 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 266 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
266 GaiaConstants::kSyncService, "sync_token"); 267 GaiaConstants::kSyncService, "sync_token");
267 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); 268 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
268 service_->Initialize(); 269 service_->Initialize();
269 } 270 }
270 271
272 // Test that we can recover from a case where a bug in the code resulted in
273 // OnUserChoseDatatypes not being properly called and datatype preferences
274 // therefore being left unset.
275 TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) {
276 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
277 EXPECT_CALL(*data_type_manager, Configure(_, _));
278 EXPECT_CALL(*data_type_manager, state()).
279 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
280 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
281
282 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
283
284 // Clear the datatype preference fields (simulating bug 154940).
285 profile_->GetPrefs()->ClearPref(prefs::kSyncKeepEverythingSynced);
286 for (syncer::ModelTypeSet::Iterator iter = syncer::UserTypes().First();
287 iter.Good(); iter.Inc()) {
288 profile_->GetPrefs()->ClearPref(
289 browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get()));
290 }
291
292 // Pre load the tokens
293 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
294 GaiaConstants::kSyncService, "sync_token");
295 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
296 service_->Initialize();
297
298 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(
299 prefs::kSyncKeepEverythingSynced));
300 }
301
302 // Verify that the recovery of datatype preferences doesn't overwrite a valid
303 // case where only bookmarks are enabled.
304 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) {
305 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
306 EXPECT_CALL(*data_type_manager, Configure(_, _));
307 EXPECT_CALL(*data_type_manager, state()).
308 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
309 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
310
311 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
312
313 // Explicitly set Keep Everything Synced to false and have only bookmarks
314 // enabled.
315 profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
316
317 // Pre load the tokens
318 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
319 GaiaConstants::kSyncService, "sync_token");
320 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user");
321 service_->Initialize();
322
323 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
324 prefs::kSyncKeepEverythingSynced));
325 }
326
271 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { 327 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) {
272 // Disable sync through policy. 328 // Disable sync through policy.
273 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); 329 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true);
274 330
275 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _)).Times(0); 331 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _)).Times(0);
276 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 332 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
277 333
278 // Service should not be started by Initialize() since it's managed. 334 // Service should not be started by Initialize() since it's managed.
279 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 335 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
280 GaiaConstants::kSyncService, "sync_token"); 336 GaiaConstants::kSyncService, "sync_token");
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 399
344 // Preload the tokens. 400 // Preload the tokens.
345 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 401 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
346 GaiaConstants::kSyncService, "sync_token"); 402 GaiaConstants::kSyncService, "sync_token");
347 service_->fail_initial_download(); 403 service_->fail_initial_download();
348 404
349 service_->Initialize(); 405 service_->Initialize();
350 EXPECT_FALSE(service_->sync_initialized()); 406 EXPECT_FALSE(service_->sync_initialized());
351 EXPECT_FALSE(service_->GetBackendForTest()); 407 EXPECT_FALSE(service_->GetBackendForTest());
352 } 408 }
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