Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset=utf-8> |
michael@0 | 5 | <title>Font family name parsing tests</title> |
michael@0 | 6 | <link rel="author" title="John Daggett" href="mailto:jdaggett@mozilla.com"> |
michael@0 | 7 | <link rel="help" href="http://www.w3.org/TR/css3-fonts/#font-family-prop" /> |
michael@0 | 8 | <link rel="help" href="http://www.w3.org/TR/css3-fonts/#font-prop" /> |
michael@0 | 9 | <meta name="assert" content="tests that valid font family names parse and invalid ones don't" /> |
michael@0 | 10 | <script type="text/javascript" src="/resources/testharness.js"></script> |
michael@0 | 11 | <script type="text/javascript" src="/resources/testharnessreport.js"></script> |
michael@0 | 12 | <style type="text/css"> |
michael@0 | 13 | </style> |
michael@0 | 14 | </head> |
michael@0 | 15 | <body> |
michael@0 | 16 | <div id="log"></div> |
michael@0 | 17 | <pre id="display"></pre> |
michael@0 | 18 | <style type="text/css" id="testbox"></style> |
michael@0 | 19 | |
michael@0 | 20 | <script type="text/javascript"> |
michael@0 | 21 | |
michael@0 | 22 | function fontProp(n, size, s1, s2) { return (s1 ? s1 + " " : "") + (s2 ? s2 + " " : "") + size + " " + n; } |
michael@0 | 23 | function font(n, size, s1, s2) { return "font: " + fontProp(n, size, s1, s2); } |
michael@0 | 24 | |
michael@0 | 25 | // testrules |
michael@0 | 26 | // namelist - font family list |
michael@0 | 27 | // invalid - true if declarations won't parse in either font-family or font |
michael@0 | 28 | // fontonly - only test with the 'font' property |
michael@0 | 29 | // single - namelist includes only a single name (@font-face rules only allow a single name) |
michael@0 | 30 | |
michael@0 | 31 | var testFontFamilyLists = [ |
michael@0 | 32 | |
michael@0 | 33 | /* basic syntax */ |
michael@0 | 34 | { namelist: "simple", single: true }, |
michael@0 | 35 | { namelist: "'simple'", single: true }, |
michael@0 | 36 | { namelist: '"simple"', single: true }, |
michael@0 | 37 | { namelist: "-simple", single: true }, |
michael@0 | 38 | { namelist: "_simple", single: true }, |
michael@0 | 39 | { namelist: "quite simple", single: true }, |
michael@0 | 40 | { namelist: "quite _simple", single: true }, |
michael@0 | 41 | { namelist: "quite -simple", single: true }, |
michael@0 | 42 | { namelist: "0simple", invalid: true, single: true }, |
michael@0 | 43 | { namelist: "simple!", invalid: true, single: true }, |
michael@0 | 44 | { namelist: "simple()", invalid: true, single: true }, |
michael@0 | 45 | { namelist: "quite@simple", invalid: true, single: true }, |
michael@0 | 46 | { namelist: "#simple", invalid: true, single: true }, |
michael@0 | 47 | { namelist: "quite 0simple", invalid: true, single: true }, |
michael@0 | 48 | { namelist: "納豆嫌い", single: true }, |
michael@0 | 49 | { namelist: "納豆嫌い, ick, patooey" }, |
michael@0 | 50 | { namelist: "ick, patooey, 納豆嫌い" }, |
michael@0 | 51 | { namelist: "納豆嫌い, 納豆大嫌い" }, |
michael@0 | 52 | { namelist: "納豆嫌い, 納豆大嫌い, 納豆本当に嫌い" }, |
michael@0 | 53 | { namelist: "納豆嫌い, 納豆大嫌い, 納豆本当に嫌い, 納豆は好みではない" }, |
michael@0 | 54 | { namelist: "arial, helvetica, sans-serif" }, |
michael@0 | 55 | { namelist: "arial, helvetica, 'times' new roman, sans-serif", invalid: true }, |
michael@0 | 56 | { namelist: "arial, helvetica, \"times\" new roman, sans-serif", invalid: true }, |
michael@0 | 57 | |
michael@0 | 58 | // bug 660397 - quotes contained within family names are not escaped |
michael@0 | 59 | // { namelist: "arial, helvetica, \"\\\"times new roman\", sans-serif" }, |
michael@0 | 60 | { namelist: "arial, helvetica, '\\\"times new roman', sans-serif" }, |
michael@0 | 61 | { namelist: "arial, helvetica, times 'new' roman, sans-serif", invalid: true }, |
michael@0 | 62 | { namelist: "arial, helvetica, times \"new\" roman, sans-serif", invalid: true }, |
michael@0 | 63 | // { namelist: "\"simple", invalid: true, single: true }, |
michael@0 | 64 | // { namelist: "\\\"simple", single: true }, |
michael@0 | 65 | // { namelist: "\"\\\"simple\"", single: true }, |
michael@0 | 66 | { namelist: "İsimple", single: true }, |
michael@0 | 67 | { namelist: "ßsimple", single: true }, |
michael@0 | 68 | { namelist: "ẙsimple", single: true }, |
michael@0 | 69 | |
michael@0 | 70 | /* escapes */ |
michael@0 | 71 | { namelist: "\\s imple", single: true }, |
michael@0 | 72 | { namelist: "\\073 imple", single: true }, |
michael@0 | 73 | |
michael@0 | 74 | // bug 475216 - css serialization doesn't escape characters that need escaping |
michael@0 | 75 | // { namelist: "\\035 simple", single: true }, |
michael@0 | 76 | { namelist: "sim\\035 ple", single: true }, |
michael@0 | 77 | // { namelist: "simple\\02cinitial", single: true }, |
michael@0 | 78 | // { namelist: "simple, \\02cinitial" }, |
michael@0 | 79 | // { namelist: "sim\\020 \\035 ple", single: true }, |
michael@0 | 80 | // { namelist: "sim\\020 5ple", single: true }, |
michael@0 | 81 | // { namelist: "\\;", single: true }, |
michael@0 | 82 | // { namelist: "\\;,\\;", single: true }, |
michael@0 | 83 | // { namelist: "\\,\\;", single: true }, |
michael@0 | 84 | // { namelist: "\\{", single: true }, |
michael@0 | 85 | // { namelist: "\\{\\;", single: true }, |
michael@0 | 86 | // { namelist: "\\}", single: true }, |
michael@0 | 87 | // { namelist: "\\}\\;", single: true }, |
michael@0 | 88 | // { namelist: "\\@simple", single: true }, |
michael@0 | 89 | // { namelist: "\\@simple\\;", single: true }, |
michael@0 | 90 | // { namelist: "\\@font-face", single: true }, |
michael@0 | 91 | // { namelist: "\\@font-face\\;", single: true }, |
michael@0 | 92 | // { namelist: "\\031 \\036 px", single: true }, |
michael@0 | 93 | // { namelist: "\\031 \\036 px", single: true }, |
michael@0 | 94 | { namelist: "\\1f4a9", single: true }, |
michael@0 | 95 | { namelist: "\\01f4a9", single: true }, |
michael@0 | 96 | { namelist: "\\0001f4a9", single: true }, |
michael@0 | 97 | { namelist: "\\AbAb", single: true }, |
michael@0 | 98 | |
michael@0 | 99 | /* keywords */ |
michael@0 | 100 | { namelist: "italic", single: true }, |
michael@0 | 101 | { namelist: "bold", single: true }, |
michael@0 | 102 | { namelist: "bold italic", single: true }, |
michael@0 | 103 | { namelist: "italic bold", single: true }, |
michael@0 | 104 | { namelist: "larger", single: true }, |
michael@0 | 105 | { namelist: "smaller", single: true }, |
michael@0 | 106 | { namelist: "bolder", single: true }, |
michael@0 | 107 | { namelist: "lighter", single: true }, |
michael@0 | 108 | { namelist: "default", invalid: true, fontonly: true, single: true }, |
michael@0 | 109 | { namelist: "initial", invalid: true, fontonly: true, single: true }, |
michael@0 | 110 | { namelist: "inherit", invalid: true, fontonly: true, single: true }, |
michael@0 | 111 | { namelist: "normal", single: true }, |
michael@0 | 112 | { namelist: "default, simple", invalid: true }, |
michael@0 | 113 | { namelist: "initial, simple", invalid: true }, |
michael@0 | 114 | { namelist: "inherit, simple", invalid: true }, |
michael@0 | 115 | { namelist: "normal, simple" }, |
michael@0 | 116 | { namelist: "simple, default", invalid: true }, |
michael@0 | 117 | { namelist: "simple, initial", invalid: true }, |
michael@0 | 118 | { namelist: "simple, inherit", invalid: true }, |
michael@0 | 119 | { namelist: "simple, default bongo" }, |
michael@0 | 120 | { namelist: "simple, initial bongo" }, |
michael@0 | 121 | { namelist: "simple, inherit bongo" }, |
michael@0 | 122 | { namelist: "simple, bongo default" }, |
michael@0 | 123 | { namelist: "simple, bongo initial" }, |
michael@0 | 124 | { namelist: "simple, bongo inherit" }, |
michael@0 | 125 | { namelist: "simple, normal" }, |
michael@0 | 126 | { namelist: "simple default", single: true }, |
michael@0 | 127 | { namelist: "simple initial", single: true }, |
michael@0 | 128 | { namelist: "simple inherit", single: true }, |
michael@0 | 129 | { namelist: "simple normal", single: true }, |
michael@0 | 130 | { namelist: "default simple", single: true }, |
michael@0 | 131 | { namelist: "initial simple", single: true }, |
michael@0 | 132 | { namelist: "inherit simple", single: true }, |
michael@0 | 133 | { namelist: "normal simple", single: true }, |
michael@0 | 134 | { namelist: "caption", single: true }, // these are keywords for the 'font' property but only when in the first position |
michael@0 | 135 | { namelist: "icon", single: true }, |
michael@0 | 136 | { namelist: "menu", single: true } |
michael@0 | 137 | |
michael@0 | 138 | ]; |
michael@0 | 139 | |
michael@0 | 140 | if (SpecialPowers.getBoolPref("layout.css.unset-value.enabled")) { |
michael@0 | 141 | testFontFamilyLists.push( |
michael@0 | 142 | { namelist: "unset", invalid: true, fontonly: true, single: true }, |
michael@0 | 143 | { namelist: "unset, simple", invalid: true }, |
michael@0 | 144 | { namelist: "simple, unset", invalid: true }, |
michael@0 | 145 | { namelist: "simple, unset bongo" }, |
michael@0 | 146 | { namelist: "simple, bongo unset" }, |
michael@0 | 147 | { namelist: "simple unset", single: true }, |
michael@0 | 148 | { namelist: "unset simple", single: true }); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | var gTest = 0; |
michael@0 | 152 | |
michael@0 | 153 | /* strip out just values */ |
michael@0 | 154 | function extractDecl(rule) |
michael@0 | 155 | { |
michael@0 | 156 | var t = rule.replace(/[ \n]+/g, " "); |
michael@0 | 157 | t = t.replace(/.*{[ \n]*/, ""); |
michael@0 | 158 | t = t.replace(/[ \n]*}.*/, ""); |
michael@0 | 159 | return t; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | |
michael@0 | 163 | function testStyleRuleParse(decl, invalid) { |
michael@0 | 164 | var sheet = document.styleSheets[1]; |
michael@0 | 165 | var rule = ".test" + gTest++ + " { " + decl + "; }"; |
michael@0 | 166 | |
michael@0 | 167 | while(sheet.cssRules.length > 0) { |
michael@0 | 168 | sheet.deleteRule(0); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | // shouldn't throw but improper handling of punctuation may cause some parsers to throw |
michael@0 | 172 | try { |
michael@0 | 173 | sheet.insertRule(rule, 0); |
michael@0 | 174 | } catch (e) { |
michael@0 | 175 | assert_unreached("unexpected error with " + decl + " ==> " + e.name); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | assert_equals(sheet.cssRules.length, 1, |
michael@0 | 179 | "strange number of rules (" + sheet.cssRules.length + ") with " + decl); |
michael@0 | 180 | |
michael@0 | 181 | var s = extractDecl(sheet.cssRules[0].cssText); |
michael@0 | 182 | |
michael@0 | 183 | if (invalid) { |
michael@0 | 184 | assert_equals(s, "", "rule declaration shouldn't parse - " + rule + " ==> " + s); |
michael@0 | 185 | } else { |
michael@0 | 186 | assert_not_equals(s, "", "rule declaration should parse - " + rule); |
michael@0 | 187 | |
michael@0 | 188 | // check that the serialization also parses |
michael@0 | 189 | var r = ".test" + gTest++ + " { " + s + " }"; |
michael@0 | 190 | while(sheet.cssRules.length > 0) { |
michael@0 | 191 | sheet.deleteRule(0); |
michael@0 | 192 | } |
michael@0 | 193 | try { |
michael@0 | 194 | sheet.insertRule(r, 0); |
michael@0 | 195 | } catch (e) { |
michael@0 | 196 | assert_unreached("exception occurred parsing serialized form of rule - " + rule + " ==> " + r + " " + e.name); |
michael@0 | 197 | } |
michael@0 | 198 | var s2 = extractDecl(sheet.cssRules[0].cssText); |
michael@0 | 199 | assert_not_equals(s2, "", "serialized form of rule should also parse - " + rule + " ==> " + r); |
michael@0 | 200 | } |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | var kDefaultFamilySetting = "onelittlepiggywenttomarket"; |
michael@0 | 204 | |
michael@0 | 205 | function testFontFamilySetterParse(namelist, invalid) { |
michael@0 | 206 | var el = document.getElementById("display"); |
michael@0 | 207 | |
michael@0 | 208 | el.style.fontFamily = kDefaultFamilySetting; |
michael@0 | 209 | var def = el.style.fontFamily; |
michael@0 | 210 | el.style.fontFamily = namelist; |
michael@0 | 211 | if (!invalid) { |
michael@0 | 212 | assert_not_equals(el.style.fontFamily, def, "fontFamily setter should parse - " + namelist); |
michael@0 | 213 | var parsed = el.style.fontFamily; |
michael@0 | 214 | el.style.fontFamily = kDefaultFamilySetting; |
michael@0 | 215 | el.style.fontFamily = parsed; |
michael@0 | 216 | assert_equals(el.style.fontFamily, parsed, "fontFamily setter should parse serialized form to identical serialization - " + parsed + " ==> " + el.style.fontFamily); |
michael@0 | 217 | } else { |
michael@0 | 218 | assert_equals(el.style.fontFamily, def, "fontFamily setter shouldn't parse - " + namelist); |
michael@0 | 219 | } |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | var kDefaultFontSetting = "16px onelittlepiggywenttomarket"; |
michael@0 | 223 | |
michael@0 | 224 | function testFontSetterParse(n, size, s1, s2, invalid) { |
michael@0 | 225 | var el = document.getElementById("display"); |
michael@0 | 226 | |
michael@0 | 227 | el.style.font = kDefaultFontSetting; |
michael@0 | 228 | var def = el.style.font; |
michael@0 | 229 | var fp = fontProp(n, size, s1, s2); |
michael@0 | 230 | el.style.font = fp; |
michael@0 | 231 | if (!invalid) { |
michael@0 | 232 | assert_not_equals(el.style.font, def, "font setter should parse - " + fp); |
michael@0 | 233 | var parsed = el.style.font; |
michael@0 | 234 | el.style.font = kDefaultFontSetting; |
michael@0 | 235 | el.style.font = parsed; |
michael@0 | 236 | assert_equals(el.style.font, parsed, "font setter should parse serialized form to identical serialization - " + parsed + " ==> " + el.style.font); |
michael@0 | 237 | } else { |
michael@0 | 238 | assert_equals(el.style.font, def, "font setter shouldn't parse - " + fp); |
michael@0 | 239 | } |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | var testFontVariations = [ |
michael@0 | 243 | { size: "16px" }, |
michael@0 | 244 | { size: "900px" }, |
michael@0 | 245 | { size: "900em" }, |
michael@0 | 246 | { size: "35%" }, |
michael@0 | 247 | { size: "7832.3%" }, |
michael@0 | 248 | { size: "xx-large" }, |
michael@0 | 249 | { size: "larger", s1: "lighter" }, |
michael@0 | 250 | { size: "16px", s1: "italic" }, |
michael@0 | 251 | { size: "16px", s1: "italic", s2: "bold" }, |
michael@0 | 252 | { size: "smaller", s1: "normal" }, |
michael@0 | 253 | { size: "16px", s1: "normal", s2: "normal" }, |
michael@0 | 254 | { size: "16px", s1: "400", s2: "normal" }, |
michael@0 | 255 | { size: "16px", s1: "bolder", s2: "oblique" } |
michael@0 | 256 | ]; |
michael@0 | 257 | |
michael@0 | 258 | function testFamilyNameParsing() { |
michael@0 | 259 | var i; |
michael@0 | 260 | for (i = 0; i < testFontFamilyLists.length; i++) { |
michael@0 | 261 | var tst = testFontFamilyLists[i]; |
michael@0 | 262 | var n = tst.namelist; |
michael@0 | 263 | var t; |
michael@0 | 264 | |
michael@0 | 265 | if (!tst.fontonly) { |
michael@0 | 266 | t = "font-family: " + n; |
michael@0 | 267 | test(function() { testStyleRuleParse(t, tst.invalid); }, t); |
michael@0 | 268 | test(function() { testFontFamilySetterParse(n, tst.invalid); }, t + " (setter)"); |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | var v; |
michael@0 | 272 | for (v = 0; v < testFontVariations.length; v++) { |
michael@0 | 273 | var f = testFontVariations[v]; |
michael@0 | 274 | t = font(n, f.size, f.s1, f.s2); |
michael@0 | 275 | test(function() { testStyleRuleParse(t, tst.invalid); }, t); |
michael@0 | 276 | test(function() { testFontSetterParse(n, f.size, f.s1, f.s2, tst.invalid); }, t + " (setter)"); |
michael@0 | 277 | } |
michael@0 | 278 | } |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | testFamilyNameParsing(); |
michael@0 | 282 | |
michael@0 | 283 | </script> |
michael@0 | 284 | </body> |
michael@0 | 285 | </html> |