2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-06-20 09:21:16 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2020-03-04 07:55:26 +00:00
|
|
|
#include "abstract_client.h"
|
2016-06-20 09:21:16 +00:00
|
|
|
#include "platform.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
2021-02-09 18:18:36 +00:00
|
|
|
#include "xwl/databridge.h"
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/datadevice_interface.h>
|
2016-06-20 09:21:16 +00:00
|
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
#include <QProcessEnvironment>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_xwayland_selections-0");
|
2016-06-20 09:21:16 +00:00
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
class XwaylandSelectionsTest : public QObject
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanup();
|
|
|
|
void testSync_data();
|
|
|
|
void testSync();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QProcess *m_copyProcess = nullptr;
|
|
|
|
QProcess *m_pasteProcess = nullptr;
|
|
|
|
};
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
void XwaylandSelectionsTest::initTestCase()
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
2018-11-15 13:29:13 +00:00
|
|
|
QSKIP("Skipped as it fails for unknown reasons on build.kde.org");
|
2016-06-20 09:21:16 +00:00
|
|
|
qRegisterMetaType<KWin::AbstractClient*>();
|
|
|
|
qRegisterMetaType<QProcess::ExitStatus>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2016-06-20 09:21:16 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2018-08-21 20:06:42 +00:00
|
|
|
// QSignalSpy clipboardSyncDevicedCreated{waylandServer(), &WaylandServer::xclipboardSyncDataDeviceCreated};
|
|
|
|
// QVERIFY(clipboardSyncDevicedCreated.isValid());
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2019-08-26 21:16:53 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2016-06-20 09:21:16 +00:00
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2016-06-20 09:21:16 +00:00
|
|
|
QCOMPARE(screens()->count(), 2);
|
|
|
|
QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024));
|
|
|
|
waylandServer()->initWorkspace();
|
2018-08-21 20:06:42 +00:00
|
|
|
// // wait till the xclipboard sync data device is created
|
|
|
|
// if (clipboardSyncDevicedCreated.empty()) {
|
|
|
|
// QVERIFY(clipboardSyncDevicedCreated.wait());
|
|
|
|
// }
|
|
|
|
// wait till the DataBridge sync data device is created
|
|
|
|
while (Xwl::DataBridge::self()->dataDeviceIface() == nullptr) {
|
|
|
|
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
2018-08-21 20:06:42 +00:00
|
|
|
QVERIFY(Xwl::DataBridge::self()->dataDeviceIface() != nullptr);
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
void XwaylandSelectionsTest::cleanup()
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
|
|
|
if (m_copyProcess) {
|
|
|
|
m_copyProcess->terminate();
|
|
|
|
QVERIFY(m_copyProcess->waitForFinished());
|
|
|
|
m_copyProcess = nullptr;
|
|
|
|
}
|
|
|
|
if (m_pasteProcess) {
|
|
|
|
m_pasteProcess->terminate();
|
|
|
|
QVERIFY(m_pasteProcess->waitForFinished());
|
|
|
|
m_pasteProcess = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
void XwaylandSelectionsTest::testSync_data()
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("copyPlatform");
|
|
|
|
QTest::addColumn<QString>("pastePlatform");
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
QTest::newRow("x11->wayland") << QStringLiteral("xcb") << QStringLiteral("wayland");
|
|
|
|
QTest::newRow("wayland->x11") << QStringLiteral("wayland") << QStringLiteral("xcb");
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
void XwaylandSelectionsTest::testSync()
|
2016-06-20 09:21:16 +00:00
|
|
|
{
|
|
|
|
// this test verifies the syncing of X11 to Wayland clipboard
|
2017-08-25 16:18:20 +00:00
|
|
|
const QString copy = QFINDTESTDATA(QStringLiteral("copy"));
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(!copy.isEmpty());
|
2017-08-25 16:18:20 +00:00
|
|
|
const QString paste = QFINDTESTDATA(QStringLiteral("paste"));
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(!paste.isEmpty());
|
|
|
|
|
|
|
|
QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded);
|
|
|
|
QVERIFY(clientAddedSpy.isValid());
|
2020-04-29 15:18:41 +00:00
|
|
|
QSignalSpy clipboardChangedSpy(Xwl::DataBridge::self()->dataDeviceIface(), &KWaylandServer::DataDeviceInterface::selectionChanged);
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(clipboardChangedSpy.isValid());
|
|
|
|
|
|
|
|
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
|
2018-08-21 20:06:42 +00:00
|
|
|
|
|
|
|
// start the copy process
|
2016-06-20 09:21:16 +00:00
|
|
|
QFETCH(QString, copyPlatform);
|
|
|
|
environment.insert(QStringLiteral("QT_QPA_PLATFORM"), copyPlatform);
|
|
|
|
environment.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName);
|
|
|
|
m_copyProcess = new QProcess();
|
|
|
|
m_copyProcess->setProcessEnvironment(environment);
|
|
|
|
m_copyProcess->setProcessChannelMode(QProcess::ForwardedChannels);
|
|
|
|
m_copyProcess->setProgram(copy);
|
|
|
|
m_copyProcess->start();
|
|
|
|
QVERIFY(m_copyProcess->waitForStarted());
|
|
|
|
|
|
|
|
AbstractClient *copyClient = nullptr;
|
2020-07-22 18:35:41 +00:00
|
|
|
QVERIFY(clientAddedSpy.wait());
|
|
|
|
copyClient = clientAddedSpy.first().first().value<AbstractClient *>();
|
2016-06-20 09:21:16 +00:00
|
|
|
QVERIFY(copyClient);
|
|
|
|
if (workspace()->activeClient() != copyClient) {
|
|
|
|
workspace()->activateClient(copyClient);
|
|
|
|
}
|
|
|
|
QCOMPARE(workspace()->activeClient(), copyClient);
|
|
|
|
if (copyPlatform == QLatin1String("xcb")) {
|
|
|
|
QVERIFY(clipboardChangedSpy.isEmpty());
|
|
|
|
QVERIFY(clipboardChangedSpy.wait());
|
|
|
|
} else {
|
|
|
|
// TODO: it would be better to be able to connect to a signal, instead of waiting
|
|
|
|
// the idea is to make sure that the clipboard is updated, thus we need to give it
|
|
|
|
// enough time before starting the paste process which creates another window
|
|
|
|
QTest::qWait(250);
|
|
|
|
}
|
|
|
|
|
|
|
|
// start the paste process
|
|
|
|
m_pasteProcess = new QProcess();
|
|
|
|
QSignalSpy finishedSpy(m_pasteProcess, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished));
|
|
|
|
QVERIFY(finishedSpy.isValid());
|
|
|
|
QFETCH(QString, pastePlatform);
|
|
|
|
environment.insert(QStringLiteral("QT_QPA_PLATFORM"), pastePlatform);
|
|
|
|
m_pasteProcess->setProcessEnvironment(environment);
|
|
|
|
m_pasteProcess->setProcessChannelMode(QProcess::ForwardedChannels);
|
|
|
|
m_pasteProcess->setProgram(paste);
|
|
|
|
m_pasteProcess->start();
|
|
|
|
QVERIFY(m_pasteProcess->waitForStarted());
|
|
|
|
|
|
|
|
AbstractClient *pasteClient = nullptr;
|
2020-07-22 18:35:41 +00:00
|
|
|
QVERIFY(clientAddedSpy.wait());
|
|
|
|
pasteClient = clientAddedSpy.last().first().value<AbstractClient *>();
|
2016-06-20 09:21:16 +00:00
|
|
|
QCOMPARE(clientAddedSpy.count(), 1);
|
|
|
|
QVERIFY(pasteClient);
|
2018-08-21 20:06:42 +00:00
|
|
|
|
2016-06-20 09:21:16 +00:00
|
|
|
if (workspace()->activeClient() != pasteClient) {
|
2016-06-29 10:38:02 +00:00
|
|
|
QSignalSpy clientActivatedSpy(workspace(), &Workspace::clientActivated);
|
|
|
|
QVERIFY(clientActivatedSpy.isValid());
|
2016-06-20 09:21:16 +00:00
|
|
|
workspace()->activateClient(pasteClient);
|
2016-06-29 10:38:02 +00:00
|
|
|
QVERIFY(clientActivatedSpy.wait());
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
|
|
|
QTRY_COMPARE(workspace()->activeClient(), pasteClient);
|
|
|
|
QVERIFY(finishedSpy.wait());
|
|
|
|
QCOMPARE(finishedSpy.first().first().toInt(), 0);
|
|
|
|
delete m_pasteProcess;
|
|
|
|
m_pasteProcess = nullptr;
|
2018-08-21 20:06:42 +00:00
|
|
|
delete m_copyProcess;
|
|
|
|
m_copyProcess = nullptr;
|
2016-06-20 09:21:16 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 20:06:42 +00:00
|
|
|
WAYLANDTEST_MAIN(XwaylandSelectionsTest)
|
|
|
|
#include "xwayland_selections_test.moc"
|