Visitar URL original
WebKit export of https://bugs.webkit.org/show_bug.cgi?id=319919 (#62288) · web-platform-tests/wpt@fb24b8b · GitHub
Skip to content

Commit fb24b8b

Browse files
authored
1 parent 4bb4984 commit fb24b8b

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎css/css-values/random-item-computed.html‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,41 @@
204204
assert_equals(m, Math.min(400, Math.floor(w / 100) * 100), 'random() and random-item() share the element-scoped base value');
205205
}, 'random() and random-item() share the base value for a bare element-scoped key');
206206

207+
// A derived property scope records which function produced it, so an auto random() and an auto
208+
// random-item() in one value draw independently. With random() scaled to 0-400px and two items
209+
// 0/1000px, a shared draw would make the item choice track whether random() landed above half;
210+
// over 40 samples that agreeing every time is about 1 in 10^12.
211+
function sharedDrawCount(declaration) {
212+
let consistentWithSharing = 0;
213+
const holder = document.createElement('div');
214+
document.body.appendChild(holder);
215+
try {
216+
for (let i = 0; i < 40; ++i) {
217+
const element = document.createElement('div');
218+
element.style.cssText = declaration;
219+
holder.appendChild(element);
220+
const width = parseFloat(getComputedStyle(element).width);
221+
const selectedSecondItem = width >= 1000;
222+
const randomFraction = (width - (selectedSecondItem ? 1000 : 0)) / 400;
223+
if ((randomFraction >= 0.5) === selectedSecondItem)
224+
++consistentWithSharing;
225+
}
226+
} finally {
227+
document.body.removeChild(holder);
228+
}
229+
return consistentWithSharing;
230+
}
231+
232+
test(() => {
233+
const shared = sharedDrawCount('width: calc(random(auto, 0px, 400px) + random-item(auto, 0px, 1000px))');
234+
assert_less_than(shared, 40, 'random() and random-item() drew the same base value');
235+
}, 'auto random() and auto random-item() in one value do not share a base value');
236+
237+
test(() => {
238+
const shared = sharedDrawCount('--n: random(auto, 0, 1); width: calc(var(--n) * 400px + random-item(auto, 0px, 1000px))');
239+
assert_less_than(shared, 40, 'random() reached through var() drew the same base value as random-item()');
240+
}, 'auto random() substituted through var() does not share a base value with random-item()');
241+
207242
// A <dashed-ident> as short as "--" is a valid key (parity with random()); the value resolves rather
208243
// than becoming guaranteed-invalid.
209244
test_computed_value('color', 'random-item(--, rgb(1, 0, 0), rgb(0, 1, 0))', ['rgb(1, 0, 0)', 'rgb(0, 1, 0)']);

0 commit comments

Comments
 (0)