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*)); | |
699 MOCK_METHOD2(UpdateRegisteredIds, | 700 MOCK_METHOD2(UpdateRegisteredIds, |
700 void(SyncNotifierObserver*, const ObjectIdSet&)); | 701 void(SyncNotifierObserver*, const ObjectIdSet&)); |
702 MOCK_METHOD1(UnregisterHandler, void(SyncNotifierObserver*)); | |
701 MOCK_METHOD1(SetUniqueId, void(const std::string&)); | 703 MOCK_METHOD1(SetUniqueId, void(const std::string&)); |
702 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); | 704 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); |
703 MOCK_METHOD2(UpdateCredentials, | 705 MOCK_METHOD2(UpdateCredentials, |
704 void(const std::string&, const std::string&)); | 706 void(const std::string&, const std::string&)); |
705 MOCK_METHOD1(SendNotification, void(ModelTypeSet)); | 707 MOCK_METHOD1(SendNotification, void(ModelTypeSet)); |
706 }; | 708 }; |
707 | 709 |
708 } // namespace | 710 } // namespace |
709 | 711 |
710 class SyncManagerTest : public testing::Test, | 712 class SyncManagerTest : public testing::Test, |
(...skipping 24 matching lines...) Expand all Loading... | |
735 | 737 |
736 SyncCredentials credentials; | 738 SyncCredentials credentials; |
737 credentials.email = "foo@bar.com"; | 739 credentials.email = "foo@bar.com"; |
738 credentials.sync_token = "sometoken"; | 740 credentials.sync_token = "sometoken"; |
739 | 741 |
740 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); | 742 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); |
741 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); | 743 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); |
742 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); | 744 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); |
743 EXPECT_CALL(*sync_notifier_mock_, | 745 EXPECT_CALL(*sync_notifier_mock_, |
744 UpdateCredentials(credentials.email, credentials.sync_token)); | 746 UpdateCredentials(credentials.email, credentials.sync_token)); |
747 EXPECT_CALL(*sync_notifier_mock_, RegisterHandler(_)); | |
748 EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(_)); | |
745 | 749 |
746 sync_manager_.AddObserver(&observer_); | 750 sync_manager_.AddObserver(&observer_); |
747 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). | 751 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). |
748 WillOnce(SaveArg<0>(&js_backend_)); | 752 WillOnce(SaveArg<0>(&js_backend_)); |
749 | 753 |
750 EXPECT_FALSE(js_backend_.IsInitialized()); | 754 EXPECT_FALSE(js_backend_.IsInitialized()); |
751 | 755 |
752 std::vector<ModelSafeWorker*> workers; | 756 std::vector<ModelSafeWorker*> workers; |
753 ModelSafeRoutingInfo routing_info; | 757 ModelSafeRoutingInfo routing_info; |
754 GetModelSafeRoutingInfo(&routing_info); | 758 GetModelSafeRoutingInfo(&routing_info); |
(...skipping 20 matching lines...) Expand all Loading... | |
775 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 779 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
776 i != routing_info.end(); ++i) { | 780 i != routing_info.end(); ++i) { |
777 type_roots_[i->first] = MakeServerNodeForType( | 781 type_roots_[i->first] = MakeServerNodeForType( |
778 sync_manager_.GetUserShare(), i->first); | 782 sync_manager_.GetUserShare(), i->first); |
779 } | 783 } |
780 PumpLoop(); | 784 PumpLoop(); |
781 } | 785 } |
782 | 786 |
783 void TearDown() { | 787 void TearDown() { |
784 sync_manager_.RemoveObserver(&observer_); | 788 sync_manager_.RemoveObserver(&observer_); |
785 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(_, ObjectIdSet())); | |
786 sync_manager_.ShutdownOnSyncThread(); | 789 sync_manager_.ShutdownOnSyncThread(); |
msw
2012/08/09 05:20:26
nit: comment that StrictMock ensures that the curr
akalin
2012/08/10 01:28:08
Done.
| |
787 sync_notifier_mock_ = NULL; | 790 sync_notifier_mock_ = NULL; |
788 PumpLoop(); | 791 PumpLoop(); |
789 } | 792 } |
790 | 793 |
791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 794 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
792 (*out)[NIGORI] = GROUP_PASSIVE; | 795 (*out)[NIGORI] = GROUP_PASSIVE; |
793 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 796 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
794 (*out)[THEMES] = GROUP_PASSIVE; | 797 (*out)[THEMES] = GROUP_PASSIVE; |
795 (*out)[SESSIONS] = GROUP_PASSIVE; | 798 (*out)[SESSIONS] = GROUP_PASSIVE; |
796 (*out)[PASSWORDS] = GROUP_PASSIVE; | 799 (*out)[PASSWORDS] = GROUP_PASSIVE; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
949 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 952 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
950 SyncManagerImpl sync_manager_; | 953 SyncManagerImpl sync_manager_; |
951 WeakHandle<JsBackend> js_backend_; | 954 WeakHandle<JsBackend> js_backend_; |
952 StrictMock<SyncManagerObserverMock> observer_; | 955 StrictMock<SyncManagerObserverMock> observer_; |
953 }; | 956 }; |
954 | 957 |
955 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 958 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
956 ModelSafeRoutingInfo routes; | 959 ModelSafeRoutingInfo routes; |
957 GetModelSafeRoutingInfo(&routes); | 960 GetModelSafeRoutingInfo(&routes); |
958 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | 961 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); |
959 | |
960 EXPECT_CALL(*sync_notifier_mock_, | 962 EXPECT_CALL(*sync_notifier_mock_, |
961 UpdateRegisteredIds( | 963 UpdateRegisteredIds( |
962 _, ModelTypeSetToObjectIdSet(enabled_types))); | 964 _, ModelTypeSetToObjectIdSet(enabled_types))); |
965 | |
963 sync_manager_.UpdateEnabledTypes(enabled_types); | 966 sync_manager_.UpdateEnabledTypes(enabled_types); |
964 } | 967 } |
965 | 968 |
969 TEST_F(SyncManagerTest, RegisterInvalidationHandler) { | |
970 EXPECT_CALL(*sync_notifier_mock_, RegisterHandler(NULL)); | |
971 sync_manager_.RegisterInvalidationHandler(NULL); | |
972 } | |
973 | |
966 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) { | 974 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) { |
967 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(NULL, ObjectIdSet())); | 975 EXPECT_CALL(*sync_notifier_mock_, |
976 UpdateRegisteredIds(NULL, ObjectIdSet())); | |
968 sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet()); | 977 sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet()); |
969 } | 978 } |
970 | 979 |
980 TEST_F(SyncManagerTest, UnregisterInvalidationHandler) { | |
981 EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(NULL)); | |
982 sync_manager_.UnregisterInvalidationHandler(NULL); | |
983 } | |
984 | |
971 TEST_F(SyncManagerTest, ProcessJsMessage) { | 985 TEST_F(SyncManagerTest, ProcessJsMessage) { |
972 const JsArgList kNoArgs; | 986 const JsArgList kNoArgs; |
973 | 987 |
974 StrictMock<MockJsReplyHandler> reply_handler; | 988 StrictMock<MockJsReplyHandler> reply_handler; |
975 | 989 |
976 ListValue disabled_args; | 990 ListValue disabled_args; |
977 disabled_args.Append( | 991 disabled_args.Append( |
978 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); | 992 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); |
979 | 993 |
980 EXPECT_CALL(reply_handler, | 994 EXPECT_CALL(reply_handler, |
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2783 | 2797 |
2784 // Verify only the non-disabled types remain after cleanup. | 2798 // Verify only the non-disabled types remain after cleanup. |
2785 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2799 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
2786 EXPECT_TRUE(new_enabled_types.Equals( | 2800 EXPECT_TRUE(new_enabled_types.Equals( |
2787 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2801 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
2788 EXPECT_TRUE(disabled_types.Equals( | 2802 EXPECT_TRUE(disabled_types.Equals( |
2789 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2803 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
2790 } | 2804 } |
2791 | 2805 |
2792 } // namespace | 2806 } // namespace |
OLD | NEW |