Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_datadevice.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | class TestDataDevice : public QObject | 44 | class TestDataDevice : public QObject | ||
45 | { | 45 | { | ||
46 | Q_OBJECT | 46 | Q_OBJECT | ||
47 | private Q_SLOTS: | 47 | private Q_SLOTS: | ||
48 | void init(); | 48 | void init(); | ||
49 | void cleanup(); | 49 | void cleanup(); | ||
50 | 50 | | |||
51 | void testCreate(); | 51 | void testCreate(); | ||
52 | void testDrag_data(); | ||||
52 | void testDrag(); | 53 | void testDrag(); | ||
54 | void testDragInternally_data(); | ||||
53 | void testDragInternally(); | 55 | void testDragInternally(); | ||
54 | void testSetSelection(); | 56 | void testSetSelection(); | ||
55 | void testSendSelectionOnSeat(); | 57 | void testSendSelectionOnSeat(); | ||
56 | void testReplaceSource(); | 58 | void testReplaceSource(); | ||
57 | void testDestroy(); | 59 | void testDestroy(); | ||
58 | 60 | | |||
59 | private: | 61 | private: | ||
60 | KWayland::Server::Display *m_display = nullptr; | 62 | KWayland::Server::Display *m_display = nullptr; | ||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Line(s) | 180 | { | |||
203 | // and destroy | 205 | // and destroy | ||
204 | QSignalSpy destroyedSpy(deviceInterface, &QObject::destroyed); | 206 | QSignalSpy destroyedSpy(deviceInterface, &QObject::destroyed); | ||
205 | QVERIFY(destroyedSpy.isValid()); | 207 | QVERIFY(destroyedSpy.isValid()); | ||
206 | dataDevice.reset(); | 208 | dataDevice.reset(); | ||
207 | QVERIFY(destroyedSpy.wait()); | 209 | QVERIFY(destroyedSpy.wait()); | ||
208 | QVERIFY(!m_seatInterface->selection()); | 210 | QVERIFY(!m_seatInterface->selection()); | ||
209 | } | 211 | } | ||
210 | 212 | | |||
213 | void TestDataDevice::testDrag_data() | ||||
214 | { | ||||
215 | QTest::addColumn<bool>("hasGrab"); | ||||
216 | QTest::addColumn<bool>("hasPointerFocus"); | ||||
217 | QTest::addColumn<bool>("success"); | ||||
218 | | ||||
219 | QTest::newRow("grab and focus") << true << true << true; | ||||
220 | QTest::newRow("no grab") << false << true << false; | ||||
221 | QTest::newRow("no focus") << true << false << false; | ||||
222 | QTest::newRow("no grab, no focus") << false << false << false; | ||||
223 | } | ||||
224 | | ||||
211 | void TestDataDevice::testDrag() | 225 | void TestDataDevice::testDrag() | ||
212 | { | 226 | { | ||
213 | using namespace KWayland::Client; | 227 | using namespace KWayland::Client; | ||
214 | using namespace KWayland::Server; | 228 | using namespace KWayland::Server; | ||
215 | QScopedPointer<Pointer> pointer(m_seat->createPointer()); | 229 | QScopedPointer<Pointer> pointer(m_seat->createPointer()); | ||
216 | 230 | | |||
217 | QSignalSpy dataDeviceCreatedSpy(m_dataDeviceManagerInterface, SIGNAL(dataDeviceCreated(KWayland::Server::DataDeviceInterface*))); | 231 | QSignalSpy dataDeviceCreatedSpy(m_dataDeviceManagerInterface, SIGNAL(dataDeviceCreated(KWayland::Server::DataDeviceInterface*))); | ||
218 | QVERIFY(dataDeviceCreatedSpy.isValid()); | 232 | QVERIFY(dataDeviceCreatedSpy.isValid()); | ||
Show All 27 Lines | |||||
246 | QCOMPARE(surfaceCreatedSpy.count(), 1); | 260 | QCOMPARE(surfaceCreatedSpy.count(), 1); | ||
247 | auto surfaceInterface = surfaceCreatedSpy.first().first().value<SurfaceInterface*>(); | 261 | auto surfaceInterface = surfaceCreatedSpy.first().first().value<SurfaceInterface*>(); | ||
248 | 262 | | |||
249 | // now we have all we need to start a drag operation | 263 | // now we have all we need to start a drag operation | ||
250 | QSignalSpy dragStartedSpy(deviceInterface, SIGNAL(dragStarted())); | 264 | QSignalSpy dragStartedSpy(deviceInterface, SIGNAL(dragStarted())); | ||
251 | QVERIFY(dragStartedSpy.isValid()); | 265 | QVERIFY(dragStartedSpy.isValid()); | ||
252 | 266 | | |||
253 | // first we need to fake the pointer enter | 267 | // first we need to fake the pointer enter | ||
268 | QFETCH(bool, hasGrab); | ||||
269 | QFETCH(bool, hasPointerFocus); | ||||
270 | QFETCH(bool, success); | ||||
271 | if (!hasGrab) { | ||||
272 | // in case we don't have grab, still generate a pointer serial to make it more interesting | ||||
273 | m_seatInterface->pointerButtonPressed(Qt::LeftButton); | ||||
274 | } | ||||
275 | if (hasPointerFocus) { | ||||
254 | m_seatInterface->setFocusedPointerSurface(surfaceInterface); | 276 | m_seatInterface->setFocusedPointerSurface(surfaceInterface); | ||
255 | m_seatInterface->pointerButtonPressed(1); | 277 | } | ||
278 | if (hasGrab) { | ||||
279 | m_seatInterface->pointerButtonPressed(Qt::LeftButton); | ||||
280 | } | ||||
256 | 281 | | |||
257 | QCoreApplication::processEvents(); | 282 | // TODO: This test would be better, if it could also test that a client trying to guess | ||
283 | // the last serial of a different client can't start a drag. | ||||
284 | const quint32 pointerButtonSerial = success ? m_seatInterface->pointerButtonSerial(Qt::LeftButton) : 0; | ||||
258 | 285 | | |||
259 | dataDevice->startDrag(1, dataSource.data(), surface.data()); | 286 | QCoreApplication::processEvents(); | ||
260 | QVERIFY(dragStartedSpy.wait()); | 287 | // finally start the drag | ||
261 | QCOMPARE(dragStartedSpy.count(), 1); | 288 | dataDevice->startDrag(pointerButtonSerial, dataSource.data(), surface.data()); | ||
262 | QCOMPARE(deviceInterface->dragSource(), sourceInterface); | 289 | QCOMPARE(dragStartedSpy.wait(500), success); | ||
263 | QCOMPARE(deviceInterface->origin(), surfaceInterface); | 290 | QCOMPARE(dragStartedSpy.count(), success); | ||
291 | QCOMPARE(deviceInterface->dragSource(), success ? sourceInterface : nullptr); | ||||
292 | QCOMPARE(deviceInterface->origin(), success ? surfaceInterface : nullptr); | ||||
264 | QVERIFY(!deviceInterface->icon()); | 293 | QVERIFY(!deviceInterface->icon()); | ||
265 | } | 294 | } | ||
266 | 295 | | |||
296 | void TestDataDevice::testDragInternally_data() | ||||
297 | { | ||||
298 | QTest::addColumn<bool>("hasGrab"); | ||||
299 | QTest::addColumn<bool>("hasPointerFocus"); | ||||
300 | QTest::addColumn<bool>("success"); | ||||
301 | | ||||
302 | QTest::newRow("grab and focus") << true << true << true; | ||||
303 | QTest::newRow("no grab") << false << true << false; | ||||
304 | QTest::newRow("no focus") << true << false << false; | ||||
305 | QTest::newRow("no grab, no focus") << false << false << false; | ||||
306 | } | ||||
307 | | ||||
267 | void TestDataDevice::testDragInternally() | 308 | void TestDataDevice::testDragInternally() | ||
268 | { | 309 | { | ||
269 | using namespace KWayland::Client; | 310 | using namespace KWayland::Client; | ||
270 | using namespace KWayland::Server; | 311 | using namespace KWayland::Server; | ||
271 | QScopedPointer<Pointer> pointer(m_seat->createPointer()); | 312 | QScopedPointer<Pointer> pointer(m_seat->createPointer()); | ||
272 | 313 | | |||
273 | QSignalSpy dataDeviceCreatedSpy(m_dataDeviceManagerInterface, SIGNAL(dataDeviceCreated(KWayland::Server::DataDeviceInterface*))); | 314 | QSignalSpy dataDeviceCreatedSpy(m_dataDeviceManagerInterface, SIGNAL(dataDeviceCreated(KWayland::Server::DataDeviceInterface*))); | ||
274 | QVERIFY(dataDeviceCreatedSpy.isValid()); | 315 | QVERIFY(dataDeviceCreatedSpy.isValid()); | ||
Show All 23 Lines | |||||
298 | QCOMPARE(surfaceCreatedSpy.count(), 2); | 339 | QCOMPARE(surfaceCreatedSpy.count(), 2); | ||
299 | auto iconSurfaceInterface = surfaceCreatedSpy.last().first().value<SurfaceInterface*>(); | 340 | auto iconSurfaceInterface = surfaceCreatedSpy.last().first().value<SurfaceInterface*>(); | ||
300 | 341 | | |||
301 | // now we have all we need to start a drag operation | 342 | // now we have all we need to start a drag operation | ||
302 | QSignalSpy dragStartedSpy(deviceInterface, SIGNAL(dragStarted())); | 343 | QSignalSpy dragStartedSpy(deviceInterface, SIGNAL(dragStarted())); | ||
303 | QVERIFY(dragStartedSpy.isValid()); | 344 | QVERIFY(dragStartedSpy.isValid()); | ||
304 | 345 | | |||
305 | // first we need to fake the pointer enter | 346 | // first we need to fake the pointer enter | ||
347 | QFETCH(bool, hasGrab); | ||||
348 | QFETCH(bool, hasPointerFocus); | ||||
349 | QFETCH(bool, success); | ||||
350 | if (!hasGrab) { | ||||
351 | // in case we don't have grab, still generate a pointer serial to make it more interesting | ||||
352 | m_seatInterface->pointerButtonPressed(Qt::LeftButton); | ||||
353 | } | ||||
354 | if (hasPointerFocus) { | ||||
306 | m_seatInterface->setFocusedPointerSurface(surfaceInterface); | 355 | m_seatInterface->setFocusedPointerSurface(surfaceInterface); | ||
307 | m_seatInterface->pointerButtonPressed(1); | 356 | } | ||
357 | if (hasGrab) { | ||||
358 | m_seatInterface->pointerButtonPressed(Qt::LeftButton); | ||||
359 | } | ||||
308 | 360 | | |||
309 | QCoreApplication::processEvents(); | 361 | // TODO: This test would be better, if it could also test that a client trying to guess | ||
362 | // the last serial of a different client can't start a drag. | ||||
363 | const quint32 pointerButtonSerial = success ? m_seatInterface->pointerButtonSerial(Qt::LeftButton) : 0; | ||||
310 | 364 | | |||
311 | dataDevice->startDragInternally(1, surface.data(), iconSurface.data()); | 365 | QCoreApplication::processEvents(); | ||
312 | QVERIFY(dragStartedSpy.wait()); | 366 | // finally start the internal drag | ||
313 | QCOMPARE(dragStartedSpy.count(), 1); | 367 | dataDevice->startDragInternally(pointerButtonSerial, surface.data(), iconSurface.data()); | ||
368 | QCOMPARE(dragStartedSpy.wait(500), success); | ||||
369 | QCOMPARE(dragStartedSpy.count(), success); | ||||
314 | QVERIFY(!deviceInterface->dragSource()); | 370 | QVERIFY(!deviceInterface->dragSource()); | ||
315 | QCOMPARE(deviceInterface->origin(), surfaceInterface); | 371 | QCOMPARE(deviceInterface->origin(), success ? surfaceInterface : nullptr); | ||
316 | QCOMPARE(deviceInterface->icon(), iconSurfaceInterface); | 372 | QCOMPARE(deviceInterface->icon(), success ? iconSurfaceInterface : nullptr); | ||
317 | } | 373 | } | ||
318 | 374 | | |||
319 | void TestDataDevice::testSetSelection() | 375 | void TestDataDevice::testSetSelection() | ||
320 | { | 376 | { | ||
321 | using namespace KWayland::Client; | 377 | using namespace KWayland::Client; | ||
322 | using namespace KWayland::Server; | 378 | using namespace KWayland::Server; | ||
323 | QScopedPointer<Pointer> pointer(m_seat->createPointer()); | 379 | QScopedPointer<Pointer> pointer(m_seat->createPointer()); | ||
324 | 380 | | |||
▲ Show 20 Lines • Show All 242 Lines • Show Last 20 Lines |