summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2019-02-20 14:20:04 +0100
committerJüri Valdmann <juri.valdmann@qt.io>2019-02-21 11:15:28 +0000
commit5a6a8509a96ef6795102422e217d609815d2f086 (patch)
treeb895f2473b3a94bc56690cacce27bd84fc95b332
parent53c30cd29e9cad2003d10bbb57365d7ef61d6a4d (diff)
Emit QWebEnginePage::selectionChanged asynchronously
Currently selectionChanged is emitted from a Chromium task, meaning our MessagePump is blocked and, even with a nested QEventLoop, it's not possible to for Chromium code to make any progress during the handling of this signal. Fixes: QTBUG-73876 Change-Id: I45135238cffa81fb0db74ddfd53037c7f1b94348 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp2
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp23
2 files changed, 24 insertions, 1 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index a1ddf88d..b1e7cce4 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -255,7 +255,7 @@ void QWebEnginePagePrivate::didUpdateTargetURL(const QUrl &hoveredUrl)
void QWebEnginePagePrivate::selectionChanged()
{
Q_Q(QWebEnginePage);
- Q_EMIT q->selectionChanged();
+ QTimer::singleShot(0, q, &QWebEnginePage::selectionChanged);
}
void QWebEnginePagePrivate::recentlyAudibleChanged(bool recentlyAudible)
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 0504d39f..f4d0ad1a 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -138,6 +138,7 @@ private Q_SLOTS:
void runJavaScript();
void runJavaScriptDisabled();
+ void runJavaScriptFromSlot();
void fullScreenRequested();
void quotaRequested();
@@ -1644,6 +1645,28 @@ void tst_QWebEnginePage::runJavaScriptDisabled()
QVariant(2));
}
+// Based on https://bugreports.qt.io/browse/QTBUG-73876
+void tst_QWebEnginePage::runJavaScriptFromSlot()
+{
+ QWebEngineProfile profile;
+ QWebEnginePage page(&profile);
+
+ QSignalSpy loadFinishedSpy(&page, &QWebEnginePage::loadFinished);
+ page.setHtml("<html><body>"
+ " <input type='text' id='input1' value='QtWebEngine' size='50' />"
+ "</body></html>");
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+
+ QVariant result(-1);
+ connect(&page, &QWebEnginePage::selectionChanged, [&]() {
+ result = evaluateJavaScriptSync(&page, QStringLiteral("2+2"));
+ });
+ evaluateJavaScriptSync(&page, QStringLiteral("const input = document.getElementById('input1');"
+ "input.focus();"
+ "input.select();"));
+ QTRY_COMPARE(result, QVariant(4));
+}
+
void tst_QWebEnginePage::fullScreenRequested()
{
JavaScriptCallbackWatcher watcher;