summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-02-10 18:04:33 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-13 14:28:04 +0100
commit324706a5fe9fbfd5aeaef54387dd4b08159a92a0 (patch)
tree5a99ceb64b794890fd339d0e67ea6fee5ed79abf /tests/auto
parent9cf0007b6ff49305550754babaeb67eb85c8d5ef (diff)
Implement QWebEnginePage::findText
A few changes to the API: - Return the success result asynchronously. - FindWrapsAroundDocument and HighlightAllOccurrences are enabled by defaults and cannot be disabled. - Found text isn't updating the selection on the page like QtWebKit did, but triggers a separate state not available. A find count and current index could be exposed, but isn't in this case to keep the API delta lower. This also adds the possibility to pass bool results through the CallbackDirectory and add a new tst_QWebEnginePage::findTextResult test since the old test relied on the selection to be updated when the searched text is found. Change-Id: I8189b5aea8d832df183c6c1ae03e3f08198a9c45 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp38
-rw-r--r--tests/auto/widgets/util.h7
2 files changed, 40 insertions, 5 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index d6f154e5e..bb07e2e00 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -173,6 +173,7 @@ private Q_SLOTS:
void showModalDialog();
void testStopScheduledPageRefresh();
void findText();
+ void findTextResult();
void supportedContentType();
// [Qt] tst_QWebEnginePage::infiniteLoopJS() timeouts with DFG JIT
// https://bugs.webkit.org/show_bug.cgi?id=79040
@@ -3187,26 +3188,53 @@ void tst_QWebEnginePage::testStopScheduledPageRefresh()
void tst_QWebEnginePage::findText()
{
-#if !defined(QWEBENGINEPAGE_FINDTEXT)
- QSKIP("QWEBENGINEPAGE_FINDTEXT");
-#else
m_view->setHtml(QString("<html><head></head><body><div>foo bar</div></body></html>"));
+#if defined(QWEBENGINEPAGE_TRIGGERACTION_SELECTALL)
m_page->triggerAction(QWebEnginePage::SelectAll);
QVERIFY(!m_page->selectedText().isEmpty());
QVERIFY(!m_page->selectedHtml().isEmpty());
+#endif
m_page->findText("");
QVERIFY(m_page->selectedText().isEmpty());
+#if defined(QWEBENGINEPAGE_SELECTEDHTML)
QVERIFY(m_page->selectedHtml().isEmpty());
+#endif
QStringList words = (QStringList() << "foo" << "bar");
foreach (QString subString, words) {
- m_page->findText(subString, QWebEnginePage::FindWrapsAroundDocument);
+ m_page->findText(subString);
+ QEXPECT_FAIL("", "Unsupported: findText only highlights and doesn't update the selection.", Continue);
QCOMPARE(m_page->selectedText(), subString);
+#if defined(QWEBENGINEPAGE_SELECTEDHTML)
QVERIFY(m_page->selectedHtml().contains(subString));
+#endif
m_page->findText("");
QVERIFY(m_page->selectedText().isEmpty());
+#if defined(QWEBENGINEPAGE_SELECTEDHTML)
QVERIFY(m_page->selectedHtml().isEmpty());
- }
#endif
+ }
+}
+
+void tst_QWebEnginePage::findTextResult()
+{
+ // findText will abort in blink if the view has an empty size.
+ m_view->resize(800, 600);
+ m_view->show();
+
+ QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
+ m_view->setHtml(QString("<html><head></head><body><div>foo bar</div></body></html>"));
+ QTRY_COMPARE(loadSpy.count(), 1);
+
+ QCOMPARE(findTextSync(m_page, ""), false);
+
+ QStringList words = (QStringList() << "foo" << "bar");
+ foreach (QString subString, words) {
+ QCOMPARE(findTextSync(m_page, subString), true);
+ QCOMPARE(findTextSync(m_page, ""), false);
+ }
+
+ QCOMPARE(findTextSync(m_page, "blahhh"), false);
+ QCOMPARE(findTextSync(m_page, ""), false);
}
static QString getMimeTypeForExtension(const QString &ext)
diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h
index 0b146aedc..035578358 100644
--- a/tests/auto/widgets/util.h
+++ b/tests/auto/widgets/util.h
@@ -142,6 +142,13 @@ static inline QString toHtmlSync(QWebEnginePage *page)
return spy.waitForResult();
}
+static inline bool findTextSync(QWebEnginePage *page, const QString &subString)
+{
+ CallbackSpy<bool> spy;
+ page->findText(subString, 0, spy.ref());
+ return spy.waitForResult();
+}
+
static inline QVariant evaluateJavaScriptSync(QWebEnginePage *page, const QString &script)
{
CallbackSpy<QVariant> spy;