diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2019-11-15 10:42:32 +0100 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2019-11-29 14:34:10 +0100 |
commit | 9d8ce033587c22658af9c9b06ac491ea840b71c1 (patch) | |
tree | cdff745826dca4bee3e2db12b85c6f8f7642ab9f /tests/auto/quick | |
parent | 6f0173c166d6f7a2237a031808a33b0d787acd1c (diff) |
Stop using loadVisuallyCommitted in tst_qquickwebengineviewgraphics
The loadVisuallyCommitted signal is not emitted until the grabWindow call, but
the grabWindow call is not made until the loadVisuallyCommitted signal is
emitted. This could maybe work in Prolog but in C++ it's not a good idea.
Additionally, support not only images in RGB32 format, but also ARGB32, since
that's what we get with software compositing.
Fixes: QTBUG-58449
Task-number: QTBUG-79626
Change-Id: Iddae69764855febbc3a985ef7009227bc94634a5
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r-- | tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp | 103 | ||||
-rw-r--r-- | tests/auto/quick/shared/util.h | 15 |
2 files changed, 34 insertions, 84 deletions
diff --git a/tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp b/tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp index b587f3b27..c9abe9cfe 100644 --- a/tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp +++ b/tests/auto/quick/qquickwebengineviewgraphics/tst_qquickwebengineviewgraphics.cpp @@ -34,9 +34,10 @@ #include <QQuickItem> #include <QPainter> #include <qtwebengineglobal.h> -#include <private/qquickwebenginetestsupport_p.h> #include <private/qquickwebengineview_p.h> +#include <map> + class TestView : public QQuickView { Q_OBJECT public: @@ -59,91 +60,57 @@ Q_SIGNALS: class tst_QQuickWebEngineViewGraphics : public QObject { Q_OBJECT -public: - tst_QQuickWebEngineViewGraphics(); - virtual ~tst_QQuickWebEngineViewGraphics(); - -public Q_SLOTS: - void initTestCase(); - void init(); - void cleanup(); - private Q_SLOTS: void simpleGraphics(); - void renderMultipleTimes(); - void renderAfterNodeCleanup(); void showHideShow(); void simpleAcceleratedLayer(); void reparentToOtherWindow(); private: void setHtml(const QString &html); - QScopedPointer<TestView> m_view; - QScopedPointer<QQuickWebEngineTestSupport> m_testSupport; + QScopedPointer<TestView> m_view{new TestView}; }; static const QString greenSquare("<div style=\"background-color: #00ff00; position:absolute; left:50px; top: 50px; width: 50px; height: 50px;\"></div>"); static const QString acLayerGreenSquare("<div style=\"background-color: #00ff00; position:absolute; left:50px; top: 50px; width: 50px; height: 50px; transform: translateZ(0); -webkit-transform: translateZ(0);\"></div>"); -static QImage get150x150GreenReferenceImage() +static QImage makeGreenSquare(QImage::Format format) { - static QImage reference; - if (reference.isNull()) { - reference = QImage(150, 150, QImage::Format_RGB32); - reference.fill(Qt::white); - QPainter painter(&reference); - painter.fillRect(50, 50, 50, 50, QColor("#00ff00")); - } - return reference; + QImage image(150, 150, format); + image.fill(Qt::white); + QPainter painter(&image); + painter.fillRect(50, 50, 50, 50, QColor("#00ff00")); + return image; } -tst_QQuickWebEngineViewGraphics::tst_QQuickWebEngineViewGraphics() +static QImage getGreenSquare(QImage::Format format) { + static std::map<QImage::Format, QImage> images; + auto it = images.find(format); + if (it == images.end()) + it = images.emplace(format, makeGreenSquare(format)).first; + return it->second; } -tst_QQuickWebEngineViewGraphics::~tst_QQuickWebEngineViewGraphics() -{ -} - -// This will be called before the first test function is executed. -// It is only called once. -void tst_QQuickWebEngineViewGraphics::initTestCase() -{ - QtWebEngine::initialize(); - m_testSupport.reset(new QQuickWebEngineTestSupport); -} - -void tst_QQuickWebEngineViewGraphics::init() -{ - m_view.reset(new TestView); -} - -void tst_QQuickWebEngineViewGraphics::cleanup() +static void verifyGreenSquare(QQuickWindow *window) { + QImage actual, expected; + bool ok = QTest::qWaitFor([&](){ + actual = window->grabWindow(); + expected = getGreenSquare(actual.format()); + return actual == expected; + }, 10000); + if (!ok) { + // actual.save("actual.png"); + // expected.save("expected.png"); + QFAIL("expected green square to be rendered"); + } } void tst_QQuickWebEngineViewGraphics::simpleGraphics() { setHtml(greenSquare); - QCOMPARE(m_view->grabWindow(), get150x150GreenReferenceImage()); -} - -void tst_QQuickWebEngineViewGraphics::renderMultipleTimes() -{ - // This test is for loadVisuallyCommitted signal. - // The setHtml() should not fail after multiple page load. - setHtml(greenSquare); - setHtml(greenSquare); -} - -void tst_QQuickWebEngineViewGraphics::renderAfterNodeCleanup() -{ - setHtml(greenSquare); - - // Do it twice in a row, if the window isn't visible, the scene graph is going to be trashed by QQuickWindow::grabWindow after the first render. - QVERIFY(!m_view->isVisible()); - QCOMPARE(m_view->grabWindow(), get150x150GreenReferenceImage()); - QCOMPARE(m_view->grabWindow(), get150x150GreenReferenceImage()); + verifyGreenSquare(m_view.data()); } void tst_QQuickWebEngineViewGraphics::showHideShow() @@ -152,19 +119,19 @@ void tst_QQuickWebEngineViewGraphics::showHideShow() QSignalSpy exposeSpy(m_view.data(), SIGNAL(exposeChanged())); m_view->show(); QVERIFY(exposeSpy.wait()); - QCOMPARE(m_view->grabWindow(), get150x150GreenReferenceImage()); + verifyGreenSquare(m_view.data()); m_view->hide(); QVERIFY(exposeSpy.wait()); m_view->show(); QVERIFY(exposeSpy.wait()); - QCOMPARE(m_view->grabWindow(), get150x150GreenReferenceImage()); + verifyGreenSquare(m_view.data()); } void tst_QQuickWebEngineViewGraphics::simpleAcceleratedLayer() { setHtml(acLayerGreenSquare); - QCOMPARE(m_view->grabWindow(), get150x150GreenReferenceImage()); + verifyGreenSquare(m_view.data()); } void tst_QQuickWebEngineViewGraphics::reparentToOtherWindow() @@ -175,7 +142,7 @@ void tst_QQuickWebEngineViewGraphics::reparentToOtherWindow() window.create(); m_view->rootObject()->setParentItem(window.contentItem()); - QCOMPARE(window.grabWindow(), get150x150GreenReferenceImage()); + verifyGreenSquare(&window); } void tst_QQuickWebEngineViewGraphics::setHtml(const QString &html) @@ -187,10 +154,8 @@ void tst_QQuickWebEngineViewGraphics::setHtml(const QString &html) QQuickWebEngineView *webEngineView = static_cast<QQuickWebEngineView *>(m_view->rootObject()); webEngineView->setProperty("url", QUrl(QStringLiteral("data:text/html,%1").arg(htmlData))); - webEngineView->setTestSupport(m_testSupport.data()); - QVERIFY(waitForViewportReady(webEngineView)); - QCOMPARE(m_view->rootObject()->property("loading"), QVariant(false)); + QTRY_COMPARE_WITH_TIMEOUT(m_view->rootObject()->property("loading"), QVariant(false), 30000); } -QTEST_MAIN(tst_QQuickWebEngineViewGraphics) +W_QTEST_MAIN(tst_QQuickWebEngineViewGraphics) #include "tst_qquickwebengineviewgraphics.moc" diff --git a/tests/auto/quick/shared/util.h b/tests/auto/quick/shared/util.h index bc5ae445b..fbce8bfa7 100644 --- a/tests/auto/quick/shared/util.h +++ b/tests/auto/quick/shared/util.h @@ -107,21 +107,6 @@ inline bool waitForLoadFailed(QQuickWebEngineView *webEngineView, int timeout = return spy.wait(timeout); } -inline bool waitForViewportReady(QQuickWebEngineView *webEngineView, int timeout = 10000) -{ -#if QT_CONFIG(webengine_testsupport) - QSignalSpy spy(reinterpret_cast<QObject *>(webEngineView->testSupport()), SIGNAL(loadVisuallyCommitted())); - return spy.wait(timeout); -#else - Q_UNUSED(webEngineView) - Q_UNUSED(timeout) - qFatal("Test Support API is disabled. The result is not reliable.\ - Use the following command to build Test Support module and rebuild WebEngineView API:\ - qmake -r -- --feature-testsupport=yes && make"); - return false; -#endif -} - inline QVariant evaluateJavaScriptSync(QQuickWebEngineView *view, const QString &script) { QQmlEngine *engine = qmlEngine(view); |