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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/x/events_x_unittest.cc
===================================================================
--- ui/events/x/events_x_unittest.cc (revision 286562)
+++ ui/events/x/events_x_unittest.cc (working copy)
@@ -270,6 +270,65 @@
EXPECT_FLOAT_EQ(GetTouchAngle(scoped_xevent), 0.45f);
EXPECT_FLOAT_EQ(GetTouchForce(scoped_xevent), 0.5f);
}
+
+int GetTouchIdForTrackingId(uint32 tracking_id) {
+ int slot = 0;
+ bool success =
+ TouchFactory::GetInstance()->QuerySlotForTrackingID(tracking_id, &slot);
+ if (success)
+ return slot;
+ return -1;
+}
+
+TEST_F(EventsXTest, TouchEventIdRefcounting) {
+ std::vector<unsigned int> devices;
+ devices.push_back(0);
+ ui::SetUpTouchDevicesForTest(devices);
+ std::vector<Valuator> valuators;
+
+ const int kTrackingId0 = 5;
+ const int kTrackingId1 = 7;
+
+ // Increment ref count once for first touch.
+ ui::ScopedXI2Event xpress0;
+ xpress0.InitTouchEvent(
+ 0, XI_TouchBegin, kTrackingId0, gfx::Point(10, 10), valuators);
+ scoped_ptr<ui::TouchEvent> upress0(new ui::TouchEvent(xpress0));
+ EXPECT_EQ(0, GetTouchIdForTrackingId(kTrackingId0));
+
+ // Increment ref count 4 times for second touch.
+ ui::ScopedXI2Event xpress1;
+ xpress1.InitTouchEvent(
+ 0, XI_TouchBegin, kTrackingId1, gfx::Point(20, 20), valuators);
+
+ for (int i = 0; i < 4; ++i) {
+ ui::TouchEvent upress1(xpress1);
+ EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1));
+ }
+
+ ui::ScopedXI2Event xrelease1;
+ xrelease1.InitTouchEvent(
+ 0, XI_TouchEnd, kTrackingId1, gfx::Point(10, 10), valuators);
+
+ // Decrement ref count 3 times for second touch.
+ for (int i = 0; i < 3; ++i) {
+ ui::TouchEvent urelease1(xrelease1);
+ EXPECT_EQ(1, GetTouchIdForTrackingId(kTrackingId1));
+ }
+
+ // This should clear the touch id of the second touch.
+ scoped_ptr<ui::TouchEvent> urelease1(new ui::TouchEvent(xrelease1));
+ urelease1.reset();
+ EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId1));
+
+ // This should clear the touch id of the first touch.
+ ui::ScopedXI2Event xrelease0;
+ xrelease0.InitTouchEvent(
+ 0, XI_TouchEnd, kTrackingId0, gfx::Point(10, 10), valuators);
+ scoped_ptr<ui::TouchEvent> urelease0(new ui::TouchEvent(xrelease0));
+ urelease0.reset();
+ EXPECT_EQ(-1, GetTouchIdForTrackingId(kTrackingId0));
+}
#endif
TEST(EventsXTest, NumpadKeyEvents) {
« 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