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

Unified Diff: components/keyboard_lock/keyboard_lock_host_unittest.cc

Issue 2815023002: [System-Keyboard-Lock] Add KeyboardLockHost and KeyEventInterceptor (Closed)
Patch Set: Resolve review comments Created 3 years, 8 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/keyboard_lock/keyboard_lock_host_unittest.cc
diff --git a/components/keyboard_lock/keyboard_lock_host_unittest.cc b/components/keyboard_lock/keyboard_lock_host_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a5efc75c8952a27a6ca1e9691c28973bd67beb6a
--- /dev/null
+++ b/components/keyboard_lock/keyboard_lock_host_unittest.cc
@@ -0,0 +1,52 @@
+// 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/keyboard_lock/keyboard_lock_host.h"
+
+#include "components/keyboard_lock/key_event_interceptor_installer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace keyboard_lock {
+
+namespace {
+
+class FakeKeyEventInterceptor : public KeyEventInterceptorInstaller {
+ public:
+ // Owned by |host|.
+ static FakeKeyEventInterceptor* Create(KeyboardLockHost* host);
+ ~FakeKeyEventInterceptor() override { deleted_count++; }
+
+ bool OnKeyDown(ui::KeyboardCode code) override { return false; }
+ bool OnKeyUp(ui::KeyboardCode code) override { return false; }
+
+ static int deleted_count;
+
+ private:
+ FakeKeyEventInterceptor(KeyboardLockHost* host)
+ : KeyEventInterceptorInstaller(host) {}
+};
+
+int FakeKeyEventInterceptor::deleted_count = 0;
+
+// static
+FakeKeyEventInterceptor* FakeKeyEventInterceptor::Create(
+ KeyboardLockHost* host) {
+ FakeKeyEventInterceptor* interceptor = new FakeKeyEventInterceptor(host);
+ interceptor->Install();
+ return interceptor;
+}
+
+}
+
+TEST(KeyboardLockHostTest, KeyEventInterceptorInstallationTest) {
+ {
+ KeyboardLockHost host;
+ FakeKeyEventInterceptor* interceptor =
+ FakeKeyEventInterceptor::Create(&host);
+ ASSERT_EQ(interceptor, host.interceptor());
+ }
+ ASSERT_EQ(FakeKeyEventInterceptor::deleted_count, 1);
+}
+
+} // namespace keyboard_lock

Powered by Google App Engine
This is Rietveld 408576698