summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzabolcs David <[email protected]>2025-07-28 16:35:50 +0200
committerSzabolcs David <[email protected]>2025-08-17 18:44:09 +0000
commitbe7190c6565e995bd6877b47a400f37692137ee3 (patch)
treea74dfc9a1215ddf83095a988e6e1adc8a49295ff
parent653122d8649da8d6d7791edf046aee4304b5963b (diff)
Stabilize scrollPosition auto test on fractional zoom level devices
This test fails for example when the system has a 125% global zoom level set. Inside Chromium: The requested pixel positions will be scaled up by the device pixel ratio (1.25). The resulting fractional number will be floored down and used for scrolling. In RenderWidgetHostViewQt: We are informed about the scroll event and the non-fractional integer is provided for us. We try to scale this value down by dividing with the DPR to get back the requested pixel position - but the result will never be accurate becase of the lost fractional part in Chromium. In this example, the difference between the requested and the actual scroll position is outside of the tolerance level of qFuzzyCompare. The good news is Chrome behaves the same way, it provides the same inaccurate fractional scroll position in JavaScript as WebEngine (both in the API and in JavaScript). So the best we can do is relaxing the test by implementing a less strict comparison function for floats. Pick-to: 6.10 6.9 Change-Id: I2e924fac4344126727c347098b7f17da700181e0 Reviewed-by: Allan Sandfeld Jensen <[email protected]> Reviewed-by: Peter Varga <[email protected]>
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 0eb8b4d46..6df52dc61 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -92,6 +92,11 @@ static void removeRecursive(const QString& dirname)
QDir().rmdir(dirname);
}
+bool fuzzyEqual(float a, float b, float epsilon = 1e-4f)
+{
+ return std::fabs(a - b) <= epsilon;
+}
+
struct TestBasePage : QWebEnginePage
{
explicit TestBasePage(QWebEngineProfile *profile, QObject *parent = nullptr) : QWebEnginePage(profile, parent) { }
@@ -2584,13 +2589,16 @@ void tst_QWebEnginePage::scrollPosition()
// try to set the scroll offset programmatically
view.page()->runJavaScript("window.scrollTo(23, 29);");
- QTRY_COMPARE(view.page()->scrollPosition().x(), 23);
- QCOMPARE(view.page()->scrollPosition().y(), 29);
-
- int x = evaluateJavaScriptSync(view.page(), "window.scrollX").toInt();
- int y = evaluateJavaScriptSync(view.page(), "window.scrollY").toInt();
- QCOMPARE(x, 23);
- QCOMPARE(y, 29);
+ double dpr = view.windowHandle()->devicePixelRatio();
+ float expectedX = qFloor(23 * dpr) / dpr;
+ float expectedY = qFloor(29 * dpr) / dpr;
+ QTRY_VERIFY(fuzzyEqual(view.page()->scrollPosition().x(), expectedX));
+ QVERIFY(fuzzyEqual(view.page()->scrollPosition().y(), expectedY));
+
+ float x = evaluateJavaScriptSync(view.page(), "window.scrollX").toFloat();
+ float y = evaluateJavaScriptSync(view.page(), "window.scrollY").toFloat();
+ QVERIFY(fuzzyEqual(x, expectedX));
+ QVERIFY(fuzzyEqual(y, expectedY));
}
void tst_QWebEnginePage::scrollbarsOff()