commit 2e1381577f7dde8254c516e73a8573aa433ade72 parent 97ab6014dad569a5212f6f89f43c47513741695c Author: Callum Law <callumlaw1709@outlook.com> Date: Fri, 14 Nov 2025 10:24:06 +0000 Bug 1998536 [wpt PR 55867] - A couple of fixes for the CSS `random()` tests, a=testonly Automatic update from web-platform-tests A couple of fixes for the CSS `random()` tests (#55867) * Expect correct result for CSS random with step of infinity The spec states that "In random(A, B, C)... If C is infinite, the result is A." however this test previously expected the result to be NaN, the same as if B was infinite. * Fix incorrect test_random_computed_value_has_fixed We expect the fixed value to be less than (not equal to) 1. assert_{greater_than_equal|less_than} expects the actual value to be given as a number rather than a string * Allow out of range math functions result in random fixed value [the spec](https://drafts.csswg.org/css-values-4/#calc-range) states that "Parse-time range-checking of values is not performed within math functions, and therefore out-of-range values do not cause the declaration to become invalid". This means we should allow math functions that result in out of range results in <random-value-sharing> fixed values at parse time with the expectation that they will be clamped at compute time * Allow random parameters of consistent type Corresponds to w3c/csswg-drafts@f587be0 which updated the criteria for random arguments to be of consistent rather than same type -- wpt-commits: 6827c6a75645b048ef37f3452b3f9e5bf08943e0 wpt-pr: 55867 Diffstat:
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/testing/web-platform/tests/css/css-values/random-computed.tentative.html b/testing/web-platform/tests/css/css-values/random-computed.tentative.html @@ -143,7 +143,7 @@ function test_pseudo_element_random_computed_value_in_range(property, pseudo_ele }, `Property ${property} value on pseudo element '${pseudo_element}' '${specified}'${titleExtra ? ' ' + titleExtra : ''}`); } -function test_random_computed_value_has_fixed(property, specified, minPercentage, maxPercentage, titleExtra) { +function test_random_computed_value_has_fixed(property, specified, minPercentage, maxPercentage, expectedFixedValue = undefined, titleExtra = undefined) { test(() => { for (i = 0; i < iterations; ++i) { const target = document.getElementById('target'); @@ -164,8 +164,12 @@ function test_random_computed_value_has_fixed(property, specified, minPercentage let [fixedString, fixedValue] = fixedComponent.split(' '); assert_equals(fixedString, 'fixed', specified); - assert_greater_than_equal(parseFloat(fixedValue), '0', specified); - assert_less_than_equal(parseFloat(fixedValue), '1', specified); + if (expectedFixedValue) { + assert_equals(parseFloat(fixedValue), expectedFixedValue); + } else { + assert_greater_than_equal(parseFloat(fixedValue), 0, specified); + assert_less_than(parseFloat(fixedValue), 1, specified); + } assert_equals(minComponent, minPercentage, specified); assert_equals(maxComponent, maxPercentage, specified); } @@ -245,8 +249,8 @@ test_random_computed_value(property, 'random(10, infinity, infinity)', '0'); test_random_computed_value(property, 'calc(10 + random(10, infinity))', '0'); test_random_computed_value(property, 'calc(10 + random(10, infinity, 10))', '0'); test_random_computed_value(property, 'calc(10 + random(10, infinity, infinity))', '0'); -test_random_computed_value(property, 'random(10, 100, infinity)', '0'); -test_random_computed_value(property, 'calc(10 + random(10, 100, infinity))', '0'); +test_random_computed_value(property, 'random(10, 100, infinity)', '10'); +test_random_computed_value(property, 'calc(10 + random(10, 100, infinity))', '20'); // Negative steps, even infinitely negative steps, are ignored. test_random_computed_value_in_range(property, 'random(10, 100, -infinity)', '10', '100'); test_random_computed_value_in_range(property, 'calc(10 + random(10, 100, -infinity))', '20', '110'); @@ -260,6 +264,10 @@ test_pseudo_element_random_computed_value_in_range(property, '::before', 'random // Test unresolvable percentage values test_random_computed_value_has_fixed('translate', 'random(10%, 100%)', '10%', '100%'); +// Test out of range math functions for fixed value +test_random_computed_value_has_fixed('translate', 'random(fixed random(1, 2), 10%, 100%)', '10%', '100%'); +test_random_computed_value_has_fixed('translate', 'random(fixed random(-2, -1), 10%, 100%)', '10%', '100%', 0); + // Test random value sharing test(() => { const holder = document.createElement('div'); diff --git a/testing/web-platform/tests/css/css-values/random-invalid.tentative.html b/testing/web-platform/tests/css/css-values/random-invalid.tentative.html @@ -22,7 +22,6 @@ test_invalid_value('width', 'random(element-shared foo, 1px, 2px)'); test_invalid_value('width', 'random(element-shared 1px, 2px)'); test_invalid_value('width', 'random(1px, 2px, 1px, element-shared)'); test_invalid_value('width', 'random(--foo --bar, 1px, 2px)'); -test_invalid_value('width', 'random(fixed random(1, 2), 1px, 2px)'); test_invalid_value('width', 'random(fixed 0.5 element-shared, 1px, 2px)'); test_invalid_value('width', 'random(fixed 0.5 auto, 1px, 2px)'); test_invalid_value('width', 'random(fixed 0.5 --foo, 1px, 2px)'); @@ -30,6 +29,5 @@ test_invalid_value('width', 'random(fixed 0.5px, 1px, 2px)'); test_invalid_value('width', 'random(fixed 0.5%, 1px, 2px)'); test_invalid_value('width', 'random(fixed -1, 1px, 2px)'); test_invalid_value('width', 'random(10deg, 20deg)'); -test_invalid_value('width', 'random(10px, 20%)'); </script> diff --git a/testing/web-platform/tests/css/css-values/random-serialize.tentative.html b/testing/web-platform/tests/css/css-values/random-serialize.tentative.html @@ -24,6 +24,9 @@ test_valid_value('width', 'random(element-shared --foo, 0px, 100px, 50px)', 'ran test_valid_value('width', 'random(element-shared auto, 0px, 100px, 50px)', 'random(element-shared, 0px, 100px, 50px)'); test_valid_value('width', 'random(fixed 0.5, 0px, 100px, 50px)'); +// Test consistent types +test_valid_value('width', 'random(10px, 20%)'); + // Test out of order. test_valid_value('width', 'random(100px, 0px)');