| 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 <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 "components/sync/base/model_type_test_util.h" | 14 #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/mock_debug_info_getter.h" |
| 17 #include "components/sync/engine_impl/cycle/nudge_tracker.h" |
| 18 #include "components/sync/engine_impl/cycle/status_controller.h" |
| 15 #include "components/sync/engine_impl/get_updates_delegate.h" | 19 #include "components/sync/engine_impl/get_updates_delegate.h" |
| 16 #include "components/sync/engine_impl/update_handler.h" | 20 #include "components/sync/engine_impl/update_handler.h" |
| 17 #include "components/sync/protocol/sync.pb.h" | 21 #include "components/sync/protocol/sync.pb.h" |
| 18 #include "components/sync/sessions_impl/debug_info_getter.h" | |
| 19 #include "components/sync/sessions_impl/nudge_tracker.h" | |
| 20 #include "components/sync/sessions_impl/status_controller.h" | |
| 21 #include "components/sync/test/engine/fake_model_worker.h" | 22 #include "components/sync/test/engine/fake_model_worker.h" |
| 22 #include "components/sync/test/engine/mock_update_handler.h" | 23 #include "components/sync/test/engine/mock_update_handler.h" |
| 23 #include "components/sync/test/mock_invalidation.h" | 24 #include "components/sync/test/mock_invalidation.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; | |
| 40 | |
| 41 // A test fixture for tests exercising download updates functions. | 39 // A test fixture for tests exercising download updates functions. |
| 42 class GetUpdatesProcessorTest : public ::testing::Test { | 40 class GetUpdatesProcessorTest : public ::testing::Test { |
| 43 protected: | 41 protected: |
| 44 GetUpdatesProcessorTest() | 42 GetUpdatesProcessorTest() |
| 45 : kTestStartTime(base::TimeTicks::Now()), | 43 : kTestStartTime(base::TimeTicks::Now()), |
| 46 update_handler_deleter_(&update_handler_map_) {} | 44 update_handler_deleter_(&update_handler_map_) {} |
| 47 | 45 |
| 48 void SetUp() override { | 46 void SetUp() override { |
| 49 AddUpdateHandler(AUTOFILL); | 47 AddUpdateHandler(AUTOFILL); |
| 50 AddUpdateHandler(BOOKMARKS); | 48 AddUpdateHandler(BOOKMARKS); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 ModelTypeSet enabled_types_; | 90 ModelTypeSet enabled_types_; |
| 93 UpdateHandlerMap update_handler_map_; | 91 UpdateHandlerMap update_handler_map_; |
| 94 base::STLValueDeleter<UpdateHandlerMap> update_handler_deleter_; | 92 base::STLValueDeleter<UpdateHandlerMap> update_handler_deleter_; |
| 95 std::unique_ptr<GetUpdatesProcessor> get_updates_processor_; | 93 std::unique_ptr<GetUpdatesProcessor> get_updates_processor_; |
| 96 | 94 |
| 97 DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessorTest); | 95 DISALLOW_COPY_AND_ASSIGN(GetUpdatesProcessorTest); |
| 98 }; | 96 }; |
| 99 | 97 |
| 100 // Basic test to make sure nudges are expressed properly in the request. | 98 // Basic test to make sure nudges are expressed properly in the request. |
| 101 TEST_F(GetUpdatesProcessorTest, BookmarkNudge) { | 99 TEST_F(GetUpdatesProcessorTest, BookmarkNudge) { |
| 102 sessions::NudgeTracker nudge_tracker; | 100 NudgeTracker nudge_tracker; |
| 103 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 101 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
| 104 | 102 |
| 105 sync_pb::ClientToServerMessage message; | 103 sync_pb::ClientToServerMessage message; |
| 106 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 104 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
| 107 std::unique_ptr<GetUpdatesProcessor> processor( | 105 std::unique_ptr<GetUpdatesProcessor> processor( |
| 108 BuildGetUpdatesProcessor(normal_delegate)); | 106 BuildGetUpdatesProcessor(normal_delegate)); |
| 109 processor->PrepareGetUpdates(enabled_types(), &message); | 107 processor->PrepareGetUpdates(enabled_types(), &message); |
| 110 | 108 |
| 111 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); | 109 const sync_pb::GetUpdatesMessage& gu_msg = message.get_updates(); |
| 112 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, | 110 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::LOCAL, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 } else { | 129 } else { |
| 132 EXPECT_FALSE(progress_marker.has_notification_hint()); | 130 EXPECT_FALSE(progress_marker.has_notification_hint()); |
| 133 EXPECT_EQ(0, gu_trigger.local_modification_nudges()); | 131 EXPECT_EQ(0, gu_trigger.local_modification_nudges()); |
| 134 EXPECT_EQ(0, gu_trigger.datatype_refresh_nudges()); | 132 EXPECT_EQ(0, gu_trigger.datatype_refresh_nudges()); |
| 135 } | 133 } |
| 136 } | 134 } |
| 137 } | 135 } |
| 138 | 136 |
| 139 // Basic test to ensure invalidation payloads are expressed in the request. | 137 // Basic test to ensure invalidation payloads are expressed in the request. |
| 140 TEST_F(GetUpdatesProcessorTest, NotifyMany) { | 138 TEST_F(GetUpdatesProcessorTest, NotifyMany) { |
| 141 sessions::NudgeTracker nudge_tracker; | 139 NudgeTracker nudge_tracker; |
| 142 nudge_tracker.RecordRemoteInvalidation( | 140 nudge_tracker.RecordRemoteInvalidation( |
| 143 AUTOFILL, BuildInvalidation(1, "autofill_payload")); | 141 AUTOFILL, BuildInvalidation(1, "autofill_payload")); |
| 144 nudge_tracker.RecordRemoteInvalidation( | 142 nudge_tracker.RecordRemoteInvalidation( |
| 145 BOOKMARKS, BuildInvalidation(1, "bookmark_payload")); | 143 BOOKMARKS, BuildInvalidation(1, "bookmark_payload")); |
| 146 nudge_tracker.RecordRemoteInvalidation( | 144 nudge_tracker.RecordRemoteInvalidation( |
| 147 PREFERENCES, BuildInvalidation(1, "preferences_payload")); | 145 PREFERENCES, BuildInvalidation(1, "preferences_payload")); |
| 148 ModelTypeSet notified_types; | 146 ModelTypeSet notified_types; |
| 149 notified_types.Put(AUTOFILL); | 147 notified_types.Put(AUTOFILL); |
| 150 notified_types.Put(BOOKMARKS); | 148 notified_types.Put(BOOKMARKS); |
| 151 notified_types.Put(PREFERENCES); | 149 notified_types.Put(PREFERENCES); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 177 EXPECT_EQ(1, gu_trigger.notification_hint_size()); | 175 EXPECT_EQ(1, gu_trigger.notification_hint_size()); |
| 178 } else { | 176 } else { |
| 179 EXPECT_FALSE(progress_marker.has_notification_hint()); | 177 EXPECT_FALSE(progress_marker.has_notification_hint()); |
| 180 EXPECT_EQ(0, gu_trigger.notification_hint_size()); | 178 EXPECT_EQ(0, gu_trigger.notification_hint_size()); |
| 181 } | 179 } |
| 182 } | 180 } |
| 183 } | 181 } |
| 184 | 182 |
| 185 // Basic test to ensure initial sync requests are expressed in the request. | 183 // Basic test to ensure initial sync requests are expressed in the request. |
| 186 TEST_F(GetUpdatesProcessorTest, InitialSyncRequest) { | 184 TEST_F(GetUpdatesProcessorTest, InitialSyncRequest) { |
| 187 sessions::NudgeTracker nudge_tracker; | 185 NudgeTracker nudge_tracker; |
| 188 nudge_tracker.RecordInitialSyncRequired(AUTOFILL); | 186 nudge_tracker.RecordInitialSyncRequired(AUTOFILL); |
| 189 nudge_tracker.RecordInitialSyncRequired(PREFERENCES); | 187 nudge_tracker.RecordInitialSyncRequired(PREFERENCES); |
| 190 | 188 |
| 191 ModelTypeSet initial_sync_types = ModelTypeSet(AUTOFILL, PREFERENCES); | 189 ModelTypeSet initial_sync_types = ModelTypeSet(AUTOFILL, PREFERENCES); |
| 192 | 190 |
| 193 sync_pb::ClientToServerMessage message; | 191 sync_pb::ClientToServerMessage message; |
| 194 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 192 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
| 195 std::unique_ptr<GetUpdatesProcessor> processor( | 193 std::unique_ptr<GetUpdatesProcessor> processor( |
| 196 BuildGetUpdatesProcessor(normal_delegate)); | 194 BuildGetUpdatesProcessor(normal_delegate)); |
| 197 processor->PrepareGetUpdates(enabled_types(), &message); | 195 processor->PrepareGetUpdates(enabled_types(), &message); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ModelTypeSet progress_types; | 255 ModelTypeSet progress_types; |
| 258 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 256 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
| 259 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | 257 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
| 260 gu_msg.from_progress_marker(i).data_type_id()); | 258 gu_msg.from_progress_marker(i).data_type_id()); |
| 261 progress_types.Put(type); | 259 progress_types.Put(type); |
| 262 } | 260 } |
| 263 EXPECT_EQ(enabled_types(), progress_types); | 261 EXPECT_EQ(enabled_types(), progress_types); |
| 264 } | 262 } |
| 265 | 263 |
| 266 TEST_F(GetUpdatesProcessorTest, RetryTest) { | 264 TEST_F(GetUpdatesProcessorTest, RetryTest) { |
| 267 sessions::NudgeTracker nudge_tracker; | 265 NudgeTracker nudge_tracker; |
| 268 | 266 |
| 269 // Schedule a retry. | 267 // Schedule a retry. |
| 270 base::TimeTicks t1 = kTestStartTime; | 268 base::TimeTicks t1 = kTestStartTime; |
| 271 nudge_tracker.SetNextRetryTime(t1); | 269 nudge_tracker.SetNextRetryTime(t1); |
| 272 | 270 |
| 273 // Get the nudge tracker to think the retry is due. | 271 // Get the nudge tracker to think the retry is due. |
| 274 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); | 272 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); |
| 275 | 273 |
| 276 sync_pb::ClientToServerMessage message; | 274 sync_pb::ClientToServerMessage message; |
| 277 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 275 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 288 ModelTypeSet progress_types; | 286 ModelTypeSet progress_types; |
| 289 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { | 287 for (int i = 0; i < gu_msg.from_progress_marker_size(); ++i) { |
| 290 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( | 288 syncer::ModelType type = GetModelTypeFromSpecificsFieldNumber( |
| 291 gu_msg.from_progress_marker(i).data_type_id()); | 289 gu_msg.from_progress_marker(i).data_type_id()); |
| 292 progress_types.Put(type); | 290 progress_types.Put(type); |
| 293 } | 291 } |
| 294 EXPECT_EQ(enabled_types(), progress_types); | 292 EXPECT_EQ(enabled_types(), progress_types); |
| 295 } | 293 } |
| 296 | 294 |
| 297 TEST_F(GetUpdatesProcessorTest, NudgeWithRetryTest) { | 295 TEST_F(GetUpdatesProcessorTest, NudgeWithRetryTest) { |
| 298 sessions::NudgeTracker nudge_tracker; | 296 NudgeTracker nudge_tracker; |
| 299 | 297 |
| 300 // Schedule a retry. | 298 // Schedule a retry. |
| 301 base::TimeTicks t1 = kTestStartTime; | 299 base::TimeTicks t1 = kTestStartTime; |
| 302 nudge_tracker.SetNextRetryTime(t1); | 300 nudge_tracker.SetNextRetryTime(t1); |
| 303 | 301 |
| 304 // Get the nudge tracker to think the retry is due. | 302 // Get the nudge tracker to think the retry is due. |
| 305 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); | 303 nudge_tracker.SetSyncCycleStartTime(t1 + base::TimeDelta::FromSeconds(1)); |
| 306 | 304 |
| 307 // Record a local change, too. | 305 // Record a local change, too. |
| 308 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); | 306 nudge_tracker.RecordLocalChange(ModelTypeSet(BOOKMARKS)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 323 | 321 |
| 324 // Verify that a bogus response message is detected. | 322 // Verify that a bogus response message is detected. |
| 325 TEST_F(GetUpdatesProcessorTest, InvalidResponse) { | 323 TEST_F(GetUpdatesProcessorTest, InvalidResponse) { |
| 326 sync_pb::GetUpdatesResponse gu_response; | 324 sync_pb::GetUpdatesResponse gu_response; |
| 327 InitFakeUpdateResponse(&gu_response); | 325 InitFakeUpdateResponse(&gu_response); |
| 328 | 326 |
| 329 // This field is essential for making the client stop looping. If it's unset | 327 // This field is essential for making the client stop looping. If it's unset |
| 330 // then something is very wrong. The client should detect this. | 328 // then something is very wrong. The client should detect this. |
| 331 gu_response.clear_changes_remaining(); | 329 gu_response.clear_changes_remaining(); |
| 332 | 330 |
| 333 sessions::NudgeTracker nudge_tracker; | 331 NudgeTracker nudge_tracker; |
| 334 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 332 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
| 335 sessions::StatusController status; | 333 StatusController status; |
| 336 std::unique_ptr<GetUpdatesProcessor> processor( | 334 std::unique_ptr<GetUpdatesProcessor> processor( |
| 337 BuildGetUpdatesProcessor(normal_delegate)); | 335 BuildGetUpdatesProcessor(normal_delegate)); |
| 338 SyncerError error = | 336 SyncerError error = |
| 339 processor->ProcessResponse(gu_response, enabled_types(), &status); | 337 processor->ProcessResponse(gu_response, enabled_types(), &status); |
| 340 EXPECT_EQ(error, SERVER_RESPONSE_VALIDATION_FAILED); | 338 EXPECT_EQ(error, SERVER_RESPONSE_VALIDATION_FAILED); |
| 341 } | 339 } |
| 342 | 340 |
| 343 // Verify that we correctly detect when there's more work to be done. | 341 // Verify that we correctly detect when there's more work to be done. |
| 344 TEST_F(GetUpdatesProcessorTest, MoreToDownloadResponse) { | 342 TEST_F(GetUpdatesProcessorTest, MoreToDownloadResponse) { |
| 345 sync_pb::GetUpdatesResponse gu_response; | 343 sync_pb::GetUpdatesResponse gu_response; |
| 346 InitFakeUpdateResponse(&gu_response); | 344 InitFakeUpdateResponse(&gu_response); |
| 347 gu_response.set_changes_remaining(1); | 345 gu_response.set_changes_remaining(1); |
| 348 | 346 |
| 349 sessions::NudgeTracker nudge_tracker; | 347 NudgeTracker nudge_tracker; |
| 350 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 348 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
| 351 sessions::StatusController status; | 349 StatusController status; |
| 352 std::unique_ptr<GetUpdatesProcessor> processor( | 350 std::unique_ptr<GetUpdatesProcessor> processor( |
| 353 BuildGetUpdatesProcessor(normal_delegate)); | 351 BuildGetUpdatesProcessor(normal_delegate)); |
| 354 SyncerError error = | 352 SyncerError error = |
| 355 processor->ProcessResponse(gu_response, enabled_types(), &status); | 353 processor->ProcessResponse(gu_response, enabled_types(), &status); |
| 356 EXPECT_EQ(error, SERVER_MORE_TO_DOWNLOAD); | 354 EXPECT_EQ(error, SERVER_MORE_TO_DOWNLOAD); |
| 357 } | 355 } |
| 358 | 356 |
| 359 // A simple scenario: No updates returned and nothing more to download. | 357 // A simple scenario: No updates returned and nothing more to download. |
| 360 TEST_F(GetUpdatesProcessorTest, NormalResponseTest) { | 358 TEST_F(GetUpdatesProcessorTest, NormalResponseTest) { |
| 361 sync_pb::GetUpdatesResponse gu_response; | 359 sync_pb::GetUpdatesResponse gu_response; |
| 362 InitFakeUpdateResponse(&gu_response); | 360 InitFakeUpdateResponse(&gu_response); |
| 363 gu_response.set_changes_remaining(0); | 361 gu_response.set_changes_remaining(0); |
| 364 | 362 |
| 365 sessions::NudgeTracker nudge_tracker; | 363 NudgeTracker nudge_tracker; |
| 366 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 364 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
| 367 sessions::StatusController status; | 365 StatusController status; |
| 368 std::unique_ptr<GetUpdatesProcessor> processor( | 366 std::unique_ptr<GetUpdatesProcessor> processor( |
| 369 BuildGetUpdatesProcessor(normal_delegate)); | 367 BuildGetUpdatesProcessor(normal_delegate)); |
| 370 SyncerError error = | 368 SyncerError error = |
| 371 processor->ProcessResponse(gu_response, enabled_types(), &status); | 369 processor->ProcessResponse(gu_response, enabled_types(), &status); |
| 372 EXPECT_EQ(error, SYNCER_OK); | 370 EXPECT_EQ(error, SYNCER_OK); |
| 373 } | 371 } |
| 374 | 372 |
| 375 // Variant of GetUpdatesProcessor test designed to test update application. | 373 // Variant of GetUpdatesProcessor test designed to test update application. |
| 376 // | 374 // |
| 377 // Maintains two enabled types, but requests that updates be applied for only | 375 // Maintains two enabled types, but requests that updates be applied for only |
| (...skipping 15 matching lines...) Expand all Loading... |
| 393 MockUpdateHandler* GetAppliedHandler() { return autofill_handler_; } | 391 MockUpdateHandler* GetAppliedHandler() { return autofill_handler_; } |
| 394 | 392 |
| 395 private: | 393 private: |
| 396 MockUpdateHandler* bookmarks_handler_; | 394 MockUpdateHandler* bookmarks_handler_; |
| 397 MockUpdateHandler* autofill_handler_; | 395 MockUpdateHandler* autofill_handler_; |
| 398 }; | 396 }; |
| 399 | 397 |
| 400 // Verify that a normal cycle applies updates non-passively to the specified | 398 // Verify that a normal cycle applies updates non-passively to the specified |
| 401 // types. | 399 // types. |
| 402 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Normal) { | 400 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Normal) { |
| 403 sessions::NudgeTracker nudge_tracker; | 401 NudgeTracker nudge_tracker; |
| 404 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); | 402 NormalGetUpdatesDelegate normal_delegate(nudge_tracker); |
| 405 std::unique_ptr<GetUpdatesProcessor> processor( | 403 std::unique_ptr<GetUpdatesProcessor> processor( |
| 406 BuildGetUpdatesProcessor(normal_delegate)); | 404 BuildGetUpdatesProcessor(normal_delegate)); |
| 407 | 405 |
| 408 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 406 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
| 409 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | 407 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); |
| 410 | 408 |
| 411 sessions::StatusController status; | 409 StatusController status; |
| 412 processor->ApplyUpdates(GetGuTypes(), &status); | 410 processor->ApplyUpdates(GetGuTypes(), &status); |
| 413 | 411 |
| 414 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 412 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
| 415 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); | 413 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); |
| 416 | 414 |
| 417 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | 415 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); |
| 418 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | 416 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); |
| 419 | 417 |
| 420 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); | 418 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); |
| 421 } | 419 } |
| 422 | 420 |
| 423 // Verify that a configure cycle applies updates passively to the specified | 421 // Verify that a configure cycle applies updates passively to the specified |
| 424 // types. | 422 // types. |
| 425 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Configure) { | 423 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Configure) { |
| 426 ConfigureGetUpdatesDelegate configure_delegate( | 424 ConfigureGetUpdatesDelegate configure_delegate( |
| 427 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION); | 425 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION); |
| 428 std::unique_ptr<GetUpdatesProcessor> processor( | 426 std::unique_ptr<GetUpdatesProcessor> processor( |
| 429 BuildGetUpdatesProcessor(configure_delegate)); | 427 BuildGetUpdatesProcessor(configure_delegate)); |
| 430 | 428 |
| 431 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | 429 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); |
| 432 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | 430 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); |
| 433 | 431 |
| 434 sessions::StatusController status; | 432 StatusController status; |
| 435 processor->ApplyUpdates(GetGuTypes(), &status); | 433 processor->ApplyUpdates(GetGuTypes(), &status); |
| 436 | 434 |
| 437 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | 435 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); |
| 438 EXPECT_EQ(1, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | 436 EXPECT_EQ(1, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); |
| 439 | 437 |
| 440 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 438 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
| 441 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | 439 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); |
| 442 | 440 |
| 443 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); | 441 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); |
| 444 } | 442 } |
| 445 | 443 |
| 446 // Verify that a poll cycle applies updates non-passively to the specified | 444 // Verify that a poll cycle applies updates non-passively to the specified |
| 447 // types. | 445 // types. |
| 448 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Poll) { | 446 TEST_F(GetUpdatesProcessorApplyUpdatesTest, Poll) { |
| 449 PollGetUpdatesDelegate poll_delegate; | 447 PollGetUpdatesDelegate poll_delegate; |
| 450 std::unique_ptr<GetUpdatesProcessor> processor( | 448 std::unique_ptr<GetUpdatesProcessor> processor( |
| 451 BuildGetUpdatesProcessor(poll_delegate)); | 449 BuildGetUpdatesProcessor(poll_delegate)); |
| 452 | 450 |
| 453 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 451 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
| 454 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); | 452 EXPECT_EQ(0, GetAppliedHandler()->GetApplyUpdatesCount()); |
| 455 | 453 |
| 456 sessions::StatusController status; | 454 StatusController status; |
| 457 processor->ApplyUpdates(GetGuTypes(), &status); | 455 processor->ApplyUpdates(GetGuTypes(), &status); |
| 458 | 456 |
| 459 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); | 457 EXPECT_EQ(0, GetNonAppliedHandler()->GetApplyUpdatesCount()); |
| 460 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); | 458 EXPECT_EQ(1, GetAppliedHandler()->GetApplyUpdatesCount()); |
| 461 | 459 |
| 462 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); | 460 EXPECT_EQ(0, GetNonAppliedHandler()->GetPassiveApplyUpdatesCount()); |
| 463 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); | 461 EXPECT_EQ(0, GetAppliedHandler()->GetPassiveApplyUpdatesCount()); |
| 464 | 462 |
| 465 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); | 463 EXPECT_EQ(GetGuTypes(), status.get_updates_request_types()); |
| 466 } | 464 } |
| 467 | 465 |
| 468 class DownloadUpdatesDebugInfoTest : public ::testing::Test { | 466 class DownloadUpdatesDebugInfoTest : public ::testing::Test { |
| 469 public: | 467 public: |
| 470 DownloadUpdatesDebugInfoTest() {} | 468 DownloadUpdatesDebugInfoTest() {} |
| 471 ~DownloadUpdatesDebugInfoTest() override {} | 469 ~DownloadUpdatesDebugInfoTest() override {} |
| 472 | 470 |
| 473 sessions::StatusController* status() { return &status_; } | 471 StatusController* status() { return &status_; } |
| 474 | 472 |
| 475 sessions::DebugInfoGetter* debug_info_getter() { return &debug_info_getter_; } | 473 DebugInfoGetter* debug_info_getter() { return &debug_info_getter_; } |
| 476 | 474 |
| 477 void AddDebugEvent() { debug_info_getter_.AddDebugEvent(); } | 475 void AddDebugEvent() { debug_info_getter_.AddDebugEvent(); } |
| 478 | 476 |
| 479 private: | 477 private: |
| 480 sessions::StatusController status_; | 478 StatusController status_; |
| 481 MockDebugInfoGetter debug_info_getter_; | 479 MockDebugInfoGetter debug_info_getter_; |
| 482 }; | 480 }; |
| 483 | 481 |
| 484 // Verify CopyClientDebugInfo when there are no events to upload. | 482 // Verify CopyClientDebugInfo when there are no events to upload. |
| 485 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyClientDebugInfo_Empty) { | 483 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyClientDebugInfo_Empty) { |
| 486 sync_pb::DebugInfo debug_info; | 484 sync_pb::DebugInfo debug_info; |
| 487 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 485 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
| 488 EXPECT_EQ(0, debug_info.events_size()); | 486 EXPECT_EQ(0, debug_info.events_size()); |
| 489 } | 487 } |
| 490 | 488 |
| 491 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { | 489 TEST_F(DownloadUpdatesDebugInfoTest, VerifyCopyOverwrites) { |
| 492 sync_pb::DebugInfo debug_info; | 490 sync_pb::DebugInfo debug_info; |
| 493 AddDebugEvent(); | 491 AddDebugEvent(); |
| 494 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); | 492 GetUpdatesProcessor::CopyClientDebugInfo(debug_info_getter(), &debug_info); |
| 495 EXPECT_EQ(1, debug_info.events_size()); | 493 EXPECT_EQ(1, debug_info.events_size()); |
| 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 } | 496 } |
| 499 | 497 |
| 500 } // namespace syncer | 498 } // namespace syncer |
| OLD | NEW |