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.cpp216
1 files changed, 180 insertions, 36 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index a89f0da4d2..d764b88ef7 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -58,12 +58,17 @@ class tst_QWindow: public QObject
Q_OBJECT
private slots:
+ void create();
+ void setParent();
+ void setVisible();
void eventOrderOnShow();
void resizeEventAfterResize();
void mapGlobal();
void positioning_data();
void positioning();
void positioningDuringMinimized();
+ void childWindowPositioning_data();
+ void childWindowPositioning();
void platformSurface();
void isExposed();
void isActive();
@@ -126,6 +131,111 @@ void tst_QWindow::cleanup()
QVERIFY(QGuiApplication::allWindows().isEmpty());
}
+void tst_QWindow::create()
+{
+ QWindow a;
+ QVERIFY2(!a.handle(), "QWindow should lazy init the platform window");
+
+ a.create();
+ QVERIFY2(a.handle(), "Explicitly creating a platform window should never fail");
+
+ QWindow b;
+ QWindow c(&b);
+ b.create();
+ QVERIFY(b.handle());
+ QVERIFY2(!c.handle(), "Creating a parent window should not automatically create children");
+
+ QWindow d;
+ QWindow e(&d);
+ e.create();
+ QVERIFY(e.handle());
+ QVERIFY2(d.handle(), "Creating a child window should automatically create parents");
+
+ QWindow f;
+ QWindow g(&f);
+ f.create();
+ QVERIFY(f.handle());
+ QPlatformWindow *platformWindow = f.handle();
+ g.create();
+ QVERIFY(g.handle());
+ QVERIFY2(f.handle() == platformWindow, "Creating a child window should not affect parent if already created");
+}
+
+void tst_QWindow::setParent()
+{
+ QWindow a;
+ QWindow b(&a);
+ QVERIFY2(b.parent() == &a, "Setting parent at construction time should work");
+ QVERIFY2(a.children().contains(&b), "Parent should have child in list of children");
+
+ QWindow c;
+ QWindow d;
+ d.setParent(&c);
+ QVERIFY2(d.parent() == &c, "Setting parent after construction should work");
+ QVERIFY2(c.children().contains(&d), "Parent should have child in list of children");
+
+ a.create();
+ b.setParent(0);
+ QVERIFY2(!b.handle(), "Making window top level shouild not automatically create it");
+
+ QWindow e;
+ c.create();
+ e.setParent(&c);
+ QVERIFY2(!e.handle(), "Making window a child of a created window should not automatically create it");
+
+ QWindow f;
+ QWindow g;
+ g.create();
+ QVERIFY(g.handle());
+ g.setParent(&f);
+ QVERIFY2(f.handle(), "Making a created window a child of a non-created window should automatically create it");
+}
+
+void tst_QWindow::setVisible()
+{
+ QWindow a;
+ QWindow b(&a);
+ a.setVisible(true);
+ QVERIFY2(!b.handle(), "Making a top level window visible doesn't create its children");
+ QVERIFY2(!b.isVisible(), "Making a top level window visible doesn't make its children visible");
+ QVERIFY(QTest::qWaitForWindowExposed(&a));
+
+ QWindow c;
+ QWindow d(&c);
+ d.setVisible(true);
+ QVERIFY2(!c.handle(), "Making a child window visible doesn't create parent window if parent is hidden");
+ QVERIFY2(!c.isVisible(), "Making a child window visible doesn't make its parent visible");
+
+ QVERIFY2(!d.handle(), "Making a child window visible doesn't create platform window if parent is hidden");
+
+ c.create();
+ QVERIFY(c.handle());
+ QVERIFY2(d.handle(), "Creating a parent window should automatically create children if they are visible");
+ QVERIFY2(!c.isVisible(), "Creating a parent window should not make it visible just because it has visible children");
+
+ QWindow e;
+ QWindow f(&e);
+ f.setVisible(true);
+ QVERIFY(!f.handle());
+ QVERIFY(!e.handle());
+ f.setParent(0);
+ QVERIFY2(f.handle(), "Making a visible but not created child window top level should create it");
+ QVERIFY(QTest::qWaitForWindowExposed(&f));
+
+ QWindow g;
+ QWindow h;
+ QWindow i(&g);
+ i.setVisible(true);
+ h.setVisible(true);
+ QVERIFY(QTest::qWaitForWindowExposed(&h));
+ QVERIFY(!i.handle());
+ QVERIFY(!g.handle());
+ QVERIFY(h.handle());
+ i.setParent(&h);
+ QVERIFY2(i.handle(), "Making a visible but not created child window child of a created window should create it");
+ QVERIFY(QTest::qWaitForWindowExposed(&i));
+}
+
void tst_QWindow::mapGlobal()
{
QWindow a;
@@ -214,6 +324,19 @@ private:
QPlatformSurfaceEvent::SurfaceEventType m_surfaceventType;
};
+class ColoredWindow : public QRasterWindow {
+public:
+ explicit ColoredWindow(const QColor &color, QWindow *parent = 0) : QRasterWindow(parent), m_color(color) {}
+ void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE
+ {
+ QPainter p(this);
+ p.fillRect(QRect(QPoint(0, 0), size()), m_color);
+ }
+
+private:
+ const QColor m_color;
+};
+
void tst_QWindow::eventOrderOnShow()
{
// Some platforms enforce minimum widths for windows, which can cause extra resize
@@ -249,12 +372,7 @@ void tst_QWindow::resizeEventAfterResize()
// Make sure we get a resizeEvent after calling resize
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
- QTRY_COMPARE(window.received(QEvent::Resize), 1);
-#else
QTRY_COMPARE(window.received(QEvent::Resize), 2);
-#endif
}
void tst_QWindow::positioning_data()
@@ -338,21 +456,15 @@ void tst_QWindow::positioning()
window.reset();
window.setWindowState(Qt::WindowFullScreen);
QCoreApplication::processEvents();
- // On BB10 the window is the root window and fullscreen, so nothing is resized.
-#if !defined(Q_OS_BLACKBERRY)
- QTRY_VERIFY(window.received(QEvent::Resize) > 0);
-#endif
+ QTRY_VERIFY(window.received(QEvent::Resize) > 0);
QTest::qWait(2000);
window.reset();
window.setWindowState(Qt::WindowNoState);
QCoreApplication::processEvents();
- // On BB10 the window is the root window and fullscreen, so nothing is resized.
-#if !defined(Q_OS_BLACKBERRY)
- QTRY_VERIFY(window.received(QEvent::Resize) > 0);
-#endif
+ QTRY_VERIFY(window.received(QEvent::Resize) > 0);
QTest::qWait(2000);
QTRY_COMPARE(originalPos, window.position());
@@ -415,6 +527,61 @@ void tst_QWindow::positioningDuringMinimized()
QTRY_COMPARE(window.geometry(), newGeometry);
}
+void tst_QWindow::childWindowPositioning_data()
+{
+ QTest::addColumn<bool>("showInsteadOfCreate");
+
+ QTest::newRow("create") << false;
+ QTest::newRow("show") << true;
+}
+
+void tst_QWindow::childWindowPositioning()
+{
+ const QPoint topLeftOrigin(0, 0);
+
+ ColoredWindow topLevelWindowFirst(Qt::green);
+ topLevelWindowFirst.setObjectName("topLevelWindowFirst");
+ ColoredWindow childWindowAfter(Qt::yellow, &topLevelWindowFirst);
+ childWindowAfter.setObjectName("childWindowAfter");
+
+ topLevelWindowFirst.setFramePosition(m_availableTopLeft);
+ childWindowAfter.setFramePosition(topLeftOrigin);
+
+ ColoredWindow topLevelWindowAfter(Qt::green);
+ topLevelWindowAfter.setObjectName("topLevelWindowAfter");
+ ColoredWindow childWindowFirst(Qt::yellow, &topLevelWindowAfter);
+ childWindowFirst.setObjectName("childWindowFirst");
+
+ topLevelWindowAfter.setFramePosition(m_availableTopLeft);
+ childWindowFirst.setFramePosition(topLeftOrigin);
+
+ QFETCH(bool, showInsteadOfCreate);
+
+ QWindow* windows[] = { &topLevelWindowFirst, &childWindowAfter, &childWindowFirst, &topLevelWindowAfter, 0 };
+ for (int i = 0; windows[i]; ++i) {
+ QWindow *window = windows[i];
+ if (showInsteadOfCreate) {
+ window->showNormal();
+ } else {
+ window->create();
+ }
+ }
+
+ if (showInsteadOfCreate) {
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevelWindowFirst));
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevelWindowAfter));
+ }
+
+ // Creation order shouldn't affect the geometry
+ // Use try compare since on X11 the window manager may still re-position the window after expose
+ QTRY_COMPARE(topLevelWindowFirst.geometry(), topLevelWindowAfter.geometry());
+ QTRY_COMPARE(childWindowAfter.geometry(), childWindowFirst.geometry());
+
+ // Creation order shouldn't affect the child ending up at 0,0
+ QCOMPARE(childWindowFirst.framePosition(), topLeftOrigin);
+ QCOMPARE(childWindowAfter.framePosition(), topLeftOrigin);
+}
+
// QTBUG-49709: Verify that the normal geometry is correctly restored
// when executing a sequence of window state changes. So far, Windows
// only where state changes have immediate effect.
@@ -1565,12 +1732,7 @@ void tst_QWindow::initialSize()
Window w;
w.setWidth(m_testWindowSize.width());
w.showNormal();
-#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(), m_testWindowSize.width());
-#endif
QTRY_VERIFY(w.height() > 0);
}
{
@@ -1579,12 +1741,7 @@ void tst_QWindow::initialSize()
w.resize(testSize);
w.showNormal();
-#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen
- // so we only expect one resize event
- const QSize expectedSize = QGuiApplication::primaryScreen()->availableGeometry().size();
-#else
const QSize expectedSize = testSize;
-#endif
QTRY_COMPARE(w.size(), expectedSize);
}
}
@@ -1732,19 +1889,6 @@ void tst_QWindow::modalWindowPosition()
QCOMPARE(window.geometry(), origGeo);
}
-class ColoredWindow : public QRasterWindow {
-public:
- explicit ColoredWindow(const QColor &color, QWindow *parent = 0) : QRasterWindow(parent), m_color(color) {}
- void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE
- {
- QPainter p(this);
- p.fillRect(QRect(QPoint(0, 0), size()), m_color);
- }
-
-private:
- const QColor m_color;
-};
-
static bool isNativeWindowVisible(const QWindow *window)
{
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)