File indexing completed on 2024-11-10 04:56:15
0001 /* 0002 SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 // Qt 0007 #include <QSignalSpy> 0008 #include <QTest> 0009 // KWin 0010 #include "wayland/compositor.h" 0011 #include "wayland/display.h" 0012 #include "wayland/plasmavirtualdesktop.h" 0013 #include "wayland/plasmawindowmanagement.h" 0014 0015 #include "KWayland/Client/compositor.h" 0016 #include "KWayland/Client/connection_thread.h" 0017 #include "KWayland/Client/event_queue.h" 0018 #include "KWayland/Client/plasmavirtualdesktop.h" 0019 #include "KWayland/Client/plasmawindowmanagement.h" 0020 #include "KWayland/Client/region.h" 0021 #include "KWayland/Client/registry.h" 0022 #include "KWayland/Client/surface.h" 0023 0024 class TestVirtualDesktop : public QObject 0025 { 0026 Q_OBJECT 0027 public: 0028 explicit TestVirtualDesktop(QObject *parent = nullptr); 0029 private Q_SLOTS: 0030 void init(); 0031 void cleanup(); 0032 0033 void testCreate(); 0034 void testSetRows(); 0035 void testConnectNewClient(); 0036 void testDestroy(); 0037 void testActivate(); 0038 0039 void testEnterLeaveDesktop(); 0040 void testAllDesktops(); 0041 void testCreateRequested(); 0042 void testRemoveRequested(); 0043 0044 private: 0045 KWin::Display *m_display; 0046 KWin::CompositorInterface *m_compositorInterface; 0047 KWin::PlasmaVirtualDesktopManagementInterface *m_plasmaVirtualDesktopManagementInterface; 0048 KWin::PlasmaWindowManagementInterface *m_windowManagementInterface; 0049 KWin::PlasmaWindowInterface *m_windowInterface; 0050 0051 KWayland::Client::ConnectionThread *m_connection; 0052 KWayland::Client::Compositor *m_compositor; 0053 KWayland::Client::PlasmaVirtualDesktopManagement *m_plasmaVirtualDesktopManagement; 0054 KWayland::Client::EventQueue *m_queue; 0055 KWayland::Client::PlasmaWindowManagement *m_windowManagement; 0056 KWayland::Client::PlasmaWindow *m_window; 0057 0058 QThread *m_thread; 0059 }; 0060 0061 static const QString s_socketName = QStringLiteral("kwayland-test-wayland-virtual-desktop-0"); 0062 0063 TestVirtualDesktop::TestVirtualDesktop(QObject *parent) 0064 : QObject(parent) 0065 , m_display(nullptr) 0066 , m_compositorInterface(nullptr) 0067 , m_connection(nullptr) 0068 , m_compositor(nullptr) 0069 , m_queue(nullptr) 0070 , m_thread(nullptr) 0071 { 0072 } 0073 0074 void TestVirtualDesktop::init() 0075 { 0076 using namespace KWin; 0077 delete m_display; 0078 m_display = new KWin::Display(this); 0079 m_display->addSocketName(s_socketName); 0080 m_display->start(); 0081 QVERIFY(m_display->isRunning()); 0082 0083 // setup connection 0084 m_connection = new KWayland::Client::ConnectionThread; 0085 QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected); 0086 m_connection->setSocketName(s_socketName); 0087 0088 m_thread = new QThread(this); 0089 m_connection->moveToThread(m_thread); 0090 m_thread->start(); 0091 0092 m_connection->initConnection(); 0093 QVERIFY(connectedSpy.wait()); 0094 0095 m_queue = new KWayland::Client::EventQueue(this); 0096 QVERIFY(!m_queue->isValid()); 0097 m_queue->setup(m_connection); 0098 QVERIFY(m_queue->isValid()); 0099 0100 KWayland::Client::Registry registry; 0101 QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced); 0102 0103 QSignalSpy plasmaVirtualDesktopManagementSpy(®istry, &KWayland::Client::Registry::plasmaVirtualDesktopManagementAnnounced); 0104 0105 QSignalSpy windowManagementSpy(®istry, &KWayland::Client::Registry::plasmaWindowManagementAnnounced); 0106 0107 QVERIFY(!registry.eventQueue()); 0108 registry.setEventQueue(m_queue); 0109 QCOMPARE(registry.eventQueue(), m_queue); 0110 registry.create(m_connection->display()); 0111 QVERIFY(registry.isValid()); 0112 registry.setup(); 0113 0114 m_compositorInterface = new CompositorInterface(m_display, m_display); 0115 QVERIFY(compositorSpy.wait()); 0116 m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); 0117 0118 m_plasmaVirtualDesktopManagementInterface = new PlasmaVirtualDesktopManagementInterface(m_display, m_display); 0119 0120 QVERIFY(plasmaVirtualDesktopManagementSpy.wait()); 0121 m_plasmaVirtualDesktopManagement = registry.createPlasmaVirtualDesktopManagement(plasmaVirtualDesktopManagementSpy.first().first().value<quint32>(), 0122 plasmaVirtualDesktopManagementSpy.first().last().value<quint32>(), 0123 this); 0124 0125 m_windowManagementInterface = new PlasmaWindowManagementInterface(m_display, m_display); 0126 m_windowManagementInterface->setPlasmaVirtualDesktopManagementInterface(m_plasmaVirtualDesktopManagementInterface); 0127 0128 QVERIFY(windowManagementSpy.wait()); 0129 m_windowManagement = 0130 registry.createPlasmaWindowManagement(windowManagementSpy.first().first().value<quint32>(), windowManagementSpy.first().last().value<quint32>(), this); 0131 0132 QSignalSpy windowSpy(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated); 0133 m_windowInterface = m_windowManagementInterface->createWindow(this, QUuid::createUuid()); 0134 m_windowInterface->setPid(1337); 0135 0136 QVERIFY(windowSpy.wait()); 0137 m_window = windowSpy.first().first().value<KWayland::Client::PlasmaWindow *>(); 0138 } 0139 0140 void TestVirtualDesktop::cleanup() 0141 { 0142 #define CLEANUP(variable) \ 0143 if (variable) { \ 0144 delete variable; \ 0145 variable = nullptr; \ 0146 } 0147 CLEANUP(m_compositor) 0148 CLEANUP(m_plasmaVirtualDesktopManagement) 0149 CLEANUP(m_windowInterface) 0150 CLEANUP(m_windowManagement) 0151 CLEANUP(m_queue) 0152 if (m_connection) { 0153 m_connection->deleteLater(); 0154 m_connection = nullptr; 0155 } 0156 if (m_thread) { 0157 m_thread->quit(); 0158 m_thread->wait(); 0159 delete m_thread; 0160 m_thread = nullptr; 0161 } 0162 CLEANUP(m_compositorInterface) 0163 CLEANUP(m_plasmaVirtualDesktopManagementInterface) 0164 CLEANUP(m_windowManagementInterface) 0165 CLEANUP(m_display) 0166 #undef CLEANUP 0167 } 0168 0169 void TestVirtualDesktop::testCreate() 0170 { 0171 QSignalSpy desktopCreatedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated); 0172 QSignalSpy managementDoneSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::done); 0173 0174 // on this createDesktop bind() isn't called already, the desktopadded signals will be sent after bind happened 0175 KWin::PlasmaVirtualDesktopInterface *desktop1Int = m_plasmaVirtualDesktopManagementInterface->createDesktop(QStringLiteral("0-1")); 0176 desktop1Int->setName("Desktop 1"); 0177 0178 QVERIFY(desktopCreatedSpy.wait()); 0179 QList<QVariant> arguments = desktopCreatedSpy.takeFirst(); 0180 QCOMPARE(arguments.at(0).toString(), QStringLiteral("0-1")); 0181 QCOMPARE(arguments.at(1).toUInt(), (quint32)0); 0182 m_plasmaVirtualDesktopManagementInterface->sendDone(); 0183 QVERIFY(managementDoneSpy.wait()); 0184 0185 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 1); 0186 0187 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first(); 0188 QSignalSpy desktop1DoneSpy(desktop1, &KWayland::Client::PlasmaVirtualDesktop::done); 0189 desktop1Int->sendDone(); 0190 QVERIFY(desktop1DoneSpy.wait()); 0191 0192 QCOMPARE(desktop1->id(), QStringLiteral("0-1")); 0193 QCOMPARE(desktop1->name(), QStringLiteral("Desktop 1")); 0194 0195 // on those createDesktop the bind will already be done 0196 KWin::PlasmaVirtualDesktopInterface *desktop2Int = m_plasmaVirtualDesktopManagementInterface->createDesktop(QStringLiteral("0-2")); 0197 desktop2Int->setName("Desktop 2"); 0198 QVERIFY(desktopCreatedSpy.wait()); 0199 arguments = desktopCreatedSpy.takeFirst(); 0200 QCOMPARE(arguments.at(0).toString(), QStringLiteral("0-2")); 0201 QCOMPARE(arguments.at(1).toUInt(), (quint32)1); 0202 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 2); 0203 0204 KWin::PlasmaVirtualDesktopInterface *desktop3Int = m_plasmaVirtualDesktopManagementInterface->createDesktop(QStringLiteral("0-3")); 0205 desktop3Int->setName("Desktop 3"); 0206 QVERIFY(desktopCreatedSpy.wait()); 0207 arguments = desktopCreatedSpy.takeFirst(); 0208 QCOMPARE(arguments.at(0).toString(), QStringLiteral("0-3")); 0209 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 3); 0210 0211 m_plasmaVirtualDesktopManagementInterface->sendDone(); 0212 QVERIFY(managementDoneSpy.wait()); 0213 0214 // get the clients 0215 KWayland::Client::PlasmaVirtualDesktop *desktop2 = m_plasmaVirtualDesktopManagement->desktops()[1]; 0216 QSignalSpy desktop2DoneSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::done); 0217 desktop2Int->sendDone(); 0218 QVERIFY(desktop2DoneSpy.wait()); 0219 0220 KWayland::Client::PlasmaVirtualDesktop *desktop3 = m_plasmaVirtualDesktopManagement->desktops()[2]; 0221 QSignalSpy desktop3DoneSpy(desktop3, &KWayland::Client::PlasmaVirtualDesktop::done); 0222 desktop3Int->sendDone(); 0223 QVERIFY(desktop3DoneSpy.wait()); 0224 0225 QCOMPARE(desktop1->id(), QStringLiteral("0-1")); 0226 QCOMPARE(desktop1->name(), QStringLiteral("Desktop 1")); 0227 0228 QCOMPARE(desktop2->id(), QStringLiteral("0-2")); 0229 QCOMPARE(desktop2->name(), QStringLiteral("Desktop 2")); 0230 0231 QCOMPARE(desktop3->id(), QStringLiteral("0-3")); 0232 QCOMPARE(desktop3->name(), QStringLiteral("Desktop 3")); 0233 0234 // coherence of order between client and server 0235 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().length(), 3); 0236 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 3); 0237 0238 for (int i = 0; i < m_plasmaVirtualDesktopManagement->desktops().length(); ++i) { 0239 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().at(i)->id(), m_plasmaVirtualDesktopManagement->desktops().at(i)->id()); 0240 } 0241 } 0242 0243 void TestVirtualDesktop::testSetRows() 0244 { 0245 // rebuild some desktops 0246 testCreate(); 0247 0248 QSignalSpy rowsChangedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::rowsChanged); 0249 0250 m_plasmaVirtualDesktopManagementInterface->setRows(3); 0251 QVERIFY(rowsChangedSpy.wait()); 0252 QCOMPARE(m_plasmaVirtualDesktopManagement->rows(), 3); 0253 } 0254 0255 void TestVirtualDesktop::testConnectNewClient() 0256 { 0257 // rebuild some desktops 0258 testCreate(); 0259 0260 KWayland::Client::Registry registry; 0261 QVERIFY(!registry.eventQueue()); 0262 registry.setEventQueue(m_queue); 0263 QCOMPARE(registry.eventQueue(), m_queue); 0264 registry.create(m_connection->display()); 0265 QVERIFY(registry.isValid()); 0266 registry.setup(); 0267 0268 QSignalSpy plasmaVirtualDesktopManagementSpy(®istry, &KWayland::Client::Registry::plasmaVirtualDesktopManagementAnnounced); 0269 0270 QVERIFY(plasmaVirtualDesktopManagementSpy.wait()); 0271 0272 KWayland::Client::PlasmaVirtualDesktopManagement *otherPlasmaVirtualDesktopManagement = 0273 registry.createPlasmaVirtualDesktopManagement(plasmaVirtualDesktopManagementSpy.first().first().value<quint32>(), 0274 plasmaVirtualDesktopManagementSpy.first().last().value<quint32>(), 0275 this); 0276 0277 QSignalSpy managementDoneSpy(otherPlasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::done); 0278 0279 QVERIFY(managementDoneSpy.wait()); 0280 QCOMPARE(otherPlasmaVirtualDesktopManagement->desktops().length(), 3); 0281 0282 delete otherPlasmaVirtualDesktopManagement; 0283 } 0284 0285 void TestVirtualDesktop::testDestroy() 0286 { 0287 // rebuild some desktops 0288 testCreate(); 0289 0290 KWin::PlasmaVirtualDesktopInterface *desktop1Int = m_plasmaVirtualDesktopManagementInterface->desktops().first(); 0291 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first(); 0292 0293 QSignalSpy desktop1IntDestroyedSpy(desktop1Int, &QObject::destroyed); 0294 QSignalSpy desktop1DestroyedSpy(desktop1, &QObject::destroyed); 0295 QSignalSpy desktop1RemovedSpy(desktop1, &KWayland::Client::PlasmaVirtualDesktop::removed); 0296 m_plasmaVirtualDesktopManagementInterface->removeDesktop(QStringLiteral("0-1")); 0297 0298 // test that both server and client desktoip interfaces go away 0299 QVERIFY(!desktop1IntDestroyedSpy.isEmpty()); 0300 QVERIFY(desktop1RemovedSpy.wait()); 0301 QVERIFY(desktop1DestroyedSpy.wait()); 0302 0303 // coherence of order between client and server 0304 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().length(), 2); 0305 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 2); 0306 0307 for (int i = 0; i < m_plasmaVirtualDesktopManagement->desktops().length(); ++i) { 0308 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().at(i)->id(), m_plasmaVirtualDesktopManagement->desktops().at(i)->id()); 0309 } 0310 0311 // Test the desktopRemoved signal of the manager, remove another desktop as the signals can't be tested at the same time 0312 QSignalSpy desktopManagerRemovedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopRemoved); 0313 m_plasmaVirtualDesktopManagementInterface->removeDesktop(QStringLiteral("0-2")); 0314 QVERIFY(desktopManagerRemovedSpy.wait()); 0315 QCOMPARE(desktopManagerRemovedSpy.takeFirst().at(0).toString(), QStringLiteral("0-2")); 0316 0317 QCOMPARE(m_plasmaVirtualDesktopManagementInterface->desktops().length(), 1); 0318 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().length(), 1); 0319 } 0320 0321 void TestVirtualDesktop::testActivate() 0322 { 0323 // rebuild some desktops 0324 testCreate(); 0325 0326 KWin::PlasmaVirtualDesktopInterface *desktop1Int = m_plasmaVirtualDesktopManagementInterface->desktops().first(); 0327 KWayland::Client::PlasmaVirtualDesktop *desktop1 = m_plasmaVirtualDesktopManagement->desktops().first(); 0328 QVERIFY(desktop1->isActive()); 0329 QVERIFY(desktop1Int->isActive()); 0330 0331 KWin::PlasmaVirtualDesktopInterface *desktop2Int = m_plasmaVirtualDesktopManagementInterface->desktops()[1]; 0332 KWayland::Client::PlasmaVirtualDesktop *desktop2 = m_plasmaVirtualDesktopManagement->desktops()[1]; 0333 QVERIFY(!desktop2Int->isActive()); 0334 0335 QSignalSpy requestActivateSpy(desktop2Int, &KWin::PlasmaVirtualDesktopInterface::activateRequested); 0336 QSignalSpy activatedSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::activated); 0337 0338 desktop2->requestActivate(); 0339 QVERIFY(requestActivateSpy.wait()); 0340 0341 // This simulates a compositor which supports only one active desktop at a time 0342 for (auto *deskInt : m_plasmaVirtualDesktopManagementInterface->desktops()) { 0343 if (deskInt->id() == desktop2->id()) { 0344 deskInt->setActive(true); 0345 } else { 0346 deskInt->setActive(false); 0347 } 0348 } 0349 QVERIFY(activatedSpy.wait()); 0350 0351 // correct state in the server 0352 QVERIFY(desktop2Int->isActive()); 0353 QVERIFY(!desktop1Int->isActive()); 0354 // correct state in the client 0355 QVERIFY(desktop2Int->isActive()); 0356 QVERIFY(!desktop1Int->isActive()); 0357 0358 // Test the deactivated signal 0359 QSignalSpy deactivatedSpy(desktop2, &KWayland::Client::PlasmaVirtualDesktop::deactivated); 0360 0361 for (auto *deskInt : m_plasmaVirtualDesktopManagementInterface->desktops()) { 0362 if (deskInt->id() == desktop1->id()) { 0363 deskInt->setActive(true); 0364 } else { 0365 deskInt->setActive(false); 0366 } 0367 } 0368 QVERIFY(deactivatedSpy.wait()); 0369 } 0370 0371 void TestVirtualDesktop::testEnterLeaveDesktop() 0372 { 0373 testCreate(); 0374 0375 QSignalSpy enterRequestedSpy(m_windowInterface, &KWin::PlasmaWindowInterface::enterPlasmaVirtualDesktopRequested); 0376 m_window->requestEnterVirtualDesktop(QStringLiteral("0-1")); 0377 QVERIFY(enterRequestedSpy.wait()); 0378 0379 QCOMPARE(enterRequestedSpy.takeFirst().at(0).toString(), QStringLiteral("0-1")); 0380 0381 QSignalSpy virtualDesktopEnteredSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopEntered); 0382 0383 // agree to the request 0384 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-1")); 0385 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().length(), 1); 0386 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().first(), QStringLiteral("0-1")); 0387 0388 // check if the client received the enter 0389 QVERIFY(virtualDesktopEnteredSpy.wait()); 0390 QCOMPARE(virtualDesktopEnteredSpy.takeFirst().at(0).toString(), QStringLiteral("0-1")); 0391 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 1); 0392 QCOMPARE(m_window->plasmaVirtualDesktops().first(), QStringLiteral("0-1")); 0393 0394 // add another desktop, server side 0395 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-3")); 0396 QVERIFY(virtualDesktopEnteredSpy.wait()); 0397 QCOMPARE(virtualDesktopEnteredSpy.takeFirst().at(0).toString(), QStringLiteral("0-3")); 0398 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().length(), 2); 0399 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2); 0400 QCOMPARE(m_window->plasmaVirtualDesktops()[1], QStringLiteral("0-3")); 0401 0402 // try to add an invalid desktop 0403 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("invalid")); 0404 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2); 0405 0406 // remove a desktop 0407 QSignalSpy leaveRequestedSpy(m_windowInterface, &KWin::PlasmaWindowInterface::leavePlasmaVirtualDesktopRequested); 0408 m_window->requestLeaveVirtualDesktop(QStringLiteral("0-1")); 0409 QVERIFY(leaveRequestedSpy.wait()); 0410 0411 QCOMPARE(leaveRequestedSpy.takeFirst().at(0).toString(), QStringLiteral("0-1")); 0412 0413 QSignalSpy virtualDesktopLeftSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopLeft); 0414 0415 // agree to the request 0416 m_windowInterface->removePlasmaVirtualDesktop(QStringLiteral("0-1")); 0417 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().length(), 1); 0418 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().first(), QStringLiteral("0-3")); 0419 0420 // check if the client received the leave 0421 QVERIFY(virtualDesktopLeftSpy.wait()); 0422 QCOMPARE(virtualDesktopLeftSpy.takeFirst().at(0).toString(), QStringLiteral("0-1")); 0423 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 1); 0424 QCOMPARE(m_window->plasmaVirtualDesktops().first(), QStringLiteral("0-3")); 0425 0426 // Destroy desktop 2 0427 m_plasmaVirtualDesktopManagementInterface->removeDesktop(QStringLiteral("0-3")); 0428 // the window should receive a left signal from the destroyed desktop 0429 QVERIFY(virtualDesktopLeftSpy.wait()); 0430 0431 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0); 0432 } 0433 0434 void TestVirtualDesktop::testAllDesktops() 0435 { 0436 testCreate(); 0437 QSignalSpy virtualDesktopEnteredSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopEntered); 0438 QSignalSpy virtualDesktopLeftSpy(m_window, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopLeft); 0439 0440 // in the beginning the window is on desktop 1 and desktop 3 0441 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-1")); 0442 m_windowInterface->addPlasmaVirtualDesktop(QStringLiteral("0-3")); 0443 QVERIFY(virtualDesktopEnteredSpy.wait()); 0444 0445 // setting on all desktops 0446 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 2); 0447 m_windowInterface->setOnAllDesktops(true); 0448 // setting on all desktops, the window will leave every desktop 0449 0450 QVERIFY(virtualDesktopLeftSpy.wait()); 0451 QCOMPARE(virtualDesktopLeftSpy.count(), 2); 0452 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0); 0453 QVERIFY(m_window->isOnAllDesktops()); 0454 0455 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 0); 0456 QVERIFY(m_window->isOnAllDesktops()); 0457 0458 // return to the active desktop (0-1) 0459 m_windowInterface->setOnAllDesktops(false); 0460 QVERIFY(virtualDesktopEnteredSpy.wait()); 0461 QCOMPARE(m_window->plasmaVirtualDesktops().length(), 1); 0462 QCOMPARE(m_windowInterface->plasmaVirtualDesktops().first(), QStringLiteral("0-1")); 0463 QVERIFY(!m_window->isOnAllDesktops()); 0464 } 0465 0466 void TestVirtualDesktop::testCreateRequested() 0467 { 0468 // rebuild some desktops 0469 testCreate(); 0470 0471 QSignalSpy desktopCreateRequestedSpy(m_plasmaVirtualDesktopManagementInterface, 0472 &KWin::PlasmaVirtualDesktopManagementInterface::desktopCreateRequested); 0473 QSignalSpy desktopCreatedSpy(m_plasmaVirtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated); 0474 0475 // listen for createdRequested 0476 m_plasmaVirtualDesktopManagement->requestCreateVirtualDesktop(QStringLiteral("Desktop"), 1); 0477 QVERIFY(desktopCreateRequestedSpy.wait()); 0478 QCOMPARE(desktopCreateRequestedSpy.first().first().toString(), QStringLiteral("Desktop")); 0479 QCOMPARE(desktopCreateRequestedSpy.first().at(1).toUInt(), (quint32)1); 0480 0481 // actually create 0482 m_plasmaVirtualDesktopManagementInterface->createDesktop(QStringLiteral("0-4"), 1); 0483 KWin::PlasmaVirtualDesktopInterface *desktopInt = m_plasmaVirtualDesktopManagementInterface->desktops().at(1); 0484 0485 QCOMPARE(desktopInt->id(), QStringLiteral("0-4")); 0486 desktopInt->setName(QStringLiteral("Desktop")); 0487 0488 QVERIFY(desktopCreatedSpy.wait()); 0489 0490 QCOMPARE(desktopCreatedSpy.first().first().toString(), QStringLiteral("0-4")); 0491 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().count(), 4); 0492 0493 KWayland::Client::PlasmaVirtualDesktop *desktop = m_plasmaVirtualDesktopManagement->desktops().at(1); 0494 QSignalSpy desktopDoneSpy(desktop, &KWayland::Client::PlasmaVirtualDesktop::done); 0495 desktopInt->sendDone(); 0496 // desktopDoneSpy.wait(); 0497 // check the order is correct 0498 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().at(0)->id(), QStringLiteral("0-1")); 0499 QCOMPARE(desktop->id(), QStringLiteral("0-4")); 0500 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().at(2)->id(), QStringLiteral("0-2")); 0501 QCOMPARE(m_plasmaVirtualDesktopManagement->desktops().at(3)->id(), QStringLiteral("0-3")); 0502 } 0503 0504 void TestVirtualDesktop::testRemoveRequested() 0505 { 0506 // rebuild some desktops 0507 testCreate(); 0508 0509 QSignalSpy desktopRemoveRequestedSpy(m_plasmaVirtualDesktopManagementInterface, 0510 &KWin::PlasmaVirtualDesktopManagementInterface::desktopRemoveRequested); 0511 0512 // request a remove, just check the request arrived, ignore the request. 0513 m_plasmaVirtualDesktopManagement->requestRemoveVirtualDesktop(QStringLiteral("0-1")); 0514 QVERIFY(desktopRemoveRequestedSpy.wait()); 0515 QCOMPARE(desktopRemoveRequestedSpy.first().first().toString(), QStringLiteral("0-1")); 0516 } 0517 0518 QTEST_GUILESS_MAIN(TestVirtualDesktop) 0519 #include "test_plasma_virtual_desktop.moc"