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

Side by Side Diff: ui/events/x/events_x_unittest.cc

Issue 785753002: Don't refcount tracking id -> slot id mapping. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment. Created 5 years, 10 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
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 <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
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, TouchEventIdRefcounting) { 303 TEST_F(EventsXTest, TouchEventNotRemovingFromNativeMapping) {
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 kTrackingId0 = 5; 309 const int kTrackingId = 5;
310 const int kTrackingId1 = 7;
311 310
312 // Increment ref count once for first touch. 311 // Two touch presses with the same tracking id.
313 ui::ScopedXI2Event xpress0; 312 ui::ScopedXI2Event xpress0;
314 xpress0.InitTouchEvent( 313 xpress0.InitTouchEvent(
315 0, XI_TouchBegin, kTrackingId0, gfx::Point(10, 10), valuators); 314 0, XI_TouchBegin, kTrackingId, gfx::Point(10, 10), valuators);
316 scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0)); 315 scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0));
317 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId0)); 316 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId));
318 317
319 // Increment ref count 4 times for second touch.
320 ui::ScopedXI2Event xpress1; 318 ui::ScopedXI2Event xpress1;
321 xpress1.InitTouchEvent( 319 xpress1.InitTouchEvent(
322 0, XI_TouchBegin, kTrackingId1, gfx::Point(20, 20), valuators); 320 0, XI_TouchBegin, kTrackingId, gfx::Point(20, 20), valuators);
321 ui::TouchEvent upress1(xpress1);
322 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId));
323 323
324 for (int i = 0; i < 4; ++i) { 324 // The first touch release shouldn't clear the mapping from the
325 ui::TouchEvent upress1(xpress1); 325 // tracking id.
326 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1)); 326 ui::ScopedXI2Event xrelease0;
327 xrelease0.InitTouchEvent(
328 0, XI_TouchEnd, kTrackingId, gfx::Point(10, 10), valuators);
329 {
330 ui::TouchEvent urelease0(xrelease0);
331 urelease0.set_should_remove_native_touch_id_mapping(false);
327 } 332 }
333 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId));
328 334
335 // The second touch release should clear the mapping from the
336 // tracking id.
329 ui::ScopedXI2Event xrelease1; 337 ui::ScopedXI2Event xrelease1;
330 xrelease1.InitTouchEvent( 338 xrelease1.InitTouchEvent(
331 0, XI_TouchEnd, kTrackingId1, gfx::Point(10, 10), valuators); 339 0, XI_TouchEnd, kTrackingId, gfx::Point(10, 10), valuators);
332 340 {
333 // Decrement ref count 3 times for second touch.
334 for (int i = 0; i < 3; ++i) {
335 ui::TouchEvent urelease1(xrelease1); 341 ui::TouchEvent urelease1(xrelease1);
336 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1));
337 } 342 }
338 343 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId));
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.
345 ui::ScopedXI2Event xrelease0;
346 xrelease0.InitTouchEvent(
347 0, XI_TouchEnd, kTrackingId0, gfx::Point(10, 10), valuators);
348 scoped_ptr<ui::TouchEvent> urelease0(new ui::TouchEvent(xrelease0));
349 urelease0.reset();
350 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId0));
351 } 344 }
352 345
353 TEST_F(EventsXTest, NumpadKeyEvents) { 346 TEST_F(EventsXTest, NumpadKeyEvents) {
354 XEvent event; 347 XEvent event;
355 Display* display = gfx::GetXDisplay(); 348 Display* display = gfx::GetXDisplay();
356 349
357 struct { 350 struct {
358 bool is_numpad_key; 351 bool is_numpad_key;
359 int x_keysym; 352 int x_keysym;
360 } keys[] = { 353 } keys[] = {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 KeyEventTestApi test_event(&key_event); 622 KeyEventTestApi test_event(&key_event);
630 test_event.set_is_char(true); 623 test_event.set_is_char(true);
631 } 624 }
632 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); 625 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY);
633 } 626 }
634 } 627 }
635 } 628 }
636 #endif 629 #endif
637 630
638 } // namespace ui 631 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698