From 5b219fc20dbfe6090af45c1dbdb7ad50bc743ca1 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 27 Jun 2016 16:52:55 +0200 Subject: Clear internal selected text when searching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously if a selection was made on a web page, and afterwards a find operation is executed, the selection in the web page would be cleared, but the call to selectedText() would still return the old selection. Make sure selectedText() is always cleared, when starting a find operation, as well as when stopping one. Change-Id: If78f0fa1dd836a52184015e749ef5a84b9f784cd Task-number: QTBUG-54071 Reviewed-by: Michael BrĂ¼ning --- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 31 +++++++++------------- 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 4cff50d3b..ab6db5e2c 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -2970,31 +2970,26 @@ void tst_QWebEnginePage::findText() QSignalSpy loadSpy(m_page, SIGNAL(loadFinished(bool))); m_page->setHtml(QString("
foo bar
")); QTRY_COMPARE(loadSpy.count(), 1); + + // Select whole page contents. m_page->triggerAction(QWebEnginePage::SelectAll); QTRY_COMPARE(m_page->hasSelection(), true); -#if defined(QWEBENGINEPAGE_SELECTEDHTML) - QVERIFY(!m_page->selectedHtml().isEmpty()); -#endif + + // Invoke a stopFinding() operation, which should clear the currently selected text. m_page->findText(""); - QEXPECT_FAIL("", "Unsupported: findText only highlights and doesn't update the selection.", Continue); - QVERIFY(m_page->selectedText().isEmpty()); -#if defined(QWEBENGINEPAGE_SELECTEDHTML) - QVERIFY(m_page->selectedHtml().isEmpty()); -#endif + QTRY_VERIFY(m_page->selectedText().isEmpty()); + QStringList words = (QStringList() << "foo" << "bar"); foreach (QString subString, words) { + // Invoke a find operation, which should clear the currently selected text, should + // highlight all the found ocurrences, but should not update the selected text to the + // searched for string. 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 + QTRY_VERIFY(m_page->selectedText().isEmpty()); + + // Search highlights should be cleared, selected text should still be empty. m_page->findText(""); - QEXPECT_FAIL("", "Unsupported: findText only highlights and doesn't update the selection.", Continue); - QVERIFY(m_page->selectedText().isEmpty()); -#if defined(QWEBENGINEPAGE_SELECTEDHTML) - QVERIFY(m_page->selectedHtml().isEmpty()); -#endif + QTRY_VERIFY(m_page->selectedText().isEmpty()); } } -- cgit v1.2.3