aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2021-01-14 18:46:17 +0100
committerJan Arve Sæther <jan-arve.saether@qt.io>2021-01-29 11:05:52 +0100
commit4b1acb290dc8869d0d2d1250dc1ed415d6b6e202 (patch)
treeb542f3cd93d6ea07b0843c853bd38c2498ba4724 /tests/auto
parentf9813dfa243d109dd027a40b5ca505fdee79e877 (diff)
a11y: Fix ordering on header, content item and footer in Page
Because of the previous behavior, the footer could be read aloud by the screen reader before the content item. And even worse, the footer could be read aloud even before the header in some cases. This made it hard for visually impaired people to use the application. The Page type was used by the Dialog type, so it also affected that. Fixes: QTBUG-75042 Pick-to: 5.15 6.0 Change-Id: Ic3e8ec3f7dcf18af9262b1d35c986835c8da6900 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/accessibility/accessibility.pro4
-rw-r--r--tests/auto/accessibility/data/ordering/page.qml23
-rw-r--r--tests/auto/accessibility/tst_accessibility.cpp30
3 files changed, 56 insertions, 1 deletions
diff --git a/tests/auto/accessibility/accessibility.pro b/tests/auto/accessibility/accessibility.pro
index d8d5bb95..4cc101fb 100644
--- a/tests/auto/accessibility/accessibility.pro
+++ b/tests/auto/accessibility/accessibility.pro
@@ -12,5 +12,7 @@ include (../shared/util.pri)
TESTDATA = data/*
OTHER_FILES += \
- data/*.qml
+ data/defaults\*.qml \
+ data/ordering\*.qml \
+ data/override*.qml
diff --git a/tests/auto/accessibility/data/ordering/page.qml b/tests/auto/accessibility/data/ordering/page.qml
new file mode 100644
index 00000000..8efafe32
--- /dev/null
+++ b/tests/auto/accessibility/data/ordering/page.qml
@@ -0,0 +1,23 @@
+import QtQuick
+import QtQuick.Controls
+
+Page {
+ title: "Page"
+ Accessible.role: Accessible.Pane
+
+ header: Label {
+ text: "Header"
+ }
+
+ footer: Label {
+ text: "Footer"
+ }
+
+ Label {
+ text: "Content item 1"
+ }
+
+ Label {
+ text: "Content item 2"
+ }
+}
diff --git a/tests/auto/accessibility/tst_accessibility.cpp b/tests/auto/accessibility/tst_accessibility.cpp
index 3d9a318d..f2cb8b60 100644
--- a/tests/auto/accessibility/tst_accessibility.cpp
+++ b/tests/auto/accessibility/tst_accessibility.cpp
@@ -60,6 +60,7 @@ private slots:
void override_data();
void override();
+ void ordering();
private:
QQmlEngine engine;
};
@@ -268,6 +269,35 @@ void tst_accessibility::override()
Q_UNUSED(text);
#endif
}
+template <typename Predicate>
+void a11yDescendants(QAccessibleInterface *iface, Predicate pred)
+{
+ for (int i = 0; i < iface->childCount(); ++i) {
+ if (QAccessibleInterface *child = iface->child(i)) {
+ pred(child);
+ a11yDescendants(child, pred);
+ }
+ }
+}
+
+void tst_accessibility::ordering()
+{
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("ordering/page.qml"));
+
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY2(!object.isNull(), qPrintable(component.errorString()));
+
+#if QT_CONFIG(accessibility)
+ QQuickItem *item = findItem(object.data());
+ QVERIFY(item);
+ QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(item);
+ QVERIFY(iface);
+ QStringList strings;
+ a11yDescendants(iface, [&](QAccessibleInterface *iface) {strings << iface->text(QAccessible::Name);});
+ QCOMPARE(strings.join(QLatin1String(", ")), "Header, Content item 1, Content item 2, Footer");
+#endif
+}
QTEST_MAIN(tst_accessibility)