Chromium Code Reviews| 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_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) { | |
| 273 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | |
| 274 EXPECT_CALL(*data_type_manager, Configure(_, _)); | |
| 275 EXPECT_CALL(*data_type_manager, state()). | |
| 276 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | |
| 277 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | |
| 278 | |
| 279 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | |
| 280 | |
| 281 // Clear the datatype preference fields (simulating bug 154940). | |
|
tim (not reviewing)
2012/10/29 23:25:24
Can you also write a test to cover the case where
Nicolas Zea
2012/10/30 00:05:58
Done (and check that it's true in this test). I re
| |
| 282 profile_->GetPrefs()->ClearPref(prefs::kSyncKeepEverythingSynced); | |
| 283 for (syncer::ModelTypeSet::Iterator iter = syncer::UserTypes().First(); | |
| 284 iter.Good(); iter.Inc()) { | |
| 285 profile_->GetPrefs()->ClearPref( | |
| 286 browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get())); | |
| 287 } | |
| 288 | |
| 289 // Pre load the tokens | |
| 290 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | |
| 291 GaiaConstants::kSyncService, "sync_token"); | |
| 292 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); | |
| 293 service_->Initialize(); | |
| 294 | |
| 295 EXPECT_TRUE(service_->GetPreferredDataTypes().HasAll( | |
| 296 service_->GetRegisteredDataTypes())); | |
|
tim (not reviewing)
2012/10/29 23:25:24
nit - indent
Nicolas Zea
2012/10/30 00:05:58
Done.
| |
| 297 } | |
| 298 | |
| 271 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { | 299 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { |
| 272 // Disable sync through policy. | 300 // Disable sync through policy. |
| 273 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); | 301 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); |
| 274 | 302 |
| 275 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _)).Times(0); | 303 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _, _)).Times(0); |
| 276 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 304 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 277 | 305 |
| 278 // Service should not be started by Initialize() since it's managed. | 306 // Service should not be started by Initialize() since it's managed. |
| 279 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 307 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 280 GaiaConstants::kSyncService, "sync_token"); | 308 GaiaConstants::kSyncService, "sync_token"); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 | 371 |
| 344 // Preload the tokens. | 372 // Preload the tokens. |
| 345 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 373 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 346 GaiaConstants::kSyncService, "sync_token"); | 374 GaiaConstants::kSyncService, "sync_token"); |
| 347 service_->fail_initial_download(); | 375 service_->fail_initial_download(); |
| 348 | 376 |
| 349 service_->Initialize(); | 377 service_->Initialize(); |
| 350 EXPECT_FALSE(service_->sync_initialized()); | 378 EXPECT_FALSE(service_->sync_initialized()); |
| 351 EXPECT_FALSE(service_->GetBackendForTest()); | 379 EXPECT_FALSE(service_->GetBackendForTest()); |
| 352 } | 380 } |
| OLD | NEW |