From 4ed8733d909f8a6b719bf56266114eae885cd74f Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 4 Jan 2016 16:37:55 +0100 Subject: tst_Gesture - fix failing tests on OS X 10.11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test seems to be quite broken on OS X: qWaitForWindowExposed returns too early (while no window is on screen) so gestures can not be dispatched QApplication::topLevelAt(pt) - returns null. Use qWait + isExposed combo instead (similar to qWaitForWindowExposed, but there is no isExposed test before the loop). Change-Id: I85fbd773ccce0ca92b2dceb1749d67ef767aa0cf Task-number: QTBUG-49849 Reviewed-by: Morten Johan Sørvig --- tests/auto/other/gestures/tst_gestures.cpp | 56 ++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/tests/auto/other/gestures/tst_gestures.cpp b/tests/auto/other/gestures/tst_gestures.cpp index 2a4f88c627..6db918cffd 100644 --- a/tests/auto/other/gestures/tst_gestures.cpp +++ b/tests/auto/other/gestures/tst_gestures.cpp @@ -48,6 +48,24 @@ #include +static bool waitForWindowExposed(QWindow *window) +{ + if (!window) + return false; +#ifdef Q_OS_OSX + QTest::qWait(100); + return window->isExposed(); +#endif + return QTest::qWaitForWindowExposed(window); +} + +static bool waitForWindowExposed(QWidget *widget) +{ + if (!widget) + return false; + return waitForWindowExposed(widget->windowHandle()); +} + static QPointF mapToGlobal(const QPointF &pt, QGraphicsItem *item, QGraphicsView *view) { return view->viewport()->mapToGlobal(view->mapFromScene(item->mapToScene(pt))); @@ -387,7 +405,7 @@ void tst_Gestures::customGesture() GestureWidget widget; widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); widget.show(); - QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QVERIFY(waitForWindowExposed(&widget)); CustomEvent event; event.hotSpot = widget.mapToGlobal(QPoint(5,5)); @@ -856,7 +874,7 @@ void tst_Gestures::graphicsItemGesture() item->setPos(100, 100); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); item->grabGesture(CustomGesture::GestureType); @@ -918,7 +936,7 @@ void tst_Gestures::graphicsView() item->setPos(100, 100); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); item->grabGesture(CustomGesture::GestureType); @@ -994,7 +1012,7 @@ void tst_Gestures::graphicsItemTreeGesture() item1_child2->setParentItem(item1); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); item1->grabGesture(CustomGesture::GestureType); @@ -1051,7 +1069,7 @@ void tst_Gestures::explicitGraphicsObjectTarget() item2_child1->setPos(10, 10); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); item1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); @@ -1110,7 +1128,7 @@ void tst_Gestures::gestureOverChildGraphicsItem() item2_child1->setPos(0, 0); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); item1->grabGesture(CustomGesture::GestureType); @@ -1408,7 +1426,7 @@ void tst_Gestures::testMapToScene() item0->setPos(14, 16); view.show(); // need to show to give it a global coordinate - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); QPoint origin = view.mapToGlobal(QPoint()); @@ -1534,7 +1552,7 @@ void tst_Gestures::autoCancelGestures() parent.grabGesture(CustomGesture::GestureType); child->grabGesture(secondGesture); parent.show(); - QVERIFY(QTest::qWaitForWindowExposed(&parent)); + QVERIFY(waitForWindowExposed(&parent)); /* An event is sent to both the child and the parent, when the child gets it a gesture is triggered @@ -1593,7 +1611,7 @@ void tst_Gestures::autoCancelGestures2() child->grabGesture(secondGesture); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); CustomEvent event; @@ -1639,7 +1657,7 @@ void tst_Gestures::graphicsViewParentPropagation() item1_c1_c1->setPos(0, 0); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); item0->grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures | Qt::IgnoredGesturesPropagateToParent); @@ -1709,7 +1727,7 @@ void tst_Gestures::panelPropagation() item1_child1_child1->setZValue(10); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -1820,7 +1838,7 @@ void tst_Gestures::panelStacksBehindParent() panel->setZValue(5); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -1904,7 +1922,7 @@ void tst_Gestures::deleteGestureTargetItem() items.insert(item2->objectName(), item2); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); if (propagateUpdateGesture) @@ -1949,7 +1967,7 @@ void tst_Gestures::viewportCoordinates() scene.addItem(item1); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); CustomEvent event; @@ -1986,7 +2004,7 @@ void tst_Gestures::partialGesturePropagation() scene.addItem(item4); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); item1->ignoredUpdatedGestures << CustomGesture::GestureType; @@ -2074,7 +2092,7 @@ void tst_Gestures::testQGestureRecognizerCleanup() //QGestureRecognizer::registerRecognizer(new PanRecognizer(PanRecognizer::Custom)); w->show(); - QVERIFY(QTest::qWaitForWindowExposed(w)); + QVERIFY(waitForWindowExposed(w)); delete w; } @@ -2195,7 +2213,7 @@ void tst_Gestures::testReuseCanceledGestures() gv->viewport()->grabGesture(tapGestureTypeId); mw.show(); - QVERIFY(QTest::qWaitForWindowExposed(&mw)); + QVERIFY(waitForWindowExposed(&mw)); QPoint targetPos(gv->mapFromScene(target->mapToScene(target->rect().center()))); targetPos = gv->viewport()->mapFromParent(targetPos); @@ -2261,7 +2279,7 @@ void tst_Gestures::conflictingGesturesInGraphicsView() scene.addItem(item2); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(waitForWindowExposed(&view)); view.ensureVisible(scene.sceneRect()); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -2326,7 +2344,7 @@ void tst_Gestures::bug_13501_gesture_not_accepted() NoConsumeWidgetBug13501 w; w.grabGesture(Qt::TapGesture); w.show(); - QVERIFY(QTest::qWaitForWindowExposed(&w)); + QVERIFY(waitForWindowExposed(&w)); //QTest::mousePress(&ignoreEvent, Qt::LeftButton); QTouchDevice *device = new QTouchDevice; device->setType(QTouchDevice::TouchScreen); -- cgit v1.2.3