| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/message_loop_proxy.h" | 19 #include "base/message_loop_proxy.h" |
| 20 #include "base/scoped_temp_dir.h" | 20 #include "base/scoped_temp_dir.h" |
| 21 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/test/values_test_util.h" | 23 #include "base/test/values_test_util.h" |
| 24 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
| 25 #include "base/values.h" | 25 #include "base/values.h" |
| 26 #include "sync/engine/sync_scheduler.h" |
| 26 #include "sync/internal_api/public/base/model_type_test_util.h" | 27 #include "sync/internal_api/public/base/model_type_test_util.h" |
| 27 #include "sync/engine/sync_scheduler.h" | |
| 28 #include "sync/internal_api/public/change_record.h" | 28 #include "sync/internal_api/public/change_record.h" |
| 29 #include "sync/internal_api/public/engine/model_safe_worker.h" | 29 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 30 #include "sync/internal_api/public/engine/polling_constants.h" | 30 #include "sync/internal_api/public/engine/polling_constants.h" |
| 31 #include "sync/internal_api/public/http_post_provider_factory.h" | 31 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 32 #include "sync/internal_api/public/http_post_provider_interface.h" | 32 #include "sync/internal_api/public/http_post_provider_interface.h" |
| 33 #include "sync/internal_api/public/read_node.h" | 33 #include "sync/internal_api/public/read_node.h" |
| 34 #include "sync/internal_api/public/read_transaction.h" | 34 #include "sync/internal_api/public/read_transaction.h" |
| 35 #include "sync/internal_api/public/test/test_internal_components_factory.h" | 35 #include "sync/internal_api/public/test/test_internal_components_factory.h" |
| 36 #include "sync/internal_api/public/test/test_user_share.h" | 36 #include "sync/internal_api/public/test/test_user_share.h" |
| 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_manager_impl.h" |
| 39 #include "sync/internal_api/syncapi_internal.h" | 40 #include "sync/internal_api/syncapi_internal.h" |
| 40 #include "sync/internal_api/sync_manager_impl.h" | |
| 41 #include "sync/js/js_arg_list.h" | 41 #include "sync/js/js_arg_list.h" |
| 42 #include "sync/js/js_backend.h" | 42 #include "sync/js/js_backend.h" |
| 43 #include "sync/js/js_event_handler.h" | 43 #include "sync/js/js_event_handler.h" |
| 44 #include "sync/js/js_reply_handler.h" | 44 #include "sync/js/js_reply_handler.h" |
| 45 #include "sync/js/js_test_util.h" | 45 #include "sync/js/js_test_util.h" |
| 46 #include "sync/notifier/sync_notifier.h" | 46 #include "sync/notifier/sync_notifier.h" |
| 47 #include "sync/notifier/sync_notifier_observer.h" | 47 #include "sync/notifier/sync_notifier_observer.h" |
| 48 #include "sync/protocol/bookmark_specifics.pb.h" | 48 #include "sync/protocol/bookmark_specifics.pb.h" |
| 49 #include "sync/protocol/encryption.pb.h" | 49 #include "sync/protocol/encryption.pb.h" |
| 50 #include "sync/protocol/extension_specifics.pb.h" | 50 #include "sync/protocol/extension_specifics.pb.h" |
| 51 #include "sync/protocol/password_specifics.pb.h" | 51 #include "sync/protocol/password_specifics.pb.h" |
| 52 #include "sync/protocol/preference_specifics.pb.h" | 52 #include "sync/protocol/preference_specifics.pb.h" |
| 53 #include "sync/protocol/proto_value_conversions.h" | 53 #include "sync/protocol/proto_value_conversions.h" |
| 54 #include "sync/protocol/sync.pb.h" | 54 #include "sync/protocol/sync.pb.h" |
| 55 #include "sync/sessions/sync_session.h" | 55 #include "sync/sessions/sync_session.h" |
| 56 #include "sync/syncable/directory.h" | 56 #include "sync/syncable/directory.h" |
| 57 #include "sync/syncable/entry.h" | 57 #include "sync/syncable/entry.h" |
| 58 #include "sync/syncable/mutable_entry.h" | 58 #include "sync/syncable/mutable_entry.h" |
| 59 #include "sync/syncable/nigori_util.h" | 59 #include "sync/syncable/nigori_util.h" |
| 60 #include "sync/syncable/syncable_id.h" | 60 #include "sync/syncable/syncable_id.h" |
| 61 #include "sync/syncable/write_transaction.h" | 61 #include "sync/syncable/write_transaction.h" |
| 62 #include "sync/test/callback_counter.h" | 62 #include "sync/test/callback_counter.h" |
| 63 #include "sync/test/engine/fake_sync_scheduler.h" |
| 63 #include "sync/test/fake_encryptor.h" | 64 #include "sync/test/fake_encryptor.h" |
| 64 #include "sync/test/fake_extensions_activity_monitor.h" | 65 #include "sync/test/fake_extensions_activity_monitor.h" |
| 65 #include "sync/test/engine/fake_sync_scheduler.h" | |
| 66 #include "sync/util/cryptographer.h" | 66 #include "sync/util/cryptographer.h" |
| 67 #include "sync/util/extensions_activity_monitor.h" | 67 #include "sync/util/extensions_activity_monitor.h" |
| 68 #include "sync/util/test_unrecoverable_error_handler.h" | 68 #include "sync/util/test_unrecoverable_error_handler.h" |
| 69 #include "sync/util/time.h" | 69 #include "sync/util/time.h" |
| 70 #include "testing/gmock/include/gmock/gmock.h" | 70 #include "testing/gmock/include/gmock/gmock.h" |
| 71 #include "testing/gtest/include/gtest/gtest.h" | 71 #include "testing/gtest/include/gtest/gtest.h" |
| 72 | 72 |
| 73 using base::ExpectDictStringValue; | 73 using base::ExpectDictStringValue; |
| 74 using testing::_; | 74 using testing::_; |
| 75 using testing::AnyNumber; | 75 using testing::AnyNumber; |
| (...skipping 613 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_METHOD2(UpdateRegisteredIds, void(SyncNotifierObserver*, | 699 MOCK_METHOD2(UpdateRegisteredIds, |
| 700 const ObjectIdSet&)); | 700 void(SyncNotifierObserver*, const ObjectIdSet&)); |
| 701 MOCK_METHOD1(SetUniqueId, void(const std::string&)); | 701 MOCK_METHOD1(SetUniqueId, void(const std::string&)); |
| 702 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); | 702 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); |
| 703 MOCK_METHOD2(UpdateCredentials, | 703 MOCK_METHOD2(UpdateCredentials, |
| 704 void(const std::string&, const std::string&)); | 704 void(const std::string&, const std::string&)); |
| 705 MOCK_METHOD1(SendNotification, void(ModelTypeSet)); | 705 MOCK_METHOD1(SendNotification, void(ModelTypeSet)); |
| 706 }; | 706 }; |
| 707 | 707 |
| 708 } // namespace | 708 } // namespace |
| 709 | 709 |
| 710 class SyncManagerTest : public testing::Test, | 710 class SyncManagerTest : public testing::Test, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 775 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 776 i != routing_info.end(); ++i) { | 776 i != routing_info.end(); ++i) { |
| 777 type_roots_[i->first] = MakeServerNodeForType( | 777 type_roots_[i->first] = MakeServerNodeForType( |
| 778 sync_manager_.GetUserShare(), i->first); | 778 sync_manager_.GetUserShare(), i->first); |
| 779 } | 779 } |
| 780 PumpLoop(); | 780 PumpLoop(); |
| 781 } | 781 } |
| 782 | 782 |
| 783 void TearDown() { | 783 void TearDown() { |
| 784 sync_manager_.RemoveObserver(&observer_); | 784 sync_manager_.RemoveObserver(&observer_); |
| 785 EXPECT_CALL(*sync_notifier_mock_, | 785 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(_, ObjectIdSet())); |
| 786 UpdateRegisteredIds(_, ObjectIdSet())); | |
| 787 sync_manager_.ShutdownOnSyncThread(); | 786 sync_manager_.ShutdownOnSyncThread(); |
| 788 sync_notifier_mock_ = NULL; | 787 sync_notifier_mock_ = NULL; |
| 789 PumpLoop(); | 788 PumpLoop(); |
| 790 } | 789 } |
| 791 | 790 |
| 792 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 793 (*out)[NIGORI] = GROUP_PASSIVE; | 792 (*out)[NIGORI] = GROUP_PASSIVE; |
| 794 (*out)[BOOKMARKS] = GROUP_PASSIVE; | 793 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
| 795 (*out)[THEMES] = GROUP_PASSIVE; | 794 (*out)[THEMES] = GROUP_PASSIVE; |
| 796 (*out)[SESSIONS] = GROUP_PASSIVE; | 795 (*out)[SESSIONS] = GROUP_PASSIVE; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 WeakHandle<JsBackend> js_backend_; | 951 WeakHandle<JsBackend> js_backend_; |
| 953 StrictMock<SyncManagerObserverMock> observer_; | 952 StrictMock<SyncManagerObserverMock> observer_; |
| 954 }; | 953 }; |
| 955 | 954 |
| 956 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 955 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
| 957 ModelSafeRoutingInfo routes; | 956 ModelSafeRoutingInfo routes; |
| 958 GetModelSafeRoutingInfo(&routes); | 957 GetModelSafeRoutingInfo(&routes); |
| 959 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | 958 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); |
| 960 | 959 |
| 961 EXPECT_CALL(*sync_notifier_mock_, | 960 EXPECT_CALL(*sync_notifier_mock_, |
| 962 UpdateRegisteredIds(_, ModelTypeSetToObjectIdSet(enabled_types))); | 961 UpdateRegisteredIds( |
| 962 _, ModelTypeSetToObjectIdSet(enabled_types))); |
| 963 sync_manager_.UpdateEnabledTypes(enabled_types); | 963 sync_manager_.UpdateEnabledTypes(enabled_types); |
| 964 } | 964 } |
| 965 | 965 |
| 966 TEST_F(SyncManagerTest, UpdateRegisteredInvalidationIds) { |
| 967 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(NULL, ObjectIdSet())); |
| 968 sync_manager_.UpdateRegisteredInvalidationIds(NULL, ObjectIdSet()); |
| 969 } |
| 970 |
| 966 TEST_F(SyncManagerTest, ProcessJsMessage) { | 971 TEST_F(SyncManagerTest, ProcessJsMessage) { |
| 967 const JsArgList kNoArgs; | 972 const JsArgList kNoArgs; |
| 968 | 973 |
| 969 StrictMock<MockJsReplyHandler> reply_handler; | 974 StrictMock<MockJsReplyHandler> reply_handler; |
| 970 | 975 |
| 971 ListValue false_args; | 976 ListValue false_args; |
| 972 false_args.Append(Value::CreateBooleanValue(false)); | 977 false_args.Append(Value::CreateBooleanValue(false)); |
| 973 | 978 |
| 974 EXPECT_CALL(reply_handler, | 979 EXPECT_CALL(reply_handler, |
| 975 HandleJsReply("getNotificationState", | 980 HandleJsReply("getNotificationState", |
| (...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2777 | 2782 |
| 2778 // Verify only the non-disabled types remain after cleanup. | 2783 // Verify only the non-disabled types remain after cleanup. |
| 2779 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2784 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
| 2780 EXPECT_TRUE(new_enabled_types.Equals( | 2785 EXPECT_TRUE(new_enabled_types.Equals( |
| 2781 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2786 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
| 2782 EXPECT_TRUE(disabled_types.Equals( | 2787 EXPECT_TRUE(disabled_types.Equals( |
| 2783 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2788 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
| 2784 } | 2789 } |
| 2785 | 2790 |
| 2786 } // namespace | 2791 } // namespace |
| OLD | NEW |