Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_xdg_shell_v6.cpp
- This file was added.
1 | #include "test_xdg_shell.h" | ||||
---|---|---|---|---|---|
2 | #include <wayland-xdg-shell-v6-client-protocol.h> | ||||
3 | | ||||
4 | class XdgShellTestV6 : public XdgShellTest { | ||||
5 | Q_OBJECT | ||||
6 | public: | ||||
7 | XdgShellTestV6() : | ||||
8 | XdgShellTest(KWayland::Server::XdgShellInterfaceVersion::UnstableV6) {} | ||||
9 | | ||||
10 | private Q_SLOTS: | ||||
11 | void testMaxSize(); | ||||
12 | void testMinSize(); | ||||
13 | | ||||
14 | void testPopup_data(); | ||||
15 | void testPopup(); | ||||
16 | | ||||
17 | void testMultipleRoles1(); | ||||
18 | void testMultipleRoles2(); | ||||
19 | }; | ||||
20 | | ||||
21 | void XdgShellTestV6::testMaxSize() | ||||
22 | { | ||||
23 | qRegisterMetaType<OutputInterface*>(); | ||||
24 | // this test verifies changing the window maxSize | ||||
25 | QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
26 | QVERIFY(xdgSurfaceCreatedSpy.isValid()); | ||||
27 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
28 | QScopedPointer<XdgShellSurface> xdgSurface(m_xdgShell->createSurface(surface.data())); | ||||
29 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
30 | auto serverXdgSurface = xdgSurfaceCreatedSpy.first().first().value<XdgShellSurfaceInterface*>(); | ||||
31 | QVERIFY(serverXdgSurface); | ||||
32 | | ||||
33 | QSignalSpy maxSizeSpy(serverXdgSurface, &XdgShellSurfaceInterface::maxSizeChanged); | ||||
34 | QVERIFY(maxSizeSpy.isValid()); | ||||
35 | | ||||
36 | xdgSurface->setMaxSize(QSize(100, 100)); | ||||
37 | QVERIFY(maxSizeSpy.wait()); | ||||
38 | QCOMPARE(maxSizeSpy.count(), 1); | ||||
39 | QCOMPARE(maxSizeSpy.last().at(0).value<QSize>(), QSize(100,100)); | ||||
40 | | ||||
41 | xdgSurface->setMaxSize(QSize(200, 200)); | ||||
42 | QVERIFY(maxSizeSpy.wait()); | ||||
43 | QCOMPARE(maxSizeSpy.count(), 2); | ||||
44 | QCOMPARE(maxSizeSpy.last().at(0).value<QSize>(), QSize(200,200)); | ||||
45 | } | ||||
46 | | ||||
47 | | ||||
48 | void XdgShellTestV6::testPopup_data() | ||||
49 | { | ||||
50 | QTest::addColumn<XdgPositioner>("positioners"); | ||||
51 | XdgPositioner positioner(QSize(10,10), QRect(100,100,50,50)); | ||||
52 | QTest::newRow("default") << positioner; | ||||
53 | | ||||
54 | XdgPositioner positioner2(QSize(20,20), QRect(101,102,51,52)); | ||||
55 | QTest::newRow("sizeAndAnchorRect") << positioner2; | ||||
56 | | ||||
57 | positioner.setAnchorEdge(Qt::TopEdge | Qt::RightEdge); | ||||
58 | QTest::newRow("anchorEdge") << positioner; | ||||
59 | | ||||
60 | positioner.setGravity(Qt::BottomEdge); | ||||
61 | QTest::newRow("gravity") << positioner; | ||||
62 | | ||||
63 | positioner.setGravity(Qt::TopEdge | Qt::RightEdge); | ||||
64 | QTest::newRow("gravity2") << positioner; | ||||
65 | | ||||
66 | positioner.setConstraints(XdgPositioner::Constraint::SlideX | XdgPositioner::Constraint::FlipY); | ||||
67 | QTest::newRow("constraints") << positioner; | ||||
68 | | ||||
69 | positioner.setConstraints(XdgPositioner::Constraint::SlideX | XdgPositioner::Constraint::SlideY | XdgPositioner::Constraint::FlipX | XdgPositioner::Constraint::FlipY | XdgPositioner::Constraint::ResizeX | XdgPositioner::Constraint::ResizeY); | ||||
70 | QTest::newRow("constraints2") << positioner; | ||||
71 | | ||||
72 | positioner.setAnchorOffset(QPoint(4,5)); | ||||
73 | QTest::newRow("offset") << positioner; | ||||
74 | } | ||||
75 | | ||||
76 | void XdgShellTestV6::testPopup() | ||||
77 | { | ||||
78 | QSignalSpy xdgTopLevelCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
79 | QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated); | ||||
80 | | ||||
81 | QScopedPointer<Surface> parentSurface(m_compositor->createSurface()); | ||||
82 | QScopedPointer<XdgShellSurface> xdgParentSurface(m_xdgShell->createSurface(parentSurface.data())); | ||||
83 | | ||||
84 | QVERIFY(xdgTopLevelCreatedSpy.wait()); | ||||
85 | auto serverXdgTopLevel = xdgTopLevelCreatedSpy.first().first().value<XdgShellSurfaceInterface*>(); | ||||
86 | | ||||
87 | XdgPositioner positioner(QSize(10,10), QRect(100,100,50,50)); | ||||
88 | | ||||
89 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
90 | QScopedPointer<XdgShellPopup> xdgSurface(m_xdgShell->createPopup(surface.data(), xdgParentSurface.data(), positioner)); | ||||
91 | QVERIFY(xdgPopupCreatedSpy.wait()); | ||||
92 | auto serverXdgPopup = xdgPopupCreatedSpy.first().first().value<XdgShellPopupInterface*>(); | ||||
93 | QVERIFY(serverXdgPopup); | ||||
94 | | ||||
95 | QCOMPARE(serverXdgPopup->initialSize(), positioner.initialSize()); | ||||
96 | QCOMPARE(serverXdgPopup->anchorRect(), positioner.anchorRect()); | ||||
97 | QCOMPARE(serverXdgPopup->anchorEdge(), positioner.anchorEdge()); | ||||
98 | QCOMPARE(serverXdgPopup->gravity(), positioner.gravity()); | ||||
99 | QCOMPARE(serverXdgPopup->anchorOffset(), positioner.anchorOffset()); | ||||
100 | //we have different enums for client server, but they share the same values | ||||
101 | QCOMPARE((int)serverXdgPopup->constraintAdjustments(), (int)positioner.constraints()); | ||||
102 | QCOMPARE(serverXdgPopup->transientFor().data(), serverXdgTopLevel->surface()); | ||||
103 | } | ||||
104 | | ||||
105 | void XdgShellTestV6::testMinSize() | ||||
106 | { | ||||
107 | qRegisterMetaType<OutputInterface*>(); | ||||
108 | // this test verifies changing the window minSize | ||||
109 | QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
110 | QVERIFY(xdgSurfaceCreatedSpy.isValid()); | ||||
111 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
112 | QScopedPointer<XdgShellSurface> xdgSurface(m_xdgShell->createSurface(surface.data())); | ||||
113 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
114 | auto serverXdgSurface = xdgSurfaceCreatedSpy.first().first().value<XdgShellSurfaceInterface*>(); | ||||
115 | QVERIFY(serverXdgSurface); | ||||
116 | | ||||
117 | QSignalSpy minSizeSpy(serverXdgSurface, &XdgShellSurfaceInterface::minSizeChanged); | ||||
118 | QVERIFY(minSizeSpy.isValid()); | ||||
119 | | ||||
120 | xdgSurface->setMinSize(QSize(200, 200)); | ||||
121 | QVERIFY(minSizeSpy.wait()); | ||||
122 | QCOMPARE(minSizeSpy.count(), 1); | ||||
123 | QCOMPARE(minSizeSpy.last().at(0).value<QSize>(), QSize(200,200)); | ||||
124 | | ||||
125 | xdgSurface->setMinSize(QSize(100, 100)); | ||||
126 | QVERIFY(minSizeSpy.wait()); | ||||
127 | QCOMPARE(minSizeSpy.count(), 2); | ||||
128 | QCOMPARE(minSizeSpy.last().at(0).value<QSize>(), QSize(100,100)); | ||||
129 | } | ||||
130 | | ||||
131 | //top level then toplevel | ||||
132 | void XdgShellTestV6::testMultipleRoles1() | ||||
133 | { | ||||
134 | //setting multiple roles on an xdg surface should fail | ||||
135 | QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
136 | QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated); | ||||
137 | | ||||
138 | QVERIFY(xdgSurfaceCreatedSpy.isValid()); | ||||
139 | QVERIFY(xdgPopupCreatedSpy.isValid()); | ||||
140 | | ||||
141 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
142 | //This is testing we work when a client does something stupid | ||||
143 | //we can't use KWayland API here because by design that stops you from doing anything stupid | ||||
144 | auto xdgSurface = zxdg_shell_v6_get_xdg_surface(*m_xdgShell, *surface.data()); | ||||
145 | | ||||
146 | //create a top level | ||||
147 | auto xdgTopLevel1 = zxdg_surface_v6_get_toplevel(xdgSurface); | ||||
148 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
149 | | ||||
150 | //now try to create another top level for the same xdg surface. It should fail | ||||
151 | auto xdgTopLevel2 = zxdg_surface_v6_get_toplevel(xdgSurface); | ||||
152 | QVERIFY(!xdgSurfaceCreatedSpy.wait(10)); | ||||
153 | | ||||
154 | zxdg_toplevel_v6_destroy(xdgTopLevel1); | ||||
155 | zxdg_toplevel_v6_destroy(xdgTopLevel2); | ||||
156 | zxdg_surface_v6_destroy(xdgSurface); | ||||
157 | } | ||||
158 | | ||||
159 | //toplevel then popup | ||||
160 | void XdgShellTestV6::testMultipleRoles2() | ||||
161 | { | ||||
162 | QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
163 | QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated); | ||||
164 | | ||||
165 | QVERIFY(xdgSurfaceCreatedSpy.isValid()); | ||||
166 | QVERIFY(xdgPopupCreatedSpy.isValid()); | ||||
167 | | ||||
168 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
169 | QScopedPointer<Surface> parentSurface(m_compositor->createSurface()); | ||||
170 | | ||||
171 | auto parentXdgSurface = zxdg_shell_v6_get_xdg_surface(*m_xdgShell, *parentSurface.data()); | ||||
172 | auto xdgTopLevelParent = zxdg_surface_v6_get_toplevel(parentXdgSurface); | ||||
173 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
174 | | ||||
175 | | ||||
176 | auto xdgSurface = zxdg_shell_v6_get_xdg_surface(*m_xdgShell, *surface.data()); | ||||
177 | //create a top level | ||||
178 | auto xdgTopLevel1 = zxdg_surface_v6_get_toplevel(xdgSurface); | ||||
179 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
180 | | ||||
181 | //now try to create a popup on the same xdg surface. It should fail | ||||
182 | | ||||
183 | auto positioner = zxdg_shell_v6_create_positioner(*m_xdgShell); | ||||
184 | zxdg_positioner_v6_set_anchor_rect(positioner,10, 10, 10, 10); | ||||
185 | zxdg_positioner_v6_set_size(positioner,10, 100); | ||||
186 | | ||||
187 | auto xdgPopup2 = zxdg_surface_v6_get_popup(xdgSurface, parentXdgSurface, positioner); | ||||
188 | QVERIFY(!xdgPopupCreatedSpy.wait(10)); | ||||
189 | | ||||
190 | zxdg_positioner_v6_destroy(positioner); | ||||
191 | zxdg_toplevel_v6_destroy(xdgTopLevel1); | ||||
192 | zxdg_toplevel_v6_destroy(xdgTopLevelParent); | ||||
193 | zxdg_popup_v6_destroy(xdgPopup2); | ||||
194 | zxdg_surface_v6_destroy(xdgSurface); | ||||
195 | } | ||||
196 | | ||||
197 | | ||||
198 | QTEST_GUILESS_MAIN(XdgShellTestV6) | ||||
199 | | ||||
200 | #include "test_xdg_shell_v6.moc" | ||||
201 | |