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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <map> | 10 #include <map> |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT | 689 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT |
690 MOCK_METHOD2(OnEncryptedTypesChanged, | 690 MOCK_METHOD2(OnEncryptedTypesChanged, |
691 void(ModelTypeSet, bool)); // NOLINT | 691 void(ModelTypeSet, bool)); // NOLINT |
692 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT | 692 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT |
693 MOCK_METHOD1(OnActionableError, | 693 MOCK_METHOD1(OnActionableError, |
694 void(const SyncProtocolError&)); // NOLINT | 694 void(const SyncProtocolError&)); // NOLINT |
695 }; | 695 }; |
696 | 696 |
697 class SyncNotifierMock : public SyncNotifier { | 697 class SyncNotifierMock : public SyncNotifier { |
698 public: | 698 public: |
699 MOCK_METHOD1(RegisterHandler, void(SyncNotifierObserver*)); | |
700 MOCK_METHOD2(UpdateRegisteredIds, | 699 MOCK_METHOD2(UpdateRegisteredIds, |
701 void(SyncNotifierObserver*, const ObjectIdSet&)); | 700 void(SyncNotifierObserver*, const ObjectIdSet&)); |
702 MOCK_METHOD1(UnregisterHandler, void(SyncNotifierObserver*)); | |
703 MOCK_METHOD1(SetUniqueId, void(const std::string&)); | 701 MOCK_METHOD1(SetUniqueId, void(const std::string&)); |
704 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); | 702 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); |
705 MOCK_METHOD2(UpdateCredentials, | 703 MOCK_METHOD2(UpdateCredentials, |
706 void(const std::string&, const std::string&)); | 704 void(const std::string&, const std::string&)); |
707 MOCK_METHOD1(SendNotification, void(ModelTypeSet)); | 705 MOCK_METHOD1(SendNotification, void(ModelTypeSet)); |
708 }; | 706 }; |
709 | 707 |
710 } // namespace | 708 } // namespace |
711 | 709 |
712 class SyncManagerTest : public testing::Test, | 710 class SyncManagerTest : public testing::Test, |
(...skipping 24 matching lines...) Expand all Loading... |
737 | 735 |
738 SyncCredentials credentials; | 736 SyncCredentials credentials; |
739 credentials.email = "foo@bar.com"; | 737 credentials.email = "foo@bar.com"; |
740 credentials.sync_token = "sometoken"; | 738 credentials.sync_token = "sometoken"; |
741 | 739 |
742 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); | 740 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); |
743 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); | 741 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); |
744 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); | 742 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); |
745 EXPECT_CALL(*sync_notifier_mock_, | 743 EXPECT_CALL(*sync_notifier_mock_, |
746 UpdateCredentials(credentials.email, credentials.sync_token)); | 744 UpdateCredentials(credentials.email, credentials.sync_token)); |
747 EXPECT_CALL(*sync_notifier_mock_, RegisterHandler(_)); | |
748 | |
749 // Called by ShutdownOnSyncThread(). | |
750 EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(_)); | |
751 | 745 |
752 sync_manager_.AddObserver(&observer_); | 746 sync_manager_.AddObserver(&observer_); |
753 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). | 747 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). |
754 WillOnce(SaveArg<0>(&js_backend_)); | 748 WillOnce(SaveArg<0>(&js_backend_)); |
755 | 749 |
756 EXPECT_FALSE(js_backend_.IsInitialized()); | 750 EXPECT_FALSE(js_backend_.IsInitialized()); |
757 | 751 |
758 std::vector<ModelSafeWorker*> workers; | 752 std::vector<ModelSafeWorker*> workers; |
759 ModelSafeRoutingInfo routing_info; | 753 ModelSafeRoutingInfo routing_info; |
760 GetModelSafeRoutingInfo(&routing_info); | 754 GetModelSafeRoutingInfo(&routing_info); |
(...skipping 20 matching lines...) Expand all Loading... |
781 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 775 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
782 i != routing_info.end(); ++i) { | 776 i != routing_info.end(); ++i) { |
783 type_roots_[i->first] = MakeServerNodeForType( | 777 type_roots_[i->first] = MakeServerNodeForType( |
784 sync_manager_.GetUserShare(), i->first); | 778 sync_manager_.GetUserShare(), i->first); |
785 } | 779 } |
786 PumpLoop(); | 780 PumpLoop(); |
787 } | 781 } |
788 | 782 |
789 void TearDown() { | 783 void TearDown() { |
790 sync_manager_.RemoveObserver(&observer_); | 784 sync_manager_.RemoveObserver(&observer_); |
791 // |sync_notifier_mock_| is strict, which ensures we don't do anything but | 785 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(_, ObjectIdSet())); |
792 // unregister |sync_manager_| as a handler on shutdown. | |
793 sync_manager_.ShutdownOnSyncThread(); | 786 sync_manager_.ShutdownOnSyncThread(); |
794 sync_notifier_mock_ = NULL; | 787 sync_notifier_mock_ = NULL; |
795 PumpLoop(); | 788 PumpLoop(); |
796 } | 789 } |
797 | 790 |
798 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
799 (*out)[NIGORI] = GROUP_PASSIVE; | 792 (*out)[NIGORI] = GROUP_PASSIVE; |
800 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 793 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
801 (*out)[THEMES] = GROUP_PASSIVE; | 794 (*out)[THEMES] = GROUP_PASSIVE; |
802 (*out)[SESSIONS] = GROUP_PASSIVE; | 795 (*out)[SESSIONS] = GROUP_PASSIVE; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 949 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
957 SyncManagerImpl sync_manager_; | 950 SyncManagerImpl sync_manager_; |
958 WeakHandle<JsBackend> js_backend_; | 951 WeakHandle<JsBackend> js_backend_; |
959 StrictMock<SyncManagerObserverMock> observer_; | 952 StrictMock<SyncManagerObserverMock> observer_; |
960 }; | 953 }; |
961 | 954 |
962 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 955 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
963 ModelSafeRoutingInfo routes; | 956 ModelSafeRoutingInfo routes; |
964 GetModelSafeRoutingInfo(&routes); | 957 GetModelSafeRoutingInfo(&routes); |
965 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | 958 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); |
| 959 |
966 EXPECT_CALL(*sync_notifier_mock_, | 960 EXPECT_CALL(*sync_notifier_mock_, |
967 UpdateRegisteredIds( | 961 UpdateRegisteredIds( |
968 _, ModelTypeSetToObjectIdSet(enabled_types))); | 962 _, ModelTypeSetToObjectIdSet(enabled_types))); |
969 | |
970 sync_manager_.UpdateEnabledTypes(enabled_types); | 963 sync_manager_.UpdateEnabledTypes(enabled_types); |
971 } | 964 } |
972 | 965 |
973 TEST_F(SyncManagerTest, RegisterInvalidationHandler) { | |
974 EXPECT_CALL(*sync_notifier_mock_, RegisterHandler(NULL)); | |
975 sync_manager_.RegisterInvalidationHandler(NULL); | |
976 } | |
977 | |
978 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) { | 966 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) { |
979 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(NULL, ObjectIdSet())); | 967 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(NULL, ObjectIdSet())); |
980 sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet()); | 968 sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet()); |
981 } | 969 } |
982 | 970 |
983 TEST_F(SyncManagerTest, UnregisterInvalidationHandler) { | |
984 EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(NULL)); | |
985 sync_manager_.UnregisterInvalidationHandler(NULL); | |
986 } | |
987 | |
988 TEST_F(SyncManagerTest, ProcessJsMessage) { | 971 TEST_F(SyncManagerTest, ProcessJsMessage) { |
989 const JsArgList kNoArgs; | 972 const JsArgList kNoArgs; |
990 | 973 |
991 StrictMock<MockJsReplyHandler> reply_handler; | 974 StrictMock<MockJsReplyHandler> reply_handler; |
992 | 975 |
993 ListValue disabled_args; | 976 ListValue disabled_args; |
994 disabled_args.Append( | 977 disabled_args.Append( |
995 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); | 978 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); |
996 | 979 |
997 EXPECT_CALL(reply_handler, | 980 EXPECT_CALL(reply_handler, |
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2800 | 2783 |
2801 // Verify only the non-disabled types remain after cleanup. | 2784 // Verify only the non-disabled types remain after cleanup. |
2802 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2785 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
2803 EXPECT_TRUE(new_enabled_types.Equals( | 2786 EXPECT_TRUE(new_enabled_types.Equals( |
2804 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2787 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
2805 EXPECT_TRUE(disabled_types.Equals( | 2788 EXPECT_TRUE(disabled_types.Equals( |
2806 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2789 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
2807 } | 2790 } |
2808 | 2791 |
2809 } // namespace | 2792 } // namespace |
OLD | NEW |