| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 12 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| 13 #include "chrome/browser/sync/engine/syncapi.h" | 13 #include "chrome/browser/sync/engine/syncapi.h" |
| 14 #include "chrome/browser/sync/glue/preference_change_processor.h" | 14 #include "chrome/browser/sync/glue/preference_change_processor.h" |
| 15 #include "chrome/browser/sync/glue/preference_data_type_controller.h" | 15 #include "chrome/browser/sync/glue/preference_data_type_controller.h" |
| 16 #include "chrome/browser/sync/glue/preference_model_associator.h" | 16 #include "chrome/browser/sync/glue/preference_model_associator.h" |
| 17 #include "chrome/browser/sync/glue/sync_backend_host.h" | 17 #include "chrome/browser/sync/glue/sync_backend_host.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/protocol/preference_specifics.pb.h" | 19 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 20 #include "chrome/browser/sync/syncable/model_type.h" | 20 #include "chrome/browser/sync/syncable/model_type.h" |
| 21 #include "chrome/browser/sync/test_profile_sync_service.h" | 21 #include "chrome/browser/sync/test_profile_sync_service.h" |
| 22 #include "chrome/common/net/gaia/gaia_constants.h" |
| 22 #include "chrome/common/json_value_serializer.h" | 23 #include "chrome/common/json_value_serializer.h" |
| 23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/test/testing_pref_service.h" | 25 #include "chrome/test/testing_pref_service.h" |
| 25 #include "chrome/test/testing_profile.h" | 26 #include "chrome/test/testing_profile.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| 29 using base::JSONReader; | 30 using base::JSONReader; |
| 30 using browser_sync::PreferenceChangeProcessor; | 31 using browser_sync::PreferenceChangeProcessor; |
| 31 using browser_sync::PreferenceDataTypeController; | 32 using browser_sync::PreferenceDataTypeController; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 61 service_.reset(); | 62 service_.reset(); |
| 62 profile_.reset(); | 63 profile_.reset(); |
| 63 MessageLoop::current()->RunAllPending(); | 64 MessageLoop::current()->RunAllPending(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 bool StartSyncService(Task* task, bool will_fail_association) { | 67 bool StartSyncService(Task* task, bool will_fail_association) { |
| 67 if (service_.get()) | 68 if (service_.get()) |
| 68 return false; | 69 return false; |
| 69 | 70 |
| 70 service_.reset(new TestProfileSyncService( | 71 service_.reset(new TestProfileSyncService( |
| 71 &factory_, profile_.get(), false, false, task)); | 72 &factory_, profile_.get(), "test", false, task)); |
| 72 | 73 |
| 73 // Register the preference data type. | 74 // Register the preference data type. |
| 74 model_associator_ = | 75 model_associator_ = |
| 75 new PreferenceModelAssociator(service_.get()); | 76 new PreferenceModelAssociator(service_.get()); |
| 76 change_processor_ = new PreferenceChangeProcessor(model_associator_, | 77 change_processor_ = new PreferenceChangeProcessor(model_associator_, |
| 77 service_.get()); | 78 service_.get()); |
| 78 EXPECT_CALL(factory_, CreatePreferenceSyncComponents(_, _)). | 79 EXPECT_CALL(factory_, CreatePreferenceSyncComponents(_, _)). |
| 79 WillOnce(Return(ProfileSyncFactory::SyncComponents( | 80 WillOnce(Return(ProfileSyncFactory::SyncComponents( |
| 80 model_associator_, change_processor_))); | 81 model_associator_, change_processor_))); |
| 81 | 82 |
| 82 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 83 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
| 83 WillOnce(ReturnNewDataTypeManager()); | 84 WillOnce(ReturnNewDataTypeManager()); |
| 84 | 85 |
| 85 service_->set_num_expected_resumes(will_fail_association ? 0 : 1); | 86 service_->set_num_expected_resumes(will_fail_association ? 0 : 1); |
| 86 | 87 |
| 87 service_->RegisterDataTypeController( | 88 service_->RegisterDataTypeController( |
| 88 new PreferenceDataTypeController(&factory_, | 89 new PreferenceDataTypeController(&factory_, |
| 89 service_.get())); | 90 service_.get())); |
| 91 profile_->GetTokenService()->IssueAuthTokenForTest( |
| 92 GaiaConstants::kSyncService, "token"); |
| 90 service_->Initialize(); | 93 service_->Initialize(); |
| 91 MessageLoop::current()->Run(); | 94 MessageLoop::current()->Run(); |
| 92 return true; | 95 return true; |
| 93 } | 96 } |
| 94 | 97 |
| 95 SyncBackendHost* backend() { return service_->backend_.get(); } | 98 SyncBackendHost* backend() { return service_->backend_.get(); } |
| 96 | 99 |
| 97 const Value& GetPreferenceValue(const std::string& name) { | 100 const Value& GetPreferenceValue(const std::string& name) { |
| 98 const PrefService::Preference* preference = | 101 const PrefService::Preference* preference = |
| 99 prefs_->FindPreference(name.c_str()); | 102 prefs_->FindPreference(name.c_str()); |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 482 |
| 480 // The pref value should still be the one dictated by policy. | 483 // The pref value should still be the one dictated by policy. |
| 481 EXPECT_TRUE(managed_value->Equals(&GetPreferenceValue(prefs::kHomePage))); | 484 EXPECT_TRUE(managed_value->Equals(&GetPreferenceValue(prefs::kHomePage))); |
| 482 | 485 |
| 483 // Switch kHomePage back to unmanaged. | 486 // Switch kHomePage back to unmanaged. |
| 484 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); | 487 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); |
| 485 | 488 |
| 486 // Sync value should be picked up. | 489 // Sync value should be picked up. |
| 487 EXPECT_TRUE(sync_value->Equals(&GetPreferenceValue(prefs::kHomePage))); | 490 EXPECT_TRUE(sync_value->Equals(&GetPreferenceValue(prefs::kHomePage))); |
| 488 } | 491 } |
| OLD | NEW |