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

Unified Diff: components/mus/ws/event_matcher_unittest.cc

Issue 1909733002: mus: Add EventObserver to allow passively listening to UI events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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/mus/ws/event_matcher_unittest.cc
diff --git a/components/mus/ws/event_matcher_unittest.cc b/components/mus/ws/event_matcher_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ae9bb152efa2f117f936a3daf20d26a257d86fc8
--- /dev/null
+++ b/components/mus/ws/event_matcher_unittest.cc
@@ -0,0 +1,71 @@
+// Copyright 2016 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/mus/ws/event_matcher.h"
+
+#include "base/time/time.h"
+#include "components/mus/public/interfaces/input_event_matcher.mojom.h"
+#include "components/mus/public/interfaces/input_key_codes.mojom.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/events/event.h"
+#include "ui/gfx/geometry/point.h"
+
+namespace mus {
+namespace ws {
+
+// NOTE: Most of the matching functionality is exercised by tests of Accelerator
+// handling in the EventDispatcher and WindowTree tests. These are just basic
+// sanity checks.
+
+using EventTesterTest = testing::Test;
+
+TEST_F(EventTesterTest, MatchesEventByType) {
+ mojom::EventMatcherPtr matcher = mojom::EventMatcher::New();
+ matcher->type_matcher = mojom::EventTypeMatcher::New();
+ matcher->type_matcher->type = mojom::EventType::POINTER_DOWN;
+ EventMatcher pointer_down_matcher(*matcher);
+
+ ui::PointerEvent pointer_down(
+ ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(), 1, base::TimeDelta()));
+ EXPECT_TRUE(pointer_down_matcher.MatchesEvent(pointer_down));
+
+ ui::PointerEvent pointer_up(ui::TouchEvent(
+ ui::ET_TOUCH_RELEASED, gfx::Point(), 1, base::TimeDelta()));
+ EXPECT_FALSE(pointer_down_matcher.MatchesEvent(pointer_up));
+}
+
+TEST_F(EventTesterTest, MatchesEventByKeyCode) {
+ mojom::EventMatcherPtr matcher(mojom::EventMatcher::New());
+ matcher->type_matcher = mojom::EventTypeMatcher::New();
+ matcher->type_matcher->type = mojom::EventType::KEY_PRESSED;
+ matcher->key_matcher = mojom::KeyEventMatcher::New();
+ matcher->key_matcher->keyboard_code = mojom::KeyboardCode::Z;
+ EventMatcher z_matcher(*matcher);
+
+ ui::KeyEvent z_key(ui::ET_KEY_PRESSED, ui::VKEY_Z, ui::EF_NONE);
+ EXPECT_TRUE(z_matcher.MatchesEvent(z_key));
+
+ ui::KeyEvent y_key(ui::ET_KEY_PRESSED, ui::VKEY_Y, ui::EF_NONE);
+ EXPECT_FALSE(z_matcher.MatchesEvent(y_key));
+}
+
+TEST_F(EventTesterTest, MatchesEventByKeyFlags) {
+ mojom::EventMatcherPtr matcher(mojom::EventMatcher::New());
+ matcher->type_matcher = mojom::EventTypeMatcher::New();
+ matcher->type_matcher->type = mojom::EventType::KEY_PRESSED;
+ matcher->flags_matcher = mojom::EventFlagsMatcher::New();
+ matcher->flags_matcher->flags = mojom::kEventFlagControlDown;
+ matcher->key_matcher = mojom::KeyEventMatcher::New();
+ matcher->key_matcher->keyboard_code = mojom::KeyboardCode::N;
+ EventMatcher control_n_matcher(*matcher);
+
+ ui::KeyEvent control_n(ui::ET_KEY_PRESSED, ui::VKEY_N, ui::EF_CONTROL_DOWN);
+ EXPECT_TRUE(control_n_matcher.MatchesEvent(control_n));
+
+ ui::KeyEvent shift_n(ui::ET_KEY_PRESSED, ui::VKEY_N, ui::EF_SHIFT_DOWN);
+ EXPECT_FALSE(control_n_matcher.MatchesEvent(shift_n));
+}
+
+} // namespace ws
+} // namespace mus

Powered by Google App Engine
This is Rietveld 408576698