From e2682c840575ab263bb954059b0f890ea30ea163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Sat, 24 Jun 2017 20:31:50 +0200 Subject: [PATCH] [autotests] Extend pointer constraints test for closing window of locked pointer --- .../integration/pointer_constraints_test.cpp | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/autotests/integration/pointer_constraints_test.cpp b/autotests/integration/pointer_constraints_test.cpp index 602c9b68ea..e2b825c3ff 100644 --- a/autotests/integration/pointer_constraints_test.cpp +++ b/autotests/integration/pointer_constraints_test.cpp @@ -64,6 +64,8 @@ private Q_SLOTS: void testLockedPointer(); void testBreakConstrainedPointer_data(); void testBreakConstrainedPointer(); + void testCloseWindowWithLockedPointer_data(); + void testCloseWindowWithLockedPointer(); }; void TestPointerConstraints::initTestCase() @@ -385,5 +387,46 @@ void TestPointerConstraints::testBreakConstrainedPointer() kwinApp()->platform()->keyboardKeyReleased(KEY_ESC, timestamp++); } +void TestPointerConstraints::testCloseWindowWithLockedPointer_data() +{ + QTest::addColumn("type"); + + QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell; + QTest::newRow("XdgShellV5") << Test::ShellSurfaceType::XdgShellV5; +} + +void TestPointerConstraints::testCloseWindowWithLockedPointer() +{ + // test case which verifies that the pointer gets unlocked when the window for it gets closed + QScopedPointer surface(Test::createSurface()); + QFETCH(Test::ShellSurfaceType, type); + QScopedPointer shellSurface(Test::createShellSurface(type, surface.data())); + QScopedPointer pointer(Test::waylandSeat()->createPointer()); + QScopedPointer lockedPointer(Test::waylandPointerConstraints()->lockPointer(surface.data(), pointer.data(), nullptr, PointerConstraints::LifeTime::OneShot)); + QSignalSpy lockedSpy(lockedPointer.data(), &LockedPointer::locked); + QVERIFY(lockedSpy.isValid()); + QSignalSpy unlockedSpy(lockedPointer.data(), &LockedPointer::unlocked); + QVERIFY(unlockedSpy.isValid()); + + // now map the window + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 100), Qt::blue); + QVERIFY(c); + QVERIFY(!c->geometry().contains(KWin::Cursor::pos())); + + // now let's lock + QCOMPARE(input()->pointer()->isConstrained(), false); + KWin::Cursor::setPos(c->geometry().center()); + QCOMPARE(KWin::Cursor::pos(), c->geometry().center()); + QCOMPARE(input()->pointer()->isConstrained(), true); + QVERIFY(lockedSpy.wait()); + + // close the window + shellSurface.reset(); + surface.reset(); + // this should result in unlocked + QVERIFY(unlockedSpy.wait()); + QCOMPARE(input()->pointer()->isConstrained(), false); +} + WAYLANDTEST_MAIN(TestPointerConstraints) #include "pointer_constraints_test.moc"