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(); | ||||
| 48 | }; | 51 | }; | ||
| 49 | 52 | | |||
| 50 | void TestIdleInhibition::initTestCase() | 53 | void TestIdleInhibition::initTestCase() | ||
| 51 | { | 54 | { | ||
| 52 | qRegisterMetaType<KWin::ShellClient*>(); | 55 | qRegisterMetaType<KWin::ShellClient*>(); | ||
| 53 | qRegisterMetaType<KWin::AbstractClient*>(); | 56 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
| 54 | 57 | | |||
| 55 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 58 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
| Show All 9 Lines | |||||
| 65 | { | 68 | { | ||
| 66 | QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::IdleInhibition)); | 69 | QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::IdleInhibition)); | ||
| 67 | 70 | | |||
| 68 | } | 71 | } | ||
| 69 | 72 | | |||
| 70 | void TestIdleInhibition::cleanup() | 73 | void TestIdleInhibition::cleanup() | ||
| 71 | { | 74 | { | ||
| 72 | Test::destroyWaylandConnection(); | 75 | Test::destroyWaylandConnection(); | ||
| 76 | | ||||
| 77 | VirtualDesktopManager::self()->setCount(1); | ||||
| 78 | QCOMPARE(VirtualDesktopManager::self()->count(), 1u); | ||||
| 73 | } | 79 | } | ||
| 74 | 80 | | |||
| 75 | void TestIdleInhibition::testInhibit_data() | 81 | void TestIdleInhibition::testInhibit_data() | ||
| 76 | { | 82 | { | ||
| 77 | QTest::addColumn<Test::ShellSurfaceType>("type"); | 83 | QTest::addColumn<Test::ShellSurfaceType>("type"); | ||
| 78 | 84 | | |||
| 79 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | 85 | QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; | ||
| 80 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | 86 | QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; | ||
| Show All 39 Lines | 92 | { | |||
| 120 | if (type == Test::ShellSurfaceType::WlShell) { | 126 | if (type == Test::ShellSurfaceType::WlShell) { | ||
| 121 | surface.reset(); | 127 | surface.reset(); | ||
| 122 | } | 128 | } | ||
| 123 | QVERIFY(Test::waitForWindowDestroyed(c)); | 129 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||
| 124 | QTRY_VERIFY(!idle->isInhibited()); | 130 | QTRY_VERIFY(!idle->isInhibited()); | ||
| 125 | QCOMPARE(inhibitedSpy.count(), 4); | 131 | QCOMPARE(inhibitedSpy.count(), 4); | ||
| 126 | } | 132 | } | ||
| 127 | 133 | | |||
| 134 | void TestIdleInhibition::testDontInhibitWhenNotOnCurrentDesktop() | ||||
| 135 | { | ||||
| 136 | // This test verifies that the idle inhibitor object is not honored when | ||||
| 137 | // the associated surface is not on the current virtual desktop. | ||||
| 138 | | ||||
| 139 | VirtualDesktopManager::self()->setCount(2); | ||||
| 140 | QCOMPARE(VirtualDesktopManager::self()->count(), 2u); | ||||
| 141 | | ||||
| 142 | // Get reference to the idle interface. | ||||
| 143 | auto idle = waylandServer()->display()->findChild<IdleInterface *>(); | ||||
| 144 | QVERIFY(idle); | ||||
| 145 | QVERIFY(!idle->isInhibited()); | ||||
| 146 | QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged); | ||||
| 147 | QVERIFY(inhibitedSpy.isValid()); | ||||
| 148 | | ||||
| 149 | // Create the test client. | ||||
| 150 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
| 151 | QVERIFY(!surface.isNull()); | ||||
| 152 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
| 153 | QVERIFY(!shellSurface.isNull()); | ||||
| 154 | | ||||
| 155 | // Create the inhibitor object. | ||||
| 156 | QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data())); | ||||
| 157 | QVERIFY(inhibitor->isValid()); | ||||
| 158 | | ||||
| 159 | // Render the client. | ||||
| 160 | auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
| 161 | QVERIFY(c); | ||||
| 162 | | ||||
| 163 | // The test client should be only on the first virtual desktop. | ||||
| 164 | QCOMPARE(c->desktops().count(), 1); | ||||
| 165 | QCOMPARE(c->desktops().first(), VirtualDesktopManager::self()->desktops().first()); | ||||
| 166 | | ||||
| 167 | // This should inhibit our server object. | ||||
| 168 | QVERIFY(idle->isInhibited()); | ||||
| 169 | QCOMPARE(inhibitedSpy.count(), 1); | ||||
| 170 | | ||||
| 171 | // Switch to the second virtual desktop. | ||||
| 172 | VirtualDesktopManager::self()->setCurrent(2); | ||||
| 173 | | ||||
| 174 | // The surface is no longer visible, so the compositor don't have to honor the | ||||
| 175 | // idle inhibitor object. | ||||
| 176 | QVERIFY(!idle->isInhibited()); | ||||
| 177 | QCOMPARE(inhibitedSpy.count(), 2); | ||||
| 178 | | ||||
| 179 | // Switch back to the first virtual desktop. | ||||
| 180 | VirtualDesktopManager::self()->setCurrent(1); | ||||
| 181 | | ||||
| 182 | // The test client became visible again, so the compositor has to honor the idle | ||||
| 183 | // inhibitor object back again. | ||||
| 184 | QVERIFY(idle->isInhibited()); | ||||
| 185 | QCOMPARE(inhibitedSpy.count(), 3); | ||||
| 186 | | ||||
| 187 | // Destroy the test client. | ||||
| 188 | shellSurface.reset(); | ||||
| 189 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||||
| 190 | QTRY_VERIFY(!idle->isInhibited()); | ||||
| 191 | QCOMPARE(inhibitedSpy.count(), 4); | ||||
| 192 | } | ||||
| 193 | | ||||
| 194 | void TestIdleInhibition::testDontInhibitWhenMinimized() | ||||
| 195 | { | ||||
| 196 | // This test verifies that the idle inhibitor object is not honored when the | ||||
| 197 | // associated surface is minimized. | ||||
| 198 | | ||||
| 199 | // Get reference to the idle interface. | ||||
| 200 | auto idle = waylandServer()->display()->findChild<IdleInterface *>(); | ||||
| 201 | QVERIFY(idle); | ||||
| 202 | QVERIFY(!idle->isInhibited()); | ||||
| 203 | QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged); | ||||
| 204 | QVERIFY(inhibitedSpy.isValid()); | ||||
| 205 | | ||||
| 206 | // Create the test client. | ||||
| 207 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
| 208 | QVERIFY(!surface.isNull()); | ||||
| 209 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
| 210 | QVERIFY(!shellSurface.isNull()); | ||||
| 211 | | ||||
| 212 | // Create the inhibitor object. | ||||
| 213 | QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data())); | ||||
| 214 | QVERIFY(inhibitor->isValid()); | ||||
| 215 | | ||||
| 216 | // Render the client. | ||||
| 217 | auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
| 218 | QVERIFY(c); | ||||
| 219 | | ||||
| 220 | // This should inhibit our server object. | ||||
| 221 | QVERIFY(idle->isInhibited()); | ||||
| 222 | QCOMPARE(inhibitedSpy.count(), 1); | ||||
| 223 | | ||||
| 224 | // Minimize the client, the idle inhibitor object should not be honored. | ||||
| 225 | c->minimize(); | ||||
| 226 | QVERIFY(!idle->isInhibited()); | ||||
| 227 | QCOMPARE(inhibitedSpy.count(), 2); | ||||
| 228 | | ||||
| 229 | // Unminimize the client, the idle inhibitor object should be honored back again. | ||||
| 230 | c->unminimize(); | ||||
| 231 | QVERIFY(idle->isInhibited()); | ||||
| 232 | QCOMPARE(inhibitedSpy.count(), 3); | ||||
| 233 | | ||||
| 234 | // Destroy the test client. | ||||
| 235 | shellSurface.reset(); | ||||
| 236 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||||
| 237 | QTRY_VERIFY(!idle->isInhibited()); | ||||
| 238 | QCOMPARE(inhibitedSpy.count(), 4); | ||||
| 239 | } | ||||
| 240 | | ||||
| 241 | void TestIdleInhibition::testDontInhibitWhenUnmapped() | ||||
| 242 | { | ||||
| 243 | // This test verifies that the idle inhibitor object is not honored by KWin | ||||
| 244 | // when the associated client is unmapped. | ||||
| 245 | | ||||
| 246 | // Get reference to the idle interface. | ||||
| 247 | auto idle = waylandServer()->display()->findChild<IdleInterface *>(); | ||||
| 248 | QVERIFY(idle); | ||||
| 249 | QVERIFY(!idle->isInhibited()); | ||||
| 250 | QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged); | ||||
| 251 | QVERIFY(inhibitedSpy.isValid()); | ||||
| 252 | | ||||
| 253 | // Create the test client. | ||||
| 254 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
| 255 | QVERIFY(!surface.isNull()); | ||||
| 256 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
| 257 | QVERIFY(!shellSurface.isNull()); | ||||
| 258 | | ||||
| 259 | // Create the inhibitor object. | ||||
| 260 | QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data())); | ||||
| 261 | QVERIFY(inhibitor->isValid()); | ||||
| 262 | | ||||
| 263 | // Render the client. | ||||
| 264 | auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
| 265 | QVERIFY(c); | ||||
| 266 | | ||||
| 267 | // This should inhibit our server object. | ||||
| 268 | QVERIFY(idle->isInhibited()); | ||||
| 269 | QCOMPARE(inhibitedSpy.count(), 1); | ||||
| 270 | | ||||
| 271 | // Unmap the client. | ||||
| 272 | QSignalSpy hiddenSpy(c, &ShellClient::windowHidden); | ||||
| 273 | QVERIFY(hiddenSpy.isValid()); | ||||
| 274 | surface->attachBuffer(Buffer::Ptr()); | ||||
| 275 | surface->commit(Surface::CommitFlag::None); | ||||
| 276 | QVERIFY(hiddenSpy.wait()); | ||||
| 277 | | ||||
| 278 | // The surface is no longer visible, so the compositor don't have to honor the | ||||
| 279 | // idle inhibitor object. | ||||
| 280 | QVERIFY(!idle->isInhibited()); | ||||
| 281 | QCOMPARE(inhibitedSpy.count(), 2); | ||||
| 282 | | ||||
| 283 | // Map the client. | ||||
| 284 | QSignalSpy windowShownSpy(c, &ShellClient::windowShown); | ||||
| 285 | QVERIFY(windowShownSpy.isValid()); | ||||
| 286 | Test::render(surface.data(), QSize(100, 50), Qt::blue); | ||||
| 287 | QVERIFY(windowShownSpy.wait()); | ||||
| 288 | | ||||
| 289 | // The test client became visible again, so the compositor has to honor the idle | ||||
| 290 | // inhibitor object back again. | ||||
| 291 | QVERIFY(idle->isInhibited()); | ||||
| 292 | QCOMPARE(inhibitedSpy.count(), 3); | ||||
| 293 | | ||||
| 294 | // Destroy the test client. | ||||
| 295 | shellSurface.reset(); | ||||
| 296 | QVERIFY(Test::waitForWindowDestroyed(c)); | ||||
| 297 | QTRY_VERIFY(!idle->isInhibited()); | ||||
| 298 | QCOMPARE(inhibitedSpy.count(), 4); | ||||
| 299 | } | ||||
| 300 | | ||||
| 128 | WAYLANDTEST_MAIN(TestIdleInhibition) | 301 | WAYLANDTEST_MAIN(TestIdleInhibition) | ||
| 129 | #include "idle_inhibition_test.moc" | 302 | #include "idle_inhibition_test.moc" | ||