Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/idle_inhibition_test.cpp
Show All 39 Lines | 39 | { | |||
---|---|---|---|---|---|
40 | Q_OBJECT | 40 | Q_OBJECT | ||
41 | private Q_SLOTS: | 41 | private Q_SLOTS: | ||
42 | void initTestCase(); | 42 | void initTestCase(); | ||
43 | void init(); | 43 | void init(); | ||
44 | void cleanup(); | 44 | void cleanup(); | ||
45 | 45 | | |||
46 | void testInhibit_data(); | 46 | void testInhibit_data(); | ||
47 | void testInhibit(); | 47 | void testInhibit(); | ||
48 | void testDontInhibitWhenNotOnCurrentDesktop(); | ||||
49 | void testDontInhibitWhenMinimized(); | ||||
50 | void testDontInhibitWhenUnmapped(); | ||||
51 | void testDontInhibitWhenLeftCurrentDesktop(); | ||||
48 | }; | 52 | }; | ||
49 | 53 | | |||
50 | void TestIdleInhibition::initTestCase() | 54 | void TestIdleInhibition::initTestCase() | ||
51 | { | 55 | { | ||
52 | qRegisterMetaType<KWin::ShellClient*>(); | 56 | qRegisterMetaType<KWin::ShellClient*>(); | ||
53 | qRegisterMetaType<KWin::AbstractClient*>(); | 57 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
54 | 58 | | |||
55 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 59 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
Show All 9 Lines | |||||
65 | { | 69 | { | ||
66 | QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::IdleInhibition)); | 70 | QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::IdleInhibition)); | ||
67 | 71 | | |||
68 | } | 72 | } | ||
69 | 73 | | |||
70 | void TestIdleInhibition::cleanup() | 74 | void TestIdleInhibition::cleanup() | ||
71 | { | 75 | { | ||
72 | Test::destroyWaylandConnection(); | 76 | Test::destroyWaylandConnection(); | ||
77 | | ||||
78 | VirtualDesktopManager::self()->setCount(1); | ||||
79 | QCOMPARE(VirtualDesktopManager::self()->count(), 1u); | ||||
73 | } | 80 | } | ||
74 | 81 | | |||
75 | void TestIdleInhibition::testInhibit_data() | 82 | void TestIdleInhibition::testInhibit_data() | ||
76 | { | 83 | { | ||
77 | QTest::addColumn<Test::ShellSurfaceType>("type"); | 84 | QTest::addColumn<Test::ShellSurfaceType>("type"); | ||
78 | 85 | | |||
79 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | 86 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | ||
80 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | 87 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | ||
Show All 39 Lines | 93 | { | |||
120 | if (type == Test::ShellSurfaceType::WlShell) { | 127 | if (type == Test::ShellSurfaceType::WlShell) { | ||
121 | surface.reset(); | 128 | surface.reset(); | ||
122 | } | 129 | } | ||
123 | QVERIFY(Test::waitForWindowDestroyed(c)); | 130 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||
124 | QTRY_VERIFY(!idle->isInhibited()); | 131 | QTRY_VERIFY(!idle->isInhibited()); | ||
125 | QCOMPARE(inhibitedSpy.count(), 4); | 132 | QCOMPARE(inhibitedSpy.count(), 4); | ||
126 | } | 133 | } | ||
127 | 134 | | |||
135 | void TestIdleInhibition::testDontInhibitWhenNotOnCurrentDesktop() | ||||
136 | { | ||||
137 | // This test verifies that the idle inhibitor object is not honored when | ||||
138 | // the associated surface is not on the current virtual desktop. | ||||
139 | | ||||
140 | VirtualDesktopManager::self()->setCount(2); | ||||
141 | QCOMPARE(VirtualDesktopManager::self()->count(), 2u); | ||||
142 | | ||||
143 | // Get reference to the idle interface. | ||||
144 | auto idle = waylandServer()->display()->findChild<IdleInterface *>(); | ||||
145 | QVERIFY(idle); | ||||
146 | QVERIFY(!idle->isInhibited()); | ||||
147 | QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged); | ||||
148 | QVERIFY(inhibitedSpy.isValid()); | ||||
149 | | ||||
150 | // Create the test client. | ||||
151 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
152 | QVERIFY(!surface.isNull()); | ||||
153 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
154 | QVERIFY(!shellSurface.isNull()); | ||||
155 | | ||||
156 | // Create the inhibitor object. | ||||
157 | QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data())); | ||||
158 | QVERIFY(inhibitor->isValid()); | ||||
159 | | ||||
160 | // Render the client. | ||||
161 | auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
162 | QVERIFY(c); | ||||
163 | | ||||
164 | // The test client should be only on the first virtual desktop. | ||||
165 | QCOMPARE(c->desktops().count(), 1); | ||||
166 | QCOMPARE(c->desktops().first(), VirtualDesktopManager::self()->desktops().first()); | ||||
167 | | ||||
168 | // This should inhibit our server object. | ||||
169 | QVERIFY(idle->isInhibited()); | ||||
170 | QCOMPARE(inhibitedSpy.count(), 1); | ||||
171 | | ||||
172 | // Switch to the second virtual desktop. | ||||
173 | VirtualDesktopManager::self()->setCurrent(2); | ||||
174 | | ||||
175 | // The surface is no longer visible, so the compositor don't have to honor the | ||||
176 | // idle inhibitor object. | ||||
177 | QVERIFY(!idle->isInhibited()); | ||||
178 | QCOMPARE(inhibitedSpy.count(), 2); | ||||
179 | | ||||
180 | // Switch back to the first virtual desktop. | ||||
181 | VirtualDesktopManager::self()->setCurrent(1); | ||||
182 | | ||||
183 | // The test client became visible again, so the compositor has to honor the idle | ||||
184 | // inhibitor object back again. | ||||
185 | QVERIFY(idle->isInhibited()); | ||||
186 | QCOMPARE(inhibitedSpy.count(), 3); | ||||
187 | | ||||
188 | // Destroy the test client. | ||||
189 | shellSurface.reset(); | ||||
190 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||||
191 | QTRY_VERIFY(!idle->isInhibited()); | ||||
192 | QCOMPARE(inhibitedSpy.count(), 4); | ||||
193 | } | ||||
194 | | ||||
195 | void TestIdleInhibition::testDontInhibitWhenMinimized() | ||||
196 | { | ||||
197 | // This test verifies that the idle inhibitor object is not honored when the | ||||
198 | // associated surface is minimized. | ||||
199 | | ||||
200 | // Get reference to the idle interface. | ||||
201 | auto idle = waylandServer()->display()->findChild<IdleInterface *>(); | ||||
202 | QVERIFY(idle); | ||||
203 | QVERIFY(!idle->isInhibited()); | ||||
204 | QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged); | ||||
205 | QVERIFY(inhibitedSpy.isValid()); | ||||
206 | | ||||
207 | // Create the test client. | ||||
208 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
209 | QVERIFY(!surface.isNull()); | ||||
210 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
211 | QVERIFY(!shellSurface.isNull()); | ||||
212 | | ||||
213 | // Create the inhibitor object. | ||||
214 | QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data())); | ||||
215 | QVERIFY(inhibitor->isValid()); | ||||
216 | | ||||
217 | // Render the client. | ||||
218 | auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
219 | QVERIFY(c); | ||||
220 | | ||||
221 | // This should inhibit our server object. | ||||
222 | QVERIFY(idle->isInhibited()); | ||||
223 | QCOMPARE(inhibitedSpy.count(), 1); | ||||
224 | | ||||
225 | // Minimize the client, the idle inhibitor object should not be honored. | ||||
226 | c->minimize(); | ||||
227 | QVERIFY(!idle->isInhibited()); | ||||
228 | QCOMPARE(inhibitedSpy.count(), 2); | ||||
229 | | ||||
230 | // Unminimize the client, the idle inhibitor object should be honored back again. | ||||
231 | c->unminimize(); | ||||
232 | QVERIFY(idle->isInhibited()); | ||||
233 | QCOMPARE(inhibitedSpy.count(), 3); | ||||
234 | | ||||
235 | // Destroy the test client. | ||||
236 | shellSurface.reset(); | ||||
237 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||||
238 | QTRY_VERIFY(!idle->isInhibited()); | ||||
239 | QCOMPARE(inhibitedSpy.count(), 4); | ||||
240 | } | ||||
241 | | ||||
242 | void TestIdleInhibition::testDontInhibitWhenUnmapped() | ||||
243 | { | ||||
244 | // This test verifies that the idle inhibitor object is not honored by KWin | ||||
245 | // when the associated client is unmapped. | ||||
246 | | ||||
247 | // Get reference to the idle interface. | ||||
248 | auto idle = waylandServer()->display()->findChild<IdleInterface *>(); | ||||
249 | QVERIFY(idle); | ||||
250 | QVERIFY(!idle->isInhibited()); | ||||
251 | QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged); | ||||
252 | QVERIFY(inhibitedSpy.isValid()); | ||||
253 | | ||||
254 | // Create the test client. | ||||
255 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
256 | QVERIFY(!surface.isNull()); | ||||
257 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
258 | QVERIFY(!shellSurface.isNull()); | ||||
259 | | ||||
260 | // Create the inhibitor object. | ||||
261 | QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data())); | ||||
262 | QVERIFY(inhibitor->isValid()); | ||||
263 | | ||||
264 | // Render the client. | ||||
265 | auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
266 | QVERIFY(c); | ||||
267 | | ||||
268 | // This should inhibit our server object. | ||||
269 | QVERIFY(idle->isInhibited()); | ||||
270 | QCOMPARE(inhibitedSpy.count(), 1); | ||||
271 | | ||||
272 | // Unmap the client. | ||||
273 | QSignalSpy hiddenSpy(c, &ShellClient::windowHidden); | ||||
274 | QVERIFY(hiddenSpy.isValid()); | ||||
275 | surface->attachBuffer(Buffer::Ptr()); | ||||
276 | surface->commit(Surface::CommitFlag::None); | ||||
277 | QVERIFY(hiddenSpy.wait()); | ||||
278 | | ||||
279 | // The surface is no longer visible, so the compositor don't have to honor the | ||||
280 | // idle inhibitor object. | ||||
281 | QVERIFY(!idle->isInhibited()); | ||||
282 | QCOMPARE(inhibitedSpy.count(), 2); | ||||
283 | | ||||
284 | // Map the client. | ||||
285 | QSignalSpy windowShownSpy(c, &ShellClient::windowShown); | ||||
286 | QVERIFY(windowShownSpy.isValid()); | ||||
287 | Test::render(surface.data(), QSize(100, 50), Qt::blue); | ||||
288 | QVERIFY(windowShownSpy.wait()); | ||||
289 | | ||||
290 | // The test client became visible again, so the compositor has to honor the idle | ||||
291 | // inhibitor object back again. | ||||
292 | QVERIFY(idle->isInhibited()); | ||||
293 | QCOMPARE(inhibitedSpy.count(), 3); | ||||
294 | | ||||
295 | // Destroy the test client. | ||||
296 | shellSurface.reset(); | ||||
297 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||||
298 | QTRY_VERIFY(!idle->isInhibited()); | ||||
299 | QCOMPARE(inhibitedSpy.count(), 4); | ||||
300 | } | ||||
301 | | ||||
302 | void TestIdleInhibition::testDontInhibitWhenLeftCurrentDesktop() | ||||
303 | { | ||||
304 | // This test verifies that the idle inhibitor object is not honored by KWin | ||||
305 | // when the associated surface leaves the current virtual desktop. | ||||
306 | | ||||
307 | VirtualDesktopManager::self()->setCount(2); | ||||
308 | QCOMPARE(VirtualDesktopManager::self()->count(), 2u); | ||||
309 | | ||||
310 | // Get reference to the idle interface. | ||||
311 | auto idle = waylandServer()->display()->findChild<IdleInterface *>(); | ||||
312 | QVERIFY(idle); | ||||
313 | QVERIFY(!idle->isInhibited()); | ||||
314 | QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged); | ||||
315 | QVERIFY(inhibitedSpy.isValid()); | ||||
316 | | ||||
317 | // Create the test client. | ||||
318 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
319 | QVERIFY(!surface.isNull()); | ||||
320 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
321 | QVERIFY(!shellSurface.isNull()); | ||||
322 | | ||||
323 | // Create the inhibitor object. | ||||
324 | QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data())); | ||||
325 | QVERIFY(inhibitor->isValid()); | ||||
326 | | ||||
327 | // Render the client. | ||||
328 | auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
329 | QVERIFY(c); | ||||
330 | | ||||
331 | // The test client should be only on the first virtual desktop. | ||||
332 | QCOMPARE(c->desktops().count(), 1); | ||||
333 | QCOMPARE(c->desktops().first(), VirtualDesktopManager::self()->desktops().first()); | ||||
334 | | ||||
335 | // This should inhibit our server object. | ||||
336 | QVERIFY(idle->isInhibited()); | ||||
337 | QCOMPARE(inhibitedSpy.count(), 1); | ||||
338 | | ||||
339 | // Let the client enter the second virtual desktop. | ||||
340 | c->enterDesktop(VirtualDesktopManager::self()->desktops().at(1)); | ||||
341 | QCOMPARE(inhibitedSpy.count(), 1); | ||||
342 | | ||||
343 | // If the client leaves the first virtual desktop, then the associated idle | ||||
344 | // inhibitor object should not be honored. | ||||
345 | c->leaveDesktop(VirtualDesktopManager::self()->desktops().at(0)); | ||||
346 | QVERIFY(!idle->isInhibited()); | ||||
347 | QCOMPARE(inhibitedSpy.count(), 2); | ||||
348 | | ||||
349 | // If the client enters the first desktop, then the associated idle inhibitor | ||||
350 | // object should be honored back again. | ||||
351 | c->enterDesktop(VirtualDesktopManager::self()->desktops().at(0)); | ||||
352 | QVERIFY(idle->isInhibited()); | ||||
353 | QCOMPARE(inhibitedSpy.count(), 3); | ||||
354 | | ||||
355 | // Destroy the test client. | ||||
356 | shellSurface.reset(); | ||||
357 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||||
358 | QTRY_VERIFY(!idle->isInhibited()); | ||||
359 | QCOMPARE(inhibitedSpy.count(), 4); | ||||
360 | } | ||||
361 | | ||||
128 | WAYLANDTEST_MAIN(TestIdleInhibition) | 362 | WAYLANDTEST_MAIN(TestIdleInhibition) | ||
129 | #include "idle_inhibition_test.moc" | 363 | #include "idle_inhibition_test.moc" |