summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mathml/presentation-markup/fractions/frac-linethickness-002.html
blob: bb47f186879c612e6609825a5f7adb4678400a6d (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
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>fractions linethickness</title>
    <link rel="help" href="https://w3c.github.io/mathml-core/#fractions-mfrac">
    <link rel="help" href="https://w3c.github.io/mathml-core/#dom-and-javascript">
    <meta name="assert" content="Verifies fraction with positive, negative, percent and named space linethickness values.">
    <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>
    <style type="text/css">
      @font-face {
        font-family: TestFont;
        src: url("/fonts/math/fraction-rulethickness10000.woff");
      }
      math {
        /* FractionRuleThickness = 10000 * 10 / 1000 = 100px; */
        font-family: "TestFont";
        font-size: 10px;
      }
    </style>
    <script>
      function LineThickness(aId) {
        var mfrac = document.getElementById(aId);
        var numBox = mfrac.firstElementChild.getBoundingClientRect();
        var denumBox = mfrac.lastElementChild.getBoundingClientRect();
        return denumBox.top - numBox.bottom;
      }

      setup({ explicit_done: true });
      window.addEventListener("load", () => { loadAllFonts().then(runTests); });

      function runTests() {
        var defaultRuleThickness = 100;
        var epsilon = 2;

        test(function() {
          assert_true(MathMLFeatureDetection.has_mspace());
          assert_approx_equals(LineThickness("positive"),  5.67 * 10, epsilon);
        }, "Positive");

        test(function() {
          assert_true(MathMLFeatureDetection.has_mspace());
          /* Negative values are treated as 0 */
          assert_approx_equals(LineThickness("negative"),  0, epsilon);
        }, "Negative");

        test(function() {
          assert_true(MathMLFeatureDetection.has_mspace());
          assert_approx_equals(LineThickness("percent"), defaultRuleThickness * 234 / 100, epsilon);
        }, "Percentage");

        test(function() {
          assert_true(MathMLFeatureDetection.has_mspace());
          /* Namedspace values are invalid in MathML Core. */
          assert_approx_equals(LineThickness("namedspace"), defaultRuleThickness, epsilon);
        }, "Named space");

        test(function() {
          assert_true(MathMLFeatureDetection.has_mspace());
          /* Calc() expressions are invalid in MathML Core. */
          assert_approx_equals(LineThickness("calc"), defaultRuleThickness, epsilon);
        }, "Calc() expression");

        test(function() {
          assert_true(MathMLFeatureDetection.has_mspace());
          document.getElementById("dynamic-attach").setAttribute("linethickness", "400%");
          document.getElementById("dynamic-modify").setAttribute("linethickness", "200%");
          document.getElementById("dynamic-remove").removeAttribute("linethickness");
          assert_approx_equals(LineThickness("dynamic-attach"), defaultRuleThickness * 4, epsilon, "attach");
          assert_approx_equals(LineThickness("dynamic-modify"), defaultRuleThickness * 2, epsilon, "modify");
          assert_approx_equals(LineThickness("dynamic-remove"), defaultRuleThickness, epsilon, "remove");
        }, "Dynamic linethickness");

        done();
      }
    </script>
  </head>
  <body>
    <math>
      <mfrac id="positive" linethickness="5.67em">
        <mspace width="20px" height="10px" style="background: blue"></mspace>
        <mspace width="20px" height="10px" style="background: cyan"></mspace>
      </mfrac>
    </math>
    <math>
      <mfrac id="negative" linethickness="-1.23em">
        <mspace width="20px" height="10px" style="background: blue"></mspace>
        <mspace width="20px" height="10px" style="background: cyan"></mspace>
      </mfrac>
    </math>
    <math>
      <mfrac id="percent" linethickness="234%">
        <mspace width="20px" height="10px" style="background: blue"></mspace>
        <mspace width="20px" height="10px" style="background: cyan"></mspace>
      </mfrac>
    </math>
    <math>
      <mfrac id="namedspace" linethickness="veryverythickmathspace">
        <mspace width="20px" height="10px" style="background: blue"></mspace>
        <mspace width="20px" height="10px" style="background: cyan"></mspace>
      </mfrac>
    </math>
    <math>
      <mfrac id="calc" linethickness="calc(20px)">
        <mspace width="20px" height="10px" style="background: blue"></mspace>
        <mspace width="20px" height="10px" style="background: cyan"></mspace>
      </mfrac>
    </math>
    <math>
      <mfrac id="dynamic-attach">
        <mspace width="20px" height="10px" style="background: blue"></mspace>
        <mspace width="20px" height="10px" style="background: cyan"></mspace>
      </mfrac>
    </math>
    <math>
      <mfrac id="dynamic-modify" linethickness="300%">
        <mspace width="20px" height="10px" style="background: blue"></mspace>
        <mspace width="20px" height="10px" style="background: cyan"></mspace>
      </mfrac>
    </math>
    <math>
      <mfrac id="dynamic-remove" linethickness="300%">
        <mspace width="20px" height="10px" style="background: blue"></mspace>
        <mspace width="20px" height="10px" style="background: cyan"></mspace>
      </mfrac>
    </math>
  </body>
</html>