| 1 |
<!DOCTYPE html> |
| 2 |
<meta charset="utf-8"> |
| 3 |
<title>Test MathML console messages</title> |
| 4 |
<script src="/resources/testharness.js"></script> |
| 5 |
<script src="/resources/testharnessreport.js"></script> |
| 6 |
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=553917"/> |
| 7 |
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=827713"/> |
| 8 |
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1845461"/> |
| 9 |
<body> |
| 10 |
<script> |
| 11 |
const MessageLevel = { |
| 12 |
ERROR: 0, |
| 13 |
WARNING: 1, |
| 14 |
}; |
| 15 |
|
| 16 |
function retrieveConsoleMessagesFor(markup) { |
| 17 |
return new Promise(resolve => { |
| 18 |
const iframe = document.createElement('iframe'); |
| 19 |
iframe.srcdoc = `<!DOCTYPE html> |
| 20 |
<script>let messages = []; |
| 21 |
SpecialPowers.registerConsoleListener(msg => { |
| 22 |
if (msg.message == "SENTINEL") { |
| 23 |
window.parent.postMessage(messages); |
| 24 |
} else if (msg.isScriptError) { |
| 25 |
messages.push(msg); |
| 26 |
} |
| 27 |
}); |
| 28 |
window.addEventListener("load", () => SpecialPowers.postConsoleSentinel()); |
| 29 |
<\/script> |
| 30 |
<body>${markup}</body>`; |
| 31 |
window.addEventListener("message", event => { |
| 32 |
iframe.remove(); |
| 33 |
resolve(event.data); |
| 34 |
}, {once: true}); |
| 35 |
document.body.appendChild(iframe); |
| 36 |
}); |
| 37 |
} |
| 38 |
|
| 39 |
function testMessageForMarkup(markup, regexp, level) { |
| 40 |
promise_test(async function() { |
| 41 |
let messages = await retrieveConsoleMessagesFor(markup); |
| 42 |
|
| 43 |
// Sometimes MathML messages are logged several times, so just |
| 44 |
// ensure there is at least one. |
| 45 |
assert_greater_than_equal(messages.length, 1); |
| 46 |
|
| 47 |
// Compare against the regexp. |
| 48 |
assert_regexp_match(messages[0].errorMessage, regexp); |
| 49 |
|
| 50 |
// Check whether this is a warning or an error. |
| 51 |
assert_equals(messages[0].isWarning, level == MessageLevel.WARNING); |
| 52 |
}, `Message for ${markup}`); |
| 53 |
} |
| 54 |
|
| 55 |
function testNoMessageForMarkup(markup) { |
| 56 |
promise_test(async function() { |
| 57 |
let messages = await retrieveConsoleMessagesFor(markup); |
| 58 |
assert_equals(messages.length, 0); |
| 59 |
}, `No message for ${markup}`); |
| 60 |
} |
| 61 |
|
| 62 |
// ChildCountIncorrect |
| 63 |
[ |
| 64 |
"mroot", |
| 65 |
"msub", |
| 66 |
"msup", |
| 67 |
"mfrac", |
| 68 |
"msubsup", |
| 69 |
"munderover", |
| 70 |
].forEach(tag => { |
| 71 |
testMessageForMarkup( |
| 72 |
`<math><${tag}></${tag}></math>`, |
| 73 |
new RegExp(`Incorrect number of children for <${tag}/>`), |
| 74 |
MessageLevel.ERROR); |
| 75 |
}); |
| 76 |
|
| 77 |
// AttributeParsingError |
| 78 |
[ |
| 79 |
"width", |
| 80 |
"height", |
| 81 |
"voffset", |
| 82 |
].forEach(attribute => { |
| 83 |
testMessageForMarkup( |
| 84 |
`<math><mpadded ${attribute}="BAD!"></mpadded></math>`, |
| 85 |
new RegExp(`Error in parsing the value ‘BAD!’ for ‘${attribute}’ attribute`), |
| 86 |
MessageLevel.ERROR); |
| 87 |
}); |
| 88 |
|
| 89 |
// LengthParsingError |
| 90 |
[ |
| 91 |
'<math><mo rspace="2..0px">+</mo></math>', |
| 92 |
'<math><mo minsize="1.5notaunit">+</mo></math>', |
| 93 |
'<math><mspace width="2"/></math>', |
| 94 |
'<math><mo lspace="BADlspace">+</mo></math>', |
| 95 |
'<math><mspace height="BADheight"/></math>', |
| 96 |
'<math><mspace depth="BADdepth"/></math>', |
| 97 |
'<math><mfrac linethickness="thin"><mn>1</mn><mn>2</mn></mfrac></math>', |
| 98 |
'<math><mfrac linethickness="medium"><mn>1</mn><mn>2</mn></mfrac></math>', |
| 99 |
'<math><mfrac linethickness="thick"><mn>1</mn><mn>2</mn></mfrac></math>', |
| 100 |
'<math><mstyle mathsize="small"></mstyle></math>', |
| 101 |
'<math><mstyle mathsize="normal"></mstyle></math>', |
| 102 |
'<math><mstyle mathsize="big"></mstyle></math>', |
| 103 |
'<math><mspace width="12345."/></math>', |
| 104 |
'<math><mo minsize="17">+</mo></math>', |
| 105 |
].forEach(markup => { |
| 106 |
const value = /="([a-zA-Z0-9.]+)"/.exec(markup)[1]; |
| 107 |
testMessageForMarkup( |
| 108 |
markup, |
| 109 |
new RegExp(`Error in parsing MathML attribute value ‘${value}’`), |
| 110 |
MessageLevel.ERROR); |
| 111 |
}); |
| 112 |
|
| 113 |
// MathML_DeprecatedMathSpaceValueWarning |
| 114 |
[ |
| 115 |
'<math><mspace width="mediummathspace"></mspace></math>', |
| 116 |
'<math><mspace width="negativemediummathspace"></mspace></math>', |
| 117 |
'<math><mspace width="negativethickmathspace"></mspace></math>', |
| 118 |
'<math><mspace width="negativethinmathspace"></mspace></math>', |
| 119 |
'<math><mspace width="negativeverythickmathspace"></mspace></math>', |
| 120 |
'<math><mspace width="negativeverythinmathspace"></mspace></math>', |
| 121 |
'<math><mspace width="negativeveryverythickmathspace"></mspace></math>', |
| 122 |
'<math><mspace width="negativeveryverythinmathspace"></mspace></math>', |
| 123 |
'<math><mspace width="thickmathspace"></mspace></math>', |
| 124 |
'<math><mspace width="thinmathspace"></mspace></math>', |
| 125 |
'<math><mspace width="verythickmathspace"></mspace></math>', |
| 126 |
'<math><mspace width="verythinmathspace"></mspace></math>', |
| 127 |
'<math><mspace width="veryverythickmathspace"></mspace></math>', |
| 128 |
'<math><mspace width="veryverythinmathspace"></mspace></math>', |
| 129 |
].forEach(markup => { |
| 130 |
const value = /="([a-zA-Z0-9.]+)"/.exec(markup)[1]; |
| 131 |
testMessageForMarkup( |
| 132 |
markup, |
| 133 |
new RegExp(`MathML length value “${value}” is deprecated`), |
| 134 |
MessageLevel.WARNING); |
| 135 |
}); |
| 136 |
|
| 137 |
// InvalidChild |
| 138 |
[ |
| 139 |
`<math> |
| 140 |
<msubsup> |
| 141 |
<mprescripts/> |
| 142 |
</msubsup> |
| 143 |
</math>`, |
| 144 |
`<math> |
| 145 |
<msubsup> |
| 146 |
<mprescripts/> |
| 147 |
<mprescripts/> |
| 148 |
</msubsup> |
| 149 |
</math>`, |
| 150 |
`<math> |
| 151 |
<msub> |
| 152 |
<mtext>a</mtext> |
| 153 |
<mprescripts/> |
| 154 |
<mtext>a</mtext> |
| 155 |
<mprescripts/> |
| 156 |
</msub> |
| 157 |
</math>`, |
| 158 |
'<math><msub><mn>0</mn><mprescripts/></msub></math>', |
| 159 |
'<math><msup><mn>0</mn><mprescripts/></msup></math>', |
| 160 |
'<math><msubsup><mn>0</mn><mn>1</mn><mprescripts/></msubsup></math>', |
| 161 |
].forEach(markup => { |
| 162 |
const tag = /<math>\s*<([a-z]+)>/.exec(markup)[1]; |
| 163 |
testMessageForMarkup( |
| 164 |
markup, |
| 165 |
new RegExp(`<mprescripts> is not allowed as a child of <${tag}>`), |
| 166 |
MessageLevel.ERROR); |
| 167 |
}); |
| 168 |
|
| 169 |
// NoBase |
| 170 |
testMessageForMarkup( |
| 171 |
`<math><mmultiscripts></mmultiscripts></math>`, |
| 172 |
/Expected exactly one Base element/, |
| 173 |
MessageLevel.ERROR |
| 174 |
); |
| 175 |
|
| 176 |
// AttributeParsingErrorNoTag |
| 177 |
testMessageForMarkup( |
| 178 |
`<math scriptlevel="BAD!"></math>`, |
| 179 |
/Error in parsing the value ‘BAD!’ for ‘scriptlevel’ attribute/, |
| 180 |
MessageLevel.ERROR |
| 181 |
); |
| 182 |
|
| 183 |
// DuplicateMprescripts |
| 184 |
testMessageForMarkup( |
| 185 |
`<math> |
| 186 |
<mmultiscripts> |
| 187 |
<mprescripts/> |
| 188 |
<mprescripts/> |
| 189 |
</mmultiscripts> |
| 190 |
</math>`, |
| 191 |
/More than one <mprescripts\/>/, |
| 192 |
MessageLevel.ERROR); |
| 193 |
|
| 194 |
// SubSupMismatch |
| 195 |
[ |
| 196 |
`<math> |
| 197 |
<mmultiscripts> |
| 198 |
<mi>x</mi> |
| 199 |
<mi>y</mi> |
| 200 |
</mmultiscripts> |
| 201 |
</math>`, |
| 202 |
`<math> |
| 203 |
<mmultiscripts> |
| 204 |
<mtext>b</mtext> |
| 205 |
<mtext>c</mtext> |
| 206 |
<mprescripts/> |
| 207 |
<mtext>a</mtext> |
| 208 |
</mmultiscripts> |
| 209 |
</math>`, |
| 210 |
].forEach(markup => { |
| 211 |
testMessageForMarkup( |
| 212 |
markup, |
| 213 |
/Incomplete subscript\/superscript pair/, |
| 214 |
MessageLevel.ERROR); |
| 215 |
}); |
| 216 |
|
| 217 |
|
| 218 |
// MathML_DeprecatedMathVariantWarning |
| 219 |
testNoMessageForMarkup('<math><mi mathvariant="normal">A</mi></math>'); |
| 220 |
[ |
| 221 |
"bold", |
| 222 |
"italic", |
| 223 |
"bold-italic", |
| 224 |
"script", |
| 225 |
"bold-script", |
| 226 |
"fraktur", |
| 227 |
"double-struck", |
| 228 |
"bold-fraktur", |
| 229 |
"sans-serif", |
| 230 |
"bold-sans-serif", |
| 231 |
"sans-serif-italic", |
| 232 |
"sans-serif-bold-italic", |
| 233 |
"monospace", |
| 234 |
"initial", |
| 235 |
"tailed", |
| 236 |
"looped", |
| 237 |
"stretched" |
| 238 |
].forEach((value) => { |
| 239 |
testMessageForMarkup( |
| 240 |
`<math><mi mathvariant="${value}">A</mi></math>`, |
| 241 |
new RegExp(`mathvariant='${value}'” .* deprecated`), |
| 242 |
MessageLevel.WARNING); |
| 243 |
}); |
| 244 |
</script> |
| 245 |
</body> |