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

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

Issue 433533003: Merge 285580 "Currently, destroying a ui::TouchEvent removes its..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2062/src/
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/events/x/events_x.cc ('k') | ui/events/x/touch_factory_x11.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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>
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_MAJOR, 50)); 263 valuators.push_back(Valuator(DeviceDataManager::DT_TOUCH_MAJOR, 50));
264 scoped_xevent.InitTouchEvent( 264 scoped_xevent.InitTouchEvent(
265 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators); 265 0, XI_TouchEnd, 6, gfx::Point(200, 200), valuators);
266 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent)); 266 EXPECT_EQ(ui::ET_TOUCH_RELEASED, ui::EventTypeFromNative(scoped_xevent));
267 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString()); 267 EXPECT_EQ("200,200", ui::EventLocationFromNative(scoped_xevent).ToString());
268 EXPECT_EQ(GetTouchId(scoped_xevent), 1); 268 EXPECT_EQ(GetTouchId(scoped_xevent), 1);
269 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25); 269 EXPECT_EQ(GetTouchRadiusX(scoped_xevent), 25);
270 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f); 270 EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f);
271 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f); 271 EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f);
272 } 272 }
273
274 int GetTouchIdForTrackingId(uint32 tracking_id) {
275 int slot = 0;
276 bool success =
277 TouchFactory::GetInstance()->QuerySlotForTrackingID(tracking_id, &slot);
278 if (success)
279 return slot;
280 return -1;
281 }
282
283 TEST_F(EventsXTest, TouchEventIdRefcounting) {
284 std::vector<unsigned int> devices;
285 devices.push_back(0);
286 ui::SetUpTouchDevicesForTest(devices);
287 std::vector<Valuator> valuators;
288
289 const int kTrackingId0 = 5;
290 const int kTrackingId1 = 7;
291
292 // Increment ref count once for first touch.
293 ui::ScopedXI2Event xpress0;
294 xpress0.InitTouchEvent(
295 0, XI_TouchBegin, kTrackingId0, gfx::Point(10, 10), valuators);
296 scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0));
297 EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId0));
298
299 // Increment ref count 4 times for second touch.
300 ui::ScopedXI2Event xpress1;
301 xpress1.InitTouchEvent(
302 0, XI_TouchBegin, kTrackingId1, gfx::Point(20, 20), valuators);
303
304 for (int i = 0; i < 4; ++i) {
305 ui::TouchEvent upress1(xpress1);
306 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1));
307 }
308
309 ui::ScopedXI2Event xrelease1;
310 xrelease1.InitTouchEvent(
311 0, XI_TouchEnd, kTrackingId1, gfx::Point(10, 10), valuators);
312
313 // Decrement ref count 3 times for second touch.
314 for (int i = 0; i < 3; ++i) {
315 ui::TouchEvent urelease1(xrelease1);
316 EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1));
317 }
318
319 // This should clear the touch id of the second touch.
320 scoped_ptr<ui::TouchEvent> urelease1(new ui::TouchEvent(xrelease1));
321 urelease1.reset();
322 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId1));
323
324 // This should clear the touch id of the first touch.
325 ui::ScopedXI2Event xrelease0;
326 xrelease0.InitTouchEvent(
327 0, XI_TouchEnd, kTrackingId0, gfx::Point(10, 10), valuators);
328 scoped_ptr<ui::TouchEvent> urelease0(new ui::TouchEvent(xrelease0));
329 urelease0.reset();
330 EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId0));
331 }
273 #endif 332 #endif
274 333
275 TEST(EventsXTest, NumpadKeyEvents) { 334 TEST(EventsXTest, NumpadKeyEvents) {
276 XEvent event; 335 XEvent event;
277 Display* display = gfx::GetXDisplay(); 336 Display* display = gfx::GetXDisplay();
278 337
279 struct { 338 struct {
280 bool is_numpad_key; 339 bool is_numpad_key;
281 int x_keysym; 340 int x_keysym;
282 } keys[] = { 341 } keys[] = {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 XEvent x_event; 513 XEvent x_event;
455 InitKeyEvent(display, &x_event, true, 0, state); 514 InitKeyEvent(display, &x_event, true, 0, state);
456 ui::KeyEvent key_event(&x_event, is_char); 515 ui::KeyEvent key_event(&x_event, is_char);
457 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY); 516 EXPECT_FALSE(key_event.flags() & ui::EF_IME_FABRICATED_KEY);
458 } 517 }
459 } 518 }
460 } 519 }
461 #endif 520 #endif
462 521
463 } // namespace ui 522 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/x/events_x.cc ('k') | ui/events/x/touch_factory_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698