7070 }
7171} , `random() in var() should be allowed in if() style() condition` ) ;
7272
73+ test ( ( ) => {
74+ const holder = document . createElement ( 'div' ) ;
75+ document . body . appendChild ( holder ) ;
76+ try {
77+ let allSame = true ;
78+ for ( let i = 0 ; i < 30 ; i ++ ) {
79+ const prop = `--unregistered-${ i } ` ;
80+ const el1 = document . createElement ( 'div' ) ;
81+ el1 . style . setProperty ( prop , 'if(style(random(0, 1) = random(0, 1)): true; else: false;)' ) ;
82+ holder . appendChild ( el1 ) ;
83+ const elComputedValue1 = getComputedStyle ( el1 ) . getPropertyValue ( prop ) ;
84+ if ( elComputedValue1 == 'false' ) {
85+ allSame = false ;
86+ }
87+ }
88+ assert_equals ( allSame , false ) ;
89+ } finally {
90+ document . body . removeChild ( holder ) ;
91+ }
92+ } , `Sharing random() in same if() condition` ) ;
93+
94+ test ( ( ) => {
95+ const holder = document . createElement ( 'div' ) ;
96+ document . body . appendChild ( holder ) ;
97+ try {
98+ let allSame = true ;
99+ for ( let i = 0 ; i < 30 ; i ++ ) {
100+ const prop = `--unregistered-${ i } ` ;
101+ const el1 = document . createElement ( 'div' ) ;
102+ el1 . style . setProperty ( prop , 'if(style(random(property-scoped, 0, 1) = random(property-scoped, 0, 1)): true; else: false;)' ) ;
103+ holder . appendChild ( el1 ) ;
104+ const elComputedValue1 = getComputedStyle ( el1 ) . getPropertyValue ( prop ) ;
105+ if ( elComputedValue1 == 'false' ) {
106+ allSame = false ;
107+ }
108+ }
109+ assert_equals ( allSame , true ) ;
110+ } finally {
111+ document . body . removeChild ( holder ) ;
112+ }
113+ } , `Sharing property-scoped random() in same if() condition` ) ;
114+
73115test ( ( ) => {
74116 const holder = document . createElement ( 'div' ) ;
75117 document . body . appendChild ( holder ) ;
282324 }
283325} , `random() with same property name on different elements in if() declaration value should be equal` ) ;
284326
327+ test ( ( ) => {
328+ const holder = document . createElement ( 'div' ) ;
329+ document . body . appendChild ( holder ) ;
330+ try {
331+ let allSame = true ;
332+ for ( let i = 0 ; i < 30 ; i ++ ) {
333+ const prop1 = `--unregistered-${ i } ` ;
334+ const prop2 = `--unregistered2-${ i } ` ;
335+ const el1 = document . createElement ( 'div' ) ;
336+ el1 . style . setProperty ( prop1 , 'if(style(random(0, 1) > 0.5): true; else: false;)' ) ;
337+ el1 . style . setProperty ( prop2 , 'if(style(random(property-index-scoped, 0, 1) > 0.5): true; else: false;)' ) ;
338+
339+ const el2 = document . createElement ( 'div' ) ;
340+ el2 . style . setProperty ( prop2 , 'if(style(random(property-index-scoped, 0, 1) > 0.5): true; else: false;)' ) ;
341+
342+ holder . appendChild ( el1 ) ;
343+ holder . appendChild ( el2 ) ;
344+
345+ const elComputedValue1 = getComputedStyle ( el1 ) . getPropertyValue ( prop2 ) ;
346+ const elComputedValue2 = getComputedStyle ( el2 ) . getPropertyValue ( prop2 ) ;
347+ if ( elComputedValue1 != elComputedValue2 ) {
348+ allSame = false ;
349+ }
350+ }
351+ assert_equals ( allSame , true ) ;
352+ } finally {
353+ document . body . removeChild ( holder ) ;
354+ }
355+ } , `Sharing property-index-scoped random() in if() style() condition across different elements with different property counts` ) ;
356+
357+ test ( ( ) => {
358+ const holder = document . createElement ( 'div' ) ;
359+ document . body . appendChild ( holder ) ;
360+ try {
361+ let allSame = true ;
362+ for ( let i = 0 ; i < 30 ; i ++ ) {
363+ const prop = `--unregistered-${ i } ` ;
364+ const el1 = document . createElement ( 'div' ) ;
365+ el1 . style . setProperty ( prop , 'if(style(calc(random(property-index-scoped, 0, 1) + random(property-index-scoped, 0, 1)) > 0.5): true; else: false;) if(style(random(property-index-scoped, 0, 1) > 0.5): true; else: false;)' ) ;
366+
367+ const el2 = document . createElement ( 'div' ) ;
368+ el2 . style . setProperty ( prop , 'if(style(random(property-index-scoped, 0, 1) > 0.5): true; else: false;) if(style(random(property-index-scoped, 0, 1) > 0.5): true; else: false;)' ) ;
369+
370+ holder . appendChild ( el1 ) ;
371+ holder . appendChild ( el2 ) ;
372+
373+ const elComputedValue1 = getComputedStyle ( el1 ) . getPropertyValue ( prop ) ;
374+ let [ , val1_second ] = elComputedValue1 . split ( ' ' ) ;
375+
376+ const elComputedValue2 = getComputedStyle ( el2 ) . getPropertyValue ( prop ) ;
377+ let [ , val2_second ] = elComputedValue2 . split ( ' ' ) ;
378+
379+ if ( val1_second != val2_second ) {
380+ allSame = false ;
381+ }
382+ }
383+ assert_equals ( allSame , false ) ;
384+ } finally {
385+ document . body . removeChild ( holder ) ;
386+ }
387+ } , `Sharing property-index-scoped random() with multiple random() inside calc()` ) ;
388+
285389</ script >
0 commit comments