KWin
Loading...
Searching...
No Matches
dont_crash_glxgears.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: 2015 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 "wayland_server.h"
12#include "window.h"
13#include "workspace.h"
14#include "x11window.h"
15
16#include <KDecoration2/Decoration>
17
18#include <QSignalSpy>
19
20namespace KWin
21{
22
23static const QString s_socketName = QStringLiteral("wayland_test_kwin_dont_crash_glxgears-0");
24
25class DontCrashGlxgearsTest : public QObject
26{
27 Q_OBJECT
28private Q_SLOTS:
29 void initTestCase();
30 void testGlxgears();
31};
32
33void DontCrashGlxgearsTest::initTestCase()
34{
35 qRegisterMetaType<KWin::Window *>();
36 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
37 QVERIFY(waylandServer()->init(s_socketName));
39 QRect(0, 0, 1280, 1024),
40 QRect(1280, 0, 1280, 1024),
41 });
42 kwinApp()->start();
43 QVERIFY(applicationStartedSpy.wait());
44}
45
46void DontCrashGlxgearsTest::testGlxgears()
47{
48 // closing a glxgears window through Aurorae themes used to crash KWin
49 // Let's make sure that doesn't happen anymore
50
51 QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
52
53 QProcess glxgears;
54 glxgears.setProgram(QStringLiteral("glxgears"));
55 glxgears.start();
56 QVERIFY(glxgears.waitForStarted());
57
58 QVERIFY(windowAddedSpy.wait());
59 QCOMPARE(windowAddedSpy.count(), 1);
60 QCOMPARE(workspace()->windows().count(), 1);
61 Window *glxgearsWindow = workspace()->windows().first();
62 QVERIFY(glxgearsWindow->isDecorated());
63 QSignalSpy closedSpy(glxgearsWindow, &X11Window::closed);
64 KDecoration2::Decoration *decoration = glxgearsWindow->decoration();
65 QVERIFY(decoration);
66
67 // send a mouse event to the position of the close button
68 // TODO: position is dependent on the decoration in use. We should use a static target instead, a fake deco for autotests.
69 QPointF pos = decoration->rect().topRight() + QPointF(-decoration->borderTop() / 2, decoration->borderTop() / 2);
70 QHoverEvent event(QEvent::HoverMove, pos, pos);
71 QCoreApplication::instance()->sendEvent(decoration, &event);
72 // mouse press
73 QMouseEvent mousePressevent(QEvent::MouseButtonPress, pos, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
74 mousePressevent.setAccepted(false);
75 QCoreApplication::sendEvent(decoration, &mousePressevent);
76 QVERIFY(mousePressevent.isAccepted());
77 // mouse Release
78 QMouseEvent mouseReleaseEvent(QEvent::MouseButtonRelease, pos, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
79 mouseReleaseEvent.setAccepted(false);
80 QCoreApplication::sendEvent(decoration, &mouseReleaseEvent);
81 QVERIFY(mouseReleaseEvent.isAccepted());
82
83 QVERIFY(closedSpy.wait());
84 QCOMPARE(closedSpy.count(), 1);
85 xcb_flush(connection());
86
87 if (glxgears.state() == QProcess::Running) {
88 QVERIFY(glxgears.waitForFinished());
89 }
90}
91
92}
93
95#include "dont_crash_glxgears.moc"
void windowAdded(KWin::Window *)
const QList< Window * > windows() const
Definition workspace.h:248
#define WAYLANDTEST_MAIN(TestObject)
void setOutputConfig(const QList< QRect > &geometries)
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
KWIN_EXPORT xcb_connection_t * connection()
Definition xcb.h:19