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 |
| 749 // Called by ShutdownOnSyncThread(). |
| 750 EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(_)); |
745 | 751 |
746 sync_manager_.AddObserver(&observer_); | 752 sync_manager_.AddObserver(&observer_); |
747 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). | 753 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). |
748 WillOnce(SaveArg<0>(&js_backend_)); | 754 WillOnce(SaveArg<0>(&js_backend_)); |
749 | 755 |
750 EXPECT_FALSE(js_backend_.IsInitialized()); | 756 EXPECT_FALSE(js_backend_.IsInitialized()); |
751 | 757 |
752 std::vector<ModelSafeWorker*> workers; | 758 std::vector<ModelSafeWorker*> workers; |
753 ModelSafeRoutingInfo routing_info; | 759 ModelSafeRoutingInfo routing_info; |
754 GetModelSafeRoutingInfo(&routing_info); | 760 GetModelSafeRoutingInfo(&routing_info); |
(...skipping 20 matching lines...) Expand all Loading... |
775 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 781 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
776 i != routing_info.end(); ++i) { | 782 i != routing_info.end(); ++i) { |
777 type_roots_[i->first] = MakeServerNodeForType( | 783 type_roots_[i->first] = MakeServerNodeForType( |
778 sync_manager_.GetUserShare(), i->first); | 784 sync_manager_.GetUserShare(), i->first); |
779 } | 785 } |
780 PumpLoop(); | 786 PumpLoop(); |
781 } | 787 } |
782 | 788 |
783 void TearDown() { | 789 void TearDown() { |
784 sync_manager_.RemoveObserver(&observer_); | 790 sync_manager_.RemoveObserver(&observer_); |
785 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(_, ObjectIdSet())); | 791 // |sync_notifier_mock_| is strict, which ensures we don't do anything but |
| 792 // unregister |sync_manager_| as a handler on shutdown. |
786 sync_manager_.ShutdownOnSyncThread(); | 793 sync_manager_.ShutdownOnSyncThread(); |
787 sync_notifier_mock_ = NULL; | 794 sync_notifier_mock_ = NULL; |
788 PumpLoop(); | 795 PumpLoop(); |
789 } | 796 } |
790 | 797 |
791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 798 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
792 (*out)[NIGORI] = GROUP_PASSIVE; | 799 (*out)[NIGORI] = GROUP_PASSIVE; |
793 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 800 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
794 (*out)[THEMES] = GROUP_PASSIVE; | 801 (*out)[THEMES] = GROUP_PASSIVE; |
795 (*out)[SESSIONS] = GROUP_PASSIVE; | 802 (*out)[SESSIONS] = GROUP_PASSIVE; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 956 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
950 SyncManagerImpl sync_manager_; | 957 SyncManagerImpl sync_manager_; |
951 WeakHandle<JsBackend> js_backend_; | 958 WeakHandle<JsBackend> js_backend_; |
952 StrictMock<SyncManagerObserverMock> observer_; | 959 StrictMock<SyncManagerObserverMock> observer_; |
953 }; | 960 }; |
954 | 961 |
955 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 962 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
956 ModelSafeRoutingInfo routes; | 963 ModelSafeRoutingInfo routes; |
957 GetModelSafeRoutingInfo(&routes); | 964 GetModelSafeRoutingInfo(&routes); |
958 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | 965 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); |
959 | |
960 EXPECT_CALL(*sync_notifier_mock_, | 966 EXPECT_CALL(*sync_notifier_mock_, |
961 UpdateRegisteredIds( | 967 UpdateRegisteredIds( |
962 _, ModelTypeSetToObjectIdSet(enabled_types))); | 968 _, ModelTypeSetToObjectIdSet(enabled_types))); |
| 969 |
963 sync_manager_.UpdateEnabledTypes(enabled_types); | 970 sync_manager_.UpdateEnabledTypes(enabled_types); |
964 } | 971 } |
965 | 972 |
| 973 TEST_F(SyncManagerTest, RegisterInvalidationHandler) { |
| 974 EXPECT_CALL(*sync_notifier_mock_, RegisterHandler(NULL)); |
| 975 sync_manager_.RegisterInvalidationHandler(NULL); |
| 976 } |
| 977 |
966 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) { | 978 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) { |
967 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(NULL, ObjectIdSet())); | 979 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(NULL, ObjectIdSet())); |
968 sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet()); | 980 sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet()); |
969 } | 981 } |
970 | 982 |
| 983 TEST_F(SyncManagerTest, UnregisterInvalidationHandler) { |
| 984 EXPECT_CALL(*sync_notifier_mock_, UnregisterHandler(NULL)); |
| 985 sync_manager_.UnregisterInvalidationHandler(NULL); |
| 986 } |
| 987 |
971 TEST_F(SyncManagerTest, ProcessJsMessage) { | 988 TEST_F(SyncManagerTest, ProcessJsMessage) { |
972 const JsArgList kNoArgs; | 989 const JsArgList kNoArgs; |
973 | 990 |
974 StrictMock<MockJsReplyHandler> reply_handler; | 991 StrictMock<MockJsReplyHandler> reply_handler; |
975 | 992 |
976 ListValue disabled_args; | 993 ListValue disabled_args; |
977 disabled_args.Append( | 994 disabled_args.Append( |
978 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); | 995 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); |
979 | 996 |
980 EXPECT_CALL(reply_handler, | 997 EXPECT_CALL(reply_handler, |
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2783 | 2800 |
2784 // Verify only the non-disabled types remain after cleanup. | 2801 // Verify only the non-disabled types remain after cleanup. |
2785 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2802 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
2786 EXPECT_TRUE(new_enabled_types.Equals( | 2803 EXPECT_TRUE(new_enabled_types.Equals( |
2787 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2804 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
2788 EXPECT_TRUE(disabled_types.Equals( | 2805 EXPECT_TRUE(disabled_types.Equals( |
2789 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2806 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
2790 } | 2807 } |
2791 | 2808 |
2792 } // namespace | 2809 } // namespace |
OLD | NEW |