summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-03 12:59:23 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-05 11:38:23 +0200
commit8f160af577e4d979954a63ab56f56e4d0c8ad0f8 (patch)
tree0c6cf366f3309c96e43e532527aff362320b7e94 /tests
parent601003362c75283e9164e997e3835e7c36c6db00 (diff)
parentfcdde728f0c4b4af5159b993e44eb6089d70aa90 (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qmltests/data/tst_download.qml17
-rw-r--r--tests/auto/quick/qmltests/data/tst_findText.qml58
-rw-r--r--tests/auto/quick/qmltests/data/tst_loadProgress.qml21
-rw-r--r--tests/auto/quick/qmltests/data/tst_loadProgressSignal.qml60
-rw-r--r--tests/auto/quick/qmltests/data/tst_newViewRequest.qml18
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro1
-rw-r--r--tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp131
-rw-r--r--tests/auto/widgets/qwebengineview/BLACKLIST3
-rw-r--r--tests/auto/widgets/qwebengineview/resources/input_types.html14
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp270
10 files changed, 323 insertions, 270 deletions
diff --git a/tests/auto/quick/qmltests/data/tst_download.qml b/tests/auto/quick/qmltests/data/tst_download.qml
index e4e93b993..019ebd9dc 100644
--- a/tests/auto/quick/qmltests/data/tst_download.qml
+++ b/tests/auto/quick/qmltests/data/tst_download.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -28,7 +28,7 @@
import QtQuick 2.0
import QtTest 1.0
-import QtWebEngine 1.1
+import QtWebEngine 1.5
TestWebEngineView {
id: webEngineView
@@ -40,6 +40,7 @@ TestWebEngineView {
property int receivedBytes: 0
property bool cancelDownload: false
property var downloadState: []
+ property var downloadInterruptReason: null
SignalSpy {
id: downLoadRequestedSpy
@@ -55,7 +56,9 @@ TestWebEngineView {
Connections {
id: downloadItemConnections
+ ignoreUnknownSignals: true
onStateChanged: downloadState.push(target.state)
+ onInterruptReasonChanged: downloadInterruptReason = target.interruptReason
}
WebEngineProfile {
@@ -88,6 +91,7 @@ TestWebEngineView {
cancelDownload = false
downloadItemConnections.target = null
downloadState = []
+ downloadInterruptReason = null
}
function test_downloadRequest() {
@@ -96,6 +100,7 @@ TestWebEngineView {
downLoadRequestedSpy.wait()
compare(downLoadRequestedSpy.count, 1)
compare(downloadState[0], WebEngineDownloadItem.DownloadRequested)
+ verify(!downloadInterruptReason)
}
function test_totalFileLength() {
@@ -104,6 +109,7 @@ TestWebEngineView {
downLoadRequestedSpy.wait()
compare(downLoadRequestedSpy.count, 1)
compare(totalBytes, 325)
+ verify(!downloadInterruptReason)
}
function test_downloadSucceeded() {
@@ -111,10 +117,12 @@ TestWebEngineView {
webEngineView.url = Qt.resolvedUrl("download.zip")
downLoadRequestedSpy.wait()
compare(downLoadRequestedSpy.count, 1)
- compare(downloadState[1], WebEngineDownloadItem.DownloadInProgress)
+ compare(downloadState[0], WebEngineDownloadItem.DownloadRequested)
+ tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadInProgress)
downloadFinishedSpy.wait()
compare(totalBytes, receivedBytes)
tryCompare(downloadState, "2", WebEngineDownloadItem.DownloadCompleted)
+ verify(!downloadInterruptReason)
}
function test_downloadCancelled() {
@@ -124,7 +132,8 @@ TestWebEngineView {
downLoadRequestedSpy.wait()
compare(downLoadRequestedSpy.count, 1)
compare(downloadFinishedSpy.count, 1)
- compare(downloadState[1], WebEngineDownloadItem.DownloadCancelled)
+ tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadCancelled)
+ tryCompare(webEngineView, "downloadInterruptReason", WebEngineDownloadItem.UserCanceled)
}
}
}
diff --git a/tests/auto/quick/qmltests/data/tst_findText.qml b/tests/auto/quick/qmltests/data/tst_findText.qml
index 78359bfc2..8526012c9 100644
--- a/tests/auto/quick/qmltests/data/tst_findText.qml
+++ b/tests/auto/quick/qmltests/data/tst_findText.qml
@@ -61,6 +61,32 @@ TestWebEngineView {
return bodyInnerHTML;
}
+ function getListItemText(index) {
+ var listItemText;
+ runJavaScript("document.getElementById('list').getElementsByTagName('li')[" + index + "].innerText;", function(result) {
+ listItemText = result;
+ });
+ tryVerify(function() { return listItemText != undefined; });
+ return listItemText;
+ }
+
+ function appendListItem(text) {
+ var script =
+ "(function () {" +
+ " var list = document.getElementById('list');" +
+ " var item = document.createElement('li');" +
+ " item.appendChild(document.createTextNode('" + text + "'));" +
+ " list.appendChild(item);" +
+ " return list.getElementsByTagName('li').length - 1;" +
+ "})();";
+ var itemIndex;
+
+ runJavaScript(script, function(result) { itemIndex = result; });
+ tryVerify(function() { return itemIndex != undefined; });
+ // Make sure the DOM is up-to-date.
+ tryVerify(function() { return getListItemText(itemIndex).length == text.length; });
+ }
+
function test_findText() {
var findFlags = WebEngineView.FindCaseSensitively
webEngineView.url = Qt.resolvedUrl("test1.html")
@@ -157,5 +183,37 @@ TestWebEngineView {
tryCompare(webEngineView, "matchCount", 1)
verify(!findFailed)
}
+
+ function test_findTextInterruptedByLoad() {
+ var findFlags = 0;
+
+ var listItemText = '';
+ for (var i = 0; i < 100000; ++i)
+ listItemText += "bla ";
+ listItemText = listItemText.trim();
+
+ webEngineView.loadHtml(
+ "<html><body>" +
+ "<ol id='list' />" +
+ "</body></html>");
+ verify(webEngineView.waitForLoadSucceeded());
+
+ // Generating a huge list is a workaround to avoid timeout while loading the test page.
+ for (var i = 0; i < 10; ++i)
+ appendListItem(listItemText);
+ appendListItem("hello");
+
+ webEngineView.clear();
+ webEngineView.findText("hello", findFlags, webEngineView.findTextCallback);
+
+ // This should not crash.
+ webEngineView.url = "https://www.qt.io";
+ if (!webEngineView.waitForLoadSucceeded(12000))
+ skip("Couldn't load page from network, skipping test.");
+
+ // Can't be sure whether the findText succeeded before the new load.
+ // Thus don't check the find result just whether the callback was called.
+ tryVerify(function() { return webEngineView.matchCount != -1; });
+ }
}
}
diff --git a/tests/auto/quick/qmltests/data/tst_loadProgress.qml b/tests/auto/quick/qmltests/data/tst_loadProgress.qml
index 32cd91418..bb85ed8e3 100644
--- a/tests/auto/quick/qmltests/data/tst_loadProgress.qml
+++ b/tests/auto/quick/qmltests/data/tst_loadProgress.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -41,15 +41,31 @@ TestWebEngineView {
loadProgressArray.push(webEngineView.loadProgress)
}
+ SignalSpy {
+ id: spyProgress
+ target: webEngineView
+ signalName: "loadProgressChanged"
+ }
+
TestCase {
name: "WebEngineViewLoadProgress"
function test_loadProgress() {
compare(webEngineView.loadProgress, 0)
+ compare(spyProgress.count, 0)
loadProgressArray = []
webEngineView.url = Qt.resolvedUrl("test1.html")
+ // Wait for the first loadProgressChanged signal, which have to be non-negative
+ spyProgress.wait()
+ verify(loadProgressArray[0] >= 0)
+ verify(webEngineView.loadProgress >= 0)
+
+ // Wait for the last loadProgressChanged signal, which have to be 100%
verify(webEngineView.waitForLoadSucceeded())
+ spyProgress.wait()
+ compare(loadProgressArray[loadProgressArray.length - 1], 100)
+ compare(webEngineView.loadProgress, 100)
// Test whether the chromium emits progress numbers in ascending order
var loadProgressMin = 0
@@ -58,9 +74,6 @@ TestWebEngineView {
verify(loadProgressMin <= loadProgress)
loadProgressMin = loadProgress
}
-
- // The progress must be 100% at the end
- compare(loadProgressArray[loadProgressArray.length - 1], 100)
}
}
}
diff --git a/tests/auto/quick/qmltests/data/tst_loadProgressSignal.qml b/tests/auto/quick/qmltests/data/tst_loadProgressSignal.qml
deleted file mode 100644
index f05bb1e3d..000000000
--- a/tests/auto/quick/qmltests/data/tst_loadProgressSignal.qml
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-import QtQuick 2.0
-import QtTest 1.0
-import QtWebEngine 1.2
-
-TestWebEngineView {
- id: webEngineView
- width: 400
- height: 300
-
- SignalSpy {
- id: spyProgress
- target: webEngineView
- signalName: "loadProgressChanged"
- }
-
- TestCase {
- name: "WebEngineViewLoadProgressSignal"
-
- function test_loadProgressSignal() {
- compare(spyProgress.count, 0)
- compare(webEngineView.loadProgress, 0)
- webEngineView.url = Qt.resolvedUrl("test1.html")
- spyProgress.wait()
- verify(webEngineView.loadProgress > -1 && webEngineView.loadProgress < 101)
- if (webEngineView.loadProgress > 0 && webEngineView.loadProgress < 100) {
- verify(webEngineView.waitForLoadSucceeded())
- spyProgress.wait()
- compare(webEngineView.loadProgress, 100)
- }
- }
- }
-}
diff --git a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml
index 7a04d5f5b..4becbb620 100644
--- a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml
+++ b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml
@@ -28,7 +28,7 @@
import QtQuick 2.0
import QtTest 1.0
-import QtWebEngine 1.2
+import QtWebEngine 1.5
TestWebEngineView {
id: webEngineView
@@ -47,7 +47,8 @@ TestWebEngineView {
onNewViewRequested: {
newViewRequest = {
"destination": request.destination,
- "userInitiated": request.userInitiated
+ "userInitiated": request.userInitiated,
+ "requestedUrl": request.requestedUrl
};
dialog = Qt.createQmlObject(
@@ -81,6 +82,8 @@ TestWebEngineView {
}
function test_jsWindowOpen() {
+ var url = 'data:text/html,%3Chtml%3E%3Cbody%3ETest+Page%3C%2Fbody%3E%3C%2Fhtml%3E';
+
// Open an empty page in a new tab
webEngineView.loadHtml(
"<html><head><script>" +
@@ -95,28 +98,30 @@ TestWebEngineView {
verify(dialog.webEngineView.waitForLoadSucceeded());
compare(dialog.webEngineView.url, "");
+ compare(newViewRequest.requestedUrl, 'about:blank');
newViewRequestedSpy.clear();
dialog.destroy();
- // Open an empty page in a new dialog
+ // Open a page in a new dialog
webEngineView.loadHtml(
"<html><head><script>" +
- " function popup() { window.open('', '_blank', 'width=200,height=100'); }" +
+ " function popup() { window.open('" + url + "', '_blank', 'width=200,height=100'); }" +
"</script></head>" +
"<body onload='popup()'></body></html>");
verify(webEngineView.waitForLoadSucceeded());
tryCompare(newViewRequestedSpy, "count", 1);
compare(newViewRequest.destination, WebEngineView.NewViewInDialog);
+ compare(newViewRequest.requestedUrl, url);
verify(!newViewRequest.userInitiated);
verify(dialog.webEngineView.waitForLoadSucceeded());
newViewRequestedSpy.clear();
dialog.destroy();
- // Open an empty page in a new dialog by user
+ // Open a page in a new dialog by user
webEngineView.loadHtml(
"<html><head><script>" +
- " function popup() { window.open('', '_blank', 'width=200,height=100'); }" +
+ " function popup() { window.open('" + url + "', '_blank', 'width=200,height=100'); }" +
"</script></head>" +
"<body onload=\"document.getElementById('popupButton').focus();\">" +
" <button id='popupButton' onclick='popup()'>Pop Up!</button>" +
@@ -124,6 +129,7 @@ TestWebEngineView {
verify(webEngineView.waitForLoadSucceeded());
verifyElementHasFocus("popupButton");
keyPress(Qt.Key_Enter);
+ compare(newViewRequest.requestedUrl, url);
tryCompare(newViewRequestedSpy, "count", 1);
compare(newViewRequest.destination, WebEngineView.NewViewInDialog);
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 3973ede14..d2c9245bd 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -58,7 +58,6 @@ OTHER_FILES += \
$$PWD/data/tst_loadFail.qml \
$$PWD/data/tst_loadHtml.qml \
$$PWD/data/tst_loadProgress.qml \
- $$PWD/data/tst_loadProgressSignal.qml \
$$PWD/data/tst_loadRecursionCrash.qml \
$$PWD/data/tst_loadUrl.qml \
$$PWD/data/tst_navigationHistory.qml \
diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
index dffd995c9..d9bbce173 100644
--- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
+++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp
@@ -37,8 +37,9 @@ public:
protected :
void loadPage(int nr)
{
+ loadFinishedSpy->clear();
page->load(QUrl("qrc:/resources/page" + QString::number(nr) + ".html"));
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 1);
}
public Q_SLOTS:
@@ -75,7 +76,7 @@ private Q_SLOTS:
private:
QWebEnginePage* page;
QWebEngineHistory* hist;
- QScopedPointer<SignalBarrier> loadFinishedBarrier;
+ QScopedPointer<QSignalSpy> loadFinishedSpy;
int histsize;
};
@@ -94,7 +95,7 @@ void tst_QWebEngineHistory::initTestCase()
void tst_QWebEngineHistory::init()
{
page = new QWebEnginePage(this);
- loadFinishedBarrier.reset(new SignalBarrier(page, SIGNAL(loadFinished(bool))));
+ loadFinishedSpy.reset(new QSignalSpy(page, SIGNAL(loadFinished(bool))));
for (int i = 1;i < 6;i++) {
loadPage(i);
@@ -105,7 +106,7 @@ void tst_QWebEngineHistory::init()
void tst_QWebEngineHistory::cleanup()
{
- loadFinishedBarrier.reset();
+ loadFinishedSpy.reset();
delete page;
}
@@ -114,7 +115,7 @@ void tst_QWebEngineHistory::cleanup()
*/
void tst_QWebEngineHistory::title()
{
- QCOMPARE(hist->currentItem().title(), QString("page5"));
+ QTRY_COMPARE(hist->currentItem().title(), QString("page5"));
}
void tst_QWebEngineHistory::lastVisited()
@@ -128,7 +129,7 @@ void tst_QWebEngineHistory::lastVisited()
*/
void tst_QWebEngineHistory::count()
{
- QCOMPARE(hist->count(), histsize);
+ QTRY_COMPARE(hist->count(), histsize);
}
/**
@@ -136,17 +137,17 @@ void tst_QWebEngineHistory::count()
*/
void tst_QWebEngineHistory::back()
{
- SignalBarrier titleChangedBarrier(page, SIGNAL(titleChanged(const QString&)));
+ QSignalSpy titleChangedSpy(page, SIGNAL(titleChanged(const QString&)));
for (int i = histsize;i > 1;i--) {
- QCOMPARE(toPlainTextSync(page), QString("page") + QString::number(i));
+ QTRY_COMPARE(toPlainTextSync(page), QString("page") + QString::number(i));
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
- QVERIFY(titleChangedBarrier.ensureSignalEmitted());
+ QTRY_COMPARE(loadFinishedSpy->count(), histsize-i+1);
+ QTRY_COMPARE(titleChangedSpy.count(), histsize-i+1);
}
//try one more time (too many). crash test
hist->back();
- QCOMPARE(toPlainTextSync(page), QString("page1"));
+ QTRY_COMPARE(toPlainTextSync(page), QString("page1"));
}
/**
@@ -155,21 +156,23 @@ void tst_QWebEngineHistory::back()
void tst_QWebEngineHistory::forward()
{
//rewind history :-)
+ int histBackCount = 0;
while (hist->canGoBack()) {
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
+ histBackCount++;
+ QTRY_COMPARE(loadFinishedSpy->count(), histBackCount+1);
}
- SignalBarrier titleChangedBarrier(page, SIGNAL(titleChanged(const QString&)));
+ QSignalSpy titleChangedSpy(page, SIGNAL(titleChanged(const QString&)));
for (int i = 1;i < histsize;i++) {
- QCOMPARE(toPlainTextSync(page), QString("page") + QString::number(i));
+ QTRY_COMPARE(toPlainTextSync(page), QString("page") + QString::number(i));
hist->forward();
- loadFinishedBarrier->ensureSignalEmitted();
- QVERIFY(titleChangedBarrier.ensureSignalEmitted());
+ QTRY_COMPARE(loadFinishedSpy->count(), i+histBackCount);
+ QTRY_COMPARE(titleChangedSpy.count(), i);
}
//try one more time (too many). crash test
hist->forward();
- QCOMPARE(toPlainTextSync(page), QString("page") + QString::number(histsize));
+ QTRY_COMPARE(toPlainTextSync(page), QString("page") + QString::number(histsize));
}
/**
@@ -178,7 +181,7 @@ void tst_QWebEngineHistory::forward()
void tst_QWebEngineHistory::itemAt()
{
for (int i = 1;i < histsize;i++) {
- QCOMPARE(hist->itemAt(i - 1).title(), QString("page") + QString::number(i));
+ QTRY_COMPARE(hist->itemAt(i - 1).title(), QString("page") + QString::number(i));
QVERIFY(hist->itemAt(i - 1).isValid());
}
//check out of range values
@@ -192,14 +195,19 @@ void tst_QWebEngineHistory::itemAt()
void tst_QWebEngineHistory::goToItem()
{
QWebEngineHistoryItem current = hist->currentItem();
+
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 2);
+
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 3);
+
QVERIFY(hist->currentItem().title() != current.title());
+
hist->goToItem(current);
- loadFinishedBarrier->ensureSignalEmitted();
- QCOMPARE(hist->currentItem().title(), current.title());
+ QTRY_COMPARE(loadFinishedSpy->count(), 3);
+
+ QTRY_COMPARE(hist->currentItem().title(), current.title());
}
/**
@@ -209,25 +217,27 @@ void tst_QWebEngineHistory::items()
{
QList<QWebEngineHistoryItem> items = hist->items();
//check count
- QCOMPARE(histsize, items.count());
+ QTRY_COMPARE(histsize, items.count());
//check order
for (int i = 1;i <= histsize;i++) {
- QCOMPARE(items.at(i - 1).title(), QString("page") + QString::number(i));
+ QTRY_COMPARE(items.at(i - 1).title(), QString("page") + QString::number(i));
}
}
void tst_QWebEngineHistory::backForwardItems()
{
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 2);
+
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
- QCOMPARE(hist->items().size(), 5);
- QCOMPARE(hist->backItems(100).size(), 2);
- QCOMPARE(hist->backItems(1).size(), 1);
- QCOMPARE(hist->forwardItems(100).size(), 2);
- QCOMPARE(hist->forwardItems(1).size(), 1);
+ QTRY_COMPARE(loadFinishedSpy->count(), 3);
+
+ QTRY_COMPARE(hist->items().size(), 5);
+ QTRY_COMPARE(hist->backItems(100).size(), 2);
+ QTRY_COMPARE(hist->backItems(1).size(), 1);
+ QTRY_COMPARE(hist->forwardItems(100).size(), 2);
+ QTRY_COMPARE(hist->forwardItems(1).size(), 1);
}
/**
@@ -242,20 +252,20 @@ void tst_QWebEngineHistory::serialize_1()
save << *hist;
QVERIFY(save.status() == QDataStream::Ok);
- QCOMPARE(hist->count(), histsize);
+ QTRY_COMPARE(hist->count(), histsize);
//check size of history
//load next page to find differences
loadPage(6);
- QCOMPARE(hist->count(), histsize + 1);
+ QTRY_COMPARE(hist->count(), histsize + 1);
load >> *hist;
QVERIFY(load.status() == QDataStream::Ok);
- QCOMPARE(hist->count(), histsize);
+ QTRY_COMPARE(hist->count(), histsize);
//check order of historyItems
QList<QWebEngineHistoryItem> items = hist->items();
for (int i = 1;i <= histsize;i++) {
- QCOMPARE(items.at(i - 1).title(), QString("page") + QString::number(i));
+ QTRY_COMPARE(items.at(i - 1).title(), QString("page") + QString::number(i));
}
}
@@ -271,16 +281,16 @@ void tst_QWebEngineHistory::serialize_2()
// Force a "same document" navigation.
page->load(page->url().toString() + QLatin1String("#dummyAnchor"));
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 1);
int initialCurrentIndex = hist->currentItemIndex();
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 2);
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 3);
hist->back();
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 4);
//check if current index was changed (make sure that it is not last item)
QVERIFY(hist->currentItemIndex() != initialCurrentIndex);
//save current index
@@ -291,18 +301,18 @@ void tst_QWebEngineHistory::serialize_2()
load >> *hist;
QVERIFY(load.status() == QDataStream::Ok);
// Restoring the history will trigger a load.
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 5);
//check current index
- QCOMPARE(hist->currentItemIndex(), oldCurrentIndex);
+ QTRY_COMPARE(hist->currentItemIndex(), oldCurrentIndex);
hist->forward();
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 6);
hist->forward();
- loadFinishedBarrier->ensureSignalEmitted();
+ QTRY_COMPARE(loadFinishedSpy->count(), 7);
hist->forward();
- loadFinishedBarrier->ensureSignalEmitted();
- QCOMPARE(hist->currentItemIndex(), initialCurrentIndex);
+ QTRY_COMPARE(loadFinishedSpy->count(), 8);
+ QTRY_COMPARE(hist->currentItemIndex(), initialCurrentIndex);
}
/**
@@ -334,10 +344,10 @@ void tst_QWebEngineHistory::serialize_3()
QWebEngineHistoryItem b = hist->currentItem();
//check properties AFTER serialization
- QCOMPARE(b.title(), title);
- QCOMPARE(b.lastVisited(), lastVisited);
- QCOMPARE(b.originalUrl(), originalUrl);
- QCOMPARE(b.url(), url);
+ QTRY_COMPARE(b.title(), title);
+ QTRY_COMPARE(b.lastVisited(), lastVisited);
+ QTRY_COMPARE(b.originalUrl(), originalUrl);
+ QTRY_COMPARE(b.url(), url);
//Check if all data was read
QVERIFY(load.atEnd());
@@ -398,27 +408,16 @@ void tst_QWebEngineHistory::saveAndRestore_crash_3()
void tst_QWebEngineHistory::saveAndRestore_crash_4()
{
-#if !defined(QWEBENGINESETTINGS)
- QSKIP("QWEBENGINESETTINGS");
-#else
QByteArray buffer;
saveHistory(hist, &buffer);
QScopedPointer<QWebEnginePage> page2(new QWebEnginePage(this));
- // The initial crash was in PageCache.
- page2->settings()->setMaximumPagesInCache(3);
// Load the history in a new page, waiting for the load to finish.
- QEventLoop waitForLoadFinished;
- QObject::connect(page2.data(), SIGNAL(loadFinished(bool)), &waitForLoadFinished, SLOT(quit()), Qt::QueuedConnection);
+ QSignalSpy loadFinishedSpy2(page2.data(), SIGNAL(loadFinished(bool)));
QDataStream load(&buffer, QIODevice::ReadOnly);
load >> *page2->history();
- waitForLoadFinished.exec();
-
- page2.reset();
- // Give some time for the PageCache cleanup 0-timer to fire.
- QTest::qWait(50);
-#endif
+ QTRY_COMPARE(loadFinishedSpy2.count(), 1);
}
void tst_QWebEngineHistory::popPushState_data()
@@ -469,10 +468,10 @@ void tst_QWebEngineHistory::historyItemFromDeletedPage()
foreach (QWebEngineHistoryItem item, items) {
QVERIFY(!item.isValid());
- QCOMPARE(item.originalUrl(), QUrl());
- QCOMPARE(item.url(), QUrl());
- QCOMPARE(item.title(), QString());
- QCOMPARE(item.lastVisited(), QDateTime());
+ QTRY_COMPARE(item.originalUrl(), QUrl());
+ QTRY_COMPARE(item.url(), QUrl());
+ QTRY_COMPARE(item.title(), QString());
+ QTRY_COMPARE(item.lastVisited(), QDateTime());
}
}
diff --git a/tests/auto/widgets/qwebengineview/BLACKLIST b/tests/auto/widgets/qwebengineview/BLACKLIST
index 7121f7561..b3f393af4 100644
--- a/tests/auto/widgets/qwebengineview/BLACKLIST
+++ b/tests/auto/widgets/qwebengineview/BLACKLIST
@@ -3,3 +3,6 @@ windows
[imeComposition]
osx
+
+[inputFieldOverridesShortcuts]
+osx
diff --git a/tests/auto/widgets/qwebengineview/resources/input_types.html b/tests/auto/widgets/qwebengineview/resources/input_types.html
index 2e893afae..5ba1a6069 100644
--- a/tests/auto/widgets/qwebengineview/resources/input_types.html
+++ b/tests/auto/widgets/qwebengineview/resources/input_types.html
@@ -1,9 +1,9 @@
<html><body>
-<input type='text' maxlength='20' style='position: absolute; left: 10px; top: 0px; height: 50px; width: 100px;'/><br>
-<input type='password' style='position: absolute; left: 10px; top: 50px; height: 50px; width: 100px;'/><br>
-<input type='tel' style='position: absolute; left: 10px; top: 100px; height: 50px; width: 100px;'/><br>
-<input type='number' style='position: absolute; left: 10px; top: 150px; height: 50px; width: 100px;'/><br>
-<input type='email' style='position: absolute; left: 10px; top: 200px; height: 50px; width: 100px;'/><br>
-<input type='url' style='position: absolute; left: 10px; top: 250px; height: 50px; width: 100px;'/><br>
-<textarea style='position: absolute; left: 10px; top: 310px; height: 50px; width: 100px;' rows="2" cols="20">blah blah blah blah</textarea><br>
+<input type='text' id='textInput' maxlength='20' style='position: absolute; left: 10px; top: 0px; height: 50px; width: 100px;'/><br>
+<input type='password' id='passwordInput' style='position: absolute; left: 10px; top: 50px; height: 50px; width: 100px;'/><br>
+<input type='tel' id='telInput' style='position: absolute; left: 10px; top: 100px; height: 50px; width: 100px;'/><br>
+<input type='number' id='numberInput' style='position: absolute; left: 10px; top: 150px; height: 50px; width: 100px;'/><br>
+<input type='email' id='emailInput' style='position: absolute; left: 10px; top: 200px; height: 50px; width: 100px;'/><br>
+<input type='url' id='urlInput' style='position: absolute; left: 10px; top: 250px; height: 50px; width: 100px;'/><br>
+<textarea id='textArea' style='position: absolute; left: 10px; top: 310px; height: 50px; width: 100px;' rows="2" cols="20">blah blah blah blah</textarea><br>
</body></html>
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index 37c7ae881..8509e9a2d 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -55,6 +55,43 @@ do { \
QCOMPARE((__expr), __expected); \
} while (0)
+static QPoint elementCenter(QWebEnginePage *page, const QString &id)
+{
+ const QString jsCode(
+ "(function(){"
+ " var elem = document.getElementById('" + id + "');"
+ " var rect = elem.getBoundingClientRect();"
+ " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];"
+ "})()");
+ QVariantList rectList = evaluateJavaScriptSync(page, jsCode).toList();
+
+ if (rectList.count() != 2) {
+ qWarning("elementCenter failed.");
+ return QPoint();
+ }
+
+ return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt());
+}
+
+static QRect elementGeometry(QWebEnginePage *page, const QString &id)
+{
+ const QString jsCode(
+ "(function() {"
+ " var elem = document.getElementById('" + id + "');"
+ " var rect = elem.getBoundingClientRect();"
+ " return [rect.left, rect.top, rect.right, rect.bottom];"
+ "})()");
+ QVariantList coords = evaluateJavaScriptSync(page, jsCode).toList();
+
+ if (coords.count() != 4) {
+ qWarning("elementGeometry faield.");
+ return QRect();
+ }
+
+ return QRect(coords[0].toInt(), coords[1].toInt(), coords[2].toInt(), coords[3].toInt());
+}
+
+
class tst_QWebEngineView : public QObject
{
Q_OBJECT
@@ -263,113 +300,111 @@ void tst_QWebEngineView::crashTests()
void tst_QWebEngineView::microFocusCoordinates()
{
-#if !defined(QWEBENGINEPAGE_INPUTMETHODQUERY)
- QSKIP("QWEBENGINEPAGE_INPUTMETHODQUERY");
-#else
- QWebEnginePage* page = new QWebEnginePage;
- QWebEngineView* webView = new QWebEngineView;
- webView->setPage( page );
-
- page->setHtml("<html><body>" \
- "<input type='text' id='input1' style='font--family: serif' value='' maxlength='20'/><br>" \
- "<canvas id='canvas1' width='500' height='500'></canvas>" \
- "<input type='password'/><br>" \
- "<canvas id='canvas2' width='500' height='500'></canvas>" \
- "</body></html>");
-
-#if defined(QWEBENGINEFRAME)
- page->mainFrame()->setFocus();
-#endif
+ QWebEngineView webView;
+ webView.show();
+ QTest::qWaitForWindowExposed(&webView);
+
+ QSignalSpy scrollSpy(webView.page(), SIGNAL(scrollPositionChanged(QPointF)));
+ QSignalSpy loadFinishedSpy(&webView, SIGNAL(loadFinished(bool)));
+ webView.page()->setHtml("<html><body>"
+ "<input type='text' id='input1' value='' maxlength='20'/><br>"
+ "<canvas id='canvas1' width='500' height='500'></canvas>"
+ "<input type='password'/><br>"
+ "<canvas id='canvas2' width='500' height='500'></canvas>"
+ "</body></html>");
+ QVERIFY(loadFinishedSpy.wait());
- QVariant initialMicroFocus = page->inputMethodQuery(Qt::ImMicroFocus);
- QVERIFY(initialMicroFocus.isValid());
+ evaluateJavaScriptSync(webView.page(), "document.getElementById('input1').focus()");
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("input1"));
- page->scroll(0,50);
+ QTRY_VERIFY(webView.focusProxy()->inputMethodQuery(Qt::ImMicroFocus).isValid());
+ QVariant initialMicroFocus = webView.focusProxy()->inputMethodQuery(Qt::ImMicroFocus);
- QVariant currentMicroFocus = page->inputMethodQuery(Qt::ImMicroFocus);
- QVERIFY(currentMicroFocus.isValid());
+ evaluateJavaScriptSync(webView.page(), "window.scrollBy(0, 50)");
+ QVERIFY(scrollSpy.wait());
+
+ QTRY_VERIFY(webView.focusProxy()->inputMethodQuery(Qt::ImMicroFocus).isValid());
+ QVariant currentMicroFocus = webView.focusProxy()->inputMethodQuery(Qt::ImMicroFocus);
QCOMPARE(initialMicroFocus.toRect().translated(QPoint(0,-50)), currentMicroFocus.toRect());
-#endif
}
void tst_QWebEngineView::focusInputTypes()
{
-#if !defined(QWEBENGINEELEMENT)
- QSKIP("QWEBENGINEELEMENT");
-#else
QWebEngineView webView;
webView.show();
QTest::qWaitForWindowExposed(&webView);
- QUrl url("qrc:///resources/input_types.html");
- QWebEngineFrame* const mainFrame = webView.page()->mainFrame();
- webView.load(url);
- mainFrame->setFocus();
-
- QSignalSpy spyFinished(webView, &QWebEngineView::loadFinished);
- QVERIFY(spyFinished.wait());
+ QSignalSpy loadFinishedSpy(&webView, SIGNAL(loadFinished(bool)));
+ webView.load(QUrl("qrc:///resources/input_types.html"));
+ QVERIFY(loadFinishedSpy.wait());
- // 'text' type
- QWebEngineElement inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=text]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- QVERIFY(webView.inputMethodHints() == Qt::ImhNone);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ // 'text' field
+ QPoint textInputCenter = elementCenter(webView.page(), "textInput");
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, textInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("textInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhPreferLowercase);
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'password' field
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=password]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- VERIFY_INPUTMETHOD_HINTS(webView.inputMethodHints(), Qt::ImhHiddenText);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ QPoint passwordInputCenter = elementCenter(webView.page(), "passwordInput");
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, passwordInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("passwordInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhSensitiveData | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase | Qt::ImhHiddenText));
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'tel' field
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=tel]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- VERIFY_INPUTMETHOD_HINTS(webView.inputMethodHints(), Qt::ImhDialableCharactersOnly);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ QPoint telInputCenter = elementCenter(webView.page(), "telInput");
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, telInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("telInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhDialableCharactersOnly);
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'number' field
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=number]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- VERIFY_INPUTMETHOD_HINTS(webView.inputMethodHints(), Qt::ImhDigitsOnly);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ QPoint numberInputCenter = elementCenter(webView.page(), "numberInput");
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, numberInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("numberInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhFormattedNumbersOnly);
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'email' field
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=email]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- VERIFY_INPUTMETHOD_HINTS(webView.inputMethodHints(), Qt::ImhEmailCharactersOnly);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ QPoint emailInputCenter = elementCenter(webView.page(), "emailInput");
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, emailInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("emailInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhEmailCharactersOnly);
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'url' field
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=url]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- VERIFY_INPUTMETHOD_HINTS(webView.inputMethodHints(), Qt::ImhUrlCharactersOnly);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ QPoint urlInputCenter = elementCenter(webView.page(), "urlInput");
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, urlInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("urlInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhUrlCharactersOnly | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase));
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'password' field
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=password]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- VERIFY_INPUTMETHOD_HINTS(webView.inputMethodHints(), Qt::ImhHiddenText);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, passwordInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("passwordInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhSensitiveData | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase | Qt::ImhHiddenText));
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'text' type
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=text]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- QVERIFY(webView.inputMethodHints() == Qt::ImhNone);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, textInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("textInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), Qt::ImhPreferLowercase);
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'password' field
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("input[type=password]"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- VERIFY_INPUTMETHOD_HINTS(webView.inputMethodHints(), Qt::ImhHiddenText);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, passwordInputCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("passwordInput"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhSensitiveData | Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase | Qt::ImhHiddenText));
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
// 'text area' field
- inputElement = mainFrame->documentElement().findFirst(QLatin1String("textarea"));
- QTest::mouseClick(&webView, Qt::LeftButton, 0, inputElement.geometry().center());
- QVERIFY(webView.inputMethodHints() == Qt::ImhNone);
- QVERIFY(webView.testAttribute(Qt::WA_InputMethodEnabled));
-#endif
+ QPoint textAreaCenter = elementCenter(webView.page(), "textArea");
+ QTest::mouseClick(webView.focusProxy(), Qt::LeftButton, 0, textAreaCenter);
+ QTRY_COMPARE(evaluateJavaScriptSync(webView.page(), "document.activeElement.id").toString(), QStringLiteral("textArea"));
+ VERIFY_INPUTMETHOD_HINTS(webView.focusProxy()->inputMethodHints(), (Qt::ImhMultiLine | Qt::ImhPreferLowercase));
+ QVERIFY(webView.focusProxy()->testAttribute(Qt::WA_InputMethodEnabled));
}
class KeyEventRecordingWidget : public QWidget {
@@ -1309,7 +1344,6 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts()
{
bool actionTriggered = false;
QAction *action = new QAction;
- action->setShortcut(Qt::Key_X);
connect(action, &QAction::triggered, [&actionTriggered] () { actionTriggered = true; });
QWebEngineView view;
@@ -1317,7 +1351,7 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts()
QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool)));
view.setHtml(QString("<html><body onload=\"input1=document.getElementById('input1')\">"
- "<input id=\"dummy\" type=\"text\">"
+ "<button id=\"btn1\" type=\"button\">push it real good</button>"
"<input id=\"input1\" type=\"text\" value=\"x\">"
"</body></html>"));
QVERIFY(loadFinishedSpy.wait());
@@ -1330,7 +1364,15 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts()
"input1.value").toString();
};
+ // The input form is not focused. The action is triggered on pressing Shift+Delete.
+ action->setShortcut(Qt::SHIFT + Qt::Key_Delete);
+ QTest::keyClick(view.windowHandle(), Qt::Key_Delete, Qt::ShiftModifier);
+ QTRY_VERIFY(actionTriggered);
+ QCOMPARE(inputFieldValue(), QString("x"));
+
// The input form is not focused. The action is triggered on pressing X.
+ action->setShortcut(Qt::Key_X);
+ actionTriggered = false;
QTest::keyClick(view.windowHandle(), Qt::Key_X);
QTRY_VERIFY(actionTriggered);
QCOMPARE(inputFieldValue(), QString("x"));
@@ -1349,16 +1391,12 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts()
QTRY_VERIFY(actionTriggered);
QCOMPARE(inputFieldValue(), QString("yx"));
- // Remove focus from the input field. A QKeySequence::Copy action still must not be triggered.
- evaluateJavaScriptSync(view.page(), "input1.blur();");
+ // Remove focus from the input field. A QKeySequence::Copy action must be triggerable.
+ evaluateJavaScriptSync(view.page(), "document.getElementById('btn1').focus();");
action->setShortcut(QKeySequence::Copy);
actionTriggered = false;
QTest::keyClick(view.windowHandle(), Qt::Key_C, Qt::ControlModifier);
- // Add some text in the input field to ensure that the key event went through.
- evaluateJavaScriptSync(view.page(), "input1.focus();");
- QTest::keyClick(view.windowHandle(), Qt::Key_U);
- QTRY_COMPARE(inputFieldValue(), QString("yux"));
- QVERIFY(!actionTriggered);
+ QTRY_VERIFY(actionTriggered);
}
class TestInputContext : public QPlatformInputContext
@@ -1393,42 +1431,6 @@ public:
bool m_visible;
};
-static QPoint elementCenter(QWebEnginePage *page, const QString &id)
-{
- const QString jsCode(
- "(function(){"
- " var elem = document.getElementById('" + id + "');"
- " var rect = elem.getBoundingClientRect();"
- " return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];"
- "})()");
- QVariantList rectList = evaluateJavaScriptSync(page, jsCode).toList();
-
- if (rectList.count() != 2) {
- qWarning("elementCenter failed.");
- return QPoint();
- }
-
- return QPoint(rectList.at(0).toInt(), rectList.at(1).toInt());
-}
-
-static QRect elementGeometry(QWebEnginePage *page, const QString &id)
-{
- const QString jsCode(
- "(function() {"
- " var elem = document.getElementById('" + id + "');"
- " var rect = elem.getBoundingClientRect();"
- " return [rect.left, rect.top, rect.right, rect.bottom];"
- "})()");
- QVariantList coords = evaluateJavaScriptSync(page, jsCode).toList();
-
- if (coords.count() != 4) {
- qWarning("elementGeometry faield.");
- return QRect();
- }
-
- return QRect(coords[0].toInt(), coords[1].toInt(), coords[2].toInt(), coords[3].toInt());
-}
-
void tst_QWebEngineView::softwareInputPanel()
{
TestInputContext testContext;
@@ -1798,12 +1800,36 @@ void tst_QWebEngineView::emptyInputMethodEvent()
QEXPECT_FAIL("", "https://bugreports.qt.io/browse/QTBUG-53134", Continue);
QCOMPARE(selectionChangedSpy.count(), 1);
- // Send empty QInputMethodEvent
+ // 1. Empty input method event does not clear text
QInputMethodEvent emptyEvent;
QApplication::sendEvent(view.focusProxy(), &emptyEvent);
QString inputValue = evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString();
- QCOMPARE(inputValue, QString("QtWebEngine"));
+ QCOMPARE(inputValue, QStringLiteral("QtWebEngine"));
+ QCOMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QStringLiteral("QtWebEngine"));
+
+ // Reset: clear input field
+ evaluateJavaScriptSync(view.page(), "var inputEle = document.getElementById('input1').value = ''");
+ QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty());
+ QTRY_VERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty());
+
+ // 2. Cancel IME composition with empty input method event
+ // Start IME composition
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent eventComposition("a", attributes);
+ QApplication::sendEvent(view.focusProxy(), &eventComposition);
+ QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QStringLiteral("a"));
+ QVERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty());
+
+ // Cancel IME composition
+ QApplication::sendEvent(view.focusProxy(), &emptyEvent);
+ QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString().isEmpty());
+ QVERIFY(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString().isEmpty());
+
+ // Try key press after cancelled IME composition
+ QTest::keyClick(view.focusProxy(), Qt::Key_B);
+ QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.getElementById('input1').value").toString(), QStringLiteral("b"));
+ QTRY_COMPARE(view.focusProxy()->inputMethodQuery(Qt::ImSurroundingText).toString(), QStringLiteral("b"));
}
void tst_QWebEngineView::imeComposition()