Client: Add tests for xdg-shell v6 window geometry

Change-Id: Ifb7a1d63a136349cd99d516e63732b4393967468
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
Johan Klokkhammer Helsing 2018-06-05 16:16:13 +02:00 committed by Johan Helsing
parent 90336adc17
commit 2c9bb12fe3
4 changed files with 53 additions and 0 deletions

View File

@ -189,6 +189,7 @@ signals:
uint unsetMaximizedRequested();
uint setFullscreenRequested();
uint unsetFullscreenRequested();
void windowGeometryRequested(QRect geometry); // NOTE: This is really an xdg surface event
private:
MockXdgToplevelV6(Impl::XdgToplevelV6 *toplevel) : m_toplevel(toplevel) {}

View File

@ -57,6 +57,14 @@ void XdgSurfaceV6::zxdg_surface_v6_get_toplevel(QtWaylandServer::zxdg_surface_v6
m_toplevel = new XdgToplevelV6(this, resource->client(), id, version);
}
void XdgSurfaceV6::zxdg_surface_v6_set_window_geometry(QtWaylandServer::zxdg_surface_v6::Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
{
if (m_toplevel) {
QRect geometry(x, y, width, height);
emit m_toplevel->mockToplevel()->windowGeometryRequested(geometry);
}
}
void XdgSurfaceV6::zxdg_surface_v6_destroy(QtWaylandServer::zxdg_surface_v6::Resource *resource)
{
Q_ASSERT(!m_toplevel);

View File

@ -52,6 +52,7 @@ public:
protected:
void zxdg_surface_v6_destroy_resource(Resource *) override { delete this; }
void zxdg_surface_v6_get_toplevel(Resource *resource, uint32_t id) override;
void zxdg_surface_v6_set_window_geometry(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
void zxdg_surface_v6_destroy(Resource *resource) override;
private:

View File

@ -99,6 +99,8 @@ private slots:
void unsetMaximized();
void focusWindowFollowsConfigure();
void windowStateChangedEvents();
void windowGeometrySimple();
void windowGeometryFixed();
private:
MockCompositor *m_compositor = nullptr;
@ -317,6 +319,47 @@ void tst_WaylandClientXdgShellV6::windowStateChangedEvents()
}
}
void tst_WaylandClientXdgShellV6::windowGeometrySimple()
{
QWindow window;
window.show();
QSharedPointer<MockXdgToplevelV6> toplevel;
QTRY_VERIFY(toplevel = m_compositor->xdgToplevelV6());
QSignalSpy geometrySpy(toplevel.data(), SIGNAL(windowGeometryRequested(QRect)));
m_compositor->sendXdgToplevelV6Configure(toplevel);
QTRY_COMPARE(geometrySpy.count(), 1);
QCOMPARE(geometrySpy.takeFirst().at(0).toRect().size(), window.frameGeometry().size());
m_compositor->sendXdgToplevelV6Configure(toplevel, QSize(123, 456));
QTRY_COMPARE(geometrySpy.count(), 1);
QCOMPARE(geometrySpy.takeFirst().at(0).toRect().size(), QSize(123, 456));
}
void tst_WaylandClientXdgShellV6::windowGeometryFixed()
{
QWindow window;
window.resize(QSize(1337, 137));
window.setMaximumSize(window.size());
window.setMinimumSize(window.size());
window.show();
QSharedPointer<MockXdgToplevelV6> toplevel;
QTRY_VERIFY(toplevel = m_compositor->xdgToplevelV6());
QSignalSpy geometrySpy(toplevel.data(), SIGNAL(windowGeometryRequested(QRect)));
m_compositor->sendXdgToplevelV6Configure(toplevel);
QTRY_COMPARE(geometrySpy.count(), 1);
QRect initialWindowGeometry = geometrySpy.takeFirst().at(0).toRect();
QCOMPARE(initialWindowGeometry.size(), window.frameGeometry().size());
m_compositor->sendXdgToplevelV6Configure(toplevel, QSize(123, 456));
QTRY_COMPARE(geometrySpy.count(), 1);
// Configuring the window should not change the window geometry
QCOMPARE(geometrySpy.takeFirst().at(0).toRect().size(), initialWindowGeometry.size());
}
int main(int argc, char **argv)
{
setenv("XDG_RUNTIME_DIR", ".", 1);