OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sync/driver/glue/sync_backend_registrar.h" | 5 #include "components/sync/driver/glue/sync_backend_registrar.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "components/sync/base/model_type.h" | 10 #include "components/sync/base/model_type.h" |
11 #include "components/sync/core/test/test_user_share.h" | 11 #include "components/sync/core/test/test_user_share.h" |
12 #include "components/sync/driver/change_processor_mock.h" | 12 #include "components/sync/driver/change_processor_mock.h" |
13 #include "components/sync/driver/fake_sync_client.h" | 13 #include "components/sync/driver/fake_sync_client.h" |
14 #include "components/sync/driver/glue/browser_thread_model_worker.h" | 14 #include "components/sync/driver/glue/browser_thread_model_worker.h" |
15 #include "components/sync/driver/sync_api_component_factory_mock.h" | 15 #include "components/sync/driver/sync_api_component_factory_mock.h" |
16 #include "components/sync/engine/passive_model_worker.h" | 16 #include "components/sync/engine/passive_model_worker.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace syncer { | 20 namespace browser_sync { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 using ::testing::_; | 24 using ::testing::_; |
25 using ::testing::InSequence; | 25 using ::testing::InSequence; |
26 using ::testing::Return; | 26 using ::testing::Return; |
27 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
| 28 using syncer::FIRST_REAL_MODEL_TYPE; |
| 29 using syncer::AUTOFILL; |
| 30 using syncer::BOOKMARKS; |
| 31 using syncer::PREFERENCES; |
| 32 using syncer::THEMES; |
| 33 using syncer::NIGORI; |
| 34 using syncer::PASSWORDS; |
| 35 using syncer::MODEL_TYPE_COUNT; |
| 36 using syncer::ModelSafeGroup; |
| 37 using syncer::ModelSafeRoutingInfo; |
| 38 using syncer::ModelTypeSet; |
| 39 using syncer::ModelType; |
| 40 using syncer::ModelTypeFromInt; |
28 | 41 |
29 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { | 42 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { |
30 registrar->OnChangesApplied(type, 0, NULL, ImmutableChangeRecordList()); | 43 registrar->OnChangesApplied(type, 0, NULL, |
| 44 syncer::ImmutableChangeRecordList()); |
31 registrar->OnChangesComplete(type); | 45 registrar->OnChangesComplete(type); |
32 } | 46 } |
33 | 47 |
34 class RegistrarSyncClient : public FakeSyncClient { | 48 class RegistrarSyncClient : public sync_driver::FakeSyncClient { |
35 public: | 49 public: |
36 RegistrarSyncClient( | 50 RegistrarSyncClient( |
37 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 51 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
38 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner, | 52 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner, |
39 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | 53 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
40 : ui_task_runner_(ui_task_runner), | 54 : ui_task_runner_(ui_task_runner), |
41 db_task_runner_(db_task_runner), | 55 db_task_runner_(db_task_runner), |
42 file_task_runner_(file_task_runner) {} | 56 file_task_runner_(file_task_runner) {} |
43 | 57 |
44 scoped_refptr<ModelSafeWorker> CreateModelWorkerForGroup( | 58 scoped_refptr<syncer::ModelSafeWorker> CreateModelWorkerForGroup( |
45 ModelSafeGroup group, | 59 ModelSafeGroup group, |
46 WorkerLoopDestructionObserver* observer) override { | 60 syncer::WorkerLoopDestructionObserver* observer) override { |
47 switch (group) { | 61 switch (group) { |
48 case GROUP_UI: | 62 case syncer::GROUP_UI: |
49 return new BrowserThreadModelWorker(ui_task_runner_, group, observer); | 63 return new BrowserThreadModelWorker(ui_task_runner_, group, observer); |
50 case GROUP_DB: | 64 case syncer::GROUP_DB: |
51 return new BrowserThreadModelWorker(db_task_runner_, group, observer); | 65 return new BrowserThreadModelWorker(db_task_runner_, group, observer); |
52 case GROUP_FILE: | 66 case syncer::GROUP_FILE: |
53 return new BrowserThreadModelWorker(file_task_runner_, group, observer); | 67 return new BrowserThreadModelWorker(file_task_runner_, group, observer); |
54 case GROUP_PASSIVE: | 68 case syncer::GROUP_PASSIVE: |
55 return new PassiveModelWorker(observer); | 69 return new syncer::PassiveModelWorker(observer); |
56 default: | 70 default: |
57 return nullptr; | 71 return nullptr; |
58 } | 72 } |
59 } | 73 } |
60 | 74 |
61 private: | 75 private: |
62 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 76 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
63 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; | 77 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; |
64 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 78 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
65 }; | 79 }; |
66 | 80 |
67 // Flaky: https://crbug.com/498238 | 81 // Flaky: https://crbug.com/498238 |
68 class SyncBackendRegistrarTest : public testing::Test { | 82 class SyncBackendRegistrarTest : public testing::Test { |
69 public: | 83 public: |
70 void TestNonUIDataTypeActivationAsync(ChangeProcessor* processor, | 84 void TestNonUIDataTypeActivationAsync(sync_driver::ChangeProcessor* processor, |
71 base::WaitableEvent* done) { | 85 base::WaitableEvent* done) { |
72 registrar_->ActivateDataType(AUTOFILL, GROUP_DB, processor, | 86 registrar_->ActivateDataType(AUTOFILL, syncer::GROUP_DB, processor, |
73 test_user_share_.user_share()); | 87 test_user_share_.user_share()); |
74 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, GROUP_DB}}); | 88 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, syncer::GROUP_DB}}); |
75 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL)); | 89 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL)); |
76 TriggerChanges(registrar_.get(), AUTOFILL); | 90 TriggerChanges(registrar_.get(), AUTOFILL); |
77 done->Signal(); | 91 done->Signal(); |
78 } | 92 } |
79 | 93 |
80 protected: | 94 protected: |
81 SyncBackendRegistrarTest() | 95 SyncBackendRegistrarTest() |
82 : db_thread_("DBThreadForTest"), | 96 : db_thread_("DBThreadForTest"), |
83 file_thread_("FileThreadForTest"), | 97 file_thread_("FileThreadForTest"), |
84 sync_thread_(NULL) {} | 98 sync_thread_(NULL) {} |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar, | 131 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar, |
118 ModelTypeSet types) { | 132 ModelTypeSet types) { |
119 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 133 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
120 ModelType model_type = ModelTypeFromInt(i); | 134 ModelType model_type = ModelTypeFromInt(i); |
121 EXPECT_EQ(types.Has(model_type), | 135 EXPECT_EQ(types.Has(model_type), |
122 registrar_->IsTypeActivatedForTest(model_type)); | 136 registrar_->IsTypeActivatedForTest(model_type)); |
123 } | 137 } |
124 } | 138 } |
125 | 139 |
126 size_t GetWorkersSize() { | 140 size_t GetWorkersSize() { |
127 std::vector<scoped_refptr<ModelSafeWorker>> workers; | 141 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers; |
128 registrar_->GetWorkers(&workers); | 142 registrar_->GetWorkers(&workers); |
129 return workers.size(); | 143 return workers.size(); |
130 } | 144 } |
131 | 145 |
132 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() { | 146 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() { |
133 return message_loop_.task_runner(); | 147 return message_loop_.task_runner(); |
134 } | 148 } |
135 | 149 |
136 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner() { | 150 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner() { |
137 return db_thread_.task_runner(); | 151 return db_thread_.task_runner(); |
138 } | 152 } |
139 | 153 |
140 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner() { | 154 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner() { |
141 return db_thread_.task_runner(); | 155 return db_thread_.task_runner(); |
142 } | 156 } |
143 | 157 |
144 base::MessageLoop message_loop_; | 158 base::MessageLoop message_loop_; |
145 base::Thread db_thread_; | 159 base::Thread db_thread_; |
146 base::Thread file_thread_; | 160 base::Thread file_thread_; |
147 | 161 |
148 TestUserShare test_user_share_; | 162 syncer::TestUserShare test_user_share_; |
149 std::unique_ptr<RegistrarSyncClient> sync_client_; | 163 std::unique_ptr<RegistrarSyncClient> sync_client_; |
150 std::unique_ptr<SyncBackendRegistrar> registrar_; | 164 std::unique_ptr<SyncBackendRegistrar> registrar_; |
151 | 165 |
152 base::Thread* sync_thread_; | 166 base::Thread* sync_thread_; |
153 }; | 167 }; |
154 | 168 |
155 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { | 169 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { |
156 registrar_->SetInitialTypes(ModelTypeSet()); | 170 registrar_->SetInitialTypes(ModelTypeSet()); |
157 EXPECT_FALSE(registrar_->IsNigoriEnabled()); | 171 EXPECT_FALSE(registrar_->IsNigoriEnabled()); |
158 EXPECT_EQ(4u, GetWorkersSize()); | 172 EXPECT_EQ(4u, GetWorkersSize()); |
159 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo()); | 173 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo()); |
160 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 174 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
161 } | 175 } |
162 | 176 |
163 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { | 177 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { |
164 registrar_->RegisterNonBlockingType(BOOKMARKS); | 178 registrar_->RegisterNonBlockingType(BOOKMARKS); |
165 registrar_->SetInitialTypes(ModelTypeSet(BOOKMARKS, NIGORI, PASSWORDS)); | 179 registrar_->SetInitialTypes(ModelTypeSet(BOOKMARKS, NIGORI, PASSWORDS)); |
166 EXPECT_TRUE(registrar_->IsNigoriEnabled()); | 180 EXPECT_TRUE(registrar_->IsNigoriEnabled()); |
167 EXPECT_EQ(4u, GetWorkersSize()); | 181 EXPECT_EQ(4u, GetWorkersSize()); |
168 EXPECT_EQ(ModelTypeSet(NIGORI), registrar_->GetLastConfiguredTypes()); | 182 EXPECT_EQ(ModelTypeSet(NIGORI), registrar_->GetLastConfiguredTypes()); |
169 // Bookmarks dropped because it is nonblocking. | 183 // Bookmarks dropped because it is nonblocking. |
170 // Passwords dropped because of no password store. | 184 // Passwords dropped because of no password store. |
171 ExpectRoutingInfo(registrar_.get(), {{NIGORI, GROUP_PASSIVE}}); | 185 ExpectRoutingInfo(registrar_.get(), {{NIGORI, syncer::GROUP_PASSIVE}}); |
172 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 186 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
173 } | 187 } |
174 | 188 |
175 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmptyReversedInitialization) { | 189 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmptyReversedInitialization) { |
176 // The blocking types get to set initial types before NonBlocking types here. | 190 // The blocking types get to set initial types before NonBlocking types here. |
177 registrar_->SetInitialTypes(ModelTypeSet(BOOKMARKS, NIGORI, PASSWORDS)); | 191 registrar_->SetInitialTypes(ModelTypeSet(BOOKMARKS, NIGORI, PASSWORDS)); |
178 registrar_->RegisterNonBlockingType(BOOKMARKS); | 192 registrar_->RegisterNonBlockingType(BOOKMARKS); |
179 EXPECT_TRUE(registrar_->IsNigoriEnabled()); | 193 EXPECT_TRUE(registrar_->IsNigoriEnabled()); |
180 EXPECT_EQ(4u, GetWorkersSize()); | 194 EXPECT_EQ(4u, GetWorkersSize()); |
181 EXPECT_EQ(ModelTypeSet(NIGORI), registrar_->GetLastConfiguredTypes()); | 195 EXPECT_EQ(ModelTypeSet(NIGORI), registrar_->GetLastConfiguredTypes()); |
182 // Bookmarks dropped because it is nonblocking. | 196 // Bookmarks dropped because it is nonblocking. |
183 // Passwords dropped because of no password store. | 197 // Passwords dropped because of no password store. |
184 ExpectRoutingInfo(registrar_.get(), {{NIGORI, GROUP_PASSIVE}}); | 198 ExpectRoutingInfo(registrar_.get(), {{NIGORI, syncer::GROUP_PASSIVE}}); |
185 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 199 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
186 } | 200 } |
187 | 201 |
188 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { | 202 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { |
189 registrar_->RegisterNonBlockingType(BOOKMARKS); | 203 registrar_->RegisterNonBlockingType(BOOKMARKS); |
190 registrar_->SetInitialTypes(ModelTypeSet()); | 204 registrar_->SetInitialTypes(ModelTypeSet()); |
191 | 205 |
192 // Add. | 206 // Add. |
193 const ModelTypeSet types1(BOOKMARKS, NIGORI, AUTOFILL); | 207 const ModelTypeSet types1(BOOKMARKS, NIGORI, AUTOFILL); |
194 EXPECT_EQ(types1, registrar_->ConfigureDataTypes(types1, ModelTypeSet())); | 208 EXPECT_EQ(types1, registrar_->ConfigureDataTypes(types1, ModelTypeSet())); |
195 ExpectRoutingInfo(registrar_.get(), {{BOOKMARKS, GROUP_NON_BLOCKING}, | 209 ExpectRoutingInfo(registrar_.get(), {{BOOKMARKS, syncer::GROUP_NON_BLOCKING}, |
196 {NIGORI, GROUP_PASSIVE}, | 210 {NIGORI, syncer::GROUP_PASSIVE}, |
197 {AUTOFILL, GROUP_PASSIVE}}); | 211 {AUTOFILL, syncer::GROUP_PASSIVE}}); |
198 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 212 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
199 EXPECT_EQ(types1, registrar_->GetLastConfiguredTypes()); | 213 EXPECT_EQ(types1, registrar_->GetLastConfiguredTypes()); |
200 | 214 |
201 // Add and remove. | 215 // Add and remove. |
202 const ModelTypeSet types2(PREFERENCES, THEMES); | 216 const ModelTypeSet types2(PREFERENCES, THEMES); |
203 EXPECT_EQ(types2, registrar_->ConfigureDataTypes(types2, types1)); | 217 EXPECT_EQ(types2, registrar_->ConfigureDataTypes(types2, types1)); |
204 | 218 |
205 ExpectRoutingInfo(registrar_.get(), | 219 ExpectRoutingInfo(registrar_.get(), {{PREFERENCES, syncer::GROUP_PASSIVE}, |
206 {{PREFERENCES, GROUP_PASSIVE}, {THEMES, GROUP_PASSIVE}}); | 220 {THEMES, syncer::GROUP_PASSIVE}}); |
207 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 221 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
208 EXPECT_EQ(types2, registrar_->GetLastConfiguredTypes()); | 222 EXPECT_EQ(types2, registrar_->GetLastConfiguredTypes()); |
209 | 223 |
210 // Remove. | 224 // Remove. |
211 EXPECT_TRUE(registrar_->ConfigureDataTypes(ModelTypeSet(), types2).Empty()); | 225 EXPECT_TRUE(registrar_->ConfigureDataTypes(ModelTypeSet(), types2).Empty()); |
212 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo()); | 226 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo()); |
213 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 227 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
214 EXPECT_EQ(ModelTypeSet(), registrar_->GetLastConfiguredTypes()); | 228 EXPECT_EQ(ModelTypeSet(), registrar_->GetLastConfiguredTypes()); |
215 } | 229 } |
216 | 230 |
217 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { | 231 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { |
218 InSequence in_sequence; | 232 InSequence in_sequence; |
219 registrar_->SetInitialTypes(ModelTypeSet()); | 233 registrar_->SetInitialTypes(ModelTypeSet()); |
220 | 234 |
221 // Should do nothing. | 235 // Should do nothing. |
222 TriggerChanges(registrar_.get(), BOOKMARKS); | 236 TriggerChanges(registrar_.get(), BOOKMARKS); |
223 | 237 |
224 StrictMock<ChangeProcessorMock> change_processor_mock; | 238 StrictMock<sync_driver::ChangeProcessorMock> change_processor_mock; |
225 EXPECT_CALL(change_processor_mock, StartImpl()); | 239 EXPECT_CALL(change_processor_mock, StartImpl()); |
226 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); | 240 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
227 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); | 241 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); |
228 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); | 242 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
229 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); | 243 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); |
230 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); | 244 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); |
231 | 245 |
232 const ModelTypeSet types(BOOKMARKS); | 246 const ModelTypeSet types(BOOKMARKS); |
233 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); | 247 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); |
234 registrar_->ActivateDataType(BOOKMARKS, GROUP_UI, &change_processor_mock, | 248 registrar_->ActivateDataType(BOOKMARKS, syncer::GROUP_UI, |
| 249 &change_processor_mock, |
235 test_user_share_.user_share()); | 250 test_user_share_.user_share()); |
236 ExpectRoutingInfo(registrar_.get(), {{BOOKMARKS, GROUP_UI}}); | 251 ExpectRoutingInfo(registrar_.get(), {{BOOKMARKS, syncer::GROUP_UI}}); |
237 ExpectHasProcessorsForTypes(*registrar_, types); | 252 ExpectHasProcessorsForTypes(*registrar_, types); |
238 | 253 |
239 TriggerChanges(registrar_.get(), BOOKMARKS); | 254 TriggerChanges(registrar_.get(), BOOKMARKS); |
240 | 255 |
241 registrar_->DeactivateDataType(BOOKMARKS); | 256 registrar_->DeactivateDataType(BOOKMARKS); |
242 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo()); | 257 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo()); |
243 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); | 258 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); |
244 | 259 |
245 // Should do nothing. | 260 // Should do nothing. |
246 TriggerChanges(registrar_.get(), BOOKMARKS); | 261 TriggerChanges(registrar_.get(), BOOKMARKS); |
247 } | 262 } |
248 | 263 |
249 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { | 264 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { |
250 InSequence in_sequence; | 265 InSequence in_sequence; |
251 registrar_->SetInitialTypes(ModelTypeSet()); | 266 registrar_->SetInitialTypes(ModelTypeSet()); |
252 | 267 |
253 // Should do nothing. | 268 // Should do nothing. |
254 TriggerChanges(registrar_.get(), AUTOFILL); | 269 TriggerChanges(registrar_.get(), AUTOFILL); |
255 | 270 |
256 StrictMock<ChangeProcessorMock> change_processor_mock; | 271 StrictMock<sync_driver::ChangeProcessorMock> change_processor_mock; |
257 EXPECT_CALL(change_processor_mock, StartImpl()); | 272 EXPECT_CALL(change_processor_mock, StartImpl()); |
258 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); | 273 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
259 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); | 274 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); |
260 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); | 275 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); |
261 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); | 276 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); |
262 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); | 277 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); |
263 | 278 |
264 const ModelTypeSet types(AUTOFILL); | 279 const ModelTypeSet types(AUTOFILL); |
265 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); | 280 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); |
266 | 281 |
(...skipping 17 matching lines...) Expand all Loading... |
284 // handled correctly in SyncBackendRegistrar. | 299 // handled correctly in SyncBackendRegistrar. |
285 TEST_F(SyncBackendRegistrarTest, ConfigureNonBlockingDataType) { | 300 TEST_F(SyncBackendRegistrarTest, ConfigureNonBlockingDataType) { |
286 registrar_->RegisterNonBlockingType(AUTOFILL); | 301 registrar_->RegisterNonBlockingType(AUTOFILL); |
287 registrar_->RegisterNonBlockingType(BOOKMARKS); | 302 registrar_->RegisterNonBlockingType(BOOKMARKS); |
288 | 303 |
289 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo()); | 304 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo()); |
290 // Simulate that initial sync was already done for AUTOFILL. | 305 // Simulate that initial sync was already done for AUTOFILL. |
291 registrar_->AddRestoredNonBlockingType(AUTOFILL); | 306 registrar_->AddRestoredNonBlockingType(AUTOFILL); |
292 // It should be added to routing info and set of configured types. | 307 // It should be added to routing info and set of configured types. |
293 EXPECT_EQ(ModelTypeSet(AUTOFILL), registrar_->GetLastConfiguredTypes()); | 308 EXPECT_EQ(ModelTypeSet(AUTOFILL), registrar_->GetLastConfiguredTypes()); |
294 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, GROUP_NON_BLOCKING}}); | 309 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, syncer::GROUP_NON_BLOCKING}}); |
295 | 310 |
296 // Configure two non-blocking types. Initial sync wasn't done for BOOKMARKS so | 311 // Configure two non-blocking types. Initial sync wasn't done for BOOKMARKS so |
297 // it should be included in types to be downloaded. | 312 // it should be included in types to be downloaded. |
298 ModelTypeSet types_to_add(AUTOFILL, BOOKMARKS); | 313 ModelTypeSet types_to_add(AUTOFILL, BOOKMARKS); |
299 ModelTypeSet newly_added_types = | 314 ModelTypeSet newly_added_types = |
300 registrar_->ConfigureDataTypes(types_to_add, ModelTypeSet()); | 315 registrar_->ConfigureDataTypes(types_to_add, ModelTypeSet()); |
301 EXPECT_EQ(ModelTypeSet(BOOKMARKS), newly_added_types); | 316 EXPECT_EQ(ModelTypeSet(BOOKMARKS), newly_added_types); |
302 EXPECT_EQ(types_to_add, registrar_->GetLastConfiguredTypes()); | 317 EXPECT_EQ(types_to_add, registrar_->GetLastConfiguredTypes()); |
303 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, GROUP_NON_BLOCKING}, | 318 ExpectRoutingInfo(registrar_.get(), |
304 {BOOKMARKS, GROUP_NON_BLOCKING}}); | 319 {{AUTOFILL, syncer::GROUP_NON_BLOCKING}, |
| 320 {BOOKMARKS, syncer::GROUP_NON_BLOCKING}}); |
305 } | 321 } |
306 | 322 |
307 class SyncBackendRegistrarShutdownTest : public testing::Test { | 323 class SyncBackendRegistrarShutdownTest : public testing::Test { |
308 public: | 324 public: |
309 void BlockDBThread() { | 325 void BlockDBThread() { |
310 EXPECT_FALSE(db_thread_lock_.Try()); | 326 EXPECT_FALSE(db_thread_lock_.Try()); |
311 | 327 |
312 db_thread_blocked_.Signal(); | 328 db_thread_blocked_.Signal(); |
313 base::AutoLock l(db_thread_lock_); | 329 base::AutoLock l(db_thread_lock_); |
314 } | 330 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 374 |
359 base::Lock db_thread_lock_; | 375 base::Lock db_thread_lock_; |
360 base::RunLoop run_loop_; | 376 base::RunLoop run_loop_; |
361 base::Closure quit_closure_; | 377 base::Closure quit_closure_; |
362 }; | 378 }; |
363 | 379 |
364 // Wrap SyncBackendRegistrar so that we can monitor its lifetime. | 380 // Wrap SyncBackendRegistrar so that we can monitor its lifetime. |
365 class TestRegistrar : public SyncBackendRegistrar { | 381 class TestRegistrar : public SyncBackendRegistrar { |
366 public: | 382 public: |
367 explicit TestRegistrar( | 383 explicit TestRegistrar( |
368 SyncClient* sync_client, | 384 sync_driver::SyncClient* sync_client, |
369 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, | 385 const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
370 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | 386 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
371 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, | 387 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, |
372 SyncBackendRegistrarShutdownTest* test) | 388 SyncBackendRegistrarShutdownTest* test) |
373 : SyncBackendRegistrar("test", | 389 : SyncBackendRegistrar("test", |
374 sync_client, | 390 sync_client, |
375 std::unique_ptr<base::Thread>(), | 391 std::unique_ptr<base::Thread>(), |
376 ui_thread, | 392 ui_thread, |
377 db_thread, | 393 db_thread, |
378 file_thread), | 394 file_thread), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 439 |
424 db_thread_lock_.Release(); | 440 db_thread_lock_.Release(); |
425 | 441 |
426 // Run the main thread loop until all workers have been removed and the | 442 // Run the main thread loop until all workers have been removed and the |
427 // registrar destroyed. | 443 // registrar destroyed. |
428 run_loop_.Run(); | 444 run_loop_.Run(); |
429 } | 445 } |
430 | 446 |
431 } // namespace | 447 } // namespace |
432 | 448 |
433 } // namespace syncer | 449 } // namespace browser_sync |
OLD | NEW |