diff --git a/autotests/integration/effects/CMakeLists.txt b/autotests/integration/effects/CMakeLists.txt index cf591c3cb..92b3a3f0f 100644 --- a/autotests/integration/effects/CMakeLists.txt +++ b/autotests/integration/effects/CMakeLists.txt @@ -1,12 +1,13 @@ if (XCB_ICCCM_FOUND) integrationTest(NAME testTranslucency SRCS translucency_test.cpp LIBS XCB::ICCCM) integrationTest(NAME testSlidingPopups SRCS slidingpopups_test.cpp LIBS XCB::ICCCM) integrationTest(NAME testShadeWobblyWindows SRCS wobbly_shade_test.cpp LIBS XCB::ICCCM) endif() integrationTest(NAME testFade SRCS fade_test.cpp) integrationTest(WAYLAND_ONLY NAME testEffectWindowGeometry SRCS windowgeometry_test.cpp) integrationTest(NAME testScriptedEffects SRCS scripted_effects_test.cpp) integrationTest(WAYLAND_ONLY NAME testToplevelOpenCloseAnimation SRCS toplevel_open_close_animation_test.cpp) integrationTest(WAYLAND_ONLY NAME testPopupOpenCloseAnimation SRCS popup_open_close_animation_test.cpp) integrationTest(WAYLAND_ONLY NAME testDesktopSwitchingAnimation SRCS desktop_switching_animation_test.cpp) integrationTest(WAYLAND_ONLY NAME testMinimizeAnimation SRCS minimize_animation_test.cpp) +integrationTest(WAYLAND_ONLY NAME testMaximizeAnimation SRCS maximize_animation_test.cpp) diff --git a/autotests/integration/effects/maximize_animation_test.cpp b/autotests/integration/effects/maximize_animation_test.cpp new file mode 100644 index 000000000..45c8b5acc --- /dev/null +++ b/autotests/integration/effects/maximize_animation_test.cpp @@ -0,0 +1,211 @@ +/******************************************************************** +KWin - the KDE window manager +This file is part of the KDE project. + +Copyright (C) 2019 Vlad Zagorodniy + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ + +#include "kwin_wayland_test.h" + +#include "abstract_client.h" +#include "composite.h" +#include "effectloader.h" +#include "effects.h" +#include "platform.h" +#include "scene.h" +#include "shell_client.h" +#include "wayland_server.h" +#include "workspace.h" + +#include "effect_builtins.h" + +#include +#include + +using namespace KWin; + +static const QString s_socketName = QStringLiteral("wayland_test_effects_maximize_animation-0"); + +class MaximizeAnimationTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase(); + void init(); + void cleanup(); + + void testMaximizeRestore_data(); + void testMaximizeRestore(); +}; + +void MaximizeAnimationTest::initTestCase() +{ + qputenv("XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8()); + + qRegisterMetaType(); + qRegisterMetaType(); + QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); + QVERIFY(workspaceCreatedSpy.isValid()); + kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); + QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); + + auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); + KConfigGroup plugins(config, QStringLiteral("Plugins")); + ScriptedEffectLoader loader; + const auto builtinNames = BuiltInEffects::availableEffectNames() << loader.listOfKnownEffects(); + for (const QString &name : builtinNames) { + plugins.writeEntry(name + QStringLiteral("Enabled"), false); + } + config->sync(); + kwinApp()->setConfig(config); + + qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", QByteArrayLiteral("1")); + + kwinApp()->start(); + QVERIFY(workspaceCreatedSpy.wait()); + waylandServer()->initWorkspace(); +} + +void MaximizeAnimationTest::init() +{ + QVERIFY(Test::setupWaylandConnection()); +} + +void MaximizeAnimationTest::cleanup() +{ + auto effectsImpl = qobject_cast(effects); + QVERIFY(effectsImpl); + effectsImpl->unloadAllEffects(); + QVERIFY(effectsImpl->loadedEffects().isEmpty()); + + Test::destroyWaylandConnection(); +} + +void MaximizeAnimationTest::testMaximizeRestore_data() +{ + QTest::addColumn("type"); + + QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5; + QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6; + QTest::newRow("xdgWmBase") << Test::ShellSurfaceType::XdgShellStable; +} + +void MaximizeAnimationTest::testMaximizeRestore() +{ + // This test verifies that the maximize effect animates a client + // when it's maximized or restored. + + using namespace KWayland::Client; + + // Create the test client. + QScopedPointer surface(Test::createSurface()); + QVERIFY(!surface.isNull()); + + QFETCH(Test::ShellSurfaceType, type); + QScopedPointer shellSurface(qobject_cast( + Test::createShellSurface(type, surface.data()))); + + // Wait for the initial configure event. + XdgShellSurface::States states; + QSignalSpy configureRequestedSpy(shellSurface.data(), &XdgShellSurface::configureRequested); + QVERIFY(configureRequestedSpy.isValid()); + QVERIFY(configureRequestedSpy.wait()); + QCOMPARE(configureRequestedSpy.count(), 1); + QCOMPARE(configureRequestedSpy.last().at(0).value(), QSize(0, 0)); + states = configureRequestedSpy.last().at(1).value(); + QVERIFY(!states.testFlag(XdgShellSurface::State::Activated)); + QVERIFY(!states.testFlag(XdgShellSurface::State::Maximized)); + + // Draw contents of the surface. + shellSurface->ackConfigure(configureRequestedSpy.last().at(2).value()); + ShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); + QVERIFY(client); + QVERIFY(client->isActive()); + QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeRestore); + + // We should receive a configure event when the client becomes active. + QVERIFY(configureRequestedSpy.wait()); + QCOMPARE(configureRequestedSpy.count(), 2); + states = configureRequestedSpy.last().at(1).value(); + QVERIFY(states.testFlag(XdgShellSurface::State::Activated)); + QVERIFY(!states.testFlag(XdgShellSurface::State::Maximized)); + + // Load effect that will be tested. + const QString effectName = QStringLiteral("kwin4_effect_maximize"); + auto effectsImpl = qobject_cast(effects); + QVERIFY(effectsImpl); + QVERIFY(effectsImpl->loadEffect(effectName)); + QCOMPARE(effectsImpl->loadedEffects().count(), 1); + QCOMPARE(effectsImpl->loadedEffects().first(), effectName); + Effect *effect = effectsImpl->findEffect(effectName); + QVERIFY(effect); + QVERIFY(!effect->isActive()); + + // Maximize the client. + QSignalSpy geometryChangedSpy(client, &ShellClient::geometryChanged); + QVERIFY(geometryChangedSpy.isValid()); + QSignalSpy maximizeChangedSpy(client, qOverload(&ShellClient::clientMaximizedStateChanged)); + QVERIFY(maximizeChangedSpy.isValid()); + + workspace()->slotWindowMaximize(); + QVERIFY(configureRequestedSpy.wait()); + QCOMPARE(configureRequestedSpy.count(), 3); + QCOMPARE(configureRequestedSpy.last().at(0).value(), QSize(1280, 1024)); + states = configureRequestedSpy.last().at(1).value(); + QVERIFY(states.testFlag(XdgShellSurface::State::Activated)); + QVERIFY(states.testFlag(XdgShellSurface::State::Maximized)); + + // Draw contents of the maximized client. + shellSurface->ackConfigure(configureRequestedSpy.last().at(2).value()); + Test::render(surface.data(), QSize(1280, 1024), Qt::red); + QVERIFY(geometryChangedSpy.wait()); + QCOMPARE(geometryChangedSpy.count(), 2); + QCOMPARE(maximizeChangedSpy.count(), 1); + QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeFull); + QVERIFY(effect->isActive()); + + // Eventually, the animation will be complete. + QTRY_VERIFY(!effect->isActive()); + + // Restore the client. + workspace()->slotWindowMaximize(); + QVERIFY(configureRequestedSpy.wait()); + QCOMPARE(configureRequestedSpy.count(), 4); + QCOMPARE(configureRequestedSpy.last().at(0).value(), QSize(100, 50)); + states = configureRequestedSpy.last().at(1).value(); + QVERIFY(states.testFlag(XdgShellSurface::State::Activated)); + QVERIFY(!states.testFlag(XdgShellSurface::State::Maximized)); + + // Draw contents of the restored client. + shellSurface->ackConfigure(configureRequestedSpy.last().at(2).value()); + Test::render(surface.data(), QSize(100, 50), Qt::blue); + QVERIFY(geometryChangedSpy.wait()); + QCOMPARE(geometryChangedSpy.count(), 4); + QCOMPARE(maximizeChangedSpy.count(), 2); + QCOMPARE(client->maximizeMode(), MaximizeMode::MaximizeRestore); + QVERIFY(effect->isActive()); + + // Eventually, the animation will be complete. + QTRY_VERIFY(!effect->isActive()); + + // Destroy the test client. + surface.reset(); + QVERIFY(Test::waitForWindowDestroyed(client)); +} + +WAYLANDTEST_MAIN(MaximizeAnimationTest) +#include "maximize_animation_test.moc"