Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_xdg_shell_stable.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2016 Martin Gräßlin <mgraesslin@kde.org> | ||||
3 | Copyright 2017 David Edmundson <davidedmundson@kde.org> | ||||
4 | | ||||
5 | This library is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU Lesser General Public | ||||
7 | License as published by the Free Software Foundation; either | ||||
8 | version 2.1 of the License, or (at your option) version 3, or any | ||||
9 | later version accepted by the membership of KDE e.V. (or its | ||||
10 | successor approved by the membership of KDE e.V.), which shall | ||||
11 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
12 | | ||||
13 | This library is distributed in the hope that it will be useful, | ||||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
16 | Lesser General Public License for more details. | ||||
17 | | ||||
18 | You should have received a copy of the GNU Lesser General Public | ||||
19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | *********************************************************************/ | ||||
21 | | ||||
22 | #include "test_xdg_shell.h" | ||||
23 | #include <wayland-xdg-shell-client-protocol.h> | ||||
24 | | ||||
25 | class XdgShellTestStable : public XdgShellTest { | ||||
26 | Q_OBJECT | ||||
27 | public: | ||||
28 | XdgShellTestStable() : | ||||
29 | XdgShellTest(KWayland::Server::XdgShellInterfaceVersion::Stable) {} | ||||
30 | | ||||
31 | private Q_SLOTS: | ||||
32 | void testMaxSize(); | ||||
33 | void testMinSize(); | ||||
34 | | ||||
35 | void testPopup_data(); | ||||
36 | void testPopup(); | ||||
37 | | ||||
38 | void testMultipleRoles1(); | ||||
39 | void testMultipleRoles2(); | ||||
40 | }; | ||||
41 | | ||||
42 | void XdgShellTestStable::testMaxSize() | ||||
43 | { | ||||
44 | qRegisterMetaType<OutputInterface*>(); | ||||
45 | // this test verifies changing the window maxSize | ||||
46 | QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
47 | QVERIFY(xdgSurfaceCreatedSpy.isValid()); | ||||
48 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
49 | QScopedPointer<XdgShellSurface> xdgSurface(m_xdgShell->createSurface(surface.data())); | ||||
50 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
51 | auto serverXdgSurface = xdgSurfaceCreatedSpy.first().first().value<XdgShellSurfaceInterface*>(); | ||||
52 | QVERIFY(serverXdgSurface); | ||||
53 | | ||||
54 | QSignalSpy maxSizeSpy(serverXdgSurface, &XdgShellSurfaceInterface::maxSizeChanged); | ||||
55 | QVERIFY(maxSizeSpy.isValid()); | ||||
56 | | ||||
57 | xdgSurface->setMaxSize(QSize(100, 100)); | ||||
58 | QVERIFY(maxSizeSpy.wait()); | ||||
59 | QCOMPARE(maxSizeSpy.count(), 1); | ||||
60 | QCOMPARE(maxSizeSpy.last().at(0).value<QSize>(), QSize(100,100)); | ||||
61 | | ||||
62 | xdgSurface->setMaxSize(QSize(200, 200)); | ||||
63 | QVERIFY(maxSizeSpy.wait()); | ||||
64 | QCOMPARE(maxSizeSpy.count(), 2); | ||||
65 | QCOMPARE(maxSizeSpy.last().at(0).value<QSize>(), QSize(200,200)); | ||||
66 | } | ||||
67 | | ||||
68 | | ||||
69 | void XdgShellTestStable::testPopup_data() | ||||
70 | { | ||||
71 | QTest::addColumn<XdgPositioner>("positioner"); | ||||
72 | XdgPositioner positioner(QSize(10,10), QRect(100,100,50,50)); | ||||
73 | QTest::newRow("default") << positioner; | ||||
74 | | ||||
75 | XdgPositioner positioner2(QSize(20,20), QRect(101,102,51,52)); | ||||
76 | QTest::newRow("sizeAndAnchorRect") << positioner2; | ||||
77 | | ||||
78 | positioner.setAnchorEdge(Qt::TopEdge | Qt::RightEdge); | ||||
79 | QTest::newRow("anchorEdge") << positioner; | ||||
80 | | ||||
81 | positioner.setGravity(Qt::BottomEdge); | ||||
82 | QTest::newRow("gravity") << positioner; | ||||
83 | | ||||
84 | positioner.setGravity(Qt::TopEdge | Qt::RightEdge); | ||||
85 | QTest::newRow("gravity2") << positioner; | ||||
86 | | ||||
87 | positioner.setConstraints(XdgPositioner::Constraint::SlideX | XdgPositioner::Constraint::FlipY); | ||||
88 | QTest::newRow("constraints") << positioner; | ||||
89 | | ||||
90 | positioner.setConstraints(XdgPositioner::Constraint::SlideX | XdgPositioner::Constraint::SlideY | XdgPositioner::Constraint::FlipX | XdgPositioner::Constraint::FlipY | XdgPositioner::Constraint::ResizeX | XdgPositioner::Constraint::ResizeY); | ||||
91 | QTest::newRow("constraints2") << positioner; | ||||
92 | | ||||
93 | positioner.setAnchorOffset(QPoint(4,5)); | ||||
94 | QTest::newRow("offset") << positioner; | ||||
95 | } | ||||
96 | | ||||
97 | void XdgShellTestStable::testPopup() | ||||
98 | { | ||||
99 | QSignalSpy xdgTopLevelCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
100 | QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated); | ||||
101 | | ||||
102 | QScopedPointer<Surface> parentSurface(m_compositor->createSurface()); | ||||
103 | QScopedPointer<XdgShellSurface> xdgParentSurface(m_xdgShell->createSurface(parentSurface.data())); | ||||
104 | | ||||
105 | QVERIFY(xdgTopLevelCreatedSpy.wait()); | ||||
106 | auto serverXdgTopLevel = xdgTopLevelCreatedSpy.first().first().value<XdgShellSurfaceInterface*>(); | ||||
107 | | ||||
108 | QFETCH(XdgPositioner, positioner); | ||||
109 | | ||||
110 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
111 | QScopedPointer<XdgShellPopup> xdgSurface(m_xdgShell->createPopup(surface.data(), xdgParentSurface.data(), positioner)); | ||||
112 | QVERIFY(xdgPopupCreatedSpy.wait()); | ||||
113 | auto serverXdgPopup = xdgPopupCreatedSpy.first().first().value<XdgShellPopupInterface*>(); | ||||
114 | QVERIFY(serverXdgPopup); | ||||
115 | | ||||
116 | QCOMPARE(serverXdgPopup->initialSize(), positioner.initialSize()); | ||||
117 | QCOMPARE(serverXdgPopup->anchorRect(), positioner.anchorRect()); | ||||
118 | QCOMPARE(serverXdgPopup->anchorEdge(), positioner.anchorEdge()); | ||||
119 | QCOMPARE(serverXdgPopup->gravity(), positioner.gravity()); | ||||
120 | QCOMPARE(serverXdgPopup->anchorOffset(), positioner.anchorOffset()); | ||||
121 | //we have different enums for client server, but they share the same values | ||||
122 | QCOMPARE((int)serverXdgPopup->constraintAdjustments(), (int)positioner.constraints()); | ||||
123 | QCOMPARE(serverXdgPopup->transientFor().data(), serverXdgTopLevel->surface()); | ||||
124 | } | ||||
125 | | ||||
126 | void XdgShellTestStable::testMinSize() | ||||
127 | { | ||||
128 | qRegisterMetaType<OutputInterface*>(); | ||||
129 | // this test verifies changing the window minSize | ||||
130 | QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
131 | QVERIFY(xdgSurfaceCreatedSpy.isValid()); | ||||
132 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
133 | QScopedPointer<XdgShellSurface> xdgSurface(m_xdgShell->createSurface(surface.data())); | ||||
134 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
135 | auto serverXdgSurface = xdgSurfaceCreatedSpy.first().first().value<XdgShellSurfaceInterface*>(); | ||||
136 | QVERIFY(serverXdgSurface); | ||||
137 | | ||||
138 | QSignalSpy minSizeSpy(serverXdgSurface, &XdgShellSurfaceInterface::minSizeChanged); | ||||
139 | QVERIFY(minSizeSpy.isValid()); | ||||
140 | | ||||
141 | xdgSurface->setMinSize(QSize(200, 200)); | ||||
142 | QVERIFY(minSizeSpy.wait()); | ||||
143 | QCOMPARE(minSizeSpy.count(), 1); | ||||
144 | QCOMPARE(minSizeSpy.last().at(0).value<QSize>(), QSize(200,200)); | ||||
145 | | ||||
146 | xdgSurface->setMinSize(QSize(100, 100)); | ||||
147 | QVERIFY(minSizeSpy.wait()); | ||||
148 | QCOMPARE(minSizeSpy.count(), 2); | ||||
149 | QCOMPARE(minSizeSpy.last().at(0).value<QSize>(), QSize(100,100)); | ||||
150 | } | ||||
151 | | ||||
152 | //top level then toplevel | ||||
153 | void XdgShellTestStable::testMultipleRoles1() | ||||
154 | { | ||||
155 | //setting multiple roles on an xdg surface should fail | ||||
156 | QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
157 | QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated); | ||||
158 | | ||||
159 | QVERIFY(xdgSurfaceCreatedSpy.isValid()); | ||||
160 | QVERIFY(xdgPopupCreatedSpy.isValid()); | ||||
161 | | ||||
162 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
163 | //This is testing we work when a client does something stupid | ||||
164 | //we can't use KWayland API here because by design that stops you from doing anything stupid | ||||
165 | | ||||
166 | qDebug() << (xdg_wm_base*)*m_xdgShell; | ||||
167 | auto xdgSurface = xdg_wm_base_get_xdg_surface(*m_xdgShell, *surface.data()); | ||||
168 | | ||||
169 | //create a top level | ||||
170 | auto xdgTopLevel1 = xdg_surface_get_toplevel(xdgSurface); | ||||
171 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
172 | | ||||
173 | //now try to create another top level for the same xdg surface. It should fail | ||||
174 | auto xdgTopLevel2 = xdg_surface_get_toplevel(xdgSurface); | ||||
175 | QVERIFY(!xdgSurfaceCreatedSpy.wait(10)); | ||||
176 | | ||||
177 | xdg_toplevel_destroy(xdgTopLevel1); | ||||
178 | xdg_toplevel_destroy(xdgTopLevel2); | ||||
179 | xdg_surface_destroy(xdgSurface); | ||||
180 | } | ||||
181 | | ||||
182 | //toplevel then popup | ||||
183 | void XdgShellTestStable::testMultipleRoles2() | ||||
184 | { | ||||
185 | QSignalSpy xdgSurfaceCreatedSpy(m_xdgShellInterface, &XdgShellInterface::surfaceCreated); | ||||
186 | QSignalSpy xdgPopupCreatedSpy(m_xdgShellInterface, &XdgShellInterface::xdgPopupCreated); | ||||
187 | | ||||
188 | QVERIFY(xdgSurfaceCreatedSpy.isValid()); | ||||
189 | QVERIFY(xdgPopupCreatedSpy.isValid()); | ||||
190 | | ||||
191 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
192 | QScopedPointer<Surface> parentSurface(m_compositor->createSurface()); | ||||
193 | | ||||
194 | auto parentXdgSurface = xdg_wm_base_get_xdg_surface(*m_xdgShell, *parentSurface.data()); | ||||
195 | auto xdgTopLevelParent = xdg_surface_get_toplevel(parentXdgSurface); | ||||
196 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
197 | | ||||
198 | | ||||
199 | auto xdgSurface = xdg_wm_base_get_xdg_surface(*m_xdgShell, *surface.data()); | ||||
200 | //create a top level | ||||
201 | auto xdgTopLevel1 = xdg_surface_get_toplevel(xdgSurface); | ||||
202 | QVERIFY(xdgSurfaceCreatedSpy.wait()); | ||||
203 | | ||||
204 | //now try to create a popup on the same xdg surface. It should fail | ||||
205 | | ||||
206 | auto positioner = xdg_wm_base_create_positioner(*m_xdgShell); | ||||
207 | xdg_positioner_set_anchor_rect(positioner,10, 10, 10, 10); | ||||
208 | xdg_positioner_set_size(positioner,10, 100); | ||||
209 | | ||||
210 | auto xdgPopup2 = xdg_surface_get_popup(xdgSurface, parentXdgSurface, positioner); | ||||
211 | QVERIFY(!xdgPopupCreatedSpy.wait(10)); | ||||
212 | | ||||
213 | xdg_positioner_destroy(positioner); | ||||
214 | xdg_toplevel_destroy(xdgTopLevel1); | ||||
215 | xdg_toplevel_destroy(xdgTopLevelParent); | ||||
216 | xdg_popup_destroy(xdgPopup2); | ||||
217 | xdg_surface_destroy(xdgSurface); | ||||
218 | } | ||||
219 | | ||||
220 | | ||||
221 | QTEST_GUILESS_MAIN(XdgShellTestStable) | ||||
222 | | ||||
223 | #include "test_xdg_shell_stable.moc" | ||||
224 | |