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 28 Lines | 52 | { | |||
62 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | 63 | QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); | ||
63 | 64 | | |||
64 | kwinApp()->start(); | 65 | kwinApp()->start(); | ||
65 | QVERIFY(workspaceCreatedSpy.wait()); | 66 | QVERIFY(workspaceCreatedSpy.wait()); | ||
66 | QCOMPARE(screens()->count(), 2); | 67 | QCOMPARE(screens()->count(), 2); | ||
67 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | 68 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||
68 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 69 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
69 | waylandServer()->initWorkspace(); | 70 | waylandServer()->initWorkspace(); | ||
70 | // wait till the xclipboard sync data device is created | 71 | // // wait till the xclipboard sync data device is created | ||
71 | if (clipboardSyncDevicedCreated.empty()) { | 72 | // if (clipboardSyncDevicedCreated.empty()) { | ||
72 | QVERIFY(clipboardSyncDevicedCreated.wait()); | 73 | // QVERIFY(clipboardSyncDevicedCreated.wait()); | ||
74 | // } | ||||
75 | // wait till the DataBridge sync data device is created | ||||
76 | while (Xwl::DataBridge::self()->dataDeviceIface() == nullptr) { | ||||
77 | QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents); | ||||
73 | } | 78 | } | ||
74 | QVERIFY(!waylandServer()->xclipboardSyncDataDevice().isNull()); | 79 | QVERIFY(Xwl::DataBridge::self()->dataDeviceIface() != nullptr); | ||
75 | } | 80 | } | ||
76 | 81 | | |||
77 | void XClipboardSyncTest::cleanup() | 82 | void XClipboardSyncTest::cleanup() | ||
78 | { | 83 | { | ||
79 | if (m_copyProcess) { | 84 | if (m_copyProcess) { | ||
80 | m_copyProcess->terminate(); | 85 | m_copyProcess->terminate(); | ||
81 | QVERIFY(m_copyProcess->waitForFinished()); | 86 | QVERIFY(m_copyProcess->waitForFinished()); | ||
82 | m_copyProcess = nullptr; | 87 | m_copyProcess = nullptr; | ||
83 | } | 88 | } | ||
84 | if (m_pasteProcess) { | 89 | if (m_pasteProcess) { | ||
85 | m_pasteProcess->terminate(); | 90 | m_pasteProcess->terminate(); | ||
86 | QVERIFY(m_pasteProcess->waitForFinished()); | 91 | QVERIFY(m_pasteProcess->waitForFinished()); | ||
87 | m_pasteProcess = nullptr; | 92 | m_pasteProcess = nullptr; | ||
88 | } | 93 | } | ||
89 | } | 94 | } | ||
90 | 95 | | |||
91 | void XClipboardSyncTest::testSync_data() | 96 | void XClipboardSyncTest::testSync_data() | ||
92 | { | 97 | { | ||
93 | QTest::addColumn<QString>("copyPlatform"); | 98 | QTest::addColumn<QString>("copyPlatform"); | ||
94 | QTest::addColumn<QString>("pastePlatform"); | 99 | QTest::addColumn<QString>("pastePlatform"); | ||
95 | 100 | | |||
96 | QTest::newRow("x11-wayland") << QStringLiteral("xcb") << QStringLiteral("wayland"); | 101 | QTest::newRow("x11->wayland") << QStringLiteral("xcb") << QStringLiteral("wayland"); | ||
97 | QTest::newRow("wayland-x11") << QStringLiteral("wayland") << QStringLiteral("xcb"); | 102 | QTest::newRow("wayland->x11") << QStringLiteral("wayland") << QStringLiteral("xcb"); | ||
98 | } | 103 | } | ||
99 | 104 | | |||
100 | void XClipboardSyncTest::testSync() | 105 | void XClipboardSyncTest::testSync() | ||
101 | { | 106 | { | ||
102 | // this test verifies the syncing of X11 to Wayland clipboard | 107 | // this test verifies the syncing of X11 to Wayland clipboard | ||
103 | const QString copy = QFINDTESTDATA(QStringLiteral("copy")); | 108 | const QString copy = QFINDTESTDATA(QStringLiteral("copy")); | ||
104 | QVERIFY(!copy.isEmpty()); | 109 | QVERIFY(!copy.isEmpty()); | ||
105 | const QString paste = QFINDTESTDATA(QStringLiteral("paste")); | 110 | const QString paste = QFINDTESTDATA(QStringLiteral("paste")); | ||
106 | QVERIFY(!paste.isEmpty()); | 111 | QVERIFY(!paste.isEmpty()); | ||
107 | 112 | | |||
108 | QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded); | 113 | QSignalSpy clientAddedSpy(workspace(), &Workspace::clientAdded); | ||
109 | QVERIFY(clientAddedSpy.isValid()); | 114 | QVERIFY(clientAddedSpy.isValid()); | ||
110 | QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 115 | QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
111 | QVERIFY(shellClientAddedSpy.isValid()); | 116 | QVERIFY(shellClientAddedSpy.isValid()); | ||
112 | QSignalSpy clipboardChangedSpy(waylandServer()->xclipboardSyncDataDevice().data(), &KWayland::Server::DataDeviceInterface::selectionChanged); | 117 | QSignalSpy clipboardChangedSpy(Xwl::DataBridge::self()->dataDeviceIface(), &KWayland::Server::DataDeviceInterface::selectionChanged); | ||
113 | QVERIFY(clipboardChangedSpy.isValid()); | 118 | QVERIFY(clipboardChangedSpy.isValid()); | ||
114 | 119 | | |||
115 | QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); | 120 | QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); | ||
121 | | ||||
122 | // start the copy process | ||||
116 | QFETCH(QString, copyPlatform); | 123 | QFETCH(QString, copyPlatform); | ||
117 | environment.insert(QStringLiteral("QT_QPA_PLATFORM"), copyPlatform); | 124 | environment.insert(QStringLiteral("QT_QPA_PLATFORM"), copyPlatform); | ||
118 | environment.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName); | 125 | environment.insert(QStringLiteral("WAYLAND_DISPLAY"), s_socketName); | ||
119 | m_copyProcess = new QProcess(); | 126 | m_copyProcess = new QProcess(); | ||
120 | m_copyProcess->setProcessEnvironment(environment); | 127 | m_copyProcess->setProcessEnvironment(environment); | ||
121 | m_copyProcess->setProcessChannelMode(QProcess::ForwardedChannels); | 128 | m_copyProcess->setProcessChannelMode(QProcess::ForwardedChannels); | ||
122 | m_copyProcess->setProgram(copy); | 129 | m_copyProcess->setProgram(copy); | ||
123 | m_copyProcess->start(); | 130 | m_copyProcess->start(); | ||
Show All 40 Lines | 169 | if (pastePlatform == QLatin1String("xcb")) { | |||
164 | pasteClient = clientAddedSpy.last().first().value<AbstractClient*>(); | 171 | pasteClient = clientAddedSpy.last().first().value<AbstractClient*>(); | ||
165 | } else { | 172 | } else { | ||
166 | QVERIFY(shellClientAddedSpy.wait()); | 173 | QVERIFY(shellClientAddedSpy.wait()); | ||
167 | pasteClient = shellClientAddedSpy.last().first().value<AbstractClient*>(); | 174 | pasteClient = shellClientAddedSpy.last().first().value<AbstractClient*>(); | ||
168 | } | 175 | } | ||
169 | QCOMPARE(clientAddedSpy.count(), 1); | 176 | QCOMPARE(clientAddedSpy.count(), 1); | ||
170 | QCOMPARE(shellClientAddedSpy.count(), 1); | 177 | QCOMPARE(shellClientAddedSpy.count(), 1); | ||
171 | QVERIFY(pasteClient); | 178 | QVERIFY(pasteClient); | ||
179 | | ||||
172 | if (workspace()->activeClient() != pasteClient) { | 180 | if (workspace()->activeClient() != pasteClient) { | ||
173 | QSignalSpy clientActivatedSpy(workspace(), &Workspace::clientActivated); | 181 | QSignalSpy clientActivatedSpy(workspace(), &Workspace::clientActivated); | ||
174 | QVERIFY(clientActivatedSpy.isValid()); | 182 | QVERIFY(clientActivatedSpy.isValid()); | ||
175 | workspace()->activateClient(pasteClient); | 183 | workspace()->activateClient(pasteClient); | ||
176 | QVERIFY(clientActivatedSpy.wait()); | 184 | QVERIFY(clientActivatedSpy.wait()); | ||
177 | } | 185 | } | ||
178 | QTRY_COMPARE(workspace()->activeClient(), pasteClient); | 186 | QTRY_COMPARE(workspace()->activeClient(), pasteClient); | ||
179 | QVERIFY(finishedSpy.wait()); | 187 | QVERIFY(finishedSpy.wait()); | ||
180 | QCOMPARE(finishedSpy.first().first().toInt(), 0); | 188 | QCOMPARE(finishedSpy.first().first().toInt(), 0); | ||
181 | delete m_pasteProcess; | 189 | delete m_pasteProcess; | ||
182 | m_pasteProcess = nullptr; | 190 | m_pasteProcess = nullptr; | ||
191 | delete m_copyProcess; | ||||
192 | m_copyProcess = nullptr; | ||||
183 | } | 193 | } | ||
184 | 194 | | |||
185 | WAYLANDTEST_MAIN(XClipboardSyncTest) | 195 | WAYLANDTEST_MAIN(XClipboardSyncTest) | ||
186 | #include "xclipboardsync_test.moc" | 196 | #include "xclipboardsync_test.moc" |