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

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

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First set of review fixes Created 7 years, 7 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 28 matching lines...) Expand all
39 #include "sync/internal_api/public/write_transaction.h" 39 #include "sync/internal_api/public/write_transaction.h"
40 #include "sync/internal_api/sync_encryption_handler_impl.h" 40 #include "sync/internal_api/sync_encryption_handler_impl.h"
41 #include "sync/internal_api/sync_manager_impl.h" 41 #include "sync/internal_api/sync_manager_impl.h"
42 #include "sync/internal_api/syncapi_internal.h" 42 #include "sync/internal_api/syncapi_internal.h"
43 #include "sync/js/js_arg_list.h" 43 #include "sync/js/js_arg_list.h"
44 #include "sync/js/js_backend.h" 44 #include "sync/js/js_backend.h"
45 #include "sync/js/js_event_handler.h" 45 #include "sync/js/js_event_handler.h"
46 #include "sync/js/js_reply_handler.h" 46 #include "sync/js/js_reply_handler.h"
47 #include "sync/js/js_test_util.h" 47 #include "sync/js/js_test_util.h"
48 #include "sync/notifier/fake_invalidation_handler.h" 48 #include "sync/notifier/fake_invalidation_handler.h"
49 #include "sync/notifier/fake_invalidator.h"
50 #include "sync/notifier/invalidation_handler.h" 49 #include "sync/notifier/invalidation_handler.h"
51 #include "sync/notifier/invalidator.h" 50 #include "sync/notifier/invalidator.h"
52 #include "sync/protocol/bookmark_specifics.pb.h" 51 #include "sync/protocol/bookmark_specifics.pb.h"
53 #include "sync/protocol/encryption.pb.h" 52 #include "sync/protocol/encryption.pb.h"
54 #include "sync/protocol/extension_specifics.pb.h" 53 #include "sync/protocol/extension_specifics.pb.h"
55 #include "sync/protocol/password_specifics.pb.h" 54 #include "sync/protocol/password_specifics.pb.h"
56 #include "sync/protocol/preference_specifics.pb.h" 55 #include "sync/protocol/preference_specifics.pb.h"
57 #include "sync/protocol/proto_value_conversions.h" 56 #include "sync/protocol/proto_value_conversions.h"
58 #include "sync/protocol/sync.pb.h" 57 #include "sync/protocol/sync.pb.h"
59 #include "sync/sessions/sync_session.h" 58 #include "sync/sessions/sync_session.h"
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 WRITE_TO_NIGORI 781 WRITE_TO_NIGORI
783 }; 782 };
784 783
785 enum EncryptionStatus { 784 enum EncryptionStatus {
786 UNINITIALIZED, 785 UNINITIALIZED,
787 DEFAULT_ENCRYPTION, 786 DEFAULT_ENCRYPTION,
788 FULL_ENCRYPTION 787 FULL_ENCRYPTION
789 }; 788 };
790 789
791 SyncManagerTest() 790 SyncManagerTest()
792 : fake_invalidator_(NULL), 791 : sync_manager_("Test sync manager") {
793 sync_manager_("Test sync manager") {
794 switches_.encryption_method = 792 switches_.encryption_method =
795 InternalComponentsFactory::ENCRYPTION_KEYSTORE; 793 InternalComponentsFactory::ENCRYPTION_KEYSTORE;
796 } 794 }
797 795
798 virtual ~SyncManagerTest() { 796 virtual ~SyncManagerTest() {
799 EXPECT_FALSE(fake_invalidator_);
800 } 797 }
801 798
802 // Test implementation. 799 // Test implementation.
803 void SetUp() { 800 void SetUp() {
804 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 801 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
805 802
806 SyncCredentials credentials; 803 SyncCredentials credentials;
807 credentials.email = "foo@bar.com"; 804 credentials.email = "foo@bar.com";
808 credentials.sync_token = "sometoken"; 805 credentials.sync_token = "sometoken";
809 806
810 fake_invalidator_ = new FakeInvalidator();
811
812 sync_manager_.AddObserver(&manager_observer_); 807 sync_manager_.AddObserver(&manager_observer_);
813 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)). 808 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)).
814 WillOnce(SaveArg<0>(&js_backend_)); 809 WillOnce(SaveArg<0>(&js_backend_));
815 810
816 EXPECT_FALSE(js_backend_.IsInitialized()); 811 EXPECT_FALSE(js_backend_.IsInitialized());
817 812
818 std::vector<ModelSafeWorker*> workers; 813 std::vector<ModelSafeWorker*> workers;
819 ModelSafeRoutingInfo routing_info; 814 ModelSafeRoutingInfo routing_info;
820 GetModelSafeRoutingInfo(&routing_info); 815 GetModelSafeRoutingInfo(&routing_info);
821 816
822 // Takes ownership of |fake_invalidator_|. 817 // Takes ownership of |fake_invalidator_|.
823 sync_manager_.Init( 818 sync_manager_.Init(
824 temp_dir_.path(), 819 temp_dir_.path(),
825 WeakHandle<JsEventHandler>(), 820 WeakHandle<JsEventHandler>(),
826 "bogus", 821 "bogus",
827 0, 822 0,
828 false, 823 false,
829 scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()), 824 scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()),
830 workers, 825 workers,
831 &extensions_activity_monitor_, 826 &extensions_activity_monitor_,
832 this, 827 this,
833 credentials, 828 credentials,
834 scoped_ptr<Invalidator>(fake_invalidator_),
835 "fake_invalidator_client_id", 829 "fake_invalidator_client_id",
836 std::string(), 830 std::string(),
837 std::string(), // bootstrap tokens 831 std::string(), // bootstrap tokens
838 scoped_ptr<InternalComponentsFactory>(GetFactory()), 832 scoped_ptr<InternalComponentsFactory>(GetFactory()),
839 &encryptor_, 833 &encryptor_,
840 &handler_, 834 &handler_,
841 NULL); 835 NULL);
842 836
843 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); 837 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_);
844 838
845 EXPECT_TRUE(js_backend_.IsInitialized()); 839 EXPECT_TRUE(js_backend_.IsInitialized());
846 840
847 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 841 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
848 i != routing_info.end(); ++i) { 842 i != routing_info.end(); ++i) {
849 type_roots_[i->first] = MakeServerNodeForType( 843 type_roots_[i->first] = MakeServerNodeForType(
850 sync_manager_.GetUserShare(), i->first); 844 sync_manager_.GetUserShare(), i->first);
851 } 845 }
852 PumpLoop(); 846 PumpLoop();
853
854 EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&sync_manager_));
855 } 847 }
856 848
857 void TearDown() { 849 void TearDown() {
858 sync_manager_.RemoveObserver(&manager_observer_); 850 sync_manager_.RemoveObserver(&manager_observer_);
859 sync_manager_.ShutdownOnSyncThread(); 851 sync_manager_.ShutdownOnSyncThread();
860 // We can't assert that |sync_manager_| isn't registered with
861 // |fake_invalidator_| anymore because |fake_invalidator_| is now
862 // destroyed.
863 fake_invalidator_ = NULL;
864 PumpLoop(); 852 PumpLoop();
865 } 853 }
866 854
867 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { 855 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
868 (*out)[NIGORI] = GROUP_PASSIVE; 856 (*out)[NIGORI] = GROUP_PASSIVE;
869 (*out)[DEVICE_INFO] = GROUP_PASSIVE; 857 (*out)[DEVICE_INFO] = GROUP_PASSIVE;
870 (*out)[EXPERIMENTS] = GROUP_PASSIVE; 858 (*out)[EXPERIMENTS] = GROUP_PASSIVE;
871 (*out)[BOOKMARKS] = GROUP_PASSIVE; 859 (*out)[BOOKMARKS] = GROUP_PASSIVE;
872 (*out)[THEMES] = GROUP_PASSIVE; 860 (*out)[THEMES] = GROUP_PASSIVE;
873 (*out)[SESSIONS] = GROUP_PASSIVE; 861 (*out)[SESSIONS] = GROUP_PASSIVE;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 base::MessageLoop message_loop_; 1007 base::MessageLoop message_loop_;
1020 // Needed by |sync_manager_|. 1008 // Needed by |sync_manager_|.
1021 base::ScopedTempDir temp_dir_; 1009 base::ScopedTempDir temp_dir_;
1022 // Sync Id's for the roots of the enabled datatypes. 1010 // Sync Id's for the roots of the enabled datatypes.
1023 std::map<ModelType, int64> type_roots_; 1011 std::map<ModelType, int64> type_roots_;
1024 FakeExtensionsActivityMonitor extensions_activity_monitor_; 1012 FakeExtensionsActivityMonitor extensions_activity_monitor_;
1025 1013
1026 protected: 1014 protected:
1027 FakeEncryptor encryptor_; 1015 FakeEncryptor encryptor_;
1028 TestUnrecoverableErrorHandler handler_; 1016 TestUnrecoverableErrorHandler handler_;
1029 FakeInvalidator* fake_invalidator_;
1030 SyncManagerImpl sync_manager_; 1017 SyncManagerImpl sync_manager_;
1031 WeakHandle<JsBackend> js_backend_; 1018 WeakHandle<JsBackend> js_backend_;
1032 StrictMock<SyncManagerObserverMock> manager_observer_; 1019 StrictMock<SyncManagerObserverMock> manager_observer_;
1033 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; 1020 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_;
1034 InternalComponentsFactory::Switches switches_; 1021 InternalComponentsFactory::Switches switches_;
1035 }; 1022 };
1036 1023
1037 TEST_F(SyncManagerTest, UpdateEnabledTypes) {
1038 ModelSafeRoutingInfo routes;
1039 GetModelSafeRoutingInfo(&routes);
1040 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes);
1041 sync_manager_.UpdateEnabledTypes(enabled_types);
1042 EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types),
1043 fake_invalidator_->GetRegisteredIds(&sync_manager_));
1044 }
1045
1046 TEST_F(SyncManagerTest, RegisterInvalidationHandler) {
1047 FakeInvalidationHandler fake_handler;
1048 sync_manager_.RegisterInvalidationHandler(&fake_handler);
1049 EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&fake_handler));
1050
1051 const ObjectIdSet& ids =
1052 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES));
1053 sync_manager_.UpdateRegisteredInvalidationIds(&fake_handler, ids);
1054 EXPECT_EQ(ids, fake_invalidator_->GetRegisteredIds(&fake_handler));
1055
1056 sync_manager_.UnregisterInvalidationHandler(&fake_handler);
1057 EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler));
1058 }
1059
1060 TEST_F(SyncManagerTest, ProcessJsMessage) { 1024 TEST_F(SyncManagerTest, ProcessJsMessage) {
1061 const JsArgList kNoArgs; 1025 const JsArgList kNoArgs;
1062 1026
1063 StrictMock<MockJsReplyHandler> reply_handler; 1027 StrictMock<MockJsReplyHandler> reply_handler;
1064 1028
1065 base::ListValue disabled_args; 1029 base::ListValue disabled_args;
1066 disabled_args.Append(new base::StringValue("TRANSIENT_INVALIDATION_ERROR")); 1030 disabled_args.Append(new base::StringValue("TRANSIENT_INVALIDATION_ERROR"));
1067 1031
1068 EXPECT_CALL(reply_handler, 1032 EXPECT_CALL(reply_handler,
1069 HandleJsReply("getNotificationState", 1033 HandleJsReply("getNotificationState",
(...skipping 2349 matching lines...) Expand 10 before | Expand all | Expand 10 after
3419 size_t folder_b_pos = 3383 size_t folder_b_pos =
3420 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); 3384 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE);
3421 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); 3385 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE);
3422 3386
3423 // Deletes should appear before updates. 3387 // Deletes should appear before updates.
3424 EXPECT_LT(child_pos, folder_a_pos); 3388 EXPECT_LT(child_pos, folder_a_pos);
3425 EXPECT_LT(folder_b_pos, folder_a_pos); 3389 EXPECT_LT(folder_b_pos, folder_a_pos);
3426 } 3390 }
3427 3391
3428 } // namespace 3392 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698