OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
24 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread.h" |
25 #include "google/cacheinvalidation/include/types.h" | 25 #include "google/cacheinvalidation/include/types.h" |
26 #include "google_apis/gaia/gaia_constants.h" | 26 #include "google_apis/gaia/gaia_constants.h" |
27 #include "sync/js/js_arg_list.h" | 27 #include "sync/js/js_arg_list.h" |
28 #include "sync/js/js_event_details.h" | 28 #include "sync/js/js_event_details.h" |
29 #include "sync/js/js_test_util.h" | 29 #include "sync/js/js_test_util.h" |
30 #include "sync/notifier/fake_invalidation_handler.h" | 30 #include "sync/notifier/fake_invalidation_handler.h" |
31 #include "sync/notifier/invalidator.h" | 31 #include "sync/notifier/invalidator.h" |
32 #include "sync/notifier/invalidator_test_template.h" | 32 #include "sync/notifier/invalidator_test_template.h" |
33 #include "sync/notifier/object_id_state_map_test_util.h" | 33 #include "sync/notifier/object_id_invalidation_map_test_util.h" |
34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "webkit/user_agent/user_agent.h" | 36 #include "webkit/user_agent/user_agent.h" |
37 | 37 |
38 // TODO(akalin): Add tests here that exercise the whole | 38 // TODO(akalin): Add tests here that exercise the whole |
39 // ProfileSyncService/SyncBackendHost stack while mocking out as | 39 // ProfileSyncService/SyncBackendHost stack while mocking out as |
40 // little as possible. | 40 // little as possible. |
41 | 41 |
42 namespace browser_sync { | 42 namespace browser_sync { |
43 | 43 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 399 } |
400 | 400 |
401 // Register for some IDs with the ProfileSyncService, restart sync, | 401 // Register for some IDs with the ProfileSyncService, restart sync, |
402 // and trigger some invalidation messages. They should still be | 402 // and trigger some invalidation messages. They should still be |
403 // received by the handler. | 403 // received by the handler. |
404 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { | 404 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { |
405 harness_.StartSyncService(); | 405 harness_.StartSyncService(); |
406 | 406 |
407 syncer::ObjectIdSet ids; | 407 syncer::ObjectIdSet ids; |
408 ids.insert(invalidation::ObjectId(3, "id3")); | 408 ids.insert(invalidation::ObjectId(3, "id3")); |
409 const syncer::ObjectIdStateMap& states = | 409 const syncer::ObjectIdInvalidationMap& states = |
410 syncer::ObjectIdSetToStateMap(ids, "payload"); | 410 syncer::ObjectIdSetToInvalidationMap(ids, "payload"); |
411 | 411 |
412 syncer::FakeInvalidationHandler handler; | 412 syncer::FakeInvalidationHandler handler; |
413 | 413 |
414 harness_.service->RegisterInvalidationHandler(&handler); | 414 harness_.service->RegisterInvalidationHandler(&handler); |
415 harness_.service->UpdateRegisteredInvalidationIds(&handler, ids); | 415 harness_.service->UpdateRegisteredInvalidationIds(&handler, ids); |
416 | 416 |
417 harness_.service->StopAndSuppress(); | 417 harness_.service->StopAndSuppress(); |
418 harness_.service->UnsuppressAndStart(); | 418 harness_.service->UnsuppressAndStart(); |
419 | 419 |
420 SyncBackendHostForProfileSyncTest* const backend = | 420 SyncBackendHostForProfileSyncTest* const backend = |
421 harness_.service->GetBackendForTest(); | 421 harness_.service->GetBackendForTest(); |
422 | 422 |
423 backend->EmitOnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED); | 423 backend->EmitOnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED); |
424 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); | 424 EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState()); |
425 | 425 |
426 backend->EmitOnIncomingInvalidation(states, syncer::REMOTE_INVALIDATION); | 426 backend->EmitOnIncomingInvalidation(states, syncer::REMOTE_INVALIDATION); |
427 EXPECT_THAT(states, Eq(handler.GetLastInvalidationIdStateMap())); | 427 EXPECT_THAT(states, Eq(handler.GetLastInvalidationMap())); |
428 EXPECT_EQ(syncer::REMOTE_INVALIDATION, handler.GetLastInvalidationSource()); | 428 EXPECT_EQ(syncer::REMOTE_INVALIDATION, handler.GetLastInvalidationSource()); |
429 | 429 |
430 backend->EmitOnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR); | 430 backend->EmitOnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR); |
431 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, | 431 EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR, |
432 handler.GetInvalidatorState()); | 432 handler.GetInvalidatorState()); |
433 } | 433 } |
434 | 434 |
435 // Thin Invalidator wrapper around ProfileSyncService. | 435 // Thin Invalidator wrapper around ProfileSyncService. |
436 class ProfileSyncServiceInvalidator : public syncer::Invalidator { | 436 class ProfileSyncServiceInvalidator : public syncer::Invalidator { |
437 public: | 437 public: |
(...skipping 28 matching lines...) Expand all Loading... |
466 virtual void SetStateDeprecated(const std::string& state) OVERRIDE { | 466 virtual void SetStateDeprecated(const std::string& state) OVERRIDE { |
467 // Do nothing. | 467 // Do nothing. |
468 } | 468 } |
469 | 469 |
470 virtual void UpdateCredentials( | 470 virtual void UpdateCredentials( |
471 const std::string& email, const std::string& token) OVERRIDE { | 471 const std::string& email, const std::string& token) OVERRIDE { |
472 // Do nothing. | 472 // Do nothing. |
473 } | 473 } |
474 | 474 |
475 virtual void SendInvalidation( | 475 virtual void SendInvalidation( |
476 const syncer::ObjectIdStateMap& id_state_map) OVERRIDE { | 476 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE { |
477 // Do nothing. | 477 // Do nothing. |
478 } | 478 } |
479 | 479 |
480 private: | 480 private: |
481 ProfileSyncService* const service_; | 481 ProfileSyncService* const service_; |
482 | 482 |
483 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceInvalidator); | 483 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceInvalidator); |
484 }; | 484 }; |
485 | 485 |
486 } // namespace | 486 } // namespace |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 518 |
519 void WaitForInvalidator() { | 519 void WaitForInvalidator() { |
520 // Do nothing. | 520 // Do nothing. |
521 } | 521 } |
522 | 522 |
523 void TriggerOnInvalidatorStateChange(syncer::InvalidatorState state) { | 523 void TriggerOnInvalidatorStateChange(syncer::InvalidatorState state) { |
524 harness_.service->GetBackendForTest()->EmitOnInvalidatorStateChange(state); | 524 harness_.service->GetBackendForTest()->EmitOnInvalidatorStateChange(state); |
525 } | 525 } |
526 | 526 |
527 void TriggerOnIncomingInvalidation( | 527 void TriggerOnIncomingInvalidation( |
528 const syncer::ObjectIdStateMap& id_state_map, | 528 const syncer::ObjectIdInvalidationMap& invalidation_map, |
529 syncer::IncomingInvalidationSource source) { | 529 syncer::IncomingInvalidationSource source) { |
530 harness_.service->GetBackendForTest()->EmitOnIncomingInvalidation( | 530 harness_.service->GetBackendForTest()->EmitOnIncomingInvalidation( |
531 id_state_map, source); | 531 invalidation_map, source); |
532 } | 532 } |
533 | 533 |
534 static bool InvalidatorHandlesDeprecatedState() { | 534 static bool InvalidatorHandlesDeprecatedState() { |
535 return false; | 535 return false; |
536 } | 536 } |
537 | 537 |
538 private: | 538 private: |
539 ProfileSyncServiceTestHarness harness_; | 539 ProfileSyncServiceTestHarness harness_; |
540 scoped_ptr<ProfileSyncServiceInvalidator> invalidator_; | 540 scoped_ptr<ProfileSyncServiceInvalidator> invalidator_; |
541 }; | 541 }; |
542 | 542 |
543 } // namespace browser_sync | 543 } // namespace browser_sync |
544 | 544 |
545 namespace syncer { | 545 namespace syncer { |
546 namespace { | 546 namespace { |
547 | 547 |
548 // ProfileSyncService should behave just like an invalidator. | 548 // ProfileSyncService should behave just like an invalidator. |
549 INSTANTIATE_TYPED_TEST_CASE_P( | 549 INSTANTIATE_TYPED_TEST_CASE_P( |
550 ProfileSyncServiceInvalidatorTest, InvalidatorTest, | 550 ProfileSyncServiceInvalidatorTest, InvalidatorTest, |
551 ::browser_sync::ProfileSyncServiceInvalidatorTestDelegate); | 551 ::browser_sync::ProfileSyncServiceInvalidatorTestDelegate); |
552 | 552 |
553 } // namespace | 553 } // namespace |
554 } // namespace syncer | 554 } // namespace syncer |
OLD | NEW |