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 <memory> | |
10 #include <set> | 9 #include <set> |
11 #include <string> | 10 #include <string> |
12 #include <utility> | |
13 | 11 |
14 #include "base/macros.h" | 12 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
16 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
17 #include "components/sync/base/model_type_test_util.h" | 15 #include "components/sync/base/model_type_test_util.h" |
18 #include "components/sync/engine_impl/cycle/debug_info_getter.h" | 16 #include "components/sync/engine_impl/cycle/debug_info_getter.h" |
19 #include "components/sync/engine_impl/cycle/mock_debug_info_getter.h" | 17 #include "components/sync/engine_impl/cycle/mock_debug_info_getter.h" |
20 #include "components/sync/engine_impl/cycle/nudge_tracker.h" | 18 #include "components/sync/engine_impl/cycle/nudge_tracker.h" |
21 #include "components/sync/engine_impl/cycle/status_controller.h" | 19 #include "components/sync/engine_impl/cycle/status_controller.h" |
22 #include "components/sync/engine_impl/get_updates_delegate.h" | 20 #include "components/sync/engine_impl/get_updates_delegate.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 106 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
109 std::unique_ptr<GetUpdatesProcessor> processor( | 107 std::unique_ptr<GetUpdatesProcessor> processor( |
110 BuildGetUpdatesProcessor(normal_delegate)); | 108 BuildGetUpdatesProcessor(normal_delegate)); |
111 processor->PrepareGetUpdates(enabled_types(), &message); | 109 processor->PrepareGetUpdates(enabled_types(), &message); |
112 | 110 |
113 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 111 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
114 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, | 112 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, |
115 gu_msg.caller_info().source()); | 113 gu_msg.caller_info().source()); |
116 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); | 114 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); |
117 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 115 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
118 ModelType type = GetModelTypeFromSpecificsFieldNumber( | 116 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
119 gu_msg.from_progress_marker(i).data_type_id()); | 117 gu_msg.from_progress_marker(i).data_type_id()); |
120 | 118 |
121 const sync_pb::DataTypeProgressMarker& progress_marker = | 119 const sync_pb::DataTypeProgressMarker& progress_marker = |
122 gu_msg.from_progress_marker(i); | 120 gu_msg.from_progress_marker(i); |
123 const sync_pb::GetUpdateTriggers& gu_trigger = | 121 const sync_pb::GetUpdateTriggers& gu_trigger = |
124 progress_marker.get_update_triggers(); | 122 progress_marker.get_update_triggers(); |
125 | 123 |
126 // We perform some basic tests of GU trigger and source fields here. The | 124 // We perform some basic tests of GU trigger and source fields here. The |
127 // more complicated scenarios are tested by the NudgeTracker tests. | 125 // more complicated scenarios are tested by the NudgeTracker tests. |
128 if (type == BOOKMARKS) { | 126 if (type == BOOKMARKS) { |
(...skipping 27 matching lines...) Expand all Loading... |
156 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 154 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
157 std::unique_ptr<GetUpdatesProcessor> processor( | 155 std::unique_ptr<GetUpdatesProcessor> processor( |
158 BuildGetUpdatesProcessor(normal_delegate)); | 156 BuildGetUpdatesProcessor(normal_delegate)); |
159 processor->PrepareGetUpdates(enabled_types(), &message); | 157 processor->PrepareGetUpdates(enabled_types(), &message); |
160 | 158 |
161 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 159 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
162 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, | 160 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, |
163 gu_msg.caller_info().source()); | 161 gu_msg.caller_info().source()); |
164 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); | 162 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); |
165 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 163 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
166 ModelType type = GetModelTypeFromSpecificsFieldNumber( | 164 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
167 gu_msg.from_progress_marker(i).data_type_id()); | 165 gu_msg.from_progress_marker(i).data_type_id()); |
168 | 166 |
169 const sync_pb::DataTypeProgressMarker& progress_marker = | 167 const sync_pb::DataTypeProgressMarker& progress_marker = |
170 gu_msg.from_progress_marker(i); | 168 gu_msg.from_progress_marker(i); |
171 const sync_pb::GetUpdateTriggers& gu_trigger = | 169 const sync_pb::GetUpdateTriggers& gu_trigger = |
172 progress_marker.get_update_triggers(); | 170 progress_marker.get_update_triggers(); |
173 | 171 |
174 // We perform some basic tests of GU trigger and source fields here. The | 172 // We perform some basic tests of GU trigger and source fields here. The |
175 // more complicated scenarios are tested by the NudgeTracker tests. | 173 // more complicated scenarios are tested by the NudgeTracker tests. |
176 if (notified_types.Has(type)) { | 174 if (notified_types.Has(type)) { |
(...skipping 19 matching lines...) Expand all Loading... |
196 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 194 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
197 std::unique_ptr<GetUpdatesProcessor> processor( | 195 std::unique_ptr<GetUpdatesProcessor> processor( |
198 BuildGetUpdatesProcessor(normal_delegate)); | 196 BuildGetUpdatesProcessor(normal_delegate)); |
199 processor->PrepareGetUpdates(enabled_types(), &message); | 197 processor->PrepareGetUpdates(enabled_types(), &message); |
200 | 198 |
201 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 199 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
202 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, | 200 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, |
203 gu_msg.caller_info().source()); | 201 gu_msg.caller_info().source()); |
204 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); | 202 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); |
205 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 203 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
206 ModelType type = GetModelTypeFromSpecificsFieldNumber( | 204 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
207 gu_msg.from_progress_marker(i).data_type_id()); | 205 gu_msg.from_progress_marker(i).data_type_id()); |
208 | 206 |
209 const sync_pb::DataTypeProgressMarker& progress_marker = | 207 const sync_pb::DataTypeProgressMarker& progress_marker = |
210 gu_msg.from_progress_marker(i); | 208 gu_msg.from_progress_marker(i); |
211 const sync_pb::GetUpdateTriggers& gu_trigger = | 209 const sync_pb::GetUpdateTriggers& gu_trigger = |
212 progress_marker.get_update_triggers(); | 210 progress_marker.get_update_triggers(); |
213 | 211 |
214 // We perform some basic tests of GU trigger and source fields here. The | 212 // We perform some basic tests of GU trigger and source fields here. The |
215 // more complicated scenarios are tested by the NudgeTracker tests. | 213 // more complicated scenarios are tested by the NudgeTracker tests. |
216 if (initial_sync_types.Has(type)) { | 214 if (initial_sync_types.Has(type)) { |
(...skipping 13 matching lines...) Expand all Loading... |
230 BuildGetUpdatesProcessor(configure_delegate)); | 228 BuildGetUpdatesProcessor(configure_delegate)); |
231 processor->PrepareGetUpdates(enabled_types(), &message); | 229 processor->PrepareGetUpdates(enabled_types(), &message); |
232 | 230 |
233 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 231 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
234 EXPECT_EQ(sync_pb::SyncEnums::RECONFIGURATION, gu_msg.get_updates_origin()); | 232 EXPECT_EQ(sync_pb::SyncEnums::RECONFIGURATION, gu_msg.get_updates_origin()); |
235 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 233 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, |
236 gu_msg.caller_info().source()); | 234 gu_msg.caller_info().source()); |
237 | 235 |
238 ModelTypeSet progress_types; | 236 ModelTypeSet progress_types; |
239 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 237 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
240 ModelType type = GetModelTypeFromSpecificsFieldNumber( | 238 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
241 gu_msg.from_progress_marker(i).data_type_id()); | 239 gu_msg.from_progress_marker(i).data_type_id()); |
242 progress_types.Put(type); | 240 progress_types.Put(type); |
243 } | 241 } |
244 EXPECT_EQ(enabled_types(), progress_types); | 242 EXPECT_EQ(enabled_types(), progress_types); |
245 } | 243 } |
246 | 244 |
247 TEST_F(GetUpdatesProcessorTest, PollTest) { | 245 TEST_F(GetUpdatesProcessorTest, PollTest) { |
248 sync_pb::ClientToServerMessage message; | 246 sync_pb::ClientToServerMessage message; |
249 PollGetUpdatesDelegate poll_delegate; | 247 PollGetUpdatesDelegate poll_delegate; |
250 std::unique_ptr<GetUpdatesProcessor> processor( | 248 std::unique_ptr<GetUpdatesProcessor> processor( |
251 BuildGetUpdatesProcessor(poll_delegate)); | 249 BuildGetUpdatesProcessor(poll_delegate)); |
252 processor->PrepareGetUpdates(enabled_types(), &message); | 250 processor->PrepareGetUpdates(enabled_types(), &message); |
253 | 251 |
254 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 252 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
255 EXPECT_EQ(sync_pb::SyncEnums::PERIODIC, gu_msg.get_updates_origin()); | 253 EXPECT_EQ(sync_pb::SyncEnums::PERIODIC, gu_msg.get_updates_origin()); |
256 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, | 254 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, |
257 gu_msg.caller_info().source()); | 255 gu_msg.caller_info().source()); |
258 | 256 |
259 ModelTypeSet progress_types; | 257 ModelTypeSet progress_types; |
260 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 258 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
261 ModelType type = GetModelTypeFromSpecificsFieldNumber( | 259 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
262 gu_msg.from_progress_marker(i).data_type_id()); | 260 gu_msg.from_progress_marker(i).data_type_id()); |
263 progress_types.Put(type); | 261 progress_types.Put(type); |
264 } | 262 } |
265 EXPECT_EQ(enabled_types(), progress_types); | 263 EXPECT_EQ(enabled_types(), progress_types); |
266 } | 264 } |
267 | 265 |
268 TEST_F(GetUpdatesProcessorTest, RetryTest) { | 266 TEST_F(GetUpdatesProcessorTest, RetryTest) { |
269 NudgeTracker nudge_tracker; | 267 NudgeTracker nudge_tracker; |
270 | 268 |
271 // Schedule a retry. | 269 // Schedule a retry. |
(...skipping 10 matching lines...) Expand all Loading... |
282 processor->PrepareGetUpdates(enabled_types(), &message); | 280 processor->PrepareGetUpdates(enabled_types(), &message); |
283 | 281 |
284 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 282 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
285 EXPECT_EQ(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin()); | 283 EXPECT_EQ(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin()); |
286 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RETRY, | 284 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RETRY, |
287 gu_msg.caller_info().source()); | 285 gu_msg.caller_info().source()); |
288 EXPECT_TRUE(gu_msg.is_retry()); | 286 EXPECT_TRUE(gu_msg.is_retry()); |
289 | 287 |
290 ModelTypeSet progress_types; | 288 ModelTypeSet progress_types; |
291 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 289 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
292 ModelType type = GetModelTypeFromSpecificsFieldNumber( | 290 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
293 gu_msg.from_progress_marker(i).data_type_id()); | 291 gu_msg.from_progress_marker(i).data_type_id()); |
294 progress_types.Put(type); | 292 progress_types.Put(type); |
295 } | 293 } |
296 EXPECT_EQ(enabled_types(), progress_types); | 294 EXPECT_EQ(enabled_types(), progress_types); |
297 } | 295 } |
298 | 296 |
299 TEST_F(GetUpdatesProcessorTest, NudgeWithRetryTest) { | 297 TEST_F(GetUpdatesProcessorTest, NudgeWithRetryTest) { |
300 NudgeTracker nudge_tracker; | 298 NudgeTracker nudge_tracker; |
301 | 299 |
302 // Schedule a retry. | 300 // Schedule a retry. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { | 491 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { |
494 sync_pb::DebugInfo debug_info; | 492 sync_pb::DebugInfo debug_info; |
495 AddDebugEvent(); | 493 AddDebugEvent(); |
496 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 494 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
497 EXPECT_EQ(1, debug_info.events_size()); | 495 EXPECT_EQ(1, debug_info.events_size()); |
498 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 496 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
499 EXPECT_EQ(1, debug_info.events_size()); | 497 EXPECT_EQ(1, debug_info.events_size()); |
500 } | 498 } |
501 | 499 |
502 } // namespace syncer | 500 } // namespace syncer |
OLD | NEW |