From bd6eb42fa31919aff1906aa60036aa33fd3edaa4 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Mon, 14 Oct 2019 11:10:42 +0200 Subject: Fix build: Use temporary directories for tests' XDG_RUNTIME_DIR Using XDG_RUNTIME_DIR="." does not work after qtbase 5542785, and it was a rather brittle solution anyway. Fixes: QTBUG-79185 Change-Id: Iaf9ced66709cc6cbac8a2d54efc64e1a8c528561 Reviewed-by: Paul Olav Tvete --- tests/auto/client/client/tst_client.cpp | 3 ++- tests/auto/client/inputcontext/tst_inputcontext.cpp | 3 ++- tests/auto/client/shared/mockcompositor.h | 3 ++- tests/auto/compositor/compositor/tst_compositor.cpp | 7 ++++++- 4 files changed, 12 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/client/client/tst_client.cpp b/tests/auto/client/client/tst_client.cpp index 83b9e6ce0..e7729ce8b 100644 --- a/tests/auto/client/client/tst_client.cpp +++ b/tests/auto/client/client/tst_client.cpp @@ -507,7 +507,8 @@ void tst_WaylandClient::longWindowTitleWithUtf16Characters() int main(int argc, char **argv) { - setenv("XDG_RUNTIME_DIR", ".", 1); + QTemporaryDir tmpRuntimeDir; + setenv("XDG_RUNTIME_DIR", tmpRuntimeDir.path().toLocal8Bit(), 1); setenv("QT_QPA_PLATFORM", "wayland", 1); // force QGuiApplication to use wayland plugin MockCompositor compositor; diff --git a/tests/auto/client/inputcontext/tst_inputcontext.cpp b/tests/auto/client/inputcontext/tst_inputcontext.cpp index b1a5a7f17..3e6de4a08 100644 --- a/tests/auto/client/inputcontext/tst_inputcontext.cpp +++ b/tests/auto/client/inputcontext/tst_inputcontext.cpp @@ -173,7 +173,8 @@ void tst_inputcontext::inputContextReconfigurationWhenTogglingTextInputExtension int main(int argc, char *argv[]) { - qputenv("XDG_RUNTIME_DIR", "."); + QTemporaryDir tmpRuntimeDir; + qputenv("XDG_RUNTIME_DIR", tmpRuntimeDir.path().toLocal8Bit()); qputenv("QT_QPA_PLATFORM", "wayland"); tst_inputcontext tc; diff --git a/tests/auto/client/shared/mockcompositor.h b/tests/auto/client/shared/mockcompositor.h index 05bf32c8d..f5264ccf6 100644 --- a/tests/auto/client/shared/mockcompositor.h +++ b/tests/auto/client/shared/mockcompositor.h @@ -77,7 +77,8 @@ public: #define QCOMPOSITOR_TEST_MAIN(test) \ int main(int argc, char **argv) \ { \ - setenv("XDG_RUNTIME_DIR", ".", 1); \ + QTemporaryDir tmpRuntimeDir; \ + setenv("XDG_RUNTIME_DIR", tmpRuntimeDir.path().toLocal8Bit(), 1); \ setenv("XDG_CURRENT_DESKTOP", "qtwaylandtests", 1); \ setenv("QT_QPA_PLATFORM", "wayland", 1); \ test tc; \ diff --git a/tests/auto/compositor/compositor/tst_compositor.cpp b/tests/auto/compositor/compositor/tst_compositor.cpp index c425f2ba1..c286aae70 100644 --- a/tests/auto/compositor/compositor/tst_compositor.cpp +++ b/tests/auto/compositor/compositor/tst_compositor.cpp @@ -110,10 +110,15 @@ private slots: void viewportDestinationNoSurfaceError(); void viewportSourceNoSurfaceError(); void viewportHiDpi(); + +private: + QTemporaryDir m_tmpRuntimeDir; }; void tst_WaylandCompositor::init() { - qputenv("XDG_RUNTIME_DIR", "."); + // We need to set a test specific runtime dir so we don't conflict with other tests' + // compositors by accident. + qputenv("XDG_RUNTIME_DIR", m_tmpRuntimeDir.path().toLocal8Bit()); } void tst_WaylandCompositor::singleClient() -- cgit v1.2.3 From e306847cd46e68d86b1d5478c0c05b9a5acb026c Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 22 Oct 2019 12:30:09 +0200 Subject: Add client test for clipboard when losing keyboard focus Also, verifies that we fixed a recent bug about QClipboard::dataChanged not being emitted when the clipboard is invalidated due to losing focus. Change-Id: Ie92b618a4f673c21d6582979249700aef8785536 Reviewed-by: Pekka Vuorela --- .../auto/client/datadevicev1/tst_datadevicev1.cpp | 30 ++++++++++++++++++++++ tests/auto/client/shared/datadevice.h | 1 - 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/client/datadevicev1/tst_datadevicev1.cpp b/tests/auto/client/datadevicev1/tst_datadevicev1.cpp index e3babceb5..1568b3b96 100644 --- a/tests/auto/client/datadevicev1/tst_datadevicev1.cpp +++ b/tests/auto/client/datadevicev1/tst_datadevicev1.cpp @@ -59,6 +59,7 @@ private slots: void pasteUtf8(); void destroysPreviousSelection(); void destroysSelectionWithSurface(); + void destroysSelectionOnLeave(); void dragWithoutFocus(); }; @@ -215,6 +216,35 @@ void tst_datadevicev1::destroysSelectionWithSurface() QCOMPOSITOR_TRY_COMPARE(dataDevice()->m_sentSelectionOffers.size(), 0); } +void tst_datadevicev1::destroysSelectionOnLeave() +{ + QRasterWindow window; + window.resize(64, 64); + window.show(); + QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial); + + exec([&] { + auto *offer = dataDevice()->sendDataOffer(client(), {"text/plain"}); + dataDevice()->sendSelection(offer); + + auto *surface = xdgSurface()->m_surface; + keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol + }); + + QTRY_VERIFY(QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard)); + QTRY_VERIFY(QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard)->hasText()); + + QSignalSpy dataChangedSpy(QGuiApplication::clipboard(), &QClipboard::dataChanged); + + exec([&] { + auto *surface = xdgSurface()->m_surface; + keyboard()->sendLeave(surface); + }); + + QTRY_COMPARE(dataChangedSpy.count(), 1); + QVERIFY(!QGuiApplication::clipboard()->mimeData(QClipboard::Clipboard)->hasText()); +} + // The application should not crash if it attempts to start a drag operation // when it doesn't have input focus (QTBUG-76368) void tst_datadevicev1::dragWithoutFocus() diff --git a/tests/auto/client/shared/datadevice.h b/tests/auto/client/shared/datadevice.h index a96da86f0..98e780b22 100644 --- a/tests/auto/client/shared/datadevice.h +++ b/tests/auto/client/shared/datadevice.h @@ -65,7 +65,6 @@ public: ~DataDevice() override; void send_data_offer(::wl_resource *resource) = delete; DataOffer *sendDataOffer(::wl_client *client, const QStringList &mimeTypes = {}); - DataOffer *sendDataOffer(const QStringList &mimeTypes = {}); void send_selection(::wl_resource *resource) = delete; void sendSelection(DataOffer *offer); -- cgit v1.2.3 From 1c67c2e281f8a5e1af5ae2ef697e570bdd50514b Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 22 Oct 2019 10:17:56 +0200 Subject: Fix missing emission of QClipboard::selectionChanged And add a test to verify we've fixed it. Change-Id: Ic6d5e64b3000444465935f7caf7e32ec9c4f1012 Reviewed-by: Paul Olav Tvete --- .../primaryselectionv1/tst_primaryselectionv1.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp b/tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp index 216db85cd..b3fa2b13c 100644 --- a/tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp +++ b/tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp @@ -261,6 +261,7 @@ private slots: void pasteAscii(); void pasteUtf8(); void destroysPreviousSelection(); + void destroysSelectionOnLeave(); void copy(); }; @@ -411,6 +412,35 @@ void tst_primaryselectionv1::destroysPreviousSelection() QCOMPOSITOR_TRY_COMPARE(primarySelectionDevice()->m_sentSelectionOffers.size(), 1); } +void tst_primaryselectionv1::destroysSelectionOnLeave() +{ + QRasterWindow window; + window.resize(64, 64); + window.show(); + QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial); + + exec([&] { + auto *surface = xdgSurface()->m_surface; + keyboard()->sendEnter(surface); // Need to set keyboard focus according to protocol + + auto *offer = primarySelectionDevice()->sendDataOffer({"text/plain"}); + primarySelectionDevice()->sendSelection(offer); + }); + + QTRY_VERIFY(QGuiApplication::clipboard()->mimeData(QClipboard::Selection)); + QTRY_VERIFY(QGuiApplication::clipboard()->mimeData(QClipboard::Selection)->hasText()); + + QSignalSpy selectionChangedSpy(QGuiApplication::clipboard(), &QClipboard::selectionChanged); + + exec([&] { + auto *surface = xdgSurface()->m_surface; + keyboard()->sendLeave(surface); + }); + + QTRY_COMPARE(selectionChangedSpy.count(), 1); + QVERIFY(!QGuiApplication::clipboard()->mimeData(QClipboard::Selection)->hasText()); +} + void tst_primaryselectionv1::copy() { class Window : public QRasterWindow { -- cgit v1.2.3 From a3ab80f3463ce4f2e8c973e3f1048cc133fdba35 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 22 Oct 2019 12:02:23 +0200 Subject: Fix QClipboard::ownSelection always returning false It would return false regardless of whether we owned the selection. Change-Id: I6df394d8dbceeccb6eb6d0670b4351af1a158491 Reviewed-by: Paul Olav Tvete --- tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto') diff --git a/tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp b/tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp index b3fa2b13c..ee9fa110e 100644 --- a/tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp +++ b/tests/auto/client/primaryselectionv1/tst_primaryselectionv1.cpp @@ -472,6 +472,7 @@ void tst_primaryselectionv1::copy() }); QCOMPOSITOR_TRY_VERIFY(primarySelectionDevice()->m_selectionSource); QCOMPOSITOR_TRY_VERIFY(mouseSerials.contains(primarySelectionDevice()->m_serial)); + QVERIFY(QGuiApplication::clipboard()->ownsSelection()); QByteArray pastedBuf; exec([&](){ auto *source = primarySelectionDevice()->m_selectionSource; -- cgit v1.2.3