OLD | NEW |
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 <cstring> | 5 #include <cstring> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/XKBlib.h> | |
10 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
11 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
| 11 #include <X11/XKBlib.h> |
12 | 12 |
13 // Generically-named #defines from Xlib that conflict with symbols in GTest. | 13 // Generically-named #defines from Xlib that conflict with symbols in GTest. |
14 #undef Bool | 14 #undef Bool |
15 #undef None | 15 #undef None |
16 | 16 |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/events/devices/x11/device_data_manager_x11.h" |
| 20 #include "ui/events/devices/x11/touch_factory_x11.h" |
19 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
20 #include "ui/events/event_constants.h" | 22 #include "ui/events/event_constants.h" |
21 #include "ui/events/event_utils.h" | 23 #include "ui/events/event_utils.h" |
22 #include "ui/events/platform/platform_event_builder.h" | |
23 #include "ui/events/platform/platform_event_utils.h" | |
24 #include "ui/events/platform/x11/device_data_manager_x11.h" | |
25 #include "ui/events/platform/x11/touch_factory_x11.h" | |
26 #include "ui/events/test/events_test_utils.h" | 24 #include "ui/events/test/events_test_utils.h" |
27 #include "ui/events/test/events_test_utils_x11.h" | 25 #include "ui/events/test/events_test_utils_x11.h" |
28 #include "ui/gfx/point.h" | 26 #include "ui/gfx/geometry/point.h" |
29 | 27 |
30 namespace ui { | 28 namespace ui { |
31 | 29 |
32 namespace { | 30 namespace { |
33 | 31 |
34 // Initializes the passed-in Xlib event. | 32 // Initializes the passed-in Xlib event. |
35 void InitButtonEvent(XEvent* event, | 33 void InitButtonEvent(XEvent* event, |
36 bool is_press, | 34 bool is_press, |
37 const gfx::Point& location, | 35 const gfx::Point& location, |
38 int button, | 36 int button, |
39 int state) { | 37 int state) { |
40 memset(event, 0, sizeof(*event)); | 38 memset(event, 0, sizeof(*event)); |
41 | 39 |
42 // We don't bother setting fields that the event code doesn't use, such as | 40 // We don't bother setting fields that the event code doesn't use, such as |
43 // x_root/y_root and window/root/subwindow. | 41 // x_root/y_root and window/root/subwindow. |
44 XButtonEvent* button_event = &(event->xbutton); | 42 XButtonEvent* button_event = &(event->xbutton); |
45 button_event->type = is_press ? ButtonPress : ButtonRelease; | 43 button_event->type = is_press ? ButtonPress : ButtonRelease; |
46 button_event->x = location.x(); | 44 button_event->x = location.x(); |
47 button_event->y = location.y(); | 45 button_event->y = location.y(); |
48 button_event->button = button; | 46 button_event->button = button; |
49 button_event->state = state; | 47 button_event->state = state; |
50 } | 48 } |
51 | 49 |
| 50 #if !defined(OS_CHROMEOS) |
52 // Initializes the passed-in Xlib event. | 51 // Initializes the passed-in Xlib event. |
53 void InitKeyEvent(Display* display, | 52 void InitKeyEvent(Display* display, |
54 XEvent* event, | 53 XEvent* event, |
55 bool is_press, | 54 bool is_press, |
56 int keycode, | 55 int keycode, |
57 int state) { | 56 int state) { |
58 memset(event, 0, sizeof(*event)); | 57 memset(event, 0, sizeof(*event)); |
59 | 58 |
60 // We don't bother setting fields that the event code doesn't use, such as | 59 // We don't bother setting fields that the event code doesn't use, such as |
61 // x_root/y_root and window/root/subwindow. | 60 // x_root/y_root and window/root/subwindow. |
62 XKeyEvent* key_event = &(event->xkey); | 61 XKeyEvent* key_event = &(event->xkey); |
63 key_event->display = display; | 62 key_event->display = display; |
64 key_event->type = is_press ? KeyPress : KeyRelease; | 63 key_event->type = is_press ? KeyPress : KeyRelease; |
65 key_event->keycode = keycode; | 64 key_event->keycode = keycode; |
66 key_event->state = state; | 65 key_event->state = state; |
67 } | 66 } |
68 | 67 #endif |
69 // Returns true if the keysym maps to a KeyEvent with the EF_FUNCTION_KEY | |
70 // flag set, or the keysym maps to a zero key code. | |
71 bool HasFunctionKeyFlagSetIfSupported(Display* display, int x_keysym) { | |
72 XEvent event; | |
73 int x_keycode = XKeysymToKeycode(display, x_keysym); | |
74 // Exclude keysyms for which the server has no corresponding keycode. | |
75 if (x_keycode) { | |
76 InitKeyEvent(display, &event, true, x_keycode, 0); | |
77 ui::KeyEvent ui_key_event = PlatformEventBuilder::BuildKeyEvent(&event); | |
78 return (ui_key_event.flags() & ui::EF_FUNCTION_KEY); | |
79 } | |
80 return true; | |
81 } | |
82 | 68 |
83 } // namespace | 69 } // namespace |
84 | 70 |
85 class PlatformEventUtilsXTest : public testing::Test { | 71 class EventsXTest : public testing::Test { |
86 public: | 72 public: |
87 PlatformEventUtilsXTest() {} | 73 EventsXTest() {} |
88 ~PlatformEventUtilsXTest() override {} | 74 ~EventsXTest() override {} |
89 | 75 |
90 void SetUp() override { | 76 void SetUp() override { |
91 DeviceDataManagerX11::CreateInstance(); | 77 DeviceDataManagerX11::CreateInstance(); |
92 ui::TouchFactory::GetInstance()->ResetForTest(); | 78 ui::TouchFactory::GetInstance()->ResetForTest(); |
93 } | 79 } |
94 | |
95 private: | 80 private: |
96 DISALLOW_COPY_AND_ASSIGN(PlatformEventUtilsXTest); | 81 DISALLOW_COPY_AND_ASSIGN(EventsXTest); |
97 }; | 82 }; |
98 | 83 |
99 TEST_F(PlatformEventUtilsXTest, ButtonEvents) { | 84 TEST_F(EventsXTest, ButtonEvents) { |
100 XEvent event; | 85 XEvent event; |
101 gfx::Point location(5, 10); | 86 gfx::Point location(5, 10); |
102 gfx::Vector2d offset; | 87 gfx::Vector2d offset; |
103 | 88 |
104 InitButtonEvent(&event, true, location, 1, 0); | 89 InitButtonEvent(&event, true, location, 1, 0); |
105 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(&event)); | 90 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(&event)); |
106 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, ui::EventFlagsFromNative(&event)); | 91 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, ui::EventFlagsFromNative(&event)); |
| 92 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, |
| 93 ui::GetChangedMouseButtonFlagsFromNative(&event)); |
107 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 94 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
108 | 95 |
109 InitButtonEvent(&event, true, location, 2, Button1Mask | ShiftMask); | 96 InitButtonEvent(&event, true, location, 2, Button1Mask | ShiftMask); |
110 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(&event)); | 97 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(&event)); |
111 EXPECT_EQ( | 98 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON | |
112 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_SHIFT_DOWN, | 99 ui::EF_SHIFT_DOWN, |
113 ui::EventFlagsFromNative(&event)); | 100 ui::EventFlagsFromNative(&event)); |
| 101 EXPECT_EQ(ui::EF_MIDDLE_MOUSE_BUTTON, |
| 102 ui::GetChangedMouseButtonFlagsFromNative(&event)); |
114 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 103 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
115 | 104 |
116 InitButtonEvent(&event, false, location, 3, 0); | 105 InitButtonEvent(&event, false, location, 3, 0); |
117 EXPECT_EQ(ui::ET_MOUSE_RELEASED, ui::EventTypeFromNative(&event)); | 106 EXPECT_EQ(ui::ET_MOUSE_RELEASED, ui::EventTypeFromNative(&event)); |
118 EXPECT_EQ(ui::EF_RIGHT_MOUSE_BUTTON, ui::EventFlagsFromNative(&event)); | 107 EXPECT_EQ(ui::EF_RIGHT_MOUSE_BUTTON, ui::EventFlagsFromNative(&event)); |
| 108 EXPECT_EQ(ui::EF_RIGHT_MOUSE_BUTTON, |
| 109 ui::GetChangedMouseButtonFlagsFromNative(&event)); |
119 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 110 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
120 | 111 |
121 // Scroll up. | 112 // Scroll up. |
122 InitButtonEvent(&event, true, location, 4, 0); | 113 InitButtonEvent(&event, true, location, 4, 0); |
123 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); | 114 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); |
124 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); | 115 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); |
| 116 EXPECT_EQ(ui::EF_NONE, ui::GetChangedMouseButtonFlagsFromNative(&event)); |
125 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 117 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
126 offset = ui::GetMouseWheelOffset(&event); | 118 offset = ui::GetMouseWheelOffset(&event); |
127 EXPECT_GT(offset.y(), 0); | 119 EXPECT_GT(offset.y(), 0); |
128 EXPECT_EQ(0, offset.x()); | 120 EXPECT_EQ(0, offset.x()); |
129 | 121 |
130 // Scroll down. | 122 // Scroll down. |
131 InitButtonEvent(&event, true, location, 5, 0); | 123 InitButtonEvent(&event, true, location, 5, 0); |
132 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); | 124 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); |
133 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); | 125 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); |
| 126 EXPECT_EQ(ui::EF_NONE, ui::GetChangedMouseButtonFlagsFromNative(&event)); |
134 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 127 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
135 offset = ui::GetMouseWheelOffset(&event); | 128 offset = ui::GetMouseWheelOffset(&event); |
136 EXPECT_LT(offset.y(), 0); | 129 EXPECT_LT(offset.y(), 0); |
137 EXPECT_EQ(0, offset.x()); | 130 EXPECT_EQ(0, offset.x()); |
138 | 131 |
139 // Scroll left. | 132 // Scroll left. |
140 InitButtonEvent(&event, true, location, 6, 0); | 133 InitButtonEvent(&event, true, location, 6, 0); |
141 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); | 134 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); |
142 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); | 135 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); |
| 136 EXPECT_EQ(ui::EF_NONE, ui::GetChangedMouseButtonFlagsFromNative(&event)); |
143 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 137 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
144 offset = ui::GetMouseWheelOffset(&event); | 138 offset = ui::GetMouseWheelOffset(&event); |
145 EXPECT_EQ(0, offset.y()); | 139 EXPECT_EQ(0, offset.y()); |
146 EXPECT_GT(offset.x(), 0); | 140 EXPECT_GT(offset.x(), 0); |
147 | 141 |
148 // Scroll right. | 142 // Scroll right. |
149 InitButtonEvent(&event, true, location, 7, 0); | 143 InitButtonEvent(&event, true, location, 7, 0); |
150 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); | 144 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); |
151 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); | 145 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); |
| 146 EXPECT_EQ(ui::EF_NONE, ui::GetChangedMouseButtonFlagsFromNative(&event)); |
152 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 147 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
153 offset = ui::GetMouseWheelOffset(&event); | 148 offset = ui::GetMouseWheelOffset(&event); |
154 EXPECT_EQ(0, offset.y()); | 149 EXPECT_EQ(0, offset.y()); |
155 EXPECT_LT(offset.x(), 0); | 150 EXPECT_LT(offset.x(), 0); |
156 | 151 |
157 // TODO(derat): Test XInput code. | 152 // TODO(derat): Test XInput code. |
158 } | 153 } |
159 | 154 |
160 TEST_F(PlatformEventUtilsXTest, AvoidExtraEventsOnWheelRelease) { | 155 TEST_F(EventsXTest, AvoidExtraEventsOnWheelRelease) { |
161 XEvent event; | 156 XEvent event; |
162 gfx::Point location(5, 10); | 157 gfx::Point location(5, 10); |
163 | 158 |
164 InitButtonEvent(&event, true, location, 4, 0); | 159 InitButtonEvent(&event, true, location, 4, 0); |
165 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); | 160 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); |
166 | 161 |
167 // We should return ET_UNKNOWN for the release event instead of returning | 162 // We should return ET_UNKNOWN for the release event instead of returning |
168 // ET_MOUSEWHEEL; otherwise we'll scroll twice for each scrollwheel step. | 163 // ET_MOUSEWHEEL; otherwise we'll scroll twice for each scrollwheel step. |
169 InitButtonEvent(&event, false, location, 4, 0); | 164 InitButtonEvent(&event, false, location, 4, 0); |
170 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(&event)); | 165 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(&event)); |
171 | 166 |
172 // TODO(derat): Test XInput code. | 167 // TODO(derat): Test XInput code. |
173 } | 168 } |
174 | 169 |
175 TEST_F(PlatformEventUtilsXTest, EnterLeaveEvent) { | 170 TEST_F(EventsXTest, EnterLeaveEvent) { |
176 XEvent event; | 171 XEvent event; |
177 event.xcrossing.type = EnterNotify; | 172 event.xcrossing.type = EnterNotify; |
178 event.xcrossing.x = 10; | 173 event.xcrossing.x = 10; |
179 event.xcrossing.y = 20; | 174 event.xcrossing.y = 20; |
180 event.xcrossing.x_root = 110; | 175 event.xcrossing.x_root = 110; |
181 event.xcrossing.y_root = 120; | 176 event.xcrossing.y_root = 120; |
182 | 177 |
183 // Mouse enter events are converted to mouse move events to be consistent with | 178 // Mouse enter events are converted to mouse move events to be consistent with |
184 // the way views handle mouse enter. See comments for EnterNotify case in | 179 // the way views handle mouse enter. See comments for EnterNotify case in |
185 // ui::EventTypeFromNative for more details. | 180 // ui::EventTypeFromNative for more details. |
186 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(&event)); | 181 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(&event)); |
187 EXPECT_EQ("10,20", ui::EventLocationFromNative(&event).ToString()); | 182 EXPECT_EQ("10,20", ui::EventLocationFromNative(&event).ToString()); |
188 EXPECT_EQ("110,120", ui::EventSystemLocationFromNative(&event).ToString()); | 183 EXPECT_EQ("110,120", ui::EventSystemLocationFromNative(&event).ToString()); |
189 | 184 |
190 event.xcrossing.type = LeaveNotify; | 185 event.xcrossing.type = LeaveNotify; |
191 event.xcrossing.x = 30; | 186 event.xcrossing.x = 30; |
192 event.xcrossing.y = 40; | 187 event.xcrossing.y = 40; |
193 event.xcrossing.x_root = 230; | 188 event.xcrossing.x_root = 230; |
194 event.xcrossing.y_root = 240; | 189 event.xcrossing.y_root = 240; |
195 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(&event)); | 190 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(&event)); |
196 EXPECT_EQ("30,40", ui::EventLocationFromNative(&event).ToString()); | 191 EXPECT_EQ("30,40", ui::EventLocationFromNative(&event).ToString()); |
197 EXPECT_EQ("230,240", ui::EventSystemLocationFromNative(&event).ToString()); | 192 EXPECT_EQ("230,240", ui::EventSystemLocationFromNative(&event).ToString()); |
198 } | 193 } |
199 | 194 |
200 TEST_F(PlatformEventUtilsXTest, ClickCount) { | 195 TEST_F(EventsXTest, ClickCount) { |
201 XEvent event; | 196 XEvent event; |
202 gfx::Point location(5, 10); | 197 gfx::Point location(5, 10); |
203 | 198 |
| 199 base::TimeDelta time_stamp = base::TimeDelta::FromMilliseconds(1); |
204 for (int i = 1; i <= 3; ++i) { | 200 for (int i = 1; i <= 3; ++i) { |
205 InitButtonEvent(&event, true, location, 1, 0); | 201 InitButtonEvent(&event, true, location, 1, 0); |
206 { | 202 { |
207 MouseEvent mouseev = PlatformEventBuilder::BuildMouseEvent(&event); | 203 event.xbutton.time = time_stamp.InMilliseconds(); |
| 204 MouseEvent mouseev(&event); |
208 EXPECT_EQ(ui::ET_MOUSE_PRESSED, mouseev.type()); | 205 EXPECT_EQ(ui::ET_MOUSE_PRESSED, mouseev.type()); |
209 EXPECT_EQ(i, mouseev.GetClickCount()); | 206 EXPECT_EQ(i, mouseev.GetClickCount()); |
210 } | 207 } |
211 | 208 |
212 InitButtonEvent(&event, false, location, 1, 0); | 209 InitButtonEvent(&event, false, location, 1, 0); |
213 { | 210 { |
214 MouseEvent mouseev = PlatformEventBuilder::BuildMouseEvent(&event); | 211 event.xbutton.time = time_stamp.InMilliseconds(); |
| 212 MouseEvent mouseev(&event); |
215 EXPECT_EQ(ui::ET_MOUSE_RELEASED, mouseev.type()); | 213 EXPECT_EQ(ui::ET_MOUSE_RELEASED, mouseev.type()); |
216 EXPECT_EQ(i, mouseev.GetClickCount()); | 214 EXPECT_EQ(i, mouseev.GetClickCount()); |
217 } | 215 } |
| 216 time_stamp += base::TimeDelta::FromMilliseconds(1); |
218 } | 217 } |
219 } | 218 } |
220 | 219 |
221 #if defined(USE_XI2_MT) | 220 TEST_F(EventsXTest, TouchEventBasic) { |
222 TEST_F(PlatformEventUtilsXTest, TouchEventBasic) { | 221 std::vector<int> devices; |
223 std::vector<unsigned int> devices; | |
224 devices.push_back(0); | 222 devices.push_back(0); |
225 ui::SetUpTouchDevicesForTest(devices); | 223 ui::SetUpTouchDevicesForTest(devices); |
226 std::vector<Valuator> valuators; | 224 std::vector<Valuator> valuators; |
227 | 225 |
228 // Init touch begin with tracking id 5, touch id 0. | 226 // Init touch begin with tracking id 5, touch id 0. |
229 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 20)); | 227 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 20)); |
230 valuators.push_back( | 228 valuators.push_back( |
231 Valuator(DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.3f)); | 229 Valuator(DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.3f)); |
232 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 100)); | 230 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 100)); |
233 ui::ScopedXI2Event scoped_xevent; | 231 ui::ScopedXI2Event scoped_xevent; |
234 scoped_xevent.InitTouchEvent(0, XI_TouchBegin, 5, gfx::Point(10, 10), | 232 scoped_xevent.InitTouchEvent( |
235 valuators); | 233 0, XI_TouchBegin, 5, gfx::Point(10, 10), valuators); |
236 EXPECT_EQ(ui::ET_TOUCH_PRESSED, ui::EventTypeFromNative(scoped_xevent)); | 234 EXPECT_EQ(ui::ET_TOUCH_PRESSED, ui::EventTypeFromNative(scoped_xevent)); |
237 EXPECT_EQ("10,10", ui::EventLocationFromNative(scoped_xevent).ToString()); | 235 EXPECT_EQ("10,10", ui::EventLocationFromNative(scoped_xevent).ToString()); |
238 EXPECT_EQ(GetTouchId(scoped_xevent), 0); | 236 EXPECT_EQ(GetTouchId(scoped_xevent), 0); |
239 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); | 237 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); |
240 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.15f); | 238 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.15f); |
241 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.1f); | 239 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.1f); |
242 | 240 |
243 // Touch update, with new orientation info. | 241 // Touch update, with new orientation info. |
244 valuators.clear(); | 242 valuators.clear(); |
245 valuators.push_back( | 243 valuators.push_back( |
246 Valuator(DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.5f)); | 244 Valuator(DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.5f)); |
247 scoped_xevent.InitTouchEvent(0, XI_TouchUpdate, 5, gfx::Point(20, 20), | 245 scoped_xevent.InitTouchEvent( |
248 valuators); | 246 0, XI_TouchUpdate, 5, gfx::Point(20, 20), valuators); |
249 EXPECT_EQ(ui::ET_TOUCH_MOVED, ui::EventTypeFromNative(scoped_xevent)); | 247 EXPECT_EQ(ui::ET_TOUCH_MOVED, ui::EventTypeFromNative(scoped_xevent)); |
250 EXPECT_EQ("20,20", ui::EventLocationFromNative(scoped_xevent).ToString()); | 248 EXPECT_EQ("20,20", ui::EventLocationFromNative(scoped_xevent).ToString()); |
251 EXPECT_EQ(GetTouchId(scoped_xevent), 0); | 249 EXPECT_EQ(GetTouchId(scoped_xevent), 0); |
252 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); | 250 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); |
253 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.25f); | 251 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.25f); |
254 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.1f); | 252 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.1f); |
255 | 253 |
256 // Another touch with tracking id 6, touch id 1. | 254 // Another touch with tracking id 6, touch id 1. |
257 valuators.clear(); | 255 valuators.clear(); |
258 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 100)); | 256 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 100)); |
259 valuators.push_back( | 257 valuators.push_back(Valuator( |
260 Valuator(DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.9f)); | 258 DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.9f)); |
261 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 500)); | 259 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 500)); |
262 scoped_xevent.InitTouchEvent(0, XI_TouchBegin, 6, gfx::Point(200, 200), | 260 scoped_xevent.InitTouchEvent( |
263 valuators); | 261 0, XI_TouchBegin, 6, gfx::Point(200, 200), valuators); |
264 EXPECT_EQ(ui::ET_TOUCH_PRESSED, ui::EventTypeFromNative(scoped_xevent)); | 262 EXPECT_EQ(ui::ET_TOUCH_PRESSED, ui::EventTypeFromNative(scoped_xevent)); |
265 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); | 263 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); |
266 EXPECT_EQ(GetTouchId(scoped_xevent), 1); | 264 EXPECT_EQ(GetTouchId(scoped_xevent), 1); |
267 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 50); | 265 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 50); |
268 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); | 266 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); |
269 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); | 267 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); |
270 | 268 |
271 // Touch with tracking id 5 should have old radius/angle value and new pressue | 269 // Touch with tracking id 5 should have old radius/angle value and new pressue |
272 // value. | 270 // value. |
273 valuators.clear(); | 271 valuators.clear(); |
274 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 50)); | 272 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 50)); |
275 scoped_xevent.InitTouchEvent(0, XI_TouchEnd, 5, gfx::Point(30, 30), | 273 scoped_xevent.InitTouchEvent( |
276 valuators); | 274 0, XI_TouchEnd, 5, gfx::Point(30, 30), valuators); |
277 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); | 275 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); |
278 EXPECT_EQ("30,30", ui::EventLocationFromNative(scoped_xevent).ToString()); | 276 EXPECT_EQ("30,30", ui::EventLocationFromNative(scoped_xevent).ToString()); |
279 EXPECT_EQ(GetTouchId(scoped_xevent), 0); | 277 EXPECT_EQ(GetTouchId(scoped_xevent), 0); |
280 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); | 278 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); |
281 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.25f); | 279 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.25f); |
282 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.05f); | 280 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.05f); |
283 | 281 |
284 // Touch with tracking id 6 should have old angle/pressure value and new | 282 // Touch with tracking id 6 should have old angle/pressure value and new |
285 // radius value. | 283 // radius value. |
286 valuators.clear(); | 284 valuators.clear(); |
287 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 50)); | 285 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 50)); |
288 scoped_xevent.InitTouchEvent(0, XI_TouchEnd, 6, gfx::Point(200, 200), | 286 scoped_xevent.InitTouchEvent( |
289 valuators); | 287 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators); |
290 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); | 288 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); |
291 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); | 289 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); |
292 EXPECT_EQ(GetTouchId(scoped_xevent), 1); | 290 EXPECT_EQ(GetTouchId(scoped_xevent), 1); |
293 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); | 291 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); |
294 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); | 292 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); |
295 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); | 293 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); |
296 } | 294 } |
297 | 295 |
298 int GetTouchIdForTrackingId(uint32 tracking_id) { | 296 int GetTouchIdForTrackingId(uint32 tracking_id) { |
299 int slot = 0; | 297 int slot = 0; |
300 bool success = | 298 bool success = |
301 TouchFactory::GetInstance()->QuerySlotForTrackingID(tracking_id, &slot); | 299 TouchFactory::GetInstance()->QuerySlotForTrackingID(tracking_id, &slot); |
302 if (success) | 300 if (success) |
303 return slot; | 301 return slot; |
304 return -1; | 302 return -1; |
305 } | 303 } |
306 | 304 |
307 TEST_F(PlatformEventUtilsXTest, TouchEventIdRefcounting) { | 305 TEST_F(EventsXTest, TouchEventNotRemovingFromNativeMapping) { |
308 std::vector<unsigned int> devices; | 306 std::vector<int> devices; |
309 devices.push_back(0); | 307 devices.push_back(0); |
310 ui::SetUpTouchDevicesForTest(devices); | 308 ui::SetUpTouchDevicesForTest(devices); |
311 std::vector<Valuator> valuators; | 309 std::vector<Valuator> valuators; |
312 | 310 |
313 const int kTrackingId0 = 5; | 311 const int kTrackingId = 5; |
314 const int kTrackingId1 = 7; | |
315 | 312 |
316 // Increment ref count once for first touch. | 313 // Two touch presses with the same tracking id. |
317 ui::ScopedXI2Event xpress0; | 314 ui::ScopedXI2Event xpress0; |
318 xpress0.InitTouchEvent(0, XI_TouchBegin, kTrackingId0, gfx::Point(10, 10), | 315 xpress0.InitTouchEvent( |
319 valuators); | 316 0, XI_TouchBegin, kTrackingId, gfx::Point(10, 10), valuators); |
320 scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0)); | 317 scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0)); |
321 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId0)); | 318 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId)); |
322 | 319 |
323 // Increment ref count 4 times for second touch. | |
324 ui::ScopedXI2Event xpress1; | 320 ui::ScopedXI2Event xpress1; |
325 xpress1.InitTouchEvent(0, XI_TouchBegin, kTrackingId1, gfx::Point(20, 20), | 321 xpress1.InitTouchEvent( |
326 valuators); | 322 0, XI_TouchBegin, kTrackingId, gfx::Point(20, 20), valuators); |
| 323 ui::TouchEvent upress1(xpress1); |
| 324 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId)); |
327 | 325 |
328 for (int i = 0; i < 4; ++i) { | 326 // The first touch release shouldn't clear the mapping from the |
329 ui::TouchEvent upress1(xpress1); | 327 // tracking id. |
330 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); | 328 ui::ScopedXI2Event xrelease0; |
| 329 xrelease0.InitTouchEvent( |
| 330 0, XI_TouchEnd, kTrackingId, gfx::Point(10, 10), valuators); |
| 331 { |
| 332 ui::TouchEvent urelease0(xrelease0); |
| 333 urelease0.set_should_remove_native_touch_id_mapping(false); |
331 } | 334 } |
| 335 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId)); |
332 | 336 |
| 337 // The second touch release should clear the mapping from the |
| 338 // tracking id. |
333 ui::ScopedXI2Event xrelease1; | 339 ui::ScopedXI2Event xrelease1; |
334 xrelease1.InitTouchEvent(0, XI_TouchEnd, kTrackingId1, gfx::Point(10, 10), | 340 xrelease1.InitTouchEvent( |
335 valuators); | 341 0, XI_TouchEnd, kTrackingId, gfx::Point(10, 10), valuators); |
| 342 { |
| 343 ui::TouchEvent urelease1(xrelease1); |
| 344 } |
| 345 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId)); |
| 346 } |
336 | 347 |
337 // Decrement ref count 3 times for second touch. | 348 // Copied events should not remove native touch id mappings, as this causes a |
338 for (int i = 0; i < 3; ++i) { | 349 // crash (crbug.com/467102). Copied events do not contain a proper |
339 ui::TouchEvent urelease1(xrelease1); | 350 // base::NativeEvent and should not attempt to access it. |
340 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); | 351 TEST_F(EventsXTest, CopiedTouchEventNotRemovingFromNativeMapping) { |
341 } | 352 std::vector<int> devices; |
| 353 devices.push_back(0); |
| 354 ui::SetUpTouchDevicesForTest(devices); |
| 355 std::vector<Valuator> valuators; |
342 | 356 |
343 // This should clear the touch id of the second touch. | 357 // Create a release event which has a native touch id mapping. |
344 scoped_ptr<ui::TouchEvent> urelease1(new ui::TouchEvent(xrelease1)); | |
345 urelease1.reset(); | |
346 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId1)); | |
347 | |
348 // This should clear the touch id of the first touch. | |
349 ui::ScopedXI2Event xrelease0; | 358 ui::ScopedXI2Event xrelease0; |
350 xrelease0.InitTouchEvent(0, XI_TouchEnd, kTrackingId0, gfx::Point(10, 10), | 359 xrelease0.InitTouchEvent(0, XI_TouchEnd, 0, gfx::Point(10, 10), valuators); |
351 valuators); | 360 ui::TouchEvent urelease0(xrelease0); |
352 scoped_ptr<ui::TouchEvent> urelease0(new ui::TouchEvent(xrelease0)); | 361 { |
353 urelease0.reset(); | 362 // When the copy is destructed it should not attempt to remove the mapping. |
354 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId0)); | 363 // Exiting this scope should not cause a crash. |
355 } | 364 ui::TouchEvent copy = urelease0; |
356 #endif | |
357 | |
358 TEST_F(PlatformEventUtilsXTest, NumpadKeyEvents) { | |
359 XEvent event; | |
360 Display* display = gfx::GetXDisplay(); | |
361 | |
362 struct { | |
363 bool is_numpad_key; | |
364 int x_keysym; | |
365 } keys[] = { | |
366 // XK_KP_Space and XK_KP_Equal are the extrema in the conventional | |
367 // keysymdef.h numbering. | |
368 {true, XK_KP_Space}, | |
369 {true, XK_KP_Equal}, | |
370 // Other numpad keysyms. (This is actually exhaustive in the current | |
371 // list.) | |
372 {true, XK_KP_Tab}, | |
373 {true, XK_KP_Enter}, | |
374 {true, XK_KP_F1}, | |
375 {true, XK_KP_F2}, | |
376 {true, XK_KP_F3}, | |
377 {true, XK_KP_F4}, | |
378 {true, XK_KP_Home}, | |
379 {true, XK_KP_Left}, | |
380 {true, XK_KP_Up}, | |
381 {true, XK_KP_Right}, | |
382 {true, XK_KP_Down}, | |
383 {true, XK_KP_Prior}, | |
384 {true, XK_KP_Page_Up}, | |
385 {true, XK_KP_Next}, | |
386 {true, XK_KP_Page_Down}, | |
387 {true, XK_KP_End}, | |
388 {true, XK_KP_Begin}, | |
389 {true, XK_KP_Insert}, | |
390 {true, XK_KP_Delete}, | |
391 {true, XK_KP_Multiply}, | |
392 {true, XK_KP_Add}, | |
393 {true, XK_KP_Separator}, | |
394 {true, XK_KP_Subtract}, | |
395 {true, XK_KP_Decimal}, | |
396 {true, XK_KP_Divide}, | |
397 {true, XK_KP_0}, | |
398 {true, XK_KP_1}, | |
399 {true, XK_KP_2}, | |
400 {true, XK_KP_3}, | |
401 {true, XK_KP_4}, | |
402 {true, XK_KP_5}, | |
403 {true, XK_KP_6}, | |
404 {true, XK_KP_7}, | |
405 {true, XK_KP_8}, | |
406 {true, XK_KP_9}, | |
407 // Largest keysym preceding XK_KP_Space. | |
408 {false, XK_Num_Lock}, | |
409 // Smallest keysym following XK_KP_Equal. | |
410 {false, XK_F1}, | |
411 // Non-numpad analogues of numpad keysyms. | |
412 {false, XK_Tab}, | |
413 {false, XK_Return}, | |
414 {false, XK_F1}, | |
415 {false, XK_F2}, | |
416 {false, XK_F3}, | |
417 {false, XK_F4}, | |
418 {false, XK_Home}, | |
419 {false, XK_Left}, | |
420 {false, XK_Up}, | |
421 {false, XK_Right}, | |
422 {false, XK_Down}, | |
423 {false, XK_Prior}, | |
424 {false, XK_Page_Up}, | |
425 {false, XK_Next}, | |
426 {false, XK_Page_Down}, | |
427 {false, XK_End}, | |
428 {false, XK_Insert}, | |
429 {false, XK_Delete}, | |
430 {false, XK_multiply}, | |
431 {false, XK_plus}, | |
432 {false, XK_minus}, | |
433 {false, XK_period}, | |
434 {false, XK_slash}, | |
435 {false, XK_0}, | |
436 {false, XK_1}, | |
437 {false, XK_2}, | |
438 {false, XK_3}, | |
439 {false, XK_4}, | |
440 {false, XK_5}, | |
441 {false, XK_6}, | |
442 {false, XK_7}, | |
443 {false, XK_8}, | |
444 {false, XK_9}, | |
445 // Miscellaneous other keysyms. | |
446 {false, XK_BackSpace}, | |
447 {false, XK_Scroll_Lock}, | |
448 {false, XK_Multi_key}, | |
449 {false, XK_Select}, | |
450 {false, XK_Num_Lock}, | |
451 {false, XK_Shift_L}, | |
452 {false, XK_space}, | |
453 {false, XK_A}, | |
454 }; | |
455 | |
456 for (size_t k = 0; k < arraysize(keys); ++k) { | |
457 int x_keycode = XKeysymToKeycode(display, keys[k].x_keysym); | |
458 // Exclude keysyms for which the server has no corresponding keycode. | |
459 if (x_keycode) { | |
460 InitKeyEvent(display, &event, true, x_keycode, 0); | |
461 // int keysym = XLookupKeysym(&event.xkey, 0); | |
462 // if (keysym) { | |
463 ui::KeyEvent ui_key_event = PlatformEventBuilder::BuildKeyEvent(&event); | |
464 EXPECT_EQ(keys[k].is_numpad_key ? ui::EF_NUMPAD_KEY : 0, | |
465 ui_key_event.flags() & ui::EF_NUMPAD_KEY); | |
466 } | |
467 } | 365 } |
468 } | 366 } |
469 | 367 |
470 TEST_F(PlatformEventUtilsXTest, FunctionKeyEvents) { | |
471 Display* display = gfx::GetXDisplay(); | |
472 | |
473 // Min function key code minus 1. | |
474 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F1 - 1)); | |
475 // All function keys. | |
476 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F1)); | |
477 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F2)); | |
478 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F3)); | |
479 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F4)); | |
480 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F5)); | |
481 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F6)); | |
482 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F7)); | |
483 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F8)); | |
484 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F9)); | |
485 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F10)); | |
486 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F11)); | |
487 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F12)); | |
488 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F13)); | |
489 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F14)); | |
490 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F15)); | |
491 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F16)); | |
492 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F17)); | |
493 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F18)); | |
494 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F19)); | |
495 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F20)); | |
496 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F21)); | |
497 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F22)); | |
498 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F23)); | |
499 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F24)); | |
500 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F25)); | |
501 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F26)); | |
502 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F27)); | |
503 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F28)); | |
504 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F29)); | |
505 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F30)); | |
506 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F31)); | |
507 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F32)); | |
508 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F33)); | |
509 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F34)); | |
510 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F35)); | |
511 // Max function key code plus 1. | |
512 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1)); | |
513 } | |
514 | |
515 #if defined(USE_XI2_MT) | |
516 // Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but | 368 // Verifies that the type of events from a disabled keyboard is ET_UNKNOWN, but |
517 // that an exception list of keys can still be processed. | 369 // that an exception list of keys can still be processed. |
518 TEST_F(PlatformEventUtilsXTest, DisableKeyboard) { | 370 TEST_F(EventsXTest, DisableKeyboard) { |
519 DeviceDataManagerX11* device_data_manager = | 371 DeviceDataManagerX11* device_data_manager = |
520 static_cast<DeviceDataManagerX11*>(DeviceDataManager::GetInstance()); | 372 static_cast<DeviceDataManagerX11*>( |
521 unsigned int blocked_device_id = 1; | 373 DeviceDataManager::GetInstance()); |
522 unsigned int other_device_id = 2; | 374 int blocked_device_id = 1; |
523 unsigned int master_device_id = 3; | 375 int other_device_id = 2; |
| 376 int master_device_id = 3; |
524 device_data_manager->DisableDevice(blocked_device_id); | 377 device_data_manager->DisableDevice(blocked_device_id); |
525 | 378 |
526 scoped_ptr<std::set<KeyboardCode>> excepted_keys(new std::set<KeyboardCode>); | 379 scoped_ptr<std::set<KeyboardCode> > excepted_keys(new std::set<KeyboardCode>); |
527 excepted_keys->insert(VKEY_B); | 380 excepted_keys->insert(VKEY_B); |
528 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); | 381 device_data_manager->SetDisabledKeyboardAllowedKeys(excepted_keys.Pass()); |
529 | 382 |
530 ScopedXI2Event xev; | 383 ScopedXI2Event xev; |
531 // A is not allowed on the blocked keyboard, and should return ET_UNKNOWN. | 384 // A is not allowed on the blocked keyboard, and should return ET_UNKNOWN. |
532 xev.InitGenericKeyEvent(master_device_id, blocked_device_id, | 385 xev.InitGenericKeyEvent(master_device_id, |
533 ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | 386 blocked_device_id, |
| 387 ui::ET_KEY_PRESSED, |
| 388 ui::VKEY_A, |
| 389 0); |
534 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); | 390 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); |
535 | 391 |
536 // The B key is allowed as an exception, and should return KEY_PRESSED. | 392 // The B key is allowed as an exception, and should return KEY_PRESSED. |
537 xev.InitGenericKeyEvent(master_device_id, blocked_device_id, | 393 xev.InitGenericKeyEvent(master_device_id, |
538 ui::ET_KEY_PRESSED, ui::VKEY_B, 0); | 394 blocked_device_id, |
| 395 ui::ET_KEY_PRESSED, |
| 396 ui::VKEY_B, |
| 397 0); |
539 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); | 398 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); |
540 | 399 |
541 // Both A and B are allowed on an unblocked keyboard device. | 400 // Both A and B are allowed on an unblocked keyboard device. |
542 xev.InitGenericKeyEvent(master_device_id, other_device_id, ui::ET_KEY_PRESSED, | 401 xev.InitGenericKeyEvent(master_device_id, |
543 ui::VKEY_A, 0); | 402 other_device_id, |
| 403 ui::ET_KEY_PRESSED, |
| 404 ui::VKEY_A, |
| 405 0); |
544 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); | 406 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); |
545 xev.InitGenericKeyEvent(master_device_id, other_device_id, ui::ET_KEY_PRESSED, | 407 xev.InitGenericKeyEvent(master_device_id, |
546 ui::VKEY_B, 0); | 408 other_device_id, |
| 409 ui::ET_KEY_PRESSED, |
| 410 ui::VKEY_B, |
| 411 0); |
547 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); | 412 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); |
548 | 413 |
549 device_data_manager->EnableDevice(blocked_device_id); | 414 device_data_manager->EnableDevice(blocked_device_id); |
550 device_data_manager->SetDisabledKeyboardAllowedKeys( | 415 device_data_manager->SetDisabledKeyboardAllowedKeys(nullptr); |
551 scoped_ptr<std::set<KeyboardCode>>()); | |
552 | 416 |
553 // A key returns KEY_PRESSED as per usual now that keyboard was re-enabled. | 417 // A key returns KEY_PRESSED as per usual now that keyboard was re-enabled. |
554 xev.InitGenericKeyEvent(master_device_id, blocked_device_id, | 418 xev.InitGenericKeyEvent(master_device_id, |
555 ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | 419 blocked_device_id, |
| 420 ui::ET_KEY_PRESSED, |
| 421 ui::VKEY_A, |
| 422 0); |
556 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); | 423 EXPECT_EQ(ui::ET_KEY_PRESSED, ui::EventTypeFromNative(xev)); |
557 } | 424 } |
558 | 425 |
559 // Verifies that the type of events from a disabled mouse is ET_UNKNOWN. | 426 // Verifies that the type of events from a disabled mouse is ET_UNKNOWN. |
560 TEST_F(PlatformEventUtilsXTest, DisableMouse) { | 427 TEST_F(EventsXTest, DisableMouse) { |
561 DeviceDataManagerX11* device_data_manager = | 428 DeviceDataManagerX11* device_data_manager = |
562 static_cast<DeviceDataManagerX11*>(DeviceDataManager::GetInstance()); | 429 static_cast<DeviceDataManagerX11*>( |
563 unsigned int blocked_device_id = 1; | 430 DeviceDataManager::GetInstance()); |
564 unsigned int other_device_id = 2; | 431 int blocked_device_id = 1; |
565 std::vector<unsigned int> device_list; | 432 int other_device_id = 2; |
| 433 std::vector<int> device_list; |
566 device_list.push_back(blocked_device_id); | 434 device_list.push_back(blocked_device_id); |
567 device_list.push_back(other_device_id); | 435 device_list.push_back(other_device_id); |
568 TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); | 436 TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); |
569 | 437 |
570 device_data_manager->DisableDevice(blocked_device_id); | 438 device_data_manager->DisableDevice(blocked_device_id); |
571 | 439 |
572 ScopedXI2Event xev; | 440 ScopedXI2Event xev; |
573 xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(), | 441 xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
574 EF_LEFT_MOUSE_BUTTON); | 442 EF_LEFT_MOUSE_BUTTON); |
575 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); | 443 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); |
576 | 444 |
577 xev.InitGenericButtonEvent(other_device_id, ET_MOUSE_PRESSED, gfx::Point(), | 445 xev.InitGenericButtonEvent(other_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
578 EF_LEFT_MOUSE_BUTTON); | 446 EF_LEFT_MOUSE_BUTTON); |
579 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev)); | 447 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev)); |
580 | 448 |
581 device_data_manager->EnableDevice(blocked_device_id); | 449 device_data_manager->EnableDevice(blocked_device_id); |
582 | 450 |
583 xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(), | 451 xev.InitGenericButtonEvent(blocked_device_id, ET_MOUSE_PRESSED, gfx::Point(), |
584 EF_LEFT_MOUSE_BUTTON); | 452 EF_LEFT_MOUSE_BUTTON); |
585 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev)); | 453 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(xev)); |
586 } | 454 } |
587 #endif // defined(USE_XI2_MT) | |
588 | 455 |
589 #if !defined(OS_CHROMEOS) | 456 #if !defined(OS_CHROMEOS) |
590 TEST_F(PlatformEventUtilsXTest, ImeFabricatedKeyEvents) { | 457 TEST_F(EventsXTest, ImeFabricatedKeyEvents) { |
591 Display* display = gfx::GetXDisplay(); | 458 Display* display = gfx::GetXDisplay(); |
592 | 459 |
593 unsigned int state_to_be_fabricated[] = { | 460 unsigned int state_to_be_fabricated[] = { |
594 0, ShiftMask, LockMask, ShiftMask | LockMask, | 461 0, ShiftMask, LockMask, ShiftMask | LockMask, |
595 }; | 462 }; |
596 for (size_t i = 0; i < arraysize(state_to_be_fabricated); ++i) { | 463 for (size_t i = 0; i < arraysize(state_to_be_fabricated); ++i) { |
597 unsigned int state = state_to_be_fabricated[i]; | 464 unsigned int state = state_to_be_fabricated[i]; |
598 for (int is_char = 0; is_char < 2; ++is_char) { | 465 for (int is_char = 0; is_char < 2; ++is_char) { |
599 XEvent x_event; | 466 XEvent x_event; |
600 InitKeyEvent(display, &x_event, true, 0, state); | 467 InitKeyEvent(display, &x_event, true, 0, state); |
601 ui::KeyEvent key_event = PlatformEventBuilder::BuildKeyEvent(&x_event); | 468 ui::KeyEvent key_event(&x_event); |
602 if (is_char) { | 469 if (is_char) { |
603 KeyEventTestApi test_event(&key_event); | 470 KeyEventTestApi test_event(&key_event); |
604 test_event.set_is_char(true); | 471 test_event.set_is_char(true); |
605 } | 472 } |
606 EXPECT_TRUE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 473 EXPECT_TRUE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
607 } | 474 } |
608 } | 475 } |
609 | 476 |
610 unsigned int state_to_be_not_fabricated[] = { | 477 unsigned int state_to_be_not_fabricated[] = { |
611 ControlMask, Mod1Mask, Mod2Mask, ShiftMask | ControlMask, | 478 ControlMask, Mod1Mask, Mod2Mask, ShiftMask | ControlMask, |
612 }; | 479 }; |
613 for (size_t i = 0; i < arraysize(state_to_be_not_fabricated); ++i) { | 480 for (size_t i = 0; i < arraysize(state_to_be_not_fabricated); ++i) { |
614 unsigned int state = state_to_be_not_fabricated[i]; | 481 unsigned int state = state_to_be_not_fabricated[i]; |
615 for (int is_char = 0; is_char < 2; ++is_char) { | 482 for (int is_char = 0; is_char < 2; ++is_char) { |
616 XEvent x_event; | 483 XEvent x_event; |
617 InitKeyEvent(display, &x_event, true, 0, state); | 484 InitKeyEvent(display, &x_event, true, 0, state); |
618 ui::KeyEvent key_event = PlatformEventBuilder::BuildKeyEvent(&x_event); | 485 ui::KeyEvent key_event(&x_event); |
619 if (is_char) { | 486 if (is_char) { |
620 KeyEventTestApi test_event(&key_event); | 487 KeyEventTestApi test_event(&key_event); |
621 test_event.set_is_char(true); | 488 test_event.set_is_char(true); |
622 } | 489 } |
623 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 490 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
624 } | 491 } |
625 } | 492 } |
626 } | 493 } |
627 #endif | 494 #endif |
628 | 495 |
| 496 TEST_F(EventsXTest, IgnoresMotionEventForMouseWheelScroll) { |
| 497 int device_id = 1; |
| 498 std::vector<int> devices; |
| 499 devices.push_back(device_id); |
| 500 ui::SetUpPointerDevicesForTest(devices); |
| 501 |
| 502 ScopedXI2Event xev; |
| 503 xev.InitScrollEvent(device_id, 1, 2, 3, 4, 1); |
| 504 // We shouldn't produce a mouse move event on a mouse wheel |
| 505 // scroll. These events are only produced for some mice. |
| 506 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(xev)); |
| 507 } |
| 508 |
629 } // namespace ui | 509 } // namespace ui |
OLD | NEW |