autotests/integration: test restoration of window states on moveresize cancel

This commit is contained in:
Xaver Hugl 2023-01-23 16:35:30 +01:00
parent 9f2ed2083c
commit 58fdbbc444
3 changed files with 79 additions and 0 deletions

View file

@ -553,6 +553,7 @@ void pointerAxisVertical(qreal delta,
void pointerButtonPressed(quint32 button, quint32 time); void pointerButtonPressed(quint32 button, quint32 time);
void pointerButtonReleased(quint32 button, quint32 time); void pointerButtonReleased(quint32 button, quint32 time);
void pointerMotion(const QPointF &position, quint32 time); void pointerMotion(const QPointF &position, quint32 time);
void pointerMotionRelative(const QPointF &delta, quint32 time);
void touchCancel(); void touchCancel();
void touchDown(qint32 id, const QPointF &pos, quint32 time); void touchDown(qint32 id, const QPointF &pos, quint32 time);
void touchMotion(qint32 id, const QPointF &pos, quint32 time); void touchMotion(qint32 id, const QPointF &pos, quint32 time);

View file

@ -70,6 +70,8 @@ private Q_SLOTS:
void testResizeForVirtualKeyboardWithFullScreen(); void testResizeForVirtualKeyboardWithFullScreen();
void testDestroyMoveClient(); void testDestroyMoveClient();
void testDestroyResizeClient(); void testDestroyResizeClient();
void testCancelInteractiveMoveResize_data();
void testCancelInteractiveMoveResize();
private: private:
KWayland::Client::ConnectionThread *m_connection = nullptr; KWayland::Client::ConnectionThread *m_connection = nullptr;
@ -1074,6 +1076,76 @@ void MoveResizeWindowTest::testDestroyResizeClient()
QCOMPARE(workspace()->moveResizeWindow(), nullptr); QCOMPARE(workspace()->moveResizeWindow(), nullptr);
} }
void MoveResizeWindowTest::testCancelInteractiveMoveResize_data()
{
QTest::addColumn<QuickTileMode>("quickTileMode");
QTest::addColumn<MaximizeMode>("maximizeMode");
QTest::newRow("quicktile_bottom") << QuickTileMode(QuickTileFlag::Bottom) << MaximizeMode::MaximizeRestore;
QTest::newRow("quicktile_top") << QuickTileMode(QuickTileFlag::Top) << MaximizeMode::MaximizeRestore;
QTest::newRow("quicktile_left") << QuickTileMode(QuickTileFlag::Left) << MaximizeMode::MaximizeRestore;
QTest::newRow("quicktile_right") << QuickTileMode(QuickTileFlag::Right) << MaximizeMode::MaximizeRestore;
QTest::newRow("maximize_vertical") << QuickTileMode(QuickTileFlag::None) << MaximizeMode::MaximizeVertical;
QTest::newRow("maximize_horizontal") << QuickTileMode(QuickTileFlag::None) << MaximizeMode::MaximizeHorizontal;
QTest::newRow("maximize_full") << QuickTileMode(QuickTileFlag::Maximize) << MaximizeMode::MaximizeFull;
}
void MoveResizeWindowTest::testCancelInteractiveMoveResize()
{
// This test verifies that after moveresize is cancelled, all relevant window states are restored
// to what they were before moveresize began
// Create the test client.
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
QVERIFY(surface != nullptr);
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
QVERIFY(shellSurface != nullptr);
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
QVERIFY(window);
// tile / maximize window
QFETCH(QuickTileMode, quickTileMode);
QFETCH(MaximizeMode, maximizeMode);
if (maximizeMode) {
window->setMaximize(maximizeMode & MaximizeMode::MaximizeVertical, maximizeMode & MaximizeMode::MaximizeHorizontal);
} else {
window->setQuickTileMode(quickTileMode, true);
}
QCOMPARE(window->quickTileMode(), quickTileMode);
QCOMPARE(window->requestedMaximizeMode(), maximizeMode);
QSignalSpy toplevelConfigureRequestedSpy(shellSurface.get(), &Test::XdgToplevel::configureRequested);
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
QVERIFY(surfaceConfigureRequestedSpy.wait());
Test::render(surface.get(), toplevelConfigureRequestedSpy.last().first().toSize(), Qt::blue);
const QRectF geometry = window->moveResizeGeometry();
const QRectF geometryRestore = window->geometryRestore();
// Start resizing the client.
QSignalSpy clientStartMoveResizedSpy(window, &Window::clientStartUserMovedResized);
QSignalSpy clientFinishUserMovedResizedSpy(window, &Window::clientFinishUserMovedResized);
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
QCOMPARE(window->isInteractiveMove(), false);
QCOMPARE(window->isInteractiveResize(), false);
workspace()->slotWindowResize();
QCOMPARE(clientStartMoveResizedSpy.count(), 1);
QCOMPARE(workspace()->moveResizeWindow(), window);
QCOMPARE(window->isInteractiveMove(), false);
QCOMPARE(window->isInteractiveResize(), true);
Test::pointerMotionRelative(QPoint(1, 1), 1);
QCOMPARE(window->quickTileMode(), QuickTileMode());
QCOMPARE(window->requestedMaximizeMode(), MaximizeMode::MaximizeRestore);
// cancel moveresize, all state from before should be restored
window->keyPressEvent(Qt::Key::Key_Escape);
QCOMPARE(window->moveResizeGeometry(), geometry);
QCOMPARE(window->quickTileMode(), quickTileMode);
QCOMPARE(window->requestedMaximizeMode(), maximizeMode);
QCOMPARE(window->geometryRestore(), geometryRestore);
}
} }
WAYLANDTEST_MAIN(KWin::MoveResizeWindowTest) WAYLANDTEST_MAIN(KWin::MoveResizeWindowTest)

View file

@ -1423,6 +1423,12 @@ void pointerMotion(const QPointF &position, quint32 time)
Q_EMIT virtualPointer->pointerMotionAbsolute(position, std::chrono::milliseconds(time), virtualPointer); Q_EMIT virtualPointer->pointerMotionAbsolute(position, std::chrono::milliseconds(time), virtualPointer);
} }
void pointerMotionRelative(const QPointF &delta, quint32 time)
{
auto virtualPointer = static_cast<WaylandTestApplication *>(kwinApp())->virtualPointer();
Q_EMIT virtualPointer->pointerMotion(delta, delta, std::chrono::milliseconds(time), virtualPointer);
}
void touchCancel() void touchCancel()
{ {
auto virtualTouch = static_cast<WaylandTestApplication *>(kwinApp())->virtualTouch(); auto virtualTouch = static_cast<WaylandTestApplication *>(kwinApp())->virtualTouch();