14#include "KWayland/Client/compositor.h"
15#include "KWayland/Client/connection_thread.h"
16#include "KWayland/Client/event_queue.h"
17#include "KWayland/Client/plasmashell.h"
18#include "KWayland/Client/registry.h"
19#include "KWayland/Client/surface.h"
33 void testSkipTaskbar();
34 void testSkipSwitcher();
35 void testPanelBehavior_data();
36 void testPanelBehavior();
37 void testAutoHidePanel();
38 void testPanelTakesFocus();
39 void testDisconnect();
40 void testWhileDestroying();
47 KWayland::Client::ConnectionThread *m_connection =
nullptr;
48 KWayland::Client::Compositor *m_compositor =
nullptr;
49 KWayland::Client::EventQueue *m_queue =
nullptr;
50 QThread *m_thread =
nullptr;
51 KWayland::Client::Registry *m_registry =
nullptr;
52 KWayland::Client::PlasmaShell *m_plasmaShell =
nullptr;
55static const QString s_socketName = QStringLiteral(
"kwayland-test-wayland-plasma-shell-0");
57void TestPlasmaShell::init()
71 m_connection =
new KWayland::Client::ConnectionThread;
72 QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
73 m_connection->setSocketName(s_socketName);
75 m_thread =
new QThread(
this);
76 m_connection->moveToThread(m_thread);
79 m_connection->initConnection();
80 QVERIFY(connectedSpy.wait());
82 m_queue =
new KWayland::Client::EventQueue(
this);
83 QVERIFY(!m_queue->isValid());
84 m_queue->setup(m_connection);
85 QVERIFY(m_queue->isValid());
87 m_registry =
new KWayland::Client::Registry();
88 QSignalSpy interfacesAnnouncedSpy(m_registry, &KWayland::Client::Registry::interfaceAnnounced);
90 QVERIFY(!m_registry->eventQueue());
91 m_registry->setEventQueue(m_queue);
92 QCOMPARE(m_registry->eventQueue(), m_queue);
93 m_registry->create(m_connection);
94 QVERIFY(m_registry->isValid());
97 QVERIFY(interfacesAnnouncedSpy.wait());
98#define CREATE(variable, factory, iface) \
100 m_registry->create##factory(m_registry->interface(KWayland::Client::Registry::Interface::iface).name, m_registry->interface(KWayland::Client::Registry::Interface::iface).version, this); \
104 CREATE(m_plasmaShell, PlasmaShell, PlasmaShell)
109void TestPlasmaShell::cleanup()
111#define DELETE(name) \
128 m_connection =
nullptr;
134void TestPlasmaShell::testRole_data()
136 QTest::addColumn<KWayland::Client::PlasmaShellSurface::Role>(
"clientRole");
137 QTest::addColumn<KWin::PlasmaShellSurfaceInterface::Role>(
"serverRole");
139 QTest::newRow(
"desktop") << KWayland::Client::PlasmaShellSurface::Role::Desktop << PlasmaShellSurfaceInterface::Role::Desktop;
140 QTest::newRow(
"osd") << KWayland::Client::PlasmaShellSurface::Role::OnScreenDisplay << PlasmaShellSurfaceInterface::Role::OnScreenDisplay;
141 QTest::newRow(
"panel") << KWayland::Client::PlasmaShellSurface::Role::Panel << PlasmaShellSurfaceInterface::Role::Panel;
142 QTest::newRow(
"notification") << KWayland::Client::PlasmaShellSurface::Role::Notification << PlasmaShellSurfaceInterface::Role::Notification;
143 QTest::newRow(
"tooltip") << KWayland::Client::PlasmaShellSurface::Role::ToolTip << PlasmaShellSurfaceInterface::Role::ToolTip;
144 QTest::newRow(
"criticalnotification") << KWayland::Client::PlasmaShellSurface::Role::CriticalNotification << PlasmaShellSurfaceInterface::Role::CriticalNotification;
145 QTest::newRow(
"appletPopup") << KWayland::Client::PlasmaShellSurface::Role::AppletPopup << PlasmaShellSurfaceInterface::Role::AppletPopup;
148void TestPlasmaShell::testRole()
157 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
159 QVERIFY(!KWayland::Client::PlasmaShellSurface::get(s.get()));
160 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
161 QCOMPARE(ps->role(), KWayland::Client::PlasmaShellSurface::Role::Normal);
163 QCOMPARE(KWayland::Client::PlasmaShellSurface::get(s.get()), ps.get());
166 QCOMPARE(m_plasmaShell->createSurface(s.get()), ps.get());
169 QVERIFY(plasmaSurfaceCreatedSpy.wait());
170 QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
171 QCOMPARE(surfaceCreatedSpy.count(), 1);
176 QVERIFY(sps->surface());
177 QCOMPARE(sps->surface(), surfaceCreatedSpy.first().first().value<
SurfaceInterface *>());
180 QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Normal);
184 QFETCH(KWayland::Client::PlasmaShellSurface::Role, clientRole);
185 ps->setRole(clientRole);
186 QCOMPARE(ps->role(), clientRole);
187 QVERIFY(roleChangedSpy.wait());
188 QCOMPARE(roleChangedSpy.count(), 1);
189 QTEST(sps->role(),
"serverRole");
192 ps->setRole(clientRole);
193 QVERIFY(!roleChangedSpy.wait(100));
196 ps->setRole(KWayland::Client::PlasmaShellSurface::Role::Normal);
197 QCOMPARE(ps->role(), KWayland::Client::PlasmaShellSurface::Role::Normal);
198 QVERIFY(roleChangedSpy.wait());
199 QCOMPARE(roleChangedSpy.count(), 2);
200 QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Normal);
203void TestPlasmaShell::testPosition()
208 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
209 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
210 QVERIFY(plasmaSurfaceCreatedSpy.wait());
211 QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
216 QVERIFY(sps->surface());
219 QVERIFY(!sps->isPositionSet());
220 QCOMPARE(sps->position(), QPoint());
224 ps->setPosition(QPoint(1, 2));
225 QVERIFY(positionChangedSpy.wait());
226 QCOMPARE(positionChangedSpy.count(), 1);
227 QVERIFY(sps->isPositionSet());
228 QCOMPARE(sps->position(), QPoint(1, 2));
231 ps->setPosition(QPoint(1, 2));
232 QVERIFY(!positionChangedSpy.wait(100));
234 ps->setPosition(QPoint(3, 4));
235 QVERIFY(positionChangedSpy.wait());
236 QCOMPARE(positionChangedSpy.count(), 2);
237 QCOMPARE(sps->position(), QPoint(3, 4));
240void TestPlasmaShell::testSkipTaskbar()
245 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
246 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
247 QVERIFY(plasmaSurfaceCreatedSpy.wait());
248 QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
253 QVERIFY(sps->surface());
254 QVERIFY(!sps->skipTaskbar());
258 ps->setSkipTaskbar(
true);
259 QVERIFY(skipTaskbarChangedSpy.wait());
260 QVERIFY(sps->skipTaskbar());
262 ps->setSkipTaskbar(
true);
263 QEXPECT_FAIL(
"",
"Should not be emitted if not changed", Continue);
264 QVERIFY(!skipTaskbarChangedSpy.wait(100));
265 QVERIFY(sps->skipTaskbar());
268 ps->setSkipTaskbar(
false);
269 QVERIFY(skipTaskbarChangedSpy.wait());
270 QVERIFY(!sps->skipTaskbar());
273void TestPlasmaShell::testSkipSwitcher()
278 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
279 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
280 QVERIFY(plasmaSurfaceCreatedSpy.wait());
281 QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
286 QVERIFY(sps->surface());
287 QVERIFY(!sps->skipSwitcher());
291 ps->setSkipSwitcher(
true);
292 QVERIFY(skipSwitcherChangedSpy.wait());
293 QVERIFY(sps->skipSwitcher());
295 ps->setSkipSwitcher(
true);
296 QEXPECT_FAIL(
"",
"Should not be emitted if not changed", Continue);
297 QVERIFY(!skipSwitcherChangedSpy.wait(100));
298 QVERIFY(sps->skipSwitcher());
301 ps->setSkipSwitcher(
false);
302 QVERIFY(skipSwitcherChangedSpy.wait());
303 QVERIFY(!sps->skipSwitcher());
306void TestPlasmaShell::testPanelBehavior_data()
308 QTest::addColumn<KWayland::Client::PlasmaShellSurface::PanelBehavior>(
"client");
309 QTest::addColumn<PlasmaShellSurfaceInterface::PanelBehavior>(
"server");
311 QTest::newRow(
"autohide") << KWayland::Client::PlasmaShellSurface::PanelBehavior::AutoHide << PlasmaShellSurfaceInterface::PanelBehavior::AutoHide;
312 QTest::newRow(
"can cover") << KWayland::Client::PlasmaShellSurface::PanelBehavior::WindowsCanCover << PlasmaShellSurfaceInterface::PanelBehavior::WindowsCanCover;
313 QTest::newRow(
"go below") << KWayland::Client::PlasmaShellSurface::PanelBehavior::WindowsGoBelow << PlasmaShellSurfaceInterface::PanelBehavior::WindowsGoBelow;
316void TestPlasmaShell::testPanelBehavior()
321 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
322 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
323 ps->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
324 QVERIFY(plasmaSurfaceCreatedSpy.wait());
325 QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
330 QVERIFY(sps->surface());
331 QCOMPARE(sps->panelBehavior(), PlasmaShellSurfaceInterface::PanelBehavior::AlwaysVisible);
335 QFETCH(KWayland::Client::PlasmaShellSurface::PanelBehavior, client);
336 ps->setPanelBehavior(client);
337 QVERIFY(behaviorChangedSpy.wait());
338 QTEST(sps->panelBehavior(),
"server");
341 ps->setPanelBehavior(client);
342 QVERIFY(!behaviorChangedSpy.wait(100));
345 ps->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AlwaysVisible);
346 QVERIFY(behaviorChangedSpy.wait());
347 QCOMPARE(sps->panelBehavior(), PlasmaShellSurfaceInterface::PanelBehavior::AlwaysVisible);
350void TestPlasmaShell::testAutoHidePanel()
355 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
356 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
357 ps->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
358 ps->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AutoHide);
359 QVERIFY(plasmaSurfaceCreatedSpy.wait());
360 QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
363 QCOMPARE(sps->panelBehavior(), PlasmaShellSurfaceInterface::PanelBehavior::AutoHide);
367 ps->requestHideAutoHidingPanel();
368 QVERIFY(autoHideRequestedSpy.wait());
369 QCOMPARE(autoHideRequestedSpy.count(), 1);
370 QCOMPARE(autoHideShowRequestedSpy.count(), 0);
372 QSignalSpy panelShownSpy(ps.get(), &KWayland::Client::PlasmaShellSurface::autoHidePanelShown);
373 QSignalSpy panelHiddenSpy(ps.get(), &KWayland::Client::PlasmaShellSurface::autoHidePanelHidden);
375 sps->hideAutoHidingPanel();
376 QVERIFY(panelHiddenSpy.wait());
377 QCOMPARE(panelHiddenSpy.count(), 1);
378 QCOMPARE(panelShownSpy.count(), 0);
380 ps->requestShowAutoHidingPanel();
381 QVERIFY(autoHideShowRequestedSpy.wait());
382 QCOMPARE(autoHideRequestedSpy.count(), 1);
383 QCOMPARE(autoHideShowRequestedSpy.count(), 1);
385 sps->showAutoHidingPanel();
386 QVERIFY(panelShownSpy.wait());
387 QCOMPARE(panelHiddenSpy.count(), 1);
388 QCOMPARE(panelShownSpy.count(), 1);
391 ps->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AlwaysVisible);
393 QSignalSpy errorSpy(m_connection, &KWayland::Client::ConnectionThread::errorOccurred);
394 ps->requestHideAutoHidingPanel();
395 QVERIFY(errorSpy.wait());
398void TestPlasmaShell::testPanelTakesFocus()
403 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
404 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
405 ps->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
406 QVERIFY(plasmaSurfaceCreatedSpy.wait());
407 QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
412 QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Panel);
413 QCOMPARE(sps->panelTakesFocus(),
false);
415 ps->setPanelTakesFocus(
true);
416 m_connection->flush();
417 QVERIFY(plasmaSurfaceTakesFocusSpy.wait());
418 QCOMPARE(plasmaSurfaceTakesFocusSpy.count(), 1);
419 QCOMPARE(sps->panelTakesFocus(),
true);
420 ps->setPanelTakesFocus(
false);
421 m_connection->flush();
422 QVERIFY(plasmaSurfaceTakesFocusSpy.wait());
423 QCOMPARE(plasmaSurfaceTakesFocusSpy.count(), 2);
424 QCOMPARE(sps->panelTakesFocus(),
false);
427void TestPlasmaShell::testDisconnect()
432 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
433 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
436 QVERIFY(plasmaSurfaceCreatedSpy.wait());
437 QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1);
442 QSignalSpy surfaceDestroyedSpy(sps, &QObject::destroyed);
444 m_connection->deleteLater();
445 m_connection =
nullptr;
447 QCOMPARE(surfaceDestroyedSpy.count(), 0);
448 QVERIFY(surfaceDestroyedSpy.wait());
449 QCOMPARE(surfaceDestroyedSpy.count(), 1);
453 m_plasmaShell->destroy();
454 m_compositor->destroy();
455 m_registry->destroy();
459void TestPlasmaShell::testWhileDestroying()
465 std::unique_ptr<KWayland::Client::Surface> s(m_compositor->createSurface());
466 QVERIFY(surfaceCreatedSpy.wait());
467 auto serverSurface = surfaceCreatedSpy.first().first().value<
SurfaceInterface *>();
468 QVERIFY(serverSurface);
472 std::unique_ptr<KWayland::Client::PlasmaShellSurface> ps(m_plasmaShell->createSurface(s.get()));
473 QVERIFY(shellSurfaceCreatedSpy.wait());
476 QSignalSpy clientErrorSpy(m_connection, &KWayland::Client::ConnectionThread::errorOccurred);
477 for (
int i = 0; i < 100; i++) {
479 s.reset(m_compositor->createSurface());
480 m_plasmaShell->createSurface(s.get(),
this);
481 QVERIFY(surfaceCreatedSpy.wait());
483 QVERIFY(clientErrorSpy.isEmpty());
484 QVERIFY(!clientErrorSpy.wait(100));
485 QVERIFY(clientErrorSpy.isEmpty());
489#include "test_plasmashell.moc"
void surfaceCreated(KWin::SurfaceInterface *surface)
Class holding the Wayland server display loop.
bool addSocketName(const QString &name=QString())
Global for the org_kde_plasma_shell interface.
void surfaceCreated(KWin::PlasmaShellSurfaceInterface *)
Resource for the org_kde_plasma_shell_surface interface.
void skipTaskbarChanged()
void panelBehaviorChanged()
void skipSwitcherChanged()
void panelTakesFocusChanged()
void panelAutoHideShowRequested()
void panelAutoHideHideRequested()
Resource representing a wl_surface.
#define CREATE(variable, factory, iface)