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

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

Issue 2864973002: [Sync] Create UserEventService. (Closed)
Patch Set: Added keyed service dep to Build file. 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
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
Patrick Noland 2017/05/08 22:42:37 Maybe add a test to ensure the uniqueness of sessi
skym 2017/05/08 23:35:27 Done.
82 } // namespace
83
84 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698