2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2017-10-06 19:22:50 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
|
2017-10-06 19:22:50 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2021-04-23 18:40:04 +00:00
|
|
|
|
|
|
|
#include "kwin_wayland_test.h"
|
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/platform.h"
|
2021-04-23 18:40:04 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include "virtualkeyboard_dbus.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
|
2017-10-06 19:22:50 +00:00
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusPendingReply>
|
|
|
|
#include <QSignalSpy>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <QTest>
|
2017-10-06 19:22:50 +00:00
|
|
|
|
2021-02-23 15:12:38 +00:00
|
|
|
#include <virtualkeyboardinterface.h>
|
2017-10-06 19:22:50 +00:00
|
|
|
|
|
|
|
using KWin::VirtualKeyboardDBus;
|
2021-02-26 15:16:45 +00:00
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWin::Test;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_virtualkeyboarddbus-0");
|
2017-10-06 19:22:50 +00:00
|
|
|
|
|
|
|
class VirtualKeyboardDBusTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void testEnabled();
|
|
|
|
void testRequestEnabled_data();
|
|
|
|
void testRequestEnabled();
|
2021-06-22 13:28:45 +00:00
|
|
|
void init();
|
2021-02-26 15:16:45 +00:00
|
|
|
void cleanup();
|
2017-10-06 19:22:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void VirtualKeyboardDBusTest::initTestCase()
|
|
|
|
{
|
|
|
|
QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kwin.testvirtualkeyboard"));
|
2021-02-26 15:16:45 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2021-04-23 18:40:04 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2021-02-26 15:16:45 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2021-04-23 18:40:04 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2021-02-26 15:16:45 +00:00
|
|
|
|
|
|
|
static_cast<WaylandTestApplication *>(kwinApp())->setInputMethodServerToStart("internal");
|
|
|
|
kwinApp()->start();
|
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
QVERIFY(setupWaylandConnection(AdditionalWaylandInterface::Seat | AdditionalWaylandInterface::InputMethodV1 | AdditionalWaylandInterface::TextInputManagerV2 | AdditionalWaylandInterface::TextInputManagerV3));
|
2021-02-26 15:16:45 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 13:28:45 +00:00
|
|
|
void VirtualKeyboardDBusTest::init()
|
|
|
|
{
|
2022-07-20 10:14:27 +00:00
|
|
|
kwinApp()->inputMethod()->setEnabled(false);
|
2021-06-22 13:28:45 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 15:16:45 +00:00
|
|
|
void VirtualKeyboardDBusTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
2017-10-06 19:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboardDBusTest::testEnabled()
|
|
|
|
{
|
2022-07-20 10:14:27 +00:00
|
|
|
VirtualKeyboardDBus dbus(KWin::kwinApp()->inputMethod());
|
2021-02-23 15:12:38 +00:00
|
|
|
OrgKdeKwinVirtualKeyboardInterface iface(QStringLiteral("org.kde.kwin.testvirtualkeyboard"), QStringLiteral("/VirtualKeyboard"), QDBusConnection::sessionBus());
|
|
|
|
QSignalSpy helperChangedSpy(&iface, &OrgKdeKwinVirtualKeyboardInterface::enabledChanged);
|
2017-10-06 19:22:50 +00:00
|
|
|
QVERIFY(helperChangedSpy.isValid());
|
|
|
|
|
|
|
|
QCOMPARE(dbus.isEnabled(), false);
|
|
|
|
QCOMPARE(dbus.property("enabled").toBool(), false);
|
|
|
|
QSignalSpy enabledChangedSpy(&dbus, &VirtualKeyboardDBus::enabledChanged);
|
|
|
|
QVERIFY(enabledChangedSpy.isValid());
|
|
|
|
|
2021-02-23 15:12:38 +00:00
|
|
|
QVERIFY(iface.isValid());
|
|
|
|
QCOMPARE(iface.enabled(), false);
|
2017-10-06 19:22:50 +00:00
|
|
|
|
|
|
|
dbus.setEnabled(true);
|
|
|
|
QCOMPARE(enabledChangedSpy.count(), 1);
|
|
|
|
QVERIFY(helperChangedSpy.wait());
|
|
|
|
QCOMPARE(helperChangedSpy.count(), 1);
|
|
|
|
QCOMPARE(dbus.isEnabled(), true);
|
|
|
|
QCOMPARE(dbus.property("enabled").toBool(), true);
|
2021-02-23 15:12:38 +00:00
|
|
|
QCOMPARE(iface.enabled(), true);
|
2017-10-06 19:22:50 +00:00
|
|
|
|
|
|
|
// setting again to enabled should not change anything
|
|
|
|
dbus.setEnabled(true);
|
|
|
|
QCOMPARE(enabledChangedSpy.count(), 1);
|
|
|
|
|
|
|
|
// back to false
|
|
|
|
dbus.setEnabled(false);
|
|
|
|
QCOMPARE(enabledChangedSpy.count(), 2);
|
|
|
|
QVERIFY(helperChangedSpy.wait());
|
|
|
|
QCOMPARE(helperChangedSpy.count(), 2);
|
|
|
|
QCOMPARE(dbus.isEnabled(), false);
|
|
|
|
QCOMPARE(dbus.property("enabled").toBool(), false);
|
2021-02-23 15:12:38 +00:00
|
|
|
QCOMPARE(iface.enabled(), false);
|
2017-10-06 19:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboardDBusTest::testRequestEnabled_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("method");
|
|
|
|
QTest::addColumn<bool>("expectedResult");
|
|
|
|
|
2021-02-26 15:16:45 +00:00
|
|
|
QTest::newRow("enable") << QStringLiteral("setEnabled") << true;
|
|
|
|
QTest::newRow("disable") << QStringLiteral("setEnabled") << false;
|
2017-10-06 19:22:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VirtualKeyboardDBusTest::testRequestEnabled()
|
|
|
|
{
|
2021-02-23 15:12:38 +00:00
|
|
|
QFETCH(QString, method);
|
|
|
|
QFETCH(bool, expectedResult);
|
|
|
|
|
2022-07-20 10:14:27 +00:00
|
|
|
VirtualKeyboardDBus dbus(KWin::kwinApp()->inputMethod());
|
2021-02-23 15:12:38 +00:00
|
|
|
OrgKdeKwinVirtualKeyboardInterface iface(QStringLiteral("org.kde.kwin.testvirtualkeyboard"), QStringLiteral("/VirtualKeyboard"), QDBusConnection::sessionBus());
|
2021-06-22 13:28:45 +00:00
|
|
|
|
2021-02-26 15:16:45 +00:00
|
|
|
iface.setEnabled(expectedResult);
|
2021-06-22 13:28:45 +00:00
|
|
|
QTRY_COMPARE(iface.enabled(), expectedResult);
|
2017-10-06 19:22:50 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 15:16:45 +00:00
|
|
|
WAYLANDTEST_MAIN(VirtualKeyboardDBusTest)
|
2017-10-06 19:22:50 +00:00
|
|
|
#include "test_virtualkeyboard_dbus.moc"
|