Debian Codegraph @

tests/unit/swipearea13/tst_swipearea.cpp

raw
1 /*
2 * Copyright 2015-2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <QtCore/QObject>
18 #include <QtCore/QPointer>
19 #include <QtCore/QSysInfo>
20 #include <QtQuick/QQuickView>
21 #include <QtQuick/private/qquickmousearea_p.h>
22 #include <QtQml/QQmlEngine>
23 #include <QtTest/QtTest>
24 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
25 #include <LomiriGestures-Qt6/private/ucswipearea_p_p.h>
26 #else
27 #include <LomiriGestures/private/ucswipearea_p_p.h>
28 #endif
29 #define protected public
30 #define private public
31 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
32 #include <LomiriGestures-Qt6/private/touchregistry_p.h>
33 #else
34 #include <LomiriGestures/private/touchregistry_p.h>
35 #endif
36 #undef protected
37 #undef private
38
39 #include "uctestcase.h"
40
41 #include "GestureTest.h"
42
43 UG_USE_NAMESPACE
44
45 // Because QSignalSpy(UCSwipeArea, SIGNAL(UCSwipeArea::Status)) simply
46 // doesn't work
47 class StatusSpy : public UCSwipeAreaStatusListener
48 {
49 public:
50 StatusSpy(UCSwipeArea *edgeDragArea)
51 : m_edgeDragArea(edgeDragArea)
52 , m_recognized(false)
53 {
54 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(m_edgeDragArea);
55 d->addStatusChangeListener(this);
56 }
57 virtual ~StatusSpy()
58 {
59 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(m_edgeDragArea);
60 d->removeStatusChangeListener(this);
61 }
62
63 bool recognized() {
64 return m_recognized;
65 }
66
67 private:
68 void swipeStatusChanged(UCSwipeAreaPrivate::Status, UCSwipeAreaPrivate::Status status) override
69 {
70 m_recognized |= status == UCSwipeAreaPrivate::Recognized;
71 }
72
73 private:
74 UCSwipeArea *m_edgeDragArea;
75 bool m_recognized;
76 };
77
78 /*
79 QQuickMouseArea::canceled() signal is not registered in the meta object system.
80 So using a QSignalSpy to track it won't work. Thus the only way to connect to it
81 is using its method address directly.
82 */
83 class MouseAreaSpy : public QObject
84 {
85 Q_OBJECT
86 public:
87 MouseAreaSpy(QQuickMouseArea *mouseArea)
88 : canceledCount(0)
89 {
90 connect(mouseArea, &QQuickMouseArea::canceled,
91 this, &MouseAreaSpy::onMouseAreaCanceled);
92 }
93
94 int canceledCount;
95
96 private Q_SLOTS:
97 void onMouseAreaCanceled() {
98 ++canceledCount;
99 }
100 };
101
102 class tst_UCSwipeArea: public GestureTest
103 {
104 Q_OBJECT
105 public:
106 tst_UCSwipeArea();
107 private Q_SLOTS:
108 void init() override; // called right before each and every test function is executed
109
110 void dragWithShortDirectionChange();
111 void recognitionTimerUsage();
112 void sceneXAndX();
113 void sceneYAndY();
114 void twoFingerTap();
115 void movingDDA();
116 void ignoreOldFinger();
117 void rotated();
118 void distance();
119 void distance_data();
120 void disabledWhileDragging();
121 void oneFingerDownFollowedByLateSecondFingerDown();
122 void givesUpWhenLosesTouch();
123 void threeFingerDrag();
124 void immediateRecognitionWhenConstraintsDisabled();
125 void withdrawTouchOwnershipCandidacyIfDisabledDuringRecognition();
126 void withdrawTouchOwnershipCandidacyIfDisabledDuringRecognition_data();
127 void gettingTouchOwnershipMakesMouseAreaBehindGetCanceled();
128 void interleavedTouches();
129 void makoRightEdgeDrag();
130 void makoRightEdgeDrag_verticalDownwards();
131 void makoLeftEdgeDrag_slowStart();
132 void makoLeftEdgeDrag_movesSlightlyBackwardsOnStart();
133 void grabGesture();
134 void grabGestureWithImmediateRecognition();
135
136 private:
137 // QTest::touchEvent takes QPoint instead of QPointF and I don't want to
138 // lose precision due to rounding.
139 // Besides, those helper functions lead to more compact code.
140 void sendTouchPress(qint64 timestamp, int id, QPointF pos);
141 void sendTouchUpdate(qint64 timestamp, int id, QPointF pos);
142 void sendTouchRelease(qint64 timestamp, int id, QPointF pos);
143 void sendTouch(qint64 timestamp, int id, QPointF pos,
144 Qt::TouchPointState pointState, QEvent::Type eventType);
145
146 void passTime(qint64 timeSpanMs);
147 };
148
149 tst_UCSwipeArea::tst_UCSwipeArea()
150 : GestureTest(QStringLiteral("tst_swipearea.qml"))
151 {
152 }
153
154 void tst_UCSwipeArea::init()
155 {
156 GestureTest::init();
157
158 // We shouldn't need the three lines below, but a compiz/unity7
159 // regression means we don't pass the test without them because
160 // the window doesn't have the proper size. Can be removed in the
161 // future if the regression is fixed and tests pass again
162 m_view->resize(m_view->rootObject()->width(), m_view->rootObject()->height());
163 QTRY_COMPARE(m_view->width(), (int)m_view->rootObject()->width());
164 QTRY_COMPARE(m_view->height(), (int)m_view->rootObject()->height());
165 }
166
167 void tst_UCSwipeArea::sendTouchPress(qint64 timestamp, int id, QPointF pos)
168 {
169 sendTouch(timestamp, id, pos, Qt::TouchPointPressed, QEvent::TouchBegin);
170 }
171
172 void tst_UCSwipeArea::sendTouchUpdate(qint64 timestamp, int id, QPointF pos)
173 {
174 sendTouch(timestamp, id, pos, Qt::TouchPointMoved, QEvent::TouchUpdate);
175 }
176
177 void tst_UCSwipeArea::sendTouchRelease(qint64 timestamp, int id, QPointF pos)
178 {
179 sendTouch(timestamp, id, pos, Qt::TouchPointReleased, QEvent::TouchEnd);
180 }
181
182 void tst_UCSwipeArea::sendTouch(qint64 timestamp, int id, QPointF pos,
183 Qt::TouchPointState pointState, QEvent::Type eventType)
184 {
185 m_fakeTimerFactory->updateTime(timestamp);
186
187 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
188 QTouchEvent::TouchPoint point;
189
190 point.setState(pointState);
191 point.setId(id);
192 point.setScenePos(pos);
193 point.setPos(pos);
194
195 QList<QTouchEvent::TouchPoint> points;
196 points << point;
197
198 QTouchEvent touchEvent(eventType, m_device, Qt::NoModifier, Qt::TouchPointPressed, points);
199 QCoreApplication::sendEvent(m_view, &touchEvent);
200 QCoreApplication::processEvents();
201 #else
202 switch (pointState) {
203 case Qt::TouchPointPressed:
204 QTest::touchEvent(m_view, m_device).press(id, pos.toPoint(), (QWindow*)nullptr);
205 break;
206 case Qt::TouchPointMoved:
207 QTest::touchEvent(m_view, m_device).move(id, pos.toPoint(), (QWindow*)nullptr);
208 break;
209 case Qt::TouchPointReleased:
210 QTest::touchEvent(m_view, m_device).release(id, pos.toPoint(), (QWindow*)nullptr);
211 break;
212 default:
213 break;
214 }
215 QTest::qWait(50);
216 #endif
217 }
218
219 void tst_UCSwipeArea::passTime(qint64 timeSpanMs)
220 {
221 qint64 finalTime = m_fakeTimerFactory->timeSource()->msecsSinceReference() + timeSpanMs;
222 m_fakeTimerFactory->updateTime(finalTime);
223 }
224
225 namespace {
226 QPointF calculateInitialtouchPosition(UCSwipeArea *edgeDragArea)
227 {
228 QPointF localCenter(edgeDragArea->width() / 2., edgeDragArea->height() / 2.);
229 return edgeDragArea->mapToScene(localCenter);
230 }
231 }
232
233 /*
234 A directional drag should still be recognized if there is a momentaneous, small,
235 change in the direction of a drag. That should be accounted as input noise and
236 therefore ignored.
237 */
238 void tst_UCSwipeArea::dragWithShortDirectionChange()
239 {
240 UCSwipeArea *edgeDragArea =
241 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
242 QVERIFY(edgeDragArea != 0);
243 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
244 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
245 d->setTimeSource(m_fakeTimerFactory->timeSource());
246
247 QPointF initialtouchPosition = calculateInitialtouchPosition(edgeDragArea);
248 QPointF touchPoint = initialtouchPosition;
249
250 qreal desiredDragDistance = d->distanceThreshold * 2.0;
251 QPointF dragDirectionVector(1.0, 0.0);
252 qreal touchStepDistance = d->distanceThreshold * 0.1f;
253 // make sure we are above maximum time
254 int touchStepTimeMs = d->maxTime / 20. ;
255 QPointF touchMovement = dragDirectionVector * touchStepDistance;
256
257 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint(), (QWindow*)nullptr);
258
259 // Move a bit in the proper direction
260 for (int i=0; i < 3; ++i) {
261 touchPoint += touchMovement;
262 passTime(touchStepTimeMs);
263 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
264 }
265
266 // Then a sudden and small movement to the opposite direction
267 touchPoint -= touchMovement*0.2;
268 passTime(touchStepTimeMs*0.2);
269 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
270
271 // And then resume movment in the correct direction until it crosses the distance and time
272 // thresholds.
273 do {
274 touchPoint += touchMovement;
275 passTime(touchStepTimeMs);
276 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
277 } while ((touchPoint - initialtouchPosition).manhattanLength() < desiredDragDistance
278 || m_fakeTimerFactory->timeSource()->msecsSinceReference() < (d->compositionTime * 1.5f));
279
280 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
281
282 QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint(), (QWindow*)nullptr);
283 }
284
285 /*
286 Checks that the recognition timer is started and stopped appropriately.
287 I.e., check that it's running only while gesture recognition is taking place
288 (status == Undecided)
289 */
290 void tst_UCSwipeArea::recognitionTimerUsage()
291 {
292 UCSwipeArea *edgeDragArea =
293 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
294 QVERIFY(edgeDragArea != 0);
295 AbstractTimer *fakeTimer = m_fakeTimerFactory->createTimer();
296 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
297 d->setRecognitionTimer(fakeTimer);
298 d->setTimeSource(m_fakeTimerFactory->timeSource());
299
300 int timeStepMs = 5; // some arbitrary small value.
301
302 QPointF initialtouchPosition = calculateInitialtouchPosition(edgeDragArea);
303 QPointF touchPoint = initialtouchPosition;
304
305 QPointF dragDirectionVector(1.0, 0.0);
306 QPointF touchMovement = dragDirectionVector * (d->distanceThreshold * 0.2f);
307
308 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
309 QVERIFY(!fakeTimer->isRunning());
310
311 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint(), (QWindow*)nullptr);
312
313 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
314 QVERIFY(fakeTimer->isRunning());
315
316 // Move beyond distance threshold and composition time to ensure recognition
317 while (m_fakeTimerFactory->timeSource()->msecsSinceReference() <= d->compositionTime ||
318 (touchPoint - initialtouchPosition).manhattanLength() <= d->distanceThreshold) {
319
320 QCOMPARE(d->status == UCSwipeAreaPrivate::Undecided, fakeTimer->isRunning());
321
322 touchPoint += touchMovement;
323 passTime(timeStepMs);
324 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
325 }
326
327 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
328 QVERIFY(!fakeTimer->isRunning());
329 }
330
331 /*
332 Checks that it informs the X coordinate of the touch point in local and scene coordinates
333 correctly.
334 */
335 void tst_UCSwipeArea::sceneXAndX()
336 {
337 UCSwipeArea *edgeDragArea =
338 m_view->rootObject()->findChild<UCSwipeArea*>("hnDragArea");
339 QVERIFY(edgeDragArea != 0);
340 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
341 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
342 d->setTimeSource(m_fakeTimerFactory->timeSource());
343 edgeDragArea->setImmediateRecognition(true);
344
345 QPointF touchScenePosition(m_view->width() - (edgeDragArea->width()/2.0f), m_view->height()/2.0f);
346
347 sendTouchPress(0 /* timestamp */, 0 /* id */, touchScenePosition);
348
349 QSignalSpy touchSpy(edgeDragArea, &UCSwipeArea::touchPositionChanged);
350
351 touchScenePosition.rx() = m_view->width() / 2;
352 sendTouchUpdate(50 /* timestamp */, 0 /* id */, touchScenePosition);
353
354 QCOMPARE(touchSpy.count(), 1);
355 QCOMPARE(edgeDragArea->touchPosition().x(), touchScenePosition.x() - edgeDragArea->x());
356 }
357
358 /*
359 Checks that it informs the Y coordinate of the touch point in local and scene coordinates
360 correctly.
361 */
362 void tst_UCSwipeArea::sceneYAndY()
363 {
364 UCSwipeArea *edgeDragArea =
365 m_view->rootObject()->findChild<UCSwipeArea*>("vnDragArea");
366 QVERIFY(edgeDragArea != 0);
367 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
368 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
369 d->setTimeSource(m_fakeTimerFactory->timeSource());
370 edgeDragArea->setImmediateRecognition(true);
371
372 QPointF touchScenePosition(m_view->width()/2.0f, m_view->height() - (edgeDragArea->height()/2.0f));
373
374 sendTouchPress(0 /* timestamp */, 0 /* id */, touchScenePosition);
375
376 QSignalSpy touchSpy(edgeDragArea, &UCSwipeArea::touchPositionChanged);
377
378 touchScenePosition.ry() = m_view->height() / 2;
379 sendTouchUpdate(50 /* timestamp */, 0 /* id */, touchScenePosition);
380
381 QCOMPARE(touchSpy.count(), 1);
382 QCOMPARE(edgeDragArea->touchPosition().y(), touchScenePosition.y() - edgeDragArea->y());
383 }
384
385 /*
386 Regression test for https://bugs.launchpad.net/bugs/1228336
387
388 Perform a quick two-finger double-tap and check that UCSwipeArea properly
389 rejects those touch points. In the bug above it got confused and crashed.
390 */
391 void tst_UCSwipeArea::twoFingerTap()
392 {
393 UCSwipeArea *edgeDragArea =
394 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
395 QVERIFY(edgeDragArea != 0);
396 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
397 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
398 d->setTimeSource(m_fakeTimerFactory->timeSource());
399
400 // Make touches evenly spaced along the edgeDragArea
401 QPoint touchAPos(edgeDragArea->width()/2.0f, m_view->height()*0.33f);
402 QPoint touchBPos(edgeDragArea->width()/2.0f, m_view->height()*0.66f);
403
404 qint64 timeStepMsecs = 5; // some arbitrary, small value
405
406 // Perform the first two-finger tap
407 // NB: using move() instead of stationary() becasue in the latter you cannot provide
408 // the touch position and therefore it's left with some garbage numbers.
409 QTest::touchEvent(m_view, m_device)
410 .press(0, touchAPos, (QWindow*)nullptr);
411
412 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
413
414 passTime(timeStepMsecs);
415 QTest::touchEvent(m_view, m_device)
416 .move(0, touchAPos, (QWindow*)nullptr)
417 .press(1, touchBPos, (QWindow*)nullptr);
418
419 // A second touch point appeared during recognition, reject immediately as this
420 // can't be a single-touch gesture anymore.
421 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
422
423 passTime(timeStepMsecs);
424 QTest::touchEvent(m_view, m_device)
425 .release(0, touchAPos, (QWindow*)nullptr)
426 .move(1, touchBPos, (QWindow*)nullptr);
427
428 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
429
430 passTime(timeStepMsecs);
431 QTest::touchEvent(m_view, m_device)
432 .release(1, touchBPos, (QWindow*)nullptr);
433
434 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
435
436 // Perform the second two-finger tap
437
438 passTime(timeStepMsecs);
439 QTest::touchEvent(m_view, m_device)
440 .press(0, touchAPos, (QWindow*)nullptr);
441
442 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
443
444 passTime(timeStepMsecs);
445 QTest::touchEvent(m_view, m_device)
446 .move(0, touchAPos, (QWindow*)nullptr)
447 .press(1, touchBPos, (QWindow*)nullptr);
448
449 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
450
451 passTime(timeStepMsecs);
452 QTest::touchEvent(m_view, m_device)
453 .release(0, touchAPos, (QWindow*)nullptr)
454 .move(1, touchBPos, (QWindow*)nullptr);
455
456 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
457
458 passTime(timeStepMsecs);
459 QTest::touchEvent(m_view, m_device)
460 .release(1, touchBPos, (QWindow*)nullptr);
461
462 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
463 }
464
465 /*
466 Tests that gesture recognition works normally even if the UCSwipeArea moves
467 during recognition.
468 This effectively means that we have to do gesture recognition with scene coordinates
469 instead of local item coordinates.
470 */
471 void tst_UCSwipeArea::movingDDA()
472 {
473 QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
474 Q_ASSERT(rightwardsLauncher != 0);
475
476 UCSwipeArea *edgeDragArea =
477 rightwardsLauncher->findChild<UCSwipeArea*>("hpDragArea");
478 Q_ASSERT(edgeDragArea != 0);
479 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
480 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
481 d->setTimeSource(m_fakeTimerFactory->timeSource());
482
483 QPointF initialtouchPosition = calculateInitialtouchPosition(edgeDragArea);
484 QPointF touchPoint = initialtouchPosition;
485
486 qreal desiredDragDistance = d->distanceThreshold * 2.0f;
487 QPointF dragDirectionVector(1.0f, 0.0f);
488
489 qreal movementStepDistance = d->distanceThreshold * 0.1f;
490 QPointF touchMovement = dragDirectionVector * movementStepDistance;
491 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
492 int movementTimeStepMs = (d->compositionTime * 1.5f) / totalMovementSteps;
493
494 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint(), (QWindow*)nullptr);
495
496 // Move it far ahead along the direction of the gesture
497 // rightwardsLauncher is a parent of our UCSwipeArea. So moving it will move our DDA
498 rightwardsLauncher->setX(rightwardsLauncher->x() + d->distanceThreshold * 5.0f);
499
500 for (int i = 0; i < totalMovementSteps; ++i) {
501 touchPoint += touchMovement;
502 passTime(movementTimeStepMs);
503 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
504 }
505
506 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
507
508 QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint(), (QWindow*)nullptr);
509 }
510
511 /*
512 The presence of and old, rejected, touch point lying on the UCSwipeArea
513 shouldn't impede the recognition of a gesture from a new touch point.
514 */
515 void tst_UCSwipeArea::ignoreOldFinger()
516 {
517 UCSwipeArea *edgeDragArea =
518 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
519 Q_ASSERT(edgeDragArea != 0);
520 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
521 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
522 d->setTimeSource(m_fakeTimerFactory->timeSource());
523
524 // Make touches evenly spaced along the edgeDragArea
525 QPoint touch0Pos(edgeDragArea->width()/2.0f, m_view->height()*0.33f);
526 QPoint touch1Pos(edgeDragArea->width()/2.0f, m_view->height()*0.66f);
527
528 QTest::touchEvent(m_view, m_device).press(0, touch0Pos, (QWindow*)nullptr);
529
530 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
531
532 // leave it lying around for some time
533 passTime(d->maxTime * 10);
534
535 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
536
537 qreal desiredDragDistance = d->distanceThreshold * 2.0f;
538 QPointF dragDirectionVector(1.0f, 0.0f);
539
540 qreal movementStepDistance = d->distanceThreshold * 0.1f;
541 QPointF touchMovement = dragDirectionVector * movementStepDistance;
542 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
543 int movementTimeStepMs = (d->compositionTime * 1.5f) / totalMovementSteps;
544
545 QTest::touchEvent(m_view, m_device)
546 .move(0, touch0Pos, (QWindow*)nullptr)
547 .press(1, touch1Pos, (QWindow*)nullptr);
548
549 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
550
551 for (int i = 0; i < totalMovementSteps; ++i) {
552 touch1Pos += touchMovement.toPoint();
553 passTime(movementTimeStepMs);
554 QTest::touchEvent(m_view, m_device)
555 .move(0, touch0Pos, (QWindow*)nullptr)
556 .move(1, touch1Pos, (QWindow*)nullptr);
557 }
558
559 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
560
561 QTest::touchEvent(m_view, m_device)
562 .move(0, touch0Pos, (QWindow*)nullptr)
563 .release(1, touch1Pos, (QWindow*)nullptr);
564
565 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
566 }
567
568 /*
569 A Rightwards DDA that is rotated 90 degrees clockwise should recognize gestures
570 that are done downwards in scene coordinates. I.e. the gesture recognition direction
571 should be in local coordinates, not scene coordinates.
572 */
573 void tst_UCSwipeArea::rotated()
574 {
575 QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
576 baseItem->setRotation(90.);
577
578 QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
579 Q_ASSERT(rightwardsLauncher != 0);
580
581 UCSwipeArea *edgeDragArea =
582 rightwardsLauncher->findChild<UCSwipeArea*>("hpDragArea");
583 Q_ASSERT(edgeDragArea != 0);
584 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
585 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
586 d->setTimeSource(m_fakeTimerFactory->timeSource());
587
588 QPointF initialtouchPosition = calculateInitialtouchPosition(edgeDragArea);
589 QPointF touchPoint = initialtouchPosition;
590
591 qreal desiredDragDistance = d->distanceThreshold * 2.0f;
592 QPointF dragDirectionVector(0.0f, 1.0f);
593
594 qreal movementStepDistance = d->distanceThreshold * 0.1f;
595 QPointF touchMovement = dragDirectionVector * movementStepDistance;
596 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
597 int movementTimeStepMs = (d->compositionTime * 1.5f) / totalMovementSteps;
598
599 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint(), (QWindow*)nullptr);
600
601 for (int i = 0; i < totalMovementSteps; ++i) {
602 touchPoint += touchMovement;
603 passTime(movementTimeStepMs);
604 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
605 }
606
607 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
608
609 QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint(), (QWindow*)nullptr);
610 }
611
612 void tst_UCSwipeArea::distance()
613 {
614 QQuickItem *baseItem = m_view->rootObject()->findChild<QQuickItem*>("baseItem");
615 QFETCH(qreal, rotation);
616 QFETCH(QPointF, dragDirectionVector);
617 baseItem->setRotation(rotation);
618
619 QQuickItem *rightwardsLauncher = m_view->rootObject()->findChild<QQuickItem*>("rightwardsLauncher");
620 Q_ASSERT(rightwardsLauncher != 0);
621
622 UCSwipeArea *edgeDragArea =
623 rightwardsLauncher->findChild<UCSwipeArea*>("hpDragArea");
624 Q_ASSERT(edgeDragArea != 0);
625 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
626 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
627 d->setTimeSource(m_fakeTimerFactory->timeSource());
628
629 // to disable the position smoothing so that we can more easily check distance values
630 edgeDragArea->setImmediateRecognition(true);
631
632 QPointF initialtouchPosition = calculateInitialtouchPosition(edgeDragArea);
633 QPointF touchPoint = initialtouchPosition;
634
635 qreal desiredDragDistance = d->distanceThreshold * 2.0f;
636
637 qreal movementStepDistance = d->distanceThreshold * 0.1f;
638 QPointF touchMovement = dragDirectionVector * movementStepDistance;
639 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
640 int movementTimeStepMs = (d->compositionTime * 1.5f) / totalMovementSteps;
641
642 qint64 timestamp = 0;
643
644 sendTouchPress(timestamp, 0, touchPoint);
645
646 for (int i = 0; i < totalMovementSteps; ++i) {
647 touchPoint += touchMovement;
648 timestamp += movementTimeStepMs;
649 sendTouchUpdate(timestamp, 0, touchPoint);
650 }
651
652 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
653 QPointF displacement(touchPoint.toPoint() - initialtouchPosition.toPoint());
654 qreal actualDragDistance = QPointF::dotProduct(displacement, dragDirectionVector);
655 #else
656 qreal actualDragDistance = ((qreal)totalMovementSteps) * movementStepDistance;
657 #endif
658
659 // UCSwipeArea::distance() must match the actual drag distance as the
660 // drag was aligned with the gesture direction
661 // NB: qFuzzyCompare(), used internally by QCOMPARE(), is broken.
662 QVERIFY(qAbs(edgeDragArea->distance() - actualDragDistance) < 0.001);
663
664 timestamp += movementTimeStepMs;
665 sendTouchRelease(timestamp, 0, touchPoint);
666 }
667
668 void tst_UCSwipeArea::distance_data()
669 {
670 QTest::addColumn<qreal>("rotation");
671 QTest::addColumn<QPointF>("dragDirectionVector");
672
673 QTest::newRow("not rotated") << 0. << QPointF(1., 0.);
674 QTest::newRow("rotated by 90 degrees") << 90. << QPointF(0., 1.);
675 }
676
677 /*
678 Regression test for https://bugs.launchpad.net/unity8/+bug/1276122
679
680 The bug:
681 If setting "enabled: false" while the UCSwipeArea's (DDA) dragging
682 property is true, the DDA stays in that state and doesn't recover any more.
683 */
684 void tst_UCSwipeArea::disabledWhileDragging()
685 {
686 UCSwipeArea *edgeDragArea =
687 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
688 Q_ASSERT(edgeDragArea != 0);
689 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
690 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
691 d->setTimeSource(m_fakeTimerFactory->timeSource());
692
693 QPointF touchPoint = calculateInitialtouchPosition(edgeDragArea);
694
695 qreal desiredDragDistance = d->distanceThreshold * 2.0f;
696 QPointF dragDirectionVector(1., 0.); // horizontal positive
697
698 qreal movementStepDistance = d->distanceThreshold * 0.1f;
699 QPointF touchMovement = dragDirectionVector * movementStepDistance;
700 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
701 int movementTimeStepMs = (d->compositionTime * 1.5f) / totalMovementSteps;
702
703 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint(), (QWindow*)nullptr);
704
705 for (int i = 0; i < totalMovementSteps; ++i) {
706 touchPoint += touchMovement;
707 passTime(movementTimeStepMs);
708 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
709 }
710
711 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
712 QCOMPARE(edgeDragArea->dragging(), true);
713
714 // disable the swipeArea while it's being dragged.
715 edgeDragArea->setEnabled(false);
716
717 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
718 QCOMPARE(edgeDragArea->dragging(), false);
719
720 QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint(), (QWindow*)nullptr);
721 }
722
723 void tst_UCSwipeArea::oneFingerDownFollowedByLateSecondFingerDown()
724 {
725 QSKIP("Fails on Qt 5.9");
726
727 UCSwipeArea *edgeDragArea =
728 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
729 Q_ASSERT(edgeDragArea != 0);
730 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
731 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
732 d->setTimeSource(m_fakeTimerFactory->timeSource());
733
734 // Disable some constraints we're not interested in
735 d->setMaxTime(60 * 1000);
736
737 // And ensure others have the values we want
738 d->compositionTime = 60;
739
740 // Put an item right behind edgeDragArea to receive the touches ignored by it
741 DummyItem *dummyItem = new DummyItem;
742 dummyItem->setParentItem(edgeDragArea->parentItem());
743 dummyItem->setX(edgeDragArea->x());
744 dummyItem->setY(edgeDragArea->y());
745 dummyItem->setZ(edgeDragArea->z() - 1.0);
746 dummyItem->setWidth(edgeDragArea->width());
747 dummyItem->setHeight(edgeDragArea->height());
748
749 // Make touches evenly spaced along the edgeDragArea
750 QPoint touch0Pos(edgeDragArea->width()/2.0f, m_view->height()*0.33f);
751 QPoint touch1Pos(edgeDragArea->width()/2.0f, m_view->height()*0.66f);
752
753 QTest::touchEvent(m_view, m_device).press(0, touch0Pos, (QWindow*)nullptr);
754
755 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
756
757 // We are now going to be way beyond compositionTime
758 passTime(d->compositionTime*3);
759
760 QTest::touchEvent(m_view, m_device)
761 .move(0, touch0Pos, (QWindow*)nullptr)
762 .press(1, touch1Pos, (QWindow*)nullptr);
763
764 // A new touch has come, but as it can't be composed with touch 0, it should be
765 // ignored/rejected by the UCSwipeArea
766 // Therefore the last event received by dummyItem must have both touch points (0 and 1)
767 {
768 TouchMemento &touchMemento = dummyItem->touchEvents.last();
769 QCOMPARE(touchMemento.touchPoints.count(), 2);
770 QVERIFY(touchMemento.containsTouchWithId(0));
771 QVERIFY(touchMemento.containsTouchWithId(1));
772 }
773
774 passTime(30);
775
776 QTest::touchEvent(m_view, m_device)
777 .move(0, touch0Pos, (QWindow*)nullptr)
778 .move(1, touch1Pos, (QWindow*)nullptr);
779
780 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
781
782 passTime(5);
783
784 QTest::touchEvent(m_view, m_device)
785 .release(0, touch0Pos, (QWindow*)nullptr)
786 .move(1, touch1Pos, (QWindow*)nullptr);
787
788 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
789
790 passTime(5);
791
792 QTest::touchEvent(m_view, m_device)
793 .release(1, touch1Pos, (QWindow*)nullptr);
794
795 // Shouldn't be keepping info about touches that no longer exist or interest us
796 QVERIFY(d->activeTouches.isEmpty());
797
798 delete dummyItem;
799 }
800
801 void tst_UCSwipeArea::givesUpWhenLosesTouch()
802 {
803 QSKIP("Fails on Qt 5.9. See LP: #1628066");
804
805 UCSwipeArea *edgeDragArea =
806 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
807 Q_ASSERT(edgeDragArea != 0);
808 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
809 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
810 d->setTimeSource(m_fakeTimerFactory->timeSource());
811
812 // Disable some constraints we're not interested in
813 d->setMaxTime(60 * 1000);
814
815 // Put an item right in front of edgeDragArea
816 DummyItem *dummyItem = new DummyItem(edgeDragArea->parentItem());
817 dummyItem->setX(edgeDragArea->x());
818 dummyItem->setY(edgeDragArea->y());
819 dummyItem->setZ(edgeDragArea->z() + 1.0);
820 dummyItem->setWidth(edgeDragArea->width());
821 dummyItem->setHeight(edgeDragArea->height());
822
823 QPoint touchPosition(edgeDragArea->width()/2.0f, m_view->height()/2.0f);
824
825 dummyItem->touchEventHandler = [&](QTouchEvent *event) {
826 m_touchRegistry->addCandidateOwnerForTouch(0, dummyItem);
827 event->ignore();
828 };
829
830 QTest::touchEvent(m_view, m_device).press(0, touchPosition, (QWindow*)nullptr);
831
832 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
833
834 m_touchRegistry->requestTouchOwnership(0, dummyItem);
835
836 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
837
838 dummyItem->grabTouchPoints({0});
839 dummyItem->touchEventHandler = [&](QTouchEvent *event) { event->accept(); };
840
841 passTime(5);
842 QTest::touchEvent(m_view, m_device).release(0, touchPosition, (QWindow*)nullptr);
843
844 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
845
846 QVERIFY(d->activeTouches.isEmpty());
847 }
848
849 void tst_UCSwipeArea::threeFingerDrag()
850 {
851 UCSwipeArea *edgeDragArea =
852 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
853 Q_ASSERT(edgeDragArea != 0);
854 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
855 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
856 d->setTimeSource(m_fakeTimerFactory->timeSource());
857
858 // Disable some constraints we're not interested in
859 d->setMaxTime(60 * 1000);
860
861 // And ensure others have the values we want
862 d->compositionTime = 60;
863
864 // Make touches evenly spaced along the edgeDragArea
865 QPoint touch0Pos(edgeDragArea->width()/2.0f, m_view->height()*0.25f);
866 QPoint touch1Pos(edgeDragArea->width()/2.0f, m_view->height()*0.50f);
867 QPoint touch2Pos(edgeDragArea->width()/2.0f, m_view->height()*0.75f);
868
869 QTest::touchEvent(m_view, m_device)
870 .press(0, touch0Pos, (QWindow*)nullptr);
871
872 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
873
874 passTime(5);
875 QTest::touchEvent(m_view, m_device)
876 .move(0, touch0Pos, (QWindow*)nullptr)
877 .press(1, touch1Pos, (QWindow*)nullptr);
878
879 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
880
881 passTime(5);
882 QTest::touchEvent(m_view, m_device)
883 .move(0, touch0Pos, (QWindow*)nullptr)
884 .move(1, touch1Pos, (QWindow*)nullptr)
885 .press(2, touch2Pos, (QWindow*)nullptr);
886
887 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
888
889 passTime(10);
890 QTest::touchEvent(m_view, m_device)
891 .move(0, touch0Pos, (QWindow*)nullptr)
892 .move(1, touch1Pos, (QWindow*)nullptr)
893 .move(2, touch2Pos, (QWindow*)nullptr);
894
895 passTime(200);
896 QTest::touchEvent(m_view, m_device)
897 .move(0, touch0Pos, (QWindow*)nullptr)
898 .release(1, touch1Pos, (QWindow*)nullptr)
899 .move(2, touch2Pos, (QWindow*)nullptr);
900
901 passTime(10);
902 QTest::touchEvent(m_view, m_device)
903 .move(0, touch0Pos, (QWindow*)nullptr)
904 .release(2, touch2Pos, (QWindow*)nullptr);
905
906 passTime(5);
907 QTest::touchEvent(m_view, m_device)
908 .release(0, touch0Pos, (QWindow*)nullptr);
909
910 // Shouldn't be keepping info about touches that no longer exist or interest us
911 QVERIFY(d->activeTouches.isEmpty());
912 }
913
914 /*
915 If all the relevant gesture recognition constraints/parameters have been disabled,
916 it means that the gesture recognition itself has been disabled and UCSwipeArea
917 will therefore work like a simple touch area, merely reporting touch movement.
918 */
919 void tst_UCSwipeArea::immediateRecognitionWhenConstraintsDisabled()
920 {
921 UCSwipeArea *edgeDragArea =
922 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
923 Q_ASSERT(edgeDragArea != 0);
924 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
925 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
926 d->setTimeSource(m_fakeTimerFactory->timeSource());
927
928 // Disable the minimum amount of constraints to ensure immediate recognition
929 d->setDistanceThreshold(0);
930 d->compositionTime = 0;
931
932 // Put an item right behind edgeDragArea to receive the touches ignored by it
933 DummyItem *dummyItem = new DummyItem;
934 dummyItem->setParentItem(edgeDragArea->parentItem());
935 dummyItem->setX(edgeDragArea->x());
936 dummyItem->setY(edgeDragArea->y());
937 dummyItem->setZ(edgeDragArea->z() - 1.0);
938 dummyItem->setWidth(edgeDragArea->width());
939 dummyItem->setHeight(edgeDragArea->height());
940
941 QPoint touch0Pos(edgeDragArea->width()/2.0f, m_view->height()/2.0f);
942
943 QSignalSpy pressedSpy(edgeDragArea, &UCSwipeArea::pressedChanged);
944 QCOMPARE(edgeDragArea->pressed(), false);
945
946 QTest::touchEvent(m_view, m_device).press(0, touch0Pos, (QWindow*)nullptr);
947
948 // check for immediate recognition
949 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
950
951 // and it is pressed
952 QCOMPARE(edgeDragArea->pressed(), true);
953 QCOMPARE(pressedSpy.count(), 1);
954
955 // and therefore it should have immediately grabbed the touch point,
956 // not letting it leak to items behind him.
957 QCOMPARE(dummyItem->touchEvents.count(), 0);
958 }
959
960 void tst_UCSwipeArea::withdrawTouchOwnershipCandidacyIfDisabledDuringRecognition()
961 {
962 QSKIP("Fails on Qt 5.9 with segfault.");
963
964 UCSwipeArea *edgeDragArea =
965 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
966 Q_ASSERT(edgeDragArea != 0);
967 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
968 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
969 d->setTimeSource(m_fakeTimerFactory->timeSource());
970
971 QPointF touchPoint = calculateInitialtouchPosition(edgeDragArea);
972
973 // Move less than the minimum needed for the drag gesture recognition
974 qreal desiredDragDistance = d->distanceThreshold * 0.5f;
975 QPointF dragDirectionVector(1., 0.); // horizontal positive
976
977 qreal movementStepDistance = d->distanceThreshold * 0.1f;
978 QPointF touchMovement = dragDirectionVector * movementStepDistance;
979 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
980 int movementTimeStepMs = (d->compositionTime * 0.8f) / totalMovementSteps;
981
982 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint(), (QWindow*)nullptr);
983
984 for (int i = 0; i < totalMovementSteps; ++i) {
985 touchPoint += touchMovement;
986 passTime(movementTimeStepMs);
987 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
988 }
989
990 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
991
992 // edgeDragArea should be an undecided candidate
993 {
994 auto touchInfo = m_touchRegistry->findTouchInfo(0);
995 QCOMPARE(touchInfo->candidates.size(), 1);
996 QCOMPARE(touchInfo->candidates.at(0).item.data(), edgeDragArea);
997 QCOMPARE(touchInfo->candidates.at(0).state, TouchRegistry::CandidateInfo::Undecided);
998 }
999
1000 // disable the swipeArea while it's still recognizing a possible drag gesture.
1001 QFETCH(bool, disable);
1002 if (disable) {
1003 edgeDragArea->setEnabled(false);
1004 } else {
1005 edgeDragArea->setVisible(false);
1006 }
1007
1008 // edgeDragArea should no longer be a candidate
1009 {
1010 auto touchInfo = m_touchRegistry->findTouchInfo(0);
1011 QCOMPARE(touchInfo->candidates.size(), 0);
1012 }
1013
1014 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
1015
1016 QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint(), (QWindow*)nullptr);
1017 }
1018
1019 void tst_UCSwipeArea::withdrawTouchOwnershipCandidacyIfDisabledDuringRecognition_data()
1020 {
1021 QTest::addColumn<bool>("disable");
1022
1023 QTest::newRow("disabled") << true;
1024 QTest::newRow("invisible") << false;
1025 }
1026
1027 void tst_UCSwipeArea::gettingTouchOwnershipMakesMouseAreaBehindGetCanceled()
1028 {
1029 UCSwipeArea *edgeDragArea =
1030 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
1031 QVERIFY(edgeDragArea != nullptr);
1032 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
1033 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
1034 d->setTimeSource(m_fakeTimerFactory->timeSource());
1035
1036 QQuickMouseArea *mouseArea =
1037 m_view->rootObject()->findChild<QQuickMouseArea*>("mouseArea");
1038 QVERIFY(mouseArea != nullptr);
1039
1040 MouseAreaSpy mouseAreaSpy(mouseArea);
1041
1042 QPointF initialtouchPosition = calculateInitialtouchPosition(edgeDragArea);
1043 QPointF touchPoint = initialtouchPosition;
1044
1045 qreal desiredDragDistance = d->distanceThreshold * 2;
1046 QPointF dragDirectionVector(1.0f, 0.0f); // rightwards
1047 qreal movementStepDistance = d->distanceThreshold * 0.1f;
1048 QPointF touchMovement = dragDirectionVector * movementStepDistance;
1049 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
1050 int movementTimeStepMs = (d->compositionTime * 1.5f) / totalMovementSteps;
1051
1052 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1053 QCOMPARE(mouseArea->isPressed(), false);
1054 #else
1055 QCOMPARE(mouseArea->pressed(), false);
1056 #endif
1057
1058 QTest::touchEvent(m_view, m_device).press(0, touchPoint.toPoint(), (QWindow*)nullptr);
1059
1060 // The TouchBegin passes through the UCSwipeArea and reaches the MouseArea behind it,
1061 // where it's converted to a MouseEvent by QQuickWindow and sent to the MouseArea which then
1062 // accepts it. Making it get pressed.
1063 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1064 QCOMPARE(mouseArea->isPressed(), true);
1065 #else
1066 QCOMPARE(mouseArea->pressed(), true);
1067 #endif
1068 QCOMPARE(mouseAreaSpy.canceledCount, 0);
1069
1070 for (int i = 0; i < totalMovementSteps; ++i) {
1071 touchPoint += touchMovement;
1072 passTime(movementTimeStepMs);
1073 QTest::touchEvent(m_view, m_device).move(0, touchPoint.toPoint(), (QWindow*)nullptr);
1074 }
1075
1076 // As the UCSwipeArea recognizes the gesture, it grabs the touch from the MouseArea,
1077 // which should make the MouseArea get a cancelation event, which will then cause it to
1078 // reset its state (going back to "unpressed"/"released").
1079 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
1080 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1081 QCOMPARE(mouseArea->isPressed(), false);
1082 #else
1083 QCOMPARE(mouseArea->pressed(), false);
1084 #endif
1085 QCOMPARE(mouseAreaSpy.canceledCount, 1);
1086
1087 QTest::touchEvent(m_view, m_device).release(0, touchPoint.toPoint(), (QWindow*)nullptr);
1088 }
1089
1090 void tst_UCSwipeArea::interleavedTouches()
1091 {
1092 QSKIP("Fails on Qt 5.9");
1093
1094 UCSwipeArea *edgeDragArea =
1095 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
1096 QVERIFY(edgeDragArea != 0);
1097 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
1098 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
1099 d->setTimeSource(m_fakeTimerFactory->timeSource());
1100
1101 QPointF touch0 = edgeDragArea->mapToScene(
1102 QPointF(edgeDragArea->width()*0.5, edgeDragArea->height()*0.3));
1103
1104 qreal desiredDragDistance = d->distanceThreshold * 2;
1105 QPointF dragDirectionVector(1.0f, 0.0f); // rightwards
1106 qreal movementStepDistance = d->distanceThreshold * 0.1f;
1107 QPointF touchMovement = dragDirectionVector * movementStepDistance;
1108 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
1109 int movementTimeStepMs = (d->maxTime * 0.4f) / totalMovementSteps;
1110
1111 QTest::touchEvent(m_view, m_device).press(0, touch0.toPoint(), (QWindow*)nullptr);
1112 for (int i = 0; i < totalMovementSteps; ++i) {
1113 touch0 += touchMovement;
1114 passTime(movementTimeStepMs);
1115 QTest::touchEvent(m_view, m_device).move(0, touch0.toPoint(), (QWindow*)nullptr);
1116 }
1117 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
1118
1119 QPointF touch1 = edgeDragArea->mapToScene(
1120 QPointF(edgeDragArea->width()*0.5, edgeDragArea->height()*0.6));
1121
1122 QTest::touchEvent(m_view, m_device)
1123 .move(0, touch0.toPoint(), (QWindow*)nullptr)
1124 .press(1, touch1.toPoint(), (QWindow*)nullptr);
1125
1126 touch1 += touchMovement;
1127 passTime(movementTimeStepMs);
1128 QTest::touchEvent(m_view, m_device)
1129 .move(0, touch0.toPoint(), (QWindow*)nullptr)
1130 .move(1, touch1.toPoint(), (QWindow*)nullptr);
1131
1132 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
1133
1134 QTest::touchEvent(m_view, m_device)
1135 .release(0, touch0.toPoint(), (QWindow*)nullptr)
1136 .move(1, touch1.toPoint(), (QWindow*)nullptr);
1137
1138 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
1139
1140 touch1 += touchMovement;
1141 passTime(movementTimeStepMs);
1142 QTest::touchEvent(m_view, m_device)
1143 .move(1, touch1.toPoint(), (QWindow*)nullptr);
1144
1145 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
1146
1147 QPointF touch2 = edgeDragArea->mapToScene(
1148 QPointF(edgeDragArea->width()*0.5, edgeDragArea->height()*0.9));
1149
1150 passTime(d->compositionTime + movementTimeStepMs);
1151 QTest::touchEvent(m_view, m_device)
1152 .move(1, touch1.toPoint(), (QWindow*)nullptr)
1153 .press(2, touch2.toPoint(), (QWindow*)nullptr);
1154
1155 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Undecided);
1156 QCOMPARE(d->touchId, 2);
1157
1158 touch2 += touchMovement;
1159 passTime(movementTimeStepMs);
1160 QTest::touchEvent(m_view, m_device)
1161 .move(1, touch1.toPoint(), (QWindow*)nullptr)
1162 .move(2, touch2.toPoint(), (QWindow*)nullptr);
1163
1164 touch1 += touchMovement;
1165 passTime(movementTimeStepMs);
1166 QTest::touchEvent(m_view, m_device)
1167 .move(1, touch1.toPoint(), (QWindow*)nullptr)
1168 .move(2, touch2.toPoint(), (QWindow*)nullptr);
1169
1170 passTime(movementTimeStepMs);
1171 QTest::touchEvent(m_view, m_device)
1172 .release(1, touch1.toPoint(), (QWindow*)nullptr)
1173 .move(2, touch2.toPoint(), (QWindow*)nullptr);
1174
1175 passTime(movementTimeStepMs);
1176 QTest::touchEvent(m_view, m_device)
1177 .release(2, touch2.toPoint(), (QWindow*)nullptr);
1178
1179 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::WaitingForTouch);
1180 }
1181
1182 /*
1183 A valid right-edge drag performed on mako
1184 */
1185 void tst_UCSwipeArea::makoRightEdgeDrag()
1186 {
1187 m_view->resize(768, 1280);
1188 QTest::qWait(300);
1189
1190 UCSwipeArea *edgeDragArea =
1191 m_view->rootObject()->findChild<UCSwipeArea*>("hnDragArea");
1192 QVERIFY(edgeDragArea != nullptr);
1193 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
1194 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
1195 d->setTimeSource(m_fakeTimerFactory->timeSource());
1196
1197 StatusSpy *statusSpy = new StatusSpy(edgeDragArea);
1198
1199 d->setPixelsPerMm(320.0 /*mako ppi*/ * 0.03937 /* inches per mm*/);
1200
1201 sendTouchPress(319744, 0, QPointF(767.001, 719.719));
1202 sendTouchUpdate(319765, 0, QPointF(765.744,729.973));
1203 sendTouchUpdate(319784, 0, QPointF(740.879,752.182));
1204 sendTouchUpdate(319803, 0, QPointF(689.698,795.795));
1205 sendTouchUpdate(319826, 0, QPointF(616.978,856.212));
1206 sendTouchUpdate(319845, 0, QPointF(558.769,906.157));
1207 sendTouchUpdate(319859, 0, QPointF(513.219,945.266));
1208 sendTouchUpdate(319878, 0, QPointF(481.31,975.496));
1209 sendTouchUpdate(319902, 0, QPointF(460.016,997.439));
1210 sendTouchUpdate(319920, 0, QPointF(449.761,1008.6));
1211 sendTouchUpdate(319929, 0, QPointF(445.891,1012.42));
1212 sendTouchUpdate(319947, 0, QPointF(444.884,1013.93));
1213 sendTouchUpdate(319965, 0, QPointF(444.461,1014.35));
1214 sendTouchUpdate(320057, 0, QPointF(444.71,1013.56));
1215 sendTouchUpdate(320138, 0, QPointF(445.434,1013.6));
1216 sendTouchUpdate(320154, 0, QPointF(446.338,1012.98));
1217 sendTouchUpdate(320171, 0, QPointF(447.232,1012.08));
1218 sendTouchRelease(320171, 0, QPointF(447.232,1012.08));
1219
1220 QTRY_COMPARE_WITH_TIMEOUT(statusSpy->recognized(), true, 500);
1221
1222 delete statusSpy;
1223 }
1224
1225 /*
1226 A vertical, downwards swipe performed on mako near its right edge.
1227
1228 The UCSwipeArea on the right edge must not recognize this
1229 gesture.
1230 */
1231 void tst_UCSwipeArea::makoRightEdgeDrag_verticalDownwards()
1232 {
1233 m_view->resize(768, 1280);
1234 QTest::qWait(300);
1235
1236 UCSwipeArea *edgeDragArea =
1237 m_view->rootObject()->findChild<UCSwipeArea*>("hnDragArea");
1238 QVERIFY(edgeDragArea != nullptr);
1239 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
1240 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
1241 d->setTimeSource(m_fakeTimerFactory->timeSource());
1242
1243 d->setPixelsPerMm(320.0 /*mako ppi*/ * 0.03937 /* inches per mm*/);
1244
1245 StatusSpy *statusSpy = new StatusSpy(edgeDragArea);
1246
1247 sendTouchPress(12012445, 26, QPointF(767.001,461.82));
1248 sendTouchUpdate(12012472, 26, QPointF(767.001,462.569));
1249 sendTouchUpdate(12012528, 26, QPointF(767.001,463.334));
1250 sendTouchUpdate(12012546, 26, QPointF(767.001,466.856));
1251 sendTouchUpdate(12012571, 26, QPointF(767.001,473.291));
1252 sendTouchUpdate(12012587, 26, QPointF(767.001,487.31));
1253 sendTouchUpdate(12012604, 26, QPointF(765.364,507.521));
1254 sendTouchUpdate(12012618, 26, QPointF(765.364,507.521));
1255 sendTouchUpdate(12012627, 26, QPointF(762.642,534.317));
1256 sendTouchUpdate(12012655, 26, QPointF(760.846,573.406));
1257 sendTouchUpdate(12012667, 26, QPointF(759.838,625.295));
1258 sendTouchUpdate(12012675, 26, QPointF(758.875,703.207));
1259 sendTouchUpdate(12012696, 26, QPointF(761.52,777.015));
1260 sendTouchUpdate(12012713, 26, QPointF(765.659,835.591));
1261 sendTouchUpdate(12012731, 26, QPointF(766.778,883.206));
1262 sendTouchUpdate(12012748, 26, QPointF(767.001,922.937));
1263 sendTouchUpdate(12012779, 26, QPointF(767.001,967.558));
1264 sendTouchUpdate(12012798, 26, QPointF(767.001,1006.12));
1265 sendTouchUpdate(12012809, 26, QPointF(767.001,1033.1));
1266 sendTouchRelease(12012810, 26, QPointF(767.001,1033.1));
1267
1268 QCOMPARE(statusSpy->recognized(), false);
1269
1270 delete statusSpy;
1271 }
1272
1273 /*
1274 A valid left-edge drag performed on mako. This one starts a bit slow than speeds up
1275 */
1276 void tst_UCSwipeArea::makoLeftEdgeDrag_slowStart()
1277 {
1278 m_view->resize(768, 1280);
1279 QTest::qWait(300);
1280
1281 UCSwipeArea *edgeDragArea =
1282 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
1283 QVERIFY(edgeDragArea != nullptr);
1284 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
1285 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
1286 d->setTimeSource(m_fakeTimerFactory->timeSource());
1287
1288 d->setPixelsPerMm(320.0 /*mako ppi*/ * 0.03937 /* inches per mm*/);
1289
1290 StatusSpy *statusSpy = new StatusSpy(edgeDragArea);
1291
1292 sendTouchPress(4002267, 77, QPointF(0,885.154));
1293 sendTouchUpdate(4002275, 77, QPointF(0,886.214));
1294 sendTouchUpdate(4002311, 77, QPointF(1.09568,887.75));
1295 sendTouchUpdate(4002329, 77, QPointF(3.53647,890.191));
1296 sendTouchUpdate(4002347, 77, QPointF(7.87434,892.879));
1297 sendTouchUpdate(4002366, 77, QPointF(12.3036,895.075));
1298 sendTouchUpdate(4002384, 77, QPointF(15.8885,896.849));
1299 sendTouchUpdate(4002406, 77, QPointF(18.4504,897.88));
1300 sendTouchUpdate(4002420, 77, QPointF(20.2429,898.149));
1301 sendTouchUpdate(4002439, 77, QPointF(20.9945,898.149));
1302 sendTouchUpdate(4002457, 77, QPointF(21.8819,898.149));
1303 sendTouchUpdate(4002480, 77, QPointF(22.7454,897.389));
1304 sendTouchUpdate(4002493, 77, QPointF(23.5456,896.589));
1305 sendTouchUpdate(4002511, 77, QPointF(24.5435,895.031));
1306 sendTouchUpdate(4002529, 77, QPointF(25.4271,892.32));
1307 sendTouchUpdate(4002548, 77, QPointF(26.3145,889.658));
1308 sendTouchUpdate(4002566, 77, QPointF(27.2004,886.999));
1309 sendTouchUpdate(4002584, 77, QPointF(28.035,885.048));
1310 sendTouchUpdate(4002603, 77, QPointF(29.9684,883.167));
1311 sendTouchUpdate(4002620, 77, QPointF(33.3591,881.403));
1312 sendTouchUpdate(4002639, 77, QPointF(44.1017,879.642));
1313 sendTouchUpdate(4002657, 77, QPointF(64.828,878.502));
1314 sendTouchUpdate(4002675, 77, QPointF(87.9486,878.157));
1315 sendTouchUpdate(4002693, 77, QPointF(112.96,877.742));
1316 sendTouchUpdate(4002711, 77, QPointF(138.903,877.157));
1317 sendTouchUpdate(4002729, 77, QPointF(163.204,877.157));
1318 sendTouchUpdate(4002747, 77, QPointF(182.127,877.157));
1319 sendTouchUpdate(4002765, 77, QPointF(194.478,877.657));
1320 sendTouchUpdate(4002785, 77, QPointF(201.474,878.508));
1321 sendTouchUpdate(4002803, 77, QPointF(204.855,879.401));
1322 sendTouchUpdate(4002822, 77, QPointF(206.616,880.281));
1323 sendTouchUpdate(4002839, 77, QPointF(207.115,880.906));
1324 sendTouchUpdate(4002894, 77, QPointF(206.865,881.184));
1325 sendTouchUpdate(4002912, 77, QPointF(206.865,882.143));
1326 sendTouchUpdate(4002930, 77, QPointF(206.865,883.106));
1327 sendTouchUpdate(4002949, 77, QPointF(206.526,883.994));
1328 sendTouchUpdate(4002967, 77, QPointF(205.866,884.88));
1329 sendTouchUpdate(4002985, 77, QPointF(205.866,885.766));
1330 sendTouchUpdate(4003005, 77, QPointF(205.866,886.654));
1331 sendTouchUpdate(4003021, 77, QPointF(205.366,887.537));
1332 sendTouchUpdate(4003039, 77, QPointF(204.592,888.428));
1333 sendTouchUpdate(4003050, 77, QPointF(204.367,888.653));
1334 sendTouchRelease(4003050, 77, QPointF(204.367,888.653));
1335
1336 QCOMPARE(statusSpy->recognized(), true);
1337
1338 delete statusSpy;
1339 }
1340
1341 void tst_UCSwipeArea::makoLeftEdgeDrag_movesSlightlyBackwardsOnStart()
1342 {
1343 m_view->resize(768, 1280);
1344 QTest::qWait(300);
1345
1346 UCSwipeArea *edgeDragArea =
1347 m_view->rootObject()->findChild<UCSwipeArea*>("hpDragArea");
1348 QVERIFY(edgeDragArea != nullptr);
1349 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
1350 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
1351 d->setTimeSource(m_fakeTimerFactory->timeSource());
1352
1353 d->setPixelsPerMm(320.0 /*mako ppi*/ * 0.03937 /* inches per mm*/);
1354
1355 StatusSpy *statusSpy = new StatusSpy(edgeDragArea);
1356
1357 sendTouchPress(41097, 24, QPointF(13.9909,827.177));
1358 sendTouchUpdate(41120, 24, QPointF(19.2375,825.677));
1359 sendTouchUpdate(41138, 24, QPointF(18.4057,826.177));
1360 sendTouchUpdate(41161, 24, QPointF(20.1067,825.867));
1361 sendTouchUpdate(41177, 24, QPointF(21.8869,824.977));
1362 sendTouchUpdate(41193, 24, QPointF(24.7603,823.494));
1363 sendTouchUpdate(41211, 24, QPointF(28.3889,821.725));
1364 sendTouchUpdate(41229, 24, QPointF(32.2909,819.955));
1365 sendTouchUpdate(41247, 24, QPointF(38.2251,817.431));
1366 sendTouchUpdate(41266, 24, QPointF(52.4182,814.223));
1367 sendTouchUpdate(41284, 24, QPointF(85.8465,809.483));
1368 sendTouchUpdate(41302, 24, QPointF(126.091,802.741));
1369 sendTouchUpdate(41320, 24, QPointF(153.171,797.977));
1370 sendTouchUpdate(41338, 24, QPointF(170.565,795.077));
1371 sendTouchUpdate(41356, 24, QPointF(178.685,794.101));
1372 sendTouchUpdate(41375, 24, QPointF(183.706,793.225));
1373 sendTouchUpdate(41393, 24, QPointF(186.112,793.19));
1374 sendTouchUpdate(41411, 24, QPointF(187.634,793.19));
1375 sendTouchUpdate(41429, 24, QPointF(188.505,793.19));
1376 sendTouchUpdate(41532, 24, QPointF(187.816,793.19));
1377 sendTouchUpdate(41538, 24, QPointF(186.902,793.19));
1378 sendTouchUpdate(41557, 24, QPointF(186.01,793.19));
1379 sendTouchUpdate(41575, 24, QPointF(185.125,793.444));
1380 sendTouchUpdate(41593, 24, QPointF(184.229,793.69));
1381 sendTouchUpdate(41605, 24, QPointF(183.88,793.69));
1382 sendTouchRelease(41607, 24, QPointF(183.88,793.69));
1383
1384 QCOMPARE(statusSpy->recognized(), true);
1385
1386 delete statusSpy;
1387 }
1388
1389 void tst_UCSwipeArea::grabGesture()
1390 {
1391 UCSwipeArea *edgeDragArea =
1392 m_view->rootObject()->findChild<UCSwipeArea*>("vpDragArea");
1393 Q_ASSERT(edgeDragArea != 0);
1394 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
1395 d->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragArea));
1396 d->setTimeSource(m_fakeTimerFactory->timeSource());
1397
1398 UCSwipeArea *edgeDragAreaNoGrab =
1399 m_view->rootObject()->findChild<UCSwipeArea*>("vpDragAreaNoGrab");
1400 Q_ASSERT(edgeDragAreaNoGrab != 0);
1401 QCOMPARE(edgeDragAreaNoGrab->grabGesture(), false);
1402 UCSwipeAreaPrivate *dNoGrab = UCSwipeAreaPrivate::get(edgeDragAreaNoGrab);
1403 dNoGrab->setRecognitionTimer(m_fakeTimerFactory->createTimer(edgeDragAreaNoGrab));
1404 dNoGrab->setTimeSource(m_fakeTimerFactory->timeSource());
1405
1406 QPointF touchPoint = calculateInitialtouchPosition(edgeDragArea);
1407
1408 qreal desiredDragDistance = d->distanceThreshold * 2.0f;
1409 QPointF dragDirectionVector(0., 1.); // vertical positive
1410
1411 qreal movementStepDistance = d->distanceThreshold * 0.1f;
1412 QPointF touchMovement = dragDirectionVector * movementStepDistance;
1413 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
1414 int movementTimeStepMs = (d->compositionTime * 1.5f) / totalMovementSteps;
1415
1416 qint64 timestamp = 0;
1417
1418 sendTouchPress(timestamp, 0, touchPoint);
1419
1420 for (int i = 0; i < totalMovementSteps; ++i) {
1421 touchPoint += touchMovement;
1422 timestamp += movementTimeStepMs;
1423 sendTouchUpdate(timestamp, 0, touchPoint);
1424 }
1425
1426 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
1427 QCOMPARE(edgeDragArea->dragging(), true);
1428
1429 QCOMPARE((int)dNoGrab->status, (int)UCSwipeAreaPrivate::Recognized);
1430 QCOMPARE(edgeDragAreaNoGrab->dragging(), true);
1431
1432 // Use a large distance margin because position smoothing makes it hard
1433 // to assume high accuracy. The test below using immediateRecognition uses
1434 // a smaller margin.
1435 // NB: qFuzzyCompare(), used internally by QCOMPARE(), is broken.
1436 QVERIFY(qAbs(edgeDragArea->distance() - edgeDragAreaNoGrab->distance()) < 2);
1437
1438 timestamp += movementTimeStepMs;
1439 sendTouchRelease(timestamp, 0, touchPoint);
1440 }
1441
1442 void tst_UCSwipeArea::grabGestureWithImmediateRecognition()
1443 {
1444 UCSwipeArea *edgeDragArea =
1445 m_view->rootObject()->findChild<UCSwipeArea*>("vpDragArea");
1446 Q_ASSERT(edgeDragArea != 0);
1447 UCSwipeAreaPrivate *d = UCSwipeAreaPrivate::get(edgeDragArea);
1448
1449 UCSwipeArea *edgeDragAreaNoGrab =
1450 m_view->rootObject()->findChild<UCSwipeArea*>("vpDragAreaNoGrab");
1451 Q_ASSERT(edgeDragAreaNoGrab != 0);
1452 QCOMPARE(edgeDragAreaNoGrab->grabGesture(), false);
1453 UCSwipeAreaPrivate *dNoGrab = UCSwipeAreaPrivate::get(edgeDragAreaNoGrab);
1454
1455 edgeDragArea->setImmediateRecognition(true);
1456 edgeDragAreaNoGrab->setImmediateRecognition(true);
1457
1458 QPointF touchPoint = calculateInitialtouchPosition(edgeDragArea);
1459
1460 qreal desiredDragDistance = d->distanceThreshold * 2.0f;
1461 QPointF dragDirectionVector(0., 1.); // vertical positive
1462
1463 qreal movementStepDistance = d->distanceThreshold * 0.1f;
1464 QPointF touchMovement = dragDirectionVector * movementStepDistance;
1465 int totalMovementSteps = qCeil(desiredDragDistance / movementStepDistance);
1466 int movementTimeStepMs = (d->compositionTime * 1.5f) / totalMovementSteps;
1467
1468 qint64 timestamp = 0;
1469
1470 sendTouchPress(timestamp, 0, touchPoint);
1471
1472 for (int i = 0; i < totalMovementSteps; ++i) {
1473 touchPoint += touchMovement;
1474 timestamp += movementTimeStepMs;
1475 sendTouchUpdate(timestamp, 0, touchPoint);
1476 }
1477
1478 QCOMPARE((int)d->status, (int)UCSwipeAreaPrivate::Recognized);
1479 QCOMPARE(edgeDragArea->dragging(), true);
1480
1481 QCOMPARE((int)dNoGrab->status, (int)UCSwipeAreaPrivate::Recognized);
1482 QCOMPARE(edgeDragAreaNoGrab->dragging(), true);
1483
1484 // NB: qFuzzyCompare(), used internally by QCOMPARE(), is broken.
1485 QVERIFY(qAbs(edgeDragArea->distance() - edgeDragAreaNoGrab->distance()) < 0.001);
1486
1487 timestamp += movementTimeStepMs;
1488 sendTouchRelease(timestamp, 0, touchPoint);
1489 }
1490
1491 QTEST_MAIN(tst_UCSwipeArea)
1492
1493 #include "tst_swipearea.moc"