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/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 50)); | 282 valuators.push_back(Valuator(DeviceDataManagerX11::DT_TOUCH_MAJOR, 50)); |
283 scoped_xevent.InitTouchEvent( | 283 scoped_xevent.InitTouchEvent( |
284 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators); | 284 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators); |
285 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); | 285 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); |
286 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); | 286 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); |
287 EXPECT_EQ(GetTouchId(scoped_xevent), 1); | 287 EXPECT_EQ(GetTouchId(scoped_xevent), 1); |
288 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); | 288 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); |
289 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); | 289 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); |
290 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); | 290 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); |
291 } | 291 } |
| 292 |
| 293 int GetTouchIdForTrackingId(uint32 tracking_id) { |
| 294 int slot = 0; |
| 295 bool success = |
| 296 TouchFactory::GetInstance()->QuerySlotForTrackingID(tracking_id, &slot); |
| 297 if (success) |
| 298 return slot; |
| 299 return -1; |
| 300 } |
| 301 |
| 302 TEST_F(EventsXTest, TouchEventIdRefcounting) { |
| 303 std::vector<unsigned int> devices; |
| 304 devices.push_back(0); |
| 305 ui::SetUpTouchDevicesForTest(devices); |
| 306 std::vector<Valuator> valuators; |
| 307 |
| 308 const int kTrackingId0 = 5; |
| 309 const int kTrackingId1 = 7; |
| 310 |
| 311 // Increment ref count once for first touch. |
| 312 ui::ScopedXI2Event xpress0; |
| 313 xpress0.InitTouchEvent( |
| 314 0, XI_TouchBegin, kTrackingId0, gfx::Point(10, 10), valuators); |
| 315 scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0)); |
| 316 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId0)); |
| 317 |
| 318 // Increment ref count 4 times for second touch. |
| 319 ui::ScopedXI2Event xpress1; |
| 320 xpress1.InitTouchEvent( |
| 321 0, XI_TouchBegin, kTrackingId1, gfx::Point(20, 20), valuators); |
| 322 |
| 323 for (int i = 0; i < 4; ++i) { |
| 324 ui::TouchEvent upress1(xpress1); |
| 325 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); |
| 326 } |
| 327 |
| 328 ui::ScopedXI2Event xrelease1; |
| 329 xrelease1.InitTouchEvent( |
| 330 0, XI_TouchEnd, kTrackingId1, gfx::Point(10, 10), valuators); |
| 331 |
| 332 // Decrement ref count 3 times for second touch. |
| 333 for (int i = 0; i < 3; ++i) { |
| 334 ui::TouchEvent urelease1(xrelease1); |
| 335 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); |
| 336 } |
| 337 |
| 338 // This should clear the touch id of the second touch. |
| 339 scoped_ptr<ui::TouchEvent> urelease1(new ui::TouchEvent(xrelease1)); |
| 340 urelease1.reset(); |
| 341 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId1)); |
| 342 |
| 343 // This should clear the touch id of the first touch. |
| 344 ui::ScopedXI2Event xrelease0; |
| 345 xrelease0.InitTouchEvent( |
| 346 0, XI_TouchEnd, kTrackingId0, gfx::Point(10, 10), valuators); |
| 347 scoped_ptr<ui::TouchEvent> urelease0(new ui::TouchEvent(xrelease0)); |
| 348 urelease0.reset(); |
| 349 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId0)); |
| 350 } |
292 #endif | 351 #endif |
293 | 352 |
294 TEST_F(EventsXTest, NumpadKeyEvents) { | 353 TEST_F(EventsXTest, NumpadKeyEvents) { |
295 XEvent event; | 354 XEvent event; |
296 Display* display = gfx::GetXDisplay(); | 355 Display* display = gfx::GetXDisplay(); |
297 | 356 |
298 struct { | 357 struct { |
299 bool is_numpad_key; | 358 bool is_numpad_key; |
300 int x_keysym; | 359 int x_keysym; |
301 } keys[] = { | 360 } keys[] = { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 XEvent x_event; | 592 XEvent x_event; |
534 InitKeyEvent(display, &x_event, true, 0, state); | 593 InitKeyEvent(display, &x_event, true, 0, state); |
535 ui::KeyEvent key_event(&x_event, is_char); | 594 ui::KeyEvent key_event(&x_event, is_char); |
536 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 595 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
537 } | 596 } |
538 } | 597 } |
539 } | 598 } |
540 #endif | 599 #endif |
541 | 600 |
542 } // namespace ui | 601 } // namespace ui |
OLD | NEW |