Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: components/sync/driver/glue/sync_backend_registrar_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698