Skip to content

Commit 403c505

Browse files
tursunovachromium-wpt-export-bot
authored andcommitted
Implement basic support for random() function
Add random function to CSSMathExpressionNode. Random base value cache [0] is stored on the Document. There are two major remaining things: 1. Currently we don't store correct property name and property value index in random caching key [1]. There are failing tests reflecting that. 2. If a random() function can’t be simplified by computed value time, then it should compute to its maximally-simplified form, but with its <random-value-sharing> set to its random base value, [2]. This currently doesn't work correctly since we just resolve to computed percentage value instead, i.e. same as min-max percentage serialization doesn't work correctly in chrome [3]. Note: There are some failing tests that allows calc expressions and random function inside fixed value, like: random(fixed calc(2 / 4), 0px, 100px) Though according to spec only numbers from 0 to 1 (fixed <number [0,1]>) should be allowed. These tests should probably be removed. Tests with invalidation to be added in the next CL. [0] https://drafts.csswg.org/css-values-5/#random-caching [1] https://drafts.csswg.org/css-values-5/#random-caching-key [2] https://drafts.csswg.org/css-values-5/#random [3] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/css/css-values/minmax-percentage-serialize-expected.txt [4] https://drafts.csswg.org/css-values-5/#valdef-random-fixed Bug: 413385732 Change-Id: I350a1c616d69302353c935dd12580f846ec59a53 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7170451 Commit-Queue: Munira Tursunova <[email protected]> Reviewed-by: Rune Lillesveen <[email protected]> Cr-Commit-Position: refs/heads/main@{#1549109}
1 parent 7d1c922 commit 403c505

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

css/css-values/random-computed.tentative.html

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
// Run each test a number of times to increase the likelyhood that failure is not the cause of random chance.
5151
const iterations = 5;
5252

53+
// Since actual and expected values are generated randomly, `assert_equals()`
54+
// does not generate deterministic test failure output. Chrome relies on test
55+
// failure output to be deterministic and stable for failing test expectations.
56+
function test_random_equals(actual, expected, message = "Random values should be equal") {
57+
assert_true(actual === expected, message);
58+
}
59+
5360
function test_random_computed_value(property, specified, computed, titleExtra, options = {}) {
5461
if (!computed)
5562
computed = specified;
@@ -68,12 +75,12 @@
6875
} else if (Array.isArray(computed)) {
6976
assert_in_array(readValue, computed);
7077
} else {
71-
assert_equals(readValue, computed);
78+
test_random_equals(readValue, computed);
7279
}
7380
if (readValue !== specified) {
7481
target.style[property] = '';
7582
target.style[property] = readValue;
76-
assert_equals(getComputedStyle(target)[property], readValue,
83+
test_random_equals(getComputedStyle(target)[property], readValue,
7784
'computed value should round-trip');
7885
}
7986
}
@@ -163,15 +170,15 @@
163170
// split fixed component into its two components
164171
let [fixedString, fixedValue] = fixedComponent.split(' ');
165172

166-
assert_equals(fixedString, 'fixed', specified);
173+
test_random_equals(fixedString, 'fixed', `Computed value for ${specified} should include 'fixed'`);
167174
if (expectedFixedValue) {
168-
assert_equals(parseFloat(fixedValue), expectedFixedValue);
175+
test_random_equals(parseFloat(fixedValue), expectedFixedValue, `Random value for ${specified} should be ${expectedFixedValue}`);
169176
} else {
170177
assert_greater_than_equal(parseFloat(fixedValue), 0, specified);
171178
assert_less_than(parseFloat(fixedValue), 1, specified);
172179
}
173-
assert_equals(minComponent, minPercentage, specified);
174-
assert_equals(maxComponent, maxPercentage, specified);
180+
test_random_equals(minComponent, minPercentage, specified);
181+
test_random_equals(maxComponent, maxPercentage, specified);
175182
}
176183
}, `Property ${property} value '${specified}'${titleExtra ? ' ' + titleExtra : ''}`);
177184
}
@@ -323,7 +330,7 @@
323330
} finally {
324331
document.body.removeChild(holder);
325332
}
326-
}, `Maximum random - shorthand: random(a, b))`);
333+
}, `Maximum random - shorthand: random(a, b)`);
327334

328335
test(() => {
329336
const holder = document.createElement('div');
@@ -338,7 +345,8 @@
338345
let elComputedWidth = getComputedStyle(el)['width'];
339346
let elComputedHeight = getComputedStyle(el)['height'];
340347

341-
assert_equals(elComputedWidth, elComputedHeight);
348+
test_random_equals(elComputedWidth, elComputedHeight,
349+
"width and height values on same element should be equal");
342350
}
343351
} finally {
344352
document.body.removeChild(holder);
@@ -384,7 +392,8 @@
384392
let t1ComputedWidth = getComputedStyle(t1)['width'];
385393
let t2ComputedWidth = getComputedStyle(t2)['width'];
386394

387-
assert_equals(t1ComputedWidth, t2ComputedWidth);
395+
test_random_equals(t1ComputedWidth, t2ComputedWidth,
396+
"width values on different elements should be equal");
388397
}
389398
} finally {
390399
document.body.removeChild(holder);
@@ -430,7 +439,8 @@
430439
let t1ComputedWidth = getComputedStyle(t1)['width'];
431440
let t2ComputedHeight = getComputedStyle(t2)['height'];
432441

433-
assert_equals(t1ComputedWidth, t2ComputedHeight);
442+
test_random_equals(t1ComputedWidth, t2ComputedHeight,
443+
"width and height values on different elements should be equal");
434444
}
435445
} finally {
436446
document.body.removeChild(holder);
@@ -472,7 +482,7 @@
472482

473483
let t1ComputedWidth = getComputedStyle(t1)['width'];
474484

475-
assert_equals(t1ComputedWidth, "55px");
485+
test_random_equals(t1ComputedWidth, "55px", "Random value with fixed should be 55px");
476486
}
477487
} finally {
478488
document.body.removeChild(holder);

0 commit comments

Comments
 (0)