diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-07-03 16:15:21 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-07-04 08:58:42 +0200 |
commit | 01f1e10695216993fe86e35adcecc8115a654beb (patch) | |
tree | 9a0bec8cf5dc1dfca15a092e9d7f4d7feaaafc06 /tests | |
parent | 9c79f6dfb3b5724b52421f74fbee6f5c0005d0e3 (diff) |
Accessibility Linux: Implement set focus action
This is used by Orca for geometric navigation (aka flat review) to move
the focus around. It is also generally sensible to be able to
programatically move the focus around. This way of moving the focus
is redundant with the action interface's focus action.
Task-number: QTBUG-40048
Change-Id: I1b61ea843f6bfc3dc00007772e0e5102555ca752
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp index a8313215be..79e212a65a 100644 --- a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp +++ b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp @@ -47,6 +47,7 @@ #include <QtWidgets/QListWidget> #include <QtWidgets/QTreeWidget> #include <QtWidgets/QTextEdit> +#include <QtWidgets/QPushButton> #include <QDBusArgument> #include <QDBusConnection> @@ -102,6 +103,7 @@ private slots: void testTreeWidget(); void testTextEdit(); void testSlider(); + void testFocus(); void cleanupTestCase(); @@ -465,6 +467,54 @@ void tst_QAccessibilityLinux::testSlider() QCOMPARE(valueInterface->property("CurrentValue").toInt(), 4); } +quint64 getAtspiState(QDBusInterface *interface) +{ + QDBusMessage msg = interface->call(QDBus::Block, "GetState"); + const QDBusArgument arg = msg.arguments().at(0).value<QDBusArgument>(); + quint32 state1 = 0; + quint64 state2 = 0; + arg.beginArray(); + arg >> state1; + arg >> state2; + arg.endArray(); + + state2 = state2 << 32; + return state2 | state1; +} + +void tst_QAccessibilityLinux::testFocus() +{ + QLineEdit *lineEdit1 = new QLineEdit(m_window); + lineEdit1->setText("lineEdit 1"); + QLineEdit *lineEdit2 = new QLineEdit(m_window); + lineEdit2->setText("lineEdit 2"); + + m_window->addWidget(lineEdit1); + m_window->addWidget(lineEdit2); + lineEdit1->setFocus(); + + QStringList children = getChildren(mainWindow); + QCOMPARE(children.length(), 2); + QDBusInterface *accessibleInterfaceLineEdit1 = getInterface(children.at(0), "org.a11y.atspi.Accessible"); + QVERIFY(accessibleInterfaceLineEdit1->isValid()); + QDBusInterface *accessibleInterfaceLineEdit2 = getInterface(children.at(1), "org.a11y.atspi.Accessible"); + QVERIFY(accessibleInterfaceLineEdit2->isValid()); + QDBusInterface *componentInterfaceLineEdit1 = getInterface(children.at(0), "org.a11y.atspi.Component"); + QVERIFY(componentInterfaceLineEdit1->isValid()); + QDBusInterface *componentInterfaceLineEdit2 = getInterface(children.at(1), "org.a11y.atspi.Component"); + QVERIFY(componentInterfaceLineEdit2->isValid()); + + quint64 focusedState = quint64(1) << ATSPI_STATE_FOCUSED; + QVERIFY(getAtspiState(accessibleInterfaceLineEdit1) & focusedState); + QVERIFY(!(getAtspiState(accessibleInterfaceLineEdit2) & focusedState)); + + QDBusMessage focusReply = componentInterfaceLineEdit2->call(QDBus::Block, "GrabFocus"); + QVERIFY(focusReply.arguments().at(0).toBool()); + QVERIFY(lineEdit2->hasFocus()); + QVERIFY(!(getAtspiState(accessibleInterfaceLineEdit1) & focusedState)); + QVERIFY(getAtspiState(accessibleInterfaceLineEdit2) & focusedState); +} + QTEST_MAIN(tst_QAccessibilityLinux) #include "tst_qaccessibilitylinux.moc" |