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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/sync/user_events/user_event_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..83e968a25e2f8dd6dca16807b3a2a0a18b703c27
--- /dev/null
+++ b/components/sync/user_events/user_event_service_unittest.cc
@@ -0,0 +1,103 @@
+// 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());
+}
+
+TEST_F(UserEventServiceTest, SessionIdIsDifferent) {
+ TestSyncService sync_service(true, ModelTypeSet(HISTORY_DELETE_DIRECTIVES));
+
+ UserEventService service1(&sync_service, MakeBridge());
+ service1.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
+ ASSERT_EQ(1u, processor().put_multimap().size());
+ auto put1 = processor().put_multimap().begin();
+ int64_t session_id1 = put1->second->specifics.user_event().session_id();
+
+ UserEventService service2(&sync_service, MakeBridge());
+ service2.RecordUserEvent(base::MakeUnique<UserEventSpecifics>());
+ // The object processor() points to has changed to be |service2|'s processor.
+ ASSERT_EQ(1u, processor().put_multimap().size());
+ auto put2 = processor().put_multimap().begin();
+ int64_t session_id2 = put2->second->specifics.user_event().session_id();
+
+ EXPECT_NE(session_id1, session_id2);
+}
+
+} // namespace
+
+} // namespace syncer
« 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