summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKari Oikarinen <kari.oikarinen@qt.io>2019-09-04 12:12:51 +0300
committerKari Oikarinen <kari.oikarinen@qt.io>2019-09-04 13:15:42 +0300
commit705210a03a8fa1ab4366e269bff2a1d6691a912b (patch)
tree8b278bdb97f667ce54e3b36b71e4b6b8c7f49df3 /tests
parent48c85451adf1d530bccf9bfb542abb3211f0bf36 (diff)
parentff1272de6bb44dda30b90c62806d037ca4ef8b77 (diff)
Merge "Merge dev into 5.14 (delayed final downmerge)"
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp5
-rw-r--r--tests/auto/quick/qmltests/data/tst_findText.qml84
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp136
3 files changed, 213 insertions, 12 deletions
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index f464d58d0..9f7dfa8ad 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -35,6 +35,7 @@
#include <QtTest/QtTest>
#include <QtWebEngine/QQuickWebEngineProfile>
#include <QtWebEngine/QQuickWebEngineScript>
+#include <QtWebEngineCore/QWebEngineFindTextResult>
#include <QtWebEngineCore/QWebEngineNotification>
#include <QtWebEngineCore/QWebEngineQuotaRequest>
#include <QtWebEngineCore/QWebEngineRegisterProtocolHandlerRequest>
@@ -85,6 +86,7 @@ static const QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *
<< &QWebEngineQuotaRequest::staticMetaObject
<< &QWebEngineRegisterProtocolHandlerRequest::staticMetaObject
<< &QWebEngineNotification::staticMetaObject
+ << &QWebEngineFindTextResult::staticMetaObject
;
static QList<const char *> knownEnumNames = QList<const char *>();
@@ -276,6 +278,8 @@ static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineFileDialogRequest.dialogAccept(QStringList) --> void"
<< "QQuickWebEngineFileDialogRequest.dialogReject() --> void"
<< "QQuickWebEngineFileDialogRequest.mode --> FileMode"
+ << "QWebEngineFindTextResult.numberOfMatches --> int"
+ << "QWebEngineFindTextResult.activeMatchOrdinal --> int"
<< "QQuickWebEngineFormValidationMessageRequest.Hide --> RequestType"
<< "QQuickWebEngineFormValidationMessageRequest.Move --> RequestType"
<< "QQuickWebEngineFormValidationMessageRequest.Show --> RequestType"
@@ -694,6 +698,7 @@ static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineView.findText(QString) --> void"
<< "QQuickWebEngineView.findText(QString,FindFlags) --> void"
<< "QQuickWebEngineView.findText(QString,FindFlags,QJSValue) --> void"
+ << "QQuickWebEngineView.findTextFinished(QWebEngineFindTextResult) --> void"
<< "QQuickWebEngineView.formValidationMessageRequested(QQuickWebEngineFormValidationMessageRequest*) --> void"
<< "QQuickWebEngineView.fullScreenCancelled() --> void"
<< "QQuickWebEngineView.fullScreenRequested(QQuickWebEngineFullScreenRequest) --> void"
diff --git a/tests/auto/quick/qmltests/data/tst_findText.qml b/tests/auto/quick/qmltests/data/tst_findText.qml
index 14053a675..040d324e6 100644
--- a/tests/auto/quick/qmltests/data/tst_findText.qml
+++ b/tests/auto/quick/qmltests/data/tst_findText.qml
@@ -38,9 +38,16 @@ TestWebEngineView {
property int matchCount: 0
property bool findFailed: false
+ SignalSpy {
+ id: findTextSpy
+ target: webEngineView
+ signalName: "findTextFinished"
+ }
+
function clear() {
findFailed = false
matchCount = -1
+ findTextSpy.clear()
}
function findCallbackCalled() { return matchCount != -1 }
@@ -104,6 +111,9 @@ TestWebEngineView {
webEngineView.findText("Hello", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 1)
verify(!findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
}
function test_findTextCaseInsensitive() {
@@ -115,6 +125,9 @@ TestWebEngineView {
webEngineView.findText("heLLo", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 1)
verify(!findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
}
function test_findTextManyMatches() {
@@ -126,6 +139,9 @@ TestWebEngineView {
webEngineView.findText("bla", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 100, 20000)
verify(!findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 100)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
}
@@ -138,6 +154,9 @@ TestWebEngineView {
webEngineView.findText("heLLo", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 0)
verify(findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0)
}
function test_findTextNotFound() {
@@ -149,6 +168,9 @@ TestWebEngineView {
webEngineView.findText("string-that-is-not-threre", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 0)
verify(findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0)
}
function test_findTextAfterNotFound() {
@@ -160,6 +182,9 @@ TestWebEngineView {
webEngineView.findText("hello", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 0)
verify(findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0)
webEngineView.url = Qt.resolvedUrl("test1.html")
verify(webEngineView.waitForLoadSucceeded())
@@ -168,6 +193,9 @@ TestWebEngineView {
webEngineView.findText("hello", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 1)
verify(!findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
}
function test_findTextInModifiedDOMAfterNotFound() {
@@ -182,6 +210,9 @@ TestWebEngineView {
webEngineView.findText("hello", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 0, 20000)
verify(findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0)
runJavaScript("document.body.innerHTML = 'blahellobla'");
tryVerify(function() { return getBodyInnerHTML() == "blahellobla"; }, 20000);
@@ -190,6 +221,9 @@ TestWebEngineView {
webEngineView.findText("hello", findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, "matchCount", 1)
verify(!findFailed)
+ tryCompare(findTextSpy, "count", 1)
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 1)
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1)
}
function test_findTextInterruptedByLoad() {
@@ -227,5 +261,55 @@ TestWebEngineView {
webEngineView.findText('New page', findFlags, webEngineView.findTextCallback)
tryCompare(webEngineView, 'matchCount', 1)
}
+
+ function test_findTextActiveMatchOrdinal() {
+ webEngineView.loadHtml(
+ "<html><body>" +
+ "foo bar foo bar foo" +
+ "</body></html>");
+ verify(webEngineView.waitForLoadSucceeded());
+
+ // Iterate over all "foo" matches.
+ webEngineView.clear();
+ for (var i = 1; i <= 3; ++i) {
+ webEngineView.findText("foo");
+ findTextSpy.wait();
+ compare(findTextSpy.count, i);
+ compare(findTextSpy.signalArguments[i-1][0].numberOfMatches, 3);
+ compare(findTextSpy.signalArguments[i-1][0].activeMatchOrdinal, i);
+ }
+
+ // The last match is followed by the fist one.
+ webEngineView.clear();
+ webEngineView.findText("foo");
+ findTextSpy.wait();
+ compare(findTextSpy.count, 1);
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 3);
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1);
+
+ // The first match is preceded by the last one.
+ webEngineView.clear();
+ webEngineView.findText("foo", WebEngineView.FindBackward);
+ findTextSpy.wait();
+ compare(findTextSpy.count, 1);
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 3);
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 3);
+
+ // Finding another word resets the activeMatchOrdinal.
+ webEngineView.clear();
+ webEngineView.findText("bar");
+ findTextSpy.wait();
+ compare(findTextSpy.count, 1);
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 2);
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 1);
+
+ // If no match activeMatchOrdinal is 0.
+ webEngineView.clear();
+ webEngineView.findText("bla");
+ findTextSpy.wait();
+ compare(findTextSpy.count, 1);
+ compare(findTextSpy.signalArguments[0][0].numberOfMatches, 0);
+ compare(findTextSpy.signalArguments[0][0].activeMatchOrdinal, 0);
+ }
}
}
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 713feca6d..dbb15ba10 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -47,6 +47,7 @@
#include <qnetworkreply.h>
#include <qnetworkrequest.h>
#include <qwebenginedownloaditem.h>
+#include <qwebenginefindtextresult.h>
#include <qwebenginefullscreenrequest.h>
#include <qwebenginehistory.h>
#include <qwebenginenotification.h>
@@ -127,6 +128,8 @@ private Q_SLOTS:
void findText();
void findTextResult();
void findTextSuccessiveShouldCallAllCallbacks();
+ void findTextCalledOnMatch();
+ void findTextActiveMatchOrdinal();
void deleteQWebEngineViewTwice();
void loadSignalsOrder_data();
void loadSignalsOrder();
@@ -941,18 +944,24 @@ void tst_QWebEnginePage::findText()
// Invoking a stopFinding operation will not change or clear the currently selected text,
// if nothing was found beforehand.
{
- CallbackSpy<bool> spy;
- m_view->findText("", 0, spy.ref());
- QVERIFY(spy.wasCalled());
+ CallbackSpy<bool> callbackSpy;
+ QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
+ m_view->findText("", 0, callbackSpy.ref());
+ QVERIFY(callbackSpy.wasCalled());
+ QCOMPARE(signalSpy.count(), 1);
QTRY_COMPARE(m_view->selectedText(), QString("foo bar"));
}
// Invoking a startFinding operation with text that won't be found, will clear the current
// selection.
{
- CallbackSpy<bool> spy;
- m_view->findText("Will not be found", 0, spy.ref());
- QCOMPARE(spy.waitForResult(), false);
+ CallbackSpy<bool> callbackSpy;
+ QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
+ m_view->findText("Will not be found", 0, callbackSpy.ref());
+ QCOMPARE(callbackSpy.waitForResult(), false);
+ QTRY_COMPARE(signalSpy.count(), 1);
+ auto result = signalSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
+ QCOMPARE(result.numberOfMatches(), 0);
QTRY_VERIFY(m_view->selectedText().isEmpty());
}
@@ -963,24 +972,36 @@ void tst_QWebEnginePage::findText()
// Invoking a startFinding operation with text that will be found, will clear the current
// selection as well.
{
- CallbackSpy<bool> spy;
- m_view->findText("foo", 0, spy.ref());
- QVERIFY(spy.waitForResult());
+ CallbackSpy<bool> callbackSpy;
+ QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
+ m_view->findText("foo", 0, callbackSpy.ref());
+ QVERIFY(callbackSpy.waitForResult());
+ QTRY_COMPARE(signalSpy.count(), 1);
QTRY_VERIFY(m_view->selectedText().isEmpty());
}
// Invoking a stopFinding operation after text was found, will set the selected text to the
// found text.
{
- CallbackSpy<bool> spy;
- m_view->findText("", 0, spy.ref());
- QTRY_VERIFY(spy.wasCalled());
+ CallbackSpy<bool> callbackSpy;
+ QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
+ m_view->findText("", 0, callbackSpy.ref());
+ QTRY_VERIFY(callbackSpy.wasCalled());
+ QTRY_COMPARE(signalSpy.count(), 1);
QTRY_COMPARE(m_view->selectedText(), QString("foo"));
}
}
void tst_QWebEnginePage::findTextResult()
{
+ QSignalSpy findTextSpy(m_view->page(), &QWebEnginePage::findTextFinished);
+ auto signalResult = [&findTextSpy]() -> QVector<int> {
+ if (findTextSpy.count() != 1)
+ return QVector<int>({-1, -1});
+ auto r = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
+ return QVector<int>({ r.numberOfMatches(), r.activeMatchOrdinal() });
+ };
+
// findText will abort in blink if the view has an empty size.
m_view->resize(800, 600);
m_view->show();
@@ -990,15 +1011,21 @@ void tst_QWebEnginePage::findTextResult()
QTRY_COMPARE(loadSpy.count(), 1);
QCOMPARE(findTextSync(m_page, ""), false);
+ QCOMPARE(signalResult(), QVector<int>({0, 0}));
const QStringList words = { "foo", "bar" };
for (const QString &subString : words) {
QCOMPARE(findTextSync(m_page, subString), true);
+ QCOMPARE(signalResult(), QVector<int>({1, 1}));
+
QCOMPARE(findTextSync(m_page, ""), false);
+ QCOMPARE(signalResult(), QVector<int>({0, 0}));
}
QCOMPARE(findTextSync(m_page, "blahhh"), false);
+ QCOMPARE(signalResult(), QVector<int>({0, 0}));
QCOMPARE(findTextSync(m_page, ""), false);
+ QCOMPARE(signalResult(), QVector<int>({0, 0}));
}
void tst_QWebEnginePage::findTextSuccessiveShouldCallAllCallbacks()
@@ -1024,6 +1051,91 @@ void tst_QWebEnginePage::findTextSuccessiveShouldCallAllCallbacks()
QVERIFY(spy5.wasCalled());
}
+void tst_QWebEnginePage::findTextCalledOnMatch()
+{
+ QSignalSpy loadSpy(m_view->page(), &QWebEnginePage::loadFinished);
+
+ // findText will abort in blink if the view has an empty size.
+ m_view->resize(800, 600);
+ m_view->show();
+ m_view->setHtml(QString("<html><head></head><body><div>foo bar</div></body></html>"));
+ QTRY_COMPARE(loadSpy.count(), 1);
+
+ // CALLBACK
+ bool callbackCalled = false;
+ m_view->page()->findText("foo", 0, [this, &callbackCalled](bool found) {
+ QVERIFY(found);
+
+ m_view->page()->findText("bar", 0, [&callbackCalled](bool found) {
+ QVERIFY(found);
+ callbackCalled = true;
+ });
+ });
+ QTRY_VERIFY(callbackCalled);
+
+ // SIGNAL
+ int findTextFinishedCount = 0;
+ connect(m_view->page(), &QWebEnginePage::findTextFinished, [this, &findTextFinishedCount](QWebEngineFindTextResult result) {
+ QCOMPARE(result.numberOfMatches(), 1);
+ if (findTextFinishedCount == 0)
+ m_view->page()->findText("bar");
+ findTextFinishedCount++;
+ });
+
+ m_view->page()->findText("foo");
+ QTRY_COMPARE(findTextFinishedCount, 2);
+}
+
+void tst_QWebEnginePage::findTextActiveMatchOrdinal()
+{
+ QSignalSpy loadSpy(m_view->page(), &QWebEnginePage::loadFinished);
+ QSignalSpy findTextSpy(m_view->page(), &QWebEnginePage::findTextFinished);
+ QWebEngineFindTextResult result;
+
+ // findText will abort in blink if the view has an empty size.
+ m_view->resize(800, 600);
+ m_view->show();
+ m_view->setHtml(QString("<html><head></head><body><div>foo bar foo bar foo</div></body></html>"));
+ QTRY_COMPARE(loadSpy.count(), 1);
+
+ // Iterate over all "foo" matches.
+ for (int i = 1; i <= 3; ++i) {
+ m_view->page()->findText("foo", 0);
+ QTRY_COMPARE(findTextSpy.count(), 1);
+ result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
+ QCOMPARE(result.numberOfMatches(), 3);
+ QCOMPARE(result.activeMatchOrdinal(), i);
+ }
+
+ // The last match is followed by the fist one.
+ m_view->page()->findText("foo", 0);
+ QTRY_COMPARE(findTextSpy.count(), 1);
+ result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
+ QCOMPARE(result.numberOfMatches(), 3);
+ QCOMPARE(result.activeMatchOrdinal(), 1);
+
+ // The first match is preceded by the last one.
+ m_view->page()->findText("foo", QWebEnginePage::FindBackward);
+ QTRY_COMPARE(findTextSpy.count(), 1);
+ result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
+ QCOMPARE(result.numberOfMatches(), 3);
+ QCOMPARE(result.activeMatchOrdinal(), 3);
+
+ // Finding another word resets the activeMatchOrdinal.
+ m_view->page()->findText("bar", 0);
+ QTRY_COMPARE(findTextSpy.count(), 1);
+ result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
+ QCOMPARE(result.numberOfMatches(), 2);
+ QCOMPARE(result.activeMatchOrdinal(), 1);
+
+ // If no match activeMatchOrdinal is 0.
+ m_view->page()->findText("bla", 0);
+ QTRY_COMPARE(findTextSpy.count(), 1);
+ result = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
+ QCOMPARE(result.numberOfMatches(), 0);
+ QCOMPARE(result.activeMatchOrdinal(), 0);
+}
+
static QWindow *findNewTopLevelWindow(const QWindowList &oldTopLevelWindows)
{
const auto tlws = QGuiApplication::topLevelWindows();