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

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

Issue 2864973002: [Sync] Create UserEventService. (Closed)
Patch Set: Updates for Patrick. Created 3 years, 7 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
« no previous file with comments | « components/sync/user_events/user_event_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/sync/user_events/user_event_service.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "components/sync/base/model_type.h"
10 #include "components/sync/driver/fake_sync_service.h"
11 #include "components/sync/model/model_type_store_test_util.h"
12 #include "components/sync/model/recording_model_type_change_processor.h"
13 #include "components/sync/protocol/sync.pb.h"
14 #include "components/sync/user_events/user_event_sync_bridge.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using sync_pb::UserEventSpecifics;
18
19 namespace syncer {
20
21 namespace {
22
23 class TestSyncService : public FakeSyncService {
24 public:
25 TestSyncService(bool is_engine_initialized, ModelTypeSet preferred_data_types)
26 : is_engine_initialized_(is_engine_initialized),
27 preferred_data_types_(preferred_data_types) {}
28
29 bool IsEngineInitialized() const override { return is_engine_initialized_; }
30
31 ModelTypeSet GetPreferredDataTypes() const override {
32 return preferred_data_types_;
33 }
34
35 private:
36 bool is_engine_initialized_;
37 ModelTypeSet preferred_data_types_;
38 };
39
40 class UserEventServiceTest : public testing::Test {
41 protected:
42 std::unique_ptr<UserEventSyncBridge> MakeBridge() {
43 return base::MakeUnique<UserEventSyncBridge>(
44 ModelTypeStoreTestUtil::FactoryForInMemoryStoreForTest(),
45 RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_));
46 }
47
48 const RecordingModelTypeChangeProcessor& processor() { return *processor_; }
49
50 private:
51 RecordingModelTypeChangeProcessor* processor_;
52 base::MessageLoop message_loop_;
53 };
54
55 TEST_F(UserEventServiceTest, ShouldNotRecordNoSync) {
56 UserEventService service(nullptr, MakeBridge());
57 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
58 EXPECT_EQ(0u, processor().put_multimap().size());
59 }
60
61 TEST_F(UserEventServiceTest, ShouldNotRecordNoHistory) {
62 TestSyncService sync_service(true, ModelTypeSet());
63 UserEventService service(&sync_service, MakeBridge());
64 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
65 EXPECT_EQ(0u, processor().put_multimap().size());
66 }
67
68 TEST_F(UserEventServiceTest, ShouldNotRecordEngineOff) {
69 TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
70 UserEventService service(&sync_service, MakeBridge());
71 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
72 EXPECT_EQ(0u, processor().put_multimap().size());
73 }
74
75 TEST_F(UserEventServiceTest, ShouldRecord) {
76 TestSyncService sync_service(true, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
77 UserEventService service(&sync_service, MakeBridge());
78 service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
79 EXPECT_EQ(1u, processor().put_multimap().size());
80 }
81
82 TEST_F(UserEventServiceTest, SessionIdIsDifferent) {
83 TestSyncService sync_service(true, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
84
85 UserEventService service1(&sync_service, MakeBridge());
86 service1.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
87 ASSERT_EQ(1u, processor().put_multimap().size());
88 auto put1 = processor().put_multimap().begin();
89 int64_t session_id1 = put1->second->specifics.user_event().session_id();
90
91 UserEventService service2(&sync_service, MakeBridge());
92 service2.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
93 // The object processor() points to has changed to be |service2|'s processor.
94 ASSERT_EQ(1u, processor().put_multimap().size());
95 auto put2 = processor().put_multimap().begin();
96 int64_t session_id2 = put2->second->specifics.user_event().session_id();
97
98 EXPECT_NE(session_id1, session_id2);
99 }
100
101 } // namespace
102
103 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/user_events/user_event_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698