Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/plasmawindow_test.cpp
Show All 23 Lines | |||||
24 | #include "screenedge.h" | 24 | #include "screenedge.h" | ||
25 | #include "screens.h" | 25 | #include "screens.h" | ||
26 | #include "wayland_server.h" | 26 | #include "wayland_server.h" | ||
27 | #include "workspace.h" | 27 | #include "workspace.h" | ||
28 | #include "shell_client.h" | 28 | #include "shell_client.h" | ||
29 | #include <kwineffects.h> | 29 | #include <kwineffects.h> | ||
30 | 30 | | |||
31 | #include <KWayland/Client/compositor.h> | 31 | #include <KWayland/Client/compositor.h> | ||
32 | #include <KWayland/Client/connection_thread.h> | | |||
33 | #include <KWayland/Client/event_queue.h> | | |||
34 | #include <KWayland/Client/plasmawindowmanagement.h> | 32 | #include <KWayland/Client/plasmawindowmanagement.h> | ||
35 | #include <KWayland/Client/registry.h> | | |||
36 | #include <KWayland/Client/shell.h> | 33 | #include <KWayland/Client/shell.h> | ||
37 | #include <KWayland/Client/shm_pool.h> | | |||
38 | #include <KWayland/Client/surface.h> | 34 | #include <KWayland/Client/surface.h> | ||
39 | #include <KWayland/Server/seat_interface.h> | 35 | #include <KWayland/Server/seat_interface.h> | ||
40 | //screenlocker | 36 | //screenlocker | ||
41 | #include <KScreenLocker/KsldApp> | 37 | #include <KScreenLocker/KsldApp> | ||
42 | 38 | | |||
43 | #include <QPainter> | 39 | #include <QPainter> | ||
44 | #include <QRasterWindow> | 40 | #include <QRasterWindow> | ||
45 | 41 | | |||
Show All 16 Lines | 55 | private Q_SLOTS: | |||
62 | void cleanup(); | 58 | void cleanup(); | ||
63 | void testCreateDestroyX11PlasmaWindow(); | 59 | void testCreateDestroyX11PlasmaWindow(); | ||
64 | void testInternalWindowNoPlasmaWindow(); | 60 | void testInternalWindowNoPlasmaWindow(); | ||
65 | void testPopupWindowNoPlasmaWindow(); | 61 | void testPopupWindowNoPlasmaWindow(); | ||
66 | void testLockScreenNoPlasmaWindow(); | 62 | void testLockScreenNoPlasmaWindow(); | ||
67 | void testDestroyedButNotUnmapped(); | 63 | void testDestroyedButNotUnmapped(); | ||
68 | 64 | | |||
69 | private: | 65 | private: | ||
70 | ConnectionThread *m_connection = nullptr; | | |||
71 | PlasmaWindowManagement *m_windowManagement = nullptr; | 66 | PlasmaWindowManagement *m_windowManagement = nullptr; | ||
72 | KWayland::Client::Compositor *m_compositor = nullptr; | 67 | KWayland::Client::Compositor *m_compositor = nullptr; | ||
73 | Shell *m_shell = nullptr; | 68 | Shell *m_shell = nullptr; | ||
74 | ShmPool *m_shm = nullptr; | | |||
75 | EventQueue *m_queue = nullptr; | | |||
76 | QThread *m_thread = nullptr; | | |||
77 | }; | 69 | }; | ||
78 | 70 | | |||
79 | void PlasmaWindowTest::initTestCase() | 71 | void PlasmaWindowTest::initTestCase() | ||
80 | { | 72 | { | ||
81 | qRegisterMetaType<KWin::ShellClient*>(); | 73 | qRegisterMetaType<KWin::ShellClient*>(); | ||
82 | qRegisterMetaType<KWin::AbstractClient*>(); | 74 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
83 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 75 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
84 | QVERIFY(workspaceCreatedSpy.isValid()); | 76 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
85 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 77 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
86 | QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); | 78 | QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); | ||
87 | waylandServer()->init(s_socketName.toLocal8Bit()); | 79 | waylandServer()->init(s_socketName.toLocal8Bit()); | ||
88 | 80 | | |||
89 | kwinApp()->start(); | 81 | kwinApp()->start(); | ||
90 | QVERIFY(workspaceCreatedSpy.wait()); | 82 | QVERIFY(workspaceCreatedSpy.wait()); | ||
91 | QCOMPARE(screens()->count(), 2); | 83 | QCOMPARE(screens()->count(), 2); | ||
92 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | 84 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||
93 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 85 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
94 | setenv("QT_QPA_PLATFORM", "wayland", true); | 86 | setenv("QT_QPA_PLATFORM", "wayland", true); | ||
95 | setenv("QMLSCENE_DEVICE", "softwarecontext", true); | 87 | setenv("QMLSCENE_DEVICE", "softwarecontext", true); | ||
96 | waylandServer()->initWorkspace(); | 88 | waylandServer()->initWorkspace(); | ||
97 | } | 89 | } | ||
98 | 90 | | |||
99 | void PlasmaWindowTest::init() | 91 | void PlasmaWindowTest::init() | ||
100 | { | 92 | { | ||
101 | // setup connection | 93 | QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::WindowManagement)); | ||
102 | m_connection = new ConnectionThread; | 94 | m_windowManagement = Test::waylandWindowManagement(); | ||
103 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | 95 | m_compositor = Test::waylandCompositor(); | ||
104 | QVERIFY(connectedSpy.isValid()); | 96 | m_shell = Test::waylandShell(); | ||
105 | m_connection->setSocketName(s_socketName); | | |||
106 | | ||||
107 | m_thread = new QThread(this); | | |||
108 | m_connection->moveToThread(m_thread); | | |||
109 | m_thread->start(); | | |||
110 | | ||||
111 | m_connection->initConnection(); | | |||
112 | QVERIFY(connectedSpy.wait()); | | |||
113 | | ||||
114 | m_queue = new EventQueue(this); | | |||
115 | QVERIFY(!m_queue->isValid()); | | |||
116 | m_queue->setup(m_connection); | | |||
117 | QVERIFY(m_queue->isValid()); | | |||
118 | | ||||
119 | Registry registry; | | |||
120 | registry.setEventQueue(m_queue); | | |||
121 | QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); | | |||
122 | QVERIFY(allAnnounced.isValid()); | | |||
123 | registry.create(m_connection->display()); | | |||
124 | QVERIFY(registry.isValid()); | | |||
125 | registry.setup(); | | |||
126 | QVERIFY(allAnnounced.wait()); | | |||
127 | | ||||
128 | m_windowManagement = registry.createPlasmaWindowManagement(registry.interface(Registry::Interface::PlasmaWindowManagement).name, | | |||
129 | registry.interface(Registry::Interface::PlasmaWindowManagement).version, | | |||
130 | this); | | |||
131 | QVERIFY(m_windowManagement); | | |||
132 | m_compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, | | |||
133 | registry.interface(Registry::Interface::Compositor).version, | | |||
134 | this); | | |||
135 | QVERIFY(m_compositor); | | |||
136 | m_shm = registry.createShmPool(registry.interface(Registry::Interface::Shm).name, | | |||
137 | registry.interface(Registry::Interface::Shm).version, | | |||
138 | this); | | |||
139 | QVERIFY(m_shm); | | |||
140 | m_shell = registry.createShell(registry.interface(Registry::Interface::Shell).name, | | |||
141 | registry.interface(Registry::Interface::Shell).version, | | |||
142 | this); | | |||
143 | QVERIFY(m_shell); | | |||
144 | 97 | | |||
145 | screens()->setCurrent(0); | 98 | screens()->setCurrent(0); | ||
146 | Cursor::setPos(QPoint(640, 512)); | 99 | Cursor::setPos(QPoint(640, 512)); | ||
147 | } | 100 | } | ||
148 | 101 | | |||
149 | void PlasmaWindowTest::cleanup() | 102 | void PlasmaWindowTest::cleanup() | ||
150 | { | 103 | { | ||
151 | #define CLEANUP(name) \ | 104 | Test::destroyWaylandConnection(); | ||
152 | if (name) { \ | | |||
153 | delete name; \ | | |||
154 | name = nullptr; \ | | |||
155 | } | | |||
156 | CLEANUP(m_windowManagement) | | |||
157 | CLEANUP(m_shm) | | |||
158 | CLEANUP(m_shell) | | |||
159 | CLEANUP(m_compositor) | | |||
160 | CLEANUP(m_queue) | | |||
161 | #undef CLEANUP | | |||
162 | if (m_connection) { | | |||
163 | m_connection->deleteLater(); | | |||
164 | m_connection = nullptr; | | |||
165 | } | | |||
166 | if (m_thread) { | | |||
167 | m_thread->quit(); | | |||
168 | m_thread->wait(); | | |||
169 | delete m_thread; | | |||
170 | m_thread = nullptr; | | |||
171 | } | | |||
172 | } | 105 | } | ||
173 | 106 | | |||
174 | void PlasmaWindowTest::testCreateDestroyX11PlasmaWindow() | 107 | void PlasmaWindowTest::testCreateDestroyX11PlasmaWindow() | ||
175 | { | 108 | { | ||
176 | // this test verifies that a PlasmaWindow gets unmapped on Client side when an X11 client is destroyed | 109 | // this test verifies that a PlasmaWindow gets unmapped on Client side when an X11 client is destroyed | ||
177 | QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated); | 110 | QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated); | ||
178 | QVERIFY(plasmaWindowCreatedSpy.isValid()); | 111 | QVERIFY(plasmaWindowCreatedSpy.isValid()); | ||
179 | 112 | | |||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | |||||
299 | 232 | | |||
300 | void PlasmaWindowTest::testPopupWindowNoPlasmaWindow() | 233 | void PlasmaWindowTest::testPopupWindowNoPlasmaWindow() | ||
301 | { | 234 | { | ||
302 | // this test verifies that for a popup window no PlasmaWindow is sent to the client | 235 | // this test verifies that for a popup window no PlasmaWindow is sent to the client | ||
303 | QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated); | 236 | QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated); | ||
304 | QVERIFY(plasmaWindowCreatedSpy.isValid()); | 237 | QVERIFY(plasmaWindowCreatedSpy.isValid()); | ||
305 | 238 | | |||
306 | // first create the parent window | 239 | // first create the parent window | ||
307 | QScopedPointer<Surface> parentSurface(m_compositor->createSurface()); | 240 | QScopedPointer<Surface> parentSurface(Test::createSurface()); | ||
308 | QScopedPointer<ShellSurface> parentShellSurface(m_shell->createSurface(parentSurface.data())); | 241 | QScopedPointer<ShellSurface> parentShellSurface(Test::createShellSurface(parentSurface.data())); | ||
309 | // map that window | 242 | // map that window | ||
310 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 243 | Test::render(parentSurface.data(), QSize(100, 50), Qt::blue); | ||
311 | img.fill(Qt::blue); | | |||
312 | parentSurface->attachBuffer(m_shm->createBuffer(img)); | | |||
313 | parentSurface->damage(QRect(0, 0, 100, 50)); | | |||
314 | parentSurface->commit(); | | |||
315 | // this should create a plasma window | 244 | // this should create a plasma window | ||
316 | QVERIFY(plasmaWindowCreatedSpy.wait()); | 245 | QVERIFY(plasmaWindowCreatedSpy.wait()); | ||
317 | 246 | | |||
318 | // now let's create a popup window for it | 247 | // now let's create a popup window for it | ||
319 | QScopedPointer<Surface> popupSurface(m_compositor->createSurface()); | 248 | QScopedPointer<Surface> popupSurface(Test::createSurface()); | ||
320 | QScopedPointer<ShellSurface> popupShellSurface(m_shell->createSurface(popupSurface.data())); | 249 | QScopedPointer<ShellSurface> popupShellSurface(Test::createShellSurface(popupSurface.data())); | ||
321 | popupShellSurface->setTransient(parentSurface.data(), QPoint(0, 0), ShellSurface::TransientFlag::NoFocus); | 250 | popupShellSurface->setTransient(parentSurface.data(), QPoint(0, 0), ShellSurface::TransientFlag::NoFocus); | ||
322 | // let's map it | 251 | // let's map it | ||
323 | popupSurface->attachBuffer(m_shm->createBuffer(img)); | 252 | Test::render(popupSurface.data(), QSize(100, 50), Qt::blue); | ||
324 | popupSurface->damage(QRect(0, 0, 100, 50)); | | |||
325 | popupSurface->commit(); | | |||
326 | 253 | | |||
327 | // this should not create a plasma window | 254 | // this should not create a plasma window | ||
328 | QVERIFY(!plasmaWindowCreatedSpy.wait()); | 255 | QVERIFY(!plasmaWindowCreatedSpy.wait()); | ||
329 | 256 | | |||
330 | // now the same with an already mapped surface when we create the shell surface | 257 | // now the same with an already mapped surface when we create the shell surface | ||
331 | QScopedPointer<Surface> popup2Surface(m_compositor->createSurface()); | 258 | QScopedPointer<Surface> popup2Surface(Test::createSurface()); | ||
332 | popup2Surface->attachBuffer(m_shm->createBuffer(img)); | 259 | Test::render(popup2Surface.data(), QSize(100, 50), Qt::blue); | ||
333 | popup2Surface->damage(QRect(0, 0, 100, 50)); | 260 | QScopedPointer<ShellSurface> popup2ShellSurface(Test::createShellSurface(popup2Surface.data())); | ||
334 | popup2Surface->commit(); | | |||
335 | QScopedPointer<ShellSurface> popup2ShellSurface(m_shell->createSurface(popup2Surface.data())); | | |||
336 | popup2ShellSurface->setTransient(popupSurface.data(), QPoint(0, 0), ShellSurface::TransientFlag::NoFocus); | 261 | popup2ShellSurface->setTransient(popupSurface.data(), QPoint(0, 0), ShellSurface::TransientFlag::NoFocus); | ||
337 | 262 | | |||
338 | // this should not create a plasma window | 263 | // this should not create a plasma window | ||
339 | QEXPECT_FAIL("", "The call to setTransient comes to late the window is already mapped then", Continue); | 264 | QEXPECT_FAIL("", "The call to setTransient comes to late the window is already mapped then", Continue); | ||
340 | QVERIFY(!plasmaWindowCreatedSpy.wait()); | 265 | QVERIFY(!plasmaWindowCreatedSpy.wait()); | ||
341 | 266 | | |||
342 | // let's destroy the windows | 267 | // let's destroy the windows | ||
343 | QCOMPARE(waylandServer()->clients().count(), 3); | 268 | QCOMPARE(waylandServer()->clients().count(), 3); | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
404 | void PlasmaWindowTest::testDestroyedButNotUnmapped() | 329 | void PlasmaWindowTest::testDestroyedButNotUnmapped() | ||
405 | { | 330 | { | ||
406 | // this test verifies that also when a ShellSurface gets destroyed without a prior unmap | 331 | // this test verifies that also when a ShellSurface gets destroyed without a prior unmap | ||
407 | // the PlasmaWindow gets destroyed on Client side | 332 | // the PlasmaWindow gets destroyed on Client side | ||
408 | QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated); | 333 | QSignalSpy plasmaWindowCreatedSpy(m_windowManagement, &PlasmaWindowManagement::windowCreated); | ||
409 | QVERIFY(plasmaWindowCreatedSpy.isValid()); | 334 | QVERIFY(plasmaWindowCreatedSpy.isValid()); | ||
410 | 335 | | |||
411 | // first create the parent window | 336 | // first create the parent window | ||
412 | QScopedPointer<Surface> parentSurface(m_compositor->createSurface()); | 337 | QScopedPointer<Surface> parentSurface(Test::createSurface()); | ||
413 | QScopedPointer<ShellSurface> parentShellSurface(m_shell->createSurface(parentSurface.data())); | 338 | QScopedPointer<ShellSurface> parentShellSurface(Test::createShellSurface(parentSurface.data())); | ||
414 | // map that window | 339 | // map that window | ||
415 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 340 | Test::render(parentSurface.data(), QSize(100, 50), Qt::blue); | ||
416 | img.fill(Qt::blue); | | |||
417 | parentSurface->attachBuffer(m_shm->createBuffer(img)); | | |||
418 | parentSurface->damage(QRect(0, 0, 100, 50)); | | |||
419 | parentSurface->commit(); | | |||
420 | // this should create a plasma window | 341 | // this should create a plasma window | ||
421 | QVERIFY(plasmaWindowCreatedSpy.wait()); | 342 | QVERIFY(plasmaWindowCreatedSpy.wait()); | ||
422 | QCOMPARE(plasmaWindowCreatedSpy.count(), 1); | 343 | QCOMPARE(plasmaWindowCreatedSpy.count(), 1); | ||
423 | auto window = plasmaWindowCreatedSpy.first().first().value<PlasmaWindow*>(); | 344 | auto window = plasmaWindowCreatedSpy.first().first().value<PlasmaWindow*>(); | ||
424 | QVERIFY(window); | 345 | QVERIFY(window); | ||
425 | QSignalSpy destroyedSpy(window, &QObject::destroyed); | 346 | QSignalSpy destroyedSpy(window, &QObject::destroyed); | ||
426 | QVERIFY(destroyedSpy.isValid()); | 347 | QVERIFY(destroyedSpy.isValid()); | ||
427 | 348 | | |||
Show All 10 Lines |