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 26 matching lines...) Expand all Loading... |
37 #include "sync/internal_api/public/write_node.h" | 37 #include "sync/internal_api/public/write_node.h" |
38 #include "sync/internal_api/public/write_transaction.h" | 38 #include "sync/internal_api/public/write_transaction.h" |
39 #include "sync/internal_api/sync_encryption_handler_impl.h" | 39 #include "sync/internal_api/sync_encryption_handler_impl.h" |
40 #include "sync/internal_api/sync_manager_impl.h" | 40 #include "sync/internal_api/sync_manager_impl.h" |
41 #include "sync/internal_api/syncapi_internal.h" | 41 #include "sync/internal_api/syncapi_internal.h" |
42 #include "sync/js/js_arg_list.h" | 42 #include "sync/js/js_arg_list.h" |
43 #include "sync/js/js_backend.h" | 43 #include "sync/js/js_backend.h" |
44 #include "sync/js/js_event_handler.h" | 44 #include "sync/js/js_event_handler.h" |
45 #include "sync/js/js_reply_handler.h" | 45 #include "sync/js/js_reply_handler.h" |
46 #include "sync/js/js_test_util.h" | 46 #include "sync/js/js_test_util.h" |
47 #include "sync/notifier/fake_sync_notifier.h" | 47 #include "sync/notifier/fake_invalidation_handler.h" |
48 #include "sync/notifier/fake_sync_notifier_observer.h" | 48 #include "sync/notifier/fake_invalidator.h" |
49 #include "sync/notifier/sync_notifier.h" | 49 #include "sync/notifier/invalidation_handler.h" |
50 #include "sync/notifier/sync_notifier_observer.h" | 50 #include "sync/notifier/invalidator.h" |
51 #include "sync/protocol/bookmark_specifics.pb.h" | 51 #include "sync/protocol/bookmark_specifics.pb.h" |
52 #include "sync/protocol/encryption.pb.h" | 52 #include "sync/protocol/encryption.pb.h" |
53 #include "sync/protocol/extension_specifics.pb.h" | 53 #include "sync/protocol/extension_specifics.pb.h" |
54 #include "sync/protocol/password_specifics.pb.h" | 54 #include "sync/protocol/password_specifics.pb.h" |
55 #include "sync/protocol/preference_specifics.pb.h" | 55 #include "sync/protocol/preference_specifics.pb.h" |
56 #include "sync/protocol/proto_value_conversions.h" | 56 #include "sync/protocol/proto_value_conversions.h" |
57 #include "sync/protocol/sync.pb.h" | 57 #include "sync/protocol/sync.pb.h" |
58 #include "sync/sessions/sync_session.h" | 58 #include "sync/sessions/sync_session.h" |
59 #include "sync/syncable/directory.h" | 59 #include "sync/syncable/directory.h" |
60 #include "sync/syncable/entry.h" | 60 #include "sync/syncable/entry.h" |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 WRITE_TO_NIGORI | 711 WRITE_TO_NIGORI |
712 }; | 712 }; |
713 | 713 |
714 enum EncryptionStatus { | 714 enum EncryptionStatus { |
715 UNINITIALIZED, | 715 UNINITIALIZED, |
716 DEFAULT_ENCRYPTION, | 716 DEFAULT_ENCRYPTION, |
717 FULL_ENCRYPTION | 717 FULL_ENCRYPTION |
718 }; | 718 }; |
719 | 719 |
720 SyncManagerTest() | 720 SyncManagerTest() |
721 : fake_notifier_(NULL), | 721 : fake_invalidator_(NULL), |
722 sync_manager_("Test sync manager") { | 722 sync_manager_("Test sync manager") { |
723 switches_.encryption_method = | 723 switches_.encryption_method = |
724 InternalComponentsFactory::ENCRYPTION_KEYSTORE; | 724 InternalComponentsFactory::ENCRYPTION_KEYSTORE; |
725 } | 725 } |
726 | 726 |
727 virtual ~SyncManagerTest() { | 727 virtual ~SyncManagerTest() { |
728 EXPECT_FALSE(fake_notifier_); | 728 EXPECT_FALSE(fake_invalidator_); |
729 } | 729 } |
730 | 730 |
731 // Test implementation. | 731 // Test implementation. |
732 void SetUp() { | 732 void SetUp() { |
733 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 733 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
734 | 734 |
735 SyncCredentials credentials; | 735 SyncCredentials credentials; |
736 credentials.email = "foo@bar.com"; | 736 credentials.email = "foo@bar.com"; |
737 credentials.sync_token = "sometoken"; | 737 credentials.sync_token = "sometoken"; |
738 | 738 |
739 fake_notifier_ = new FakeSyncNotifier(); | 739 fake_invalidator_ = new FakeInvalidator(); |
740 | 740 |
741 sync_manager_.AddObserver(&manager_observer_); | 741 sync_manager_.AddObserver(&manager_observer_); |
742 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _)). | 742 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _)). |
743 WillOnce(SaveArg<0>(&js_backend_)); | 743 WillOnce(SaveArg<0>(&js_backend_)); |
744 | 744 |
745 EXPECT_FALSE(js_backend_.IsInitialized()); | 745 EXPECT_FALSE(js_backend_.IsInitialized()); |
746 | 746 |
747 std::vector<ModelSafeWorker*> workers; | 747 std::vector<ModelSafeWorker*> workers; |
748 ModelSafeRoutingInfo routing_info; | 748 ModelSafeRoutingInfo routing_info; |
749 GetModelSafeRoutingInfo(&routing_info); | 749 GetModelSafeRoutingInfo(&routing_info); |
750 | 750 |
751 // Takes ownership of |fake_notifier_|. | 751 // Takes ownership of |fake_invalidator_|. |
752 sync_manager_.Init(temp_dir_.path(), | 752 sync_manager_.Init(temp_dir_.path(), |
753 WeakHandle<JsEventHandler>(), | 753 WeakHandle<JsEventHandler>(), |
754 "bogus", 0, false, | 754 "bogus", 0, false, |
755 base::MessageLoopProxy::current(), | 755 base::MessageLoopProxy::current(), |
756 scoped_ptr<HttpPostProviderFactory>( | 756 scoped_ptr<HttpPostProviderFactory>( |
757 new TestHttpPostProviderFactory()), | 757 new TestHttpPostProviderFactory()), |
758 workers, &extensions_activity_monitor_, this, | 758 workers, &extensions_activity_monitor_, this, |
759 credentials, | 759 credentials, |
760 scoped_ptr<SyncNotifier>(fake_notifier_), | 760 scoped_ptr<Invalidator>(fake_invalidator_), |
761 "", "", // bootstrap tokens | 761 "", "", // bootstrap tokens |
762 scoped_ptr<InternalComponentsFactory>(GetFactory()), | 762 scoped_ptr<InternalComponentsFactory>(GetFactory()), |
763 &encryptor_, | 763 &encryptor_, |
764 &handler_, | 764 &handler_, |
765 NULL); | 765 NULL); |
766 | 766 |
767 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); | 767 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
768 | 768 |
769 EXPECT_TRUE(js_backend_.IsInitialized()); | 769 EXPECT_TRUE(js_backend_.IsInitialized()); |
770 | 770 |
771 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 771 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
772 i != routing_info.end(); ++i) { | 772 i != routing_info.end(); ++i) { |
773 type_roots_[i->first] = MakeServerNodeForType( | 773 type_roots_[i->first] = MakeServerNodeForType( |
774 sync_manager_.GetUserShare(), i->first); | 774 sync_manager_.GetUserShare(), i->first); |
775 } | 775 } |
776 PumpLoop(); | 776 PumpLoop(); |
777 | 777 |
778 EXPECT_TRUE(fake_notifier_->IsHandlerRegistered(&sync_manager_)); | 778 EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&sync_manager_)); |
779 } | 779 } |
780 | 780 |
781 void TearDown() { | 781 void TearDown() { |
782 sync_manager_.RemoveObserver(&manager_observer_); | 782 sync_manager_.RemoveObserver(&manager_observer_); |
783 sync_manager_.ShutdownOnSyncThread(); | 783 sync_manager_.ShutdownOnSyncThread(); |
784 // We can't assert that |sync_manager_| isn't registered with | 784 // We can't assert that |sync_manager_| isn't registered with |
785 // |fake_notifier_| anymore because |fake_notifier_| is now | 785 // |fake_invalidator_| anymore because |fake_invalidator_| is now |
786 // destroyed. | 786 // destroyed. |
787 fake_notifier_ = NULL; | 787 fake_invalidator_ = NULL; |
788 PumpLoop(); | 788 PumpLoop(); |
789 } | 789 } |
790 | 790 |
791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
792 (*out)[NIGORI] = GROUP_PASSIVE; | 792 (*out)[NIGORI] = GROUP_PASSIVE; |
793 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 793 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
794 (*out)[THEMES] = GROUP_PASSIVE; | 794 (*out)[THEMES] = GROUP_PASSIVE; |
795 (*out)[SESSIONS] = GROUP_PASSIVE; | 795 (*out)[SESSIONS] = GROUP_PASSIVE; |
796 (*out)[PASSWORDS] = GROUP_PASSIVE; | 796 (*out)[PASSWORDS] = GROUP_PASSIVE; |
797 (*out)[PREFERENCES] = GROUP_PASSIVE; | 797 (*out)[PREFERENCES] = GROUP_PASSIVE; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 MessageLoop message_loop_; | 950 MessageLoop message_loop_; |
951 // Needed by |sync_manager_|. | 951 // Needed by |sync_manager_|. |
952 ScopedTempDir temp_dir_; | 952 ScopedTempDir temp_dir_; |
953 // Sync Id's for the roots of the enabled datatypes. | 953 // Sync Id's for the roots of the enabled datatypes. |
954 std::map<ModelType, int64> type_roots_; | 954 std::map<ModelType, int64> type_roots_; |
955 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 955 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
956 | 956 |
957 protected: | 957 protected: |
958 FakeEncryptor encryptor_; | 958 FakeEncryptor encryptor_; |
959 TestUnrecoverableErrorHandler handler_; | 959 TestUnrecoverableErrorHandler handler_; |
960 FakeSyncNotifier* fake_notifier_; | 960 FakeInvalidator* fake_invalidator_; |
961 SyncManagerImpl sync_manager_; | 961 SyncManagerImpl sync_manager_; |
962 WeakHandle<JsBackend> js_backend_; | 962 WeakHandle<JsBackend> js_backend_; |
963 StrictMock<SyncManagerObserverMock> manager_observer_; | 963 StrictMock<SyncManagerObserverMock> manager_observer_; |
964 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; | 964 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; |
965 InternalComponentsFactory::Switches switches_; | 965 InternalComponentsFactory::Switches switches_; |
966 }; | 966 }; |
967 | 967 |
968 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 968 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
969 ModelSafeRoutingInfo routes; | 969 ModelSafeRoutingInfo routes; |
970 GetModelSafeRoutingInfo(&routes); | 970 GetModelSafeRoutingInfo(&routes); |
971 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | 971 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); |
972 sync_manager_.UpdateEnabledTypes(enabled_types); | 972 sync_manager_.UpdateEnabledTypes(enabled_types); |
973 EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types), | 973 EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types), |
974 fake_notifier_->GetRegisteredIds(&sync_manager_)); | 974 fake_invalidator_->GetRegisteredIds(&sync_manager_)); |
975 } | 975 } |
976 | 976 |
977 TEST_F(SyncManagerTest, RegisterInvalidationHandler) { | 977 TEST_F(SyncManagerTest, RegisterInvalidationHandler) { |
978 FakeSyncNotifierObserver fake_observer; | 978 FakeInvalidationHandler fake_handler; |
979 sync_manager_.RegisterInvalidationHandler(&fake_observer); | 979 sync_manager_.RegisterInvalidationHandler(&fake_handler); |
980 EXPECT_TRUE(fake_notifier_->IsHandlerRegistered(&fake_observer)); | 980 EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); |
981 | 981 |
982 const ObjectIdSet& ids = | 982 const ObjectIdSet& ids = |
983 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES)); | 983 ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES)); |
984 sync_manager_.UpdateRegisteredInvalidationIds(&fake_observer, ids); | 984 sync_manager_.UpdateRegisteredInvalidationIds(&fake_handler, ids); |
985 EXPECT_EQ(ids, fake_notifier_->GetRegisteredIds(&fake_observer)); | 985 EXPECT_EQ(ids, fake_invalidator_->GetRegisteredIds(&fake_handler)); |
986 | 986 |
987 sync_manager_.UnregisterInvalidationHandler(&fake_observer); | 987 sync_manager_.UnregisterInvalidationHandler(&fake_handler); |
988 EXPECT_FALSE(fake_notifier_->IsHandlerRegistered(&fake_observer)); | 988 EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); |
989 } | 989 } |
990 | 990 |
991 TEST_F(SyncManagerTest, ProcessJsMessage) { | 991 TEST_F(SyncManagerTest, ProcessJsMessage) { |
992 const JsArgList kNoArgs; | 992 const JsArgList kNoArgs; |
993 | 993 |
994 StrictMock<MockJsReplyHandler> reply_handler; | 994 StrictMock<MockJsReplyHandler> reply_handler; |
995 | 995 |
996 ListValue disabled_args; | 996 ListValue disabled_args; |
997 disabled_args.Append( | 997 disabled_args.Append( |
998 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); | 998 Value::CreateStringValue("TRANSIENT_NOTIFICATION_ERROR")); |
(...skipping 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2872 | 2872 |
2873 // Verify only the non-disabled types remain after cleanup. | 2873 // Verify only the non-disabled types remain after cleanup. |
2874 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2874 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
2875 EXPECT_TRUE(new_enabled_types.Equals( | 2875 EXPECT_TRUE(new_enabled_types.Equals( |
2876 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2876 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
2877 EXPECT_TRUE(disabled_types.Equals( | 2877 EXPECT_TRUE(disabled_types.Equals( |
2878 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2878 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
2879 } | 2879 } |
2880 | 2880 |
2881 } // namespace | 2881 } // namespace |
OLD | NEW |