From d75f57fc4290e769d3f159e7fc464a6c28b867b3 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Date: Mon, 31 Aug 2015 12:38:43 +0200 Subject: [PATCH] Enable parts of tst_QWebEnginePage::textSelection We can support the basics of the test though we are missing the actions to move selections. Change-Id: Iba1eae0d17857761145cd99c77a58a7d2f2b2c4c Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com> --- .../qwebenginepage/tst_qwebenginepage.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index b4b4eddd6..c77799387 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -1177,6 +1177,10 @@ public: int isSelectionCollapsed() { return evaluateJavaScriptSync(this, "window.getSelection().getRangeAt(0).collapsed").toBool(); } + bool hasSelection() + { + return !selectedText().isEmpty(); + } }; void tst_QWebEnginePage::cursorMovements() @@ -1381,17 +1385,19 @@ void tst_QWebEnginePage::cursorMovements() void tst_QWebEnginePage::textSelection() { -#if !defined(QWEBENGINEPAGE_EVALUATEJAVASCRIPT) - QSKIP("QWEBENGINEPAGE_EVALUATEJAVASCRIPT"); -#else - CursorTrackedPage* page = new CursorTrackedPage; + QWebEngineView *view = new QWebEngineView; + CursorTrackedPage *page = new CursorTrackedPage; QString content("<html><body><p id=one>The quick brown fox</p>" \ "<p id=two>jumps over the lazy dog</p>" \ "<p>May the source<br/>be with you!</p></body></html>"); + page->setView(view); + QSignalSpy loadSpy(view, SIGNAL(loadFinished(bool))); page->setHtml(content); + QTRY_COMPARE(loadSpy.count(), 1); // these actions must exist QVERIFY(page->action(QWebEnginePage::SelectAll) != 0); +#if defined(QWEBENGINEPAGE_SELECTACTIONS) QVERIFY(page->action(QWebEnginePage::SelectNextChar) != 0); QVERIFY(page->action(QWebEnginePage::SelectPreviousChar) != 0); QVERIFY(page->action(QWebEnginePage::SelectNextWord) != 0); @@ -1419,6 +1425,7 @@ void tst_QWebEnginePage::textSelection() QCOMPARE(page->action(QWebEnginePage::SelectEndOfBlock)->isEnabled(), false); QCOMPARE(page->action(QWebEnginePage::SelectStartOfDocument)->isEnabled(), false); QCOMPARE(page->action(QWebEnginePage::SelectEndOfDocument)->isEnabled(), false); +#endif // ..but SelectAll is awalys enabled QCOMPARE(page->action(QWebEnginePage::SelectAll)->isEnabled(), true); @@ -1433,13 +1440,15 @@ void tst_QWebEnginePage::textSelection() "getSelection().addRange(range);"; evaluateJavaScriptSync(page, selectScript); QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox")); +#if defined(QWEBENGINEPAGE_SELECTEDHTML) QRegExp regExp(" style=\".*\""); regExp.setMinimal(true); QCOMPARE(page->selectedHtml().trimmed().replace(regExp, ""), QString::fromLatin1("<p id=\"one\">The quick brown fox</p>")); - +#endif // Make sure hasSelection returns true, since there is selected text now... QCOMPARE(page->hasSelection(), true); +#if defined(QWEBENGINEPAGE_SELECTACTIONS) // here the actions are enabled after a selection has been created QCOMPARE(page->action(QWebEnginePage::SelectNextChar)->isEnabled(), true); QCOMPARE(page->action(QWebEnginePage::SelectPreviousChar)->isEnabled(), true); @@ -1475,9 +1484,10 @@ void tst_QWebEnginePage::textSelection() QCOMPARE(page->action(QWebEnginePage::SelectEndOfBlock)->isEnabled(), true); QCOMPARE(page->action(QWebEnginePage::SelectStartOfDocument)->isEnabled(), true); QCOMPARE(page->action(QWebEnginePage::SelectEndOfDocument)->isEnabled(), true); +#endif delete page; -#endif + delete view; } void tst_QWebEnginePage::textEditing() -- GitLab