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 "sync/engine/get_updates_processor.h" | 5 #include "components/sync/engine_impl/get_updates_processor.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "sync/engine/get_updates_delegate.h" | 14 #include "components/sync/base/model_type_test_util.h" |
15 #include "sync/engine/update_handler.h" | 15 #include "components/sync/engine_impl/get_updates_delegate.h" |
16 #include "sync/internal_api/public/base/model_type_test_util.h" | 16 #include "components/sync/engine_impl/update_handler.h" |
17 #include "sync/protocol/sync.pb.h" | 17 #include "components/sync/protocol/sync.pb.h" |
18 #include "sync/sessions/debug_info_getter.h" | 18 #include "components/sync/sessions_impl/debug_info_getter.h" |
19 #include "sync/sessions/nudge_tracker.h" | 19 #include "components/sync/sessions_impl/nudge_tracker.h" |
20 #include "sync/sessions/status_controller.h" | 20 #include "components/sync/sessions_impl/status_controller.h" |
21 #include "sync/test/engine/fake_model_worker.h" | 21 #include "components/sync/test/engine/fake_model_worker.h" |
22 #include "sync/test/engine/mock_update_handler.h" | 22 #include "components/sync/test/engine/mock_update_handler.h" |
23 #include "sync/test/mock_invalidation.h" | 23 #include "components/sync/test/mock_invalidation.h" |
24 #include "sync/test/sessions/mock_debug_info_getter.h" | 24 #include "components/sync/test/sessions/mock_debug_info_getter.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 namespace syncer { | 27 namespace syncer { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 std::unique_ptr<InvalidationInterface> BuildInvalidation( | 31 std::unique_ptr<InvalidationInterface> BuildInvalidation( |
32 int64_t version, | 32 int64_t version, |
33 const std::string& payload) { | 33 const std::string& payload) { |
34 return MockInvalidation::Build(version, payload); | 34 return MockInvalidation::Build(version, payload); |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 using sessions::MockDebugInfoGetter; | 39 using sessions::MockDebugInfoGetter; |
40 | 40 |
41 // A test fixture for tests exercising download updates functions. | 41 // A test fixture for tests exercising download updates functions. |
42 class GetUpdatesProcessorTest : public ::testing::Test { | 42 class GetUpdatesProcessorTest : public ::testing::Test { |
43 protected: | 43 protected: |
44 GetUpdatesProcessorTest() : | 44 GetUpdatesProcessorTest() |
45 kTestStartTime(base::TimeTicks::Now()), | 45 : kTestStartTime(base::TimeTicks::Now()), |
46 update_handler_deleter_(&update_handler_map_) {} | 46 update_handler_deleter_(&update_handler_map_) {} |
47 | 47 |
48 void SetUp() override { | 48 void SetUp() override { |
49 AddUpdateHandler(AUTOFILL); | 49 AddUpdateHandler(AUTOFILL); |
50 AddUpdateHandler(BOOKMARKS); | 50 AddUpdateHandler(BOOKMARKS); |
51 AddUpdateHandler(PREFERENCES); | 51 AddUpdateHandler(PREFERENCES); |
52 } | 52 } |
53 | 53 |
54 ModelTypeSet enabled_types() { | 54 ModelTypeSet enabled_types() { return enabled_types_; } |
55 return enabled_types_; | |
56 } | |
57 | 55 |
58 std::unique_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( | 56 std::unique_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( |
59 const GetUpdatesDelegate& delegate) { | 57 const GetUpdatesDelegate& delegate) { |
60 return std::unique_ptr<GetUpdatesProcessor>( | 58 return std::unique_ptr<GetUpdatesProcessor>( |
61 new GetUpdatesProcessor(&update_handler_map_, delegate)); | 59 new GetUpdatesProcessor(&update_handler_map_, delegate)); |
62 } | 60 } |
63 | 61 |
64 void InitFakeUpdateResponse(sync_pb::GetUpdatesResponse* response) { | 62 void InitFakeUpdateResponse(sync_pb::GetUpdatesResponse* response) { |
65 ModelTypeSet types = enabled_types(); | 63 ModelTypeSet types = enabled_types(); |
66 | 64 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 328 |
331 // This field is essential for making the client stop looping. If it's unset | 329 // This field is essential for making the client stop looping. If it's unset |
332 // then something is very wrong. The client should detect this. | 330 // then something is very wrong. The client should detect this. |
333 gu_response.clear_changes_remaining(); | 331 gu_response.clear_changes_remaining(); |
334 | 332 |
335 sessions::NudgeTracker nudge_tracker; | 333 sessions::NudgeTracker nudge_tracker; |
336 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 334 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
337 sessions::StatusController status; | 335 sessions::StatusController status; |
338 std::unique_ptr<GetUpdatesProcessor> processor( | 336 std::unique_ptr<GetUpdatesProcessor> processor( |
339 BuildGetUpdatesProcessor(normal_delegate)); | 337 BuildGetUpdatesProcessor(normal_delegate)); |
340 SyncerError error = processor->ProcessResponse(gu_response, | 338 SyncerError error = |
341 enabled_types(), | 339 processor->ProcessResponse(gu_response, enabled_types(), &status); |
342 &status); | |
343 EXPECT_EQ(error, SERVER_RESPONSE_VALIDATION_FAILED); | 340 EXPECT_EQ(error, SERVER_RESPONSE_VALIDATION_FAILED); |
344 } | 341 } |
345 | 342 |
346 // Verify that we correctly detect when there's more work to be done. | 343 // Verify that we correctly detect when there's more work to be done. |
347 TEST_F(GetUpdatesProcessorTest, MoreToDownloadResponse) { | 344 TEST_F(GetUpdatesProcessorTest, MoreToDownloadResponse) { |
348 sync_pb::GetUpdatesResponse gu_response; | 345 sync_pb::GetUpdatesResponse gu_response; |
349 InitFakeUpdateResponse(&gu_response); | 346 InitFakeUpdateResponse(&gu_response); |
350 gu_response.set_changes_remaining(1); | 347 gu_response.set_changes_remaining(1); |
351 | 348 |
352 sessions::NudgeTracker nudge_tracker; | 349 sessions::NudgeTracker nudge_tracker; |
353 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 350 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
354 sessions::StatusController status; | 351 sessions::StatusController status; |
355 std::unique_ptr<GetUpdatesProcessor> processor( | 352 std::unique_ptr<GetUpdatesProcessor> processor( |
356 BuildGetUpdatesProcessor(normal_delegate)); | 353 BuildGetUpdatesProcessor(normal_delegate)); |
357 SyncerError error = processor->ProcessResponse(gu_response, | 354 SyncerError error = |
358 enabled_types(), | 355 processor->ProcessResponse(gu_response, enabled_types(), &status); |
359 &status); | |
360 EXPECT_EQ(error, SERVER_MORE_TO_DOWNLOAD); | 356 EXPECT_EQ(error, SERVER_MORE_TO_DOWNLOAD); |
361 } | 357 } |
362 | 358 |
363 // A simple scenario: No updates returned and nothing more to download. | 359 // A simple scenario: No updates returned and nothing more to download. |
364 TEST_F(GetUpdatesProcessorTest, NormalResponseTest) { | 360 TEST_F(GetUpdatesProcessorTest, NormalResponseTest) { |
365 sync_pb::GetUpdatesResponse gu_response; | 361 sync_pb::GetUpdatesResponse gu_response; |
366 InitFakeUpdateResponse(&gu_response); | 362 InitFakeUpdateResponse(&gu_response); |
367 gu_response.set_changes_remaining(0); | 363 gu_response.set_changes_remaining(0); |
368 | 364 |
369 sessions::NudgeTracker nudge_tracker; | 365 sessions::NudgeTracker nudge_tracker; |
370 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 366 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
371 sessions::StatusController status; | 367 sessions::StatusController status; |
372 std::unique_ptr<GetUpdatesProcessor> processor( | 368 std::unique_ptr<GetUpdatesProcessor> processor( |
373 BuildGetUpdatesProcessor(normal_delegate)); | 369 BuildGetUpdatesProcessor(normal_delegate)); |
374 SyncerError error = processor->ProcessResponse(gu_response, | 370 SyncerError error = |
375 enabled_types(), | 371 processor->ProcessResponse(gu_response, enabled_types(), &status); |
376 &status); | |
377 EXPECT_EQ(error, SYNCER_OK); | 372 EXPECT_EQ(error, SYNCER_OK); |
378 } | 373 } |
379 | 374 |
380 // Variant of GetUpdatesProcessor test designed to test update application. | 375 // Variant of GetUpdatesProcessor test designed to test update application. |
381 // | 376 // |
382 // Maintains two enabled types, but requests that updates be applied for only | 377 // Maintains two enabled types, but requests that updates be applied for only |
383 // one of them. | 378 // one of them. |
384 class GetUpdatesProcessorApplyUpdatesTest : public GetUpdatesProcessorTest { | 379 class GetUpdatesProcessorApplyUpdatesTest : public GetUpdatesProcessorTest { |
385 public: | 380 public: |
386 GetUpdatesProcessorApplyUpdatesTest() {} | 381 GetUpdatesProcessorApplyUpdatesTest() {} |
387 ~GetUpdatesProcessorApplyUpdatesTest() override {} | 382 ~GetUpdatesProcessorApplyUpdatesTest() override {} |
388 | 383 |
389 void SetUp() override { | 384 void SetUp() override { |
390 bookmarks_handler_ = AddUpdateHandler(BOOKMARKS); | 385 bookmarks_handler_ = AddUpdateHandler(BOOKMARKS); |
391 autofill_handler_ = AddUpdateHandler(AUTOFILL); | 386 autofill_handler_ = AddUpdateHandler(AUTOFILL); |
392 } | 387 } |
393 | 388 |
394 ModelTypeSet GetGuTypes() { | 389 ModelTypeSet GetGuTypes() { return ModelTypeSet(AUTOFILL); } |
395 return ModelTypeSet(AUTOFILL); | |
396 } | |
397 | 390 |
398 MockUpdateHandler* GetNonAppliedHandler() { | 391 MockUpdateHandler* GetNonAppliedHandler() { return bookmarks_handler_; } |
399 return bookmarks_handler_; | |
400 } | |
401 | 392 |
402 MockUpdateHandler* GetAppliedHandler() { | 393 MockUpdateHandler* GetAppliedHandler() { return autofill_handler_; } |
403 return autofill_handler_; | |
404 } | |
405 | 394 |
406 private: | 395 private: |
407 MockUpdateHandler* bookmarks_handler_; | 396 MockUpdateHandler* bookmarks_handler_; |
408 MockUpdateHandler* autofill_handler_; | 397 MockUpdateHandler* autofill_handler_; |
409 }; | 398 }; |
410 | 399 |
411 // Verify that a normal cycle applies updates non-passively to the specified | 400 // Verify that a normal cycle applies updates non-passively to the specified |
412 // types. | 401 // types. |
413 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Normal) { | 402 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Normal) { |
414 sessions::NudgeTracker nudge_tracker; | 403 sessions::NudgeTracker nudge_tracker; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | 463 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); |
475 | 464 |
476 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); | 465 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); |
477 } | 466 } |
478 | 467 |
479 class DownloadUpdatesDebugInfoTest : public ::testing::Test { | 468 class DownloadUpdatesDebugInfoTest : public ::testing::Test { |
480 public: | 469 public: |
481 DownloadUpdatesDebugInfoTest() {} | 470 DownloadUpdatesDebugInfoTest() {} |
482 ~DownloadUpdatesDebugInfoTest() override {} | 471 ~DownloadUpdatesDebugInfoTest() override {} |
483 | 472 |
484 sessions::StatusController* status() { | 473 sessions::StatusController* status() { return &status_; } |
485 return &status_; | |
486 } | |
487 | 474 |
488 sessions::DebugInfoGetter* debug_info_getter() { | 475 sessions::DebugInfoGetter* debug_info_getter() { return &debug_info_getter_; } |
489 return &debug_info_getter_; | |
490 } | |
491 | 476 |
492 void AddDebugEvent() { | 477 void AddDebugEvent() { debug_info_getter_.AddDebugEvent(); } |
493 debug_info_getter_.AddDebugEvent(); | |
494 } | |
495 | 478 |
496 private: | 479 private: |
497 sessions::StatusController status_; | 480 sessions::StatusController status_; |
498 MockDebugInfoGetter debug_info_getter_; | 481 MockDebugInfoGetter debug_info_getter_; |
499 }; | 482 }; |
500 | 483 |
501 // Verify CopyClientDebugInfo when there are no events to upload. | 484 // Verify CopyClientDebugInfo when there are no events to upload. |
502 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyClientDebugInfo_Empty) { | 485 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyClientDebugInfo_Empty) { |
503 sync_pb::DebugInfo debug_info; | 486 sync_pb::DebugInfo debug_info; |
504 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 487 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
505 EXPECT_EQ(0, debug_info.events_size()); | 488 EXPECT_EQ(0, debug_info.events_size()); |
506 } | 489 } |
507 | 490 |
508 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { | 491 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { |
509 sync_pb::DebugInfo debug_info; | 492 sync_pb::DebugInfo debug_info; |
510 AddDebugEvent(); | 493 AddDebugEvent(); |
511 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 494 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
512 EXPECT_EQ(1, debug_info.events_size()); | 495 EXPECT_EQ(1, debug_info.events_size()); |
513 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 496 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
514 EXPECT_EQ(1, debug_info.events_size()); | 497 EXPECT_EQ(1, debug_info.events_size()); |
515 } | 498 } |
516 | 499 |
517 } // namespace syncer | 500 } // namespace syncer |
OLD | NEW |