Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/plasma_surface_test.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 42 | private Q_SLOTS: | |||
---|---|---|---|---|---|
47 | void testRoleOnAllDesktops_data(); | 47 | void testRoleOnAllDesktops_data(); | ||
48 | void testRoleOnAllDesktops(); | 48 | void testRoleOnAllDesktops(); | ||
49 | void testAcceptsFocus_data(); | 49 | void testAcceptsFocus_data(); | ||
50 | void testAcceptsFocus(); | 50 | void testAcceptsFocus(); | ||
51 | 51 | | |||
52 | private: | 52 | private: | ||
53 | ConnectionThread *m_connection = nullptr; | 53 | ConnectionThread *m_connection = nullptr; | ||
54 | KWayland::Client::Compositor *m_compositor = nullptr; | 54 | KWayland::Client::Compositor *m_compositor = nullptr; | ||
55 | ShmPool *m_shm = nullptr; | | |||
56 | Shell *m_shell = nullptr; | 55 | Shell *m_shell = nullptr; | ||
57 | PlasmaShell *m_plasmaShell = nullptr; | 56 | PlasmaShell *m_plasmaShell = nullptr; | ||
58 | EventQueue *m_queue = nullptr; | | |||
59 | QThread *m_thread = nullptr; | | |||
60 | }; | 57 | }; | ||
61 | 58 | | |||
62 | void PlasmaSurfaceTest::initTestCase() | 59 | void PlasmaSurfaceTest::initTestCase() | ||
63 | { | 60 | { | ||
64 | qRegisterMetaType<KWin::ShellClient*>(); | 61 | qRegisterMetaType<KWin::ShellClient*>(); | ||
65 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 62 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
66 | QVERIFY(workspaceCreatedSpy.isValid()); | 63 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
67 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 64 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
68 | waylandServer()->init(s_socketName.toLocal8Bit()); | 65 | waylandServer()->init(s_socketName.toLocal8Bit()); | ||
69 | kwinApp()->start(); | 66 | kwinApp()->start(); | ||
70 | QVERIFY(workspaceCreatedSpy.wait()); | 67 | QVERIFY(workspaceCreatedSpy.wait()); | ||
71 | } | 68 | } | ||
72 | 69 | | |||
73 | void PlasmaSurfaceTest::init() | 70 | void PlasmaSurfaceTest::init() | ||
74 | { | 71 | { | ||
75 | // setup connection | 72 | QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell)); | ||
76 | m_connection = new ConnectionThread; | 73 | m_compositor = Test::waylandCompositor(); | ||
77 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | 74 | m_shell = Test::waylandShell(); | ||
78 | QVERIFY(connectedSpy.isValid()); | 75 | m_plasmaShell = Test::waylandPlasmaShell(); | ||
79 | m_connection->setSocketName(s_socketName); | | |||
80 | | ||||
81 | m_thread = new QThread(this); | | |||
82 | m_connection->moveToThread(m_thread); | | |||
83 | m_thread->start(); | | |||
84 | | ||||
85 | m_connection->initConnection(); | | |||
86 | QVERIFY(connectedSpy.wait()); | | |||
87 | | ||||
88 | m_queue = new EventQueue(this); | | |||
89 | QVERIFY(!m_queue->isValid()); | | |||
90 | m_queue->setup(m_connection); | | |||
91 | QVERIFY(m_queue->isValid()); | | |||
92 | | ||||
93 | Registry registry; | | |||
94 | registry.setEventQueue(m_queue); | | |||
95 | QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); | | |||
96 | QVERIFY(allAnnounced.isValid()); | | |||
97 | registry.create(m_connection->display()); | | |||
98 | QVERIFY(registry.isValid()); | | |||
99 | registry.setup(); | | |||
100 | QVERIFY(allAnnounced.wait()); | | |||
101 | | ||||
102 | m_compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, | | |||
103 | registry.interface(Registry::Interface::Compositor).version, | | |||
104 | this); | | |||
105 | QVERIFY(m_compositor->isValid()); | | |||
106 | m_shm = registry.createShmPool(registry.interface(Registry::Interface::Shm).name, | | |||
107 | registry.interface(Registry::Interface::Shm).version, | | |||
108 | this); | | |||
109 | QVERIFY(m_shm->isValid()); | | |||
110 | m_shell = registry.createShell(registry.interface(Registry::Interface::Shell).name, | | |||
111 | registry.interface(Registry::Interface::Shell).version, | | |||
112 | this); | | |||
113 | QVERIFY(m_shell->isValid()); | | |||
114 | m_plasmaShell = registry.createPlasmaShell(registry.interface(Registry::Interface::PlasmaShell).name, | | |||
115 | registry.interface(Registry::Interface::PlasmaShell).version, | | |||
116 | this); | | |||
117 | QVERIFY(m_plasmaShell->isValid()); | | |||
118 | } | 76 | } | ||
119 | 77 | | |||
120 | void PlasmaSurfaceTest::cleanup() | 78 | void PlasmaSurfaceTest::cleanup() | ||
121 | { | 79 | { | ||
122 | #define CLEANUP(name) delete name; name = nullptr; | 80 | Test::destroyWaylandConnection(); | ||
123 | CLEANUP(m_plasmaShell) | | |||
124 | CLEANUP(m_shell) | | |||
125 | CLEANUP(m_shm) | | |||
126 | CLEANUP(m_compositor) | | |||
127 | CLEANUP(m_queue) | | |||
128 | if (m_connection) { | | |||
129 | m_connection->deleteLater(); | | |||
130 | m_connection = nullptr; | | |||
131 | } | | |||
132 | if (m_thread) { | | |||
133 | m_thread->quit(); | | |||
134 | m_thread->wait(); | | |||
135 | delete m_thread; | | |||
136 | m_thread = nullptr; | | |||
137 | } | | |||
138 | #undef CLEANUP | | |||
139 | } | 81 | } | ||
140 | 82 | | |||
141 | void PlasmaSurfaceTest::testRoleOnAllDesktops_data() | 83 | void PlasmaSurfaceTest::testRoleOnAllDesktops_data() | ||
142 | { | 84 | { | ||
143 | QTest::addColumn<PlasmaShellSurface::Role>("role"); | 85 | QTest::addColumn<PlasmaShellSurface::Role>("role"); | ||
144 | QTest::addColumn<bool>("expectedOnAllDesktops"); | 86 | QTest::addColumn<bool>("expectedOnAllDesktops"); | ||
145 | 87 | | |||
146 | QTest::newRow("Desktop") << PlasmaShellSurface::Role::Desktop << true; | 88 | QTest::newRow("Desktop") << PlasmaShellSurface::Role::Desktop << true; | ||
147 | QTest::newRow("Panel") << PlasmaShellSurface::Role::Panel << true; | 89 | QTest::newRow("Panel") << PlasmaShellSurface::Role::Panel << true; | ||
148 | QTest::newRow("OSD") << PlasmaShellSurface::Role::OnScreenDisplay << true; | 90 | QTest::newRow("OSD") << PlasmaShellSurface::Role::OnScreenDisplay << true; | ||
149 | QTest::newRow("Normal") << PlasmaShellSurface::Role::Normal << false; | 91 | QTest::newRow("Normal") << PlasmaShellSurface::Role::Normal << false; | ||
150 | QTest::newRow("Notification") << PlasmaShellSurface::Role::Notification << true; | 92 | QTest::newRow("Notification") << PlasmaShellSurface::Role::Notification << true; | ||
151 | QTest::newRow("ToolTip") << PlasmaShellSurface::Role::ToolTip << true; | 93 | QTest::newRow("ToolTip") << PlasmaShellSurface::Role::ToolTip << true; | ||
152 | } | 94 | } | ||
153 | 95 | | |||
154 | void PlasmaSurfaceTest::testRoleOnAllDesktops() | 96 | void PlasmaSurfaceTest::testRoleOnAllDesktops() | ||
155 | { | 97 | { | ||
156 | // this test verifies that a ShellClient is set on all desktops when the role changes | 98 | // this test verifies that a ShellClient is set on all desktops when the role changes | ||
157 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 99 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
158 | QVERIFY(!surface.isNull()); | 100 | QVERIFY(!surface.isNull()); | ||
159 | QScopedPointer<ShellSurface> shellSurface(m_shell->createSurface(surface.data())); | 101 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||
160 | QVERIFY(!shellSurface.isNull()); | 102 | QVERIFY(!shellSurface.isNull()); | ||
161 | QScopedPointer<PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.data())); | 103 | QScopedPointer<PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.data())); | ||
162 | QVERIFY(!plasmaSurface.isNull()); | 104 | QVERIFY(!plasmaSurface.isNull()); | ||
163 | 105 | | |||
164 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 106 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
165 | QVERIFY(clientAddedSpy.isValid()); | 107 | QVERIFY(clientAddedSpy.isValid()); | ||
166 | 108 | | |||
167 | // now render to map the window | 109 | // now render to map the window | ||
168 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 110 | Test::render(surface.data(), QSize(100, 50), Qt::blue); | ||
169 | img.fill(Qt::blue); | | |||
170 | surface->attachBuffer(m_shm->createBuffer(img)); | | |||
171 | surface->damage(QRect(0, 0, 100, 50)); | | |||
172 | surface->commit(); | | |||
173 | QVERIFY(clientAddedSpy.wait()); | 111 | QVERIFY(clientAddedSpy.wait()); | ||
174 | AbstractClient *c = workspace()->activeClient(); | 112 | AbstractClient *c = workspace()->activeClient(); | ||
175 | QVERIFY(c); | 113 | QVERIFY(c); | ||
176 | QCOMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | 114 | QCOMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | ||
177 | 115 | | |||
178 | // currently the role is not yet set, so the window should not be on all desktops | 116 | // currently the role is not yet set, so the window should not be on all desktops | ||
179 | QCOMPARE(c->isOnAllDesktops(), false); | 117 | QCOMPARE(c->isOnAllDesktops(), false); | ||
180 | 118 | | |||
181 | // now let's try to change that | 119 | // now let's try to change that | ||
182 | QSignalSpy onAllDesktopsSpy(c, &AbstractClient::desktopChanged); | 120 | QSignalSpy onAllDesktopsSpy(c, &AbstractClient::desktopChanged); | ||
183 | QVERIFY(onAllDesktopsSpy.isValid()); | 121 | QVERIFY(onAllDesktopsSpy.isValid()); | ||
184 | QFETCH(PlasmaShellSurface::Role, role); | 122 | QFETCH(PlasmaShellSurface::Role, role); | ||
185 | plasmaSurface->setRole(role); | 123 | plasmaSurface->setRole(role); | ||
186 | QFETCH(bool, expectedOnAllDesktops); | 124 | QFETCH(bool, expectedOnAllDesktops); | ||
187 | QCOMPARE(onAllDesktopsSpy.wait(), expectedOnAllDesktops); | 125 | QCOMPARE(onAllDesktopsSpy.wait(), expectedOnAllDesktops); | ||
188 | QCOMPARE(c->isOnAllDesktops(), expectedOnAllDesktops); | 126 | QCOMPARE(c->isOnAllDesktops(), expectedOnAllDesktops); | ||
189 | 127 | | |||
190 | // let's create a second window where we init a little bit different | 128 | // let's create a second window where we init a little bit different | ||
191 | // first creating the PlasmaSurface then the Shell Surface | 129 | // first creating the PlasmaSurface then the Shell Surface | ||
192 | QScopedPointer<Surface> surface2(m_compositor->createSurface()); | 130 | QScopedPointer<Surface> surface2(Test::createSurface()); | ||
193 | QVERIFY(!surface2.isNull()); | 131 | QVERIFY(!surface2.isNull()); | ||
194 | QScopedPointer<PlasmaShellSurface> plasmaSurface2(m_plasmaShell->createSurface(surface2.data())); | 132 | QScopedPointer<PlasmaShellSurface> plasmaSurface2(m_plasmaShell->createSurface(surface2.data())); | ||
195 | QVERIFY(!plasmaSurface2.isNull()); | 133 | QVERIFY(!plasmaSurface2.isNull()); | ||
196 | plasmaSurface2->setRole(role); | 134 | plasmaSurface2->setRole(role); | ||
197 | QScopedPointer<ShellSurface> shellSurface2(m_shell->createSurface(surface2.data())); | 135 | QScopedPointer<ShellSurface> shellSurface2(Test::createShellSurface(surface2.data())); | ||
198 | QVERIFY(!shellSurface2.isNull()); | 136 | QVERIFY(!shellSurface2.isNull()); | ||
199 | surface2->attachBuffer(m_shm->createBuffer(img)); | 137 | Test::render(surface2.data(), QSize(100, 50), Qt::blue); | ||
200 | surface2->damage(QRect(0, 0, 100, 50)); | | |||
201 | surface2->commit(); | | |||
202 | QVERIFY(clientAddedSpy.wait()); | 138 | QVERIFY(clientAddedSpy.wait()); | ||
203 | 139 | | |||
204 | QVERIFY(workspace()->activeClient() != c); | 140 | QVERIFY(workspace()->activeClient() != c); | ||
205 | c = workspace()->activeClient(); | 141 | c = workspace()->activeClient(); | ||
206 | QEXPECT_FAIL("Desktop", "PS before WS not supported", Continue); | 142 | QEXPECT_FAIL("Desktop", "PS before WS not supported", Continue); | ||
207 | QEXPECT_FAIL("Panel", "PS before WS not supported", Continue); | 143 | QEXPECT_FAIL("Panel", "PS before WS not supported", Continue); | ||
208 | QEXPECT_FAIL("OSD", "PS before WS not supported", Continue); | 144 | QEXPECT_FAIL("OSD", "PS before WS not supported", Continue); | ||
209 | QEXPECT_FAIL("Notification", "PS before WS not supported", Continue); | 145 | QEXPECT_FAIL("Notification", "PS before WS not supported", Continue); | ||
Show All 13 Lines | 151 | { | |||
223 | QTest::newRow("Normal") << PlasmaShellSurface::Role::Normal << true << true; | 159 | QTest::newRow("Normal") << PlasmaShellSurface::Role::Normal << true << true; | ||
224 | QTest::newRow("Notification") << PlasmaShellSurface::Role::Notification << false << false; | 160 | QTest::newRow("Notification") << PlasmaShellSurface::Role::Notification << false << false; | ||
225 | QTest::newRow("ToolTip") << PlasmaShellSurface::Role::ToolTip << false << false; | 161 | QTest::newRow("ToolTip") << PlasmaShellSurface::Role::ToolTip << false << false; | ||
226 | } | 162 | } | ||
227 | 163 | | |||
228 | void PlasmaSurfaceTest::testAcceptsFocus() | 164 | void PlasmaSurfaceTest::testAcceptsFocus() | ||
229 | { | 165 | { | ||
230 | // this test verifies that some surface roles don't get focus | 166 | // this test verifies that some surface roles don't get focus | ||
231 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 167 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
232 | QVERIFY(!surface.isNull()); | 168 | QVERIFY(!surface.isNull()); | ||
233 | QScopedPointer<ShellSurface> shellSurface(m_shell->createSurface(surface.data())); | 169 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||
234 | QVERIFY(!shellSurface.isNull()); | 170 | QVERIFY(!shellSurface.isNull()); | ||
235 | QScopedPointer<PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.data())); | 171 | QScopedPointer<PlasmaShellSurface> plasmaSurface(m_plasmaShell->createSurface(surface.data())); | ||
236 | QVERIFY(!plasmaSurface.isNull()); | 172 | QVERIFY(!plasmaSurface.isNull()); | ||
237 | QFETCH(PlasmaShellSurface::Role, role); | 173 | QFETCH(PlasmaShellSurface::Role, role); | ||
238 | plasmaSurface->setRole(role); | 174 | plasmaSurface->setRole(role); | ||
239 | 175 | | |||
240 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 176 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
241 | QVERIFY(clientAddedSpy.isValid()); | 177 | QVERIFY(clientAddedSpy.isValid()); | ||
242 | 178 | | |||
243 | // now render to map the window | 179 | // now render to map the window | ||
244 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 180 | Test::render(surface.data(), QSize(100, 50), Qt::blue); | ||
245 | img.fill(Qt::blue); | | |||
246 | surface->attachBuffer(m_shm->createBuffer(img)); | | |||
247 | surface->damage(QRect(0, 0, 100, 50)); | | |||
248 | surface->commit(); | | |||
249 | QVERIFY(clientAddedSpy.wait()); | 181 | QVERIFY(clientAddedSpy.wait()); | ||
250 | 182 | | |||
251 | auto c = clientAddedSpy.first().first().value<ShellClient*>(); | 183 | auto c = clientAddedSpy.first().first().value<ShellClient*>(); | ||
252 | QVERIFY(c); | 184 | QVERIFY(c); | ||
253 | QTEST(c->wantsInput(), "wantsInput"); | 185 | QTEST(c->wantsInput(), "wantsInput"); | ||
254 | QTEST(c->isActive(), "active"); | 186 | QTEST(c->isActive(), "active"); | ||
255 | } | 187 | } | ||
256 | 188 | | |||
257 | WAYLANDTEST_MAIN(PlasmaSurfaceTest) | 189 | WAYLANDTEST_MAIN(PlasmaSurfaceTest) | ||
258 | #include "plasma_surface_test.moc" | 190 | #include "plasma_surface_test.moc" |