Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/effects/desktop_switching_animation_test.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) 2019 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 "effectloader.h" | ||||
26 | #include "effects.h" | ||||
27 | #include "platform.h" | ||||
28 | #include "scene.h" | ||||
29 | #include "shell_client.h" | ||||
30 | #include "wayland_server.h" | ||||
31 | #include "workspace.h" | ||||
32 | | ||||
33 | #include "effect_builtins.h" | ||||
34 | | ||||
35 | #include <KWayland/Client/surface.h> | ||||
36 | #include <KWayland/Client/xdgshell.h> | ||||
37 | | ||||
38 | using namespace KWin; | ||||
39 | | ||||
40 | static const QString s_socketName = QStringLiteral("wayland_test_effects_desktop_switching_animation-0"); | ||||
41 | | ||||
42 | class DesktopSwitchingAnimationTest : public QObject | ||||
43 | { | ||||
44 | Q_OBJECT | ||||
45 | | ||||
46 | private Q_SLOTS: | ||||
47 | void initTestCase(); | ||||
48 | void init(); | ||||
49 | void cleanup(); | ||||
50 | | ||||
51 | void testSwitchDesktops_data(); | ||||
52 | void testSwitchDesktops(); | ||||
53 | }; | ||||
54 | | ||||
55 | void DesktopSwitchingAnimationTest::initTestCase() | ||||
56 | { | ||||
57 | qputenv("XDG_DATA_DIRS", QCoreApplication::applicationDirPath().toUtf8()); | ||||
58 | | ||||
59 | qRegisterMetaType<KWin::AbstractClient *>(); | ||||
60 | qRegisterMetaType<KWin::ShellClient *>(); | ||||
61 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||||
62 | QVERIFY(workspaceCreatedSpy.isValid()); | ||||
63 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||||
64 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||||
65 | | ||||
66 | auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); | ||||
67 | KConfigGroup plugins(config, QStringLiteral("Plugins")); | ||||
68 | ScriptedEffectLoader loader; | ||||
69 | const auto builtinNames = BuiltInEffects::availableEffectNames() << loader.listOfKnownEffects(); | ||||
70 | for (const QString &name : builtinNames) { | ||||
71 | plugins.writeEntry(name + QStringLiteral("Enabled"), false); | ||||
72 | } | ||||
73 | config->sync(); | ||||
74 | kwinApp()->setConfig(config); | ||||
75 | | ||||
76 | qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2")); | ||||
77 | qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", QByteArrayLiteral("1")); | ||||
78 | | ||||
79 | kwinApp()->start(); | ||||
80 | QVERIFY(workspaceCreatedSpy.wait()); | ||||
81 | waylandServer()->initWorkspace(); | ||||
82 | | ||||
83 | auto scene = Compositor::self()->scene(); | ||||
84 | QVERIFY(scene); | ||||
85 | QCOMPARE(scene->compositingType(), OpenGL2Compositing); | ||||
86 | } | ||||
87 | | ||||
88 | void DesktopSwitchingAnimationTest::init() | ||||
89 | { | ||||
90 | QVERIFY(Test::setupWaylandConnection()); | ||||
91 | } | ||||
92 | | ||||
93 | void DesktopSwitchingAnimationTest::cleanup() | ||||
94 | { | ||||
95 | auto effectsImpl = qobject_cast<EffectsHandlerImpl *>(effects); | ||||
96 | QVERIFY(effectsImpl); | ||||
97 | effectsImpl->unloadAllEffects(); | ||||
98 | QVERIFY(effectsImpl->loadedEffects().isEmpty()); | ||||
99 | | ||||
100 | VirtualDesktopManager::self()->setCount(1); | ||||
101 | | ||||
102 | Test::destroyWaylandConnection(); | ||||
103 | } | ||||
104 | | ||||
105 | void DesktopSwitchingAnimationTest::testSwitchDesktops_data() | ||||
106 | { | ||||
107 | QTest::addColumn<QString>("effectName"); | ||||
108 | | ||||
109 | QTest::newRow("Desktop Cube Animation") << QStringLiteral("cubeslide"); | ||||
110 | QTest::newRow("Fade Desktop") << QStringLiteral("kwin4_effect_fadedesktop"); | ||||
111 | QTest::newRow("Slide") << QStringLiteral("slide"); | ||||
112 | } | ||||
113 | | ||||
114 | void DesktopSwitchingAnimationTest::testSwitchDesktops() | ||||
115 | { | ||||
116 | // This test verifies that virtual desktop switching animation effects actually | ||||
117 | // try to animate switching between desktops. | ||||
118 | | ||||
119 | // We need at least 2 virtual desktops for the test. | ||||
120 | VirtualDesktopManager::self()->setCount(2); | ||||
121 | QCOMPARE(VirtualDesktopManager::self()->current(), 1u); | ||||
122 | QCOMPARE(VirtualDesktopManager::self()->count(), 2u); | ||||
123 | | ||||
124 | // The Fade Desktop effect will do nothing if there are no clients to fade, | ||||
125 | // so we have to create a dummy test client. | ||||
126 | using namespace KWayland::Client; | ||||
127 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
128 | QVERIFY(!surface.isNull()); | ||||
129 | QScopedPointer<XdgShellSurface> shellSurface(Test::createXdgShellStableSurface(surface.data())); | ||||
130 | QVERIFY(!shellSurface.isNull()); | ||||
131 | ShellClient *client = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); | ||||
132 | QVERIFY(client); | ||||
133 | QCOMPARE(client->desktops().count(), 1); | ||||
134 | QCOMPARE(client->desktops().first(), VirtualDesktopManager::self()->desktops().first()); | ||||
135 | | ||||
136 | // Load effect that will be tested. | ||||
137 | QFETCH(QString, effectName); | ||||
138 | auto effectsImpl = qobject_cast<EffectsHandlerImpl *>(effects); | ||||
139 | QVERIFY(effectsImpl); | ||||
140 | QVERIFY(effectsImpl->loadEffect(effectName)); | ||||
141 | QCOMPARE(effectsImpl->loadedEffects().count(), 1); | ||||
142 | QCOMPARE(effectsImpl->loadedEffects().first(), effectName); | ||||
143 | Effect *effect = effectsImpl->findEffect(effectName); | ||||
144 | QVERIFY(effect); | ||||
145 | QVERIFY(!effect->isActive()); | ||||
146 | | ||||
147 | // Switch to the second virtual desktop. | ||||
148 | VirtualDesktopManager::self()->setCurrent(2u); | ||||
149 | QCOMPARE(VirtualDesktopManager::self()->current(), 2u); | ||||
150 | QVERIFY(effect->isActive()); | ||||
151 | QCOMPARE(effects->activeFullScreenEffect(), effect); | ||||
152 | | ||||
153 | // Eventually, the animation will be complete. | ||||
154 | QTRY_VERIFY(!effect->isActive()); | ||||
155 | QTRY_COMPARE(effects->activeFullScreenEffect(), nullptr); | ||||
156 | | ||||
157 | // Destroy the test client. | ||||
158 | surface.reset(); | ||||
159 | QVERIFY(Test::waitForWindowDestroyed(client)); | ||||
160 | } | ||||
161 | | ||||
162 | WAYLANDTEST_MAIN(DesktopSwitchingAnimationTest) | ||||
163 | #include "desktop_switching_animation_test.moc" |