summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/kernel/qwindow/tst_qwindow.cpp')
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp171
1 files changed, 118 insertions, 53 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 868288e36e..b4659b7caf 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -67,6 +67,7 @@ private slots:
void mapGlobal();
void positioning_data();
void positioning();
+ void positioningDuringMinimized();
void isExposed();
void isActive();
void testInputEvents();
@@ -93,18 +94,36 @@ private slots:
void modalWithChildWindow();
void modalWindowModallity();
void modalWindowPosition();
-
- void initTestCase()
- {
- touchDevice = new QTouchDevice;
- touchDevice->setType(QTouchDevice::TouchScreen);
- QWindowSystemInterface::registerTouchDevice(touchDevice);
- }
+ void initTestCase();
+ void cleanup();
private:
+ QPoint m_availableTopLeft;
+ QSize m_testWindowSize;
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()
+{
+ QVERIFY(QGuiApplication::allWindows().isEmpty());
+}
+
void tst_QWindow::mapGlobal()
{
QWindow a;
@@ -145,6 +164,8 @@ public:
{
m_received[event->type()]++;
m_order << event->type();
+ if (event->type() == QEvent::Expose)
+ m_exposeRegion = static_cast<QExposeEvent *>(event)->region();
return QWindow::event(event);
}
@@ -159,16 +180,22 @@ public:
return m_order.indexOf(type);
}
+ QRegion exposeRegion() const
+ {
+ return m_exposeRegion;
+ }
+
private:
QHash<QEvent::Type, int> m_received;
QVector<QEvent::Type> m_order;
+ QRegion m_exposeRegion;
};
void tst_QWindow::eventOrderOnShow()
{
// Some platforms enforce minimum widths for windows, which can cause extra resize
// 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.setGeometry(geometry);
@@ -187,7 +214,7 @@ void tst_QWindow::resizeEventAfterResize()
{
// Some platforms enforce minimum widths for windows, which can cause extra resize
// 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.setGeometry(geometry);
@@ -197,7 +224,7 @@ void tst_QWindow::resizeEventAfterResize()
// QTBUG-32706
// 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
// so we only expect one resize event
@@ -233,15 +260,14 @@ void tst_QWindow::positioning()
// Some platforms enforce minimum widths for windows, which can cause extra resize
// events, so set the width to suitably large value to avoid those.
- const QSize size = QSize(300, 40);
- const QRect geometry(QPoint(80, 80), size);
+ const QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
QFETCH(int, windowflags);
QFETCH(int, resizecount);
Window window((Qt::WindowFlags)windowflags);
- window.setGeometry(QRect(QPoint(20, 20), size));
- window.setFramePosition(QPoint(40, 40)); // Move window around before show, size must not change.
- QCOMPARE(window.geometry().size(), size);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(20, 20), m_testWindowSize));
+ window.setFramePosition(m_availableTopLeft + QPoint(40, 40)); // Move window around before show, size must not change.
+ QCOMPARE(window.geometry().size(), m_testWindowSize);
window.setGeometry(geometry);
QCOMPARE(window.geometry(), geometry);
// explicitly use non-fullscreen show. show() can be fullscreen on some platforms
@@ -306,9 +332,30 @@ void tst_QWindow::positioning()
}
}
+void tst_QWindow::positioningDuringMinimized()
+{
+ // QTBUG-39544, setting a geometry in minimized state should work as well.
+ if (QGuiApplication::platformName().compare("windows", Qt::CaseInsensitive))
+ QSKIP("Not supported on this platform");
+ Window window;
+ window.setTitle(QStringLiteral("positioningDuringMinimized"));
+ const QRect initialGeometry(m_availableTopLeft + QPoint(100, 100), m_testWindowSize);
+ window.setGeometry(initialGeometry);
+ window.showNormal();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QCOMPARE(window.geometry(), initialGeometry);
+ window.setWindowState(Qt::WindowMinimized);
+ QCOMPARE(window.geometry(), initialGeometry);
+ const QRect newGeometry(initialGeometry.topLeft() + QPoint(50, 50), initialGeometry.size() + QSize(50, 50));
+ window.setGeometry(newGeometry);
+ QTRY_COMPARE(window.geometry(), newGeometry);
+ window.setWindowState(Qt::WindowNoState);
+ QTRY_COMPARE(window.geometry(), newGeometry);
+}
+
void tst_QWindow::isExposed()
{
- QRect geometry(80, 80, 40, 40);
+ QRect geometry(m_availableTopLeft + QPoint(80, 80), m_testWindowSize);
Window window;
window.setGeometry(geometry);
@@ -319,6 +366,14 @@ void tst_QWindow::isExposed()
QTRY_VERIFY(window.received(QEvent::Expose) > 0);
QTRY_VERIFY(window.isExposed());
+ // This is a top-level window so assuming it is completely exposed, the
+ // expose region must be (0, 0), (width, height). If this is not the case,
+ // the platform plugin is sending expose events with a region in an
+ // incorrect coordinate system.
+ QRect r = window.exposeRegion().boundingRect();
+ r = QRect(window.mapToGlobal(r.topLeft()), r.size());
+ QCOMPARE(r, window.geometry());
+
window.hide();
QCoreApplication::processEvents();
@@ -332,7 +387,7 @@ void tst_QWindow::isActive()
Window window;
// Some platforms enforce minimum widths for windows, which can cause extra resize
// 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();
QCoreApplication::processEvents();
@@ -372,7 +427,7 @@ void tst_QWindow::isActive()
Window dialog;
dialog.setTransientParent(&window);
- dialog.setGeometry(110, 110, 300, 30);
+ dialog.setGeometry(QRect(m_availableTopLeft + QPoint(110, 100), m_testWindowSize));
dialog.show();
dialog.requestActivate();
@@ -508,7 +563,7 @@ public:
void tst_QWindow::testInputEvents()
{
InputTestWindow window;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.showNormal();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -546,7 +601,7 @@ void tst_QWindow::testInputEvents()
// Now with null pointer as window. local param should not be utilized:
// handleMouseEvent() with tlw == 0 means the event is in global coords only.
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::NoButton);
QCoreApplication::processEvents();
@@ -568,7 +623,7 @@ void tst_QWindow::touchToMouseTranslation()
QSKIP("Mouse events are synthesized by the system on this platform.");
InputTestWindow window;
window.ignoreTouch = true;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -644,7 +699,7 @@ void tst_QWindow::mouseToTouchTranslation()
InputTestWindow window;
window.ignoreMouse = true;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -693,7 +748,7 @@ void tst_QWindow::mouseToTouchLoop()
InputTestWindow window;
window.ignoreMouse = true;
window.ignoreTouch = true;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -708,7 +763,7 @@ void tst_QWindow::mouseToTouchLoop()
void tst_QWindow::touchCancel()
{
InputTestWindow window;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -770,7 +825,7 @@ void tst_QWindow::touchCancelWithTouchToMouse()
QSKIP("Mouse events are synthesized by the system on this platform.");
InputTestWindow window;
window.ignoreTouch = true;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -811,7 +866,7 @@ void tst_QWindow::touchCancelWithTouchToMouse()
void tst_QWindow::touchInterruptedByPopup()
{
InputTestWindow window;
- window.setGeometry(80, 80, 200, 200);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -832,8 +887,7 @@ void tst_QWindow::touchInterruptedByPopup()
InputTestWindow popup;
popup.setFlags(Qt::Popup);
popup.setModality(Qt::WindowModal);
- popup.setWidth(160);
- popup.setHeight(160);
+ popup.resize(m_testWindowSize / 2);
popup.setTransientParent(&window);
popup.show();
QVERIFY(QTest::qWaitForWindowExposed(&popup));
@@ -863,7 +917,7 @@ void tst_QWindow::orientation()
qRegisterMetaType<Qt::ScreenOrientation>("Qt::ScreenOrientation");
QWindow window;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.create();
window.reportContentOrientationChange(Qt::PortraitOrientation);
@@ -974,7 +1028,7 @@ void tst_QWindow::mouseEventSequence()
int doubleClickInterval = qGuiApp->styleHints()->mouseDoubleClickInterval();
InputTestWindow window;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -1096,7 +1150,7 @@ void tst_QWindow::inputReentrancy()
InputTestWindow window;
window.spinLoopWhenPressed = true;
- window.setGeometry(80, 80, 40, 40);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
@@ -1165,7 +1219,7 @@ void tst_QWindow::tabletEvents()
{
#ifndef QT_NO_TABLETEVENT
TabletTestWindow window;
- window.setGeometry(10, 10, 100, 100);
+ window.setGeometry(QRect(m_availableTopLeft + QPoint(10, 10), m_testWindowSize));
qGuiApp->installEventFilter(&window);
QPoint local(10, 10);
@@ -1195,18 +1249,18 @@ void tst_QWindow::tabletEvents()
void tst_QWindow::windowModality_QTBUG27039()
{
QWindow parent;
- parent.setGeometry(10, 10, 100, 100);
+ parent.setGeometry(QRect(m_availableTopLeft + QPoint(10, 10), m_testWindowSize));
parent.show();
InputTestWindow modalA;
modalA.setTransientParent(&parent);
- modalA.setGeometry(10, 10, 20, 20);
+ modalA.setGeometry(QRect(m_availableTopLeft + QPoint(20, 10), m_testWindowSize));
modalA.setModality(Qt::ApplicationModal);
modalA.show();
InputTestWindow modalB;
modalB.setTransientParent(&parent);
- modalB.setGeometry(30, 10, 20, 20);
+ modalA.setGeometry(QRect(m_availableTopLeft + QPoint(30, 10), m_testWindowSize));
modalB.setModality(Qt::ApplicationModal);
modalB.show();
@@ -1296,40 +1350,43 @@ void tst_QWindow::initialSize()
}
{
Window w;
- w.setWidth(200);
+ w.setWidth(m_testWindowSize.width());
w.show();
#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen
// so we only expect one resize event
QTRY_COMPARE(w.width(), qGuiApp->primaryScreen()->availableGeometry().width());
#else
- QTRY_COMPARE(w.width(), 200);
+ QTRY_COMPARE(w.width(), m_testWindowSize.width());
#endif
QTRY_VERIFY(w.height() > 0);
}
{
Window w;
- w.resize(200, 42);
+ const QSize testSize(m_testWindowSize.width(), 42);
+ w.resize(testSize);
w.show();
+
#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen
// so we only expect one resize event
- QTRY_COMPARE(w.width(), qGuiApp->primaryScreen()->availableGeometry().width());
- QTRY_COMPARE(w.height(), qGuiApp->primaryScreen()->availableGeometry().height());
+ const QSize expectedSize = QGuiApplication::primaryScreen()->availableGeometry().size();
#else
- QTRY_COMPARE(w.width(), 200);
- QTRY_COMPARE(w.height(), 42);
+ const QSize expectedSize = testSize;
#endif
+ QTRY_COMPARE(w.size(), expectedSize);
}
}
void tst_QWindow::modalDialog()
{
QWindow normalWindow;
- normalWindow.resize(400, 400);
+ normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
+ normalWindow.resize(m_testWindowSize);
normalWindow.show();
QVERIFY(QTest::qWaitForWindowExposed(&normalWindow));
QWindow dialog;
- dialog.resize(200,200);
+ dialog.setFramePosition(m_availableTopLeft + QPoint(200, 200));
+ dialog.resize(m_testWindowSize);
dialog.setModality(Qt::ApplicationModal);
dialog.setFlags(Qt::Dialog);
dialog.show();
@@ -1345,12 +1402,14 @@ void tst_QWindow::modalDialog()
void tst_QWindow::modalDialogClosingOneOfTwoModal()
{
QWindow normalWindow;
- normalWindow.resize(400, 400);
+ normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
+ normalWindow.resize(m_testWindowSize);
normalWindow.show();
QVERIFY(QTest::qWaitForWindowExposed(&normalWindow));
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.setFlags(Qt::Dialog);
first_dialog.show();
@@ -1358,7 +1417,8 @@ void tst_QWindow::modalDialogClosingOneOfTwoModal()
{
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.setFlags(Qt::Dialog);
second_dialog.show();
@@ -1377,12 +1437,14 @@ void tst_QWindow::modalDialogClosingOneOfTwoModal()
void tst_QWindow::modalWithChildWindow()
{
QWindow normalWindow;
- normalWindow.resize(400, 400);
+ normalWindow.setFramePosition(m_availableTopLeft + QPoint(80, 80));
+ normalWindow.resize(m_testWindowSize);
normalWindow.show();
QVERIFY(QTest::qWaitForWindowExposed(&normalWindow));
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.setFlags(Qt::Dialog);
tlw_dialog.create();
@@ -1406,18 +1468,21 @@ void tst_QWindow::modalWithChildWindow()
void tst_QWindow::modalWindowModallity()
{
QWindow normal_window;
- normal_window.resize(400, 400);
+ normal_window.setFramePosition(m_availableTopLeft + QPoint(80, 80));
+ normal_window.resize(m_testWindowSize);
normal_window.show();
QVERIFY(QTest::qWaitForWindowExposed(&normal_window));
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();
QVERIFY(QTest::qWaitForWindowExposed(&parent_to_modal));
QTRY_COMPARE(QGuiApplication::focusWindow(), &parent_to_modal);
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.setFlags(Qt::Dialog);
modal_dialog.setTransientParent(&parent_to_modal);
@@ -1433,7 +1498,7 @@ void tst_QWindow::modalWindowModallity()
void tst_QWindow::modalWindowPosition()
{
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
QRect origGeo = window.geometry();
window.setModality(Qt::WindowModal);