From 6ac1bf6434f2a508b895f6da7997bd90a5a8c08a Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 7 Jul 2014 10:45:41 +0200 Subject: Widget based accessibility glue code With this patch the accessibility hierarchy inside webengine becomes available when navigating from QWidget based web views. Change-Id: Ib3625a6ec93b4d3f298fb845ab85209b348349ba Reviewed-by: Zeno Albisser Reviewed-by: Andras Becsi --- .../qwebengineaccessibility.pro | 2 + .../tst_qwebengineaccessibility.cpp | 116 +++++++++++++++++++++ tests/auto/widgets/widgets.pro | 1 + 3 files changed, 119 insertions(+) create mode 100644 tests/auto/widgets/qwebengineaccessibility/qwebengineaccessibility.pro create mode 100644 tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/qwebengineaccessibility/qwebengineaccessibility.pro b/tests/auto/widgets/qwebengineaccessibility/qwebengineaccessibility.pro new file mode 100644 index 000000000..ff6c49628 --- /dev/null +++ b/tests/auto/widgets/qwebengineaccessibility/qwebengineaccessibility.pro @@ -0,0 +1,2 @@ +include(../tests.pri) +exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc diff --git a/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp b/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp new file mode 100644 index 000000000..6cc7ac799 --- /dev/null +++ b/tests/auto/widgets/qwebengineaccessibility/tst_qwebengineaccessibility.cpp @@ -0,0 +1,116 @@ +/* + Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include "../util.h" + +#include +#include +#include +#include + +class tst_QWebEngineView : public QObject +{ + Q_OBJECT + +public Q_SLOTS: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private Q_SLOTS: + void noPage(); + void hierarchy(); +}; + +// This will be called before the first test function is executed. +// It is only called once. +void tst_QWebEngineView::initTestCase() +{ + QWebEngineWidgets::initialize(); +} + +// This will be called after the last test function is executed. +// It is only called once. +void tst_QWebEngineView::cleanupTestCase() +{ +} + +// This will be called before each test function is executed. +void tst_QWebEngineView::init() +{ +} + +// This will be called after every test function. +void tst_QWebEngineView::cleanup() +{ +} + +void tst_QWebEngineView::noPage() +{ + QWebEngineView webView; + webView.show(); + + QTest::qWait(1000); + QAccessibleInterface *view = QAccessible::queryAccessibleInterface(&webView); + QVERIFY(view); + QCOMPARE(view->childCount(), 1); + QAccessibleInterface *document = view->child(0); + QCOMPARE(document->role(), QAccessible::Document); + QCOMPARE(document->parent(), view); + QCOMPARE(document->childCount(), 0); +} + +void tst_QWebEngineView::hierarchy() +{ + QWebEngineView webView; + webView.setHtml("" \ + "Hello world" \ + "
" \ + ""); + webView.show(); + ::waitForSignal(&webView, SIGNAL(loadFinished(bool))); + + QAccessibleInterface *view = QAccessible::queryAccessibleInterface(&webView); + QVERIFY(view); + QCOMPARE(view->childCount(), 1); + // Wait for accessibility to be fully initialized + QTRY_VERIFY(view->child(0)->childCount() == 1); + QAccessibleInterface *document = view->child(0); + QCOMPARE(document->role(), QAccessible::Document); + QCOMPARE(document->parent(), view); + QCOMPARE(document->childCount(), 1); + QAccessibleInterface *grouping = document->child(0); + QVERIFY(grouping); + QCOMPARE(grouping->parent(), document); + QCOMPARE(grouping->childCount(), 2); + QAccessibleInterface *text = grouping->child(0); + QCOMPARE(text->role(), QAccessible::StaticText); + QCOMPARE(text->parent(), grouping); + QEXPECT_FAIL("", "FIXME: static text should probably not have a child element", Continue); + QCOMPARE(text->childCount(), 0); + QAccessibleInterface *input = grouping->child(1); + QCOMPARE(input->role(), QAccessible::EditableText); + QCOMPARE(input->parent(), grouping); + QCOMPARE(input->childCount(), 0); +} + +QTEST_MAIN(tst_QWebEngineView) +#include "tst_qwebengineaccessibility.moc" diff --git a/tests/auto/widgets/widgets.pro b/tests/auto/widgets/widgets.pro index cb6cae103..40d3b40bb 100644 --- a/tests/auto/widgets/widgets.pro +++ b/tests/auto/widgets/widgets.pro @@ -3,6 +3,7 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS += \ + qwebengineaccessibility \ qwebengineframe \ qwebenginepage \ qwebenginehistoryinterface \ -- cgit v1.2.3