Fix tst_qaccessibility on Android

On Android we had 10 failing unit-tests in tst_qaccessibility

One of them was failing because on Android QMdiSubWindow is created
maximized by default, so we need to explicitly call showNormal() on
it before doing all the checks.

Other 9 were failing because we didn't get A11Y events when expected.
This is a bit more tricky.
On Android a11y state is not explicitly set by calling
QPlatformAccessibility::setActive(), there is another flag that is
controller from the Java side. It is set to 'true' only when some
of the a11y services are enabled on the device. The state of this
flag is queried during event processing, so a11y state can be reset
to false while we do QTest::qWait().
This logic is absolutely correct for real applications, but it is
a problem for the test case, because we can't easily enable a11y
services in the CI.
To overcome the issue in unit-tests, re-enable a11y before each test.
A more precise fix will require re-enabling it after every qWait() or
processEvents() call, but the current tests pass with such condition.

Fixes: QTBUG-87674
Change-Id: I6f765bc6d3aaeaa19aba3a64473ea25e9cbdb0f8
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 3b82c2d16780c4474ebdf7064f406dc266eeba58)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ivan Solovev 2022-02-16 18:07:54 +01:00 committed by Qt Cherry-pick Bot
parent e336e062ef
commit 1dde5a6cce
2 changed files with 27 additions and 5 deletions

View File

@ -21,8 +21,7 @@ endif()
if(TARGET Qt::Network)
add_subdirectory(networkselftest)
endif()
# QTBUG-87674 # special case
if(QT_FEATURE_accessibility AND TARGET Qt::Gui AND TARGET Qt::Widgets AND NOT ANDROID)
if(QT_FEATURE_accessibility AND TARGET Qt::Gui AND TARGET Qt::Widgets)
add_subdirectory(qaccessibility)
endif()
if(TARGET Qt::Gui)

View File

@ -269,13 +269,21 @@ void tst_QAccessibility::onClicked()
click_count++;
}
static bool initAccessibility()
{
QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
if (pfIntegration->accessibility()) {
pfIntegration->accessibility()->setActive(true);
return true;
}
return false;
}
void tst_QAccessibility::initTestCase()
{
QTestAccessibility::initialize();
QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
if (!pfIntegration->accessibility())
if (!initAccessibility())
QSKIP("This platform does not support accessibility");
pfIntegration->accessibility()->setActive(true);
}
void tst_QAccessibility::cleanupTestCase()
@ -286,6 +294,17 @@ void tst_QAccessibility::cleanupTestCase()
void tst_QAccessibility::init()
{
QTestAccessibility::clearEvents();
#ifdef Q_OS_ANDROID
// On Android a11y state is not explicitly set by calling
// QPlatformAccessibility::setActive(), there is another flag that is
// controlled from the Java side. The state of this flag is queried
// during event processing, so a11y state can be reset to false while
// we do QTest::qWait().
// To overcome the issue in unit-tests, re-enable a11y before each test.
// A more precise fix will require re-enabling it after every qWait() or
// processEvents() call, but the current tests pass with such condition.
initAccessibility();
#endif
}
void tst_QAccessibility::cleanup()
@ -1978,6 +1997,10 @@ void tst_QAccessibility::mdiSubWindowTest()
mdiArea.setActiveSubWindow(testWindow);
#ifdef Q_OS_ANDROID // on Android QMdiSubWindow is maximized by default
testWindow->showNormal();
#endif
// state
QAccessible::State state;
state.focusable = true;