| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sync/engine/get_updates_processor.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/message_loop/message_loop.h" | |
| 13 #include "base/stl_util.h" | |
| 14 #include "sync/engine/get_updates_delegate.h" | |
| 15 #include "sync/engine/update_handler.h" | |
| 16 #include "sync/internal_api/public/base/model_type_test_util.h" | |
| 17 #include "sync/protocol/sync.pb.h" | |
| 18 #include "sync/sessions/debug_info_getter.h" | |
| 19 #include "sync/sessions/nudge_tracker.h" | |
| 20 #include "sync/sessions/status_controller.h" | |
| 21 #include "sync/test/engine/fake_model_worker.h" | |
| 22 #include "sync/test/engine/mock_update_handler.h" | |
| 23 #include "sync/test/mock_invalidation.h" | |
| 24 #include "sync/test/sessions/mock_debug_info_getter.h" | |
| 25 #include "testing/gtest/include/gtest/gtest.h" | |
| 26 | |
| 27 namespace syncer { | |
| 28 | |
| 29 namespace { | |
| 30 | |
| 31 std::unique_ptr<InvalidationInterface> BuildInvalidation( | |
| 32 int64_t version, | |
| 33 const std::string& payload) { | |
| 34 return MockInvalidation::Build(version, payload); | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 using sessions::MockDebugInfoGetter; | |
| 40 | |
| 41 // A test fixture for tests exercising download updates functions. | |
| 42 class GetUpdatesProcessorTest : public ::testing::Test { | |
| 43 protected: | |
| 44 GetUpdatesProcessorTest() : | |
| 45 kTestStartTime(base::TimeTicks::Now()), | |
| 46 update_handler_deleter_(&update_handler_map_) {} | |
| 47 | |
| 48 void SetUp() override { | |
| 49 AddUpdateHandler(AUTOFILL); | |
| 50 AddUpdateHandler(BOOKMARKS); | |
| 51 AddUpdateHandler(PREFERENCES); | |
| 52 } | |
| 53 | |
| 54 ModelTypeSet enabled_types() { | |
| 55 return enabled_types_; | |
| 56 } | |
| 57 | |
| 58 std::unique_ptr<GetUpdatesProcessor> BuildGetUpdatesProcessor( | |
| 59 const GetUpdatesDelegate& delegate) { | |
| 60 return std::unique_ptr<GetUpdatesProcessor>( | |
| 61 new GetUpdatesProcessor(&update_handler_map_, delegate)); | |
| 62 } | |
| 63 | |
| 64 void InitFakeUpdateResponse(sync_pb::GetUpdatesResponse* response) { | |
| 65 ModelTypeSet types = enabled_types(); | |
| 66 | |
| 67 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { | |
| 68 sync_pb::DataTypeProgressMarker* marker = | |
| 69 response->add_new_progress_marker(); | |
| 70 marker->set_data_type_id(GetSpecificsFieldNumberFromModelType(it.Get())); | |
| 71 marker->set_token("foobarbaz"); | |
| 72 sync_pb::DataTypeContext* context = response->add_context_mutations(); | |
| 73 context->set_data_type_id(GetSpecificsFieldNumberFromModelType(it.Get())); | |
| 74 context->set_version(1); | |
| 75 context->set_context("context"); | |
| 76 } | |
| 77 | |
| 78 response->set_changes_remaining(0); | |
| 79 } | |
| 80 | |
| 81 const base::TimeTicks kTestStartTime; | |
| 82 | |
| 83 protected: | |
| 84 MockUpdateHandler* AddUpdateHandler(ModelType type) { | |
| 85 enabled_types_.Put(type); | |
| 86 | |
| 87 MockUpdateHandler* handler = new MockUpdateHandler(type); | |
| 88 update_handler_map_.insert(std::make_pair(type, handler)); | |
| 89 | |
| 90 return handler; | |
| 91 } | |
| 92 | |
| 93 private: | |
| 94 ModelTypeSet enabled_types_; | |
| 95 UpdateHandlerMap update_handler_map_; | |
| 96 STLValueDeleter<UpdateHandlerMap> update_handler_deleter_; | |
| 97 std::unique_ptr<GetUpdatesProcessor> get_updates_processor_; | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessorTest); | |
| 100 }; | |
| 101 | |
| 102 // Basic test to make sure nudges are expressed properly in the request. | |
| 103 TEST_F(GetUpdatesProcessorTest, BookmarkNudge) { | |
| 104 sessions::NudgeTracker nudge_tracker; | |
| 105 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | |
| 106 | |
| 107 sync_pb::ClientToServerMessage message; | |
| 108 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 109 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 110 BuildGetUpdatesProcessor(normal_delegate)); | |
| 111 processor->PrepareGetUpdates(enabled_types(), &message); | |
| 112 | |
| 113 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | |
| 114 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, | |
| 115 gu_msg.caller_info().source()); | |
| 116 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) { | |
| 118 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | |
| 119 gu_msg.from_progress_marker(i).data_type_id()); | |
| 120 | |
| 121 const sync_pb::DataTypeProgressMarker& progress_marker = | |
| 122 gu_msg.from_progress_marker(i); | |
| 123 const sync_pb::GetUpdateTriggers& gu_trigger = | |
| 124 progress_marker.get_update_triggers(); | |
| 125 | |
| 126 // We perform some basic tests of GU trigger and source fields here. The | |
| 127 // more complicated scenarios are tested by the NudgeTracker tests. | |
| 128 if (type == BOOKMARKS) { | |
| 129 EXPECT_TRUE(progress_marker.has_notification_hint()); | |
| 130 EXPECT_EQ("", progress_marker.notification_hint()); | |
| 131 EXPECT_EQ(1, gu_trigger.local_modification_nudges()); | |
| 132 EXPECT_EQ(0, gu_trigger.datatype_refresh_nudges()); | |
| 133 } else { | |
| 134 EXPECT_FALSE(progress_marker.has_notification_hint()); | |
| 135 EXPECT_EQ(0, gu_trigger.local_modification_nudges()); | |
| 136 EXPECT_EQ(0, gu_trigger.datatype_refresh_nudges()); | |
| 137 } | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 // Basic test to ensure invalidation payloads are expressed in the request. | |
| 142 TEST_F(GetUpdatesProcessorTest, NotifyMany) { | |
| 143 sessions::NudgeTracker nudge_tracker; | |
| 144 nudge_tracker.RecordRemoteInvalidation( | |
| 145 AUTOFILL, BuildInvalidation(1, "autofill_payload")); | |
| 146 nudge_tracker.RecordRemoteInvalidation( | |
| 147 BOOKMARKS, BuildInvalidation(1, "bookmark_payload")); | |
| 148 nudge_tracker.RecordRemoteInvalidation( | |
| 149 PREFERENCES, BuildInvalidation(1, "preferences_payload")); | |
| 150 ModelTypeSet notified_types; | |
| 151 notified_types.Put(AUTOFILL); | |
| 152 notified_types.Put(BOOKMARKS); | |
| 153 notified_types.Put(PREFERENCES); | |
| 154 | |
| 155 sync_pb::ClientToServerMessage message; | |
| 156 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 157 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 158 BuildGetUpdatesProcessor(normal_delegate)); | |
| 159 processor->PrepareGetUpdates(enabled_types(), &message); | |
| 160 | |
| 161 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | |
| 162 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::NOTIFICATION, | |
| 163 gu_msg.caller_info().source()); | |
| 164 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) { | |
| 166 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | |
| 167 gu_msg.from_progress_marker(i).data_type_id()); | |
| 168 | |
| 169 const sync_pb::DataTypeProgressMarker& progress_marker = | |
| 170 gu_msg.from_progress_marker(i); | |
| 171 const sync_pb::GetUpdateTriggers& gu_trigger = | |
| 172 progress_marker.get_update_triggers(); | |
| 173 | |
| 174 // We perform some basic tests of GU trigger and source fields here. The | |
| 175 // more complicated scenarios are tested by the NudgeTracker tests. | |
| 176 if (notified_types.Has(type)) { | |
| 177 EXPECT_TRUE(progress_marker.has_notification_hint()); | |
| 178 EXPECT_FALSE(progress_marker.notification_hint().empty()); | |
| 179 EXPECT_EQ(1, gu_trigger.notification_hint_size()); | |
| 180 } else { | |
| 181 EXPECT_FALSE(progress_marker.has_notification_hint()); | |
| 182 EXPECT_EQ(0, gu_trigger.notification_hint_size()); | |
| 183 } | |
| 184 } | |
| 185 } | |
| 186 | |
| 187 // Basic test to ensure initial sync requests are expressed in the request. | |
| 188 TEST_F(GetUpdatesProcessorTest, InitialSyncRequest) { | |
| 189 sessions::NudgeTracker nudge_tracker; | |
| 190 nudge_tracker.RecordInitialSyncRequired(AUTOFILL); | |
| 191 nudge_tracker.RecordInitialSyncRequired(PREFERENCES); | |
| 192 | |
| 193 ModelTypeSet initial_sync_types = ModelTypeSet(AUTOFILL, PREFERENCES); | |
| 194 | |
| 195 sync_pb::ClientToServerMessage message; | |
| 196 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 197 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 198 BuildGetUpdatesProcessor(normal_delegate)); | |
| 199 processor->PrepareGetUpdates(enabled_types(), &message); | |
| 200 | |
| 201 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | |
| 202 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH, | |
| 203 gu_msg.caller_info().source()); | |
| 204 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) { | |
| 206 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | |
| 207 gu_msg.from_progress_marker(i).data_type_id()); | |
| 208 | |
| 209 const sync_pb::DataTypeProgressMarker& progress_marker = | |
| 210 gu_msg.from_progress_marker(i); | |
| 211 const sync_pb::GetUpdateTriggers& gu_trigger = | |
| 212 progress_marker.get_update_triggers(); | |
| 213 | |
| 214 // We perform some basic tests of GU trigger and source fields here. The | |
| 215 // more complicated scenarios are tested by the NudgeTracker tests. | |
| 216 if (initial_sync_types.Has(type)) { | |
| 217 EXPECT_TRUE(gu_trigger.initial_sync_in_progress()); | |
| 218 } else { | |
| 219 EXPECT_TRUE(gu_trigger.has_initial_sync_in_progress()); | |
| 220 EXPECT_FALSE(gu_trigger.initial_sync_in_progress()); | |
| 221 } | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 TEST_F(GetUpdatesProcessorTest, ConfigureTest) { | |
| 226 sync_pb::ClientToServerMessage message; | |
| 227 ConfigureGetUpdatesDelegate configure_delegate( | |
| 228 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION); | |
| 229 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 230 BuildGetUpdatesProcessor(configure_delegate)); | |
| 231 processor->PrepareGetUpdates(enabled_types(), &message); | |
| 232 | |
| 233 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | |
| 234 EXPECT_EQ(sync_pb::SyncEnums::RECONFIGURATION, gu_msg.get_updates_origin()); | |
| 235 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | |
| 236 gu_msg.caller_info().source()); | |
| 237 | |
| 238 ModelTypeSet progress_types; | |
| 239 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | |
| 240 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | |
| 241 gu_msg.from_progress_marker(i).data_type_id()); | |
| 242 progress_types.Put(type); | |
| 243 } | |
| 244 EXPECT_EQ(enabled_types(), progress_types); | |
| 245 } | |
| 246 | |
| 247 TEST_F(GetUpdatesProcessorTest, PollTest) { | |
| 248 sync_pb::ClientToServerMessage message; | |
| 249 PollGetUpdatesDelegate poll_delegate; | |
| 250 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 251 BuildGetUpdatesProcessor(poll_delegate)); | |
| 252 processor->PrepareGetUpdates(enabled_types(), &message); | |
| 253 | |
| 254 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | |
| 255 EXPECT_EQ(sync_pb::SyncEnums::PERIODIC, gu_msg.get_updates_origin()); | |
| 256 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, | |
| 257 gu_msg.caller_info().source()); | |
| 258 | |
| 259 ModelTypeSet progress_types; | |
| 260 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | |
| 261 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | |
| 262 gu_msg.from_progress_marker(i).data_type_id()); | |
| 263 progress_types.Put(type); | |
| 264 } | |
| 265 EXPECT_EQ(enabled_types(), progress_types); | |
| 266 } | |
| 267 | |
| 268 TEST_F(GetUpdatesProcessorTest, RetryTest) { | |
| 269 sessions::NudgeTracker nudge_tracker; | |
| 270 | |
| 271 // Schedule a retry. | |
| 272 base::TimeTicks t1 = kTestStartTime; | |
| 273 nudge_tracker.SetNextRetryTime(t1); | |
| 274 | |
| 275 // Get the nudge tracker to think the retry is due. | |
| 276 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); | |
| 277 | |
| 278 sync_pb::ClientToServerMessage message; | |
| 279 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 280 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 281 BuildGetUpdatesProcessor(normal_delegate)); | |
| 282 processor->PrepareGetUpdates(enabled_types(), &message); | |
| 283 | |
| 284 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | |
| 285 EXPECT_EQ(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin()); | |
| 286 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RETRY, | |
| 287 gu_msg.caller_info().source()); | |
| 288 EXPECT_TRUE(gu_msg.is_retry()); | |
| 289 | |
| 290 ModelTypeSet progress_types; | |
| 291 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | |
| 292 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | |
| 293 gu_msg.from_progress_marker(i).data_type_id()); | |
| 294 progress_types.Put(type); | |
| 295 } | |
| 296 EXPECT_EQ(enabled_types(), progress_types); | |
| 297 } | |
| 298 | |
| 299 TEST_F(GetUpdatesProcessorTest, NudgeWithRetryTest) { | |
| 300 sessions::NudgeTracker nudge_tracker; | |
| 301 | |
| 302 // Schedule a retry. | |
| 303 base::TimeTicks t1 = kTestStartTime; | |
| 304 nudge_tracker.SetNextRetryTime(t1); | |
| 305 | |
| 306 // Get the nudge tracker to think the retry is due. | |
| 307 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); | |
| 308 | |
| 309 // Record a local change, too. | |
| 310 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | |
| 311 | |
| 312 sync_pb::ClientToServerMessage message; | |
| 313 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 314 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 315 BuildGetUpdatesProcessor(normal_delegate)); | |
| 316 processor->PrepareGetUpdates(enabled_types(), &message); | |
| 317 | |
| 318 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | |
| 319 EXPECT_NE(sync_pb::SyncEnums::RETRY, gu_msg.get_updates_origin()); | |
| 320 EXPECT_NE(sync_pb::GetUpdatesCallerInfo::RETRY, | |
| 321 gu_msg.caller_info().source()); | |
| 322 | |
| 323 EXPECT_TRUE(gu_msg.is_retry()); | |
| 324 } | |
| 325 | |
| 326 // Verify that a bogus response message is detected. | |
| 327 TEST_F(GetUpdatesProcessorTest, InvalidResponse) { | |
| 328 sync_pb::GetUpdatesResponse gu_response; | |
| 329 InitFakeUpdateResponse(&gu_response); | |
| 330 | |
| 331 // 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. | |
| 333 gu_response.clear_changes_remaining(); | |
| 334 | |
| 335 sessions::NudgeTracker nudge_tracker; | |
| 336 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 337 sessions::StatusController status; | |
| 338 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 339 BuildGetUpdatesProcessor(normal_delegate)); | |
| 340 SyncerError error = processor->ProcessResponse(gu_response, | |
| 341 enabled_types(), | |
| 342 &status); | |
| 343 EXPECT_EQ(error, SERVER_RESPONSE_VALIDATION_FAILED); | |
| 344 } | |
| 345 | |
| 346 // Verify that we correctly detect when there's more work to be done. | |
| 347 TEST_F(GetUpdatesProcessorTest, MoreToDownloadResponse) { | |
| 348 sync_pb::GetUpdatesResponse gu_response; | |
| 349 InitFakeUpdateResponse(&gu_response); | |
| 350 gu_response.set_changes_remaining(1); | |
| 351 | |
| 352 sessions::NudgeTracker nudge_tracker; | |
| 353 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 354 sessions::StatusController status; | |
| 355 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 356 BuildGetUpdatesProcessor(normal_delegate)); | |
| 357 SyncerError error = processor->ProcessResponse(gu_response, | |
| 358 enabled_types(), | |
| 359 &status); | |
| 360 EXPECT_EQ(error, SERVER_MORE_TO_DOWNLOAD); | |
| 361 } | |
| 362 | |
| 363 // A simple scenario: No updates returned and nothing more to download. | |
| 364 TEST_F(GetUpdatesProcessorTest, NormalResponseTest) { | |
| 365 sync_pb::GetUpdatesResponse gu_response; | |
| 366 InitFakeUpdateResponse(&gu_response); | |
| 367 gu_response.set_changes_remaining(0); | |
| 368 | |
| 369 sessions::NudgeTracker nudge_tracker; | |
| 370 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 371 sessions::StatusController status; | |
| 372 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 373 BuildGetUpdatesProcessor(normal_delegate)); | |
| 374 SyncerError error = processor->ProcessResponse(gu_response, | |
| 375 enabled_types(), | |
| 376 &status); | |
| 377 EXPECT_EQ(error, SYNCER_OK); | |
| 378 } | |
| 379 | |
| 380 // Variant of GetUpdatesProcessor test designed to test update application. | |
| 381 // | |
| 382 // Maintains two enabled types, but requests that updates be applied for only | |
| 383 // one of them. | |
| 384 class GetUpdatesProcessorApplyUpdatesTest : public GetUpdatesProcessorTest { | |
| 385 public: | |
| 386 GetUpdatesProcessorApplyUpdatesTest() {} | |
| 387 ~GetUpdatesProcessorApplyUpdatesTest() override {} | |
| 388 | |
| 389 void SetUp() override { | |
| 390 bookmarks_handler_ = AddUpdateHandler(BOOKMARKS); | |
| 391 autofill_handler_ = AddUpdateHandler(AUTOFILL); | |
| 392 } | |
| 393 | |
| 394 ModelTypeSet GetGuTypes() { | |
| 395 return ModelTypeSet(AUTOFILL); | |
| 396 } | |
| 397 | |
| 398 MockUpdateHandler* GetNonAppliedHandler() { | |
| 399 return bookmarks_handler_; | |
| 400 } | |
| 401 | |
| 402 MockUpdateHandler* GetAppliedHandler() { | |
| 403 return autofill_handler_; | |
| 404 } | |
| 405 | |
| 406 private: | |
| 407 MockUpdateHandler* bookmarks_handler_; | |
| 408 MockUpdateHandler* autofill_handler_; | |
| 409 }; | |
| 410 | |
| 411 // Verify that a normal cycle applies updates non-passively to the specified | |
| 412 // types. | |
| 413 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Normal) { | |
| 414 sessions::NudgeTracker nudge_tracker; | |
| 415 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | |
| 416 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 417 BuildGetUpdatesProcessor(normal_delegate)); | |
| 418 | |
| 419 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | |
| 420 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | |
| 421 | |
| 422 sessions::StatusController status; | |
| 423 processor->ApplyUpdates(GetGuTypes(), &status); | |
| 424 | |
| 425 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | |
| 426 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); | |
| 427 | |
| 428 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | |
| 429 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | |
| 430 | |
| 431 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); | |
| 432 } | |
| 433 | |
| 434 // Verify that a configure cycle applies updates passively to the specified | |
| 435 // types. | |
| 436 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Configure) { | |
| 437 ConfigureGetUpdatesDelegate configure_delegate( | |
| 438 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION); | |
| 439 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 440 BuildGetUpdatesProcessor(configure_delegate)); | |
| 441 | |
| 442 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | |
| 443 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | |
| 444 | |
| 445 sessions::StatusController status; | |
| 446 processor->ApplyUpdates(GetGuTypes(), &status); | |
| 447 | |
| 448 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | |
| 449 EXPECT_EQ(1, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | |
| 450 | |
| 451 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | |
| 452 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | |
| 453 | |
| 454 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); | |
| 455 } | |
| 456 | |
| 457 // Verify that a poll cycle applies updates non-passively to the specified | |
| 458 // types. | |
| 459 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Poll) { | |
| 460 PollGetUpdatesDelegate poll_delegate; | |
| 461 std::unique_ptr<GetUpdatesProcessor> processor( | |
| 462 BuildGetUpdatesProcessor(poll_delegate)); | |
| 463 | |
| 464 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | |
| 465 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | |
| 466 | |
| 467 sessions::StatusController status; | |
| 468 processor->ApplyUpdates(GetGuTypes(), &status); | |
| 469 | |
| 470 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | |
| 471 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); | |
| 472 | |
| 473 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | |
| 474 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | |
| 475 | |
| 476 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); | |
| 477 } | |
| 478 | |
| 479 class DownloadUpdatesDebugInfoTest : public ::testing::Test { | |
| 480 public: | |
| 481 DownloadUpdatesDebugInfoTest() {} | |
| 482 ~DownloadUpdatesDebugInfoTest() override {} | |
| 483 | |
| 484 sessions::StatusController* status() { | |
| 485 return &status_; | |
| 486 } | |
| 487 | |
| 488 sessions::DebugInfoGetter* debug_info_getter() { | |
| 489 return &debug_info_getter_; | |
| 490 } | |
| 491 | |
| 492 void AddDebugEvent() { | |
| 493 debug_info_getter_.AddDebugEvent(); | |
| 494 } | |
| 495 | |
| 496 private: | |
| 497 sessions::StatusController status_; | |
| 498 MockDebugInfoGetter debug_info_getter_; | |
| 499 }; | |
| 500 | |
| 501 // Verify CopyClientDebugInfo when there are no events to upload. | |
| 502 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyClientDebugInfo_Empty) { | |
| 503 sync_pb::DebugInfo debug_info; | |
| 504 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | |
| 505 EXPECT_EQ(0, debug_info.events_size()); | |
| 506 } | |
| 507 | |
| 508 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { | |
| 509 sync_pb::DebugInfo debug_info; | |
| 510 AddDebugEvent(); | |
| 511 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | |
| 512 EXPECT_EQ(1, debug_info.events_size()); | |
| 513 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | |
| 514 EXPECT_EQ(1, debug_info.events_size()); | |
| 515 } | |
| 516 | |
| 517 } // namespace syncer | |
| OLD | NEW |