summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2019-10-22 12:30:09 +0200
committerJohan Klokkhammer Helsing <johan.helsing@qt.io>2019-10-23 11:48:09 +0200
commite306847cd46e68d86b1d5478c0c05b9a5acb026c (patch)
tree2cdd6be686b200335a4fc06e6a2f77c5cfd2ea5b
parentb108d7a88d23a17d1cc94ecdc69b360dae11afa5 (diff)
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 <pvuorela@iki.fi>
-rw-r--r--tests/auto/client/datadevicev1/tst_datadevicev1.cpp30
-rw-r--r--tests/auto/client/shared/datadevice.h1
2 files changed, 30 insertions, 1 deletions
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);