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/engine_impl/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 <set> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
13 #include "base/stl_util.h" | |
14 #include "components/sync/base/model_type_test_util.h" | 15 #include "components/sync/base/model_type_test_util.h" |
15 #include "components/sync/engine_impl/cycle/debug_info_getter.h" | 16 #include "components/sync/engine_impl/cycle/debug_info_getter.h" |
16 #include "components/sync/engine_impl/cycle/mock_debug_info_getter.h" | 17 #include "components/sync/engine_impl/cycle/mock_debug_info_getter.h" |
17 #include "components/sync/engine_impl/cycle/nudge_tracker.h" | 18 #include "components/sync/engine_impl/cycle/nudge_tracker.h" |
18 #include "components/sync/engine_impl/cycle/status_controller.h" | 19 #include "components/sync/engine_impl/cycle/status_controller.h" |
19 #include "components/sync/engine_impl/get_updates_delegate.h" | 20 #include "components/sync/engine_impl/get_updates_delegate.h" |
20 #include "components/sync/engine_impl/update_handler.h" | 21 #include "components/sync/engine_impl/update_handler.h" |
21 #include "components/sync/protocol/sync.pb.h" | 22 #include "components/sync/protocol/sync.pb.h" |
22 #include "components/sync/test/engine/fake_model_worker.h" | 23 #include "components/sync/test/engine/fake_model_worker.h" |
23 #include "components/sync/test/engine/mock_update_handler.h" | 24 #include "components/sync/test/engine/mock_update_handler.h" |
24 #include "components/sync/test/mock_invalidation.h" | 25 #include "components/sync/test/mock_invalidation.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 | 27 |
27 namespace syncer { | 28 namespace syncer { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 std::unique_ptr<InvalidationInterface> BuildInvalidation( | 32 std::unique_ptr<InvalidationInterface> BuildInvalidation( |
32 int64_t version, | 33 int64_t version, |
33 const std::string& payload) { | 34 const std::string& payload) { |
34 return MockInvalidation::Build(version, payload); | 35 return MockInvalidation::Build(version, payload); |
35 } | 36 } |
36 | 37 |
37 } // namespace | 38 } // namespace |
38 | 39 |
39 // A test fixture for tests exercising download updates functions. | 40 // A test fixture for tests exercising download updates functions. |
40 class GetUpdatesProcessorTest : public ::testing::Test { | 41 class GetUpdatesProcessorTest : public ::testing::Test { |
41 protected: | 42 protected: |
42 GetUpdatesProcessorTest() | 43 GetUpdatesProcessorTest() : kTestStartTime(base::TimeTicks::Now()) {} |
43 : kTestStartTime(base::TimeTicks::Now()), | |
44 update_handler_deleter_(&update_handler_map_) {} | |
45 | 44 |
46 void SetUp() override { | 45 void SetUp() override { |
47 AddUpdateHandler(AUTOFILL); | 46 AddUpdateHandler(AUTOFILL); |
48 AddUpdateHandler(BOOKMARKS); | 47 AddUpdateHandler(BOOKMARKS); |
49 AddUpdateHandler(PREFERENCES); | 48 AddUpdateHandler(PREFERENCES); |
50 } | 49 } |
51 | 50 |
52 ModelTypeSet enabled_types() { return enabled_types_; } | 51 ModelTypeSet enabled_types() { return enabled_types_; } |
53 | 52 |
54 std::unique_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( | 53 std::unique_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( |
(...skipping 18 matching lines...) Expand all Loading... |
73 | 72 |
74 response->set_changes_remaining(0); | 73 response->set_changes_remaining(0); |
75 } | 74 } |
76 | 75 |
77 const base::TimeTicks kTestStartTime; | 76 const base::TimeTicks kTestStartTime; |
78 | 77 |
79 protected: | 78 protected: |
80 MockUpdateHandler* AddUpdateHandler(ModelType type) { | 79 MockUpdateHandler* AddUpdateHandler(ModelType type) { |
81 enabled_types_.Put(type); | 80 enabled_types_.Put(type); |
82 | 81 |
83 MockUpdateHandler* handler = new MockUpdateHandler(type); | 82 std::unique_ptr<MockUpdateHandler> handler = |
84 update_handler_map_.insert(std::make_pair(type, handler)); | 83 base::MakeUnique<MockUpdateHandler>(type); |
| 84 MockUpdateHandler* handler_ptr = handler.get(); |
85 | 85 |
86 return handler; | 86 update_handler_map_.insert(std::make_pair(type, handler_ptr)); |
| 87 update_handlers_.insert(std::move(handler)); |
| 88 return handler_ptr; |
87 } | 89 } |
88 | 90 |
89 private: | 91 private: |
90 ModelTypeSet enabled_types_; | 92 ModelTypeSet enabled_types_; |
| 93 std::set<std::unique_ptr<MockUpdateHandler>> update_handlers_; |
91 UpdateHandlerMap update_handler_map_; | 94 UpdateHandlerMap update_handler_map_; |
92 base::STLValueDeleter<UpdateHandlerMap> update_handler_deleter_; | |
93 std::unique_ptr<GetUpdatesProcessor> get_updates_processor_; | 95 std::unique_ptr<GetUpdatesProcessor> get_updates_processor_; |
94 | 96 |
95 DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessorTest); | 97 DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessorTest); |
96 }; | 98 }; |
97 | 99 |
98 // Basic test to make sure nudges are expressed properly in the request. | 100 // Basic test to make sure nudges are expressed properly in the request. |
99 TEST_F(GetUpdatesProcessorTest, BookmarkNudge) { | 101 TEST_F(GetUpdatesProcessorTest, BookmarkNudge) { |
100 NudgeTracker nudge_tracker; | 102 NudgeTracker nudge_tracker; |
101 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 103 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
102 | 104 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { | 491 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { |
490 sync_pb::DebugInfo debug_info; | 492 sync_pb::DebugInfo debug_info; |
491 AddDebugEvent(); | 493 AddDebugEvent(); |
492 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 494 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
493 EXPECT_EQ(1, debug_info.events_size()); | 495 EXPECT_EQ(1, debug_info.events_size()); |
494 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 496 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
495 EXPECT_EQ(1, debug_info.events_size()); | 497 EXPECT_EQ(1, debug_info.events_size()); |
496 } | 498 } |
497 | 499 |
498 } // namespace syncer | 500 } // namespace syncer |
OLD | NEW |