Stabilize tst_qaccessibility

Ensure windows are cleaned up. Add scaling where native coordinates
are used.

Task-number: QTQAINFRA-1440
Change-Id: Ie080ff780c687418f4dc5d71fd49112486b217e6
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
Friedemann Kleint 2017-09-18 10:17:54 +02:00 committed by Liang Qi
parent 3b8f828174
commit d020d3f4ed

View File

@ -47,6 +47,7 @@
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformaccessibility.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qhighdpiscaling_p.h>
#if defined(Q_OS_WIN) && defined(interface)
# undef interface
@ -301,6 +302,7 @@ void tst_QAccessibility::cleanup()
qAccessibleEventString(list.at(i)->type()), list.at(i)->child());
}
QTestAccessibility::clearEvents();
QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty());
}
void tst_QAccessibility::eventTest()
@ -3743,14 +3745,14 @@ void tst_QAccessibility::bridgeTest()
// Ideally it should be extended to test all aspects of the bridge.
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
// First, test MSAA part of bridge
QWidget *window = new QWidget;
QVBoxLayout *lay = new QVBoxLayout(window);
QPushButton *button = new QPushButton(tr("Push me"), window);
QTextEdit *te = new QTextEdit(window);
QWidget window;
QVBoxLayout *lay = new QVBoxLayout(&window);
QPushButton *button = new QPushButton(tr("Push me"), &window);
QTextEdit *te = new QTextEdit(&window);
te->setText(QLatin1String("hello world\nhow are you today?\n"));
// Add QTableWidget
QTableWidget *tableWidget = new QTableWidget(3, 3, window);
QTableWidget *tableWidget = new QTableWidget(3, 3, &window);
tableWidget->setColumnCount(3);
QStringList hHeader;
hHeader << "h1" << "h2" << "h3";
@ -3776,8 +3778,8 @@ void tst_QAccessibility::bridgeTest()
lay->addWidget(tableWidget);
lay->addWidget(label);
window->show();
QVERIFY(QTest::qWaitForWindowExposed(window));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
/**************************************************
@ -3789,9 +3791,8 @@ void tst_QAccessibility::bridgeTest()
QCOMPARE(buttonRect.topLeft(), buttonPos);
// All set, now test the bridge.
POINT pt;
pt.x = buttonRect.center().x();
pt.y = buttonRect.center().y();
const QPoint nativePos = QHighDpi::toNativePixels(buttonRect.center(), window.windowHandle());
POINT pt{nativePos.x(), nativePos.y()};
IAccessible *iaccButton;
VARIANT varChild;
@ -3817,7 +3818,7 @@ void tst_QAccessibility::bridgeTest()
QCOMPARE(SUCCEEDED(hr), false);
hr = iaccButton->accLocation(&x, &y, &w, &h, varSELF);
QCOMPARE(buttonRect, QRect(x, y, w, h));
QCOMPARE(buttonRect, QHighDpi::fromNativePixels(QRect(x, y, w, h), window.windowHandle()));
#ifdef QT_SUPPORTS_IACCESSIBLE2
// Test IAccessible2 part of bridge
@ -3832,7 +3833,7 @@ void tst_QAccessibility::bridgeTest()
long x, y;
hr = ia2Component->get_locationInParent(&x, &y);
QVERIFY(SUCCEEDED(hr));
QCOMPARE(button->pos(), QPoint(x, y));
QCOMPARE(button->pos(), QHighDpi::fromNativePixels(QPoint(x, y), window.windowHandle()));
ia2Component->Release();
/***** Test IAccessibleAction *****/
@ -3897,7 +3898,7 @@ void tst_QAccessibility::bridgeTest()
/**************************************************
* QWidget
**************************************************/
QWindow *windowHandle = window->windowHandle();
QWindow *windowHandle = window.windowHandle();
QPlatformNativeInterface *platform = QGuiApplication::platformNativeInterface();
HWND hWnd = (HWND)platform->nativeResourceForWindow("handle", windowHandle);