layout/style/test/test_font_face_parser.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!DOCTYPE HTML><html>
michael@0 2 <!-- https://bugzilla.mozilla.org/show_bug.cgi?id=441469 -->
michael@0 3 <head>
michael@0 4 <meta http-equiv="content-type" content="text/html; charset=utf-8">
michael@0 5 <title>Test of @font-face parser</title>
michael@0 6 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <p>@font-face parsing (<a
michael@0 11 target="_blank"
michael@0 12 href="https://bugzilla.mozilla.org/show_bug.cgi?id=441469"
michael@0 13 >bug 441469</a>)</p>
michael@0 14 <pre id="display"></pre>
michael@0 15 <style type="text/css" id="testbox"></style>
michael@0 16 <script class="testbody" type="text/javascript">
michael@0 17 function _(b) { return "@font-face { " + b + " }"; };
michael@0 18 var testset = [
michael@0 19 // Complete nonsense - shouldn't make a font-face rule at all.
michael@0 20 { rule: "@font-face;" },
michael@0 21 { rule: "font-face { }" },
michael@0 22 { rule: "@fontface { }" },
michael@0 23 { rule: "@namespace foo url(http://example.com/foo);" },
michael@0 24
michael@0 25 // Empty rule.
michael@0 26 { rule: "@font-face { }", d: {} },
michael@0 27 { rule: "@font-face {", d: {} },
michael@0 28 { rule: "@font-face { ; }", d: {}, noncanonical: true },
michael@0 29
michael@0 30 // Correct font-family.
michael@0 31 { rule: _("font-family: \"Mouse\";"), d: {"font-family" : "\"Mouse\""} },
michael@0 32 { rule: _("font-family: \"Mouse\""), d: {"font-family" : "\"Mouse\""},
michael@0 33 noncanonical: true },
michael@0 34 { rule: _("font-family: Mouse;"), d: {"font-family" : "\"Mouse\"" },
michael@0 35 noncanonical: true },
michael@0 36 { rule: _("font-family: Mouse"), d: {"font-family" : "\"Mouse\"" },
michael@0 37 noncanonical: true },
michael@0 38
michael@0 39 // Correct but unusual font-family.
michael@0 40 { rule: _("font-family: Hoefler Text;"),
michael@0 41 d: {"font-family" : "\"Hoefler Text\""},
michael@0 42 noncanonical: true },
michael@0 43
michael@0 44 // Incorrect font-family.
michael@0 45 { rule: _("font-family:"), d: {} },
michael@0 46 { rule: _("font-family \"Mouse\""), d: {} },
michael@0 47 { rule: _("font-family: *"), d: {} },
michael@0 48 { rule: _("font-family: Mouse, Rat"), d: {} },
michael@0 49 { rule: _("font-family: sans-serif"), d: {} },
michael@0 50
michael@0 51 // Correct font-style.
michael@0 52 { rule: _("font-style: normal;"), d: {"font-style" : "normal"} },
michael@0 53 { rule: _("font-style: italic;"), d: {"font-style" : "italic"} },
michael@0 54 { rule: _("font-style: oblique;"), d: {"font-style" : "oblique"} },
michael@0 55
michael@0 56 // Correct font-weight.
michael@0 57 { rule: _("font-weight: 100;"), d: {"font-weight" : "100"} },
michael@0 58 { rule: _("font-weight: 200;"), d: {"font-weight" : "200"} },
michael@0 59 { rule: _("font-weight: 300;"), d: {"font-weight" : "300"} },
michael@0 60 { rule: _("font-weight: 400;"), d: {"font-weight" : "400"} },
michael@0 61 { rule: _("font-weight: 500;"), d: {"font-weight" : "500"} },
michael@0 62 { rule: _("font-weight: 600;"), d: {"font-weight" : "600"} },
michael@0 63 { rule: _("font-weight: 700;"), d: {"font-weight" : "700"} },
michael@0 64 { rule: _("font-weight: 800;"), d: {"font-weight" : "800"} },
michael@0 65 { rule: _("font-weight: 900;"), d: {"font-weight" : "900"} },
michael@0 66 { rule: _("font-weight: normal;"), d: {"font-weight" : "normal"} },
michael@0 67 { rule: _("font-weight: bold;"), d: {"font-weight" : "bold"} },
michael@0 68
michael@0 69 // Incorrect font-weight.
michael@0 70 { rule: _("font-weight: bolder;"), d: {} },
michael@0 71 { rule: _("font-weight: lighter;"), d: {} },
michael@0 72
michael@0 73 // Correct font-stretch.
michael@0 74 { rule: _("font-stretch: ultra-condensed;"),
michael@0 75 d: {"font-stretch" : "ultra-condensed"} },
michael@0 76 { rule: _("font-stretch: extra-condensed;"),
michael@0 77 d: {"font-stretch" : "extra-condensed"} },
michael@0 78 { rule: _("font-stretch: condensed;"),
michael@0 79 d: {"font-stretch" : "condensed"} },
michael@0 80 { rule: _("font-stretch: semi-condensed;"),
michael@0 81 d: {"font-stretch" : "semi-condensed"} },
michael@0 82 { rule: _("font-stretch: normal;"),
michael@0 83 d: {"font-stretch" : "normal"} },
michael@0 84 { rule: _("font-stretch: semi-expanded;"),
michael@0 85 d: {"font-stretch" : "semi-expanded"} },
michael@0 86 { rule: _("font-stretch: expanded;"),
michael@0 87 d: {"font-stretch" : "expanded"} },
michael@0 88 { rule: _("font-stretch: extra-expanded;"),
michael@0 89 d: {"font-stretch" : "extra-expanded"} },
michael@0 90 { rule: _("font-stretch: ultra-expanded;"),
michael@0 91 d: {"font-stretch" : "ultra-expanded"} },
michael@0 92
michael@0 93 // Incorrect font-stretch.
michael@0 94 { rule: _("font-stretch: wider;"), d: {} },
michael@0 95 { rule: _("font-stretch: narrower;"), d: {} },
michael@0 96
michael@0 97 // Correct src:
michael@0 98 { rule: _("src: url(\"/fonts/Mouse\");"),
michael@0 99 d: { "src" : "url(\"/fonts/Mouse\")" } },
michael@0 100 { rule: _("src: url(/fonts/Mouse);"),
michael@0 101 d: { "src" : "url(\"/fonts/Mouse\")" }, noncanonical: true },
michael@0 102
michael@0 103 { rule: _("src: url(\"/fonts/Mouse\") format(\"truetype\");"),
michael@0 104 d: { "src" : "url(\"/fonts/Mouse\") format(\"truetype\")" } },
michael@0 105 { rule: _("src: url(\"/fonts/Mouse\") format(\"truetype\", \"opentype\");"),
michael@0 106 d: { "src" : "url(\"/fonts/Mouse\") format(\"truetype\", \"opentype\")" } },
michael@0 107
michael@0 108 { rule: _("src: url(\"/fonts/Mouse\"), url(\"/fonts/Rat\");"),
michael@0 109 d: { "src" : "url(\"/fonts/Mouse\"), url(\"/fonts/Rat\")" } },
michael@0 110
michael@0 111 { rule: _("src: local(Mouse), url(\"/fonts/Mouse\");"),
michael@0 112 d: { "src" : "local(\"Mouse\"), url(\"/fonts/Mouse\")" },
michael@0 113 noncanonical: true },
michael@0 114
michael@0 115 { rule: _("src: local(\"老鼠\"), url(\"/fonts/Mouse\");"),
michael@0 116 d: { "src" : "local(\"老鼠\"), url(\"/fonts/Mouse\")" } },
michael@0 117
michael@0 118 { rule: _("src: local(\"老鼠\"), url(\"/fonts/Mouse\") format(\"truetype\");"),
michael@0 119 d: { "src" : "local(\"老鼠\"), url(\"/fonts/Mouse\") format(\"truetype\")" } },
michael@0 120
michael@0 121 // Correct but unusual src:
michael@0 122 { rule: _("src: local(Hoefler Text);"),
michael@0 123 d: {"src" : "local(\"Hoefler Text\")"}, noncanonical: true },
michael@0 124
michael@0 125 // Incorrect src:
michael@0 126 { rule: _("src:"), d: {} },
michael@0 127 { rule: _("src: \"/fonts/Mouse\";"), d: {} },
michael@0 128 { rule: _("src: /fonts/Mouse;"), d: {} },
michael@0 129 { rule: _("src: url(\"/fonts/Mouse\") format(truetype);"), d: {} },
michael@0 130 { rule: _("src: url(\"/fonts/Mouse\") format(\"truetype\",opentype);"), d: {} },
michael@0 131 { rule: _("src: local(*);"), d: {} },
michael@0 132 { rule: _("src: format(\"truetype\");"), d: {} },
michael@0 133 { rule: _("src: local(Mouse) format(\"truetype\");"), d: {} },
michael@0 134 { rule: _("src: local(Mouse, Rat);"), d: {} },
michael@0 135 { rule: _("src: local(sans-serif);"), d: {} },
michael@0 136
michael@0 137 // Repeated descriptors
michael@0 138 { rule: _("font-weight: 700; font-weight: 200;"),
michael@0 139 d: {"font-weight" : "200"},
michael@0 140 noncanonical: true },
michael@0 141 { rule: _("src: url(\"/fonts/Cat\"); src: url(\"/fonts/Mouse\");"),
michael@0 142 d: { "src" : "url(\"/fonts/Mouse\")" },
michael@0 143 noncanonical: true },
michael@0 144 { rule: _("src: local(Cat); src: local(Mouse)"),
michael@0 145 d: { "src" : "local(\"Mouse\")" },
michael@0 146 noncanonical: true },
michael@0 147
michael@0 148 // Correct parenthesis matching for local()
michael@0 149 { rule: _("src: local(Mouse); src: local(Cat(); src: local(Rat); )"),
michael@0 150 d: { "src" : "local(\"Mouse\")" },
michael@0 151 noncanonical: true },
michael@0 152 { rule: _("src: local(Mouse); src: local(\"Cat\"; src: local(Rat); )"),
michael@0 153 d: { "src" : "local(\"Mouse\")" },
michael@0 154 noncanonical: true },
michael@0 155
michael@0 156 // Correct parenthesis matching for format()
michael@0 157 { rule: _("src: url(\"/fonts/Mouse\"); " +
michael@0 158 "src: url(\"/fonts/Cat\") format(Cat(); src: local(Rat); )"),
michael@0 159 d: { "src" : "url(\"/fonts/Mouse\")" },
michael@0 160 noncanonical: true },
michael@0 161 { rule: _("src: url(\"/fonts/Mouse\"); " +
michael@0 162 "src: url(\"/fonts/Cat\") format(\"Cat\"; src: local(Rat); )"),
michael@0 163 d: { "src" : "url(\"/fonts/Mouse\")" },
michael@0 164 noncanonical: true },
michael@0 165 { rule: _("src: url(\"/fonts/Mouse\"); " +
michael@0 166 "src: url(\"/fonts/Cat\") format((); src: local(Rat); )"),
michael@0 167 d: { "src" : "url(\"/fonts/Mouse\")" },
michael@0 168 noncanonical: true },
michael@0 169
michael@0 170 // Correct unicode-range:
michael@0 171 { rule: _("unicode-range: U+00A5;"), d: { "unicode-range" : "U+00A5" } },
michael@0 172 { rule: _("unicode-range: U+A5;"),
michael@0 173 d: { "unicode-range" : "U+00A5" }, noncanonical: true },
michael@0 174 { rule: _("unicode-range: U+00a5;"),
michael@0 175 d: { "unicode-range" : "U+00A5" }, noncanonical: true },
michael@0 176 { rule: _("unicode-range: u+00a5;"),
michael@0 177 d: { "unicode-range" : "U+00A5" }, noncanonical: true },
michael@0 178 { rule: _("unicode-range: U+0000-00FF;"),
michael@0 179 d: { "unicode-range" : "U+0000-00FF" } },
michael@0 180 { rule: _("unicode-range: U+00??;"),
michael@0 181 d: { "unicode-range" : "U+0000-00FF" }, noncanonical: true },
michael@0 182 { rule: _("unicode-range: U+?"),
michael@0 183 d: { "unicode-range" : "U+0000-000F" }, noncanonical: true },
michael@0 184 { rule: _("unicode-range: U+??????"),
michael@0 185 d: { "unicode-range" : "U+0000-10FFFF" }, noncanonical: true },
michael@0 186 { rule: _("unicode-range: U+590-5ff;"),
michael@0 187 d: { "unicode-range" : "U+0590-05FF" }, noncanonical: true },
michael@0 188 { rule: _("unicode-range: U+A0000-12FFFF"),
michael@0 189 d: { "unicode-range" : "U+A0000-10FFFF" }, noncanonical: true },
michael@0 190
michael@0 191 { rule: _("unicode-range: U+A5, U+4E00-9FFF, U+30??, U+FF00-FF9F;"),
michael@0 192 d: { "unicode-range" : "U+00A5, U+4E00-9FFF, U+3000-30FF, U+FF00-FF9F" },
michael@0 193 noncanonical: true },
michael@0 194
michael@0 195 { rule: _("unicode-range: U+104??;"),
michael@0 196 d: { "unicode-range" : "U+10400-104FF" }, noncanonical: true },
michael@0 197 { rule: _("unicode-range: U+320??, U+321??, U+322??, U+323??, U+324??, U+325??;"),
michael@0 198 d: { "unicode-range" : "U+32000-320FF, U+32100-321FF, U+32200-322FF, U+32300-323FF, U+32400-324FF, U+32500-325FF" },
michael@0 199 noncanonical: true },
michael@0 200 { rule: _("unicode-range: U+100000-10ABCD;"),
michael@0 201 d: { "unicode-range" : "U+100000-10ABCD" } },
michael@0 202 { rule: _("unicode-range: U+0121 , U+1023"),
michael@0 203 d: { "unicode-range" : "U+0121, U+1023" }, noncanonical: true },
michael@0 204 { rule: _("unicode-range: U+0121/**/, U+1023"),
michael@0 205 d: { "unicode-range" : "U+0121, U+1023" }, noncanonical: true },
michael@0 206
michael@0 207 // Incorrect unicode-range:
michael@0 208 { rule: _("unicode-range:"), d: {} },
michael@0 209 { rule: _("unicode-range: U+"), d: {} },
michael@0 210 { rule: _("unicode-range: U+8FFFFFFF"), d: {} },
michael@0 211 { rule: _("unicode-range: U+8FFF-7000"), d: {} },
michael@0 212 { rule: _("unicode-range: U+8F??-9000"), d: {} },
michael@0 213 { rule: _("unicode-range: U+9000-9???"), d: {} },
michael@0 214 { rule: _("unicode-range: U+??00"), d: {} },
michael@0 215 { rule: _("unicode-range: U+12345678?"), d: {} },
michael@0 216 { rule: _("unicode-range: U+1????????"), d: {} },
michael@0 217 { rule: _("unicode-range: twelve"), d: {} },
michael@0 218 { rule: _("unicode-range: 1000"), d: {} },
michael@0 219 { rule: _("unicode-range: 13??"), d: {} },
michael@0 220 { rule: _("unicode-range: 1300-1377"), d: {} },
michael@0 221 { rule: _("unicode-range: U-1000"), d: {} },
michael@0 222 { rule: _("unicode-range: U+nnnn"), d: {} },
michael@0 223 { rule: _("unicode-range: U+0121 U+1023"), d: {} },
michael@0 224 { rule: _("unicode-range: U+ 0121"), d: {} },
michael@0 225 { rule: _("unicode-range: U +0121"), d: {} },
michael@0 226 { rule: _("unicode-range: U+0121-"), d: {} },
michael@0 227 { rule: _("unicode-range: U+0121- 1023"), d: {} },
michael@0 228 { rule: _("unicode-range: U+0121 -1023"), d: {} },
michael@0 229 { rule: _("unicode-range: U+012 ?"), d: {} },
michael@0 230 { rule: _("unicode-range: U+01 2?"), d: {} },
michael@0 231
michael@0 232 // Thorough test of seven-digit rejection: all these are syntax errors
michael@0 233 { rule: _("unicode-range: U+1034560, U+A5"), d: {} },
michael@0 234 { rule: _("unicode-range: U+1034569, U+A5"), d: {} },
michael@0 235 { rule: _("unicode-range: U+103456a, U+A5"), d: {} },
michael@0 236 { rule: _("unicode-range: U+103456f, U+A5"), d: {} },
michael@0 237 { rule: _("unicode-range: U+103456?, U+A5"), d: {} },
michael@0 238 { rule: _("unicode-range: U+103456-1034560, U+A5"), d: {} },
michael@0 239 { rule: _("unicode-range: U+103456-1034569, U+A5"), d: {} },
michael@0 240 { rule: _("unicode-range: U+103456-103456a, U+A5"), d: {} },
michael@0 241 { rule: _("unicode-range: U+103456-103456f, U+A5"), d: {} },
michael@0 242
michael@0 243 // Syntactically invalid unicode-range tokens invalidate the
michael@0 244 // entire descriptor
michael@0 245 { rule: _("unicode-range: U+1, U+2, U+X"), d: {} },
michael@0 246 { rule: _("unicode-range: U+A5, U+0?F"), d: {} },
michael@0 247 { rule: _("unicode-range: U+A5, U+0F?-E00"), d: {} },
michael@0 248
michael@0 249 // Descending ranges and ranges outside 0-10FFFF are ignored
michael@0 250 // but do not invalidate the descriptor
michael@0 251 { rule: _("unicode-range: U+A5, U+90-30"),
michael@0 252 d: { "unicode-range" : "U+00A5" }, noncanonical: true },
michael@0 253 { rule: _("unicode-range: U+A5, U+220043"),
michael@0 254 d: { "unicode-range" : "U+00A5" }, noncanonical: true },
michael@0 255
michael@0 256 // -moz-font-feature-settings
michael@0 257 { rule: _("-moz-font-feature-settings: normal;"),
michael@0 258 d: { "-moz-font-feature-settings" : "normal" } },
michael@0 259 { rule: _("-moz-font-feature-settings: \"dlig\";"),
michael@0 260 d: { "-moz-font-feature-settings" : "\"dlig\"" } },
michael@0 261 { rule: _("-moz-font-feature-settings: \"dlig\" 1;"),
michael@0 262 d: { "-moz-font-feature-settings" : "\"dlig\"" }, noncanonical: true },
michael@0 263 { rule: _("-moz-font-feature-settings: 'dlig' 1"),
michael@0 264 d: { "-moz-font-feature-settings" : "\"dlig\"" }, noncanonical: true },
michael@0 265
michael@0 266 // incorrect -moz-font-feature-settings
michael@0 267 { rule: _("-moz-font-feature-settings: dlig 1"), d: {} },
michael@0 268 { rule: _("-moz-font-feature-settings: none;"), d: {} },
michael@0 269 { rule: _("-moz-font-feature-settings: 0;"), d: {} },
michael@0 270 { rule: _("-moz-font-feature-settings: 3.14;"), d: {} },
michael@0 271 { rule: _("-moz-font-feature-settings: 'blah' 3.14;"), d: {} },
michael@0 272 { rule: _("-moz-font-feature-settings: 'dlig' 1 'hist' 0;"), d: {} },
michael@0 273 { rule: _("-moz-font-feature-settings: 'dlig=1,hist=1'"), d: {} },
michael@0 274
michael@0 275 // -moz-font-language-override:
michael@0 276 { rule: _("-moz-font-language-override: normal;"),
michael@0 277 d: { "-moz-font-language-override" : "normal" } },
michael@0 278 { rule: _("-moz-font-language-override: \"TRK\";"),
michael@0 279 d: { "-moz-font-language-override" : "\"TRK\"" } },
michael@0 280 { rule: _("-moz-font-language-override: 'TRK'"),
michael@0 281 d: { "-moz-font-language-override" : "\"TRK\"" }, noncanonical: true },
michael@0 282
michael@0 283 // incorrect -moz-font-language-override
michael@0 284 { rule: _("-moz-font-language-override: TRK"), d: {} },
michael@0 285 { rule: _("-moz-font-language-override: none;"), d: {} },
michael@0 286 { rule: _("-moz-font-language-override: 0;"), d: {} },
michael@0 287 { rule: _("-moz-font-language-override: #999;"), d: {} },
michael@0 288 { rule: _("-moz-font-language-override: 'TRK' 'SRB'"), d: {} },
michael@0 289 { rule: _("-moz-font-language-override: 'TRK', 'SRB'"), d: {} },
michael@0 290 ];
michael@0 291
michael@0 292 var display = document.getElementById("display");
michael@0 293 var sheet = document.styleSheets[1];
michael@0 294
michael@0 295 for (var curTest = 0; curTest < testset.length; curTest++) {
michael@0 296 try {
michael@0 297 while(sheet.cssRules.length > 0)
michael@0 298 sheet.deleteRule(0);
michael@0 299 sheet.insertRule(testset[curTest].rule, 0);
michael@0 300 } catch (e) {
michael@0 301 ok(e.name == "SyntaxError"
michael@0 302 && e instanceof DOMException
michael@0 303 && e.code == DOMException.SYNTAX_ERR
michael@0 304 && !('d' in testset[curTest]),
michael@0 305 testset[curTest].rule + " syntax error thrown", e);
michael@0 306 }
michael@0 307
michael@0 308 try {
michael@0 309 if (testset[curTest].d) {
michael@0 310 is(sheet.cssRules.length, 1,
michael@0 311 testset[curTest].rule + " rule count");
michael@0 312 is(sheet.cssRules[0].type, 5 /*FONT_FACE_RULE*/,
michael@0 313 testset[curTest].rule + " rule type");
michael@0 314
michael@0 315 var d = testset[curTest].d;
michael@0 316 var s = sheet.cssRules[0].style;
michael@0 317 var n = 0;
michael@0 318
michael@0 319 // everything is set that should be
michael@0 320 for (var name in d) {
michael@0 321 is(s.getPropertyValue(name), d[name],
michael@0 322 testset[curTest].rule + " (prop " + name + ")");
michael@0 323 n++;
michael@0 324 }
michael@0 325 // nothing else is set
michael@0 326 is(s.length, n, testset[curTest].rule + "prop count");
michael@0 327 for (var i = 0; i < s.length; i++) {
michael@0 328 ok(s[i] in d, testset[curTest].rule,
michael@0 329 "Unexpected item #" + i + ": " + s[i]);
michael@0 330 }
michael@0 331
michael@0 332 // round-tripping of cssText
michael@0 333 // this is a strong test; it's okay if the exact serialization
michael@0 334 // changes in the future
michael@0 335 if (n && !testset[curTest].noncanonical) {
michael@0 336 is(sheet.cssRules[0].cssText.replace(/[ \n]+/g, " "),
michael@0 337 testset[curTest].rule,
michael@0 338 testset[curTest].rule + " rule text");
michael@0 339 }
michael@0 340 } else {
michael@0 341 if (sheet.cssRules.length == 0) {
michael@0 342 is(sheet.cssRules.length, 0,
michael@0 343 testset[curTest].rule + " rule count (0)");
michael@0 344 } else {
michael@0 345 is(sheet.cssRules.length, 1,
michael@0 346 testset[curTest].rule + " rule count (1 non-fontface)");
michael@0 347 isnot(sheet.cssRules[0].type, 5 /*FONT_FACE_RULE*/,
michael@0 348 testset[curTest].rule + " rule type (1 non-fontface)");
michael@0 349 }
michael@0 350 }
michael@0 351 } catch (e) {
michael@0 352 ok(false, testset[curTest].rule, "During test: " + e);
michael@0 353 }
michael@0 354 }
michael@0 355 </script>
michael@0 356 </body>
michael@0 357 </html>

mercurial