summaryrefslogtreecommitdiffstats
path: root/layout/inspector/tests/chrome/test_getBlockLineCounts.html
blob: 07a9ca2c7200ee198994ed29608dc04217218e9f (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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<style>
.test {
  margin: 1em;
  font: 13px monospace;
  width: 16ch;
}
.cols {
  columns: 3;
}
</style>
</head>

<body>
  <div class="test"><span id="test1">one two three four five six seven</span></div>
  <div class="test"><div id="test2">one two three four five six seven</div></div>
  <div class="test cols"><div id="test3">one two three four five six seven</div></div>
  <div class="test"><div id="test4" class="cols">one two three four five six seven</div></div>

  <script>
  const TEST_DATA = [
    {
      description: "Test line counts of a non-block element returns null",
      testElem: "test1",
      lineCounts: null,
    },
    {
      description: "Test line count of a non-fragmented block",
      testElem: "test2",
      lineCounts: [3],
    },
    {
      description: "Test line counts of a block that is fragmented across columns",
      testElem: "test3",
      lineCounts: [3, 3, 1],
    },
    {
      description: "Test line counts when columns are specified directly on the block",
      testElem: "test4",
      lineCounts: [3, 3, 1],
    },
  ];

  function check(a, b) {
    if (a === null) {
      return b === null;
    }
    if (a.length !== b.length) {
      return false;
    }
    for (let i = 0; i < a.length; i++) {
      if (a[i] !== b[i]) {
        return false;
      }
    }
    return true;
  }

  function run_tests() {
    for (const { description, testElem, lineCounts } of TEST_DATA) {
      info(description);

      let target = document.getElementById(testElem);
      let counts = InspectorUtils.getBlockLineCounts(target);

      ok(check(counts, lineCounts), "got expected line counts");
    }

    SimpleTest.finish();
  }

  SimpleTest.waitForExplicitFinish();
  window.requestAnimationFrame(run_tests);
  </script>
</body>