Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/xclipboardsync_test.cpp
Show All 17 Lines | |||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "kwin_wayland_test.h" | 20 | #include "kwin_wayland_test.h" | ||
21 | #include "platform.h" | 21 | #include "platform.h" | ||
22 | #include "shell_client.h" | 22 | #include "shell_client.h" | ||
23 | #include "screens.h" | 23 | #include "screens.h" | ||
24 | #include "wayland_server.h" | 24 | #include "wayland_server.h" | ||
25 | #include "workspace.h" | 25 | #include "workspace.h" | ||
26 | #include "../../xwl/databridge.h" | ||||
26 | 27 | | |||
27 | #include <KWayland/Server/datadevice_interface.h> | 28 | #include <KWayland/Server/datadevice_interface.h> | ||
28 | 29 | | |||
29 | #include <QProcess> | 30 | #include <QProcess> | ||
30 | #include <QProcessEnvironment> | 31 | #include <QProcessEnvironment> | ||
31 | 32 | | |||
32 | using namespace KWin; | 33 | using namespace KWin; | ||
33 | 34 | | |||
Show All 25 Lines | 52 | { | |||
59 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | 60 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||
60 | 61 | | |||
61 | kwinApp()->start(); | 62 | kwinApp()->start(); | ||
62 | QVERIFY(workspaceCreatedSpy.wait()); | 63 | QVERIFY(workspaceCreatedSpy.wait()); | ||
63 | QCOMPARE(screens()->count(), 2); | 64 | QCOMPARE(screens()->count(), 2); | ||
64 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | 65 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||
65 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 66 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
66 | waylandServer()->initWorkspace(); | 67 | waylandServer()->initWorkspace(); | ||
67 | // wait till the xclipboard sync data device is created | 68 | // wait till the DataBridge sync data device is created | ||
68 | while (waylandServer()->xclipboardSyncDataDevice().isNull()) { | 69 | while (Xwl::DataBridge::self()->dataDeviceIface() == nullptr) { | ||
69 | QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); | 70 | QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); | ||
70 | } | 71 | } | ||
71 | QVERIFY(!waylandServer()->xclipboardSyncDataDevice().isNull()); | 72 | QVERIFY(Xwl::DataBridge::self()->dataDeviceIface() != nullptr); | ||
72 | } | 73 | } | ||
73 | 74 | | |||
74 | void XClipboardSyncTest::cleanup() | 75 | void XClipboardSyncTest::cleanup() | ||
75 | { | 76 | { | ||
76 | if (m_copyProcess) { | 77 | if (m_copyProcess) { | ||
77 | m_copyProcess->terminate(); | 78 | m_copyProcess->terminate(); | ||
78 | QVERIFY(m_copyProcess->waitForFinished()); | 79 | QVERIFY(m_copyProcess->waitForFinished()); | ||
79 | m_copyProcess = nullptr; | 80 | m_copyProcess = nullptr; | ||
80 | } | 81 | } | ||
81 | if (m_pasteProcess) { | 82 | if (m_pasteProcess) { | ||
82 | m_pasteProcess->terminate(); | 83 | m_pasteProcess->terminate(); | ||
83 | QVERIFY(m_pasteProcess->waitForFinished()); | 84 | QVERIFY(m_pasteProcess->waitForFinished()); | ||
84 | m_pasteProcess = nullptr; | 85 | m_pasteProcess = nullptr; | ||
85 | } | 86 | } | ||
86 | } | 87 | } | ||
87 | 88 | | |||
88 | void XClipboardSyncTest::testSync_data() | 89 | void XClipboardSyncTest::testSync_data() | ||
89 | { | 90 | { | ||
90 | QTest::addColumn<QString>("copyPlatform"); | 91 | QTest::addColumn<QString>("copyPlatform"); | ||
91 | QTest::addColumn<QString>("pastePlatform"); | 92 | QTest::addColumn<QString>("pastePlatform"); | ||
92 | 93 | | |||
93 | QTest::newRow("x11-wayland") << QStringLiteral("xcb") << QStringLiteral("wayland"); | 94 | QTest::newRow("x11->wayland") << QStringLiteral("xcb") << QStringLiteral("wayland"); | ||
94 | QTest::newRow("wayland-x11") << QStringLiteral("wayland") << QStringLiteral("xcb"); | 95 | QTest::newRow("wayland->x11") << QStringLiteral("wayland") << QStringLiteral("xcb"); | ||
95 | } | 96 | } | ||
96 | 97 | | |||
97 | void XClipboardSyncTest::testSync() | 98 | void XClipboardSyncTest::testSync() | ||
98 | { | 99 | { | ||
99 | // this test verifies the syncing of X11 to Wayland clipboard | 100 | // this test verifies the syncing of X11 to Wayland clipboard | ||
100 | const QString copy = QFINDTESTDATA(QStringLiteral("copy")); | 101 | const QString copy = QFINDTESTDATA(QStringLiteral("copy")); | ||
101 | QVERIFY(!copy.isEmpty()); | 102 | QVERIFY(!copy.isEmpty()); | ||
102 | const QString paste = QFINDTESTDATA(QStringLiteral("paste")); | 103 | const QString paste = QFINDTESTDATA(QStringLiteral("paste")); | ||
103 | QVERIFY(!paste.isEmpty()); | 104 | QVERIFY(!paste.isEmpty()); | ||
104 | 105 | | |||
105 | QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded); | 106 | QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded); | ||
106 | QVERIFY(clientAddedSpy.isValid()); | 107 | QVERIFY(clientAddedSpy.isValid()); | ||
107 | QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 108 | QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
108 | QVERIFY(shellClientAddedSpy.isValid()); | 109 | QVERIFY(shellClientAddedSpy.isValid()); | ||
109 | QSignalSpy clipboardChangedSpy(waylandServer()->xclipboardSyncDataDevice().data(), &KWayland::Server::DataDeviceInterface::selectionChanged); | 110 | QSignalSpy clipboardChangedSpy(Xwl::DataBridge::self()->dataDeviceIface(), &KWayland::Server::DataDeviceInterface::selectionChanged); | ||
110 | QVERIFY(clipboardChangedSpy.isValid()); | 111 | QVERIFY(clipboardChangedSpy.isValid()); | ||
111 | 112 | | |||
112 | QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); | 113 | QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); | ||
114 | | ||||
115 | // start the copy process | ||||
113 | QFETCH(QString, copyPlatform); | 116 | QFETCH(QString, copyPlatform); | ||
114 | environment.insert(QStringLiteral("QT_QPA_PLATFORM"), copyPlatform); | 117 | environment.insert(QStringLiteral("QT_QPA_PLATFORM"), copyPlatform); | ||
115 | environment.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName); | 118 | environment.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName); | ||
116 | m_copyProcess = new QProcess(); | 119 | m_copyProcess = new QProcess(); | ||
117 | m_copyProcess->setProcessEnvironment(environment); | 120 | m_copyProcess->setProcessEnvironment(environment); | ||
118 | m_copyProcess->setProcessChannelMode(QProcess::ForwardedChannels); | 121 | m_copyProcess->setProcessChannelMode(QProcess::ForwardedChannels); | ||
119 | m_copyProcess->setProgram(copy); | 122 | m_copyProcess->setProgram(copy); | ||
120 | m_copyProcess->start(); | 123 | m_copyProcess->start(); | ||
Show All 40 Lines | 162 | if (pastePlatform == QLatin1String("xcb")) { | |||
161 | pasteClient = clientAddedSpy.last().first().value<AbstractClient*>(); | 164 | pasteClient = clientAddedSpy.last().first().value<AbstractClient*>(); | ||
162 | } else { | 165 | } else { | ||
163 | QVERIFY(shellClientAddedSpy.wait()); | 166 | QVERIFY(shellClientAddedSpy.wait()); | ||
164 | pasteClient = shellClientAddedSpy.last().first().value<AbstractClient*>(); | 167 | pasteClient = shellClientAddedSpy.last().first().value<AbstractClient*>(); | ||
165 | } | 168 | } | ||
166 | QCOMPARE(clientAddedSpy.count(), 1); | 169 | QCOMPARE(clientAddedSpy.count(), 1); | ||
167 | QCOMPARE(shellClientAddedSpy.count(), 1); | 170 | QCOMPARE(shellClientAddedSpy.count(), 1); | ||
168 | QVERIFY(pasteClient); | 171 | QVERIFY(pasteClient); | ||
172 | | ||||
169 | if (workspace()->activeClient() != pasteClient) { | 173 | if (workspace()->activeClient() != pasteClient) { | ||
170 | QSignalSpy clientActivatedSpy(workspace(), &Workspace::clientActivated); | 174 | QSignalSpy clientActivatedSpy(workspace(), &Workspace::clientActivated); | ||
171 | QVERIFY(clientActivatedSpy.isValid()); | 175 | QVERIFY(clientActivatedSpy.isValid()); | ||
172 | workspace()->activateClient(pasteClient); | 176 | workspace()->activateClient(pasteClient); | ||
173 | QVERIFY(clientActivatedSpy.wait()); | 177 | QVERIFY(clientActivatedSpy.wait()); | ||
174 | } | 178 | } | ||
175 | QTRY_COMPARE(workspace()->activeClient(), pasteClient); | 179 | QTRY_COMPARE(workspace()->activeClient(), pasteClient); | ||
176 | QVERIFY(finishedSpy.wait()); | 180 | QVERIFY(finishedSpy.wait()); | ||
177 | QCOMPARE(finishedSpy.first().first().toInt(), 0); | 181 | QCOMPARE(finishedSpy.first().first().toInt(), 0); | ||
178 | delete m_pasteProcess; | 182 | delete m_pasteProcess; | ||
179 | m_pasteProcess = nullptr; | 183 | m_pasteProcess = nullptr; | ||
184 | delete m_copyProcess; | ||||
185 | m_copyProcess = nullptr; | ||||
180 | } | 186 | } | ||
181 | 187 | | |||
182 | WAYLANDTEST_MAIN(XClipboardSyncTest) | 188 | WAYLANDTEST_MAIN(XClipboardSyncTest) | ||
183 | #include "xclipboardsync_test.moc" | 189 | #include "xclipboardsync_test.moc" |