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 "sync/engine/get_updates_processor.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "sync/test/engine/fake_model_worker.h" | 21 #include "sync/test/engine/fake_model_worker.h" |
22 #include "sync/test/engine/mock_update_handler.h" | 22 #include "sync/test/engine/mock_update_handler.h" |
23 #include "sync/test/mock_invalidation.h" | 23 #include "sync/test/mock_invalidation.h" |
24 #include "sync/test/sessions/mock_debug_info_getter.h" | 24 #include "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 scoped_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() { |
55 return enabled_types_; | 55 return enabled_types_; |
56 } | 56 } |
57 | 57 |
58 scoped_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( | 58 std::unique_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( |
59 const GetUpdatesDelegate& delegate) { | 59 const GetUpdatesDelegate& delegate) { |
60 return scoped_ptr<GetUpdatesProcessor>( | 60 return std::unique_ptr<GetUpdatesProcessor>( |
61 new GetUpdatesProcessor(&update_handler_map_, delegate)); | 61 new GetUpdatesProcessor(&update_handler_map_, delegate)); |
62 } | 62 } |
63 | 63 |
64 void InitFakeUpdateResponse(sync_pb::GetUpdatesResponse* response) { | 64 void InitFakeUpdateResponse(sync_pb::GetUpdatesResponse* response) { |
65 ModelTypeSet types = enabled_types(); | 65 ModelTypeSet types = enabled_types(); |
66 | 66 |
67 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { | 67 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { |
68 sync_pb::DataTypeProgressMarker* marker = | 68 sync_pb::DataTypeProgressMarker* marker = |
69 response->add_new_progress_marker(); | 69 response->add_new_progress_marker(); |
70 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(it.Get())); | 70 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(it.Get())); |
(...skipping 23 matching lines...) Expand all Loading... |
94 MockUpdateHandler* handler = new MockUpdateHandler(type); | 94 MockUpdateHandler* handler = new MockUpdateHandler(type); |
95 update_handler_map_.insert(std::make_pair(type, handler)); | 95 update_handler_map_.insert(std::make_pair(type, handler)); |
96 | 96 |
97 return handler; | 97 return handler; |
98 } | 98 } |
99 | 99 |
100 private: | 100 private: |
101 ModelTypeSet enabled_types_; | 101 ModelTypeSet enabled_types_; |
102 UpdateHandlerMap update_handler_map_; | 102 UpdateHandlerMap update_handler_map_; |
103 STLValueDeleter<UpdateHandlerMap> update_handler_deleter_; | 103 STLValueDeleter<UpdateHandlerMap> update_handler_deleter_; |
104 scoped_ptr<GetUpdatesProcessor> get_updates_processor_; | 104 std::unique_ptr<GetUpdatesProcessor> get_updates_processor_; |
105 | 105 |
106 DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessorTest); | 106 DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessorTest); |
107 }; | 107 }; |
108 | 108 |
109 // Basic test to make sure nudges are expressed properly in the request. | 109 // Basic test to make sure nudges are expressed properly in the request. |
110 TEST_F(GetUpdatesProcessorTest, BookmarkNudge) { | 110 TEST_F(GetUpdatesProcessorTest, BookmarkNudge) { |
111 sessions::NudgeTracker nudge_tracker; | 111 sessions::NudgeTracker nudge_tracker; |
112 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 112 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
113 | 113 |
114 sync_pb::ClientToServerMessage message; | 114 sync_pb::ClientToServerMessage message; |
115 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 115 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
116 scoped_ptr<GetUpdatesProcessor> processor( | 116 std::unique_ptr<GetUpdatesProcessor> processor( |
117 BuildGetUpdatesProcessor(normal_delegate)); | 117 BuildGetUpdatesProcessor(normal_delegate)); |
118 processor->PrepareGetUpdates(enabled_types(), &message); | 118 processor->PrepareGetUpdates(enabled_types(), &message); |
119 | 119 |
120 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 120 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
121 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, | 121 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, |
122 gu_msg.caller_info().source()); | 122 gu_msg.caller_info().source()); |
123 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); | 123 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); |
124 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 124 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
125 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | 125 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
126 gu_msg.from_progress_marker(i).data_type_id()); | 126 gu_msg.from_progress_marker(i).data_type_id()); |
(...skipping 27 matching lines...) Expand all Loading... |
154 BOOKMARKS, BuildInvalidation(1, "bookmark_payload")); | 154 BOOKMARKS, BuildInvalidation(1, "bookmark_payload")); |
155 nudge_tracker.RecordRemoteInvalidation( | 155 nudge_tracker.RecordRemoteInvalidation( |
156 PREFERENCES, BuildInvalidation(1, "preferences_payload")); | 156 PREFERENCES, BuildInvalidation(1, "preferences_payload")); |
157 ModelTypeSet notified_types; | 157 ModelTypeSet notified_types; |
158 notified_types.Put(AUTOFILL); | 158 notified_types.Put(AUTOFILL); |
159 notified_types.Put(BOOKMARKS); | 159 notified_types.Put(BOOKMARKS); |
160 notified_types.Put(PREFERENCES); | 160 notified_types.Put(PREFERENCES); |
161 | 161 |
162 sync_pb::ClientToServerMessage message; | 162 sync_pb::ClientToServerMessage message; |
163 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 163 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
164 scoped_ptr<GetUpdatesProcessor> processor( | 164 std::unique_ptr<GetUpdatesProcessor> processor( |
165 BuildGetUpdatesProcessor(normal_delegate)); | 165 BuildGetUpdatesProcessor(normal_delegate)); |
166 processor->PrepareGetUpdates(enabled_types(), &message); | 166 processor->PrepareGetUpdates(enabled_types(), &message); |
167 | 167 |
168 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 168 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
169 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, | 169 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, |
170 gu_msg.caller_info().source()); | 170 gu_msg.caller_info().source()); |
171 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); | 171 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); |
172 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 172 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
173 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | 173 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
174 gu_msg.from_progress_marker(i).data_type_id()); | 174 gu_msg.from_progress_marker(i).data_type_id()); |
(...skipping 19 matching lines...) Expand all Loading... |
194 // Basic test to ensure initial sync requests are expressed in the request. | 194 // Basic test to ensure initial sync requests are expressed in the request. |
195 TEST_F(GetUpdatesProcessorTest, InitialSyncRequest) { | 195 TEST_F(GetUpdatesProcessorTest, InitialSyncRequest) { |
196 sessions::NudgeTracker nudge_tracker; | 196 sessions::NudgeTracker nudge_tracker; |
197 nudge_tracker.RecordInitialSyncRequired(AUTOFILL); | 197 nudge_tracker.RecordInitialSyncRequired(AUTOFILL); |
198 nudge_tracker.RecordInitialSyncRequired(PREFERENCES); | 198 nudge_tracker.RecordInitialSyncRequired(PREFERENCES); |
199 | 199 |
200 ModelTypeSet initial_sync_types = ModelTypeSet(AUTOFILL, PREFERENCES); | 200 ModelTypeSet initial_sync_types = ModelTypeSet(AUTOFILL, PREFERENCES); |
201 | 201 |
202 sync_pb::ClientToServerMessage message; | 202 sync_pb::ClientToServerMessage message; |
203 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 203 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
204 scoped_ptr<GetUpdatesProcessor> processor( | 204 std::unique_ptr<GetUpdatesProcessor> processor( |
205 BuildGetUpdatesProcessor(normal_delegate)); | 205 BuildGetUpdatesProcessor(normal_delegate)); |
206 processor->PrepareGetUpdates(enabled_types(), &message); | 206 processor->PrepareGetUpdates(enabled_types(), &message); |
207 | 207 |
208 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 208 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
209 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, | 209 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, |
210 gu_msg.caller_info().source()); | 210 gu_msg.caller_info().source()); |
211 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); | 211 EXPECT_EQ(sync_pb::SyncEnums::GU_TRIGGER, gu_msg.get_updates_origin()); |
212 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 212 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
213 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | 213 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
214 gu_msg.from_progress_marker(i).data_type_id()); | 214 gu_msg.from_progress_marker(i).data_type_id()); |
(...skipping 11 matching lines...) Expand all Loading... |
226 EXPECT_TRUE(gu_trigger.has_initial_sync_in_progress()); | 226 EXPECT_TRUE(gu_trigger.has_initial_sync_in_progress()); |
227 EXPECT_FALSE(gu_trigger.initial_sync_in_progress()); | 227 EXPECT_FALSE(gu_trigger.initial_sync_in_progress()); |
228 } | 228 } |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 TEST_F(GetUpdatesProcessorTest, ConfigureTest) { | 232 TEST_F(GetUpdatesProcessorTest, ConfigureTest) { |
233 sync_pb::ClientToServerMessage message; | 233 sync_pb::ClientToServerMessage message; |
234 ConfigureGetUpdatesDelegate configure_delegate( | 234 ConfigureGetUpdatesDelegate configure_delegate( |
235 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION); | 235 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION); |
236 scoped_ptr<GetUpdatesProcessor> processor( | 236 std::unique_ptr<GetUpdatesProcessor> processor( |
237 BuildGetUpdatesProcessor(configure_delegate)); | 237 BuildGetUpdatesProcessor(configure_delegate)); |
238 processor->PrepareGetUpdates(enabled_types(), &message); | 238 processor->PrepareGetUpdates(enabled_types(), &message); |
239 | 239 |
240 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 240 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
241 EXPECT_EQ(sync_pb::SyncEnums::RECONFIGURATION, gu_msg.get_updates_origin()); | 241 EXPECT_EQ(sync_pb::SyncEnums::RECONFIGURATION, gu_msg.get_updates_origin()); |
242 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 242 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, |
243 gu_msg.caller_info().source()); | 243 gu_msg.caller_info().source()); |
244 | 244 |
245 ModelTypeSet progress_types; | 245 ModelTypeSet progress_types; |
246 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 246 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
247 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | 247 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
248 gu_msg.from_progress_marker(i).data_type_id()); | 248 gu_msg.from_progress_marker(i).data_type_id()); |
249 progress_types.Put(type); | 249 progress_types.Put(type); |
250 } | 250 } |
251 EXPECT_TRUE(enabled_types().Equals(progress_types)); | 251 EXPECT_TRUE(enabled_types().Equals(progress_types)); |
252 } | 252 } |
253 | 253 |
254 TEST_F(GetUpdatesProcessorTest, PollTest) { | 254 TEST_F(GetUpdatesProcessorTest, PollTest) { |
255 sync_pb::ClientToServerMessage message; | 255 sync_pb::ClientToServerMessage message; |
256 PollGetUpdatesDelegate poll_delegate; | 256 PollGetUpdatesDelegate poll_delegate; |
257 scoped_ptr<GetUpdatesProcessor> processor( | 257 std::unique_ptr<GetUpdatesProcessor> processor( |
258 BuildGetUpdatesProcessor(poll_delegate)); | 258 BuildGetUpdatesProcessor(poll_delegate)); |
259 processor->PrepareGetUpdates(enabled_types(), &message); | 259 processor->PrepareGetUpdates(enabled_types(), &message); |
260 | 260 |
261 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 261 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
262 EXPECT_EQ(sync_pb::SyncEnums::PERIODIC, gu_msg.get_updates_origin()); | 262 EXPECT_EQ(sync_pb::SyncEnums::PERIODIC, gu_msg.get_updates_origin()); |
263 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, | 263 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, |
264 gu_msg.caller_info().source()); | 264 gu_msg.caller_info().source()); |
265 | 265 |
266 ModelTypeSet progress_types; | 266 ModelTypeSet progress_types; |
267 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 267 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
268 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | 268 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
269 gu_msg.from_progress_marker(i).data_type_id()); | 269 gu_msg.from_progress_marker(i).data_type_id()); |
270 progress_types.Put(type); | 270 progress_types.Put(type); |
271 } | 271 } |
272 EXPECT_TRUE(enabled_types().Equals(progress_types)); | 272 EXPECT_TRUE(enabled_types().Equals(progress_types)); |
273 } | 273 } |
274 | 274 |
275 TEST_F(GetUpdatesProcessorTest, RetryTest) { | 275 TEST_F(GetUpdatesProcessorTest, RetryTest) { |
276 sessions::NudgeTracker nudge_tracker; | 276 sessions::NudgeTracker nudge_tracker; |
277 | 277 |
278 // Schedule a retry. | 278 // Schedule a retry. |
279 base::TimeTicks t1 = kTestStartTime; | 279 base::TimeTicks t1 = kTestStartTime; |
280 nudge_tracker.SetNextRetryTime(t1); | 280 nudge_tracker.SetNextRetryTime(t1); |
281 | 281 |
282 // Get the nudge tracker to think the retry is due. | 282 // Get the nudge tracker to think the retry is due. |
283 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); | 283 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); |
284 | 284 |
285 sync_pb::ClientToServerMessage message; | 285 sync_pb::ClientToServerMessage message; |
286 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 286 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
287 scoped_ptr<GetUpdatesProcessor> processor( | 287 std::unique_ptr<GetUpdatesProcessor> processor( |
288 BuildGetUpdatesProcessor(normal_delegate)); | 288 BuildGetUpdatesProcessor(normal_delegate)); |
289 processor->PrepareGetUpdates(enabled_types(), &message); | 289 processor->PrepareGetUpdates(enabled_types(), &message); |
290 | 290 |
291 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 291 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
292 EXPECT_EQ(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin()); | 292 EXPECT_EQ(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin()); |
293 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RETRY, | 293 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RETRY, |
294 gu_msg.caller_info().source()); | 294 gu_msg.caller_info().source()); |
295 EXPECT_TRUE(gu_msg.is_retry()); | 295 EXPECT_TRUE(gu_msg.is_retry()); |
296 | 296 |
297 ModelTypeSet progress_types; | 297 ModelTypeSet progress_types; |
(...skipping 13 matching lines...) Expand all Loading... |
311 nudge_tracker.SetNextRetryTime(t1); | 311 nudge_tracker.SetNextRetryTime(t1); |
312 | 312 |
313 // Get the nudge tracker to think the retry is due. | 313 // Get the nudge tracker to think the retry is due. |
314 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); | 314 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); |
315 | 315 |
316 // Record a local change, too. | 316 // Record a local change, too. |
317 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 317 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
318 | 318 |
319 sync_pb::ClientToServerMessage message; | 319 sync_pb::ClientToServerMessage message; |
320 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 320 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
321 scoped_ptr<GetUpdatesProcessor> processor( | 321 std::unique_ptr<GetUpdatesProcessor> processor( |
322 BuildGetUpdatesProcessor(normal_delegate)); | 322 BuildGetUpdatesProcessor(normal_delegate)); |
323 processor->PrepareGetUpdates(enabled_types(), &message); | 323 processor->PrepareGetUpdates(enabled_types(), &message); |
324 | 324 |
325 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 325 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
326 EXPECT_NE(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin()); | 326 EXPECT_NE(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin()); |
327 EXPECT_NE(sync_pb::GetUpdatesCallerInfo::RETRY, | 327 EXPECT_NE(sync_pb::GetUpdatesCallerInfo::RETRY, |
328 gu_msg.caller_info().source()); | 328 gu_msg.caller_info().source()); |
329 | 329 |
330 EXPECT_TRUE(gu_msg.is_retry()); | 330 EXPECT_TRUE(gu_msg.is_retry()); |
331 } | 331 } |
332 | 332 |
333 // Verify that a bogus response message is detected. | 333 // Verify that a bogus response message is detected. |
334 TEST_F(GetUpdatesProcessorTest, InvalidResponse) { | 334 TEST_F(GetUpdatesProcessorTest, InvalidResponse) { |
335 sync_pb::GetUpdatesResponse gu_response; | 335 sync_pb::GetUpdatesResponse gu_response; |
336 InitFakeUpdateResponse(&gu_response); | 336 InitFakeUpdateResponse(&gu_response); |
337 | 337 |
338 // This field is essential for making the client stop looping. If it's unset | 338 // This field is essential for making the client stop looping. If it's unset |
339 // then something is very wrong. The client should detect this. | 339 // then something is very wrong. The client should detect this. |
340 gu_response.clear_changes_remaining(); | 340 gu_response.clear_changes_remaining(); |
341 | 341 |
342 sessions::NudgeTracker nudge_tracker; | 342 sessions::NudgeTracker nudge_tracker; |
343 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 343 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
344 sessions::StatusController status; | 344 sessions::StatusController status; |
345 scoped_ptr<GetUpdatesProcessor> processor( | 345 std::unique_ptr<GetUpdatesProcessor> processor( |
346 BuildGetUpdatesProcessor(normal_delegate)); | 346 BuildGetUpdatesProcessor(normal_delegate)); |
347 SyncerError error = processor->ProcessResponse(gu_response, | 347 SyncerError error = processor->ProcessResponse(gu_response, |
348 enabled_types(), | 348 enabled_types(), |
349 &status); | 349 &status); |
350 EXPECT_EQ(error, SERVER_RESPONSE_VALIDATION_FAILED); | 350 EXPECT_EQ(error, SERVER_RESPONSE_VALIDATION_FAILED); |
351 } | 351 } |
352 | 352 |
353 // Verify that we correctly detect when there's more work to be done. | 353 // Verify that we correctly detect when there's more work to be done. |
354 TEST_F(GetUpdatesProcessorTest, MoreToDownloadResponse) { | 354 TEST_F(GetUpdatesProcessorTest, MoreToDownloadResponse) { |
355 sync_pb::GetUpdatesResponse gu_response; | 355 sync_pb::GetUpdatesResponse gu_response; |
356 InitFakeUpdateResponse(&gu_response); | 356 InitFakeUpdateResponse(&gu_response); |
357 gu_response.set_changes_remaining(1); | 357 gu_response.set_changes_remaining(1); |
358 | 358 |
359 sessions::NudgeTracker nudge_tracker; | 359 sessions::NudgeTracker nudge_tracker; |
360 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 360 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
361 sessions::StatusController status; | 361 sessions::StatusController status; |
362 scoped_ptr<GetUpdatesProcessor> processor( | 362 std::unique_ptr<GetUpdatesProcessor> processor( |
363 BuildGetUpdatesProcessor(normal_delegate)); | 363 BuildGetUpdatesProcessor(normal_delegate)); |
364 SyncerError error = processor->ProcessResponse(gu_response, | 364 SyncerError error = processor->ProcessResponse(gu_response, |
365 enabled_types(), | 365 enabled_types(), |
366 &status); | 366 &status); |
367 EXPECT_EQ(error, SERVER_MORE_TO_DOWNLOAD); | 367 EXPECT_EQ(error, SERVER_MORE_TO_DOWNLOAD); |
368 } | 368 } |
369 | 369 |
370 // A simple scenario: No updates returned and nothing more to download. | 370 // A simple scenario: No updates returned and nothing more to download. |
371 TEST_F(GetUpdatesProcessorTest, NormalResponseTest) { | 371 TEST_F(GetUpdatesProcessorTest, NormalResponseTest) { |
372 sync_pb::GetUpdatesResponse gu_response; | 372 sync_pb::GetUpdatesResponse gu_response; |
373 InitFakeUpdateResponse(&gu_response); | 373 InitFakeUpdateResponse(&gu_response); |
374 gu_response.set_changes_remaining(0); | 374 gu_response.set_changes_remaining(0); |
375 | 375 |
376 sessions::NudgeTracker nudge_tracker; | 376 sessions::NudgeTracker nudge_tracker; |
377 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 377 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
378 sessions::StatusController status; | 378 sessions::StatusController status; |
379 scoped_ptr<GetUpdatesProcessor> processor( | 379 std::unique_ptr<GetUpdatesProcessor> processor( |
380 BuildGetUpdatesProcessor(normal_delegate)); | 380 BuildGetUpdatesProcessor(normal_delegate)); |
381 SyncerError error = processor->ProcessResponse(gu_response, | 381 SyncerError error = processor->ProcessResponse(gu_response, |
382 enabled_types(), | 382 enabled_types(), |
383 &status); | 383 &status); |
384 EXPECT_EQ(error, SYNCER_OK); | 384 EXPECT_EQ(error, SYNCER_OK); |
385 } | 385 } |
386 | 386 |
387 // Variant of GetUpdatesProcessor test designed to test update application. | 387 // Variant of GetUpdatesProcessor test designed to test update application. |
388 // | 388 // |
389 // Maintains two enabled types, but requests that updates be applied for only | 389 // Maintains two enabled types, but requests that updates be applied for only |
(...skipping 23 matching lines...) Expand all Loading... |
413 private: | 413 private: |
414 MockUpdateHandler* bookmarks_handler_; | 414 MockUpdateHandler* bookmarks_handler_; |
415 MockUpdateHandler* autofill_handler_; | 415 MockUpdateHandler* autofill_handler_; |
416 }; | 416 }; |
417 | 417 |
418 // Verify that a normal cycle applies updates non-passively to the specified | 418 // Verify that a normal cycle applies updates non-passively to the specified |
419 // types. | 419 // types. |
420 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Normal) { | 420 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Normal) { |
421 sessions::NudgeTracker nudge_tracker; | 421 sessions::NudgeTracker nudge_tracker; |
422 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 422 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
423 scoped_ptr<GetUpdatesProcessor> processor( | 423 std::unique_ptr<GetUpdatesProcessor> processor( |
424 BuildGetUpdatesProcessor(normal_delegate)); | 424 BuildGetUpdatesProcessor(normal_delegate)); |
425 | 425 |
426 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 426 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
427 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | 427 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); |
428 | 428 |
429 sessions::StatusController status; | 429 sessions::StatusController status; |
430 processor->ApplyUpdates(GetGuTypes(), &status); | 430 processor->ApplyUpdates(GetGuTypes(), &status); |
431 | 431 |
432 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 432 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
433 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); | 433 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); |
434 | 434 |
435 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | 435 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); |
436 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | 436 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); |
437 | 437 |
438 EXPECT_TRUE(status.get_updates_request_types().Equals(GetGuTypes())); | 438 EXPECT_TRUE(status.get_updates_request_types().Equals(GetGuTypes())); |
439 } | 439 } |
440 | 440 |
441 // Verify that a configure cycle applies updates passively to the specified | 441 // Verify that a configure cycle applies updates passively to the specified |
442 // types. | 442 // types. |
443 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Configure) { | 443 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Configure) { |
444 ConfigureGetUpdatesDelegate configure_delegate( | 444 ConfigureGetUpdatesDelegate configure_delegate( |
445 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION); | 445 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION); |
446 scoped_ptr<GetUpdatesProcessor> processor( | 446 std::unique_ptr<GetUpdatesProcessor> processor( |
447 BuildGetUpdatesProcessor(configure_delegate)); | 447 BuildGetUpdatesProcessor(configure_delegate)); |
448 | 448 |
449 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | 449 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); |
450 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | 450 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); |
451 | 451 |
452 sessions::StatusController status; | 452 sessions::StatusController status; |
453 processor->ApplyUpdates(GetGuTypes(), &status); | 453 processor->ApplyUpdates(GetGuTypes(), &status); |
454 | 454 |
455 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | 455 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); |
456 EXPECT_EQ(1, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | 456 EXPECT_EQ(1, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); |
457 | 457 |
458 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 458 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
459 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | 459 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); |
460 | 460 |
461 EXPECT_TRUE(status.get_updates_request_types().Equals(GetGuTypes())); | 461 EXPECT_TRUE(status.get_updates_request_types().Equals(GetGuTypes())); |
462 } | 462 } |
463 | 463 |
464 // Verify that a poll cycle applies updates non-passively to the specified | 464 // Verify that a poll cycle applies updates non-passively to the specified |
465 // types. | 465 // types. |
466 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Poll) { | 466 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Poll) { |
467 PollGetUpdatesDelegate poll_delegate; | 467 PollGetUpdatesDelegate poll_delegate; |
468 scoped_ptr<GetUpdatesProcessor> processor( | 468 std::unique_ptr<GetUpdatesProcessor> processor( |
469 BuildGetUpdatesProcessor(poll_delegate)); | 469 BuildGetUpdatesProcessor(poll_delegate)); |
470 | 470 |
471 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 471 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
472 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | 472 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); |
473 | 473 |
474 sessions::StatusController status; | 474 sessions::StatusController status; |
475 processor->ApplyUpdates(GetGuTypes(), &status); | 475 processor->ApplyUpdates(GetGuTypes(), &status); |
476 | 476 |
477 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 477 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
478 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); | 478 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { | 515 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { |
516 sync_pb::DebugInfo debug_info; | 516 sync_pb::DebugInfo debug_info; |
517 AddDebugEvent(); | 517 AddDebugEvent(); |
518 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 518 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
519 EXPECT_EQ(1, debug_info.events_size()); | 519 EXPECT_EQ(1, debug_info.events_size()); |
520 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 520 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
521 EXPECT_EQ(1, debug_info.events_size()); | 521 EXPECT_EQ(1, debug_info.events_size()); |
522 } | 522 } |
523 | 523 |
524 } // namespace syncer | 524 } // namespace syncer |
OLD | NEW |