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

Unified Diff: chrome/browser/ui/webui/sync_internals_message_handler_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, 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 | « chrome/browser/ui/webui/sync_internals_message_handler.cc ('k') | components/sync/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/sync_internals_message_handler_unittest.cc
diff --git a/chrome/browser/ui/webui/sync_internals_message_handler_unittest.cc b/chrome/browser/ui/webui/sync_internals_message_handler_unittest.cc
index 41299ef02a59074186b85f54fe75239b3fb9629c..c0264788d64ded53433ed2d71cd6201abc885b7b 100644
--- a/chrome/browser/ui/webui/sync_internals_message_handler_unittest.cc
+++ b/chrome/browser/ui/webui/sync_internals_message_handler_unittest.cc
@@ -17,6 +17,7 @@
#include "components/sync/driver/fake_sync_service.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/js/js_test_util.h"
+#include "components/sync/user_events/fake_user_event_service.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_browser_thread_bundle.h"
@@ -26,6 +27,7 @@
using base::DictionaryValue;
using base::ListValue;
using base::Value;
+using syncer::FakeUserEventService;
using syncer::SyncService;
using syncer::SyncServiceObserver;
using syncer::TypeDebugInfoObserver;
@@ -97,6 +99,11 @@ static std::unique_ptr<KeyedService> BuildTestSyncService(
return base::MakeUnique<TestSyncService>();
}
+static std::unique_ptr<KeyedService> BuildFakeUserEventService(
+ content::BrowserContext* context) {
+ return base::MakeUnique<FakeUserEventService>();
+}
+
class SyncInternalsMessageHandlerTest : public ::testing::Test {
protected:
SyncInternalsMessageHandlerTest() {
@@ -107,6 +114,9 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test {
test_sync_service_ = static_cast<TestSyncService*>(
ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
&profile_, &BuildTestSyncService));
+ fake_user_event_service_ = static_cast<FakeUserEventService*>(
+ browser_sync::UserEventServiceFactory::GetInstance()
+ ->SetTestingFactoryAndUse(&profile_, &BuildFakeUserEventService));
handler_.reset(new TestableSyncInternalsMessageHandler(
&web_ui_,
base::BindRepeating(
@@ -158,6 +168,10 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test {
TestSyncService* test_sync_service() { return test_sync_service_; }
+ FakeUserEventService* fake_user_event_service() {
+ return fake_user_event_service_;
+ }
+
TestableSyncInternalsMessageHandler* handler() { return handler_.get(); }
int CallCountWithName(const std::string& function_name) {
@@ -187,6 +201,7 @@ class SyncInternalsMessageHandlerTest : public ::testing::Test {
std::unique_ptr<content::WebContents> web_contents_;
content::TestWebUI web_ui_;
TestSyncService* test_sync_service_;
+ FakeUserEventService* fake_user_event_service_;
std::unique_ptr<TestableSyncInternalsMessageHandler> handler_;
int about_sync_data_delegate_call_count_ = 0;
SyncService* last_delegate_sync_service_ = nullptr;
@@ -315,4 +330,30 @@ TEST_F(SyncInternalsMessageHandlerTest, SendAboutInfoSyncDisabled) {
ValidateAboutInfoCall();
}
+TEST_F(SyncInternalsMessageHandlerTest, WriteUserEvent) {
+ ListValue args;
+ args.AppendString("1000000000000000000");
+ args.AppendString("-1");
+ handler()->HandleWriteUserEvent(&args);
+
+ ASSERT_EQ(1u, fake_user_event_service()->GetRecordedUserEvents().size());
+ const sync_pb::UserEventSpecifics& event =
+ *fake_user_event_service()->GetRecordedUserEvents().begin();
+ EXPECT_EQ(1000000000000000000, event.event_time_usec());
+ EXPECT_EQ(-1, event.navigation_id());
+}
+
+TEST_F(SyncInternalsMessageHandlerTest, WriteUserEventBadParse) {
+ ListValue args;
+ args.AppendString("123abc");
+ args.AppendString("");
+ handler()->HandleWriteUserEvent(&args);
+
+ ASSERT_EQ(1u, fake_user_event_service()->GetRecordedUserEvents().size());
+ const sync_pb::UserEventSpecifics& event =
+ *fake_user_event_service()->GetRecordedUserEvents().begin();
+ EXPECT_EQ(0, event.event_time_usec());
+ EXPECT_EQ(0, event.navigation_id());
+}
+
} // namespace
« no previous file with comments | « chrome/browser/ui/webui/sync_internals_message_handler.cc ('k') | components/sync/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698