Index: chrome/browser/sync/profile_sync_service_startup_unittest.cc |
diff --git a/chrome/browser/sync/profile_sync_service_startup_unittest.cc b/chrome/browser/sync/profile_sync_service_startup_unittest.cc |
index 010952535438f6f6aad402090c0d47ad358d0b8c..f78445a54450104513e712e5e675c776819e4f10 100644 |
--- a/chrome/browser/sync/profile_sync_service_startup_unittest.cc |
+++ b/chrome/browser/sync/profile_sync_service_startup_unittest.cc |
@@ -16,6 +16,7 @@ |
#include "chrome/browser/sync/glue/data_type_manager_mock.h" |
#include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
#include "chrome/browser/sync/profile_sync_test_util.h" |
+#include "chrome/browser/sync/sync_prefs.h" |
#include "chrome/browser/sync/test_profile_sync_service.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "chrome/common/pref_names.h" |
@@ -268,6 +269,61 @@ TEST_F(ProfileSyncServiceStartupTest, StartNormal) { |
service_->Initialize(); |
} |
+// Test that we can recover from a case where a bug in the code resulted in |
+// OnUserChoseDatatypes not being properly called and datatype preferences |
+// therefore being left unset. |
+TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) { |
+ DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
+ EXPECT_CALL(*data_type_manager, Configure(_, _)); |
+ EXPECT_CALL(*data_type_manager, state()). |
+ WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
+ EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
+ |
+ EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
+ |
+ // Clear the datatype preference fields (simulating bug 154940). |
+ profile_->GetPrefs()->ClearPref(prefs::kSyncKeepEverythingSynced); |
+ for (syncer::ModelTypeSet::Iterator iter = syncer::UserTypes().First(); |
+ iter.Good(); iter.Inc()) { |
+ profile_->GetPrefs()->ClearPref( |
+ browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get())); |
+ } |
+ |
+ // Pre load the tokens |
+ TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
+ GaiaConstants::kSyncService, "sync_token"); |
+ profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
+ service_->Initialize(); |
+ |
+ EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( |
+ prefs::kSyncKeepEverythingSynced)); |
+} |
+ |
+// Verify that the recovery of datatype preferences doesn't overwrite a valid |
+// case where only bookmarks are enabled. |
+TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { |
+ DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
+ EXPECT_CALL(*data_type_manager, Configure(_, _)); |
+ EXPECT_CALL(*data_type_manager, state()). |
+ WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
+ EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
+ |
+ EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
+ |
+ // Explicitly set Keep Everything Synced to false and have only bookmarks |
+ // enabled. |
+ profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
+ |
+ // Pre load the tokens |
+ TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
+ GaiaConstants::kSyncService, "sync_token"); |
+ profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
+ service_->Initialize(); |
+ |
+ EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( |
+ prefs::kSyncKeepEverythingSynced)); |
+} |
+ |
TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { |
// Disable sync through policy. |
profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); |