Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_drag_drop.cpp
Show First 20 Lines • Show All 212 Lines • ▼ Show 20 Line(s) | 212 | { | |||
---|---|---|---|---|---|
213 | // this test verifies the very basic drag and drop on one surface, an enter, a move and the drop | 213 | // this test verifies the very basic drag and drop on one surface, an enter, a move and the drop | ||
214 | using namespace KWayland::Server; | 214 | using namespace KWayland::Server; | ||
215 | using namespace KWayland::Client; | 215 | using namespace KWayland::Client; | ||
216 | // first create a window | 216 | // first create a window | ||
217 | QScopedPointer<Surface> s(createSurface()); | 217 | QScopedPointer<Surface> s(createSurface()); | ||
218 | auto serverSurface = getServerSurface(); | 218 | auto serverSurface = getServerSurface(); | ||
219 | QVERIFY(serverSurface); | 219 | QVERIFY(serverSurface); | ||
220 | 220 | | |||
221 | QSignalSpy dataSourceSelectedActionChangedSpy(m_dataSource, &DataSource::selectedDragAndDropActionChanged); | ||||
222 | QVERIFY(dataSourceSelectedActionChangedSpy.isValid()); | ||||
223 | | ||||
221 | // now we need to pass pointer focus to the Surface and simulate a button press | 224 | // now we need to pass pointer focus to the Surface and simulate a button press | ||
222 | QSignalSpy buttonPressSpy(m_pointer, &Pointer::buttonStateChanged); | 225 | QSignalSpy buttonPressSpy(m_pointer, &Pointer::buttonStateChanged); | ||
223 | QVERIFY(buttonPressSpy.isValid()); | 226 | QVERIFY(buttonPressSpy.isValid()); | ||
224 | m_seatInterface->setFocusedPointerSurface(serverSurface); | 227 | m_seatInterface->setFocusedPointerSurface(serverSurface); | ||
225 | m_seatInterface->setTimestamp(2); | 228 | m_seatInterface->setTimestamp(2); | ||
226 | m_seatInterface->pointerButtonPressed(1); | 229 | m_seatInterface->pointerButtonPressed(1); | ||
227 | QVERIFY(buttonPressSpy.wait()); | 230 | QVERIFY(buttonPressSpy.wait()); | ||
228 | QCOMPARE(buttonPressSpy.first().at(1).value<quint32>(), quint32(2)); | 231 | QCOMPARE(buttonPressSpy.first().at(1).value<quint32>(), quint32(2)); | ||
229 | 232 | | |||
230 | // add some signal spies for client side | 233 | // add some signal spies for client side | ||
231 | QSignalSpy dragEnteredSpy(m_dataDevice, &DataDevice::dragEntered); | 234 | QSignalSpy dragEnteredSpy(m_dataDevice, &DataDevice::dragEntered); | ||
232 | QVERIFY(dragEnteredSpy.isValid()); | 235 | QVERIFY(dragEnteredSpy.isValid()); | ||
233 | QSignalSpy dragMotionSpy(m_dataDevice, &DataDevice::dragMotion); | 236 | QSignalSpy dragMotionSpy(m_dataDevice, &DataDevice::dragMotion); | ||
234 | QVERIFY(dragMotionSpy.isValid()); | 237 | QVERIFY(dragMotionSpy.isValid()); | ||
235 | QSignalSpy pointerMotionSpy(m_pointer, &Pointer::motion); | 238 | QSignalSpy pointerMotionSpy(m_pointer, &Pointer::motion); | ||
236 | QVERIFY(pointerMotionSpy.isValid()); | 239 | QVERIFY(pointerMotionSpy.isValid()); | ||
240 | QSignalSpy sourceDropSpy(m_dataSource, &DataSource::dragAndDropPerformed); | ||||
241 | QVERIFY(sourceDropSpy.isValid()); | ||||
237 | 242 | | |||
238 | // now we can start the drag and drop | 243 | // now we can start the drag and drop | ||
239 | QSignalSpy dragStartedSpy(m_seatInterface, &SeatInterface::dragStarted); | 244 | QSignalSpy dragStartedSpy(m_seatInterface, &SeatInterface::dragStarted); | ||
240 | QVERIFY(dragStartedSpy.isValid()); | 245 | QVERIFY(dragStartedSpy.isValid()); | ||
246 | m_dataSource->setDragAndDropActions(DataDeviceManager::DnDAction::Copy | DataDeviceManager::DnDAction::Move); | ||||
241 | m_dataDevice->startDrag(buttonPressSpy.first().first().value<quint32>(), m_dataSource, s.data()); | 247 | m_dataDevice->startDrag(buttonPressSpy.first().first().value<quint32>(), m_dataSource, s.data()); | ||
242 | QVERIFY(dragStartedSpy.wait()); | 248 | QVERIFY(dragStartedSpy.wait()); | ||
243 | QCOMPARE(m_seatInterface->dragSurface(), serverSurface); | 249 | QCOMPARE(m_seatInterface->dragSurface(), serverSurface); | ||
244 | QCOMPARE(m_seatInterface->dragSurfaceTransformation(), QMatrix4x4()); | 250 | QCOMPARE(m_seatInterface->dragSurfaceTransformation(), QMatrix4x4()); | ||
245 | QVERIFY(!m_seatInterface->dragSource()->icon()); | 251 | QVERIFY(!m_seatInterface->dragSource()->icon()); | ||
246 | QCOMPARE(m_seatInterface->dragSource()->dragImplicitGrabSerial(), buttonPressSpy.first().first().value<quint32>()); | 252 | QCOMPARE(m_seatInterface->dragSource()->dragImplicitGrabSerial(), buttonPressSpy.first().first().value<quint32>()); | ||
247 | QVERIFY(dragEnteredSpy.wait()); | 253 | QVERIFY(dragEnteredSpy.wait()); | ||
248 | QCOMPARE(dragEnteredSpy.count(), 1); | 254 | QCOMPARE(dragEnteredSpy.count(), 1); | ||
249 | QCOMPARE(dragEnteredSpy.first().first().value<quint32>(), m_display->serial()); | 255 | QCOMPARE(dragEnteredSpy.first().first().value<quint32>(), m_display->serial()); | ||
250 | QCOMPARE(dragEnteredSpy.first().last().toPointF(), QPointF(0, 0)); | 256 | QCOMPARE(dragEnteredSpy.first().last().toPointF(), QPointF(0, 0)); | ||
251 | QCOMPARE(m_dataDevice->dragSurface().data(), s.data()); | 257 | QCOMPARE(m_dataDevice->dragSurface().data(), s.data()); | ||
258 | auto offer = m_dataDevice->dragOffer(); | ||||
259 | QVERIFY(offer); | ||||
260 | QCOMPARE(offer->selectedDragAndDropAction(), DataDeviceManager::DnDAction::None); | ||||
261 | QSignalSpy offerActionChangedSpy(offer, &DataOffer::selectedDragAndDropActionChanged); | ||||
262 | QVERIFY(offerActionChangedSpy.isValid()); | ||||
252 | QCOMPARE(m_dataDevice->dragOffer()->offeredMimeTypes().count(), 1); | 263 | QCOMPARE(m_dataDevice->dragOffer()->offeredMimeTypes().count(), 1); | ||
253 | QCOMPARE(m_dataDevice->dragOffer()->offeredMimeTypes().first().name(), QStringLiteral("text/plain")); | 264 | QCOMPARE(m_dataDevice->dragOffer()->offeredMimeTypes().first().name(), QStringLiteral("text/plain")); | ||
265 | QTRY_COMPARE(offer->sourceDragAndDropActions(), DataDeviceManager::DnDAction::Copy | DataDeviceManager::DnDAction::Move); | ||||
266 | offer->setDragAndDropActions(DataDeviceManager::DnDAction::Copy | DataDeviceManager::DnDAction::Move, DataDeviceManager::DnDAction::Move); | ||||
267 | QVERIFY(offerActionChangedSpy.wait()); | ||||
268 | QCOMPARE(offerActionChangedSpy.count(), 1); | ||||
269 | QCOMPARE(offer->selectedDragAndDropAction(), DataDeviceManager::DnDAction::Move); | ||||
270 | QCOMPARE(dataSourceSelectedActionChangedSpy.count(), 1); | ||||
271 | QCOMPARE(m_dataSource->selectedDragAndDropAction(), DataDeviceManager::DnDAction::Move); | ||||
254 | 272 | | |||
255 | // simulate motion | 273 | // simulate motion | ||
256 | m_seatInterface->setTimestamp(3); | 274 | m_seatInterface->setTimestamp(3); | ||
257 | m_seatInterface->setPointerPos(QPointF(3, 3)); | 275 | m_seatInterface->setPointerPos(QPointF(3, 3)); | ||
258 | QVERIFY(dragMotionSpy.wait()); | 276 | QVERIFY(dragMotionSpy.wait()); | ||
259 | QCOMPARE(dragMotionSpy.count(), 1); | 277 | QCOMPARE(dragMotionSpy.count(), 1); | ||
260 | QCOMPARE(dragMotionSpy.first().first().toPointF(), QPointF(3, 3)); | 278 | QCOMPARE(dragMotionSpy.first().first().toPointF(), QPointF(3, 3)); | ||
261 | QCOMPARE(dragMotionSpy.first().last().toUInt(), 3u); | 279 | QCOMPARE(dragMotionSpy.first().last().toUInt(), 3u); | ||
262 | 280 | | |||
263 | // simulate drop | 281 | // simulate drop | ||
264 | QSignalSpy leftSpy(m_dataDevice, &DataDevice::dragLeft); | | |||
265 | QVERIFY(leftSpy.isValid()); | | |||
266 | QSignalSpy serverDragEndedSpy(m_seatInterface, &SeatInterface::dragEnded); | 282 | QSignalSpy serverDragEndedSpy(m_seatInterface, &SeatInterface::dragEnded); | ||
267 | QVERIFY(serverDragEndedSpy.isValid()); | 283 | QVERIFY(serverDragEndedSpy.isValid()); | ||
268 | QSignalSpy droppedSpy(m_dataDevice, &DataDevice::dropped); | 284 | QSignalSpy droppedSpy(m_dataDevice, &DataDevice::dropped); | ||
269 | QVERIFY(droppedSpy.isValid()); | 285 | QVERIFY(droppedSpy.isValid()); | ||
270 | m_seatInterface->setTimestamp(4); | 286 | m_seatInterface->setTimestamp(4); | ||
271 | m_seatInterface->pointerButtonReleased(1); | 287 | m_seatInterface->pointerButtonReleased(1); | ||
288 | QVERIFY(sourceDropSpy.isEmpty()); | ||||
272 | QVERIFY(droppedSpy.wait()); | 289 | QVERIFY(droppedSpy.wait()); | ||
273 | QCOMPARE(leftSpy.count(), 1); | 290 | QCOMPARE(sourceDropSpy.count(), 1); | ||
274 | QCOMPARE(serverDragEndedSpy.count(), 1); | 291 | QCOMPARE(serverDragEndedSpy.count(), 1); | ||
275 | 292 | | |||
293 | QSignalSpy finishedSpy(m_dataSource, &DataSource::dragAndDropFinished); | ||||
294 | QVERIFY(finishedSpy.isValid()); | ||||
295 | offer->dragAndDropFinished(); | ||||
296 | QVERIFY(finishedSpy.wait()); | ||||
297 | delete offer; | ||||
298 | | ||||
276 | // verify that we did not get any further input events | 299 | // verify that we did not get any further input events | ||
277 | QVERIFY(pointerMotionSpy.isEmpty()); | 300 | QVERIFY(pointerMotionSpy.isEmpty()); | ||
278 | QCOMPARE(buttonPressSpy.count(), 1); | 301 | QCOMPARE(buttonPressSpy.count(), 1); | ||
279 | } | 302 | } | ||
280 | 303 | | |||
281 | void TestDragAndDrop::testPointerEventsIgnored() | 304 | void TestDragAndDrop::testPointerEventsIgnored() | ||
282 | { | 305 | { | ||
283 | // this test verifies that all pointer events are ignored on the focused Pointer device during drag | 306 | // this test verifies that all pointer events are ignored on the focused Pointer device during drag | ||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |