| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 false); | 836 false); |
| 843 | 837 |
| 844 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); | 838 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
| 845 | 839 |
| 846 EXPECT_TRUE(js_backend_.IsInitialized()); | 840 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 847 | 841 |
| 848 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 842 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 849 i != routing_info.end(); ++i) { | 843 i != routing_info.end(); ++i) { |
| 850 type_roots_[i->first] = MakeServerNodeForType( | 844 type_roots_[i->first] = MakeServerNodeForType( |
| 851 sync_manager_.GetUserShare(), i->first); | 845 sync_manager_.GetUserShare(), i->first); |
| 852 } | 846 } |
| 853 PumpLoop(); | 847 PumpLoop(); |
| 854 | |
| 855 EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&sync_manager_)); | |
| 856 } | 848 } |
| 857 | 849 |
| 858 void TearDown() { | 850 void TearDown() { |
| 859 sync_manager_.RemoveObserver(&manager_observer_); | 851 sync_manager_.RemoveObserver(&manager_observer_); |
| 860 sync_manager_.ShutdownOnSyncThread(); | 852 sync_manager_.ShutdownOnSyncThread(); |
| 861 // We can't assert that |sync_manager_| isn't registered with | |
| 862 // |fake_invalidator_| anymore because |fake_invalidator_| is now | |
| 863 // destroyed. | |
| 864 fake_invalidator_ = NULL; | |
| 865 PumpLoop(); | 853 PumpLoop(); |
| 866 } | 854 } |
| 867 | 855 |
| 868 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 856 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 869 (*out)[NIGORI] = GROUP_PASSIVE; | 857 (*out)[NIGORI] = GROUP_PASSIVE; |
| 870 (*out)[DEVICE_INFO] = GROUP_PASSIVE; | 858 (*out)[DEVICE_INFO] = GROUP_PASSIVE; |
| 871 (*out)[EXPERIMENTS] = GROUP_PASSIVE; | 859 (*out)[EXPERIMENTS] = GROUP_PASSIVE; |
| 872 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 860 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
| 873 (*out)[THEMES] = GROUP_PASSIVE; | 861 (*out)[THEMES] = GROUP_PASSIVE; |
| 874 (*out)[SESSIONS] = GROUP_PASSIVE; | 862 (*out)[SESSIONS] = GROUP_PASSIVE; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 base::MessageLoop message_loop_; | 1008 base::MessageLoop message_loop_; |
| 1021 // Needed by |sync_manager_|. | 1009 // Needed by |sync_manager_|. |
| 1022 base::ScopedTempDir temp_dir_; | 1010 base::ScopedTempDir temp_dir_; |
| 1023 // Sync Id's for the roots of the enabled datatypes. | 1011 // Sync Id's for the roots of the enabled datatypes. |
| 1024 std::map<ModelType, int64> type_roots_; | 1012 std::map<ModelType, int64> type_roots_; |
| 1025 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 1013 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 1026 | 1014 |
| 1027 protected: | 1015 protected: |
| 1028 FakeEncryptor encryptor_; | 1016 FakeEncryptor encryptor_; |
| 1029 TestUnrecoverableErrorHandler handler_; | 1017 TestUnrecoverableErrorHandler handler_; |
| 1030 FakeInvalidator* fake_invalidator_; | |
| 1031 SyncManagerImpl sync_manager_; | 1018 SyncManagerImpl sync_manager_; |
| 1032 WeakHandle<JsBackend> js_backend_; | 1019 WeakHandle<JsBackend> js_backend_; |
| 1033 StrictMock<SyncManagerObserverMock> manager_observer_; | 1020 StrictMock<SyncManagerObserverMock> manager_observer_; |
| 1034 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; | 1021 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; |
| 1035 InternalComponentsFactory::Switches switches_; | 1022 InternalComponentsFactory::Switches switches_; |
| 1036 }; | 1023 }; |
| 1037 | 1024 |
| 1038 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | |
| 1039 ModelSafeRoutingInfo routes; | |
| 1040 GetModelSafeRoutingInfo(&routes); | |
| 1041 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | |
| 1042 sync_manager_.UpdateEnabledTypes(enabled_types); | |
| 1043 EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types), | |
| 1044 fake_invalidator_->GetRegisteredIds(&sync_manager_)); | |
| 1045 } | |
| 1046 | |
| 1047 TEST_F(SyncManagerTest, RegisterInvalidationHandler) { | |
| 1048 FakeInvalidationHandler fake_handler; | |
| 1049 sync_manager_.RegisterInvalidationHandler(&fake_handler); | |
| 1050 EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); | |
| 1051 | |
| 1052 const ObjectIdSet& ids = | |
| 1053 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES)); | |
| 1054 sync_manager_.UpdateRegisteredInvalidationIds(&fake_handler, ids); | |
| 1055 EXPECT_EQ(ids, fake_invalidator_->GetRegisteredIds(&fake_handler)); | |
| 1056 | |
| 1057 sync_manager_.UnregisterInvalidationHandler(&fake_handler); | |
| 1058 EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); | |
| 1059 } | |
| 1060 | |
| 1061 TEST_F(SyncManagerTest, ProcessJsMessage) { | 1025 TEST_F(SyncManagerTest, ProcessJsMessage) { |
| 1062 const JsArgList kNoArgs; | 1026 const JsArgList kNoArgs; |
| 1063 | 1027 |
| 1064 StrictMock<MockJsReplyHandler> reply_handler; | 1028 StrictMock<MockJsReplyHandler> reply_handler; |
| 1065 | 1029 |
| 1066 base::ListValue disabled_args; | 1030 base::ListValue disabled_args; |
| 1067 disabled_args.Append(new base::StringValue("TRANSIENT_INVALIDATION_ERROR")); | 1031 disabled_args.Append(new base::StringValue("TRANSIENT_INVALIDATION_ERROR")); |
| 1068 | 1032 |
| 1069 EXPECT_CALL(reply_handler, | 1033 EXPECT_CALL(reply_handler, |
| 1070 HandleJsReply("getNotificationState", | 1034 HandleJsReply("getNotificationState", |
| (...skipping 2505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3576 size_t folder_b_pos = | 3540 size_t folder_b_pos = |
| 3577 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); | 3541 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); |
| 3578 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); | 3542 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); |
| 3579 | 3543 |
| 3580 // Deletes should appear before updates. | 3544 // Deletes should appear before updates. |
| 3581 EXPECT_LT(child_pos, folder_a_pos); | 3545 EXPECT_LT(child_pos, folder_a_pos); |
| 3582 EXPECT_LT(folder_b_pos, folder_a_pos); | 3546 EXPECT_LT(folder_b_pos, folder_a_pos); |
| 3583 } | 3547 } |
| 3584 | 3548 |
| 3585 } // namespace | 3549 } // namespace |
| OLD | NEW |