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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/root_window.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/root_window.h" 5 #include "ui/aura/root_window.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/aura/env.h" 8 #include "ui/aura/env.h"
9 #include "ui/aura/event.h" 9 #include "ui/aura/event.h"
10 #include "ui/aura/event_filter.h"
10 #include "ui/aura/test/aura_test_base.h" 11 #include "ui/aura/test/aura_test_base.h"
11 #include "ui/aura/test/test_window_delegate.h" 12 #include "ui/aura/test/test_window_delegate.h"
12 #include "ui/aura/test/test_windows.h" 13 #include "ui/aura/test/test_windows.h"
13 #include "ui/base/hit_test.h" 14 #include "ui/base/hit_test.h"
14 #include "ui/gfx/point.h" 15 #include "ui/gfx/point.h"
15 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
16 17
17 namespace aura { 18 namespace aura {
18 namespace { 19 namespace {
19 20
(...skipping 25 matching lines...) Expand all
45 mouse_event_flags_ = event->flags(); 46 mouse_event_flags_ = event->flags();
46 return true; 47 return true;
47 } 48 }
48 49
49 private: 50 private:
50 int non_client_count_; 51 int non_client_count_;
51 gfx::Point non_client_location_; 52 gfx::Point non_client_location_;
52 int mouse_event_count_; 53 int mouse_event_count_;
53 gfx::Point mouse_event_location_; 54 gfx::Point mouse_event_location_;
54 int mouse_event_flags_; 55 int mouse_event_flags_;
56
57 DISALLOW_COPY_AND_ASSIGN(NonClientDelegate);
58 };
59
60 // A simple EventFilter that keeps track of the number of key events that it's
61 // seen.
62 class TestEventFilter : public EventFilter {
63 public:
64 TestEventFilter() : num_key_events_(0) {}
65 virtual ~TestEventFilter() {}
66
67 int num_key_events() const { return num_key_events_; }
68
69 // EventFilter overrides:
70 virtual bool PreHandleKeyEvent(Window* target, KeyEvent* event) OVERRIDE {
71 num_key_events_++;
72 return true;
73 }
74 virtual bool PreHandleMouseEvent(Window* target, MouseEvent* event) OVERRIDE {
75 return false;
76 }
77 virtual ui::TouchStatus PreHandleTouchEvent(
78 Window* target, TouchEvent* event) OVERRIDE {
79 return ui::TOUCH_STATUS_UNKNOWN;
80 }
81 virtual ui::GestureStatus PreHandleGestureEvent(
82 Window* target, GestureEvent* event) OVERRIDE {
83 return ui::GESTURE_STATUS_UNKNOWN;
84 }
85
86 private:
87 // How many key events have been received?
88 int num_key_events_;
89
90 DISALLOW_COPY_AND_ASSIGN(TestEventFilter);
55 }; 91 };
56 92
57 } // namespace 93 } // namespace
58 94
59 typedef test::AuraTestBase RootWindowTest; 95 typedef test::AuraTestBase RootWindowTest;
60 96
61 TEST_F(RootWindowTest, DispatchMouseEvent) { 97 TEST_F(RootWindowTest, DispatchMouseEvent) {
62 // Create two non-overlapping windows so we don't have to worry about which 98 // Create two non-overlapping windows so we don't have to worry about which
63 // is on top. 99 // is on top.
64 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); 100 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 EXPECT_EQ("100,100", root.location().ToString()); 192 EXPECT_EQ("100,100", root.location().ToString());
157 EXPECT_EQ("100,100", root.root_location().ToString()); 193 EXPECT_EQ("100,100", root.root_location().ToString());
158 194
159 MouseEvent translated_event( 195 MouseEvent translated_event(
160 root, root_window(), w1.get(), 196 root, root_window(), w1.get(),
161 ui::ET_MOUSE_ENTERED, root.flags()); 197 ui::ET_MOUSE_ENTERED, root.flags());
162 EXPECT_EQ("50,50", translated_event.location().ToString()); 198 EXPECT_EQ("50,50", translated_event.location().ToString());
163 EXPECT_EQ("100,100", translated_event.root_location().ToString()); 199 EXPECT_EQ("100,100", translated_event.root_location().ToString());
164 } 200 }
165 201
202 TEST_F(RootWindowTest, IgnoreUnknownKeys) {
203 TestEventFilter* filter = new TestEventFilter;
204 root_window()->SetEventFilter(filter); // passes ownership
205
206 KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0);
207 EXPECT_FALSE(root_window()->DispatchKeyEvent(&unknown_event));
208 EXPECT_EQ(0, filter->num_key_events());
209
210 KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0);
211 EXPECT_TRUE(root_window()->DispatchKeyEvent(&known_event));
212 EXPECT_EQ(1, filter->num_key_events());
213 }
214
166 } // namespace aura 215 } // namespace aura
OLDNEW
« 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