From 616781369e8787a02e5629b73a0c8cfffe3c5239 Mon Sep 17 00:00:00 2001 From: Kirill Burtsev Date: Thu, 27 Feb 2020 17:00:13 +0100 Subject: Stabilize tst_QWebEnginePage::localStorageVisibility() Toggling page's setting is actually first batched and then executed asynchronously by timer. So javascript code might not necessarily see this update immediately after change on UI thread. Change-Id: I1a1f373b5fd0b96c5b937a2dca1ce0ed99364c33 Reviewed-by: Allan Sandfeld Jensen --- tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 94b3f16c1..d0453e1e6 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -823,11 +823,13 @@ void tst_QWebEnginePage::localStorageVisibility() QVERIFY(evaluateJavaScriptSync(&webPage1, QString("(window.localStorage != undefined)")).toBool()); QVERIFY(!evaluateJavaScriptSync(&webPage2, QString("(window.localStorage != undefined)")).toBool()); - // Switching the feature off does not actively remove the object from webPage1. + // Toggle local setting for every page and... webPage1.settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, false); webPage2.settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true); + // ...first check second page (for storage to appear) as applying settings is batched and done asynchronously + QTRY_VERIFY(evaluateJavaScriptSync(&webPage2, QString("(window.localStorage != undefined)")).toBool()); + // Switching the feature off does not actively remove the object from webPage1. QVERIFY(evaluateJavaScriptSync(&webPage1, QString("(window.localStorage != undefined)")).toBool()); - QVERIFY(evaluateJavaScriptSync(&webPage2, QString("(window.localStorage != undefined)")).toBool()); // The object disappears only after reloading. webPage1.triggerAction(QWebEnginePage::Reload); -- cgit v1.2.3 From 19444168395424fef4daff76ce64b9813aef0610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Wed, 26 Feb 2020 14:27:57 +0100 Subject: Stabilize tst_QQuickWebEngineView::transparentWebEngineViews Change-Id: I847a1750ce5c9533db43fb60f91b9739c544791a Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/qquickwebengineview/BLACKLIST | 2 -- .../tst_qquickwebengineview.cpp | 31 ++++++++++------------ 2 files changed, 14 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/auto/quick/qquickwebengineview/BLACKLIST b/tests/auto/quick/qquickwebengineview/BLACKLIST index d4d5c9844..e69de29bb 100644 --- a/tests/auto/quick/qquickwebengineview/BLACKLIST +++ b/tests/auto/quick/qquickwebengineview/BLACKLIST @@ -1,2 +0,0 @@ -[transparentWebEngineViews] -windows diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp index 6f9cb9c69..04be25abe 100644 --- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp +++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp @@ -421,32 +421,29 @@ void tst_QQuickWebEngineView::transparentWebEngineViews() webEngineView1->setSize(QSizeF(300, 400)); webEngineView1->loadHtml(""); - QVERIFY(waitForLoadSucceeded(webEngineView1.data())); - webEngineView1->setVisible(true); + QVERIFY(waitForLoadSucceeded(webEngineView1.data(), 30000)); webEngineView2->setSize(QSizeF(300, 400)); webEngineView2->setUrl(urlFromTestPath("/html/basic_page.html")); QVERIFY(waitForLoadSucceeded(webEngineView2.data())); // Result image: black text on red background. - const QImage grabbedWindow = tryToGrabWindowUntil(m_window.data(), [] (const QImage &image) { - return image.pixelColor(0, 0) == QColor(Qt::red); + QSet colors; + tryToGrabWindowUntil(m_window.data(), [&colors] (const QImage &image) { + colors.clear(); + for (int i = 0; i < image.width(); i++) + for (int j = 0; j < image.height(); j++) + colors.insert(image.pixel(i, j)); + return colors.count() > 1; }); - QSet redComponents; - for (int i = 0, width = grabbedWindow.width(); i < width; i++) { - for (int j = 0, height = grabbedWindow.height(); j < height; j++) { - QColor color(grabbedWindow.pixel(i, j)); - redComponents.insert(color.red()); - // There are no green or blue components between red and black. - QVERIFY(color.green() == 0); - QVERIFY(color.blue() == 0); - } + QVERIFY(colors.count() > 1); + QVERIFY(colors.contains(qRgb(0, 0, 0))); // black + QVERIFY(colors.contains(qRgb(255, 0, 0))); // red + for (auto color : colors) { + QCOMPARE(qGreen(color), 0); + QCOMPARE(qBlue(color), 0); } - - QVERIFY(redComponents.count() > 1); - QVERIFY(redComponents.contains(0)); // black - QVERIFY(redComponents.contains(255)); // red } void tst_QQuickWebEngineView::inputMethod() -- cgit v1.2.3