summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_bug1490890.html
blob: 00a8176ed66069c32e9fadba990838c6c5192270 (plain)
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1490890
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1490890</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style>
    #flex {
      display: flex;
      flex-direction: column;
      height: 100px;
      max-height: 100px;
      overflow: hidden;
      border: 1px solid black;
    }
    #overflowAuto {
      overflow: auto;
      white-space: pre-wrap;
    }
  </style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1490890">Mozilla Bug 1490890</a>
<div id="display">
  <div id="content">
    <div id="flex">
      <div id="overflowAuto">
        <!-- Populated by test JS below: -->
        <div id="tall"></div>
      </div>
      <div id="testNode">abc</div>
    </div>
  </div>
</div>
<pre id="test">
<script type="application/javascript">
"use strict";

/** Test for Bug 1490890 **/

/**
 * This test checks how many reflows are required, when we make a change inside
 * a flex item, with a tall scrollable sibling flex item.
 */

const gUtils = SpecialPowers.getDOMWindowUtils(window);

// The elements that we will modify here:
const gTall = document.getElementById("tall");
const gTestNode = document.getElementById("testNode");

// Helper function to undo our modifications:
function cleanup()
{
  gTall.firstChild.remove();
  gTestNode.style = "";
}

// Flush layout & return the global frame-reflow-count
function getReflowCount()
{
  let unusedVal = document.getElementById("flex").offsetHeight; // flush layout
  return gUtils.framesReflowed;
}

// This function changes gTestNode to "display:none", and returns the number
// of frames that need to be reflowed as a result of that tweak.
function makeTweakAndCountReflows()
{
  let beforeCount = getReflowCount();
  gTestNode.style.display = "none";
  let afterCount = getReflowCount();

  let numReflows = afterCount - beforeCount;
  if (numReflows <= 0) {
    ok(false, "something's wrong -- we should've reflowed *something*");
  }
  return numReflows;
}

// ACTUAL TEST LOGIC STARTS HERE
// -----------------------------
const testLineCount = 100;
const refLineCount = 5000;

// "Reference" measurement: put enough lines of text into gTall to trigger
// a vertical scrollbar, and then see how many frames need to be reflowed
// in response to a tweak in gTestNode:
let text = document.createTextNode("a\n".repeat(testLineCount));
gTall.appendChild(text);
let numReferenceReflows = makeTweakAndCountReflows();
cleanup();

// "Test" measurement: put many more lines of text into gTall (many more than
// for reference case), and then see how many frames need to be reflowed
// in response to a tweak in gTestNode:
text = document.createTextNode("a\n".repeat(refLineCount));
gTall.appendChild(text);
let numTestReflows = makeTweakAndCountReflows();
cleanup();

is(numTestReflows, numReferenceReflows,
   "Tweak should trigger the same number of reflows regardless of " +
   "how much content is present in descendant of sibling");
</script>
</pre>
</body>
</html>