| 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 | 6 |
| 7 #include <X11/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #include <X11/Xutil.h> | 9 #include <X11/Xutil.h> |
| 10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
| 11 | 11 |
| 12 // Generically-named #defines from Xlib that conflict with symbols in GTest. | 12 // Generically-named #defines from Xlib that conflict with symbols in GTest. |
| 13 #undef Bool | 13 #undef Bool |
| 14 #undef None | 14 #undef None |
| 15 | 15 |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 18 #include "ui/events/event_constants.h" | 18 #include "ui/events/event_constants.h" |
| 19 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
| 20 #include "ui/events/test/events_test_utils_x11.h" | 20 #include "ui/events/test/events_test_utils_x11.h" |
| 21 #include "ui/events/x/device_data_manager_x11.h" |
| 21 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
| 22 | 23 |
| 23 namespace ui { | 24 namespace ui { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Initializes the passed-in Xlib event. | 28 // Initializes the passed-in Xlib event. |
| 28 void InitButtonEvent(XEvent* event, | 29 void InitButtonEvent(XEvent* event, |
| 29 bool is_press, | 30 bool is_press, |
| 30 const gfx::Point& location, | 31 const gfx::Point& location, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (x_keycode) { | 69 if (x_keycode) { |
| 69 InitKeyEvent(display, &event, true, x_keycode, 0); | 70 InitKeyEvent(display, &event, true, x_keycode, 0); |
| 70 ui::KeyEvent ui_key_event(&event, false); | 71 ui::KeyEvent ui_key_event(&event, false); |
| 71 return (ui_key_event.flags() & ui::EF_FUNCTION_KEY); | 72 return (ui_key_event.flags() & ui::EF_FUNCTION_KEY); |
| 72 } | 73 } |
| 73 return true; | 74 return true; |
| 74 } | 75 } |
| 75 | 76 |
| 76 } // namespace | 77 } // namespace |
| 77 | 78 |
| 78 TEST(EventsXTest, ButtonEvents) { | 79 class EventsXTest : public testing::Test { |
| 80 public: |
| 81 EventsXTest() {} |
| 82 virtual ~EventsXTest() {} |
| 83 |
| 84 virtual void SetUp() OVERRIDE { |
| 85 DeviceDataManagerX11::CreateInstance(); |
| 86 } |
| 87 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(EventsXTest); |
| 89 }; |
| 90 |
| 91 TEST_F(EventsXTest, ButtonEvents) { |
| 79 XEvent event; | 92 XEvent event; |
| 80 gfx::Point location(5, 10); | 93 gfx::Point location(5, 10); |
| 81 gfx::Vector2d offset; | 94 gfx::Vector2d offset; |
| 82 | 95 |
| 83 InitButtonEvent(&event, true, location, 1, 0); | 96 InitButtonEvent(&event, true, location, 1, 0); |
| 84 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(&event)); | 97 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(&event)); |
| 85 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, ui::EventFlagsFromNative(&event)); | 98 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, ui::EventFlagsFromNative(&event)); |
| 86 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 99 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
| 87 | 100 |
| 88 InitButtonEvent(&event, true, location, 2, Button1Mask | ShiftMask); | 101 InitButtonEvent(&event, true, location, 2, Button1Mask | ShiftMask); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); | 142 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); |
| 130 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); | 143 EXPECT_EQ(0, ui::EventFlagsFromNative(&event)); |
| 131 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); | 144 EXPECT_EQ(location, ui::EventLocationFromNative(&event)); |
| 132 offset = ui::GetMouseWheelOffset(&event); | 145 offset = ui::GetMouseWheelOffset(&event); |
| 133 EXPECT_EQ(0, offset.y()); | 146 EXPECT_EQ(0, offset.y()); |
| 134 EXPECT_LT(offset.x(), 0); | 147 EXPECT_LT(offset.x(), 0); |
| 135 | 148 |
| 136 // TODO(derat): Test XInput code. | 149 // TODO(derat): Test XInput code. |
| 137 } | 150 } |
| 138 | 151 |
| 139 TEST(EventsXTest, AvoidExtraEventsOnWheelRelease) { | 152 TEST_F(EventsXTest, AvoidExtraEventsOnWheelRelease) { |
| 140 XEvent event; | 153 XEvent event; |
| 141 gfx::Point location(5, 10); | 154 gfx::Point location(5, 10); |
| 142 | 155 |
| 143 InitButtonEvent(&event, true, location, 4, 0); | 156 InitButtonEvent(&event, true, location, 4, 0); |
| 144 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); | 157 EXPECT_EQ(ui::ET_MOUSEWHEEL, ui::EventTypeFromNative(&event)); |
| 145 | 158 |
| 146 // We should return ET_UNKNOWN for the release event instead of returning | 159 // We should return ET_UNKNOWN for the release event instead of returning |
| 147 // ET_MOUSEWHEEL; otherwise we'll scroll twice for each scrollwheel step. | 160 // ET_MOUSEWHEEL; otherwise we'll scroll twice for each scrollwheel step. |
| 148 InitButtonEvent(&event, false, location, 4, 0); | 161 InitButtonEvent(&event, false, location, 4, 0); |
| 149 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(&event)); | 162 EXPECT_EQ(ui::ET_UNKNOWN, ui::EventTypeFromNative(&event)); |
| 150 | 163 |
| 151 // TODO(derat): Test XInput code. | 164 // TODO(derat): Test XInput code. |
| 152 } | 165 } |
| 153 | 166 |
| 154 TEST(EventsXTest, EnterLeaveEvent) { | 167 TEST_F(EventsXTest, EnterLeaveEvent) { |
| 155 XEvent event; | 168 XEvent event; |
| 156 event.xcrossing.type = EnterNotify; | 169 event.xcrossing.type = EnterNotify; |
| 157 event.xcrossing.x = 10; | 170 event.xcrossing.x = 10; |
| 158 event.xcrossing.y = 20; | 171 event.xcrossing.y = 20; |
| 159 event.xcrossing.x_root = 110; | 172 event.xcrossing.x_root = 110; |
| 160 event.xcrossing.y_root = 120; | 173 event.xcrossing.y_root = 120; |
| 161 | 174 |
| 162 // Mouse enter events are converted to mouse move events to be consistent with | 175 // Mouse enter events are converted to mouse move events to be consistent with |
| 163 // the way views handle mouse enter. See comments for EnterNotify case in | 176 // the way views handle mouse enter. See comments for EnterNotify case in |
| 164 // ui::EventTypeFromNative for more details. | 177 // ui::EventTypeFromNative for more details. |
| 165 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(&event)); | 178 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(&event)); |
| 166 EXPECT_EQ("10,20", ui::EventLocationFromNative(&event).ToString()); | 179 EXPECT_EQ("10,20", ui::EventLocationFromNative(&event).ToString()); |
| 167 EXPECT_EQ("110,120", ui::EventSystemLocationFromNative(&event).ToString()); | 180 EXPECT_EQ("110,120", ui::EventSystemLocationFromNative(&event).ToString()); |
| 168 | 181 |
| 169 event.xcrossing.type = LeaveNotify; | 182 event.xcrossing.type = LeaveNotify; |
| 170 event.xcrossing.x = 30; | 183 event.xcrossing.x = 30; |
| 171 event.xcrossing.y = 40; | 184 event.xcrossing.y = 40; |
| 172 event.xcrossing.x_root = 230; | 185 event.xcrossing.x_root = 230; |
| 173 event.xcrossing.y_root = 240; | 186 event.xcrossing.y_root = 240; |
| 174 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(&event)); | 187 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(&event)); |
| 175 EXPECT_EQ("30,40", ui::EventLocationFromNative(&event).ToString()); | 188 EXPECT_EQ("30,40", ui::EventLocationFromNative(&event).ToString()); |
| 176 EXPECT_EQ("230,240", ui::EventSystemLocationFromNative(&event).ToString()); | 189 EXPECT_EQ("230,240", ui::EventSystemLocationFromNative(&event).ToString()); |
| 177 } | 190 } |
| 178 | 191 |
| 179 TEST(EventsXTest, ClickCount) { | 192 TEST_F(EventsXTest, ClickCount) { |
| 180 XEvent event; | 193 XEvent event; |
| 181 gfx::Point location(5, 10); | 194 gfx::Point location(5, 10); |
| 182 | 195 |
| 183 for (int i = 1; i <= 3; ++i) { | 196 for (int i = 1; i <= 3; ++i) { |
| 184 InitButtonEvent(&event, true, location, 1, 0); | 197 InitButtonEvent(&event, true, location, 1, 0); |
| 185 { | 198 { |
| 186 MouseEvent mouseev(&event); | 199 MouseEvent mouseev(&event); |
| 187 EXPECT_EQ(ui::ET_MOUSE_PRESSED, mouseev.type()); | 200 EXPECT_EQ(ui::ET_MOUSE_PRESSED, mouseev.type()); |
| 188 EXPECT_EQ(i, mouseev.GetClickCount()); | 201 EXPECT_EQ(i, mouseev.GetClickCount()); |
| 189 } | 202 } |
| 190 | 203 |
| 191 InitButtonEvent(&event, false, location, 1, 0); | 204 InitButtonEvent(&event, false, location, 1, 0); |
| 192 { | 205 { |
| 193 MouseEvent mouseev(&event); | 206 MouseEvent mouseev(&event); |
| 194 EXPECT_EQ(ui::ET_MOUSE_RELEASED, mouseev.type()); | 207 EXPECT_EQ(ui::ET_MOUSE_RELEASED, mouseev.type()); |
| 195 EXPECT_EQ(i, mouseev.GetClickCount()); | 208 EXPECT_EQ(i, mouseev.GetClickCount()); |
| 196 } | 209 } |
| 197 } | 210 } |
| 198 } | 211 } |
| 199 | 212 |
| 200 #if defined(USE_XI2_MT) | 213 #if defined(USE_XI2_MT) |
| 201 TEST(EventsXTest, TouchEventBasic) { | 214 TEST_F(EventsXTest, TouchEventBasic) { |
| 202 std::vector<unsigned int> devices; | 215 std::vector<unsigned int> devices; |
| 203 devices.push_back(0); | 216 devices.push_back(0); |
| 204 ui::SetUpTouchDevicesForTest(devices); | 217 ui::SetUpTouchDevicesForTest(devices); |
| 205 std::vector<Valuator> valuators; | 218 std::vector<Valuator> valuators; |
| 206 | 219 |
| 207 // Init touch begin with tracking id 5, touch id 0. | 220 // Init touch begin with tracking id 5, touch id 0. |
| 208 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_MAJOR, 20)); | 221 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 20)); |
| 209 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_ORIENTATION, 0.3f)); | 222 valuators.push_back( |
| 210 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_PRESSURE, 100)); | 223 Valuator(DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.3f)); |
| 224 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 100)); |
| 211 ui::ScopedXI2Event scoped_xevent; | 225 ui::ScopedXI2Event scoped_xevent; |
| 212 scoped_xevent.InitTouchEvent( | 226 scoped_xevent.InitTouchEvent( |
| 213 0, XI_TouchBegin, 5, gfx::Point(10, 10), valuators); | 227 0, XI_TouchBegin, 5, gfx::Point(10, 10), valuators); |
| 214 EXPECT_EQ(ui::ET_TOUCH_PRESSED, ui::EventTypeFromNative(scoped_xevent)); | 228 EXPECT_EQ(ui::ET_TOUCH_PRESSED, ui::EventTypeFromNative(scoped_xevent)); |
| 215 EXPECT_EQ("10,10", ui::EventLocationFromNative(scoped_xevent).ToString()); | 229 EXPECT_EQ("10,10", ui::EventLocationFromNative(scoped_xevent).ToString()); |
| 216 EXPECT_EQ(GetTouchId(scoped_xevent), 0); | 230 EXPECT_EQ(GetTouchId(scoped_xevent), 0); |
| 217 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); | 231 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); |
| 218 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.15f); | 232 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.15f); |
| 219 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.1f); | 233 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.1f); |
| 220 | 234 |
| 221 // Touch update, with new orientation info. | 235 // Touch update, with new orientation info. |
| 222 valuators.clear(); | 236 valuators.clear(); |
| 223 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_ORIENTATION, 0.5f)); | 237 valuators.push_back( |
| 238 Valuator(DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.5f)); |
| 224 scoped_xevent.InitTouchEvent( | 239 scoped_xevent.InitTouchEvent( |
| 225 0, XI_TouchUpdate, 5, gfx::Point(20, 20), valuators); | 240 0, XI_TouchUpdate, 5, gfx::Point(20, 20), valuators); |
| 226 EXPECT_EQ(ui::ET_TOUCH_MOVED, ui::EventTypeFromNative(scoped_xevent)); | 241 EXPECT_EQ(ui::ET_TOUCH_MOVED, ui::EventTypeFromNative(scoped_xevent)); |
| 227 EXPECT_EQ("20,20", ui::EventLocationFromNative(scoped_xevent).ToString()); | 242 EXPECT_EQ("20,20", ui::EventLocationFromNative(scoped_xevent).ToString()); |
| 228 EXPECT_EQ(GetTouchId(scoped_xevent), 0); | 243 EXPECT_EQ(GetTouchId(scoped_xevent), 0); |
| 229 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); | 244 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); |
| 230 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.25f); | 245 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.25f); |
| 231 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.1f); | 246 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.1f); |
| 232 | 247 |
| 233 // Another touch with tracking id 6, touch id 1. | 248 // Another touch with tracking id 6, touch id 1. |
| 234 valuators.clear(); | 249 valuators.clear(); |
| 235 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_MAJOR, 100)); | 250 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 100)); |
| 236 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_ORIENTATION, 0.9f)); | 251 valuators.push_back(Valuator( |
| 237 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_PRESSURE, 500)); | 252 DeviceDataManagerX11::DT_TOUCH_ORIENTATION, 0.9f)); |
| 253 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 500)); |
| 238 scoped_xevent.InitTouchEvent( | 254 scoped_xevent.InitTouchEvent( |
| 239 0, XI_TouchBegin, 6, gfx::Point(200, 200), valuators); | 255 0, XI_TouchBegin, 6, gfx::Point(200, 200), valuators); |
| 240 EXPECT_EQ(ui::ET_TOUCH_PRESSED, ui::EventTypeFromNative(scoped_xevent)); | 256 EXPECT_EQ(ui::ET_TOUCH_PRESSED, ui::EventTypeFromNative(scoped_xevent)); |
| 241 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); | 257 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); |
| 242 EXPECT_EQ(GetTouchId(scoped_xevent), 1); | 258 EXPECT_EQ(GetTouchId(scoped_xevent), 1); |
| 243 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 50); | 259 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 50); |
| 244 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); | 260 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); |
| 245 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); | 261 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); |
| 246 | 262 |
| 247 // Touch with tracking id 5 should have old radius/angle value and new pressue | 263 // Touch with tracking id 5 should have old radius/angle value and new pressue |
| 248 // value. | 264 // value. |
| 249 valuators.clear(); | 265 valuators.clear(); |
| 250 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_PRESSURE, 50)); | 266 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_PRESSURE, 50)); |
| 251 scoped_xevent.InitTouchEvent( | 267 scoped_xevent.InitTouchEvent( |
| 252 0, XI_TouchEnd, 5, gfx::Point(30, 30), valuators); | 268 0, XI_TouchEnd, 5, gfx::Point(30, 30), valuators); |
| 253 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); | 269 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); |
| 254 EXPECT_EQ("30,30", ui::EventLocationFromNative(scoped_xevent).ToString()); | 270 EXPECT_EQ("30,30", ui::EventLocationFromNative(scoped_xevent).ToString()); |
| 255 EXPECT_EQ(GetTouchId(scoped_xevent), 0); | 271 EXPECT_EQ(GetTouchId(scoped_xevent), 0); |
| 256 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); | 272 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 10); |
| 257 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.25f); | 273 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.25f); |
| 258 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.05f); | 274 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.05f); |
| 259 | 275 |
| 260 // Touch with tracking id 6 should have old angle/pressure value and new | 276 // Touch with tracking id 6 should have old angle/pressure value and new |
| 261 // radius value. | 277 // radius value. |
| 262 valuators.clear(); | 278 valuators.clear(); |
| 263 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_MAJOR, 50)); | 279 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 50)); |
| 264 scoped_xevent.InitTouchEvent( | 280 scoped_xevent.InitTouchEvent( |
| 265 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators); | 281 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators); |
| 266 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); | 282 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); |
| 267 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); | 283 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); |
| 268 EXPECT_EQ(GetTouchId(scoped_xevent), 1); | 284 EXPECT_EQ(GetTouchId(scoped_xevent), 1); |
| 269 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); | 285 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); |
| 270 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); | 286 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); |
| 271 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); | 287 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); |
| 272 } | 288 } |
| 273 #endif | 289 #endif |
| 274 | 290 |
| 275 TEST(EventsXTest, NumpadKeyEvents) { | 291 TEST_F(EventsXTest, NumpadKeyEvents) { |
| 276 XEvent event; | 292 XEvent event; |
| 277 Display* display = gfx::GetXDisplay(); | 293 Display* display = gfx::GetXDisplay(); |
| 278 | 294 |
| 279 struct { | 295 struct { |
| 280 bool is_numpad_key; | 296 bool is_numpad_key; |
| 281 int x_keysym; | 297 int x_keysym; |
| 282 } keys[] = { | 298 } keys[] = { |
| 283 // XK_KP_Space and XK_KP_Equal are the extrema in the conventional | 299 // XK_KP_Space and XK_KP_Equal are the extrema in the conventional |
| 284 // keysymdef.h numbering. | 300 // keysymdef.h numbering. |
| 285 { true, XK_KP_Space }, | 301 { true, XK_KP_Space }, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 InitKeyEvent(display, &event, true, x_keycode, 0); | 392 InitKeyEvent(display, &event, true, x_keycode, 0); |
| 377 // int keysym = XLookupKeysym(&event.xkey, 0); | 393 // int keysym = XLookupKeysym(&event.xkey, 0); |
| 378 // if (keysym) { | 394 // if (keysym) { |
| 379 ui::KeyEvent ui_key_event(&event, false); | 395 ui::KeyEvent ui_key_event(&event, false); |
| 380 EXPECT_EQ(keys[k].is_numpad_key ? ui::EF_NUMPAD_KEY : 0, | 396 EXPECT_EQ(keys[k].is_numpad_key ? ui::EF_NUMPAD_KEY : 0, |
| 381 ui_key_event.flags() & ui::EF_NUMPAD_KEY); | 397 ui_key_event.flags() & ui::EF_NUMPAD_KEY); |
| 382 } | 398 } |
| 383 } | 399 } |
| 384 } | 400 } |
| 385 | 401 |
| 386 TEST(EventsXTest, FunctionKeyEvents) { | 402 TEST_F(EventsXTest, FunctionKeyEvents) { |
| 387 Display* display = gfx::GetXDisplay(); | 403 Display* display = gfx::GetXDisplay(); |
| 388 | 404 |
| 389 // Min function key code minus 1. | 405 // Min function key code minus 1. |
| 390 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F1 - 1)); | 406 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F1 - 1)); |
| 391 // All function keys. | 407 // All function keys. |
| 392 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F1)); | 408 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F1)); |
| 393 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F2)); | 409 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F2)); |
| 394 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F3)); | 410 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F3)); |
| 395 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F4)); | 411 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F4)); |
| 396 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F5)); | 412 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F5)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 422 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F31)); | 438 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F31)); |
| 423 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F32)); | 439 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F32)); |
| 424 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F33)); | 440 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F33)); |
| 425 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F34)); | 441 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F34)); |
| 426 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F35)); | 442 EXPECT_TRUE(HasFunctionKeyFlagSetIfSupported(display, XK_F35)); |
| 427 // Max function key code plus 1. | 443 // Max function key code plus 1. |
| 428 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1)); | 444 EXPECT_FALSE(HasFunctionKeyFlagSetIfSupported(display, XK_F35 + 1)); |
| 429 } | 445 } |
| 430 | 446 |
| 431 #if !defined(OS_CHROMEOS) | 447 #if !defined(OS_CHROMEOS) |
| 432 TEST(EventsXTest, ImeFabricatedKeyEvents) { | 448 TEST_F(EventsXTest, ImeFabricatedKeyEvents) { |
| 433 Display* display = gfx::GetXDisplay(); | 449 Display* display = gfx::GetXDisplay(); |
| 434 | 450 |
| 435 unsigned int state_to_be_fabricated[] = { | 451 unsigned int state_to_be_fabricated[] = { |
| 436 0, ShiftMask, LockMask, ShiftMask | LockMask, | 452 0, ShiftMask, LockMask, ShiftMask | LockMask, |
| 437 }; | 453 }; |
| 438 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(state_to_be_fabricated); ++i) { | 454 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(state_to_be_fabricated); ++i) { |
| 439 unsigned int state = state_to_be_fabricated[i]; | 455 unsigned int state = state_to_be_fabricated[i]; |
| 440 for (int is_char = 0; is_char < 2; ++is_char) { | 456 for (int is_char = 0; is_char < 2; ++is_char) { |
| 441 XEvent x_event; | 457 XEvent x_event; |
| 442 InitKeyEvent(display, &x_event, true, 0, state); | 458 InitKeyEvent(display, &x_event, true, 0, state); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 454 XEvent x_event; | 470 XEvent x_event; |
| 455 InitKeyEvent(display, &x_event, true, 0, state); | 471 InitKeyEvent(display, &x_event, true, 0, state); |
| 456 ui::KeyEvent key_event(&x_event, is_char); | 472 ui::KeyEvent key_event(&x_event, is_char); |
| 457 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 473 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
| 458 } | 474 } |
| 459 } | 475 } |
| 460 } | 476 } |
| 461 #endif | 477 #endif |
| 462 | 478 |
| 463 } // namespace ui | 479 } // namespace ui |
| OLD | NEW |