Update tst_qquickapplication to support OS X ApplicationState handling
authorSamuel Gaist <samuel.gaist@edeltech.ch>
Thu, 1 May 2014 07:21:05 +0000 (09:21 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 1 May 2014 09:22:43 +0000 (11:22 +0200)
This patch modifies tst_qquickapplication so that it tests correctly
against OS X's new ApplicationState handling

Task-number: QTBUG-10899
Change-Id: Iea20b0137daabe03fdddf98435dc2626e122741f
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
tests/auto/quick/qquickapplication/tst_qquickapplication.cpp

index dfcef43..0993d03 100644 (file)
@@ -60,6 +60,7 @@ private slots:
     void state();
     void layoutDirection();
     void inputMethod();
+    void cleanup();
 
 private:
     QQmlEngine engine;
@@ -69,6 +70,14 @@ tst_qquickapplication::tst_qquickapplication()
 {
 }
 
+void tst_qquickapplication::cleanup()
+{
+    if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) {
+        QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive);
+        QTest::waitForEvents();
+    }
+}
+
 void tst_qquickapplication::active()
 {
     QQmlComponent component(&engine);
@@ -98,12 +107,19 @@ void tst_qquickapplication::active()
     QVERIFY(item->property("active").toBool());
     QVERIFY(item->property("active2").toBool());
 
-    // not active again
     QWindowSystemInterface::handleWindowActivated(0);
 
+#ifdef Q_OS_OSX
+    // OS X has the concept of "reactivation"
+    QTRY_VERIFY(QGuiApplication::focusWindow() != &window);
+    QVERIFY(item->property("active").toBool());
+    QVERIFY(item->property("active2").toBool());
+#else
+    // not active again
     QTRY_VERIFY(QGuiApplication::focusWindow() != &window);
     QVERIFY(!item->property("active").toBool());
     QVERIFY(!item->property("active2").toBool());
+#endif
 }
 
 void tst_qquickapplication::state()
@@ -117,6 +133,7 @@ void tst_qquickapplication::state()
                       "        target: Qt.application; "
                       "        onStateChanged: state2 = Qt.application.state; "
                       "    } "
+                      "    Component.onCompleted: state2 = Qt.application.state; "
                       "}", QUrl::fromLocalFile(""));
     QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
     QVERIFY(item);