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 <liang.qi@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Tor Arne Vestbø 2019-01-14 12:20:33 +01:00 committed by Liang Qi
parent cfdb483613
commit 4aa7fe666b
1 changed files with 28 additions and 22 deletions

View File

@ -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());
// 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)) {
// active
window.show();
window.requestActivate();
QVERIFY(QTest::qWaitForWindowActive(&window));
QCOMPARE(QGuiApplication::focusWindow(), &window);
QVERIFY(item->property("active").toBool());
QVERIFY(item->property("active2").toBool());
// Flush pending events, in case the platform have already queued real application state events
QWindowSystemInterface::flushWindowSystemEvents();
QWindowSystemInterface::handleWindowActivated(nullptr);
QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive);
QWindowSystemInterface::flushWindowSystemEvents();
QVERIFY(item->property("active").toBool());
QVERIFY(item->property("active2").toBool());
#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
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()