aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-09-06 09:21:15 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-09-06 15:20:10 +0000
commit9ae57848671419b2622e254af8642fef7b1b7c33 (patch)
treed25df980ee418ecd2fe09312873b42ab8691f677 /tests
parentbc0fdae8fad4e199792b3f00ebcb74bd80473227 (diff)
QQuickDrawer: fix the internal transition state
When QQuickDrawer was visible all the time, it did not emit the visibility related signals at all. Now the signals are emitted, but aboutToShow() and visibleChanged() were emitted twice when a drawer was manually dragged open. First time when the dragging begins (the drawer becomes effectively visible), and second time when the open transition begins after mouse/touch release. This change ensures that the signals won't be emitted again when the transition begins, in case they were already emitted. Change-Id: I2a175c9e86a480d5cd23e306f41f0d85e2416f75 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/drawer/tst_drawer.cpp102
-rw-r--r--tests/auto/popup/tst_popup.cpp41
2 files changed, 143 insertions, 0 deletions
diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp
index 02a4f91f..8f023c29 100644
--- a/tests/auto/drawer/tst_drawer.cpp
+++ b/tests/auto/drawer/tst_drawer.cpp
@@ -56,6 +56,8 @@ private slots:
void visible_data();
void visible();
+ void state();
+
void position_data();
void position();
@@ -118,6 +120,106 @@ void tst_Drawer::visible()
QTRY_VERIFY(!overlay->childItems().contains(popupItem));
}
+void tst_Drawer::state()
+{
+ QQuickApplicationHelper helper(this, "applicationwindow.qml");
+
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer*>();
+ QVERIFY(drawer);
+
+ QCOMPARE(drawer->isVisible(), false);
+
+ QSignalSpy visibleChangedSpy(drawer, SIGNAL(visibleChanged()));
+ QSignalSpy aboutToShowSpy(drawer, SIGNAL(aboutToShow()));
+ QSignalSpy aboutToHideSpy(drawer, SIGNAL(aboutToHide()));
+ QSignalSpy openedSpy(drawer, SIGNAL(opened()));
+ QSignalSpy closedSpy(drawer, SIGNAL(closed()));
+
+ QVERIFY(visibleChangedSpy.isValid());
+ QVERIFY(aboutToShowSpy.isValid());
+ QVERIFY(aboutToHideSpy.isValid());
+ QVERIFY(openedSpy.isValid());
+ QVERIFY(closedSpy.isValid());
+
+ int visibleChangedCount = 0;
+ int aboutToShowCount = 0;
+ int aboutToHideCount = 0;
+ int openedCount = 0;
+ int closedCount = 0;
+
+ // open programmatically...
+ drawer->open();
+ QCOMPARE(visibleChangedSpy.count(), ++visibleChangedCount);
+ QCOMPARE(aboutToShowSpy.count(), ++aboutToShowCount);
+ QCOMPARE(aboutToHideSpy.count(), aboutToHideCount);
+ QCOMPARE(openedSpy.count(), openedCount);
+ QCOMPARE(closedSpy.count(), closedCount);
+
+ // ...and wait until fully open
+ QVERIFY(openedSpy.wait());
+ QCOMPARE(visibleChangedSpy.count(), visibleChangedCount);
+ QCOMPARE(aboutToShowSpy.count(), aboutToShowCount);
+ QCOMPARE(aboutToHideSpy.count(), aboutToHideCount);
+ QCOMPARE(openedSpy.count(), ++openedCount);
+ QCOMPARE(closedSpy.count(), closedCount);
+
+ // close programmatically...
+ drawer->close();
+ QCOMPARE(visibleChangedSpy.count(), visibleChangedCount);
+ QCOMPARE(aboutToShowSpy.count(), aboutToShowCount);
+ QCOMPARE(aboutToHideSpy.count(), ++aboutToHideCount);
+ QCOMPARE(openedSpy.count(), openedCount);
+ QCOMPARE(closedSpy.count(), closedCount);
+
+ // ...and wait until fully closed
+ QVERIFY(closedSpy.wait());
+ QCOMPARE(visibleChangedSpy.count(), ++visibleChangedCount);
+ QCOMPARE(aboutToShowSpy.count(), aboutToShowCount);
+ QCOMPARE(aboutToHideSpy.count(), aboutToHideCount);
+ QCOMPARE(openedSpy.count(), openedCount);
+ QCOMPARE(closedSpy.count(), ++closedCount);
+
+ // open interactively...
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, drawer->height() / 2));
+ QTest::mouseMove(window, QPoint(drawer->width() * 0.2, drawer->height() / 2), 16);
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width() * 0.8, drawer->height() / 2), 16);
+ QCOMPARE(visibleChangedSpy.count(), ++visibleChangedCount);
+ QCOMPARE(aboutToShowSpy.count(), ++aboutToShowCount);
+ QCOMPARE(aboutToHideSpy.count(), aboutToHideCount);
+ QCOMPARE(openedSpy.count(), openedCount);
+ QCOMPARE(closedSpy.count(), closedCount);
+
+ // ...and wait until fully open
+ QVERIFY(openedSpy.wait());
+ QCOMPARE(visibleChangedSpy.count(), visibleChangedCount);
+ QCOMPARE(aboutToShowSpy.count(), aboutToShowCount);
+ QCOMPARE(aboutToHideSpy.count(), aboutToHideCount);
+ QCOMPARE(openedSpy.count(), ++openedCount);
+ QCOMPARE(closedSpy.count(), closedCount);
+
+ // close interactively...
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width(), drawer->height() / 2));
+ QTest::mouseMove(window, QPoint(drawer->width() * 0.8, drawer->height() / 2), 16);
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width() * 0.2, drawer->height() / 2), 16);
+ QCOMPARE(visibleChangedSpy.count(), visibleChangedCount);
+ QCOMPARE(aboutToShowSpy.count(), aboutToShowCount);
+ QCOMPARE(aboutToHideSpy.count(), ++aboutToHideCount);
+ QCOMPARE(openedSpy.count(), openedCount);
+ QCOMPARE(closedSpy.count(), closedCount);
+
+ // ...and wait until fully closed
+ QVERIFY(closedSpy.wait());
+ QCOMPARE(visibleChangedSpy.count(), ++visibleChangedCount);
+ QCOMPARE(aboutToShowSpy.count(), aboutToShowCount);
+ QCOMPARE(aboutToHideSpy.count(), aboutToHideCount);
+ QCOMPARE(openedSpy.count(), openedCount);
+ QCOMPARE(closedSpy.count(), ++closedCount);
+}
+
void tst_Drawer::position_data()
{
QTest::addColumn<Qt::Edge>("edge");
diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp
index 990140db..a6848fc8 100644
--- a/tests/auto/popup/tst_popup.cpp
+++ b/tests/auto/popup/tst_popup.cpp
@@ -53,6 +53,7 @@ class tst_popup : public QQmlDataTest
private slots:
void visible_data();
void visible();
+ void state();
void overlay_data();
void overlay();
void zOrder_data();
@@ -108,6 +109,46 @@ void tst_popup::visible()
QVERIFY(!overlay->childItems().contains(popupItem));
}
+void tst_popup::state()
+{
+ QQuickApplicationHelper helper(this, "applicationwindow.qml");
+
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickPopup *popup = window->property("popup").value<QQuickPopup*>();
+ QVERIFY(popup);
+
+ QCOMPARE(popup->isVisible(), false);
+
+ QSignalSpy visibleChangedSpy(popup, SIGNAL(visibleChanged()));
+ QSignalSpy aboutToShowSpy(popup, SIGNAL(aboutToShow()));
+ QSignalSpy aboutToHideSpy(popup, SIGNAL(aboutToHide()));
+ QSignalSpy openedSpy(popup, SIGNAL(opened()));
+ QSignalSpy closedSpy(popup, SIGNAL(closed()));
+
+ QVERIFY(visibleChangedSpy.isValid());
+ QVERIFY(aboutToShowSpy.isValid());
+ QVERIFY(aboutToHideSpy.isValid());
+ QVERIFY(openedSpy.isValid());
+ QVERIFY(closedSpy.isValid());
+
+ popup->open();
+ QCOMPARE(visibleChangedSpy.count(), 1);
+ QCOMPARE(aboutToShowSpy.count(), 1);
+ QCOMPARE(aboutToHideSpy.count(), 0);
+ QTRY_COMPARE(openedSpy.count(), 1);
+ QCOMPARE(closedSpy.count(), 0);
+
+ popup->close();
+ QCOMPARE(visibleChangedSpy.count(), 2);
+ QCOMPARE(aboutToShowSpy.count(), 1);
+ QCOMPARE(aboutToHideSpy.count(), 1);
+ QCOMPARE(openedSpy.count(), 1);
+ QTRY_COMPARE(closedSpy.count(), 1);
+}
+
void tst_popup::overlay_data()
{
QTest::addColumn<QString>("source");