Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/dont_crash_reinitialize_compositor.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | | ||||
21 | #include "kwin_wayland_test.h" | ||||
22 | | ||||
23 | #include "abstract_client.h" | ||||
24 | #include "composite.h" | ||||
25 | #include "deleted.h" | ||||
26 | #include "effects.h" | ||||
27 | #include "platform.h" | ||||
28 | #include "screens.h" | ||||
29 | #include "shell_client.h" | ||||
30 | #include "wayland_server.h" | ||||
31 | #include "workspace.h" | ||||
32 | | ||||
33 | #include <KWayland/Client/surface.h> | ||||
34 | #include <KWayland/Client/xdgshell.h> | ||||
35 | | ||||
36 | namespace KWin | ||||
37 | { | ||||
38 | | ||||
39 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_dont_crash_reinitialize_compositor-0"); | ||||
40 | | ||||
41 | class DontCrashReinitializeCompositorTest : public QObject | ||||
42 | { | ||||
43 | Q_OBJECT | ||||
44 | | ||||
45 | private Q_SLOTS: | ||||
46 | void initTestCase(); | ||||
47 | void init(); | ||||
48 | void cleanup(); | ||||
49 | | ||||
50 | void testReinitializeCompositor_data(); | ||||
51 | void testReinitializeCompositor(); | ||||
52 | }; | ||||
53 | | ||||
54 | void DontCrashReinitializeCompositorTest::initTestCase() | ||||
55 | { | ||||
56 | qputenv("XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8()); | ||||
57 | | ||||
58 | qRegisterMetaType<KWin::AbstractClient *>(); | ||||
59 | qRegisterMetaType<KWin::Deleted *>(); | ||||
60 | qRegisterMetaType<KWin::ShellClient *>(); | ||||
61 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||||
62 | QVERIFY(workspaceCreatedSpy.isValid()); | ||||
63 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||||
64 | QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2)); | ||||
65 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||||
66 | | ||||
67 | qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2")); | ||||
68 | qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", QByteArrayLiteral("1")); | ||||
69 | | ||||
70 | kwinApp()->start(); | ||||
71 | QVERIFY(workspaceCreatedSpy.wait()); | ||||
72 | QCOMPARE(screens()->count(), 2); | ||||
73 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||||
74 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||||
75 | waylandServer()->initWorkspace(); | ||||
76 | } | ||||
77 | | ||||
78 | void DontCrashReinitializeCompositorTest::init() | ||||
79 | { | ||||
80 | QVERIFY(Test::setupWaylandConnection()); | ||||
81 | } | ||||
82 | | ||||
83 | void DontCrashReinitializeCompositorTest::cleanup() | ||||
84 | { | ||||
85 | Test::destroyWaylandConnection(); | ||||
86 | } | ||||
87 | | ||||
88 | void DontCrashReinitializeCompositorTest::testReinitializeCompositor_data() | ||||
89 | { | ||||
90 | QTest::addColumn<QString>("effectName"); | ||||
91 | | ||||
92 | QTest::newRow("Fade") << QStringLiteral("kwin4_effect_fade"); | ||||
93 | QTest::newRow("Glide") << QStringLiteral("glide"); | ||||
94 | QTest::newRow("Scale") << QStringLiteral("kwin4_effect_scale"); | ||||
95 | } | ||||
96 | | ||||
97 | void DontCrashReinitializeCompositorTest::testReinitializeCompositor() | ||||
98 | { | ||||
99 | // This test verifies that KWin doesn't crash when the compositor settings | ||||
100 | // have been changed while a scripted effect animates the disappearing of | ||||
101 | // a window. | ||||
102 | | ||||
103 | // Make sure that we have the right effects ptr. | ||||
104 | auto effectsImpl = qobject_cast<EffectsHandlerImpl *>(effects); | ||||
105 | QVERIFY(effectsImpl); | ||||
106 | | ||||
107 | // Unload all effects. | ||||
108 | effectsImpl->unloadAllEffects(); | ||||
109 | QVERIFY(effectsImpl->loadedEffects().isEmpty()); | ||||
110 | | ||||
111 | // Create the test client. | ||||
112 | using namespace KWayland::Client; | ||||
113 | | ||||
114 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
115 | QVERIFY(!surface.isNull()); | ||||
116 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
117 | QVERIFY(!shellSurface.isNull()); | ||||
118 | ShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
119 | QVERIFY(client); | ||||
120 | | ||||
121 | // Make sure that only the test effect is loaded. | ||||
122 | QFETCH(QString, effectName); | ||||
123 | QVERIFY(effectsImpl->loadEffect(effectName)); | ||||
124 | QCOMPARE(effectsImpl->loadedEffects().count(), 1); | ||||
125 | QCOMPARE(effectsImpl->loadedEffects().first(), effectName); | ||||
126 | Effect *effect = effectsImpl->findEffect(effectName); | ||||
127 | QVERIFY(effect); | ||||
128 | QVERIFY(!effect->isActive()); | ||||
129 | | ||||
130 | // Close the test client. | ||||
131 | QSignalSpy windowClosedSpy(client, &ShellClient::windowClosed); | ||||
132 | QVERIFY(windowClosedSpy.isValid()); | ||||
133 | shellSurface.reset(); | ||||
134 | surface.reset(); | ||||
135 | QVERIFY(windowClosedSpy.wait()); | ||||
136 | | ||||
137 | // The test effect should start animating the test client. Is there a better | ||||
138 | // way to verify that the test effect actually animates the test client? | ||||
139 | QVERIFY(effect->isActive()); | ||||
140 | | ||||
141 | // Re-initialize the compositor, effects will be destroyed and created again. | ||||
142 | Compositor::self()->slotReinitialize(); | ||||
143 | | ||||
144 | // By this time, KWin should still be alive. | ||||
145 | } | ||||
146 | | ||||
147 | } // namespace KWin | ||||
148 | | ||||
149 | WAYLANDTEST_MAIN(KWin::DontCrashReinitializeCompositorTest) | ||||
150 | #include "dont_crash_reinitialize_compositor.moc" |