File indexing completed on 2024-05-12 05:30:32

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 "compositor.h"
0012 #include "effect/effecthandler.h"
0013 #include "effect/effectloader.h"
0014 #include "scripting/scriptedeffect.h"
0015 #include "wayland_server.h"
0016 #include "window.h"
0017 #include "workspace.h"
0018 #include "x11window.h"
0019 
0020 #include <KDecoration2/Decoration>
0021 
0022 #include <KWayland/Client/compositor.h>
0023 #include <KWayland/Client/connection_thread.h>
0024 #include <KWayland/Client/shm_pool.h>
0025 #include <KWayland/Client/surface.h>
0026 
0027 #include <QSignalSpy>
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::Window *>();
0047     QVERIFY(waylandServer()->init(s_socketName));
0048     Test::setOutputConfig({
0049         QRect(0, 0, 1280, 1024),
0050         QRect(1280, 0, 1280, 1024),
0051     });
0052     kwinApp()->start();
0053     QVERIFY(Compositor::self());
0054     QSignalSpy compositorToggledSpy(Compositor::self(), &Compositor::compositingToggled);
0055     QVERIFY(compositorToggledSpy.wait());
0056     QVERIFY(effects);
0057 }
0058 
0059 void DontCrashCancelAnimationFromAnimationEndedTest::init()
0060 {
0061     QVERIFY(Test::setupWaylandConnection());
0062 }
0063 
0064 void DontCrashCancelAnimationFromAnimationEndedTest::cleanup()
0065 {
0066     Test::destroyWaylandConnection();
0067 }
0068 
0069 void DontCrashCancelAnimationFromAnimationEndedTest::testScript()
0070 {
0071     // load a scripted effect which deletes animation data
0072     ScriptedEffect *effect = ScriptedEffect::create(QStringLiteral("crashy"), QFINDTESTDATA("data/anim-data-delete-effect/effect.js"), 10, QString());
0073     QVERIFY(effect);
0074 
0075     const auto children = effects->children();
0076     for (auto it = children.begin(); it != children.end(); ++it) {
0077         if (qstrcmp((*it)->metaObject()->className(), "KWin::EffectLoader") != 0) {
0078             continue;
0079         }
0080         QVERIFY(QMetaObject::invokeMethod(*it, "effectLoaded", Q_ARG(KWin::Effect *, effect), Q_ARG(QString, QStringLiteral("crashy"))));
0081         break;
0082     }
0083     QVERIFY(effects->isEffectLoaded(QStringLiteral("crashy")));
0084 
0085     // create a window
0086     std::unique_ptr<KWayland::Client::Surface> surface{Test::createSurface()};
0087     QVERIFY(surface);
0088     Test::XdgToplevel *shellSurface = Test::createXdgToplevelSurface(surface.get(), surface.get());
0089     QVERIFY(shellSurface);
0090     // let's render
0091     Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
0092     QVERIFY(window);
0093     QCOMPARE(workspace()->activeWindow(), window);
0094 
0095     // make sure we animate
0096     QTest::qWait(200);
0097 
0098     // wait for the window to be passed to Deleted
0099     QSignalSpy windowDeletedSpy(window, &Window::closed);
0100 
0101     surface.reset();
0102 
0103     QVERIFY(windowDeletedSpy.wait());
0104     // make sure we animate
0105     QTest::qWait(200);
0106 }
0107 
0108 }
0109 
0110 WAYLANDTEST_MAIN(KWin::DontCrashCancelAnimationFromAnimationEndedTest)
0111 #include "dont_crash_cancel_animation.moc"