diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-01-10 16:36:05 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-27 16:00:13 +0100 |
commit | f0595284cbe85b5716daaf307154c1ed7e660a26 (patch) | |
tree | a3a0c1347130b1b6c8418780d16d2d7f308ebf69 /tests/auto/quick/qquickaccessible | |
parent | a1ee538395198f998a73f3ef7545392aeb680900 (diff) |
Accessibility: add states to QQuickAccessibleAttached
This makes it possible to set the state of accessible objects in qml.
Change-Id: Ide70b885dac8fed180d2b221540cf2b699ac78ff
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickaccessible')
3 files changed, 104 insertions, 2 deletions
diff --git a/tests/auto/quick/qquickaccessible/data/checkbuttons.qml b/tests/auto/quick/qquickaccessible/data/checkbuttons.qml index 22cdad1377..8769c04095 100644 --- a/tests/auto/quick/qquickaccessible/data/checkbuttons.qml +++ b/tests/auto/quick/qquickaccessible/data/checkbuttons.qml @@ -6,6 +6,7 @@ Item { // button, not checkable Rectangle { + objectName: "button1" y: 20 width: 100; height: 20 Accessible.role : Accessible.Button @@ -13,34 +14,44 @@ Item { // button, checkable, not checked Rectangle { + objectName: "button2" y: 40 width: 100; height: 20 Accessible.role : Accessible.Button + Accessible.checkable: checkable + Accessible.checked: checked property bool checkable: true property bool checked: false } // button, checkable, checked Rectangle { + objectName: "button3" y: 60 width: 100; height: 20 Accessible.role : Accessible.Button + Accessible.checkable: checkable + Accessible.checked: checked property bool checkable: true property bool checked: true } // check box, checked Rectangle { + objectName: "checkbox1" y: 80 width: 100; height: 20 Accessible.role : Accessible.CheckBox + Accessible.checked: checked property bool checked: true } // check box, not checked Rectangle { + objectName: "checkbox2" y: 100 width: 100; height: 20 Accessible.role : Accessible.CheckBox + Accessible.checked: checked property bool checked: false } } diff --git a/tests/auto/quick/qquickaccessible/qquickaccessible.pro b/tests/auto/quick/qquickaccessible/qquickaccessible.pro index 6fc6011229..99c3834147 100644 --- a/tests/auto/quick/qquickaccessible/qquickaccessible.pro +++ b/tests/auto/quick/qquickaccessible/qquickaccessible.pro @@ -1,7 +1,7 @@ CONFIG += testcase TARGET = tst_qquickaccessible -QT += qml-private network quick-private testlib gui-private +QT += qml-private network quick-private testlib gui-private core-private macx:CONFIG -= app_bundle SOURCES += tst_qquickaccessible.cpp diff --git a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp index ec1b1de7c0..06dc348f61 100644 --- a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp +++ b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp @@ -44,6 +44,10 @@ #include "QtTest/qtestaccessible.h" #include <QtGui/qaccessible.h> +#include <QtGui/private/qguiapplication_p.h> +#include <qpa/qplatformnativeinterface.h> +#include <qpa/qplatformintegration.h> +#include <qpa/qplatformaccessibility.h> #include <QtQuick/qquickview.h> #include <QtQuick/qquickitem.h> @@ -96,6 +100,12 @@ public: tst_QQuickAccessible(); virtual ~tst_QQuickAccessible(); +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + private slots: void commonTests_data(); void commonTests(); @@ -116,6 +126,37 @@ tst_QQuickAccessible::~tst_QQuickAccessible() } +void tst_QQuickAccessible::initTestCase() +{ + QQmlDataTest::initTestCase(); + QTestAccessibility::initialize(); + QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration(); + pfIntegration->accessibility()->setActive(true); +} + +void tst_QQuickAccessible::cleanupTestCase() +{ + QTestAccessibility::cleanup(); +} + +void tst_QQuickAccessible::init() +{ + QTestAccessibility::clearEvents(); +} + +void tst_QQuickAccessible::cleanup() +{ + const EventList list = QTestAccessibility::events(); + if (!list.isEmpty()) { + qWarning("%d accessibility event(s) were not handled in testfunction '%s':", list.count(), + QString(QTest::currentTestFunction()).toLatin1().constData()); + for (int i = 0; i < list.count(); ++i) + qWarning(" %d: Object: %p Event: '%s' Child: %d", i + 1, list.at(i)->object(), + qAccessibleEventString(list.at(i)->type()), list.at(i)->child()); + } + QTestAccessibility::clearEvents(); +} + void tst_QQuickAccessible::commonTests_data() { QTest::addColumn<QString>("accessibleRoleFileName"); @@ -141,6 +182,7 @@ void tst_QQuickAccessible::commonTests() QVERIFY(iface); delete view; + QTestAccessibility::clearEvents(); } void tst_QQuickAccessible::quickAttachedProperties() @@ -215,6 +257,7 @@ void tst_QQuickAccessible::quickAttachedProperties() } delete object; } + QTestAccessibility::clearEvents(); } @@ -265,6 +308,7 @@ void tst_QQuickAccessible::basicPropertiesTest() QCOMPARE(text2->indexOfChild(item), -1); delete window; + QTestAccessibility::clearEvents(); } QAccessibleInterface *topLevelChildAt(QAccessibleInterface *iface, int x, int y) @@ -330,6 +374,7 @@ void tst_QQuickAccessible::hitTest() QCOMPARE(rootItemIface->text(QAccessible::Name), QLatin1String("rect201")); delete window; + QTestAccessibility::clearEvents(); } void tst_QQuickAccessible::checkableTest() @@ -337,6 +382,17 @@ void tst_QQuickAccessible::checkableTest() QQuickView *window = new QQuickView(); window->setSource(testFileUrl("checkbuttons.qml")); window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickItem *contentItem = window->contentItem(); + QVERIFY(contentItem); + QQuickItem *rootItem = contentItem->childItems().first(); + QVERIFY(rootItem); + + // the window becomes active + QAccessible::State activatedChange; + activatedChange.active = true; QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(window); QVERIFY(iface); @@ -347,9 +403,28 @@ void tst_QQuickAccessible::checkableTest() QVERIFY(!(button1->state().checked)); QVERIFY(!(button1->state().checkable)); + QVERIFY(button1->state().focusable); + QVERIFY(!button1->state().focused); + + QTestAccessibility::clearEvents(); + + // set properties + QQuickItem *button1item = qobject_cast<QQuickItem*>(rootItem->childItems().at(0)); + QVERIFY(button1item); + QCOMPARE(button1item->objectName(), QLatin1String("button1")); + button1item->forceActiveFocus(); + QVERIFY(button1->state().focusable); + QVERIFY(button1->state().focused); + + QAccessibleEvent focusEvent(button1item, QAccessible::Focus); + QVERIFY_EVENT(&focusEvent); + QAccessibleInterface *button2 = root->child(1); QVERIFY(!(button2->state().checked)); QVERIFY(button2->state().checkable); + QQuickItem *button2item = qobject_cast<QQuickItem*>(rootItem->childItems().at(1)); + QVERIFY(button2item); + QCOMPARE(button2item->objectName(), QLatin1String("button2")); QAccessibleInterface *button3 = root->child(2); QVERIFY(button3->state().checked); @@ -357,12 +432,28 @@ void tst_QQuickAccessible::checkableTest() QAccessibleInterface *checkBox1 = root->child(3); QCOMPARE(checkBox1->role(), QAccessible::CheckBox); - QVERIFY((checkBox1->state().checked)); + QVERIFY(checkBox1->state().checked); QVERIFY(checkBox1->state().checkable); + QQuickItem *checkbox1item = qobject_cast<QQuickItem*>(rootItem->childItems().at(3)); + QVERIFY(checkbox1item); + QCOMPARE(checkbox1item->objectName(), QLatin1String("checkbox1")); + + checkbox1item->setProperty("checked", false); + QVERIFY(!checkBox1->state().checked); + QAccessible::State checkState; + checkState.checked = true; + QAccessibleStateChangeEvent checkChanged(checkbox1item, checkState); + QVERIFY_EVENT(&checkChanged); + + checkbox1item->setProperty("checked", true); + QVERIFY(checkBox1->state().checked); + QVERIFY_EVENT(&checkChanged); QAccessibleInterface *checkBox2 = root->child(4); QVERIFY(!(checkBox2->state().checked)); QVERIFY(checkBox2->state().checkable); + + QTestAccessibility::clearEvents(); } QTEST_MAIN(tst_QQuickAccessible) |