| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "components/sync/user_events/user_event_service_impl.h" | 5 #include "components/sync/user_events/user_event_service_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/test/scoped_feature_list.h" | 9 #include "base/test/scoped_feature_list.h" |
| 10 #include "components/sync/base/model_type.h" | 10 #include "components/sync/base/model_type.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 ModelTypeSet GetPreferredDataTypes() const override { | 33 ModelTypeSet GetPreferredDataTypes() const override { |
| 34 return preferred_data_types_; | 34 return preferred_data_types_; |
| 35 } | 35 } |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 bool is_engine_initialized_; | 38 bool is_engine_initialized_; |
| 39 ModelTypeSet preferred_data_types_; | 39 ModelTypeSet preferred_data_types_; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class TestGlobalIdMapper : public GlobalIdMapper { |
| 43 void AddGlobalIdChangeObserver(GlobalIdChange callback) override {} |
| 44 int64_t GetLatestGlobalId(int64_t global_id) override { return global_id; } |
| 45 }; |
| 46 |
| 42 class UserEventServiceImplTest : public testing::Test { | 47 class UserEventServiceImplTest : public testing::Test { |
| 43 protected: | 48 protected: |
| 44 UserEventServiceImplTest() { | 49 UserEventServiceImplTest() { |
| 45 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); | 50 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); |
| 46 scoped_feature_list_->InitAndEnableFeature(switches::kSyncUserEvents); | 51 scoped_feature_list_->InitAndEnableFeature(switches::kSyncUserEvents); |
| 47 } | 52 } |
| 48 | 53 |
| 49 std::unique_ptr<UserEventSyncBridge> MakeBridge() { | 54 std::unique_ptr<UserEventSyncBridge> MakeBridge() { |
| 50 return base::MakeUnique<UserEventSyncBridge>( | 55 return base::MakeUnique<UserEventSyncBridge>( |
| 51 ModelTypeStoreTestUtil::FactoryForInMemoryStoreForTest(), | 56 ModelTypeStoreTestUtil::FactoryForInMemoryStoreForTest(), |
| 52 RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_)); | 57 RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_), |
| 58 &mapper_); |
| 53 } | 59 } |
| 54 | 60 |
| 55 const RecordingModelTypeChangeProcessor& processor() { return *processor_; } | 61 const RecordingModelTypeChangeProcessor& processor() { return *processor_; } |
| 56 | 62 |
| 57 void DisableUserEvents() { | 63 void DisableUserEvents() { |
| 58 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); | 64 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); |
| 59 scoped_feature_list_->Init(); | 65 scoped_feature_list_->Init(); |
| 60 } | 66 } |
| 61 | 67 |
| 62 private: | 68 private: |
| 63 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; | 69 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; |
| 64 RecordingModelTypeChangeProcessor* processor_; | 70 RecordingModelTypeChangeProcessor* processor_; |
| 71 TestGlobalIdMapper mapper_; |
| 65 base::MessageLoop message_loop_; | 72 base::MessageLoop message_loop_; |
| 66 }; | 73 }; |
| 67 | 74 |
| 68 TEST_F(UserEventServiceImplTest, ShouldNotRecordNoSync) { | 75 TEST_F(UserEventServiceImplTest, ShouldNotRecordNoSync) { |
| 69 UserEventServiceImpl service(nullptr, MakeBridge()); | 76 UserEventServiceImpl service(nullptr, MakeBridge()); |
| 70 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); | 77 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); |
| 71 EXPECT_EQ(0u, processor().put_multimap().size()); | 78 EXPECT_EQ(0u, processor().put_multimap().size()); |
| 72 } | 79 } |
| 73 | 80 |
| 74 TEST_F(UserEventServiceImplTest, ShouldNotRecordFeatureIsDisabled) { | 81 TEST_F(UserEventServiceImplTest, ShouldNotRecordFeatureIsDisabled) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 ASSERT_EQ(1u, processor().put_multimap().size()); | 122 ASSERT_EQ(1u, processor().put_multimap().size()); |
| 116 auto put2 = processor().put_multimap().begin(); | 123 auto put2 = processor().put_multimap().begin(); |
| 117 int64_t session_id2 = put2->second->specifics.user_event().session_id(); | 124 int64_t session_id2 = put2->second->specifics.user_event().session_id(); |
| 118 | 125 |
| 119 EXPECT_NE(session_id1, session_id2); | 126 EXPECT_NE(session_id1, session_id2); |
| 120 } | 127 } |
| 121 | 128 |
| 122 } // namespace | 129 } // namespace |
| 123 | 130 |
| 124 } // namespace syncer | 131 } // namespace syncer |
| OLD | NEW |