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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "chrome/browser/sync/engine/syncapi.h" | 6 #include "chrome/browser/sync/engine/syncapi.h" |
7 #include "chrome/browser/sync/glue/preference_change_processor.h" | 7 #include "chrome/browser/sync/glue/preference_change_processor.h" |
8 #include "chrome/browser/sync/glue/preference_data_type_controller.h" | 8 #include "chrome/browser/sync/glue/preference_data_type_controller.h" |
9 #include "chrome/browser/sync/glue/preference_model_associator.h" | 9 #include "chrome/browser/sync/glue/preference_model_associator.h" |
10 #include "chrome/browser/sync/glue/sync_backend_host.h" | 10 #include "chrome/browser/sync/glue/sync_backend_host.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 using base::JSONReader; | 22 using base::JSONReader; |
23 using browser_sync::PreferenceChangeProcessor; | 23 using browser_sync::PreferenceChangeProcessor; |
24 using browser_sync::PreferenceDataTypeController; | 24 using browser_sync::PreferenceDataTypeController; |
25 using browser_sync::PreferenceModelAssociator; | 25 using browser_sync::PreferenceModelAssociator; |
26 using browser_sync::SyncBackendHost; | 26 using browser_sync::SyncBackendHost; |
27 using browser_sync::SyncBackendHostMock; | 27 using browser_sync::SyncBackendHostMock; |
28 using sync_api::SyncManager; | 28 using sync_api::SyncManager; |
29 using testing::_; | 29 using testing::_; |
30 using testing::Return; | 30 using testing::Return; |
31 | 31 |
| 32 class TestPreferenceModelAssociator : public PreferenceModelAssociator { |
| 33 public: |
| 34 TestPreferenceModelAssociator(ProfileSyncService* service) |
| 35 : PreferenceModelAssociator(service), |
| 36 helper_(new TestModelAssociatorHelper()) { |
| 37 } |
| 38 virtual bool GetSyncIdForTaggedNode(const std::string& tag, int64* sync_id) { |
| 39 return helper_->GetSyncIdForTaggedNode(this, tag, sync_id); |
| 40 } |
| 41 private: |
| 42 scoped_ptr<TestModelAssociatorHelper> helper_; |
| 43 }; |
| 44 |
32 class ProfileSyncServicePreferenceTest : public testing::Test { | 45 class ProfileSyncServicePreferenceTest : public testing::Test { |
33 protected: | 46 protected: |
34 ProfileSyncServicePreferenceTest() | 47 ProfileSyncServicePreferenceTest() |
35 : ui_thread_(ChromeThread::UI, &message_loop_) { | 48 : ui_thread_(ChromeThread::UI, &message_loop_) { |
36 } | 49 } |
37 | 50 |
38 virtual void SetUp() { | 51 virtual void SetUp() { |
39 profile_.reset(new TestingProfile()); | 52 profile_.reset(new TestingProfile()); |
40 profile_->set_has_history_service(true); | 53 profile_->set_has_history_service(true); |
41 } | 54 } |
42 | 55 |
43 virtual void TearDown() { | 56 virtual void TearDown() { |
44 service_.reset(); | 57 service_.reset(); |
45 profile_.reset(); | 58 profile_.reset(); |
46 MessageLoop::current()->RunAllPending(); | 59 MessageLoop::current()->RunAllPending(); |
47 } | 60 } |
48 | 61 |
49 void StartSyncService() { | 62 void StartSyncService() { |
50 if (!service_.get()) { | 63 if (!service_.get()) { |
51 service_.reset(new TestProfileSyncService(&factory_, | 64 service_.reset(new TestProfileSyncService(&factory_, |
52 profile_.get(), | 65 profile_.get(), |
53 false, | 66 false, |
54 true)); | 67 true)); |
55 | 68 |
56 // Register the preference data type. | 69 // Register the preference data type. |
57 model_associator_ = | 70 model_associator_ = new TestPreferenceModelAssociator(service_.get()); |
58 new TestModelAssociator<PreferenceModelAssociator>(service_.get(), | |
59 service_.get()); | |
60 change_processor_ = new PreferenceChangeProcessor(model_associator_, | 71 change_processor_ = new PreferenceChangeProcessor(model_associator_, |
61 service_.get()); | 72 service_.get()); |
62 EXPECT_CALL(factory_, CreatePreferenceSyncComponents(_, _)). | 73 EXPECT_CALL(factory_, CreatePreferenceSyncComponents(_, _)). |
63 WillOnce(Return(ProfileSyncFactory::SyncComponents( | 74 WillOnce(Return(ProfileSyncFactory::SyncComponents( |
64 model_associator_, change_processor_))); | 75 model_associator_, change_processor_))); |
65 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 76 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
66 WillOnce(MakeDataTypeManager(&backend_mock_)); | 77 WillOnce(MakeDataTypeManager(&backend_mock_)); |
67 | 78 |
68 service_->RegisterDataTypeController( | 79 service_->RegisterDataTypeController( |
69 new PreferenceDataTypeController(&factory_, | 80 new PreferenceDataTypeController(&factory_, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 scoped_ptr<SyncManager::ChangeRecord> record( | 182 scoped_ptr<SyncManager::ChangeRecord> record( |
172 SetSyncedValue(prefs::kHomePage, *expected)); | 183 SetSyncedValue(prefs::kHomePage, *expected)); |
173 { | 184 { |
174 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 185 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); |
175 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 186 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
176 } | 187 } |
177 | 188 |
178 const Value& actual = GetPreferenceValue(prefs::kHomePage); | 189 const Value& actual = GetPreferenceValue(prefs::kHomePage); |
179 ASSERT_TRUE(expected->Equals(&actual)); | 190 ASSERT_TRUE(expected->Equals(&actual)); |
180 } | 191 } |
OLD | NEW |