From 6f07e22acf15651f91d326529519119af7e807a9 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Wed, 15 Jan 2014 19:01:18 +0100 Subject: Unskip and ajust tests using setHtml, setContent, toHtml and toPlainText Replace direct calls of toHtml and toPlainText to use a blocking helper function that spins a QEventLoop to wait for the async result. This should work fine for tests where the event loop is less polluted by other events that could cause code reentrancy through stacked stacks. Change-Id: Ic46a06a9abad782a39a620ceecdc51c3bbb6b5a1 Reviewed-by: Pierre Rossi --- .../qwebengineframe/tst_qwebengineframe.cpp | 57 ++++++++-------------- .../qwebenginehistory/tst_qwebenginehistory.cpp | 16 ++---- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 8 +-- .../widgets/qwebengineview/tst_qwebengineview.cpp | 6 +-- tests/auto/widgets/util.h | 52 ++++++++++++++++++++ 5 files changed, 79 insertions(+), 60 deletions(-) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp index 3cb982dd9..dd78a4076 100644 --- a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp +++ b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp @@ -127,9 +127,6 @@ void tst_QWebEngineFrame::cleanup() void tst_QWebEngineFrame::symmetricUrl() { -#if !defined(QWEBENGINEPAGE_TOPLAINTEXT) - QSKIP("QWEBENGINEPAGE_TOPLAINTEXT"); -#else QVERIFY(m_view->url().isEmpty()); QCOMPARE(m_view->history()->count(), 0); @@ -141,12 +138,12 @@ void tst_QWebEngineFrame::symmetricUrl() QCOMPARE(m_view->history()->count(), 0); // loading is _not_ immediate, so the text isn't set just yet. - QVERIFY(m_view->page()->toPlainText().isEmpty()); + QVERIFY(toPlainText(m_view->page()).isEmpty()); ::waitForSignal(m_view, SIGNAL(loadFinished(bool))); QCOMPARE(m_view->history()->count(), 1); - QCOMPARE(m_view->page()->toPlainText(), QString("Test")); + QCOMPARE(toPlainText(m_view->page()), QString("Test")); QUrl dataUrl2("data:text/html,

Test2"); QUrl dataUrl3("data:text/html,

Test3"); @@ -160,8 +157,7 @@ void tst_QWebEngineFrame::symmetricUrl() QCOMPARE(m_view->history()->count(), 2); - QCOMPARE(m_view->page()->toPlainText(), QString("Test3")); -#endif + QCOMPARE(toPlainText(m_view->page()), QString("Test3")); } void tst_QWebEngineFrame::progressSignal() @@ -374,8 +370,8 @@ void tst_QWebEngineFrame::javaScriptWindowObjectCleared_data() void tst_QWebEngineFrame::javaScriptWindowObjectCleared() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); +#if !defined(QWEBENGINEPAGE_JAVASCRIPTWINDOWOBJECTCLEARED) + QSKIP("QWEBENGINEPAGE_JAVASCRIPTWINDOWOBJECTCLEARED"); #else QWebEnginePage page; QSignalSpy spy(&page, SIGNAL(javaScriptWindowObjectCleared())); @@ -412,15 +408,11 @@ void tst_QWebEngineFrame::earlyToHtml() void tst_QWebEngineFrame::setHtml() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); -#else QString html("

hello world

"); QSignalSpy spy(m_view->page(), SIGNAL(loadFinished(bool))); m_view->page()->setHtml(html); - QCOMPARE(m_view->page()->toHtml(), html); - QCOMPARE(spy.count(), 1); -#endif + QVERIFY(spy.wait()); + QCOMPARE(toHtml(m_view->page()), html); } void tst_QWebEngineFrame::setHtmlWithImageResource() @@ -541,17 +533,13 @@ protected: void tst_QWebEngineFrame::setHtmlWithJSAlert() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); -#else QString html("

hello world

"); MyPage page; m_view->setPage(&page); page.setHtml(html); QCOMPARE(page.alerts, 1); QEXPECT_FAIL("", "https://bugs.webengine.org/show_bug.cgi?id=118663", Continue); - QCOMPARE(m_view->page()->toHtml(), html); -#endif + QCOMPARE(toHtml(m_view->page()), html); } class TestNetworkManager : public QNetworkAccessManager @@ -592,8 +580,8 @@ void tst_QWebEngineFrame::ipv6HostEncoding() void tst_QWebEngineFrame::metaData() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); +#if !defined(QWEBENGINEPAGE_METADATA) + QSKIP("QWEBENGINEPAGE_METADATA"); #else m_view->setHtml("" " " @@ -747,8 +735,8 @@ void tst_QWebEngineFrame::baseUrl_data() void tst_QWebEngineFrame::baseUrl() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); +#if !defined(QWEBENGINEPAGE_BASEURL) + QSKIP("QWEBENGINEPAGE_BASEURL"); #else QFETCH(QString, html); QFETCH(QUrl, loadUrl); @@ -944,8 +932,8 @@ int DummyPaintDevice::metric(PaintDeviceMetric metric) const void tst_QWebEngineFrame::renderHints() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); +#if !defined(QWEBENGINEPAGE_RENDER) + QSKIP("QWEBENGINEPAGE_RENDER"); #else QString html("

Hello, world!

"); @@ -1150,15 +1138,13 @@ void tst_QWebEngineFrame::setContent_data() void tst_QWebEngineFrame::setContent() { -#if !defined(QWEBENGINEPAGE_TOPLAINTEXT) - QSKIP("QWEBENGINEPAGE_TOPLAINTEXT"); -#else QFETCH(QString, mimeType); QFETCH(QByteArray, testContents); QFETCH(QString, expected); + QSignalSpy loadSpy(m_page, SIGNAL(loadFinished(bool))); m_view->setContent(testContents, mimeType); - QCOMPARE(expected , m_view->page()->toPlainText()); -#endif + QVERIFY(loadSpy.wait()); + QCOMPARE(toPlainText(m_view->page()), expected); } class CacheNetworkAccessManager : public QNetworkAccessManager { @@ -1219,13 +1205,9 @@ void tst_QWebEngineFrame::setCacheLoadControlAttribute() void tst_QWebEngineFrame::setUrlWithPendingLoads() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); -#else QWebEnginePage page; page.setHtml(""); page.setUrl(QUrl("about:blank")); -#endif } void tst_QWebEngineFrame::setUrlWithFragment_data() @@ -1242,8 +1224,8 @@ void tst_QWebEngineFrame::setUrlWithFragment_data() // Based on bug report https://bugs.webengine.org/show_bug.cgi?id=32723 void tst_QWebEngineFrame::setUrlWithFragment() { -#if !defined(QWEBENGINEPAGE_TOPLAINTEXT) - QSKIP("QWEBENGINEPAGE_TOPLAINTEXT"); +#if !defined(QWEBENGINEPAGE_REQUESTEDURL) + QSKIP("QWEBENGINEPAGE_REQUESTEDURL"); #else QFETCH(QUrl, previousUrl); @@ -1676,6 +1658,7 @@ void tst_QWebEngineFrame::loadInSignalHandlers_data() void tst_QWebEngineFrame::loadInSignalHandlers() { + QSKIP("This crashes in content::WebContentsImpl::NavigateToEntry because of reentrancy. Should we require QueuedConnections or do it ourselves to support this?"); QFETCH(URLSetter::Type, type); QFETCH(URLSetter::Signal, signal); QFETCH(QUrl, url); diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp index 29f2ed694..e84702df3 100644 --- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp +++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp @@ -124,18 +124,14 @@ void tst_QWebEngineHistory::count() */ void tst_QWebEngineHistory::back() { -#if !defined(QWEBENGINEPAGE_TOPLAINTEXT) - QSKIP("QWEBENGINEPAGE_TOPLAINTEXT"); -#else for (int i = histsize;i > 1;i--) { - QCOMPARE(page->toPlainText(), QString("page") + QString::number(i)); + QCOMPARE(toPlainText(page), QString("page") + QString::number(i)); hist->back(); loadFinishedBarrier->ensureSignalEmitted(); } //try one more time (too many). crash test hist->back(); - QCOMPARE(page->toPlainText(), QString("page1")); -#endif + QCOMPARE(toPlainText(page), QString("page1")); } /** @@ -143,9 +139,6 @@ void tst_QWebEngineHistory::back() */ void tst_QWebEngineHistory::forward() { -#if !defined(QWEBENGINEPAGE_TOPLAINTEXT) - QSKIP("QWEBENGINEPAGE_TOPLAINTEXT"); -#else //rewind history :-) while (hist->canGoBack()) { hist->back(); @@ -153,14 +146,13 @@ void tst_QWebEngineHistory::forward() } for (int i = 1;i < histsize;i++) { - QCOMPARE(page->toPlainText(), QString("page") + QString::number(i)); + QCOMPARE(toPlainText(page), QString("page") + QString::number(i)); hist->forward(); loadFinishedBarrier->ensureSignalEmitted(); } //try one more time (too many). crash test hist->forward(); - QCOMPARE(page->toPlainText(), QString("page") + QString::number(histsize)); -#endif + QCOMPARE(toPlainText(page), QString("page") + QString::number(histsize)); } /** diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index a670903fe..2a85b010c 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -2762,9 +2762,7 @@ void tst_QWebEnginePage::errorPageExtension() page.setUrl(QUrl("http://non.existent/url")); QTRY_COMPARE(spyLoadFinished.count(), 2); -#if defined(QWEBENGINEPAGE_TOPLAINTEXT) - QCOMPARE(page.toPlainText(), QString("error")); -#endif + QCOMPARE(toPlainText(&page), QString("error")); QCOMPARE(page.history()->count(), 2); QCOMPARE(page.history()->currentItem().url(), QUrl("http://non.existent/url")); QCOMPARE(page.history()->canGoBack(), true); @@ -3322,9 +3320,6 @@ void tst_QWebEnginePage::thirdPartyCookiePolicy() #ifdef Q_OS_MAC void tst_QWebEnginePage::macCopyUnicodeToClipboard() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); -#else QString unicodeText = QString::fromUtf8("αβγδεζηθικλμπ"); m_page->setHtml(QString("%1").arg(unicodeText)); m_page->triggerAction(QWebEnginePage::SelectAll); @@ -3334,7 +3329,6 @@ void tst_QWebEnginePage::macCopyUnicodeToClipboard() QVERIFY(clipboardData.contains(QLatin1String(""))); QVERIFY(clipboardData.contains(unicodeText)); -#endif } #endif diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 352040bab..4c238a074 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -138,9 +138,6 @@ void tst_QWebEngineView::reusePage_data() void tst_QWebEngineView::reusePage() { -#if !defined(QWEBENGINEPAGE_SETHTML) - QSKIP("QWEBENGINEPAGE_SETHTML"); -#else if (!QDir(TESTS_SOURCE_DIR).exists()) W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll); @@ -150,7 +147,9 @@ void tst_QWebEngineView::reusePage() QWebEngineView* view1 = new QWebEngineView; QPointer page = new QWebEnginePage; view1->setPage(page.data()); +#if defined(QWEBENGINESETTINGS) page.data()->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true); +#endif page->setHtml(html, QUrl::fromLocalFile(TESTS_SOURCE_DIR)); if (html.contains("")) { // some reasonable time for the PluginStream to feed test.swf to flash and start painting @@ -171,7 +170,6 @@ void tst_QWebEngineView::reusePage() delete page.data(); // must not crash QDir::setCurrent(QApplication::applicationDirPath()); -#endif } // Class used in crashTests diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h index 4925aa4c7..e5e991f89 100644 --- a/tests/auto/widgets/util.h +++ b/tests/auto/widgets/util.h @@ -25,6 +25,15 @@ #include #include #include +#include + +#if __cplusplus >= 201103L +#include +using std::ref; +#else +#include +using std::tr1::ref; +#endif #if !defined(TESTS_SOURCE_DIR) #define TESTS_SOURCE_DIR "" @@ -78,4 +87,47 @@ public: } }; +template +class CallbackSpy { +public: + // Tells tr1::ref the result of void operator()(const T &result) when decltype isn't available. + typedef void result_type; + + CallbackSpy() { + timeoutTimer.setSingleShot(true); + QObject::connect(&timeoutTimer, SIGNAL(timeout()), &eventLoop, SLOT(quit())); + } + + T waitForResult() { + timeoutTimer.start(10000); + eventLoop.exec(); + return result; + } + + void operator()(const T &result) { + this->result = result; + eventLoop.quit(); + } + +private: + Q_DISABLE_COPY(CallbackSpy) + QTimer timeoutTimer; + QEventLoop eventLoop; + T result; +}; + +static inline QString toPlainText(QWebEnginePage *page) +{ + CallbackSpy spy; + page->toPlainText(ref(spy)); + return spy.waitForResult(); +} + +static inline QString toHtml(QWebEnginePage *page) +{ + CallbackSpy spy; + page->toHtml(ref(spy)); + return spy.waitForResult(); +} + #define W_QSKIP(a, b) QSKIP(a) -- cgit v1.2.3