tst_qwindow: Fix geometries.

Use sizes relative to the test window size; move windows relative
to the top left point of the available screen geometry.
The test now passes on Windows using a 4K monitor.

Task-number: QTBUG-38858
Change-Id: Ia8d992f2a9bfa1cb1deacaf918ed0cfff7616959
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
This commit is contained in:
Friedemann Kleint 2014-07-31 13:48:15 +02:00 committed by Joerg Bornemann
parent 770f914083
commit dd99c10c56

View File

@ -94,19 +94,31 @@ private slots:
void modalWithChildWindow(); void modalWithChildWindow();
void modalWindowModallity(); void modalWindowModallity();
void modalWindowPosition(); void modalWindowPosition();
void initTestCase();
void initTestCase()
{
touchDevice = new QTouchDevice;
touchDevice->setType(QTouchDevice::TouchScreen);
QWindowSystemInterface::registerTouchDevice(touchDevice);
}
void cleanup(); void cleanup();
private: private:
QPoint m_availableTopLeft;
QSize m_testWindowSize;
QTouchDevice *touchDevice; QTouchDevice *touchDevice;
}; };
void tst_QWindow::initTestCase()
{
// Size of reference window, 200 for < 2000, scale up for larger screens
// to avoid Windows warnings about minimum size for decorated windows.
int width = 200;
const QScreen *screen = QGuiApplication::primaryScreen();
m_availableTopLeft = screen->availableGeometry().topLeft();
const int screenWidth = screen->geometry().width();
if (screenWidth > 2000)
width = 100 * ((screenWidth + 500) / 1000);
m_testWindowSize = QSize(width, width);
touchDevice = new QTouchDevice;
touchDevice->setType(QTouchDevice::TouchScreen);
QWindowSystemInterface::registerTouchDevice(touchDevice);
}
void tst_QWindow::cleanup() void tst_QWindow::cleanup()
{ {
QVERIFY(QGuiApplication::allWindows().isEmpty()); QVERIFY(QGuiApplication::allWindows().isEmpty());
@ -175,7 +187,7 @@ void tst_QWindow::eventOrderOnShow()
{ {
// Some platforms enforce minimum widths for windows, which can cause extra resize // Some platforms enforce minimum widths for windows, which can cause extra resize
// events, so set the width to suitably large value to avoid those. // events, so set the width to suitably large value to avoid those.
QRect geometry(80, 80, 300, 40); QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
Window window; Window window;
window.setGeometry(geometry); window.setGeometry(geometry);
@ -194,7 +206,7 @@ void tst_QWindow::resizeEventAfterResize()
{ {
// Some platforms enforce minimum widths for windows, which can cause extra resize // Some platforms enforce minimum widths for windows, which can cause extra resize
// events, so set the width to suitably large value to avoid those. // events, so set the width to suitably large value to avoid those.
QRect geometry(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(20, 20), QSize(300, 40)); QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize * 2);
Window window; Window window;
window.setGeometry(geometry); window.setGeometry(geometry);
@ -204,7 +216,7 @@ void tst_QWindow::resizeEventAfterResize()
// QTBUG-32706 // QTBUG-32706
// Make sure we get a resizeEvent after calling resize // Make sure we get a resizeEvent after calling resize
window.resize(400, 100); window.resize(m_testWindowSize);
#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen #if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen
// so we only expect one resize event // so we only expect one resize event
@ -240,15 +252,14 @@ void tst_QWindow::positioning()
// Some platforms enforce minimum widths for windows, which can cause extra resize // Some platforms enforce minimum widths for windows, which can cause extra resize
// events, so set the width to suitably large value to avoid those. // events, so set the width to suitably large value to avoid those.
const QSize size = QSize(300, 40); const QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
const QRect geometry(QPoint(80, 80), size);
QFETCH(int, windowflags); QFETCH(int, windowflags);
QFETCH(int, resizecount); QFETCH(int, resizecount);
Window window((Qt::WindowFlags)windowflags); Window window((Qt::WindowFlags)windowflags);
window.setGeometry(QRect(QPoint(20, 20), size)); window.setGeometry(QRect(m_availableTopLeft + QPoint(20, 20), m_testWindowSize));
window.setFramePosition(QPoint(40, 40)); // Move window around before show, size must not change. window.setFramePosition(m_availableTopLeft + QPoint(40, 40)); // Move window around before show, size must not change.
QCOMPARE(window.geometry().size(), size); QCOMPARE(window.geometry().size(), m_testWindowSize);
window.setGeometry(geometry); window.setGeometry(geometry);
QCOMPARE(window.geometry(), geometry); QCOMPARE(window.geometry(), geometry);
// explicitly use non-fullscreen show. show() can be fullscreen on some platforms // explicitly use non-fullscreen show. show() can be fullscreen on some platforms
@ -320,8 +331,7 @@ void tst_QWindow::positioningDuringMinimized()
QSKIP("Not supported on this platform"); QSKIP("Not supported on this platform");
Window window; Window window;
window.setTitle(QStringLiteral("positioningDuringMinimized")); window.setTitle(QStringLiteral("positioningDuringMinimized"));
const QRect initialGeometry(QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(100, 100), const QRect initialGeometry(m_availableTopLeft + QPoint(100, 100), m_testWindowSize);
QSize(200, 200));
window.setGeometry(initialGeometry); window.setGeometry(initialGeometry);
window.showNormal(); window.showNormal();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -337,7 +347,7 @@ void tst_QWindow::positioningDuringMinimized()
void tst_QWindow::isExposed() void tst_QWindow::isExposed()
{ {
QRect geometry(80, 80, 40, 40); QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
Window window; Window window;
window.setGeometry(geometry); window.setGeometry(geometry);
@ -361,7 +371,7 @@ void tst_QWindow::isActive()
Window window; Window window;
// Some platforms enforce minimum widths for windows, which can cause extra resize // Some platforms enforce minimum widths for windows, which can cause extra resize
// events, so set the width to suitably large value to avoid those. // events, so set the width to suitably large value to avoid those.
window.setGeometry(80, 80, 300, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
@ -401,7 +411,7 @@ void tst_QWindow::isActive()
Window dialog; Window dialog;
dialog.setTransientParent(&window); dialog.setTransientParent(&window);
dialog.setGeometry(110, 110, 300, 30); dialog.setGeometry(QRect(m_availableTopLeft + QPoint(110, 100), m_testWindowSize));
dialog.show(); dialog.show();
dialog.requestActivate(); dialog.requestActivate();
@ -537,7 +547,7 @@ public:
void tst_QWindow::testInputEvents() void tst_QWindow::testInputEvents()
{ {
InputTestWindow window; InputTestWindow window;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.showNormal(); window.showNormal();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -575,7 +585,7 @@ void tst_QWindow::testInputEvents()
// Now with null pointer as window. local param should not be utilized: // Now with null pointer as window. local param should not be utilized:
// handleMouseEvent() with tlw == 0 means the event is in global coords only. // handleMouseEvent() with tlw == 0 means the event is in global coords only.
window.mousePressButton = window.mouseReleaseButton = 0; window.mousePressButton = window.mouseReleaseButton = 0;
QPointF nonWindowGlobal(2000, 500); // not inside the window QPointF nonWindowGlobal(window.geometry().topRight() + QPoint(200, 50)); // not inside the window
QWindowSystemInterface::handleMouseEvent(0, nonWindowGlobal, nonWindowGlobal, Qt::LeftButton); QWindowSystemInterface::handleMouseEvent(0, nonWindowGlobal, nonWindowGlobal, Qt::LeftButton);
QWindowSystemInterface::handleMouseEvent(0, nonWindowGlobal, nonWindowGlobal, Qt::NoButton); QWindowSystemInterface::handleMouseEvent(0, nonWindowGlobal, nonWindowGlobal, Qt::NoButton);
QCoreApplication::processEvents(); QCoreApplication::processEvents();
@ -597,7 +607,7 @@ void tst_QWindow::touchToMouseTranslation()
QSKIP("Mouse events are synthesized by the system on this platform."); QSKIP("Mouse events are synthesized by the system on this platform.");
InputTestWindow window; InputTestWindow window;
window.ignoreTouch = true; window.ignoreTouch = true;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -673,7 +683,7 @@ void tst_QWindow::mouseToTouchTranslation()
InputTestWindow window; InputTestWindow window;
window.ignoreMouse = true; window.ignoreMouse = true;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -722,7 +732,7 @@ void tst_QWindow::mouseToTouchLoop()
InputTestWindow window; InputTestWindow window;
window.ignoreMouse = true; window.ignoreMouse = true;
window.ignoreTouch = true; window.ignoreTouch = true;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -737,7 +747,7 @@ void tst_QWindow::mouseToTouchLoop()
void tst_QWindow::touchCancel() void tst_QWindow::touchCancel()
{ {
InputTestWindow window; InputTestWindow window;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -799,7 +809,7 @@ void tst_QWindow::touchCancelWithTouchToMouse()
QSKIP("Mouse events are synthesized by the system on this platform."); QSKIP("Mouse events are synthesized by the system on this platform.");
InputTestWindow window; InputTestWindow window;
window.ignoreTouch = true; window.ignoreTouch = true;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -840,7 +850,7 @@ void tst_QWindow::touchCancelWithTouchToMouse()
void tst_QWindow::touchInterruptedByPopup() void tst_QWindow::touchInterruptedByPopup()
{ {
InputTestWindow window; InputTestWindow window;
window.setGeometry(80, 80, 200, 200); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -861,8 +871,7 @@ void tst_QWindow::touchInterruptedByPopup()
InputTestWindow popup; InputTestWindow popup;
popup.setFlags(Qt::Popup); popup.setFlags(Qt::Popup);
popup.setModality(Qt::WindowModal); popup.setModality(Qt::WindowModal);
popup.setWidth(160); popup.resize(m_testWindowSize / 2);
popup.setHeight(160);
popup.setTransientParent(&window); popup.setTransientParent(&window);
popup.show(); popup.show();
QVERIFY(QTest::qWaitForWindowExposed(&popup)); QVERIFY(QTest::qWaitForWindowExposed(&popup));
@ -892,7 +901,7 @@ void tst_QWindow::orientation()
qRegisterMetaType<Qt::ScreenOrientation>("Qt::ScreenOrientation"); qRegisterMetaType<Qt::ScreenOrientation>("Qt::ScreenOrientation");
QWindow window; QWindow window;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.create(); window.create();
window.reportContentOrientationChange(Qt::PortraitOrientation); window.reportContentOrientationChange(Qt::PortraitOrientation);
@ -1003,7 +1012,7 @@ void tst_QWindow::mouseEventSequence()
int doubleClickInterval = qGuiApp->styleHints()->mouseDoubleClickInterval(); int doubleClickInterval = qGuiApp->styleHints()->mouseDoubleClickInterval();
InputTestWindow window; InputTestWindow window;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -1125,7 +1134,7 @@ void tst_QWindow::inputReentrancy()
InputTestWindow window; InputTestWindow window;
window.spinLoopWhenPressed = true; window.spinLoopWhenPressed = true;
window.setGeometry(80, 80, 40, 40); window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show(); window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(QTest::qWaitForWindowExposed(&window));
@ -1194,7 +1203,7 @@ void tst_QWindow::tabletEvents()
{ {
#ifndef QT_NO_TABLETEVENT #ifndef QT_NO_TABLETEVENT
TabletTestWindow window; TabletTestWindow window;
window.setGeometry(10, 10, 100, 100); window.setGeometry(QRect(m_availableTopLeft + QPoint(10, 10), m_testWindowSize));
qGuiApp->installEventFilter(&window); qGuiApp->installEventFilter(&window);
QPoint local(10, 10); QPoint local(10, 10);
@ -1224,18 +1233,18 @@ void tst_QWindow::tabletEvents()
void tst_QWindow::windowModality_QTBUG27039() void tst_QWindow::windowModality_QTBUG27039()
{ {
QWindow parent; QWindow parent;
parent.setGeometry(10, 10, 100, 100); parent.setGeometry(QRect(m_availableTopLeft + QPoint(10, 10), m_testWindowSize));
parent.show(); parent.show();
InputTestWindow modalA; InputTestWindow modalA;
modalA.setTransientParent(&parent); modalA.setTransientParent(&parent);
modalA.setGeometry(10, 10, 20, 20); modalA.setGeometry(QRect(m_availableTopLeft + QPoint(20, 10), m_testWindowSize));
modalA.setModality(Qt::ApplicationModal); modalA.setModality(Qt::ApplicationModal);
modalA.show(); modalA.show();
InputTestWindow modalB; InputTestWindow modalB;
modalB.setTransientParent(&parent); modalB.setTransientParent(&parent);
modalB.setGeometry(30, 10, 20, 20); modalA.setGeometry(QRect(m_availableTopLeft + QPoint(30, 10), m_testWindowSize));
modalB.setModality(Qt::ApplicationModal); modalB.setModality(Qt::ApplicationModal);
modalB.show(); modalB.show();
@ -1325,40 +1334,43 @@ void tst_QWindow::initialSize()
} }
{ {
Window w; Window w;
w.setWidth(200); w.setWidth(m_testWindowSize.width());
w.show(); w.show();
#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen #if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen
// so we only expect one resize event // so we only expect one resize event
QTRY_COMPARE(w.width(), qGuiApp->primaryScreen()->availableGeometry().width()); QTRY_COMPARE(w.width(), qGuiApp->primaryScreen()->availableGeometry().width());
#else #else
QTRY_COMPARE(w.width(), 200); QTRY_COMPARE(w.width(), m_testWindowSize.width());
#endif #endif
QTRY_VERIFY(w.height() > 0); QTRY_VERIFY(w.height() > 0);
} }
{ {
Window w; Window w;
w.resize(200, 42); const QSize testSize(m_testWindowSize.width(), 42);
w.resize(testSize);
w.show(); w.show();
#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen #if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen
// so we only expect one resize event // so we only expect one resize event
QTRY_COMPARE(w.width(), qGuiApp->primaryScreen()->availableGeometry().width()); const QSize expectedSize = QGuiApplication::primaryScreen()->availableGeometry().size();
QTRY_COMPARE(w.height(), qGuiApp->primaryScreen()->availableGeometry().height());
#else #else
QTRY_COMPARE(w.width(), 200); const QSize expectedSize = testSize;
QTRY_COMPARE(w.height(), 42);
#endif #endif
QTRY_COMPARE(w.size(), expectedSize);
} }
} }
void tst_QWindow::modalDialog() void tst_QWindow::modalDialog()
{ {
QWindow normalWindow; QWindow normalWindow;
normalWindow.resize(400, 400); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normalWindow.resize(m_testWindowSize);
normalWindow.show(); normalWindow.show();
QVERIFY(QTest::qWaitForWindowExposed(&normalWindow)); QVERIFY(QTest::qWaitForWindowExposed(&normalWindow));
QWindow dialog; QWindow dialog;
dialog.resize(200,200); dialog.setFramePosition(m_availableTopLeft + QPoint(200, 200));
dialog.resize(m_testWindowSize);
dialog.setModality(Qt::ApplicationModal); dialog.setModality(Qt::ApplicationModal);
dialog.setFlags(Qt::Dialog); dialog.setFlags(Qt::Dialog);
dialog.show(); dialog.show();
@ -1374,12 +1386,14 @@ void tst_QWindow::modalDialog()
void tst_QWindow::modalDialogClosingOneOfTwoModal() void tst_QWindow::modalDialogClosingOneOfTwoModal()
{ {
QWindow normalWindow; QWindow normalWindow;
normalWindow.resize(400, 400); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normalWindow.resize(m_testWindowSize);
normalWindow.show(); normalWindow.show();
QVERIFY(QTest::qWaitForWindowExposed(&normalWindow)); QVERIFY(QTest::qWaitForWindowExposed(&normalWindow));
QWindow first_dialog; QWindow first_dialog;
first_dialog.resize(200,200); first_dialog.setFramePosition(m_availableTopLeft + QPoint(200, 200));
first_dialog.resize(m_testWindowSize);
first_dialog.setModality(Qt::ApplicationModal); first_dialog.setModality(Qt::ApplicationModal);
first_dialog.setFlags(Qt::Dialog); first_dialog.setFlags(Qt::Dialog);
first_dialog.show(); first_dialog.show();
@ -1387,7 +1401,8 @@ void tst_QWindow::modalDialogClosingOneOfTwoModal()
{ {
QWindow second_dialog; QWindow second_dialog;
second_dialog.resize(200,200); second_dialog.setFramePosition(m_availableTopLeft + QPoint(300, 300));
second_dialog.resize(m_testWindowSize);
second_dialog.setModality(Qt::ApplicationModal); second_dialog.setModality(Qt::ApplicationModal);
second_dialog.setFlags(Qt::Dialog); second_dialog.setFlags(Qt::Dialog);
second_dialog.show(); second_dialog.show();
@ -1406,12 +1421,14 @@ void tst_QWindow::modalDialogClosingOneOfTwoModal()
void tst_QWindow::modalWithChildWindow() void tst_QWindow::modalWithChildWindow()
{ {
QWindow normalWindow; QWindow normalWindow;
normalWindow.resize(400, 400); normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normalWindow.resize(m_testWindowSize);
normalWindow.show(); normalWindow.show();
QVERIFY(QTest::qWaitForWindowExposed(&normalWindow)); QVERIFY(QTest::qWaitForWindowExposed(&normalWindow));
QWindow tlw_dialog; QWindow tlw_dialog;
tlw_dialog.resize(400,200); tlw_dialog.setFramePosition(m_availableTopLeft + QPoint(200, 200));
tlw_dialog.resize(m_testWindowSize);
tlw_dialog.setModality(Qt::ApplicationModal); tlw_dialog.setModality(Qt::ApplicationModal);
tlw_dialog.setFlags(Qt::Dialog); tlw_dialog.setFlags(Qt::Dialog);
tlw_dialog.create(); tlw_dialog.create();
@ -1435,18 +1452,21 @@ void tst_QWindow::modalWithChildWindow()
void tst_QWindow::modalWindowModallity() void tst_QWindow::modalWindowModallity()
{ {
QWindow normal_window; QWindow normal_window;
normal_window.resize(400, 400); normal_window.setFramePosition(m_availableTopLeft + QPoint(80, 80));
normal_window.resize(m_testWindowSize);
normal_window.show(); normal_window.show();
QVERIFY(QTest::qWaitForWindowExposed(&normal_window)); QVERIFY(QTest::qWaitForWindowExposed(&normal_window));
QWindow parent_to_modal; QWindow parent_to_modal;
parent_to_modal.resize(400, 400); parent_to_modal.setFramePosition(normal_window.geometry().topRight() + QPoint(100, 0));
parent_to_modal.resize(m_testWindowSize);
parent_to_modal.show(); parent_to_modal.show();
QVERIFY(QTest::qWaitForWindowExposed(&parent_to_modal)); QVERIFY(QTest::qWaitForWindowExposed(&parent_to_modal));
QTRY_COMPARE(QGuiApplication::focusWindow(), &parent_to_modal); QTRY_COMPARE(QGuiApplication::focusWindow(), &parent_to_modal);
QWindow modal_dialog; QWindow modal_dialog;
modal_dialog.resize(400,200); modal_dialog.resize(m_testWindowSize);
modal_dialog.setFramePosition(normal_window.geometry().bottomLeft() + QPoint(0, 100));
modal_dialog.setModality(Qt::WindowModal); modal_dialog.setModality(Qt::WindowModal);
modal_dialog.setFlags(Qt::Dialog); modal_dialog.setFlags(Qt::Dialog);
modal_dialog.setTransientParent(&parent_to_modal); modal_dialog.setTransientParent(&parent_to_modal);
@ -1462,7 +1482,7 @@ void tst_QWindow::modalWindowModallity()
void tst_QWindow::modalWindowPosition() void tst_QWindow::modalWindowPosition()
{ {
QWindow window; QWindow window;
window.setGeometry(QRect(100, 100, 400, 400)); window.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize));
// Allow for any potential resizing due to constraints // Allow for any potential resizing due to constraints
QRect origGeo = window.geometry(); QRect origGeo = window.geometry();
window.setModality(Qt::WindowModal); window.setModality(Qt::WindowModal);