Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/virtual_desktop_test.cpp
Show All 37 Lines | |||||
38 | private Q_SLOTS: | 38 | private Q_SLOTS: | ||
39 | void initTestCase(); | 39 | void initTestCase(); | ||
40 | void init(); | 40 | void init(); | ||
41 | void cleanup(); | 41 | void cleanup(); | ||
42 | 42 | | |||
43 | void testNetCurrentDesktop(); | 43 | void testNetCurrentDesktop(); | ||
44 | void testLastDesktopRemoved_data(); | 44 | void testLastDesktopRemoved_data(); | ||
45 | void testLastDesktopRemoved(); | 45 | void testLastDesktopRemoved(); | ||
46 | void testWindowOnMultipleDesktops_data(); | ||||
47 | void testWindowOnMultipleDesktops(); | ||||
48 | void testRemoveDesktopWithWindow_data(); | ||||
49 | void testRemoveDesktopWithWindow(); | ||||
46 | }; | 50 | }; | ||
47 | 51 | | |||
48 | void VirtualDesktopTest::initTestCase() | 52 | void VirtualDesktopTest::initTestCase() | ||
49 | { | 53 | { | ||
50 | qRegisterMetaType<KWin::ShellClient*>(); | 54 | qRegisterMetaType<KWin::ShellClient*>(); | ||
51 | qRegisterMetaType<KWin::AbstractClient*>(); | 55 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
52 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 56 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
53 | QVERIFY(workspaceCreatedSpy.isValid()); | 57 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 143 | { | |||
152 | QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data())); | 156 | QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data())); | ||
153 | auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | 157 | auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||
154 | 158 | | |||
155 | QVERIFY(client); | 159 | QVERIFY(client); | ||
156 | QCOMPARE(client->desktop(), 2); | 160 | QCOMPARE(client->desktop(), 2); | ||
157 | QSignalSpy desktopPresenceChangedSpy(client, &ShellClient::desktopPresenceChanged); | 161 | QSignalSpy desktopPresenceChangedSpy(client, &ShellClient::desktopPresenceChanged); | ||
158 | QVERIFY(desktopPresenceChangedSpy.isValid()); | 162 | QVERIFY(desktopPresenceChangedSpy.isValid()); | ||
159 | 163 | | |||
164 | QCOMPARE(client->desktops().count(), 1u); | ||||
165 | QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first()); | ||||
166 | | ||||
160 | // and remove last desktop | 167 | // and remove last desktop | ||
161 | VirtualDesktopManager::self()->setCount(1); | 168 | VirtualDesktopManager::self()->setCount(1); | ||
162 | QCOMPARE(VirtualDesktopManager::self()->count(), 1u); | 169 | QCOMPARE(VirtualDesktopManager::self()->count(), 1u); | ||
163 | // now the client should be moved as well | 170 | // now the client should be moved as well | ||
164 | QTRY_COMPARE(desktopPresenceChangedSpy.count(), 1); | 171 | QTRY_COMPARE(desktopPresenceChangedSpy.count(), 1); | ||
165 | QCOMPARE(client->desktop(), 1); | 172 | QCOMPARE(client->desktop(), 1); | ||
173 | | ||||
174 | QCOMPARE(client->desktops().count(), 1u); | ||||
175 | QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first()); | ||||
176 | } | ||||
177 | | ||||
178 | void VirtualDesktopTest::testWindowOnMultipleDesktops_data() | ||||
179 | { | ||||
180 | QTest::addColumn<Test::ShellSurfaceType>("type"); | ||||
181 | | ||||
182 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | ||||
183 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | ||||
184 | QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6; | ||||
185 | } | ||||
186 | | ||||
187 | void VirtualDesktopTest::testWindowOnMultipleDesktops() | ||||
188 | { | ||||
189 | // first create two new desktops | ||||
190 | QCOMPARE(VirtualDesktopManager::self()->count(), 1u); | ||||
191 | VirtualDesktopManager::self()->setCount(3); | ||||
192 | QCOMPARE(VirtualDesktopManager::self()->count(), 3u); | ||||
193 | | ||||
194 | // switch to last desktop | ||||
195 | VirtualDesktopManager::self()->setCurrent(VirtualDesktopManager::self()->desktops().last()); | ||||
196 | QCOMPARE(VirtualDesktopManager::self()->current(), 3u); | ||||
197 | | ||||
198 | // now create a window on this desktop | ||||
199 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
200 | QFETCH(Test::ShellSurfaceType, type); | ||||
201 | QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data())); | ||||
202 | auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
203 | | ||||
204 | QVERIFY(client); | ||||
205 | QCOMPARE(client->desktop(), 3u); | ||||
206 | QSignalSpy desktopPresenceChangedSpy(client, &ShellClient::desktopPresenceChanged); | ||||
207 | QVERIFY(desktopPresenceChangedSpy.isValid()); | ||||
208 | | ||||
209 | QCOMPARE(client->desktops().count(), 1u); | ||||
210 | QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first()); | ||||
211 | | ||||
212 | //Set the window on desktop 2 as well | ||||
213 | client->setDesktop(2u); | ||||
214 | QCOMPARE(client->desktops().count(), 2u); | ||||
215 | QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]); | ||||
216 | QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[1]); | ||||
217 | QVERIFY(client->isOnDesktop(2)); | ||||
218 | QVERIFY(client->isOnDesktop(3)); | ||||
219 | | ||||
220 | //leave desktop 3 | ||||
221 | client->unSetDesktop(3); | ||||
222 | QCOMPARE(client->desktops().count(), 1u); | ||||
223 | //leave desktop 2 | ||||
224 | client->unSetDesktop(2); | ||||
225 | QCOMPARE(client->desktops().count(), 0u); | ||||
226 | //we should be on all desktops now | ||||
227 | QVERIFY(client->isOnAllDesktops()); | ||||
228 | //put on desktop 1 | ||||
229 | client->setDesktop(1); | ||||
230 | QVERIFY(client->isOnDesktop(1)); | ||||
231 | QVERIFY(!client->isOnDesktop(2)); | ||||
232 | QVERIFY(!client->isOnDesktop(3)); | ||||
233 | QCOMPARE(client->desktops().count(), 1u); | ||||
234 | //put on desktop 2 | ||||
235 | client->setDesktop(2); | ||||
236 | QVERIFY(client->isOnDesktop(1)); | ||||
237 | QVERIFY(client->isOnDesktop(2)); | ||||
238 | QVERIFY(!client->isOnDesktop(3)); | ||||
239 | QCOMPARE(client->desktops().count(), 2u); | ||||
240 | //put on desktop 3 | ||||
241 | client->setDesktop(3); | ||||
242 | QVERIFY(client->isOnDesktop(1)); | ||||
243 | QVERIFY(client->isOnDesktop(2)); | ||||
244 | QVERIFY(client->isOnDesktop(3)); | ||||
245 | QVERIFY(client->isOnAllDesktops()); | ||||
246 | //when it gets on all desktops, it loses all desktops() | ||||
247 | QCOMPARE(client->desktops().count(), 0u); | ||||
248 | } | ||||
249 | | ||||
250 | void VirtualDesktopTest::testRemoveDesktopWithWindow_data() | ||||
251 | { | ||||
252 | QTest::addColumn<Test::ShellSurfaceType>("type"); | ||||
253 | | ||||
254 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | ||||
255 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | ||||
256 | QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6; | ||||
257 | } | ||||
258 | | ||||
259 | void VirtualDesktopTest::testRemoveDesktopWithWindow() | ||||
260 | { | ||||
261 | // first create two new desktops | ||||
262 | QCOMPARE(VirtualDesktopManager::self()->count(), 1u); | ||||
263 | VirtualDesktopManager::self()->setCount(3); | ||||
264 | QCOMPARE(VirtualDesktopManager::self()->count(), 3u); | ||||
265 | | ||||
266 | // switch to last desktop | ||||
267 | VirtualDesktopManager::self()->setCurrent(VirtualDesktopManager::self()->desktops().last()); | ||||
268 | QCOMPARE(VirtualDesktopManager::self()->current(), 3u); | ||||
269 | | ||||
270 | // now create a window on this desktop | ||||
271 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
272 | QFETCH(Test::ShellSurfaceType, type); | ||||
273 | QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data())); | ||||
274 | auto client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
275 | | ||||
276 | QVERIFY(client); | ||||
277 | QCOMPARE(client->desktop(), 3u); | ||||
278 | QSignalSpy desktopPresenceChangedSpy(client, &ShellClient::desktopPresenceChanged); | ||||
279 | QVERIFY(desktopPresenceChangedSpy.isValid()); | ||||
280 | | ||||
281 | QCOMPARE(client->desktops().count(), 1u); | ||||
282 | QCOMPARE(VirtualDesktopManager::self()->currentDesktop(), client->desktops().first()); | ||||
283 | | ||||
284 | //Set the window on desktop 2 as well | ||||
285 | client->setDesktop(2u); | ||||
286 | QCOMPARE(client->desktops().count(), 2u); | ||||
287 | QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]); | ||||
288 | QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[1]); | ||||
289 | QVERIFY(client->isOnDesktop(2)); | ||||
290 | QVERIFY(client->isOnDesktop(3)); | ||||
291 | | ||||
292 | //remove desktop 3 | ||||
293 | VirtualDesktopManager::self()->setCount(2); | ||||
294 | QCOMPARE(client->desktops().count(), 1u); | ||||
295 | //window is only on desktop 2 | ||||
296 | QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[0]); | ||||
297 | | ||||
298 | //Again 3 desktops | ||||
299 | VirtualDesktopManager::self()->setCount(3); | ||||
300 | //move window to be only on desktop 3 | ||||
301 | client->setDesktop(3); | ||||
302 | client->unSetDesktop(2); | ||||
303 | QCOMPARE(client->desktops().count(), 1u); | ||||
304 | //window is only on desktop 3 | ||||
305 | QCOMPARE(VirtualDesktopManager::self()->desktops()[2], client->desktops()[0]); | ||||
306 | | ||||
307 | //remove desktop 3 | ||||
308 | VirtualDesktopManager::self()->setCount(2); | ||||
309 | QCOMPARE(client->desktops().count(), 1u); | ||||
310 | //window is only on desktop 2 | ||||
311 | QCOMPARE(VirtualDesktopManager::self()->desktops()[1], client->desktops()[0]); | ||||
166 | } | 312 | } | ||
167 | 313 | | |||
168 | WAYLANDTEST_MAIN(VirtualDesktopTest) | 314 | WAYLANDTEST_MAIN(VirtualDesktopTest) | ||
169 | #include "virtual_desktop_test.moc" | 315 | #include "virtual_desktop_test.moc" |