summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-01-21 14:58:03 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-22 23:18:27 +0000
commit3de78333c6616863996db4631222e6efae4b2db6 (patch)
treea3b10b7a3ea443ff405f688e53e31d33129c0489 /tests
parentbf614638ed278a41573eb0987dd65f91a004e04a (diff)
Stabilize tst_QQuickWebEngineView
Remove the 200 ms wait and instead try to grab the window contents repeatedly until a certain condition is met. Change-Id: I96dd720ef41ced9bdb48772939d25dd957081c33 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
index cb566c254..a1900a77d 100644
--- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
+++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
@@ -21,10 +21,13 @@
#include "util.h"
#include <QScopedPointer>
+#include <QtCore/qelapsedtimer.h>
#include <QtQml/QQmlEngine>
#include <QtTest/QtTest>
#include <private/qquickwebengineview_p.h>
+#include <functional>
+
class tst_QQuickWebEngineView : public QObject {
Q_OBJECT
public:
@@ -313,6 +316,21 @@ void tst_QQuickWebEngineView::multipleWebEngineViews()
QTest::qWait(200);
}
+QImage tryToGrabWindowUntil(QQuickWindow *window, std::function<bool(const QImage &)> checkImage,
+ int timeout = 5000)
+{
+ QImage grabbed;
+ QElapsedTimer t;
+ t.start();
+ do {
+ QTest::qWait(200);
+ grabbed = window->grabWindow();
+ if (checkImage(grabbed))
+ break;
+ } while (!t.hasExpired(timeout));
+ return grabbed;
+}
+
void tst_QQuickWebEngineView::basicRenderingSanity()
{
showWebEngineView();
@@ -322,9 +340,12 @@ void tst_QQuickWebEngineView::basicRenderingSanity()
// This should not crash.
webEngineView()->setVisible(true);
- QTest::qWait(200);
- QImage grabbedWindow = m_window->grabWindow();
+
QRgb testColor = qRgba(0, 0xff, 0, 0xff);
+ const QImage grabbedWindow = tryToGrabWindowUntil(m_window.data(),
+ [testColor] (const QImage &image) {
+ return image.pixel(10, 10) == testColor;
+ });
QVERIFY(grabbedWindow.pixel(10, 10) == testColor);
QVERIFY(grabbedWindow.pixel(100, 10) == testColor);
QVERIFY(grabbedWindow.pixel(10, 100) == testColor);
@@ -370,12 +391,11 @@ void tst_QQuickWebEngineView::transparentWebEngineViews()
webEngineView2->setSize(QSizeF(300, 400));
webEngineView2->setUrl(urlFromTestPath("/html/basic_page.html"));
QVERIFY(waitForLoadSucceeded(webEngineView2.data()));
- webEngineView2->setVisible(true);
-
- QTest::qWait(200);
// Result image: black text on red background.
- QImage grabbedWindow = m_window->grabWindow();
+ const QImage grabbedWindow = tryToGrabWindowUntil(m_window.data(), [] (const QImage &image) {
+ return image.pixelColor(0, 0) == QColor(Qt::red);
+ });
QSet<int> redComponents;
for (int i = 0, width = grabbedWindow.width(); i < width; i++) {