KWin
Loading...
Searching...
No Matches
dont_crash_cancel_animation.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "kwin_wayland_test.h"
10
11#include "compositor.h"
13#include "effect/effectloader.h"
15#include "wayland_server.h"
16#include "window.h"
17#include "workspace.h"
18#include "x11window.h"
19
20#include <KDecoration2/Decoration>
21
22#include <KWayland/Client/compositor.h>
23#include <KWayland/Client/connection_thread.h>
24#include <KWayland/Client/shm_pool.h>
25#include <KWayland/Client/surface.h>
26
27#include <QSignalSpy>
28
29namespace KWin
30{
31
32static const QString s_socketName = QStringLiteral("wayland_test_kwin_dont_crash_cancel_animation-0");
33
35{
36 Q_OBJECT
37private Q_SLOTS:
38 void initTestCase();
39 void init();
40 void cleanup();
41 void testScript();
42};
43
44void DontCrashCancelAnimationFromAnimationEndedTest::initTestCase()
45{
46 qRegisterMetaType<KWin::Window *>();
47 QVERIFY(waylandServer()->init(s_socketName));
49 QRect(0, 0, 1280, 1024),
50 QRect(1280, 0, 1280, 1024),
51 });
52 kwinApp()->start();
53 QVERIFY(Compositor::self());
54 QSignalSpy compositorToggledSpy(Compositor::self(), &Compositor::compositingToggled);
55 QVERIFY(compositorToggledSpy.wait());
56 QVERIFY(effects);
57}
58
59void DontCrashCancelAnimationFromAnimationEndedTest::init()
60{
62}
63
64void DontCrashCancelAnimationFromAnimationEndedTest::cleanup()
65{
67}
68
69void DontCrashCancelAnimationFromAnimationEndedTest::testScript()
70{
71 // load a scripted effect which deletes animation data
72 ScriptedEffect *effect = ScriptedEffect::create(QStringLiteral("crashy"), QFINDTESTDATA("data/anim-data-delete-effect/effect.js"), 10, QString());
73 QVERIFY(effect);
74
75 const auto children = effects->children();
76 for (auto it = children.begin(); it != children.end(); ++it) {
77 if (qstrcmp((*it)->metaObject()->className(), "KWin::EffectLoader") != 0) {
78 continue;
79 }
80 QVERIFY(QMetaObject::invokeMethod(*it, "effectLoaded", Q_ARG(KWin::Effect *, effect), Q_ARG(QString, QStringLiteral("crashy"))));
81 break;
82 }
83 QVERIFY(effects->isEffectLoaded(QStringLiteral("crashy")));
84
85 // create a window
86 std::unique_ptr<KWayland::Client::Surface> surface{Test::createSurface()};
87 QVERIFY(surface);
88 Test::XdgToplevel *shellSurface = Test::createXdgToplevelSurface(surface.get(), surface.get());
89 QVERIFY(shellSurface);
90 // let's render
91 Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
92 QVERIFY(window);
93 QCOMPARE(workspace()->activeWindow(), window);
94
95 // make sure we animate
96 QTest::qWait(200);
97
98 // wait for the window to be passed to Deleted
99 QSignalSpy windowDeletedSpy(window, &Window::closed);
100
101 surface.reset();
102
103 QVERIFY(windowDeletedSpy.wait());
104 // make sure we animate
105 QTest::qWait(200);
106}
107
108}
109
111#include "dont_crash_cancel_animation.moc"
void compositingToggled(bool active)
static Compositor * self()
Base class for all KWin effects.
Definition effect.h:535
Q_SCRIPTABLE bool isEffectLoaded(const QString &name) const
static ScriptedEffect * create(const QString &effectName, const QString &pathToScript, int chainPosition, const QString &exclusiveCategory)
#define WAYLANDTEST_MAIN(TestObject)
Window * renderAndWaitForShown(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format=QImage::Format_ARGB32, int timeout=5000)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
std::unique_ptr< KWayland::Client::Surface > createSurface()
XdgToplevel * createXdgToplevelSurface(KWayland::Client::Surface *surface, QObject *parent=nullptr)
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
EffectsHandler * effects