summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/mathml/mathml-console-messages.html
blob: 183d11feaa362af5dba47d947abad09c82a0319b (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test MathML console messages</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=553917"/>
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=827713"/>
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1845461"/>
<body>
  <script>
    const MessageLevel = {
        ERROR: 0,
        WARNING: 1,
    };

    function retrieveConsoleMessagesFor(markup) {
        return new Promise(resolve => {
            const iframe = document.createElement('iframe');
            iframe.srcdoc = `<!DOCTYPE html>
<script>let messages = [];
  SpecialPowers.registerConsoleListener(msg => {
    if (msg.message == "SENTINEL") {
      window.parent.postMessage(messages);
    } else if (msg.isScriptError) {
      messages.push(msg);
    }
  });
  window.addEventListener("load", () => SpecialPowers.postConsoleSentinel());
<\/script>
<body>${markup}</body>`;
            window.addEventListener("message", event => {
                iframe.remove();
                resolve(event.data);
            }, {once: true});
            document.body.appendChild(iframe);
        });
    }

    function testMessageForMarkup(markup, regexp, level) {
        promise_test(async function() {
            let messages = await retrieveConsoleMessagesFor(markup);

            // Sometimes MathML messages are logged several times, so just
            // ensure there is at least one.
            assert_greater_than_equal(messages.length, 1);

            // Compare against the regexp.
            assert_regexp_match(messages[0].errorMessage, regexp);

            // Check whether this is a warning or an error.
            assert_equals(messages[0].isWarning, level == MessageLevel.WARNING);
        }, `Message for ${markup}`);
    }

    function testNoMessageForMarkup(markup) {
        promise_test(async function() {
            let messages = await retrieveConsoleMessagesFor(markup);
            assert_equals(messages.length, 0);
        }, `No message for ${markup}`);
    }

    // ChildCountIncorrect
    [
        "mroot",
        "msub",
        "msup",
        "mfrac",
        "msubsup",
        "munderover",
    ].forEach(tag => {
        testMessageForMarkup(
            `<math><${tag}></${tag}></math>`,
            new RegExp(`Incorrect number of children for <${tag}/>`),
            MessageLevel.ERROR);
    });

    // AttributeParsingError
    [
        "width",
        "height",
        "voffset",
    ].forEach(attribute => {
        testMessageForMarkup(
            `<math><mpadded ${attribute}="BAD!"></mpadded></math>`,
            new RegExp(`Error in parsing the value ‘BAD!’ for ‘${attribute}’ attribute`),
            MessageLevel.ERROR);
    });

    // LengthParsingError
    [
        '<math><mo rspace="2..0px">+</mo></math>',
        '<math><mo minsize="1.5notaunit">+</mo></math>',
        '<math><mspace width="2"/></math>',
        '<math><mo lspace="BADlspace">+</mo></math>',
        '<math><mspace height="BADheight"/></math>',
        '<math><mspace depth="BADdepth"/></math>',
        '<math><mfrac linethickness="thin"><mn>1</mn><mn>2</mn></mfrac></math>',
        '<math><mfrac linethickness="medium"><mn>1</mn><mn>2</mn></mfrac></math>',
        '<math><mfrac linethickness="thick"><mn>1</mn><mn>2</mn></mfrac></math>',
        '<math><mstyle mathsize="small"></mstyle></math>',
        '<math><mstyle mathsize="normal"></mstyle></math>',
        '<math><mstyle mathsize="big"></mstyle></math>',
        '<math><mspace width="12345."/></math>',
        '<math><mo minsize="17">+</mo></math>',
    ].forEach(markup => {
        const value = /="([a-zA-Z0-9.]+)"/.exec(markup)[1];
        testMessageForMarkup(
            markup,
            new RegExp(`Error in parsing MathML attribute value ‘${value}’`),
            MessageLevel.ERROR);
    });

    // MathML_DeprecatedMathSpaceValueWarning
    [
        '<math><mspace width="mediummathspace"></mspace></math>',
        '<math><mspace width="negativemediummathspace"></mspace></math>',
        '<math><mspace width="negativethickmathspace"></mspace></math>',
        '<math><mspace width="negativethinmathspace"></mspace></math>',
        '<math><mspace width="negativeverythickmathspace"></mspace></math>',
        '<math><mspace width="negativeverythinmathspace"></mspace></math>',
        '<math><mspace width="negativeveryverythickmathspace"></mspace></math>',
        '<math><mspace width="negativeveryverythinmathspace"></mspace></math>',
        '<math><mspace width="thickmathspace"></mspace></math>',
        '<math><mspace width="thinmathspace"></mspace></math>',
        '<math><mspace width="verythickmathspace"></mspace></math>',
        '<math><mspace width="verythinmathspace"></mspace></math>',
        '<math><mspace width="veryverythickmathspace"></mspace></math>',
        '<math><mspace width="veryverythinmathspace"></mspace></math>',
    ].forEach(markup => {
        const value = /="([a-zA-Z0-9.]+)"/.exec(markup)[1];
        testMessageForMarkup(
            markup,
            new RegExp(`MathML length value “${value}” is deprecated`),
            MessageLevel.WARNING);
    });

    // InvalidChild
    [
        `<math>
          <msubsup>
            <mprescripts/>
          </msubsup>
         </math>`,
        `<math>
           <msubsup>
             <mprescripts/>
             <mprescripts/>
           </msubsup>
         </math>`,
        `<math>
           <msub>
           <mtext>a</mtext>
             <mprescripts/>
             <mtext>a</mtext>
           <mprescripts/>
           </msub>
         </math>`,
        '<math><msub><mn>0</mn><mprescripts/></msub></math>',
        '<math><msup><mn>0</mn><mprescripts/></msup></math>',
        '<math><msubsup><mn>0</mn><mn>1</mn><mprescripts/></msubsup></math>',
    ].forEach(markup => {
        const tag = /<math>\s*<([a-z]+)>/.exec(markup)[1];
        testMessageForMarkup(
            markup,
            new RegExp(`<mprescripts> is not allowed as a child of <${tag}>`),
            MessageLevel.ERROR);
    });

    // NoBase
    testMessageForMarkup(
        `<math><mmultiscripts></mmultiscripts></math>`,
        /Expected exactly one Base element/,
        MessageLevel.ERROR
    );

    // AttributeParsingErrorNoTag
    testMessageForMarkup(
        `<math scriptlevel="BAD!"></math>`,
        /Error in parsing the value ‘BAD!’ for ‘scriptlevel’ attribute/,
        MessageLevel.ERROR
    );

    // DuplicateMprescripts
    testMessageForMarkup(
        `<math>
           <mmultiscripts>
             <mprescripts/>
             <mprescripts/>
           </mmultiscripts>
         </math>`,
        /More than one <mprescripts\/>/,
        MessageLevel.ERROR);

    // SubSupMismatch
    [
        `<math>
           <mmultiscripts>
             <mi>x</mi>
             <mi>y</mi>
           </mmultiscripts>
          </math>`,
        `<math>
           <mmultiscripts>
             <mtext>b</mtext>
             <mtext>c</mtext>
             <mprescripts/>
            <mtext>a</mtext>
           </mmultiscripts>
         </math>`,
    ].forEach(markup => {
        testMessageForMarkup(
            markup,
            /Incomplete subscript\/superscript pair/,
            MessageLevel.ERROR);
    });


    // MathML_DeprecatedMathVariantWarning
    testNoMessageForMarkup('<math><mi mathvariant="normal">A</mi></math>');
    [
        "bold",
        "italic",
        "bold-italic",
        "script",
        "bold-script",
        "fraktur",
        "double-struck",
        "bold-fraktur",
        "sans-serif",
        "bold-sans-serif",
        "sans-serif-italic",
        "sans-serif-bold-italic",
        "monospace",
        "initial",
        "tailed",
        "looped",
        "stretched"
    ].forEach((value) => {
        testMessageForMarkup(
            `<math><mi mathvariant="${value}">A</mi></math>`,
            new RegExp(`mathvariant='${value}'” .* deprecated`),
            MessageLevel.WARNING);
    });
  </script>
</body>