summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mathml/presentation-markup/mrow/mrow-fallback.html
blob: 3f9d466148c66877e9fe4104f00d2963cbec0380 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test mrow fallback for some MathML elements</title>
<link rel="help" href="https://w3c.github.io/mathml-core/#script-and-limit-schemata">
<meta name="assert" content="Verify that invalid markup fallbacks to row layout.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
<script src="/mathml/support/fonts.js"></script>
<script src="/mathml/support/layout-comparison.js"></script>
<script src="/mathml/support/mathml-fragments.js"></script>
<script>
  setup({ explicit_done: true });
  window.addEventListener("load", () => { loadAllFonts().then(runTests); });

  function isValid(tagName, mspaceCount) {
    switch (tagName) {
      case "mfrac":
      case "mroot":
      case "munder":
      case "mover":
      case "msub":
      case "msup":
        return mspaceCount == 2;
      case "munderover":
      case "msubsup":
        return mspaceCount == 3;
      case "mmultiscripts":
        return mspaceCount % 2 == 1;
    }
  }

  function runTests() {
    let container = document.getElementById("container");
    const epsilon = 1;
    ["mfrac", "mroot", "munder", "mover", "munderover", "msub", "msup", "msubsup", "mmultiscripts"].forEach(tag => {
      let element = FragmentHelper.createElement(tag);
      let reference = FragmentHelper.createElement("mrow");
      container.appendChild(element);
      container.appendChild(reference);
      let maxCount = tag == "mmultiscripts" ? 10 : 5;
      let mspaceCount = 0;
      for (let count = 0; count <= maxCount; count++) {
        if (!isValid(tag, mspaceCount)) {
          test(function() {
            compareLayout(element, reference, epsilon);
          }, `Invalid <${element.tagName}> should lay out as an mrow (count == ${count})`);
        }
        if (tag == "mmultiscripts" && count == maxCount / 2) {
          [element, reference].forEach(el => {
            el.insertAdjacentHTML("beforeend", `<mprescripts/>`);
          });
        } else {
          let width = (count + 1) * 10;
          let height = (count + 1) * (count % 2 ? 15 : 5);
          let depth = (count + 1) * (count % 2 ? 5 : 15);
          [element, reference].forEach(el => {
            el.insertAdjacentHTML("beforeend", `<mspace height="${height}px" depth="${depth}px" width="${width}px" style="background: black"/>`);
          });
          mspaceCount++;
        }
      }
    });
    Array.from(document.getElementById("invalidMultiscripts").
               getElementsByTagName("mmultiscripts")).forEach(element => {
      let reference = element.nextElementSibling;
      let description = element.dataset.description;
      test(function() {
        compareLayout(element, reference, epsilon);
      }, `Invalid mmultiscripts should lay out as an mrow (${description})`);
    });

    done();
  }
</script>
</head>
<body>
  <div id="log"></div>
  <div id="container"></div>
  <div id="invalidMultiscripts">
    <math>
      <mmultiscripts data-description="first in-flow child is an <mprescripts>">
        <mprescripts/>
        <mspace height="5px" depth="15px" width="10px" style="background: black"/>
        <mspace height="30px" depth="10px" width="20px" style="background: black"/>
        <mspace height="15px" depth="45px" width="30px" style="background: black"/>
        <mspace height="60px" depth="20px" width="40px" style="background: black"/>

      </mmultiscripts>
      <mrow>
        <mprescripts/>
        <mspace height="5px" depth="15px" width="10px" style="background: black"/>
        <mspace height="30px" depth="10px" width="20px" style="background: black"/>
        <mspace height="15px" depth="45px" width="30px" style="background: black"/>
        <mspace height="60px" depth="20px" width="40px" style="background: black"/>

      </mrow>
    </math>
    <math>
      <mmultiscripts data-description="one of the even number of children after the first <mprescripts> is an <mprescripts>">
        <mspace height="5px" depth="15px" width="10px" style="background: black"/>
        <mspace height="30px" depth="10px" width="20px" style="background: black"/>
        <mspace height="15px" depth="45px" width="30px" style="background: black"/>
        <mprescripts/>
        <mspace height="60px" depth="20px" width="40px" style="background: black"/>
        <mprescripts/>
        <mspace height="25px" depth="75px" width="50px" style="background: black"/>
        <mspace height="35px" depth="105px" width="70px" style="background: black"/>
      </mmultiscripts>
      <mrow>
        <mspace height="5px" depth="15px" width="10px" style="background: black"/>
        <mspace height="30px" depth="10px" width="20px" style="background: black"/>
        <mspace height="15px" depth="45px" width="30px" style="background: black"/>
        <mprescripts/>
        <mspace height="60px" depth="20px" width="40px" style="background: black"/>
        <mprescripts/>
        <mspace height="25px" depth="75px" width="50px" style="background: black"/>
        <mspace height="35px" depth="105px" width="70px" style="background: black"/>
      </mrow>
    </math>
  </div>
</body>
</html>