From 4a4842118d2303a8d851d1d8b85fe182d3fe492a Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 6 May 2019 16:03:37 +0200 Subject: Accessibility: Make sure StaticText is marked read-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test more of the text properties. This is still very incomplete, but a small step forward. Also make sure that editable text reports the editable state. Fixes: QTBUG-75002 Change-Id: I9e43c980d8fa91671acb4e40e5d9162854884ee7 Reviewed-by: Jan Arve Sæther --- .../quick/qquickaccessible/data/statictext.qml | 31 -------------- tests/auto/quick/qquickaccessible/data/text.qml | 49 ++++++++++++++++++++++ .../qquickaccessible/tst_qquickaccessible.cpp | 46 ++++++++++++++++++-- 3 files changed, 92 insertions(+), 34 deletions(-) delete mode 100644 tests/auto/quick/qquickaccessible/data/statictext.qml create mode 100644 tests/auto/quick/qquickaccessible/data/text.qml (limited to 'tests/auto/quick/qquickaccessible') diff --git a/tests/auto/quick/qquickaccessible/data/statictext.qml b/tests/auto/quick/qquickaccessible/data/statictext.qml deleted file mode 100644 index 1092f33daf..0000000000 --- a/tests/auto/quick/qquickaccessible/data/statictext.qml +++ /dev/null @@ -1,31 +0,0 @@ -import QtQuick 2.0 - -Item { - width: 400 - height: 400 - Accessible.name: "root" - Accessible.role: Accessible.Client - - Text { - x: 100 - y: 20 - width: 200 - height: 50 - text : "Hello Accessibility" - - // Setting any value of the attached property - // makes an item accessible. - Accessible.name: text - } - - Text { - x: 100 - y: 40 - width: 100 - height: 40 - text : "Hello 2" - Accessible.role: Accessible.StaticText - Accessible.name: "The Hello 2 accessible text" - Accessible.description: "A text description" - } -} diff --git a/tests/auto/quick/qquickaccessible/data/text.qml b/tests/auto/quick/qquickaccessible/data/text.qml new file mode 100644 index 0000000000..88f292a61f --- /dev/null +++ b/tests/auto/quick/qquickaccessible/data/text.qml @@ -0,0 +1,49 @@ +import QtQuick 2.0 + +Item { + width: 400 + height: 400 + Accessible.name: "root" + Accessible.role: Accessible.Client + + Text { + x: 100 + y: 20 + width: 200 + height: 50 + text : "Hello Accessibility" + + // Setting any value of the attached property + // makes an item accessible. + Accessible.name: text + } + + Text { + x: 100 + y: 40 + width: 100 + height: 40 + text : "Hello 2" + Accessible.role: Accessible.StaticText + Accessible.name: "The Hello 2 accessible text" + Accessible.description: "A text description" + } + + TextInput { + x: 100 + y: 80 + width: 200 + height: 40 + text: "A text input" + Accessible.role: Accessible.EditableText + } + + TextEdit { + x: 100 + y: 120 + width: 200 + height: 100 + text: "A multi-line text edit\nTesting Accessibility." + Accessible.role: Accessible.EditableText + } +} diff --git a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp index 1bfeb94161..243d87f212 100644 --- a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp +++ b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp @@ -130,7 +130,7 @@ void tst_QQuickAccessible::commonTests_data() { QTest::addColumn("accessibleRoleFileName"); - QTest::newRow("StaticText") << "statictext.qml"; + QTest::newRow("Text") << "text.qml"; QTest::newRow("PushButton") << "pushbutton.qml"; } @@ -302,7 +302,7 @@ void tst_QQuickAccessible::basicPropertiesTest() QCOMPARE(app->childCount(), 0); QQuickView *window = new QQuickView(); - window->setSource(testFileUrl("statictext.qml")); + window->setSource(testFileUrl("text.qml")); window->show(); QCOMPARE(app->childCount(), 1); @@ -312,7 +312,7 @@ void tst_QQuickAccessible::basicPropertiesTest() QAccessibleInterface *item = iface->child(0); QVERIFY(item); - QCOMPARE(item->childCount(), 2); + QCOMPARE(item->childCount(), 4); QCOMPARE(item->rect().size(), QSize(400, 400)); QCOMPARE(item->role(), QAccessible::Client); QCOMPARE(iface->indexOfChild(item), 0); @@ -338,10 +338,50 @@ void tst_QQuickAccessible::basicPropertiesTest() QCOMPARE(text2->rect().y(), item->rect().y() + 40); QCOMPARE(text2->role(), QAccessible::StaticText); QCOMPARE(item->indexOfChild(text2), 1); + QCOMPARE(text2->state().editable, 0); + QCOMPARE(text2->state().readOnly, 1); QCOMPARE(iface->indexOfChild(text2), -1); QCOMPARE(text2->indexOfChild(item), -1); + // TextInput + QAccessibleInterface *textInput = item->child(2); + QVERIFY(textInput); + QCOMPARE(textInput->childCount(), 0); + QCOMPARE(textInput->role(), QAccessible::EditableText); + QCOMPARE(textInput->state().editable, 1); + QCOMPARE(textInput->state().readOnly, 0); + QCOMPARE(textInput->state().multiLine, 0); + QCOMPARE(textInput->state().focusable, 1); + QCOMPARE(textInput->text(QAccessible::Value), "A text input"); + auto textInterface = textInput->textInterface(); + QVERIFY(textInterface); + auto editableTextInterface = textInput->editableTextInterface(); + QEXPECT_FAIL("", "EditableTextInterface is not implemented", Continue); + QVERIFY(editableTextInterface); + auto newText = QString("a new text"); + textInput->setText(QAccessible::Value, newText); + QCOMPARE(textInput->text(QAccessible::Value), newText); + + // TextEdit + QAccessibleInterface *textEdit = item->child(3); + QVERIFY(textEdit); + QCOMPARE(textEdit->childCount(), 0); + QCOMPARE(textEdit->role(), QAccessible::EditableText); + QCOMPARE(textEdit->state().editable, 1); + QCOMPARE(textEdit->state().readOnly, 0); + QCOMPARE(textEdit->state().focusable, 1); + QCOMPARE(textEdit->text(QAccessible::Value), "A multi-line text edit\nTesting Accessibility."); + auto textEditTextInterface = textEdit->textInterface(); + QVERIFY(textEditTextInterface); + auto textEditEditableTextInterface = textEdit->editableTextInterface(); + QEXPECT_FAIL("", "EditableTextInterface is not implemented", Continue); + QVERIFY(textEditEditableTextInterface); + textEdit->setText(QAccessible::Value, newText); + QCOMPARE(textEdit->text(QAccessible::Value), newText); + QEXPECT_FAIL("", "multi line is not implemented", Continue); + QCOMPARE(textInput->state().multiLine, 1); + delete window; QTestAccessibility::clearEvents(); } -- cgit v1.2.3 From d12cc4f6b58ecb5f44458002fe9b74d0c84f10ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Tue, 7 May 2019 14:58:29 +0200 Subject: Don't overwrite states if role is assigned after a state We therefore need to keep track of which states have been explicitly set or not in order to know which ones should get initialized with their defaults. Change-Id: I49fdae82288f04ea4f50d45735a93434ac02abec Reviewed-by: Frederik Gladhorn --- tests/auto/quick/qquickaccessible/data/text.qml | 11 +++++++++ .../qquickaccessible/tst_qquickaccessible.cpp | 26 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'tests/auto/quick/qquickaccessible') diff --git a/tests/auto/quick/qquickaccessible/data/text.qml b/tests/auto/quick/qquickaccessible/data/text.qml index 88f292a61f..6daeacfd81 100644 --- a/tests/auto/quick/qquickaccessible/data/text.qml +++ b/tests/auto/quick/qquickaccessible/data/text.qml @@ -46,4 +46,15 @@ Item { text: "A multi-line text edit\nTesting Accessibility." Accessible.role: Accessible.EditableText } + + Text { + x: 100 + y: 160 + width: 100 + height: 40 + text : "Hello 3" + Accessible.name: text + Accessible.description: "description" + } + } diff --git a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp index 243d87f212..c5fdb6c1b9 100644 --- a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp +++ b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp @@ -312,7 +312,7 @@ void tst_QQuickAccessible::basicPropertiesTest() QAccessibleInterface *item = iface->child(0); QVERIFY(item); - QCOMPARE(item->childCount(), 4); + QCOMPARE(item->childCount(), 5); QCOMPARE(item->rect().size(), QSize(400, 400)); QCOMPARE(item->role(), QAccessible::Client); QCOMPARE(iface->indexOfChild(item), 0); @@ -382,6 +382,30 @@ void tst_QQuickAccessible::basicPropertiesTest() QEXPECT_FAIL("", "multi line is not implemented", Continue); QCOMPARE(textInput->state().multiLine, 1); + // Text "Hello 3" + QAccessibleInterface *text3 = item->child(4); + QVERIFY(text3); + QCOMPARE(text3->childCount(), 0); + QCOMPARE(text3->text(QAccessible::Name), QLatin1String("Hello 3")); + QCOMPARE(text3->role(), QAccessible::StaticText); + QCOMPARE(item->indexOfChild(text3), 4); + QCOMPARE(text3->state().editable, 0); + QCOMPARE(text3->state().readOnly, 0); + // test implicit state values due to role change + QQuickAccessibleAttached *attached = QQuickAccessibleAttached::attachedProperties(text3->object()); + attached->setRole(QAccessible::StaticText); + QCOMPARE(text3->role(), QAccessible::StaticText); + QCOMPARE(text3->state().readOnly, 1); + + // see if implicit changes back + attached->setRole(QAccessible::EditableText); + QEXPECT_FAIL("", "EditableText does not implicitly set readOnly to false", Continue); + QCOMPARE(text3->state().readOnly, 0); + // explicitly set state + attached->set_readOnly(false); + attached->setRole(QAccessible::StaticText); + QCOMPARE(text3->state().readOnly, 0); + delete window; QTestAccessibility::clearEvents(); } -- cgit v1.2.3