From 401bdecabb950001ae3294e864ed397d1b76b3f4 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 13 Dec 2018 10:01:14 +0100 Subject: Client test: Prefer UTF-8 when ASCII is also available [ChangeLog][QPA plugin] Fixed a bug where pasting from the clipboard would prefer ASCII over UTF-8, causing loss of special characters. The bug was fixed in QtBase, this is just the test. Task-number: QTBUG-54786 Change-Id: Ibe08bf455ad0be8fdd7a3e082dec6131f19c25d6 Reviewed-by: Paul Olav Tvete --- .../auto/client/datadevicev1/tst_datadevicev1.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/auto/client/datadevicev1/tst_datadevicev1.cpp b/tests/auto/client/datadevicev1/tst_datadevicev1.cpp index 9b42cb280..a85b10c74 100644 --- a/tests/auto/client/datadevicev1/tst_datadevicev1.cpp +++ b/tests/auto/client/datadevicev1/tst_datadevicev1.cpp @@ -57,6 +57,7 @@ private slots: void cleanup() { QTRY_VERIFY2(isClean(), qPrintable(dirtyMessage())); } void initTestCase(); void pasteAscii(); + void pasteUtf8(); }; void tst_datadevicev1::initTestCase() @@ -107,5 +108,42 @@ void tst_datadevicev1::pasteAscii() QTRY_COMPARE(window.m_text, "normal ascii"); } +void tst_datadevicev1::pasteUtf8() +{ + class Window : public QRasterWindow { + public: + void mousePressEvent(QMouseEvent *) override { m_text = QGuiApplication::clipboard()->text(); } + QString m_text; + }; + + Window window; + window.resize(64, 64); + window.show(); + + QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial); + exec([&] { + auto *offer = new DataOffer(client(), dataDeviceVersion); // Cleaned up by destroy_resource + connect(offer, &DataOffer::receive, [](QString mimeType, int fd) { + QFile file; + file.open(fd, QIODevice::WriteOnly, QFile::FileHandleFlag::AutoCloseHandle); + QCOMPARE(mimeType, "text/plain;charset=utf-8"); + file.write(QByteArray("face with tears of joy: 😂")); + file.close(); + }); + dataDevice()->sendDataOffer(offer); + offer->send_offer("text/plain"); + offer->send_offer("text/plain;charset=utf-8"); + dataDevice()->sendSelection(offer); + + auto *surface = xdgSurface()->m_surface; + keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol + + pointer()->sendEnter(surface, {32, 32}); + pointer()->sendButton(client(), BTN_LEFT, 1); + pointer()->sendButton(client(), BTN_LEFT, 0); + }); + QTRY_COMPARE(window.m_text, "face with tears of joy: 😂"); +} + QCOMPOSITOR_TEST_MAIN(tst_datadevicev1) #include "tst_datadevicev1.moc" -- cgit v1.2.3