1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1131371
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1131371</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1131371">Mozilla Bug 1131371</a>
<style>
#elemWithScrollbars { overflow: scroll }
.flexScrollerWithTransformedItems {
display: flex;
overflow: hidden;
width: 200px;
position: relative;
}
.flexScrollerWithTransformedItems div {
min-width: 50px;
min-height: 50px;
margin: 10px;
will-change: transform;
}
.absposFlexItem {
left: 250px;
top: 0;
position: absolute;
}
#tableCell,
#tableCellWithAbsPosChild {
display: table-cell;
}
</style>
<div id="display">
<div id="content">
</div>
<div id="elemWithAbsPosChild"><div style="position:absolute"></div></div>
<div id="elemWithFixedPosChild"><div style="position:fixed"></div></div>
<div id="elemWithScrollbars"></div>
<div id="elemWithoutScrollbars"></div>
<div class="flexScrollerWithTransformedItems">
<div></div>
<div></div>
<div></div>
<div></div>
<div id="flexItemMovementTarget"></div>
</div>
<div class="flexScrollerWithTransformedItems">
<div></div>
<div></div>
<div></div>
<div id="flexItemMovementTarget2"></div>
<div class="absposFlexItem"></div>
</div>
<input id="inputElem">
<textarea id="textareaElem">
Some
lines
of
text
</textarea>
<select id="selectElem">
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<button id="buttonElem">
Something
</button>
<button id="buttonElemWithAbsPosChild"><div style="position:absolute"></div></button>
<div id="tableCell"></div>
<div id="tableCellWithAbsPosChild">
<div style="position: absolute"></div>
</div>
</div>
<pre id="test">
<script>
"use strict";
/** Test for Bug 1131371 **/
const elemWithAbsPosChild = document.getElementById("elemWithAbsPosChild");
const elemWithFixedPosChild = document.getElementById("elemWithFixedPosChild");
const elemWithScrollbars = document.getElementById("elemWithScrollbars");
const elemWithoutScrollbars = document.getElementById("elemWithoutScrollbars");
const inputElem = document.getElementById("inputElem");
const textareaElem = document.getElementById("textareaElem");
const selectElem = document.getElementById("selectElem");
const buttonElem = document.getElementById("buttonElem");
const buttonElemWithAbsPosChild = document.getElementById("buttonElemWithAbsPosChild");
const tableCell = document.getElementById("tableCell");
const tableCellWithAbsPosChild = document.getElementById("tableCellWithAbsPosChild");
for (let scroller of document.querySelectorAll(".flexScrollerWithTransformedItems")) {
scroller.scrollLeft = 10000;
}
const flexItemMovementTarget = document.getElementById("flexItemMovementTarget");
const flexItemMovementTarget2 = document.getElementById("flexItemMovementTarget2");
/**
* This test verifies that certain style changes do or don't cause reflow
* and/or frame construction. We do this by checking the framesReflowed &
* framesConstructed counts, before & after a style-change, and verifying
* that any change to these counts is in line with our expectations.
*
* Each entry in gTestcases contains these member-values:
* - beforeStyle (optional): initial value to use for "style" attribute.
* - afterStyle: value to change the "style" attribute to.
*
* Testcases may also include two optional member-values to express that reflow
* and/or frame construction *are* in fact expected:
* - expectConstruction (optional): if set to something truthy, then we expect
* frame construction to occur when afterStyle is set. Otherwise, we
* expect that frame construction should *not* occur.
* - expectReflow (optional): if set to something truthy, then we expect
* reflow to occur when afterStyle is set. Otherwise, we expect that
* reflow should *not* occur.
*/
const gTestcases = [
// Things that shouldn't cause reflow:
// -----------------------------------
// * Adding an outline (e.g. for focus ring).
{
afterStyle: "outline: 1px dotted black",
},
// * Changing between completely different outlines.
{
beforeStyle: "outline: 2px solid black",
afterStyle: "outline: 6px dashed yellow",
},
// * Adding a box-shadow.
{
afterStyle: "box-shadow: inset 3px 3px gray",
},
{
afterStyle: "box-shadow: 0px 0px 10px 30px blue"
},
// * Changing between completely different box-shadow values,
// e.g. from an upper-left shadow to a bottom-right shadow:
{
beforeStyle: "box-shadow: -15px -20px teal",
afterStyle: "box-shadow: 30px 40px yellow",
},
// * Adding a text-shadow.
{
afterStyle: "text-shadow: 3px 3px gray",
},
{
afterStyle: "text-shadow: 0px 0px 10px blue"
},
// * Changing between completely different text-shadow values,
// e.g. from an upper-left shadow to a bottom-right shadow:
{
beforeStyle: "text-shadow: -15px -20px teal",
afterStyle: "text-shadow: 30px 40px yellow",
},
// * switching overflow between things that shouldn't create scrollframes.
{
beforeStyle: "overflow: visible",
afterStyle: "overflow: clip",
},
// Things that *should* cause reflow:
// ----------------------------------
// (e.g. to make sure our counts are actually measuring something)
// * Changing 'height' should cause reflow, but not frame construction.
{
beforeStyle: "height: 10px",
afterStyle: "height: 15px",
expectReflow: true,
},
// * Changing 'shape-outside' on a non-floating box should not cause anything to happen.
{
beforeStyle: "shape-outside: none",
afterStyle: "shape-outside: circle()",
},
// * Changing 'shape-outside' should cause reflow, but not frame construction.
{
beforeStyle: "float: left; shape-outside: none",
afterStyle: "float: left; shape-outside: circle()",
expectReflow: true,
},
// * Changing 'overflow' on <body> should cause reflow,
// but not frame reconstruction
{
elem: document.body,
/* beforeStyle: implicitly 'overflow:visible' */
afterStyle: "overflow: hidden",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.body,
/* beforeStyle: implicitly 'overflow:visible' */
afterStyle: "overflow: scroll",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.body,
beforeStyle: "overflow: hidden",
afterStyle: "overflow: auto",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.body,
beforeStyle: "overflow: hidden",
afterStyle: "overflow: scroll",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.body,
beforeStyle: "overflow: hidden",
afterStyle: "overflow: visible",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.body,
beforeStyle: "overflow: auto",
afterStyle: "overflow: hidden",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.body,
beforeStyle: "overflow: visible",
afterStyle: "overflow: hidden",
expectConstruction: false,
expectReflow: true,
},
// * Changing 'overflow' on <html> should cause reflow,
// but not frame reconstruction
{
elem: document.documentElement,
/* beforeStyle: implicitly 'overflow:visible' */
afterStyle: "overflow: auto",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.documentElement,
beforeStyle: "overflow: visible",
afterStyle: "overflow: auto",
expectConstruction: false,
expectReflow: true,
},
// * Setting 'overflow' on arbitrary node should cause reflow as well as
// frame reconstruction
{
/* beforeStyle: implicitly 'overflow:visible' */
afterStyle: "overflow: auto",
expectConstruction: true,
expectReflow: true,
},
{
beforeStyle: "overflow: auto",
afterStyle: "overflow: visible",
expectConstruction: true,
expectReflow: true,
},
// * but only reflow if we don't need to construct / unconstruct a new frame.
{
beforeStyle: "overflow: scroll",
afterStyle: "overflow: auto",
expectConstruction: false,
expectReflow: true,
},
{
beforeStyle: "overflow: auto",
afterStyle: "overflow: scroll",
expectConstruction: false,
expectReflow: true,
},
{
beforeStyle: "overflow: hidden",
afterStyle: "overflow: auto",
expectConstruction: true,
expectReflow: true,
},
{
beforeStyle: "overflow: auto",
afterStyle: "overflow: hidden",
expectConstruction: false,
expectReflow: true,
},
{
beforeStyle: "overflow: hidden",
afterStyle: "overflow: scroll",
expectConstruction: true,
expectReflow: true,
},
{
beforeStyle: "overflow: scroll",
afterStyle: "overflow: hidden",
expectConstruction: false,
expectReflow: true,
},
{
elem: elemWithoutScrollbars,
beforeStyle: "scrollbar-width: auto",
afterStyle: "scrollbar-width: none",
expectConstruction: false,
expectReflow: false,
},
{
elem: elemWithScrollbars,
beforeStyle: "scrollbar-width: auto",
afterStyle: "scrollbar-width: none",
expectConstruction: false,
expectReflow: true,
},
{
// Not the scrolling element, so nothing should happen.
elem: document.body,
beforeStyle: "scrollbar-width: none",
afterStyle: "scrollbar-width: auto",
expectConstruction: false,
expectReflow: false,
},
{
// Not the scrolling element, so nothing should happen.
elem: document.body,
beforeStyle: "scrollbar-width: auto",
afterStyle: "scrollbar-width: none",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.documentElement,
beforeStyle: "scrollbar-width: none;",
afterStyle: "scrollbar-width: auto",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.documentElement,
beforeStyle: "overflow: scroll; scrollbar-width: none;",
afterStyle: "overflow: scroll; scrollbar-width: auto",
expectConstruction: false,
expectReflow: true,
},
{
elem: document.documentElement,
beforeStyle: "overflow: scroll; scrollbar-width: auto;",
afterStyle: "overflow: scroll; scrollbar-width: none",
expectConstruction: false,
expectReflow: true,
},
// * Changing 'display' should cause frame construction and reflow.
{
beforeStyle: "display: inline",
afterStyle: "display: table",
expectConstruction: true,
expectReflow: true,
},
// * Position changes trigger a reframe, unless whether we're a containing
// block doesn't change, in which case we just need to reflow.
{
beforeStyle: "position: static",
afterStyle: "position: absolute",
expectConstruction: true,
expectReflow: true,
},
{
beforeStyle: "position: absolute",
afterStyle: "position: fixed",
expectConstruction: true,
expectReflow: true,
},
{
beforeStyle: "position: relative",
afterStyle: "position: fixed",
expectConstruction: true,
expectReflow: true,
},
// This doesn't change whether we're a containing block because there are no
// abspos descendants.
{
afterStyle: "position: static",
beforeStyle: "position: relative",
expectReflow: true,
},
// This doesn't change whether we're a containing block, shouldn't reframe.
{
afterStyle: "position: sticky",
beforeStyle: "position: relative",
expectReflow: true,
},
// These don't change whether we're a containing block for our
// absolutely-positioned child, so shouldn't reframe.
{
elem: elemWithAbsPosChild,
afterStyle: "position: sticky",
beforeStyle: "position: relative",
expectReflow: true,
},
{
elem: elemWithFixedPosChild,
afterStyle: "position: sticky",
beforeStyle: "position: relative",
expectReflow: true,
},
{
elem: elemWithFixedPosChild,
afterStyle: "position: static",
beforeStyle: "position: relative",
expectReflow: true,
},
{
elem: elemWithFixedPosChild,
afterStyle: "position: static",
beforeStyle: "position: sticky",
expectReflow: true,
},
{
// Even if we're a scroll frame.
elem: elemWithFixedPosChild,
afterStyle: "position: static; overflow: auto;",
beforeStyle: "position: relative; overflow: auto;",
expectReflow: true,
},
{
elem: tableCell,
afterStyle: "position: static;",
beforeStyle: "position: relative;",
expectReflow: true,
},
{
elem: tableCell,
afterStyle: "filter: none",
beforeStyle: "filter: saturate(1)",
expectReflow: false,
},
// These ones do though.
{
elem: elemWithAbsPosChild,
afterStyle: "position: static",
beforeStyle: "position: relative",
expectConstruction: true,
expectReflow: true,
},
{
elem: elemWithAbsPosChild,
afterStyle: "position: static",
beforeStyle: "position: sticky",
expectConstruction: true,
expectReflow: true,
},
{
elem: elemWithAbsPosChild,
afterStyle: "position: static; overflow: auto;",
beforeStyle: "position: relative; overflow: auto;",
expectConstruction: true,
expectReflow: true,
},
{
elem: tableCellWithAbsPosChild,
afterStyle: "position: static;",
beforeStyle: "position: relative;",
expectConstruction: true,
expectReflow: true,
},
// Adding transform to a scrollframe without abspos / fixedpos children shouldn't reframe.
{
elem: elemWithScrollbars,
afterStyle: "transform: translateX(1px)",
expectConstruction: false,
expectReflow: false,
},
// <select> can't contain abspos / floating children so shouldn't reframe
// when changing containing block-ness.
{
elem: selectElem,
afterStyle: "transform: translateX(1px)",
expectConstruction: false,
expectReflow: false,
},
{
elem: selectElem,
afterStyle: "position: relative",
expectConstruction: false,
expectReflow: true,
},
// <button> shouldn't be reframed either in the absence of positioned descendants.
{
elem: buttonElem,
afterStyle: "transform: translateX(1px)",
expectConstruction: false,
expectReflow: false,
},
{
elem: buttonElem,
afterStyle: "position: relative",
expectConstruction: false,
expectReflow: true,
},
{
elem: buttonElemWithAbsPosChild,
afterStyle: "position: relative",
expectConstruction: true,
expectReflow: true,
},
// changing scroll-behavior should not cause reflow or frame construction
{
elem: document.documentElement,
/* beforeStyle: implicitly 'scroll-behavior: auto' */
afterStyle: "scroll-behavior: smooth",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.documentElement,
beforeStyle: "scroll-behavior: smooth",
afterStyle: "scroll-behavior: auto",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.body,
/* beforeStyle: implicitly 'scroll-behavior: auto' */
afterStyle: "scroll-behavior: smooth",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.body,
beforeStyle: "scroll-behavior: smooth",
afterStyle: "scroll-behavior: auto",
expectConstruction: false,
expectReflow: false,
},
// changing scroll-snap-type should not cause reflow or frame construction
{
elem: document.documentElement,
/* beforeStyle: implicitly 'scroll-snap-type: none' */
afterStyle: "scroll-snap-type: y mandatory",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.documentElement,
/* beforeStyle: implicitly 'scroll-snap-type: none' */
afterStyle: "scroll-snap-type: x proximity",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.documentElement,
beforeStyle: "scroll-snap-type: y mandatory",
afterStyle: "scroll-snap-type: none",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.body,
/* beforeStyle: implicitly 'scroll-snap-type: none' */
afterStyle: "scroll-snap-type: y mandatory",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.body,
/* beforeStyle: implicitly 'scroll-snap-type: none' */
afterStyle: "scroll-snap-type: x proximity",
expectConstruction: false,
expectReflow: false,
},
{
elem: document.body,
beforeStyle: "scroll-snap-type: y mandatory",
afterStyle: "scroll-snap-type: none",
expectConstruction: false,
expectReflow: false,
},
{
elem: inputElem,
beforeStyle: "overflow: auto",
afterStyle: "overflow: hidden",
expectConstruction: false,
expectReflow: true,
},
{
elem: textareaElem,
beforeStyle: "overflow: auto",
afterStyle: "overflow: hidden",
expectConstruction: false,
expectReflow: true,
},
{
elem: flexItemMovementTarget,
beforeStyle: "transform: translateX(0)",
afterStyle: "transform: translateX(-100px)",
expectConstruction: false,
expectReflow: false,
},
{
elem: flexItemMovementTarget2,
beforeStyle: "transform: translateX(0)",
afterStyle: "transform: translateX(-100px)",
expectConstruction: false,
expectReflow: false,
},
];
// Helper function to let us call either "is" or "isnot" & assemble
// the failure message, based on the provided parameters.
function checkFinalCount(aFinalCount, aExpectedCount,
aExpectChange, aMsgPrefix, aCountDescription)
{
let compareFunc;
let msg = aMsgPrefix;
if (aExpectChange) {
compareFunc = isnot;
msg += "should cause " + aCountDescription;
} else {
compareFunc = is;
msg += "should not cause " + aCountDescription;
}
compareFunc(aFinalCount, aExpectedCount, msg);
}
// Vars used in runOneTest that we really only have to look up once:
const gUtils = SpecialPowers.getDOMWindowUtils(window);
const gElem = document.getElementById("content");
function runOneTest(aTestcase)
{
// sanity-check that we have the one main thing we need:
if (!aTestcase.afterStyle) {
ok(false, "testcase is missing an 'afterStyle' to change to");
return;
}
// Figure out which element we'll be tweaking (defaulting to gElem)
let elem = aTestcase.elem ? aTestcase.elem : gElem;
// Verify that 'style' attribute is unset (avoid causing ourselves trouble):
const oldStyle = elem.getAttribute("style");
// Set the "before" style, and compose the first part of the message
// to be used in our "is"/"isnot" invocations:
let msgPrefix = "Changing style ";
if (aTestcase.beforeStyle) {
elem.setAttribute("style", aTestcase.beforeStyle);
msgPrefix += "from '" + aTestcase.beforeStyle + "' ";
}
msgPrefix += "to '" + aTestcase.afterStyle + "' ";
msgPrefix += "on " + elem.nodeName + " ";
// Establish initial counts:
let unusedVal = elem.offsetHeight; // flush layout
let origFramesConstructed = gUtils.framesConstructed;
let origFramesReflowed = gUtils.framesReflowed;
// Make the change and flush:
elem.setAttribute("style", aTestcase.afterStyle);
unusedVal = elem.offsetHeight; // flush layout
// Make our is/isnot assertions about whether things should have changed:
checkFinalCount(gUtils.framesConstructed, origFramesConstructed,
aTestcase.expectConstruction, msgPrefix,
"frame construction");
checkFinalCount(gUtils.framesReflowed, origFramesReflowed,
aTestcase.expectReflow, msgPrefix,
"reflow");
// Clean up!
if (oldStyle) {
elem.setAttribute("style", oldStyle);
} else {
elem.removeAttribute("style");
}
unusedVal = elem.offsetHeight; // flush layout
}
gTestcases.forEach(runOneTest);
</script>
</pre>
</body>
</html>
|