From 4aa7fe666be35b5699b0e201c3a963777f874e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 14 Jan 2019 12:20:33 +0100 Subject: tst_qquickapplication: Don't assume app activation is tied to window activation Follows same approach as 47f6d256ed in tst_qquickapplication::state(). Change-Id: Ibecdab3f874fc9e75b38ba2ccaf3776bd46c77e8 Fixes: QTBUG-72953 Reviewed-by: Liang Qi Reviewed-by: Richard Moe Gustavsen --- .../qquickapplication/tst_qquickapplication.cpp | 56 ++++++++++++---------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'tests/auto/quick/qquickapplication') diff --git a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp index 62027f59f4..3526eb98be 100644 --- a/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp +++ b/tests/auto/quick/qquickapplication/tst_qquickapplication.cpp @@ -88,31 +88,37 @@ void tst_qquickapplication::active() QQuickWindow window; item->setParentItem(window.contentItem()); - // not active - QVERIFY(!item->property("active").toBool()); - QVERIFY(!item->property("active2").toBool()); - - // active - window.show(); - window.requestActivate(); - QVERIFY(QTest::qWaitForWindowActive(&window)); - QCOMPARE(QGuiApplication::focusWindow(), &window); - QVERIFY(item->property("active").toBool()); - QVERIFY(item->property("active2").toBool()); - - QWindowSystemInterface::handleWindowActivated(nullptr); - -#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 + // If the platform plugin has the ApplicationState capability, app activation originate from it + // as a result of a system event. We therefore have to simulate these events here. + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ApplicationState)) { + + // Flush pending events, in case the platform have already queued real application state events + QWindowSystemInterface::flushWindowSystemEvents(); + + QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive); + QWindowSystemInterface::flushWindowSystemEvents(); + QVERIFY(item->property("active").toBool()); + QVERIFY(item->property("active2").toBool()); + + QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive); + QWindowSystemInterface::flushWindowSystemEvents(); + QVERIFY(!item->property("active").toBool()); + QVERIFY(!item->property("active2").toBool()); + } else { + // Otherwise, app activation is triggered by window activation. + window.show(); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + QCOMPARE(QGuiApplication::focusWindow(), &window); + QVERIFY(item->property("active").toBool()); + QVERIFY(item->property("active2").toBool()); + + // not active again + QWindowSystemInterface::handleWindowActivated(nullptr); + QTRY_VERIFY(QGuiApplication::focusWindow() != &window); + QVERIFY(!item->property("active").toBool()); + QVERIFY(!item->property("active2").toBool()); + } } void tst_qquickapplication::state() -- cgit v1.2.3