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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 293 |
294 int GetTouchIdForTrackingId(uint32 tracking_id) { | 294 int GetTouchIdForTrackingId(uint32 tracking_id) { |
295 int slot = 0; | 295 int slot = 0; |
296 bool success = | 296 bool success = |
297 TouchFactory::GetInstance()->QuerySlotForTrackingID(tracking_id, &slot); | 297 TouchFactory::GetInstance()->QuerySlotForTrackingID(tracking_id, &slot); |
298 if (success) | 298 if (success) |
299 return slot; | 299 return slot; |
300 return -1; | 300 return -1; |
301 } | 301 } |
302 | 302 |
303 TEST_F(EventsXTest, TouchEventNotRemovingFromNativeMapping) { | 303 TEST_F(EventsXTest, TouchEventIdRefcounting) { |
304 std::vector<unsigned int> devices; | 304 std::vector<unsigned int> devices; |
305 devices.push_back(0); | 305 devices.push_back(0); |
306 ui::SetUpTouchDevicesForTest(devices); | 306 ui::SetUpTouchDevicesForTest(devices); |
307 std::vector<Valuator> valuators; | 307 std::vector<Valuator> valuators; |
308 | 308 |
309 const int kTrackingId = 5; | 309 const int kTrackingId0 = 5; |
| 310 const int kTrackingId1 = 7; |
310 | 311 |
311 // Two touch presses with the same tracking id. | 312 // Increment ref count once for first touch. |
312 ui::ScopedXI2Event xpress0; | 313 ui::ScopedXI2Event xpress0; |
313 xpress0.InitTouchEvent( | 314 xpress0.InitTouchEvent( |
314 0, XI_TouchBegin, kTrackingId, gfx::Point(10, 10), valuators); | 315 0, XI_TouchBegin, kTrackingId0, gfx::Point(10, 10), valuators); |
315 scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0)); | 316 scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0)); |
316 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId)); | 317 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId0)); |
317 | 318 |
| 319 // Increment ref count 4 times for second touch. |
318 ui::ScopedXI2Event xpress1; | 320 ui::ScopedXI2Event xpress1; |
319 xpress1.InitTouchEvent( | 321 xpress1.InitTouchEvent( |
320 0, XI_TouchBegin, kTrackingId, gfx::Point(20, 20), valuators); | 322 0, XI_TouchBegin, kTrackingId1, gfx::Point(20, 20), valuators); |
321 ui::TouchEvent upress1(xpress1); | |
322 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId)); | |
323 | 323 |
324 // The first touch release shouldn't clear the mapping from the | 324 for (int i = 0; i < 4; ++i) { |
325 // tracking id. | 325 ui::TouchEvent upress1(xpress1); |
| 326 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); |
| 327 } |
| 328 |
| 329 ui::ScopedXI2Event xrelease1; |
| 330 xrelease1.InitTouchEvent( |
| 331 0, XI_TouchEnd, kTrackingId1, gfx::Point(10, 10), valuators); |
| 332 |
| 333 // Decrement ref count 3 times for second touch. |
| 334 for (int i = 0; i < 3; ++i) { |
| 335 ui::TouchEvent urelease1(xrelease1); |
| 336 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); |
| 337 } |
| 338 |
| 339 // This should clear the touch id of the second touch. |
| 340 scoped_ptr<ui::TouchEvent> urelease1(new ui::TouchEvent(xrelease1)); |
| 341 urelease1.reset(); |
| 342 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId1)); |
| 343 |
| 344 // This should clear the touch id of the first touch. |
326 ui::ScopedXI2Event xrelease0; | 345 ui::ScopedXI2Event xrelease0; |
327 xrelease0.InitTouchEvent( | 346 xrelease0.InitTouchEvent( |
328 0, XI_TouchEnd, kTrackingId, gfx::Point(10, 10), valuators); | 347 0, XI_TouchEnd, kTrackingId0, gfx::Point(10, 10), valuators); |
329 { | 348 scoped_ptr<ui::TouchEvent> urelease0(new ui::TouchEvent(xrelease0)); |
330 ui::TouchEvent urelease0(xrelease0); | 349 urelease0.reset(); |
331 urelease0.set_should_remove_native_touch_id_mapping(false); | 350 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId0)); |
332 } | |
333 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId)); | |
334 | |
335 // The second touch release should clear the mapping from the | |
336 // tracking id. | |
337 ui::ScopedXI2Event xrelease1; | |
338 xrelease1.InitTouchEvent( | |
339 0, XI_TouchEnd, kTrackingId, gfx::Point(10, 10), valuators); | |
340 { | |
341 ui::TouchEvent urelease1(xrelease1); | |
342 } | |
343 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId)); | |
344 } | 351 } |
345 | 352 |
346 TEST_F(EventsXTest, NumpadKeyEvents) { | 353 TEST_F(EventsXTest, NumpadKeyEvents) { |
347 XEvent event; | 354 XEvent event; |
348 Display* display = gfx::GetXDisplay(); | 355 Display* display = gfx::GetXDisplay(); |
349 | 356 |
350 struct { | 357 struct { |
351 bool is_numpad_key; | 358 bool is_numpad_key; |
352 int x_keysym; | 359 int x_keysym; |
353 } keys[] = { | 360 } keys[] = { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 KeyEventTestApi test_event(&key_event); | 629 KeyEventTestApi test_event(&key_event); |
623 test_event.set_is_char(true); | 630 test_event.set_is_char(true); |
624 } | 631 } |
625 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); | 632 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); |
626 } | 633 } |
627 } | 634 } |
628 } | 635 } |
629 #endif | 636 #endif |
630 | 637 |
631 } // namespace ui | 638 } // namespace ui |
OLD | NEW |