Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 10824161: [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_METHOD2(SetHandler, void(const std::string&, SyncNotifierObserver*));
699 MOCK_METHOD2(UpdateRegisteredIds, 700 MOCK_METHOD2(UpdateRegisteredIds,
700 void(SyncNotifierObserver*, const ObjectIdSet&)); 701 void(const std::string&, const ObjectIdSet&));
701 MOCK_METHOD1(SetUniqueId, void(const std::string&)); 702 MOCK_METHOD1(SetUniqueId, void(const std::string&));
702 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); 703 MOCK_METHOD1(SetStateDeprecated, void(const std::string&));
703 MOCK_METHOD2(UpdateCredentials, 704 MOCK_METHOD2(UpdateCredentials,
704 void(const std::string&, const std::string&)); 705 void(const std::string&, const std::string&));
705 MOCK_METHOD1(SendNotification, void(ModelTypeSet)); 706 MOCK_METHOD1(SendNotification, void(ModelTypeSet));
706 }; 707 };
707 708
708 } // namespace 709 } // namespace
709 710
710 class SyncManagerTest : public testing::Test, 711 class SyncManagerTest : public testing::Test,
(...skipping 24 matching lines...) Expand all
735 736
736 SyncCredentials credentials; 737 SyncCredentials credentials;
737 credentials.email = "foo@bar.com"; 738 credentials.email = "foo@bar.com";
738 credentials.sync_token = "sometoken"; 739 credentials.sync_token = "sometoken";
739 740
740 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); 741 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>();
741 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); 742 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_));
742 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); 743 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated(""));
743 EXPECT_CALL(*sync_notifier_mock_, 744 EXPECT_CALL(*sync_notifier_mock_,
744 UpdateCredentials(credentials.email, credentials.sync_token)); 745 UpdateCredentials(credentials.email, credentials.sync_token));
746 EXPECT_CALL(*sync_notifier_mock_, SetHandler("SyncManagerImpl", _))
747 .Times(2);
745 748
746 sync_manager_.AddObserver(&observer_); 749 sync_manager_.AddObserver(&observer_);
747 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). 750 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)).
748 WillOnce(SaveArg<0>(&js_backend_)); 751 WillOnce(SaveArg<0>(&js_backend_));
749 752
750 EXPECT_FALSE(js_backend_.IsInitialized()); 753 EXPECT_FALSE(js_backend_.IsInitialized());
751 754
752 std::vector<ModelSafeWorker*> workers; 755 std::vector<ModelSafeWorker*> workers;
753 ModelSafeRoutingInfo routing_info; 756 ModelSafeRoutingInfo routing_info;
754 GetModelSafeRoutingInfo(&routing_info); 757 GetModelSafeRoutingInfo(&routing_info);
(...skipping 20 matching lines...) Expand all
775 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 778 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
776 i != routing_info.end(); ++i) { 779 i != routing_info.end(); ++i) {
777 type_roots_[i->first] = MakeServerNodeForType( 780 type_roots_[i->first] = MakeServerNodeForType(
778 sync_manager_.GetUserShare(), i->first); 781 sync_manager_.GetUserShare(), i->first);
779 } 782 }
780 PumpLoop(); 783 PumpLoop();
781 } 784 }
782 785
783 void TearDown() { 786 void TearDown() {
784 sync_manager_.RemoveObserver(&observer_); 787 sync_manager_.RemoveObserver(&observer_);
785 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(_, ObjectIdSet()));
786 sync_manager_.ShutdownOnSyncThread(); 788 sync_manager_.ShutdownOnSyncThread();
787 sync_notifier_mock_ = NULL; 789 sync_notifier_mock_ = NULL;
788 PumpLoop(); 790 PumpLoop();
789 } 791 }
790 792
791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { 793 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
792 (*out)[NIGORI] = GROUP_PASSIVE; 794 (*out)[NIGORI] = GROUP_PASSIVE;
793 (*out)[BOOKMARKS] = GROUP_PASSIVE; 795 (*out)[BOOKMARKS] = GROUP_PASSIVE;
794 (*out)[THEMES] = GROUP_PASSIVE; 796 (*out)[THEMES] = GROUP_PASSIVE;
795 (*out)[SESSIONS] = GROUP_PASSIVE; 797 (*out)[SESSIONS] = GROUP_PASSIVE;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 StrictMock<SyncNotifierMock>* sync_notifier_mock_; 951 StrictMock<SyncNotifierMock>* sync_notifier_mock_;
950 SyncManagerImpl sync_manager_; 952 SyncManagerImpl sync_manager_;
951 WeakHandle<JsBackend> js_backend_; 953 WeakHandle<JsBackend> js_backend_;
952 StrictMock<SyncManagerObserverMock> observer_; 954 StrictMock<SyncManagerObserverMock> observer_;
953 }; 955 };
954 956
955 TEST_F(SyncManagerTest, UpdateEnabledTypes) { 957 TEST_F(SyncManagerTest, UpdateEnabledTypes) {
956 ModelSafeRoutingInfo routes; 958 ModelSafeRoutingInfo routes;
957 GetModelSafeRoutingInfo(&routes); 959 GetModelSafeRoutingInfo(&routes);
958 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); 960 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes);
959
960 EXPECT_CALL(*sync_notifier_mock_, 961 EXPECT_CALL(*sync_notifier_mock_,
961 UpdateRegisteredIds( 962 UpdateRegisteredIds(
962 _, ModelTypeSetToObjectIdSet(enabled_types))); 963 _, ModelTypeSetToObjectIdSet(enabled_types)));
964
963 sync_manager_.UpdateEnabledTypes(enabled_types); 965 sync_manager_.UpdateEnabledTypes(enabled_types);
964 } 966 }
965 967
968 TEST_F(SyncManagerTest, SetInvalidationHandler) {
969 const char kHandlerName[] = "handler";
970 EXPECT_CALL(*sync_notifier_mock_, SetHandler(kHandlerName, NULL));
971 sync_manager_.SetInvalidationHandler(kHandlerName, NULL);
972 }
973
966 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) { 974 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) {
967 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(NULL, ObjectIdSet())); 975 const char kHandlerName[] = "handler";
968 sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet()); 976 EXPECT_CALL(*sync_notifier_mock_,
977 UpdateRegisteredIds(kHandlerName, ObjectIdSet()));
978 sync_manager_.UpdateRegisteredInvalidationIds(kHandlerName, ObjectIdSet());
969 } 979 }
970 980
971 TEST_F(SyncManagerTest, ProcessJsMessage) { 981 TEST_F(SyncManagerTest, ProcessJsMessage) {
972 const JsArgList kNoArgs; 982 const JsArgList kNoArgs;
973 983
974 StrictMock<MockJsReplyHandler> reply_handler; 984 StrictMock<MockJsReplyHandler> reply_handler;
975 985
976 ListValue false_args; 986 ListValue false_args;
977 false_args.Append(Value::CreateBooleanValue(false)); 987 false_args.Append(Value::CreateBooleanValue(false));
978 988
(...skipping 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 2792
2783 // Verify only the non-disabled types remain after cleanup. 2793 // Verify only the non-disabled types remain after cleanup.
2784 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 2794 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
2785 EXPECT_TRUE(new_enabled_types.Equals( 2795 EXPECT_TRUE(new_enabled_types.Equals(
2786 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); 2796 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
2787 EXPECT_TRUE(disabled_types.Equals( 2797 EXPECT_TRUE(disabled_types.Equals(
2788 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 2798 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2789 } 2799 }
2790 2800
2791 } // namespace 2801 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698