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

Unified Diff: ui/aura/root_window_unittest.cc

Issue 9835032: aura: Make RootWindow::DispatchKeyEvent drop unknown keys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/root_window_unittest.cc
diff --git a/ui/aura/root_window_unittest.cc b/ui/aura/root_window_unittest.cc
index 3b336f064d1666790e692a701a0bf21d8e3138e2..ab7e986c12a94ca332c59b237f1d7809bab42d2a 100644
--- a/ui/aura/root_window_unittest.cc
+++ b/ui/aura/root_window_unittest.cc
@@ -7,6 +7,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
+#include "ui/aura/event_filter.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
@@ -52,6 +53,41 @@ class NonClientDelegate : public test::TestWindowDelegate {
int mouse_event_count_;
gfx::Point mouse_event_location_;
int mouse_event_flags_;
+
+ DISALLOW_COPY_AND_ASSIGN(NonClientDelegate);
+};
+
+// A simple EventFilter that keeps track of the number of key events that it's
+// seen.
+class TestEventFilter : public EventFilter {
+ public:
+ TestEventFilter() : num_key_events_(0) {}
+ virtual ~TestEventFilter() {}
+
+ int num_key_events() const { return num_key_events_; }
+
+ // EventFilter overrides:
+ virtual bool PreHandleKeyEvent(Window* target, KeyEvent* event) OVERRIDE {
+ num_key_events_++;
+ return true;
+ }
+ virtual bool PreHandleMouseEvent(Window* target, MouseEvent* event) OVERRIDE {
+ return false;
+ }
+ virtual ui::TouchStatus PreHandleTouchEvent(
+ Window* target, TouchEvent* event) OVERRIDE {
+ return ui::TOUCH_STATUS_UNKNOWN;
+ }
+ virtual ui::GestureStatus PreHandleGestureEvent(
+ Window* target, GestureEvent* event) OVERRIDE {
+ return ui::GESTURE_STATUS_UNKNOWN;
+ }
+
+ private:
+ // How many key events have been received?
+ int num_key_events_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestEventFilter);
};
} // namespace
@@ -163,4 +199,17 @@ TEST_F(RootWindowTest, TranslatedEvent) {
EXPECT_EQ("100,100", translated_event.root_location().ToString());
}
+TEST_F(RootWindowTest, IgnoreUnknownKeys) {
+ TestEventFilter* filter = new TestEventFilter;
+ root_window()->SetEventFilter(filter); // passes ownership
+
+ KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0);
+ EXPECT_FALSE(root_window()->DispatchKeyEvent(&unknown_event));
+ EXPECT_EQ(0, filter->num_key_events());
+
+ KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
+ EXPECT_TRUE(root_window()->DispatchKeyEvent(&known_event));
+ EXPECT_EQ(1, filter->num_key_events());
+}
+
} // namespace aura
« no previous file with comments | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698