commit fed6070bfbe7cb605ab3860797c5c4042d01e9fa
parent ea566fe7b55bd9c1b161c0a34b6379a8657cf933
Author: Jan Varga <jvarga@igalia.com>
Date: Tue, 9 Dec 2025 11:35:23 +0000
Bug 1990419 - Make CSSMathSum and CSSMathProduct array comparison order-agnostic; r=emilio
Browsers currently differ in how they preserve array order for CSSMathSum and
CSSMathProduct. This patch adds a new helper,
`assert_style_value_array_unordered_equals()`, to compare values while ignoring
their order. This is a temporary relaxation until the spec is clarified and
tests can assert canonical (sorted) ordering.
Differential Revision: https://phabricator.services.mozilla.com/D271038
Diffstat:
1 file changed, 30 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/css/css-typed-om/resources/testhelper.js b/testing/web-platform/tests/css/css-typed-om/resources/testhelper.js
@@ -63,6 +63,8 @@ function assert_style_value_equals(a, b) {
break;
case 'CSSMathSum':
case 'CSSMathProduct':
+ assert_style_value_array_unordered_equals(a.values, b.values);
+ break;
case 'CSSMathMin':
case 'CSSMathMax':
assert_style_value_array_equals(a.values, b.values);
@@ -126,6 +128,34 @@ function assert_style_value_array_equals(a, b) {
}
}
+// Compares two arrays of CSSStyleValues, ignoring element order.
+//
+// Used for CSSMathSum and CSSMathProduct, where browsers currently differ
+// in how values are ordered. The ordering behavior is under discussion in
+// https://github.com/w3c/csswg-drafts/issues/9451.
+//
+// This is a temporary relaxation: for now, the test accepts any order
+// to avoid interop failures across engines. Once the spec is clarified,
+// tests should assert that the order matches the canonical (sorted) form
+// used for both CSS values and CSS Typed OM.
+function assert_style_value_array_unordered_equals(a, b) {
+ assert_equals(a.length, b.length);
+
+ const remaining = [...b];
+ a.forEach((valueA) => {
+ const matched = remaining.some((valueB, i) => {
+ try {
+ assert_style_value_equals(valueA, valueB);
+ remaining.splice(i, 1);
+ return true;
+ } catch {
+ return false;
+ }
+ });
+ assert_true(matched);
+ });
+}
+
const gValidUnits = [
'number', 'percent', 'em', 'ex', 'ch',
'ic', 'rem', 'lh', 'rlh', 'vw',