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" |
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" | |
20 #include "chrome/browser/sync/test_profile_sync_service.h" | 19 #include "chrome/browser/sync/test_profile_sync_service.h" |
21 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
24 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
25 #include "google_apis/gaia/gaia_auth_consumer.h" | 24 #include "google_apis/gaia/gaia_auth_consumer.h" |
26 #include "google_apis/gaia/gaia_constants.h" | 25 #include "google_apis/gaia/gaia_constants.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
28 | 27 |
29 using browser_sync::DataTypeManager; | 28 using browser_sync::DataTypeManager; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 261 |
263 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 262 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
264 | 263 |
265 // Pre load the tokens | 264 // Pre load the tokens |
266 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 265 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
267 GaiaConstants::kSyncService, "sync_token"); | 266 GaiaConstants::kSyncService, "sync_token"); |
268 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); | 267 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
269 service_->Initialize(); | 268 service_->Initialize(); |
270 } | 269 } |
271 | 270 |
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 | |
327 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { | 271 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { |
328 // Disable sync through policy. | 272 // Disable sync through policy. |
329 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); | 273 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); |
330 | 274 |
331 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _)).Times(0); | 275 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _)).Times(0); |
332 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 276 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
333 | 277 |
334 // Service should not be started by Initialize() since it's managed. | 278 // Service should not be started by Initialize() since it's managed. |
335 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 279 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
336 GaiaConstants::kSyncService, "sync_token"); | 280 GaiaConstants::kSyncService, "sync_token"); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 343 |
400 // Preload the tokens. | 344 // Preload the tokens. |
401 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 345 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
402 GaiaConstants::kSyncService, "sync_token"); | 346 GaiaConstants::kSyncService, "sync_token"); |
403 service_->fail_initial_download(); | 347 service_->fail_initial_download(); |
404 | 348 |
405 service_->Initialize(); | 349 service_->Initialize(); |
406 EXPECT_FALSE(service_->sync_initialized()); | 350 EXPECT_FALSE(service_->sync_initialized()); |
407 EXPECT_FALSE(service_->GetBackendForTest()); | 351 EXPECT_FALSE(service_->GetBackendForTest()); |
408 } | 352 } |
OLD | NEW |