kwin/autotests/integration/idle_inhibition_test.cpp
Vlad Zagorodniy 437d35eee2 [wayland] Check presence of the inhibitor object when a client is registered in IdleInhibition
Summary:
Some applications are not able to inhibit the idle behavior because
each of them creates an inhibitor object before the corresponding
ShellClient object becomes ready for painting.

BUG: 401499
FIXED-IN: 5.15.0

Test Plan: idle-inhibit client (from wlroots/examples) works.

Reviewers: #kwin, graesslin

Reviewed By: #kwin, graesslin

Subscribers: davidedmundson, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D17227
2018-11-29 18:17:34 +02:00

129 lines
4 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kwin_wayland_test.h"
#include "shell_client.h"
#include "wayland_server.h"
#include "workspace.h"
#include <KWayland/Client/idleinhibit.h>
#include <KWayland/Client/surface.h>
#include <KWayland/Client/xdgshell.h>
#include <KWayland/Server/display.h>
#include <KWayland/Server/idle_interface.h>
using namespace KWin;
using namespace KWayland::Client;
using KWayland::Server::IdleInterface;
static const QString s_socketName = QStringLiteral("wayland_test_kwin_idle_inhbition_test-0");
class TestIdleInhibition : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void testInhibit_data();
void testInhibit();
};
void TestIdleInhibition::initTestCase()
{
qRegisterMetaType<KWin::ShellClient*>();
qRegisterMetaType<KWin::AbstractClient*>();
QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
QVERIFY(workspaceCreatedSpy.isValid());
QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit()));
kwinApp()->start();
QVERIFY(workspaceCreatedSpy.wait());
waylandServer()->initWorkspace();
}
void TestIdleInhibition::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::IdleInhibition));
}
void TestIdleInhibition::cleanup()
{
Test::destroyWaylandConnection();
}
void TestIdleInhibition::testInhibit_data()
{
QTest::addColumn<Test::ShellSurfaceType>("type");
QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell;
QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5;
QTest::newRow("xdgShellV6") << Test::ShellSurfaceType::XdgShellV6;
QTest::newRow("xdgWmBase") << Test::ShellSurfaceType::XdgShellStable;
}
void TestIdleInhibition::testInhibit()
{
auto idle = waylandServer()->display()->findChild<IdleInterface*>();
QVERIFY(idle);
QVERIFY(!idle->isInhibited());
QSignalSpy inhibitedSpy(idle, &IdleInterface::inhibitedChanged);
QVERIFY(inhibitedSpy.isValid());
// now create window
QScopedPointer<Surface> surface(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type);
QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data()));
// now create inhibition on window
QScopedPointer<IdleInhibitor> inhibitor(Test::waylandIdleInhibitManager()->createInhibitor(surface.data()));
QVERIFY(inhibitor->isValid());
// render the client
auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
QVERIFY(c);
// this should inhibit our server object
QVERIFY(idle->isInhibited());
// deleting the object should uninhibit again
inhibitor.reset();
QVERIFY(inhibitedSpy.wait());
QVERIFY(!idle->isInhibited());
// inhibit again and destroy window
Test::waylandIdleInhibitManager()->createInhibitor(surface.data(), surface.data());
QVERIFY(inhibitedSpy.wait());
QVERIFY(idle->isInhibited());
shellSurface.reset();
if (type == Test::ShellSurfaceType::WlShell) {
surface.reset();
}
QVERIFY(Test::waitForWindowDestroyed(c));
QTRY_VERIFY(!idle->isInhibited());
QCOMPARE(inhibitedSpy.count(), 4);
}
WAYLANDTEST_MAIN(TestIdleInhibition)
#include "idle_inhibition_test.moc"