summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mathml/presentation-markup/tables/table-003.html
blob: 323cb03c8ac20acc7bccb150e7ed26f4eb2fbac1 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Basic table alignment</title>
<link rel="help" href="https://w3c.github.io/mathml-core/#table-or-matrix-mtable">
<meta name="assert" content="Verify alignment of cells with block elements in basic 2x2, 4x3 and 3x4 math tables.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/mathml/support/feature-detection.js"></script>
<script>
  setup({ explicit_done: true });
  window.addEventListener("load", runTests);
  function runTests() {
      var epsilon = 1;
      test(function() {
          assert_true(MathMLFeatureDetection.has_mspace());
          const ascents = [40, 0, 20, 30, 10, 80, 0, 40, 70, 30];
          const row = document.getElementById("vertical").firstElementChild;
          const cells = Array.from(row.getElementsByTagName("mtd"));
          for (var i = 0; i < cells.length - 1; i++) {
              var space1 = cells[i].firstElementChild.firstElementChild.getBoundingClientRect();
              var space2 = cells[i + 1].firstElementChild.firstElementChild.getBoundingClientRect();
              assert_approx_equals(space1.top + ascents[i],
                                   space2.top + ascents[i + 1],
                                   epsilon,
                                   `Baselines of cells ${i} and ${i + 1} should be aligned.`);
          }
      }, `Vertical alignment of cells`);

      test(function() {
          assert_true(MathMLFeatureDetection.has_mspace());
          const table = document.getElementById("horizontal");
          const rows = Array.from(table.getElementsByTagName("mtr"));
          for (var j = 0; j < rows.length - 1; j++) {
              var space1 = rows[j].firstElementChild.firstElementChild.firstElementChild.getBoundingClientRect();
              var space2 = rows[j + 1].firstElementChild.firstElementChild.firstElementChild.getBoundingClientRect();
              assert_approx_equals((space1.left + space1.right) / 2,
                                   (space2.left + space2.right) / 2,
                                   epsilon,
                                   `Baselines of cells ${j} and ${j + 1} should be aligned.`);
          }
      }, `Horizontal alignment of cells`);

      done();
  }
</script>
</head>
<body>
  <div id="log"></div>
  <p>
    <math>
      <mtable id="vertical">
        <mtr>
          <mtd>
            <mrow><mspace width="10px" height="40px" depth="0px" style="background: lightblue;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="0px" depth="40px" style="background: lightgreen;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="20px" depth="20px" style="background: cyan;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="30px" depth="10px" style="background: purple;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="10px" depth="30px" style="background: orange;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="80px" depth="0px" style="background: blue;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="0px" depth="80px" style="background: green;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="40px" depth="40px" style="background: yellow;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="70px" depth="30px" style="background: red;"></mspace></mrow>
          </mtd>
          <mtd>
            <mrow><mspace width="10px" height="30px" depth="70px" style="background: black;"></mspace></mrow>
          </mtd>
        </mtr>
      </mtable>
    </math>
  </p>
  <p>
    <math>
      <mtable id="horizontal">
        <mtr>
          <mtd>
            <mrow><mspace width="10px" height="10px" style="background: lightblue;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="40px" height="10px" style="background: lightgreen;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="30px" height="10px" style="background: cyan;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="20px" height="10px" style="background: purple;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="50px" height="10px" style="background: orange;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="100px" height="10px" style="background: blue;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="90px" height="10px" style="background: green;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="70px" height="10px" style="background: yellow;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="80px" height="10px" style="background: red;"></mspace></mrow>
          </mtd>
        </mtr>
        <mtr>
          <mtd>
            <mrow><mspace width="40px" height="10px" style="background: black;"></mspace></mrow>
          </mtd>
        </mtr>
      </mtable>
    </math>
  </p>
</body>
</html>