File indexing completed on 2025-03-23 13:47:56
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "kwin_wayland_test.h" 0010 0011 #include "composite.h" 0012 #include "core/outputbackend.h" 0013 #include "deleted.h" 0014 #include "effectloader.h" 0015 #include "effects.h" 0016 #include "scripting/scriptedeffect.h" 0017 #include "wayland_server.h" 0018 #include "window.h" 0019 #include "workspace.h" 0020 #include "x11window.h" 0021 0022 #include <KDecoration2/Decoration> 0023 0024 #include <KWayland/Client/compositor.h> 0025 #include <KWayland/Client/connection_thread.h> 0026 #include <KWayland/Client/shm_pool.h> 0027 #include <KWayland/Client/surface.h> 0028 0029 namespace KWin 0030 { 0031 0032 static const QString s_socketName = QStringLiteral("wayland_test_kwin_dont_crash_cancel_animation-0"); 0033 0034 class DontCrashCancelAnimationFromAnimationEndedTest : public QObject 0035 { 0036 Q_OBJECT 0037 private Q_SLOTS: 0038 void initTestCase(); 0039 void init(); 0040 void cleanup(); 0041 void testScript(); 0042 }; 0043 0044 void DontCrashCancelAnimationFromAnimationEndedTest::initTestCase() 0045 { 0046 qRegisterMetaType<KWin::Deleted *>(); 0047 qRegisterMetaType<KWin::Window *>(); 0048 QVERIFY(waylandServer()->init(s_socketName)); 0049 QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024))); 0050 kwinApp()->start(); 0051 QVERIFY(Compositor::self()); 0052 QSignalSpy compositorToggledSpy(Compositor::self(), &Compositor::compositingToggled); 0053 QVERIFY(compositorToggledSpy.wait()); 0054 QVERIFY(effects); 0055 } 0056 0057 void DontCrashCancelAnimationFromAnimationEndedTest::init() 0058 { 0059 QVERIFY(Test::setupWaylandConnection()); 0060 } 0061 0062 void DontCrashCancelAnimationFromAnimationEndedTest::cleanup() 0063 { 0064 Test::destroyWaylandConnection(); 0065 } 0066 0067 void DontCrashCancelAnimationFromAnimationEndedTest::testScript() 0068 { 0069 // load a scripted effect which deletes animation data 0070 ScriptedEffect *effect = ScriptedEffect::create(QStringLiteral("crashy"), QFINDTESTDATA("data/anim-data-delete-effect/effect.js"), 10, QString()); 0071 QVERIFY(effect); 0072 0073 const auto children = effects->children(); 0074 for (auto it = children.begin(); it != children.end(); ++it) { 0075 if (qstrcmp((*it)->metaObject()->className(), "KWin::EffectLoader") != 0) { 0076 continue; 0077 } 0078 QVERIFY(QMetaObject::invokeMethod(*it, "effectLoaded", Q_ARG(KWin::Effect *, effect), Q_ARG(QString, QStringLiteral("crashy")))); 0079 break; 0080 } 0081 QVERIFY(static_cast<EffectsHandlerImpl *>(effects)->isEffectLoaded(QStringLiteral("crashy"))); 0082 0083 // create a window 0084 std::unique_ptr<KWayland::Client::Surface> surface{Test::createSurface()}; 0085 QVERIFY(surface); 0086 Test::XdgToplevel *shellSurface = Test::createXdgToplevelSurface(surface.get(), surface.get()); 0087 QVERIFY(shellSurface); 0088 // let's render 0089 Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue); 0090 QVERIFY(window); 0091 QCOMPARE(workspace()->activeWindow(), window); 0092 0093 // make sure we animate 0094 QTest::qWait(200); 0095 0096 // wait for the window to be passed to Deleted 0097 QSignalSpy windowDeletedSpy(window, &Window::windowClosed); 0098 0099 surface.reset(); 0100 0101 QVERIFY(windowDeletedSpy.wait()); 0102 // make sure we animate 0103 QTest::qWait(200); 0104 } 0105 0106 } 0107 0108 WAYLANDTEST_MAIN(KWin::DontCrashCancelAnimationFromAnimationEndedTest) 0109 #include "dont_crash_cancel_animation.moc"