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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/sync/user_events/user_event_service_unittest.cc
diff --git a/components/sync/user_events/user_event_service_unittest.cc b/components/sync/user_events/user_event_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3760d3d9a3f83bd005e2fe12911b5f970a735d5e
--- /dev/null
+++ b/components/sync/user_events/user_event_service_unittest.cc
@@ -0,0 +1,84 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/sync/user_events/user_event_service.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/message_loop/message_loop.h"
+#include "components/sync/base/model_type.h"
+#include "components/sync/driver/fake_sync_service.h"
+#include "components/sync/model/model_type_store_test_util.h"
+#include "components/sync/model/recording_model_type_change_processor.h"
+#include "components/sync/protocol/sync.pb.h"
+#include "components/sync/user_events/user_event_sync_bridge.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using sync_pb::UserEventSpecifics;
+
+namespace syncer {
+
+namespace {
+
+class TestSyncService : public FakeSyncService {
+ public:
+ TestSyncService(bool is_engine_initialized, ModelTypeSet preferred_data_types)
+ : is_engine_initialized_(is_engine_initialized),
+ preferred_data_types_(preferred_data_types) {}
+
+ bool IsEngineInitialized() const override { return is_engine_initialized_; }
+
+ ModelTypeSet GetPreferredDataTypes() const override {
+ return preferred_data_types_;
+ }
+
+ private:
+ bool is_engine_initialized_;
+ ModelTypeSet preferred_data_types_;
+};
+
+class UserEventServiceTest : public testing::Test {
+ protected:
+ std::unique_ptr<UserEventSyncBridge> MakeBridge() {
+ return base::MakeUnique<UserEventSyncBridge>(
+ ModelTypeStoreTestUtil::FactoryForInMemoryStoreForTest(),
+ RecordingModelTypeChangeProcessor::FactoryForBridgeTest(&processor_));
+ }
+
+ const RecordingModelTypeChangeProcessor& processor() { return *processor_; }
+
+ private:
+ RecordingModelTypeChangeProcessor* processor_;
+ base::MessageLoop message_loop_;
+};
+
+TEST_F(UserEventServiceTest, ShouldNotRecordNoSync) {
+ UserEventService service(nullptr, MakeBridge());
+ service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
+ EXPECT_EQ(0u, processor().put_multimap().size());
+}
+
+TEST_F(UserEventServiceTest, ShouldNotRecordNoHistory) {
+ TestSyncService sync_service(true, ModelTypeSet());
+ UserEventService service(&sync_service, MakeBridge());
+ service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
+ EXPECT_EQ(0u, processor().put_multimap().size());
+}
+
+TEST_F(UserEventServiceTest, ShouldNotRecordEngineOff) {
+ TestSyncService sync_service(false, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
+ UserEventService service(&sync_service, MakeBridge());
+ service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
+ EXPECT_EQ(0u, processor().put_multimap().size());
+}
+
+TEST_F(UserEventServiceTest, ShouldRecord) {
+ TestSyncService sync_service(true, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
+ UserEventService service(&sync_service, MakeBridge());
+ service.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
+ EXPECT_EQ(1u, processor().put_multimap().size());
+}
+
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.
+} // namespace
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698