aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/accessibility
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-09-02 16:40:32 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-09-14 18:51:51 +0000
commit9ecf1fd9507101607996e8df50093098edab5d64 (patch)
tree179df2c6dbb647b6cad44967148c7cd63e68ec6d /tests/auto/accessibility
parent8957158ce42ffe1823b7ae1304a48bfdca40ec86 (diff)
Controls: move Accessible from QML to C++
Controls 2.0 could be built with QT_NO_ACCESSIBILITY defined. Added a few helper functions for accessible in QQuickControl. Don't set text as Accessible.name for TextArea and TextField. Change-Id: I40383bbcec2f8c742f709bdec0209623f80da449 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'tests/auto/accessibility')
-rw-r--r--tests/auto/accessibility/accessibility.pro15
-rw-r--r--tests/auto/accessibility/data/busyindicator.qml12
-rw-r--r--tests/auto/accessibility/data/button.qml13
-rw-r--r--tests/auto/accessibility/data/checkbox.qml13
-rw-r--r--tests/auto/accessibility/data/control.qml12
-rw-r--r--tests/auto/accessibility/data/label.qml13
-rw-r--r--tests/auto/accessibility/data/pageindicator.qml12
-rw-r--r--tests/auto/accessibility/data/progressbar.qml15
-rw-r--r--tests/auto/accessibility/data/radiobutton.qml13
-rw-r--r--tests/auto/accessibility/data/scrollbar.qml12
-rw-r--r--tests/auto/accessibility/data/scrollindicator.qml12
-rw-r--r--tests/auto/accessibility/data/slider.qml17
-rw-r--r--tests/auto/accessibility/data/switch.qml13
-rw-r--r--tests/auto/accessibility/data/tabbar.qml12
-rw-r--r--tests/auto/accessibility/data/tabbutton.qml17
-rw-r--r--tests/auto/accessibility/data/textarea-2.qml13
-rw-r--r--tests/auto/accessibility/data/textarea.qml14
-rw-r--r--tests/auto/accessibility/data/textfield-2.qml13
-rw-r--r--tests/auto/accessibility/data/textfield.qml14
-rw-r--r--tests/auto/accessibility/data/togglebutton.qml13
-rw-r--r--tests/auto/accessibility/data/toolbar.qml12
-rw-r--r--tests/auto/accessibility/data/toolbutton.qml13
-rw-r--r--tests/auto/accessibility/tst_accessibility.cpp136
23 files changed, 429 insertions, 0 deletions
diff --git a/tests/auto/accessibility/accessibility.pro b/tests/auto/accessibility/accessibility.pro
new file mode 100644
index 00000000..c57eba11
--- /dev/null
+++ b/tests/auto/accessibility/accessibility.pro
@@ -0,0 +1,15 @@
+CONFIG += testcase
+TARGET = tst_accessibility
+SOURCES += tst_accessibility.cpp
+
+osx:CONFIG -= app_bundle
+
+QT += core-private gui-private qml-private quick-private testlib
+
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
+OTHER_FILES += \
+ data/*
+
diff --git a/tests/auto/accessibility/data/busyindicator.qml b/tests/auto/accessibility/data/busyindicator.qml
new file mode 100644
index 00000000..4bde9634
--- /dev/null
+++ b/tests/auto/accessibility/data/busyindicator.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ BusyIndicator {
+ id: busyindicator
+ objectName: "busyindicator"
+ }
+}
diff --git a/tests/auto/accessibility/data/button.qml b/tests/auto/accessibility/data/button.qml
new file mode 100644
index 00000000..75925185
--- /dev/null
+++ b/tests/auto/accessibility/data/button.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ Button {
+ id: button
+ objectName: "button"
+ text: "Button"
+ }
+}
diff --git a/tests/auto/accessibility/data/checkbox.qml b/tests/auto/accessibility/data/checkbox.qml
new file mode 100644
index 00000000..9700663d
--- /dev/null
+++ b/tests/auto/accessibility/data/checkbox.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ CheckBox {
+ id: checkbox
+ objectName: "checkbox"
+ text: "CheckBox"
+ }
+}
diff --git a/tests/auto/accessibility/data/control.qml b/tests/auto/accessibility/data/control.qml
new file mode 100644
index 00000000..ceaba509
--- /dev/null
+++ b/tests/auto/accessibility/data/control.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ Control {
+ id: control
+ objectName: "control"
+ }
+}
diff --git a/tests/auto/accessibility/data/label.qml b/tests/auto/accessibility/data/label.qml
new file mode 100644
index 00000000..409898d4
--- /dev/null
+++ b/tests/auto/accessibility/data/label.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ Label {
+ id: label
+ objectName: "label"
+ text: "Label"
+ }
+}
diff --git a/tests/auto/accessibility/data/pageindicator.qml b/tests/auto/accessibility/data/pageindicator.qml
new file mode 100644
index 00000000..b42d3f9e
--- /dev/null
+++ b/tests/auto/accessibility/data/pageindicator.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ PageIndicator {
+ id: pageindicator
+ objectName: "pageindicator"
+ }
+}
diff --git a/tests/auto/accessibility/data/progressbar.qml b/tests/auto/accessibility/data/progressbar.qml
new file mode 100644
index 00000000..283db003
--- /dev/null
+++ b/tests/auto/accessibility/data/progressbar.qml
@@ -0,0 +1,15 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ ProgressBar {
+ id: progressbar
+ objectName: "progressbar"
+ from: 0
+ to: 100
+ value: 50
+ }
+}
diff --git a/tests/auto/accessibility/data/radiobutton.qml b/tests/auto/accessibility/data/radiobutton.qml
new file mode 100644
index 00000000..1883fff8
--- /dev/null
+++ b/tests/auto/accessibility/data/radiobutton.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ RadioButton {
+ id: radiobutton
+ objectName: "radiobutton"
+ text: "RadioButton"
+ }
+}
diff --git a/tests/auto/accessibility/data/scrollbar.qml b/tests/auto/accessibility/data/scrollbar.qml
new file mode 100644
index 00000000..2e360422
--- /dev/null
+++ b/tests/auto/accessibility/data/scrollbar.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ ScrollBar {
+ id: scrollbar
+ objectName: "scrollbar"
+ }
+}
diff --git a/tests/auto/accessibility/data/scrollindicator.qml b/tests/auto/accessibility/data/scrollindicator.qml
new file mode 100644
index 00000000..e933dece
--- /dev/null
+++ b/tests/auto/accessibility/data/scrollindicator.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ ScrollIndicator {
+ id: scrollindicator
+ objectName: "scrollindicator"
+ }
+}
diff --git a/tests/auto/accessibility/data/slider.qml b/tests/auto/accessibility/data/slider.qml
new file mode 100644
index 00000000..060bb66c
--- /dev/null
+++ b/tests/auto/accessibility/data/slider.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ Slider {
+ id: slider
+ objectName: "slider"
+ from: 0
+ to: 100
+ value: 50
+ stepSize: 1
+ orientation: "Horizontal"
+ }
+}
diff --git a/tests/auto/accessibility/data/switch.qml b/tests/auto/accessibility/data/switch.qml
new file mode 100644
index 00000000..9913e3f1
--- /dev/null
+++ b/tests/auto/accessibility/data/switch.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ Switch {
+ //id: switch
+ objectName: "switch"
+ text: "Switch"
+ }
+}
diff --git a/tests/auto/accessibility/data/tabbar.qml b/tests/auto/accessibility/data/tabbar.qml
new file mode 100644
index 00000000..127c4e81
--- /dev/null
+++ b/tests/auto/accessibility/data/tabbar.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ TabBar {
+ id: tabbar
+ objectName: "tabbar"
+ }
+}
diff --git a/tests/auto/accessibility/data/tabbutton.qml b/tests/auto/accessibility/data/tabbutton.qml
new file mode 100644
index 00000000..cfb04ca2
--- /dev/null
+++ b/tests/auto/accessibility/data/tabbutton.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ TabBar {
+ id: tabbar
+ objectName: "TabBar"
+ TabButton {
+ id: tabbutton
+ objectName: "tabbutton"
+ text: "TabButton"
+ }
+ }
+}
diff --git a/tests/auto/accessibility/data/textarea-2.qml b/tests/auto/accessibility/data/textarea-2.qml
new file mode 100644
index 00000000..381c08bd
--- /dev/null
+++ b/tests/auto/accessibility/data/textarea-2.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ TextArea {
+ id: textarea
+ objectName: "textarea"
+ text: "TextArea"
+ }
+}
diff --git a/tests/auto/accessibility/data/textarea.qml b/tests/auto/accessibility/data/textarea.qml
new file mode 100644
index 00000000..9ae51ca8
--- /dev/null
+++ b/tests/auto/accessibility/data/textarea.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ TextArea {
+ id: textarea
+ objectName: "textarea"
+ text: "TextArea"
+ Accessible.name: text
+ }
+}
diff --git a/tests/auto/accessibility/data/textfield-2.qml b/tests/auto/accessibility/data/textfield-2.qml
new file mode 100644
index 00000000..5db46d82
--- /dev/null
+++ b/tests/auto/accessibility/data/textfield-2.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ TextField {
+ id: textfield
+ objectName: "textfield"
+ text: "TextField"
+ }
+}
diff --git a/tests/auto/accessibility/data/textfield.qml b/tests/auto/accessibility/data/textfield.qml
new file mode 100644
index 00000000..c3ea9b08
--- /dev/null
+++ b/tests/auto/accessibility/data/textfield.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ TextField {
+ id: textfield
+ objectName: "textfield"
+ text: "TextField"
+ Accessible.name: text
+ }
+}
diff --git a/tests/auto/accessibility/data/togglebutton.qml b/tests/auto/accessibility/data/togglebutton.qml
new file mode 100644
index 00000000..8f75c364
--- /dev/null
+++ b/tests/auto/accessibility/data/togglebutton.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ ToggleButton {
+ id: togglebutton
+ objectName: "togglebutton"
+ text: "ToggleButton"
+ }
+}
diff --git a/tests/auto/accessibility/data/toolbar.qml b/tests/auto/accessibility/data/toolbar.qml
new file mode 100644
index 00000000..c0503aef
--- /dev/null
+++ b/tests/auto/accessibility/data/toolbar.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ ToolBar {
+ id: toolbar
+ objectName: "toolbar"
+ }
+}
diff --git a/tests/auto/accessibility/data/toolbutton.qml b/tests/auto/accessibility/data/toolbutton.qml
new file mode 100644
index 00000000..63aacddc
--- /dev/null
+++ b/tests/auto/accessibility/data/toolbutton.qml
@@ -0,0 +1,13 @@
+import QtQuick 2.5
+import QtQuick.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ visible: true
+
+ ToolButton {
+ id: toolbutton
+ objectName: "toolbutton"
+ text: "ToolButton"
+ }
+}
diff --git a/tests/auto/accessibility/tst_accessibility.cpp b/tests/auto/accessibility/tst_accessibility.cpp
new file mode 100644
index 00000000..31700044
--- /dev/null
+++ b/tests/auto/accessibility/tst_accessibility.cpp
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtTest/QSignalSpy>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQuick/qquickview.h>
+#include <QtQuick/private/qquickitem_p.h>
+#include "../shared/util.h"
+#include "../shared/visualtestutil.h"
+
+#ifndef QT_NO_ACCESSIBILITY
+#include <QtQuick/private/qquickaccessibleattached_p.h>
+#endif
+
+using namespace QQuickVisualTestUtil;
+
+class tst_accessibility : public QQmlDataTest
+{
+ Q_OBJECT
+public:
+
+private slots:
+ void a11y_data();
+ void a11y();
+
+private:
+ QQmlEngine engine;
+};
+
+void tst_accessibility::a11y_data()
+{
+ QTest::addColumn<QString>("name");
+ QTest::addColumn<int>("role");
+ QTest::addColumn<QString>("text");
+
+ QTest::newRow("BusyIndicator") << "busyindicator" << 0x00000027 << ""; //QAccessible::Indicator
+ QTest::newRow("Button") << "button" << 0x0000002B << "Button"; //QAccessible::Button
+ QTest::newRow("CheckBox") << "checkbox" << 0x0000002C << "CheckBox"; //QAccessible::CheckBox
+ // Frame
+ // GroupBox
+ QTest::newRow("Label") << "label" << 0x00000029 << "Label"; //QAccessible::StaticText
+ QTest::newRow("PageIndicator") << "pageindicator" << 0x00000027 << ""; //QAccessible::Indicator
+ QTest::newRow("ProgressBar") << "progressbar" << 0x00000030 << ""; //QAccessible::ProgressBar
+ QTest::newRow("RadioButton") << "radiobutton" << 0x0000002D << "RadioButton"; //QAccessible::RadioButton
+ QTest::newRow("ScrollBar") << "scrollbar" << 0x00000003 << ""; //QAccessible::ScrollBar
+ QTest::newRow("ScrollIndicator") << "scrollindicator" << 0x00000027 << ""; //QAccessible::Indicator
+ QTest::newRow("Slider") << "slider" << 0x00000033 << ""; //QAccessible::Slider
+ // StackView
+ QTest::newRow("Switch") << "switch" << 0x0000002B << "Switch"; //QAccessible::Button
+ QTest::newRow("TabBar") << "tabbar" << 0x0000003C << ""; //QAccessible::PageTabList
+ QTest::newRow("TabButton") << "tabbutton" << 0x00000025 << "TabButton"; //QAccessible::PageTab
+ QTest::newRow("TextArea") << "textarea" << 0x0000002A << "TextArea"; //QAccessible::Accessible.EditableText
+ QTest::newRow("TextField") << "textfield" << 0x0000002A << "TextField"; //QAccessible::Accessible.EditableText
+ QTest::newRow("ToggleButton") << "togglebutton" << 0x0000002B << "ToggleButton"; //QAccessible::Button
+ QTest::newRow("ToolBar") << "toolbar" << 0x00000016 << ""; //QAccessible::ToolBar
+ QTest::newRow("ToolButton") << "toolbutton" << 0x0000002B << "ToolButton"; //QAccessible::Button
+}
+
+void tst_accessibility::a11y()
+{
+ QFETCH(QString, name);
+ QFETCH(int, role);
+ QFETCH(QString, text);
+
+ QQmlComponent component(&engine);
+ QString fn = name;
+#ifdef QT_NO_ACCESSIBILITY
+ if (name == QLatin1Literal("textarea") || name == QLatin1Literal("textfield"))
+ fn += QLatin1Literal("-2");
+#endif
+ component.loadUrl(testFileUrl(fn + ".qml"));
+ QObject* created = component.create();
+ QVERIFY(created);
+ QScopedPointer<QObject> cleanup(created);
+ QVERIFY(!cleanup.isNull());
+
+ QQuickWindow* window = qobject_cast<QQuickWindow*>(created);
+ QVERIFY(window);
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickItem *item = findItem<QQuickItem>(window->contentItem(), name);
+ QVERIFY(item);
+
+#ifndef QT_NO_ACCESSIBILITY
+ QQuickAccessibleAttached *acc = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(item, false));
+ QVERIFY(acc);
+ QCOMPARE(acc->role(), (QAccessible::Role)role);
+ QCOMPARE(acc->name(), text);
+#else
+ Q_UNUSED(role)
+ Q_UNUSED(text)
+ QObject *acc = qmlAttachedPropertiesObject<QObject>(item, false);
+ QVERIFY(!acc);
+#endif
+}
+
+QTEST_MAIN(tst_accessibility)
+
+#include "tst_accessibility.moc"