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.h" | 5 #include "components/sync/user_events/user_event_service.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 "components/sync/base/model_type.h" | 10 #include "components/sync/base/model_type.h" |
10 #include "components/sync/driver/fake_sync_service.h" | 11 #include "components/sync/driver/fake_sync_service.h" |
| 12 #include "components/sync/driver/sync_driver_switches.h" |
11 #include "components/sync/model/model_type_store_test_util.h" | 13 #include "components/sync/model/model_type_store_test_util.h" |
12 #include "components/sync/model/recording_model_type_change_processor.h" | 14 #include "components/sync/model/recording_model_type_change_processor.h" |
13 #include "components/sync/protocol/sync.pb.h" | 15 #include "components/sync/protocol/sync.pb.h" |
14 #include "components/sync/user_events/user_event_sync_bridge.h" | 16 #include "components/sync/user_events/user_event_sync_bridge.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
17 using sync_pb::UserEventSpecifics; | 19 using sync_pb::UserEventSpecifics; |
18 | 20 |
19 namespace syncer { | 21 namespace syncer { |
20 | 22 |
(...skipping 11 matching lines...) Expand all Loading... |
32 return preferred_data_types_; | 34 return preferred_data_types_; |
33 } | 35 } |
34 | 36 |
35 private: | 37 private: |
36 bool is_engine_initialized_; | 38 bool is_engine_initialized_; |
37 ModelTypeSet preferred_data_types_; | 39 ModelTypeSet preferred_data_types_; |
38 }; | 40 }; |
39 | 41 |
40 class UserEventServiceTest : public testing::Test { | 42 class UserEventServiceTest : public testing::Test { |
41 protected: | 43 protected: |
| 44 UserEventServiceTest() { |
| 45 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); |
| 46 scoped_feature_list_->InitAndEnableFeature(switches::kSyncUserEvents); |
| 47 } |
| 48 |
42 std::unique_ptr<UserEventSyncBridge> MakeBridge() { | 49 std::unique_ptr<UserEventSyncBridge> MakeBridge() { |
43 return base::MakeUnique<UserEventSyncBridge>( | 50 return base::MakeUnique<UserEventSyncBridge>( |
44 ModelTypeStoreTestUtil::FactoryForInMemoryStoreForTest(), | 51 ModelTypeStoreTestUtil::FactoryForInMemoryStoreForTest(), |
45 RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_)); | 52 RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_)); |
46 } | 53 } |
47 | 54 |
48 const RecordingModelTypeChangeProcessor& processor() { return *processor_; } | 55 const RecordingModelTypeChangeProcessor& processor() { return *processor_; } |
49 | 56 |
| 57 void DisableUserEvents() { |
| 58 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); |
| 59 scoped_feature_list_->Init(); |
| 60 } |
| 61 |
50 private: | 62 private: |
| 63 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; |
51 RecordingModelTypeChangeProcessor* processor_; | 64 RecordingModelTypeChangeProcessor* processor_; |
52 base::MessageLoop message_loop_; | 65 base::MessageLoop message_loop_; |
53 }; | 66 }; |
54 | 67 |
55 TEST_F(UserEventServiceTest, ShouldNotRecordNoSync) { | 68 TEST_F(UserEventServiceTest, ShouldNotRecordNoSync) { |
56 UserEventService service(nullptr, MakeBridge()); | 69 UserEventService service(nullptr, MakeBridge()); |
57 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); | 70 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); |
58 EXPECT_EQ(0u, processor().put_multimap().size()); | 71 EXPECT_EQ(0u, processor().put_multimap().size()); |
59 } | 72 } |
60 | 73 |
| 74 TEST_F(UserEventServiceTest, ShouldNotRecordFeatureIsDisabled) { |
| 75 DisableUserEvents(); |
| 76 TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES)); |
| 77 UserEventService service(&sync_service, MakeBridge()); |
| 78 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); |
| 79 EXPECT_EQ(0u, processor().put_multimap().size()); |
| 80 } |
| 81 |
61 TEST_F(UserEventServiceTest, ShouldNotRecordNoHistory) { | 82 TEST_F(UserEventServiceTest, ShouldNotRecordNoHistory) { |
62 TestSyncService sync_service(true, ModelTypeSet()); | 83 TestSyncService sync_service(true, ModelTypeSet()); |
63 UserEventService service(&sync_service, MakeBridge()); | 84 UserEventService service(&sync_service, MakeBridge()); |
64 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); | 85 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); |
65 EXPECT_EQ(0u, processor().put_multimap().size()); | 86 EXPECT_EQ(0u, processor().put_multimap().size()); |
66 } | 87 } |
67 | 88 |
68 TEST_F(UserEventServiceTest, ShouldNotRecordEngineOff) { | 89 TEST_F(UserEventServiceTest, ShouldNotRecordEngineOff) { |
69 TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES)); | 90 TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES)); |
70 UserEventService service(&sync_service, MakeBridge()); | 91 UserEventService service(&sync_service, MakeBridge()); |
(...skipping 23 matching lines...) Expand all Loading... |
94 ASSERT_EQ(1u, processor().put_multimap().size()); | 115 ASSERT_EQ(1u, processor().put_multimap().size()); |
95 auto put2 = processor().put_multimap().begin(); | 116 auto put2 = processor().put_multimap().begin(); |
96 int64_t session_id2 = put2->second->specifics.user_event().session_id(); | 117 int64_t session_id2 = put2->second->specifics.user_event().session_id(); |
97 | 118 |
98 EXPECT_NE(session_id1, session_id2); | 119 EXPECT_NE(session_id1, session_id2); |
99 } | 120 } |
100 | 121 |
101 } // namespace | 122 } // namespace |
102 | 123 |
103 } // namespace syncer | 124 } // namespace syncer |
OLD | NEW |