Improve QAccessibleApplication

Add more testing.
This uncovers that currently the QDesktopScreenWidget
shows up as child of the app. Fixed by not creating
QAccessibleInterfaces for QDesktopScreenWidget.

Also don't crash in indexOfChild when called with 0.

Change-Id: I9fb1e47e8f1f33189e6125f56f274a7b94ecd0dd
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
This commit is contained in:
Frederik Gladhorn 2013-01-18 17:59:52 +01:00 committed by The Qt Project
parent 48c73540ad
commit 9a5ab30d52
5 changed files with 40 additions and 3 deletions

View File

@ -193,6 +193,8 @@ int QAccessibleApplication::childCount() const
/*! \reimp */
int QAccessibleApplication::indexOfChild(const QAccessibleInterface *child) const
{
if (!child)
return -1;
const QObjectList tlw(topLevelObjects());
return tlw.indexOf(child->object());
}

View File

@ -251,6 +251,9 @@ QAccessibleInterface *AccessibleFactory::create(const QString &classname, QObjec
} else if (classname == QLatin1String("QDockWidget")) {
iface = new QAccessibleDockWidget(widget);
#endif
} else if (classname == QLatin1String("QDesktopScreenWidget")) {
iface = 0;
} else {
iface = new QAccessibleWidget(widget);
}

View File

@ -47,5 +47,7 @@
"QScrollArea",
"QCalendarWidget",
"QDockWidget",
"QAccessibleWidget" ]
"QAccessibleWidget",
"QDesktopScreenWidget"
]
}

View File

@ -383,6 +383,8 @@ int QAccessibleWidget::childCount() const
/*! \reimp */
int QAccessibleWidget::indexOfChild(const QAccessibleInterface *child) const
{
if (!child)
return -1;
QWidgetList cl = childWidgets(widget());
return cl.indexOf(qobject_cast<QWidget *>(child->object()));
}

View File

@ -768,12 +768,40 @@ void tst_QAccessibility::actionTest()
void tst_QAccessibility::applicationTest()
{
{
QLatin1String name = QLatin1String("My Name");
qApp->setApplicationName(name);
QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(qApp);
QAIPtr interface(QAccessible::queryAccessibleInterface(qApp));
QCOMPARE(interface->text(QAccessible::Name), name);
QCOMPARE(interface->text(QAccessible::Description), qApp->applicationFilePath());
QCOMPARE(interface->text(QAccessible::Value), QString());
QCOMPARE(interface->role(), QAccessible::Application);
delete interface;
QCOMPARE(interface->window(), static_cast<QWindow*>(0));
QCOMPARE(interface->parent(), static_cast<QAccessibleInterface*>(0));
QCOMPARE(interface->focusChild(), static_cast<QAccessibleInterface*>(0));
QCOMPARE(interface->indexOfChild(0), -1);
QCOMPARE(interface->child(0), static_cast<QAccessibleInterface*>(0));
QCOMPARE(interface->child(-1), static_cast<QAccessibleInterface*>(0));
QCOMPARE(interface->child(1), static_cast<QAccessibleInterface*>(0));
QCOMPARE(interface->childCount(), 0);
QWidget widget;
widget.show();
qApp->setActiveWindow(&widget);
QVERIFY(QTest::qWaitForWindowActive(&widget));
QAIPtr widgetIface(QAccessible::queryAccessibleInterface(&widget));
QCOMPARE(interface->childCount(), 1);
QAIPtr focus(interface->focusChild());
QCOMPARE(focus->object(), &widget);
QCOMPARE(interface->indexOfChild(0), -1);
QCOMPARE(interface->indexOfChild(widgetIface.data()), 0);
QAIPtr child(interface->child(0));
QCOMPARE(child->object(), &widget);
QCOMPARE(interface->child(-1), static_cast<QAccessibleInterface*>(0));
QCOMPARE(interface->child(1), static_cast<QAccessibleInterface*>(0));
}
QTestAccessibility::clearEvents();
}
void tst_QAccessibility::mainWindowTest()