Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: components/sync/user_events/user_event_service_impl_unittest.cc

Issue 2909283003: [Sync] Split UserEventService into interface and impl, add fake impl, add unit tests. (Closed)
Patch Set: Added a NoOp service to handle OffTheRecord. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_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"
11 #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" 12 #include "components/sync/driver/sync_driver_switches.h"
13 #include "components/sync/model/model_type_store_test_util.h" 13 #include "components/sync/model/model_type_store_test_util.h"
14 #include "components/sync/model/recording_model_type_change_processor.h" 14 #include "components/sync/model/recording_model_type_change_processor.h"
15 #include "components/sync/protocol/sync.pb.h" 15 #include "components/sync/protocol/sync.pb.h"
(...skipping 16 matching lines...) Expand all
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 UserEventServiceTest : public testing::Test { 42 class UserEventServiceImplTest : public testing::Test {
43 protected: 43 protected:
44 UserEventServiceTest() { 44 UserEventServiceImplTest() {
45 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); 45 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>();
46 scoped_feature_list_->InitAndEnableFeature(switches::kSyncUserEvents); 46 scoped_feature_list_->InitAndEnableFeature(switches::kSyncUserEvents);
47 } 47 }
48 48
49 std::unique_ptr<UserEventSyncBridge> MakeBridge() { 49 std::unique_ptr<UserEventSyncBridge> MakeBridge() {
50 return base::MakeUnique<UserEventSyncBridge>( 50 return base::MakeUnique<UserEventSyncBridge>(
51 ModelTypeStoreTestUtil::FactoryForInMemoryStoreForTest(), 51 ModelTypeStoreTestUtil::FactoryForInMemoryStoreForTest(),
52 RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_)); 52 RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_));
53 } 53 }
54 54
55 const RecordingModelTypeChangeProcessor& processor() { return *processor_; } 55 const RecordingModelTypeChangeProcessor& processor() { return *processor_; }
56 56
57 void DisableUserEvents() { 57 void DisableUserEvents() {
58 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>(); 58 scoped_feature_list_ = base::MakeUnique<base::test::ScopedFeatureList>();
59 scoped_feature_list_->Init(); 59 scoped_feature_list_->Init();
60 } 60 }
61 61
62 private: 62 private:
63 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; 63 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_;
64 RecordingModelTypeChangeProcessor* processor_; 64 RecordingModelTypeChangeProcessor* processor_;
65 base::MessageLoop message_loop_; 65 base::MessageLoop message_loop_;
66 }; 66 };
67 67
68 TEST_F(UserEventServiceTest, ShouldNotRecordNoSync) { 68 TEST_F(UserEventServiceImplTest, ShouldNotRecordNoSync) {
69 UserEventService service(nullptr, MakeBridge()); 69 UserEventServiceImpl service(nullptr, MakeBridge());
70 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); 70 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
71 EXPECT_EQ(0u, processor().put_multimap().size()); 71 EXPECT_EQ(0u, processor().put_multimap().size());
72 } 72 }
73 73
74 TEST_F(UserEventServiceTest, ShouldNotRecordFeatureIsDisabled) { 74 TEST_F(UserEventServiceImplTest, ShouldNotRecordFeatureIsDisabled) {
75 DisableUserEvents(); 75 DisableUserEvents();
76 TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES)); 76 TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
77 UserEventService service(&sync_service, MakeBridge()); 77 UserEventServiceImpl service(&sync_service, MakeBridge());
78 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); 78 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
79 EXPECT_EQ(0u, processor().put_multimap().size()); 79 EXPECT_EQ(0u, processor().put_multimap().size());
80 } 80 }
81 81
82 TEST_F(UserEventServiceTest, ShouldNotRecordNoHistory) { 82 TEST_F(UserEventServiceImplTest, ShouldNotRecordNoHistory) {
83 TestSyncService sync_service(true, ModelTypeSet()); 83 TestSyncService sync_service(true, ModelTypeSet());
84 UserEventService service(&sync_service, MakeBridge()); 84 UserEventServiceImpl service(&sync_service, MakeBridge());
85 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); 85 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
86 EXPECT_EQ(0u, processor().put_multimap().size()); 86 EXPECT_EQ(0u, processor().put_multimap().size());
87 } 87 }
88 88
89 TEST_F(UserEventServiceTest, ShouldNotRecordEngineOff) { 89 TEST_F(UserEventServiceImplTest, ShouldNotRecordEngineOff) {
90 TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES)); 90 TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
91 UserEventService service(&sync_service, MakeBridge()); 91 UserEventServiceImpl service(&sync_service, MakeBridge());
92 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); 92 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
93 EXPECT_EQ(0u, processor().put_multimap().size()); 93 EXPECT_EQ(0u, processor().put_multimap().size());
94 } 94 }
95 95
96 TEST_F(UserEventServiceTest, ShouldRecord) { 96 TEST_F(UserEventServiceImplTest, ShouldRecord) {
97 TestSyncService sync_service(true, ModelTypeSet(HISTORY_DELETE_DIRECTIVES)); 97 TestSyncService sync_service(true, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
98 UserEventService service(&sync_service, MakeBridge()); 98 UserEventServiceImpl service(&sync_service, MakeBridge());
99 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); 99 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
100 EXPECT_EQ(1u, processor().put_multimap().size()); 100 EXPECT_EQ(1u, processor().put_multimap().size());
101 } 101 }
102 102
103 TEST_F(UserEventServiceTest, SessionIdIsDifferent) { 103 TEST_F(UserEventServiceImplTest, SessionIdIsDifferent) {
104 TestSyncService sync_service(true, ModelTypeSet(HISTORY_DELETE_DIRECTIVES)); 104 TestSyncService sync_service(true, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
105 105
106 UserEventService service1(&sync_service, MakeBridge()); 106 UserEventServiceImpl service1(&sync_service, MakeBridge());
107 service1.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); 107 service1.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
108 ASSERT_EQ(1u, processor().put_multimap().size()); 108 ASSERT_EQ(1u, processor().put_multimap().size());
109 auto put1 = processor().put_multimap().begin(); 109 auto put1 = processor().put_multimap().begin();
110 int64_t session_id1 = put1->second->specifics.user_event().session_id(); 110 int64_t session_id1 = put1->second->specifics.user_event().session_id();
111 111
112 UserEventService service2(&sync_service, MakeBridge()); 112 UserEventServiceImpl service2(&sync_service, MakeBridge());
113 service2.RecordUserEvent(base::MakeUnique<UserEventSpecifics>()); 113 service2.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
114 // The object processor() points to has changed to be |service2|'s processor. 114 // The object processor() points to has changed to be |service2|'s processor.
115 ASSERT_EQ(1u, processor().put_multimap().size()); 115 ASSERT_EQ(1u, processor().put_multimap().size());
116 auto put2 = processor().put_multimap().begin(); 116 auto put2 = processor().put_multimap().begin();
117 int64_t session_id2 = put2->second->specifics.user_event().session_id(); 117 int64_t session_id2 = put2->second->specifics.user_event().session_id();
118 118
119 EXPECT_NE(session_id1, session_id2); 119 EXPECT_NE(session_id1, session_id2);
120 } 120 }
121 121
122 } // namespace 122 } // namespace
123 123
124 } // namespace syncer 124 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/user_events/user_event_service_impl.cc ('k') | components/sync/user_events/user_event_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698