OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/device_info_sync_service.h" | 5 #include "components/sync/driver/device_info_sync_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "components/sync/api/sync_change.h" | 13 #include "components/sync/api/sync_change.h" |
14 #include "components/sync/api/sync_change_processor.h" | 14 #include "components/sync/api/sync_change_processor.h" |
15 #include "components/sync/api/sync_change_processor_wrapper_for_test.h" | 15 #include "components/sync/api/sync_change_processor_wrapper_for_test.h" |
16 #include "components/sync/api/sync_error_factory_mock.h" | 16 #include "components/sync/api/sync_error_factory_mock.h" |
17 #include "components/sync/base/time.h" | 17 #include "components/sync/base/time.h" |
18 #include "components/sync/core/attachments/attachment_service_proxy_for_test.h" | 18 #include "components/sync/core/attachments/attachment_service_proxy_for_test.h" |
19 #include "components/sync_driver/device_info_util.h" | 19 #include "components/sync/driver/device_info_util.h" |
20 #include "components/sync_driver/local_device_info_provider_mock.h" | 20 #include "components/sync/driver/local_device_info_provider_mock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 using base::Time; | 23 using base::Time; |
24 using base::TimeDelta; | 24 using base::TimeDelta; |
25 using syncer::AttachmentIdList; | 25 using syncer::AttachmentIdList; |
26 using syncer::AttachmentServiceProxyForTest; | 26 using syncer::AttachmentServiceProxyForTest; |
27 using syncer::ModelType; | 27 using syncer::ModelType; |
28 using syncer::SyncChange; | 28 using syncer::SyncChange; |
29 using syncer::SyncChangeList; | 29 using syncer::SyncChangeList; |
30 using syncer::SyncChangeProcessor; | 30 using syncer::SyncChangeProcessor; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 class DeviceInfoSyncServiceTest : public testing::Test, | 88 class DeviceInfoSyncServiceTest : public testing::Test, |
89 public DeviceInfoTracker::Observer { | 89 public DeviceInfoTracker::Observer { |
90 public: | 90 public: |
91 DeviceInfoSyncServiceTest() : num_device_info_changed_callbacks_(0) {} | 91 DeviceInfoSyncServiceTest() : num_device_info_changed_callbacks_(0) {} |
92 ~DeviceInfoSyncServiceTest() override {} | 92 ~DeviceInfoSyncServiceTest() override {} |
93 | 93 |
94 void SetUp() override { | 94 void SetUp() override { |
95 local_device_.reset(new LocalDeviceInfoProviderMock( | 95 local_device_.reset(new LocalDeviceInfoProviderMock( |
96 "guid_1", | 96 "guid_1", "client_1", "Chromium 10k", "Chrome 10k", |
97 "client_1", | 97 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id")); |
98 "Chromium 10k", | |
99 "Chrome 10k", | |
100 sync_pb::SyncEnums_DeviceType_TYPE_LINUX, | |
101 "device_id")); | |
102 sync_service_.reset(new DeviceInfoSyncService(local_device_.get())); | 98 sync_service_.reset(new DeviceInfoSyncService(local_device_.get())); |
103 sync_processor_.reset(new TestChangeProcessor()); | 99 sync_processor_.reset(new TestChangeProcessor()); |
104 // Register observer | 100 // Register observer |
105 sync_service_->AddObserver(this); | 101 sync_service_->AddObserver(this); |
106 } | 102 } |
107 | 103 |
108 void TearDown() override { sync_service_->RemoveObserver(this); } | 104 void TearDown() override { sync_service_->RemoveObserver(this); } |
109 | 105 |
110 void OnDeviceInfoChange() override { num_device_info_changed_callbacks_++; } | 106 void OnDeviceInfoChange() override { num_device_info_changed_callbacks_++; } |
111 | 107 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 std::unique_ptr<DeviceInfoSyncService> sync_service_; | 179 std::unique_ptr<DeviceInfoSyncService> sync_service_; |
184 std::unique_ptr<TestChangeProcessor> sync_processor_; | 180 std::unique_ptr<TestChangeProcessor> sync_processor_; |
185 }; | 181 }; |
186 | 182 |
187 namespace { | 183 namespace { |
188 | 184 |
189 // Sync with empty initial data. | 185 // Sync with empty initial data. |
190 TEST_F(DeviceInfoSyncServiceTest, StartSyncEmptyInitialData) { | 186 TEST_F(DeviceInfoSyncServiceTest, StartSyncEmptyInitialData) { |
191 EXPECT_FALSE(sync_service_->IsSyncing()); | 187 EXPECT_FALSE(sync_service_->IsSyncing()); |
192 | 188 |
193 SyncMergeResult merge_result = | 189 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
194 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 190 syncer::DEVICE_INFO, SyncDataList(), PassProcessor(), |
195 SyncDataList(), | 191 CreateAndPassSyncErrorFactory()); |
196 PassProcessor(), | |
197 CreateAndPassSyncErrorFactory()); | |
198 | 192 |
199 EXPECT_TRUE(sync_service_->IsSyncing()); | 193 EXPECT_TRUE(sync_service_->IsSyncing()); |
200 EXPECT_EQ(0, merge_result.num_items_added()); | 194 EXPECT_EQ(0, merge_result.num_items_added()); |
201 EXPECT_EQ(0, merge_result.num_items_modified()); | 195 EXPECT_EQ(0, merge_result.num_items_modified()); |
202 EXPECT_EQ(0, merge_result.num_items_deleted()); | 196 EXPECT_EQ(0, merge_result.num_items_deleted()); |
203 EXPECT_EQ(1, merge_result.num_items_before_association()); | 197 EXPECT_EQ(1, merge_result.num_items_before_association()); |
204 EXPECT_EQ(1, merge_result.num_items_after_association()); | 198 EXPECT_EQ(1, merge_result.num_items_after_association()); |
205 EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0)); | 199 EXPECT_EQ(SyncChange::ACTION_ADD, sync_processor_->change_type_at(0)); |
206 | 200 |
207 EXPECT_EQ(1U, sync_processor_->change_list_size()); | 201 EXPECT_EQ(1U, sync_processor_->change_list_size()); |
(...skipping 17 matching lines...) Expand all Loading... |
225 EXPECT_FALSE(sync_service_->IsSyncing()); | 219 EXPECT_FALSE(sync_service_->IsSyncing()); |
226 EXPECT_EQ(2, num_device_info_changed_callbacks_); | 220 EXPECT_EQ(2, num_device_info_changed_callbacks_); |
227 EXPECT_FALSE(IsPulseTimerRunning()); | 221 EXPECT_FALSE(IsPulseTimerRunning()); |
228 } | 222 } |
229 | 223 |
230 // Sync with initial data matching the local device data. | 224 // Sync with initial data matching the local device data. |
231 TEST_F(DeviceInfoSyncServiceTest, StartSyncMatchingInitialData) { | 225 TEST_F(DeviceInfoSyncServiceTest, StartSyncMatchingInitialData) { |
232 SyncDataList sync_data; | 226 SyncDataList sync_data; |
233 AddInitialData(&sync_data, "guid_1", "client_1"); | 227 AddInitialData(&sync_data, "guid_1", "client_1"); |
234 | 228 |
235 SyncMergeResult merge_result = | 229 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
236 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 230 syncer::DEVICE_INFO, sync_data, PassProcessor(), |
237 sync_data, | 231 CreateAndPassSyncErrorFactory()); |
238 PassProcessor(), | |
239 CreateAndPassSyncErrorFactory()); | |
240 EXPECT_EQ(0, merge_result.num_items_added()); | 232 EXPECT_EQ(0, merge_result.num_items_added()); |
241 EXPECT_EQ(0, merge_result.num_items_modified()); | 233 EXPECT_EQ(0, merge_result.num_items_modified()); |
242 EXPECT_EQ(0, merge_result.num_items_deleted()); | 234 EXPECT_EQ(0, merge_result.num_items_deleted()); |
243 EXPECT_EQ(1, merge_result.num_items_before_association()); | 235 EXPECT_EQ(1, merge_result.num_items_before_association()); |
244 EXPECT_EQ(1, merge_result.num_items_after_association()); | 236 EXPECT_EQ(1, merge_result.num_items_after_association()); |
245 | 237 |
246 // No changes expected because the device info matches. | 238 // No changes expected because the device info matches. |
247 EXPECT_EQ(0U, sync_processor_->change_list_size()); | 239 EXPECT_EQ(0U, sync_processor_->change_list_size()); |
248 | 240 |
249 EXPECT_EQ(1U, sync_service_->GetAllSyncData(syncer::DEVICE_INFO).size()); | 241 EXPECT_EQ(1U, sync_service_->GetAllSyncData(syncer::DEVICE_INFO).size()); |
250 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size()); | 242 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size()); |
251 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1")); | 243 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1")); |
252 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0")); | 244 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0")); |
253 } | 245 } |
254 | 246 |
255 // Sync with misc initial data. | 247 // Sync with misc initial data. |
256 TEST_F(DeviceInfoSyncServiceTest, StartSync) { | 248 TEST_F(DeviceInfoSyncServiceTest, StartSync) { |
257 SyncDataList sync_data; | 249 SyncDataList sync_data; |
258 AddInitialData(&sync_data, "guid_2", "foo"); | 250 AddInitialData(&sync_data, "guid_2", "foo"); |
259 AddInitialData(&sync_data, "guid_3", "bar"); | 251 AddInitialData(&sync_data, "guid_3", "bar"); |
260 // This guid matches the local device but the client name is different. | 252 // This guid matches the local device but the client name is different. |
261 AddInitialData(&sync_data, "guid_1", "baz"); | 253 AddInitialData(&sync_data, "guid_1", "baz"); |
262 | 254 |
263 SyncMergeResult merge_result = | 255 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
264 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 256 syncer::DEVICE_INFO, sync_data, PassProcessor(), |
265 sync_data, | 257 CreateAndPassSyncErrorFactory()); |
266 PassProcessor(), | |
267 CreateAndPassSyncErrorFactory()); | |
268 | 258 |
269 EXPECT_EQ(2, merge_result.num_items_added()); | 259 EXPECT_EQ(2, merge_result.num_items_added()); |
270 EXPECT_EQ(1, merge_result.num_items_modified()); | 260 EXPECT_EQ(1, merge_result.num_items_modified()); |
271 EXPECT_EQ(0, merge_result.num_items_deleted()); | 261 EXPECT_EQ(0, merge_result.num_items_deleted()); |
272 EXPECT_EQ(1, merge_result.num_items_before_association()); | 262 EXPECT_EQ(1, merge_result.num_items_before_association()); |
273 EXPECT_EQ(3, merge_result.num_items_after_association()); | 263 EXPECT_EQ(3, merge_result.num_items_after_association()); |
274 | 264 |
275 EXPECT_EQ(1U, sync_processor_->change_list_size()); | 265 EXPECT_EQ(1U, sync_processor_->change_list_size()); |
276 EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0)); | 266 EXPECT_EQ(SyncChange::ACTION_UPDATE, sync_processor_->change_type_at(0)); |
277 EXPECT_EQ("client_1", sync_processor_->client_name_at(0)); | 267 EXPECT_EQ("client_1", sync_processor_->client_name_at(0)); |
278 | 268 |
279 EXPECT_EQ(3U, sync_service_->GetAllSyncData(syncer::DEVICE_INFO).size()); | 269 EXPECT_EQ(3U, sync_service_->GetAllSyncData(syncer::DEVICE_INFO).size()); |
280 EXPECT_EQ(3U, sync_service_->GetAllDeviceInfo().size()); | 270 EXPECT_EQ(3U, sync_service_->GetAllDeviceInfo().size()); |
281 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1")); | 271 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1")); |
282 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_2")); | 272 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_2")); |
283 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_3")); | 273 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_3")); |
284 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0")); | 274 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0")); |
285 } | 275 } |
286 | 276 |
287 // Process sync change with ACTION_ADD. | 277 // Process sync change with ACTION_ADD. |
288 // Verify callback. | 278 // Verify callback. |
289 TEST_F(DeviceInfoSyncServiceTest, ProcessAddChange) { | 279 TEST_F(DeviceInfoSyncServiceTest, ProcessAddChange) { |
290 EXPECT_EQ(0, num_device_info_changed_callbacks_); | 280 EXPECT_EQ(0, num_device_info_changed_callbacks_); |
291 | 281 |
292 // Start with an empty initial data. | 282 // Start with an empty initial data. |
293 SyncMergeResult merge_result = | 283 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
294 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 284 syncer::DEVICE_INFO, SyncDataList(), PassProcessor(), |
295 SyncDataList(), | 285 CreateAndPassSyncErrorFactory()); |
296 PassProcessor(), | |
297 CreateAndPassSyncErrorFactory()); | |
298 // There should be only one item corresponding to the local device | 286 // There should be only one item corresponding to the local device |
299 EXPECT_EQ(1, merge_result.num_items_after_association()); | 287 EXPECT_EQ(1, merge_result.num_items_after_association()); |
300 EXPECT_EQ(1, num_device_info_changed_callbacks_); | 288 EXPECT_EQ(1, num_device_info_changed_callbacks_); |
301 | 289 |
302 // Add a new device info with a non-matching guid. | 290 // Add a new device info with a non-matching guid. |
303 SyncChangeList change_list; | 291 SyncChangeList change_list; |
304 AddChange(&change_list, SyncChange::ACTION_ADD, "guid_2", "foo"); | 292 AddChange(&change_list, SyncChange::ACTION_ADD, "guid_2", "foo"); |
305 | 293 |
306 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); | 294 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); |
307 EXPECT_FALSE(error.IsSet()); | 295 EXPECT_FALSE(error.IsSet()); |
308 EXPECT_EQ(2, num_device_info_changed_callbacks_); | 296 EXPECT_EQ(2, num_device_info_changed_callbacks_); |
309 | 297 |
310 EXPECT_EQ(2U, sync_service_->GetAllDeviceInfo().size()); | 298 EXPECT_EQ(2U, sync_service_->GetAllDeviceInfo().size()); |
311 | 299 |
312 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1")); | 300 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_1")); |
313 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_2")); | 301 EXPECT_TRUE(sync_service_->GetDeviceInfo("guid_2")); |
314 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0")); | 302 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_0")); |
315 } | 303 } |
316 | 304 |
317 // Process multiple sync change with ACTION_UPDATE and ACTION_ADD. | 305 // Process multiple sync change with ACTION_UPDATE and ACTION_ADD. |
318 // Verify that callback is called multiple times. | 306 // Verify that callback is called multiple times. |
319 TEST_F(DeviceInfoSyncServiceTest, ProcessMultipleChanges) { | 307 TEST_F(DeviceInfoSyncServiceTest, ProcessMultipleChanges) { |
320 SyncDataList sync_data; | 308 SyncDataList sync_data; |
321 AddInitialData(&sync_data, "guid_2", "foo"); | 309 AddInitialData(&sync_data, "guid_2", "foo"); |
322 AddInitialData(&sync_data, "guid_3", "bar"); | 310 AddInitialData(&sync_data, "guid_3", "bar"); |
323 | 311 |
324 SyncMergeResult merge_result = | 312 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
325 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 313 syncer::DEVICE_INFO, sync_data, PassProcessor(), |
326 sync_data, | 314 CreateAndPassSyncErrorFactory()); |
327 PassProcessor(), | |
328 CreateAndPassSyncErrorFactory()); | |
329 EXPECT_EQ(3, merge_result.num_items_after_association()); | 315 EXPECT_EQ(3, merge_result.num_items_after_association()); |
330 // reset callbacks counter | 316 // reset callbacks counter |
331 num_device_info_changed_callbacks_ = 0; | 317 num_device_info_changed_callbacks_ = 0; |
332 | 318 |
333 SyncChangeList change_list; | 319 SyncChangeList change_list; |
334 AddChange(&change_list, SyncChange::ACTION_UPDATE, "guid_2", "foo_2"); | 320 AddChange(&change_list, SyncChange::ACTION_UPDATE, "guid_2", "foo_2"); |
335 | 321 |
336 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); | 322 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); |
337 EXPECT_FALSE(error.IsSet()); | 323 EXPECT_FALSE(error.IsSet()); |
338 | 324 |
339 EXPECT_EQ(1, num_device_info_changed_callbacks_); | 325 EXPECT_EQ(1, num_device_info_changed_callbacks_); |
340 EXPECT_EQ(3U, sync_service_->GetAllDeviceInfo().size()); | 326 EXPECT_EQ(3U, sync_service_->GetAllDeviceInfo().size()); |
341 EXPECT_EQ("foo_2", sync_service_->GetDeviceInfo("guid_2")->client_name()); | 327 EXPECT_EQ("foo_2", sync_service_->GetDeviceInfo("guid_2")->client_name()); |
342 | 328 |
343 change_list.clear(); | 329 change_list.clear(); |
344 AddChange(&change_list, SyncChange::ACTION_UPDATE, "guid_3", "bar_3"); | 330 AddChange(&change_list, SyncChange::ACTION_UPDATE, "guid_3", "bar_3"); |
345 AddChange(&change_list, SyncChange::ACTION_ADD, "guid_4", "baz_4"); | 331 AddChange(&change_list, SyncChange::ACTION_ADD, "guid_4", "baz_4"); |
346 | 332 |
347 error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); | 333 error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); |
348 EXPECT_FALSE(error.IsSet()); | 334 EXPECT_FALSE(error.IsSet()); |
349 | 335 |
350 EXPECT_EQ(2, num_device_info_changed_callbacks_); | 336 EXPECT_EQ(2, num_device_info_changed_callbacks_); |
351 EXPECT_EQ(4U, sync_service_->GetAllDeviceInfo().size()); | 337 EXPECT_EQ(4U, sync_service_->GetAllDeviceInfo().size()); |
352 EXPECT_EQ("bar_3", sync_service_->GetDeviceInfo("guid_3")->client_name()); | 338 EXPECT_EQ("bar_3", sync_service_->GetDeviceInfo("guid_3")->client_name()); |
353 EXPECT_EQ("baz_4", sync_service_->GetDeviceInfo("guid_4")->client_name()); | 339 EXPECT_EQ("baz_4", sync_service_->GetDeviceInfo("guid_4")->client_name()); |
354 } | 340 } |
355 | 341 |
356 // Process update to the local device info and verify that it is ignored. | 342 // Process update to the local device info and verify that it is ignored. |
357 TEST_F(DeviceInfoSyncServiceTest, ProcessUpdateChangeMatchingLocalDevice) { | 343 TEST_F(DeviceInfoSyncServiceTest, ProcessUpdateChangeMatchingLocalDevice) { |
358 SyncMergeResult merge_result = | 344 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
359 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 345 syncer::DEVICE_INFO, SyncDataList(), PassProcessor(), |
360 SyncDataList(), | 346 CreateAndPassSyncErrorFactory()); |
361 PassProcessor(), | |
362 CreateAndPassSyncErrorFactory()); | |
363 EXPECT_EQ(1, merge_result.num_items_after_association()); | 347 EXPECT_EQ(1, merge_result.num_items_after_association()); |
364 // reset callbacks counter | 348 // reset callbacks counter |
365 num_device_info_changed_callbacks_ = 0; | 349 num_device_info_changed_callbacks_ = 0; |
366 | 350 |
367 SyncChangeList change_list; | 351 SyncChangeList change_list; |
368 AddChange(&change_list, SyncChange::ACTION_UPDATE, "guid_1", "foo_1"); | 352 AddChange(&change_list, SyncChange::ACTION_UPDATE, "guid_1", "foo_1"); |
369 | 353 |
370 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); | 354 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); |
371 EXPECT_FALSE(error.IsSet()); | 355 EXPECT_FALSE(error.IsSet()); |
372 // Callback shouldn't be sent in this case. | 356 // Callback shouldn't be sent in this case. |
373 EXPECT_EQ(0, num_device_info_changed_callbacks_); | 357 EXPECT_EQ(0, num_device_info_changed_callbacks_); |
374 // Should still have the old local device Info. | 358 // Should still have the old local device Info. |
375 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size()); | 359 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size()); |
376 EXPECT_EQ("client_1", sync_service_->GetDeviceInfo("guid_1")->client_name()); | 360 EXPECT_EQ("client_1", sync_service_->GetDeviceInfo("guid_1")->client_name()); |
377 } | 361 } |
378 | 362 |
379 // Process sync change with ACTION_DELETE. | 363 // Process sync change with ACTION_DELETE. |
380 TEST_F(DeviceInfoSyncServiceTest, ProcessDeleteChange) { | 364 TEST_F(DeviceInfoSyncServiceTest, ProcessDeleteChange) { |
381 SyncDataList sync_data; | 365 SyncDataList sync_data; |
382 AddInitialData(&sync_data, "guid_2", "foo"); | 366 AddInitialData(&sync_data, "guid_2", "foo"); |
383 AddInitialData(&sync_data, "guid_3", "bar"); | 367 AddInitialData(&sync_data, "guid_3", "bar"); |
384 | 368 |
385 SyncMergeResult merge_result = | 369 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
386 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 370 syncer::DEVICE_INFO, sync_data, PassProcessor(), |
387 sync_data, | 371 CreateAndPassSyncErrorFactory()); |
388 PassProcessor(), | |
389 CreateAndPassSyncErrorFactory()); | |
390 EXPECT_EQ(3, merge_result.num_items_after_association()); | 372 EXPECT_EQ(3, merge_result.num_items_after_association()); |
391 // reset callbacks counter | 373 // reset callbacks counter |
392 num_device_info_changed_callbacks_ = 0; | 374 num_device_info_changed_callbacks_ = 0; |
393 | 375 |
394 SyncChangeList change_list; | 376 SyncChangeList change_list; |
395 AddChange(&change_list, SyncChange::ACTION_DELETE, "guid_2", "foo_2"); | 377 AddChange(&change_list, SyncChange::ACTION_DELETE, "guid_2", "foo_2"); |
396 | 378 |
397 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); | 379 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); |
398 EXPECT_FALSE(error.IsSet()); | 380 EXPECT_FALSE(error.IsSet()); |
399 | 381 |
400 EXPECT_EQ(1, num_device_info_changed_callbacks_); | 382 EXPECT_EQ(1, num_device_info_changed_callbacks_); |
401 EXPECT_EQ(2U, sync_service_->GetAllDeviceInfo().size()); | 383 EXPECT_EQ(2U, sync_service_->GetAllDeviceInfo().size()); |
402 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_2")); | 384 EXPECT_FALSE(sync_service_->GetDeviceInfo("guid_2")); |
403 } | 385 } |
404 | 386 |
405 // Process sync change with unexpected action. | 387 // Process sync change with unexpected action. |
406 TEST_F(DeviceInfoSyncServiceTest, ProcessInvalidChange) { | 388 TEST_F(DeviceInfoSyncServiceTest, ProcessInvalidChange) { |
407 SyncMergeResult merge_result = | 389 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
408 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 390 syncer::DEVICE_INFO, SyncDataList(), PassProcessor(), |
409 SyncDataList(), | 391 CreateAndPassSyncErrorFactory()); |
410 PassProcessor(), | |
411 CreateAndPassSyncErrorFactory()); | |
412 EXPECT_EQ(1, merge_result.num_items_after_association()); | 392 EXPECT_EQ(1, merge_result.num_items_after_association()); |
413 // reset callbacks counter | 393 // reset callbacks counter |
414 num_device_info_changed_callbacks_ = 0; | 394 num_device_info_changed_callbacks_ = 0; |
415 | 395 |
416 SyncChangeList change_list; | 396 SyncChangeList change_list; |
417 AddChange(&change_list, (SyncChange::SyncChangeType)100, "guid_2", "foo_2"); | 397 AddChange(&change_list, (SyncChange::SyncChangeType)100, "guid_2", "foo_2"); |
418 | 398 |
419 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); | 399 SyncError error = sync_service_->ProcessSyncChanges(FROM_HERE, change_list); |
420 EXPECT_TRUE(error.IsSet()); | 400 EXPECT_TRUE(error.IsSet()); |
421 | 401 |
422 // The number of callback should still be zero. | 402 // The number of callback should still be zero. |
423 EXPECT_EQ(0, num_device_info_changed_callbacks_); | 403 EXPECT_EQ(0, num_device_info_changed_callbacks_); |
424 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size()); | 404 EXPECT_EQ(1U, sync_service_->GetAllDeviceInfo().size()); |
425 } | 405 } |
426 | 406 |
427 // Process sync change after unsubscribing from notifications. | 407 // Process sync change after unsubscribing from notifications. |
428 TEST_F(DeviceInfoSyncServiceTest, ProcessChangesAfterUnsubscribing) { | 408 TEST_F(DeviceInfoSyncServiceTest, ProcessChangesAfterUnsubscribing) { |
429 SyncMergeResult merge_result = | 409 SyncMergeResult merge_result = sync_service_->MergeDataAndStartSyncing( |
430 sync_service_->MergeDataAndStartSyncing(syncer::DEVICE_INFO, | 410 syncer::DEVICE_INFO, SyncDataList(), PassProcessor(), |
431 SyncDataList(), | 411 CreateAndPassSyncErrorFactory()); |
432 PassProcessor(), | |
433 CreateAndPassSyncErrorFactory()); | |
434 EXPECT_EQ(1, merge_result.num_items_after_association()); | 412 EXPECT_EQ(1, merge_result.num_items_after_association()); |
435 // reset callbacks counter | 413 // reset callbacks counter |
436 num_device_info_changed_callbacks_ = 0; | 414 num_device_info_changed_callbacks_ = 0; |
437 | 415 |
438 SyncChangeList change_list; | 416 SyncChangeList change_list; |
439 AddChange(&change_list, SyncChange::ACTION_ADD, "guid_2", "foo_2"); | 417 AddChange(&change_list, SyncChange::ACTION_ADD, "guid_2", "foo_2"); |
440 | 418 |
441 // Unsubscribe observer before processing changes. | 419 // Unsubscribe observer before processing changes. |
442 sync_service_->RemoveObserver(this); | 420 sync_service_->RemoveObserver(this); |
443 | 421 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 sync_pb::EntitySpecifics entity; | 572 sync_pb::EntitySpecifics entity; |
595 sync_pb::DeviceInfoSpecifics& specifics = *entity.mutable_device_info(); | 573 sync_pb::DeviceInfoSpecifics& specifics = *entity.mutable_device_info(); |
596 specifics.set_cache_guid("stale"); | 574 specifics.set_cache_guid("stale"); |
597 StoreSyncData("stale", SyncData::CreateLocalData("stale", "stale", entity)); | 575 StoreSyncData("stale", SyncData::CreateLocalData("stale", "stale", entity)); |
598 EXPECT_EQ(0, CountActiveDevices(Time() + DeviceInfoUtil::kActiveThreshold)); | 576 EXPECT_EQ(0, CountActiveDevices(Time() + DeviceInfoUtil::kActiveThreshold)); |
599 } | 577 } |
600 | 578 |
601 } // namespace | 579 } // namespace |
602 | 580 |
603 } // namespace sync_driver | 581 } // namespace sync_driver |
OLD | NEW |