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

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

Issue 2342353004: [Sync] NonBlocking type registration clear instead of crashes when also registered as pssive. (Closed)
Patch Set: Removing tuple, didn't realize ModelSafeRoutingInfo was a std::map. Created 4 years, 3 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
« no previous file with comments | « components/sync/driver/glue/sync_backend_registrar.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 15 matching lines...) Expand all
26 using ::testing::Return; 26 using ::testing::Return;
27 using ::testing::StrictMock; 27 using ::testing::StrictMock;
28 using syncer::FIRST_REAL_MODEL_TYPE; 28 using syncer::FIRST_REAL_MODEL_TYPE;
29 using syncer::AUTOFILL; 29 using syncer::AUTOFILL;
30 using syncer::BOOKMARKS; 30 using syncer::BOOKMARKS;
31 using syncer::PREFERENCES; 31 using syncer::PREFERENCES;
32 using syncer::THEMES; 32 using syncer::THEMES;
33 using syncer::NIGORI; 33 using syncer::NIGORI;
34 using syncer::PASSWORDS; 34 using syncer::PASSWORDS;
35 using syncer::MODEL_TYPE_COUNT; 35 using syncer::MODEL_TYPE_COUNT;
36 using syncer::ModelSafeGroup;
37 using syncer::ModelSafeRoutingInfo;
36 using syncer::ModelTypeSet; 38 using syncer::ModelTypeSet;
37 using syncer::ModelType; 39 using syncer::ModelType;
38 using syncer::ModelTypeFromInt; 40 using syncer::ModelTypeFromInt;
39 41
40 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) { 42 void TriggerChanges(SyncBackendRegistrar* registrar, ModelType type) {
41 registrar->OnChangesApplied(type, 0, NULL, 43 registrar->OnChangesApplied(type, 0, NULL,
42 syncer::ImmutableChangeRecordList()); 44 syncer::ImmutableChangeRecordList());
43 registrar->OnChangesComplete(type); 45 registrar->OnChangesComplete(type);
44 } 46 }
45 47
46 class RegistrarSyncClient : public sync_driver::FakeSyncClient { 48 class RegistrarSyncClient : public sync_driver::FakeSyncClient {
47 public: 49 public:
48 RegistrarSyncClient( 50 RegistrarSyncClient(
49 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, 51 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
50 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner, 52 const scoped_refptr<base::SingleThreadTaskRunner>& db_task_runner,
51 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) 53 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner)
52 : ui_task_runner_(ui_task_runner), 54 : ui_task_runner_(ui_task_runner),
53 db_task_runner_(db_task_runner), 55 db_task_runner_(db_task_runner),
54 file_task_runner_(file_task_runner) {} 56 file_task_runner_(file_task_runner) {}
55 57
56 scoped_refptr<syncer::ModelSafeWorker> CreateModelWorkerForGroup( 58 scoped_refptr<syncer::ModelSafeWorker> CreateModelWorkerForGroup(
57 syncer::ModelSafeGroup group, 59 ModelSafeGroup group,
58 syncer::WorkerLoopDestructionObserver* observer) override { 60 syncer::WorkerLoopDestructionObserver* observer) override {
59 switch (group) { 61 switch (group) {
60 case syncer::GROUP_UI: 62 case syncer::GROUP_UI:
61 return new BrowserThreadModelWorker(ui_task_runner_, group, observer); 63 return new BrowserThreadModelWorker(ui_task_runner_, group, observer);
62 case syncer::GROUP_DB: 64 case syncer::GROUP_DB:
63 return new BrowserThreadModelWorker(db_task_runner_, group, observer); 65 return new BrowserThreadModelWorker(db_task_runner_, group, observer);
64 case syncer::GROUP_FILE: 66 case syncer::GROUP_FILE:
65 return new BrowserThreadModelWorker(file_task_runner_, group, observer); 67 return new BrowserThreadModelWorker(file_task_runner_, group, observer);
66 case syncer::GROUP_PASSIVE: 68 case syncer::GROUP_PASSIVE:
67 return new syncer::PassiveModelWorker(observer); 69 return new syncer::PassiveModelWorker(observer);
68 default: 70 default:
69 return nullptr; 71 return nullptr;
70 } 72 }
71 } 73 }
72 74
73 private: 75 private:
74 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 76 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
75 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_; 77 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner_;
76 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 78 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
77 }; 79 };
78 80
79 // Flaky: https://crbug.com/498238 81 // Flaky: https://crbug.com/498238
80 class SyncBackendRegistrarTest : public testing::Test { 82 class SyncBackendRegistrarTest : public testing::Test {
81 public: 83 public:
82 void TestNonUIDataTypeActivationAsync(sync_driver::ChangeProcessor* processor, 84 void TestNonUIDataTypeActivationAsync(sync_driver::ChangeProcessor* processor,
83 base::WaitableEvent* done) { 85 base::WaitableEvent* done) {
84 registrar_->ActivateDataType(AUTOFILL, syncer::GROUP_DB, processor, 86 registrar_->ActivateDataType(AUTOFILL, syncer::GROUP_DB, processor,
85 test_user_share_.user_share()); 87 test_user_share_.user_share());
86 syncer::ModelSafeRoutingInfo expected_routing_info; 88 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, syncer::GROUP_DB}});
87 expected_routing_info[AUTOFILL] = syncer::GROUP_DB;
88 ExpectRoutingInfo(registrar_.get(), expected_routing_info);
89 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL)); 89 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet(AUTOFILL));
90 TriggerChanges(registrar_.get(), AUTOFILL); 90 TriggerChanges(registrar_.get(), AUTOFILL);
91 done->Signal(); 91 done->Signal();
92 } 92 }
93 93
94 protected: 94 protected:
95 SyncBackendRegistrarTest() 95 SyncBackendRegistrarTest()
96 : db_thread_("DBThreadForTest"), 96 : db_thread_("DBThreadForTest"),
97 file_thread_("FileThreadForTest"), 97 file_thread_("FileThreadForTest"),
98 sync_thread_(NULL) {} 98 sync_thread_(NULL) {}
(...skipping 15 matching lines...) Expand all
114 void TearDown() override { 114 void TearDown() override {
115 registrar_->RequestWorkerStopOnUIThread(); 115 registrar_->RequestWorkerStopOnUIThread();
116 test_user_share_.TearDown(); 116 test_user_share_.TearDown();
117 sync_thread_->task_runner()->PostTask( 117 sync_thread_->task_runner()->PostTask(
118 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown, 118 FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown,
119 base::Unretained(registrar_.release()))); 119 base::Unretained(registrar_.release())));
120 sync_thread_->WaitUntilThreadStarted(); 120 sync_thread_->WaitUntilThreadStarted();
121 base::RunLoop().RunUntilIdle(); 121 base::RunLoop().RunUntilIdle();
122 } 122 }
123 123
124 void ExpectRoutingInfo( 124 void ExpectRoutingInfo(SyncBackendRegistrar* registrar,
125 SyncBackendRegistrar* registrar, 125 const ModelSafeRoutingInfo& expected_routing_info) {
126 const syncer::ModelSafeRoutingInfo& expected_routing_info) { 126 ModelSafeRoutingInfo actual_routing_info;
127 syncer::ModelSafeRoutingInfo routing_info; 127 registrar->GetModelSafeRoutingInfo(&actual_routing_info);
128 registrar->GetModelSafeRoutingInfo(&routing_info); 128 EXPECT_EQ(expected_routing_info, actual_routing_info);
129 EXPECT_EQ(expected_routing_info, routing_info);
130 } 129 }
131 130
132 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar, 131 void ExpectHasProcessorsForTypes(const SyncBackendRegistrar& registrar,
133 ModelTypeSet types) { 132 ModelTypeSet types) {
134 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) {
135 ModelType model_type = ModelTypeFromInt(i); 134 ModelType model_type = ModelTypeFromInt(i);
136 EXPECT_EQ(types.Has(model_type), 135 EXPECT_EQ(types.Has(model_type),
137 registrar_->IsTypeActivatedForTest(model_type)); 136 registrar_->IsTypeActivatedForTest(model_type));
138 } 137 }
139 } 138 }
140 139
140 size_t GetWorkersSize() {
141 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers;
142 registrar_->GetWorkers(&workers);
143 return workers.size();
144 }
145
141 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() { 146 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() {
142 return message_loop_.task_runner(); 147 return message_loop_.task_runner();
143 } 148 }
144 149
145 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner() { 150 const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner() {
146 return db_thread_.task_runner(); 151 return db_thread_.task_runner();
147 } 152 }
148 153
149 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner() { 154 const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner() {
150 return db_thread_.task_runner(); 155 return db_thread_.task_runner();
151 } 156 }
152 157
153 base::MessageLoop message_loop_; 158 base::MessageLoop message_loop_;
154 base::Thread db_thread_; 159 base::Thread db_thread_;
155 base::Thread file_thread_; 160 base::Thread file_thread_;
156 161
157 syncer::TestUserShare test_user_share_; 162 syncer::TestUserShare test_user_share_;
158 std::unique_ptr<RegistrarSyncClient> sync_client_; 163 std::unique_ptr<RegistrarSyncClient> sync_client_;
159 std::unique_ptr<SyncBackendRegistrar> registrar_; 164 std::unique_ptr<SyncBackendRegistrar> registrar_;
160 165
161 base::Thread* sync_thread_; 166 base::Thread* sync_thread_;
162 }; 167 };
163 168
164 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) { 169 TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) {
165 registrar_->SetInitialTypes(ModelTypeSet()); 170 registrar_->SetInitialTypes(ModelTypeSet());
166 EXPECT_FALSE(registrar_->IsNigoriEnabled()); 171 EXPECT_FALSE(registrar_->IsNigoriEnabled());
167 { 172 EXPECT_EQ(4u, GetWorkersSize());
168 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers; 173 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo());
169 registrar_->GetWorkers(&workers);
170 EXPECT_EQ(4u, workers.size());
171 }
172 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo());
173 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); 174 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
174 } 175 }
175 176
176 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) { 177 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmpty) {
177 const ModelTypeSet initial_types(BOOKMARKS, NIGORI, PASSWORDS);
178 registrar_->RegisterNonBlockingType(BOOKMARKS); 178 registrar_->RegisterNonBlockingType(BOOKMARKS);
179 registrar_->SetInitialTypes(initial_types); 179 registrar_->SetInitialTypes(ModelTypeSet(BOOKMARKS, NIGORI, PASSWORDS));
180 EXPECT_TRUE(registrar_->IsNigoriEnabled()); 180 EXPECT_TRUE(registrar_->IsNigoriEnabled());
181 { 181 EXPECT_EQ(4u, GetWorkersSize());
182 std::vector<scoped_refptr<syncer::ModelSafeWorker>> workers; 182 EXPECT_EQ(ModelTypeSet(NIGORI), registrar_->GetLastConfiguredTypes());
183 registrar_->GetWorkers(&workers); 183 // Bookmarks dropped because it is nonblocking.
184 EXPECT_EQ(4u, workers.size()); 184 // Passwords dropped because of no password store.
185 } 185 ExpectRoutingInfo(registrar_.get(), {{NIGORI, syncer::GROUP_PASSIVE}});
186 {
187 syncer::ModelSafeRoutingInfo expected_routing_info;
188 expected_routing_info[BOOKMARKS] = syncer::GROUP_NON_BLOCKING;
189 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE;
190 // Passwords dropped because of no password store.
191 ExpectRoutingInfo(registrar_.get(), expected_routing_info);
192 }
193 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); 186 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
194 } 187 }
195 188
189 TEST_F(SyncBackendRegistrarTest, ConstructorNonEmptyReversedInitialization) {
190 // The blocking types get to set initial types before NonBlocking types here.
191 registrar_->SetInitialTypes(ModelTypeSet(BOOKMARKS, NIGORI, PASSWORDS));
192 registrar_->RegisterNonBlockingType(BOOKMARKS);
193 EXPECT_TRUE(registrar_->IsNigoriEnabled());
194 EXPECT_EQ(4u, GetWorkersSize());
195 EXPECT_EQ(ModelTypeSet(NIGORI), registrar_->GetLastConfiguredTypes());
196 // Bookmarks dropped because it is nonblocking.
197 // Passwords dropped because of no password store.
198 ExpectRoutingInfo(registrar_.get(), {{NIGORI, syncer::GROUP_PASSIVE}});
199 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
200 }
201
196 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) { 202 TEST_F(SyncBackendRegistrarTest, ConfigureDataTypes) {
197 registrar_->RegisterNonBlockingType(BOOKMARKS); 203 registrar_->RegisterNonBlockingType(BOOKMARKS);
198 registrar_->SetInitialTypes(ModelTypeSet()); 204 registrar_->SetInitialTypes(ModelTypeSet());
199 205
200 // Add. 206 // Add.
201 const ModelTypeSet types1(BOOKMARKS, NIGORI, AUTOFILL); 207 const ModelTypeSet types1(BOOKMARKS, NIGORI, AUTOFILL);
202 EXPECT_EQ(types1, registrar_->ConfigureDataTypes(types1, ModelTypeSet())); 208 EXPECT_EQ(types1, registrar_->ConfigureDataTypes(types1, ModelTypeSet()));
203 { 209 ExpectRoutingInfo(registrar_.get(), {{BOOKMARKS, syncer::GROUP_NON_BLOCKING},
204 syncer::ModelSafeRoutingInfo expected_routing_info; 210 {NIGORI, syncer::GROUP_PASSIVE},
205 expected_routing_info[BOOKMARKS] = syncer::GROUP_NON_BLOCKING; 211 {AUTOFILL, syncer::GROUP_PASSIVE}});
206 expected_routing_info[NIGORI] = syncer::GROUP_PASSIVE;
207 expected_routing_info[AUTOFILL] = syncer::GROUP_PASSIVE;
208 ExpectRoutingInfo(registrar_.get(), expected_routing_info);
209 }
210 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); 212 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
211 EXPECT_EQ(types1, registrar_->GetLastConfiguredTypes()); 213 EXPECT_EQ(types1, registrar_->GetLastConfiguredTypes());
212 214
213 // Add and remove. 215 // Add and remove.
214 const ModelTypeSet types2(PREFERENCES, THEMES); 216 const ModelTypeSet types2(PREFERENCES, THEMES);
215 EXPECT_EQ(types2, registrar_->ConfigureDataTypes(types2, types1)); 217 EXPECT_EQ(types2, registrar_->ConfigureDataTypes(types2, types1));
216 { 218
217 syncer::ModelSafeRoutingInfo expected_routing_info; 219 ExpectRoutingInfo(registrar_.get(), {{PREFERENCES, syncer::GROUP_PASSIVE},
218 expected_routing_info[PREFERENCES] = syncer::GROUP_PASSIVE; 220 {THEMES, syncer::GROUP_PASSIVE}});
219 expected_routing_info[THEMES] = syncer::GROUP_PASSIVE;
220 ExpectRoutingInfo(registrar_.get(), expected_routing_info);
221 }
222 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); 221 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
223 EXPECT_EQ(types2, registrar_->GetLastConfiguredTypes()); 222 EXPECT_EQ(types2, registrar_->GetLastConfiguredTypes());
224 223
225 // Remove. 224 // Remove.
226 EXPECT_TRUE(registrar_->ConfigureDataTypes(ModelTypeSet(), types2).Empty()); 225 EXPECT_TRUE(registrar_->ConfigureDataTypes(ModelTypeSet(), types2).Empty());
227 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); 226 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo());
228 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); 227 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
229 EXPECT_EQ(ModelTypeSet(), registrar_->GetLastConfiguredTypes()); 228 EXPECT_EQ(ModelTypeSet(), registrar_->GetLastConfiguredTypes());
230 } 229 }
231 230
232 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) { 231 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateUIDataType) {
233 InSequence in_sequence; 232 InSequence in_sequence;
234 registrar_->SetInitialTypes(ModelTypeSet()); 233 registrar_->SetInitialTypes(ModelTypeSet());
235 234
236 // Should do nothing. 235 // Should do nothing.
237 TriggerChanges(registrar_.get(), BOOKMARKS); 236 TriggerChanges(registrar_.get(), BOOKMARKS);
238 237
239 StrictMock<sync_driver::ChangeProcessorMock> change_processor_mock; 238 StrictMock<sync_driver::ChangeProcessorMock> change_processor_mock;
240 EXPECT_CALL(change_processor_mock, StartImpl()); 239 EXPECT_CALL(change_processor_mock, StartImpl());
241 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); 240 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true));
242 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _)); 241 EXPECT_CALL(change_processor_mock, ApplyChangesFromSyncModel(NULL, _, _));
243 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true)); 242 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(true));
244 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel()); 243 EXPECT_CALL(change_processor_mock, CommitChangesFromSyncModel());
245 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false)); 244 EXPECT_CALL(change_processor_mock, IsRunning()).WillRepeatedly(Return(false));
246 245
247 const ModelTypeSet types(BOOKMARKS); 246 const ModelTypeSet types(BOOKMARKS);
248 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet())); 247 EXPECT_EQ(types, registrar_->ConfigureDataTypes(types, ModelTypeSet()));
249 registrar_->ActivateDataType(BOOKMARKS, syncer::GROUP_UI, 248 registrar_->ActivateDataType(BOOKMARKS, syncer::GROUP_UI,
250 &change_processor_mock, 249 &change_processor_mock,
251 test_user_share_.user_share()); 250 test_user_share_.user_share());
252 { 251 ExpectRoutingInfo(registrar_.get(), {{BOOKMARKS, syncer::GROUP_UI}});
253 syncer::ModelSafeRoutingInfo expected_routing_info;
254 expected_routing_info[BOOKMARKS] = syncer::GROUP_UI;
255 ExpectRoutingInfo(registrar_.get(), expected_routing_info);
256 }
257 ExpectHasProcessorsForTypes(*registrar_, types); 252 ExpectHasProcessorsForTypes(*registrar_, types);
258 253
259 TriggerChanges(registrar_.get(), BOOKMARKS); 254 TriggerChanges(registrar_.get(), BOOKMARKS);
260 255
261 registrar_->DeactivateDataType(BOOKMARKS); 256 registrar_->DeactivateDataType(BOOKMARKS);
262 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); 257 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo());
263 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); 258 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
264 259
265 // Should do nothing. 260 // Should do nothing.
266 TriggerChanges(registrar_.get(), BOOKMARKS); 261 TriggerChanges(registrar_.get(), BOOKMARKS);
267 } 262 }
268 263
269 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) { 264 TEST_F(SyncBackendRegistrarTest, ActivateDeactivateNonUIDataType) {
270 InSequence in_sequence; 265 InSequence in_sequence;
271 registrar_->SetInitialTypes(ModelTypeSet()); 266 registrar_->SetInitialTypes(ModelTypeSet());
272 267
(...skipping 13 matching lines...) Expand all
286 281
287 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, 282 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC,
288 base::WaitableEvent::InitialState::NOT_SIGNALED); 283 base::WaitableEvent::InitialState::NOT_SIGNALED);
289 db_task_runner()->PostTask( 284 db_task_runner()->PostTask(
290 FROM_HERE, 285 FROM_HERE,
291 base::Bind(&SyncBackendRegistrarTest::TestNonUIDataTypeActivationAsync, 286 base::Bind(&SyncBackendRegistrarTest::TestNonUIDataTypeActivationAsync,
292 base::Unretained(this), &change_processor_mock, &done)); 287 base::Unretained(this), &change_processor_mock, &done));
293 done.Wait(); 288 done.Wait();
294 289
295 registrar_->DeactivateDataType(AUTOFILL); 290 registrar_->DeactivateDataType(AUTOFILL);
296 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); 291 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo());
297 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet()); 292 ExpectHasProcessorsForTypes(*registrar_, ModelTypeSet());
298 293
299 // Should do nothing. 294 // Should do nothing.
300 TriggerChanges(registrar_.get(), AUTOFILL); 295 TriggerChanges(registrar_.get(), AUTOFILL);
301 } 296 }
302 297
303 // Tests that registration and configuration of non-blocking data types is 298 // Tests that registration and configuration of non-blocking data types is
304 // handled correctly in SyncBackendRegistrar. 299 // handled correctly in SyncBackendRegistrar.
305 TEST_F(SyncBackendRegistrarTest, ConfigureNonBlockingDataType) { 300 TEST_F(SyncBackendRegistrarTest, ConfigureNonBlockingDataType) {
306 registrar_->RegisterNonBlockingType(AUTOFILL); 301 registrar_->RegisterNonBlockingType(AUTOFILL);
307 registrar_->RegisterNonBlockingType(BOOKMARKS); 302 registrar_->RegisterNonBlockingType(BOOKMARKS);
308 303
309 ExpectRoutingInfo(registrar_.get(), syncer::ModelSafeRoutingInfo()); 304 ExpectRoutingInfo(registrar_.get(), ModelSafeRoutingInfo());
310 // Simulate that initial sync was already done for AUTOFILL. 305 // Simulate that initial sync was already done for AUTOFILL.
311 registrar_->AddRestoredNonBlockingType(AUTOFILL); 306 registrar_->AddRestoredNonBlockingType(AUTOFILL);
312 // 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.
313 EXPECT_EQ(ModelTypeSet(AUTOFILL), registrar_->GetLastConfiguredTypes()); 308 EXPECT_EQ(ModelTypeSet(AUTOFILL), registrar_->GetLastConfiguredTypes());
314 { 309 ExpectRoutingInfo(registrar_.get(), {{AUTOFILL, syncer::GROUP_NON_BLOCKING}});
315 syncer::ModelSafeRoutingInfo expected_routing_info;
316 expected_routing_info[AUTOFILL] = syncer::GROUP_NON_BLOCKING;
317 ExpectRoutingInfo(registrar_.get(), expected_routing_info);
318 }
319 310
320 // 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
321 // it should be included in types to be downloaded. 312 // it should be included in types to be downloaded.
322 ModelTypeSet types_to_add(AUTOFILL, BOOKMARKS); 313 ModelTypeSet types_to_add(AUTOFILL, BOOKMARKS);
323 ModelTypeSet newly_added_types = 314 ModelTypeSet newly_added_types =
324 registrar_->ConfigureDataTypes(types_to_add, ModelTypeSet()); 315 registrar_->ConfigureDataTypes(types_to_add, ModelTypeSet());
325 EXPECT_EQ(ModelTypeSet(BOOKMARKS), newly_added_types); 316 EXPECT_EQ(ModelTypeSet(BOOKMARKS), newly_added_types);
326 EXPECT_EQ(types_to_add, registrar_->GetLastConfiguredTypes()); 317 EXPECT_EQ(types_to_add, registrar_->GetLastConfiguredTypes());
327 { 318 ExpectRoutingInfo(registrar_.get(),
328 syncer::ModelSafeRoutingInfo expected_routing_info; 319 {{AUTOFILL, syncer::GROUP_NON_BLOCKING},
329 expected_routing_info[AUTOFILL] = syncer::GROUP_NON_BLOCKING; 320 {BOOKMARKS, syncer::GROUP_NON_BLOCKING}});
330 expected_routing_info[BOOKMARKS] = syncer::GROUP_NON_BLOCKING;
331 ExpectRoutingInfo(registrar_.get(), expected_routing_info);
332 }
333 } 321 }
334 322
335 class SyncBackendRegistrarShutdownTest : public testing::Test { 323 class SyncBackendRegistrarShutdownTest : public testing::Test {
336 public: 324 public:
337 void BlockDBThread() { 325 void BlockDBThread() {
338 EXPECT_FALSE(db_thread_lock_.Try()); 326 EXPECT_FALSE(db_thread_lock_.Try());
339 327
340 db_thread_blocked_.Signal(); 328 db_thread_blocked_.Signal();
341 base::AutoLock l(db_thread_lock_); 329 base::AutoLock l(db_thread_lock_);
342 } 330 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 db_thread_lock_.Release(); 440 db_thread_lock_.Release();
453 441
454 // 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
455 // registrar destroyed. 443 // registrar destroyed.
456 run_loop_.Run(); 444 run_loop_.Run();
457 } 445 }
458 446
459 } // namespace 447 } // namespace
460 448
461 } // namespace browser_sync 449 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync/driver/glue/sync_backend_registrar.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698