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" |
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 Loading... |
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 syncer::ModelTypeSet user_types = syncer::UserTypes(); |
| 287 for (syncer::ModelTypeSet::Iterator iter = user_types.First(); |
| 288 iter.Good(); iter.Inc()) { |
| 289 profile_->GetPrefs()->ClearPref( |
| 290 browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get())); |
| 291 } |
| 292 |
| 293 // Pre load the tokens |
| 294 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 295 GaiaConstants::kSyncService, "sync_token"); |
| 296 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
| 297 service_->Initialize(); |
| 298 |
| 299 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( |
| 300 prefs::kSyncKeepEverythingSynced)); |
| 301 } |
| 302 |
| 303 // Verify that the recovery of datatype preferences doesn't overwrite a valid |
| 304 // case where only bookmarks are enabled. |
| 305 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { |
| 306 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
| 307 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
| 308 EXPECT_CALL(*data_type_manager, state()). |
| 309 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
| 310 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
| 311 |
| 312 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 313 |
| 314 // Explicitly set Keep Everything Synced to false and have only bookmarks |
| 315 // enabled. |
| 316 profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
| 317 |
| 318 // Pre load the tokens |
| 319 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 320 GaiaConstants::kSyncService, "sync_token"); |
| 321 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
| 322 service_->Initialize(); |
| 323 |
| 324 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( |
| 325 prefs::kSyncKeepEverythingSynced)); |
| 326 } |
| 327 |
271 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { | 328 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { |
272 // Disable sync through policy. | 329 // Disable sync through policy. |
273 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); | 330 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); |
274 | 331 |
275 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _)).Times(0); | 332 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _)).Times(0); |
276 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 333 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
277 | 334 |
278 // Service should not be started by Initialize() since it's managed. | 335 // Service should not be started by Initialize() since it's managed. |
279 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 336 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
280 GaiaConstants::kSyncService, "sync_token"); | 337 GaiaConstants::kSyncService, "sync_token"); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 400 |
344 // Preload the tokens. | 401 // Preload the tokens. |
345 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 402 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
346 GaiaConstants::kSyncService, "sync_token"); | 403 GaiaConstants::kSyncService, "sync_token"); |
347 service_->fail_initial_download(); | 404 service_->fail_initial_download(); |
348 | 405 |
349 service_->Initialize(); | 406 service_->Initialize(); |
350 EXPECT_FALSE(service_->sync_initialized()); | 407 EXPECT_FALSE(service_->sync_initialized()); |
351 EXPECT_FALSE(service_->GetBackendForTest()); | 408 EXPECT_FALSE(service_->GetBackendForTest()); |
352 } | 409 } |
OLD | NEW |