test_counter_descriptor_storage.html (6461B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Test for parsing, storage and serialization of CSS @counter-style descriptor values</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=966166">Mozilla Bug 966166</a> 10 <div id="display"></div> 11 <pre id="test"> 12 <script type="application/javascript"> 13 var gStyleElement = document.createElement("style"); 14 gStyleElement.setAttribute("type", "text/css"); 15 document.getElementsByTagName("head")[0].appendChild(gStyleElement); 16 var gSheet = gStyleElement.sheet; 17 gSheet.insertRule( 18 "@counter-style test { system: extends decimal }", 0); 19 var gRule = gSheet.cssRules[0]; 20 21 function set_rule(ruleText) { 22 gSheet.deleteRule(0); 23 gSheet.insertRule("@counter-style test { " + ruleText + " }", 0); 24 gRule = gSheet.cssRules[0]; 25 } 26 27 function run_tests(tests) { 28 for (var desc in tests) { 29 var items = tests[desc]; 30 for (var i in items) { 31 var item = items[i]; 32 var ref = item[0]; 33 if (ref === null) { 34 ref = gRule[desc]; 35 } 36 for (var j in item) { 37 if (item[j] !== null) { 38 gRule[desc] = item[j]; 39 is(gRule[desc], ref, 40 "setting '" + item[j] + "' on '" + desc + "'"); 41 } 42 } 43 } 44 } 45 } 46 47 function test_system_dep_desc() { 48 // for system requires at least one symbol 49 var oneSymbolTests = [ 50 [null, "", "0"], 51 ["x y", "x y"], 52 ["\"x\"", "'x'"], 53 ["\\-", "\\2D"], 54 ["\\*", "\\2A"], 55 ]; 56 // for system requires at least two symbols 57 var twoSymbolsTests = [ 58 [null, "", "0", "x", "\"x\""], 59 ["x y", "x y"], 60 ["\"x\" \"y\"", "'x' 'y'"], 61 ]; 62 var info = [ 63 { 64 system: "cyclic", 65 base: "symbols: x", 66 base_tests: { 67 system: "cyclic", 68 symbols: "x" 69 }, 70 tests: { 71 system: [ 72 [null, "", "symbolic"], 73 ["cyclic", "Cyclic"], 74 ], 75 symbols: oneSymbolTests 76 } 77 }, 78 { 79 system: "fixed", 80 base: "symbols: x", 81 base_tests: { 82 system: "fixed", 83 symbols: "x" 84 }, 85 tests: { 86 system: [ 87 [null, "", "symbolic"], 88 ["fixed 0"], 89 ["fixed", "FixeD"], 90 ["fixed 1", "FixeD 1"], 91 ["fixed -1"], 92 [null, "fixed a", "fixed \"0\"", "fixed 0 1"], 93 ], 94 symbols: oneSymbolTests 95 } 96 }, 97 { 98 system: "symbolic", 99 base: "symbols: x", 100 base_tests: { 101 system: "symbolic", 102 symbols: "x" 103 }, 104 tests: { 105 system: [ 106 [null, "", "cyclic"], 107 ["symbolic", "SymBolic"], 108 ], 109 symbols: oneSymbolTests 110 } 111 }, 112 { 113 system: "alphabetic", 114 base: "symbols: x y", 115 base_tests: { 116 system: "alphabetic", 117 symbols: "x y" 118 }, 119 tests: { 120 system: [ 121 [null, "", "cyclic"], 122 ["alphabetic", "AlphaBetic"], 123 ], 124 symbols: twoSymbolsTests 125 } 126 }, 127 { 128 system: "numeric", 129 base: "symbols: x y", 130 base_tests: { 131 system: "numeric", 132 symbols: "x y" 133 }, 134 tests: { 135 system: [ 136 [null, "", "cyclic"], 137 ["numeric", "NumEric"], 138 ], 139 symbols: twoSymbolsTests 140 } 141 }, 142 { 143 system: "additive", 144 base: "additive-symbols: 0 x", 145 base_tests: { 146 system: "additive", 147 additiveSymbols: "0 x" 148 }, 149 tests: { 150 system: [ 151 [null, "", "cyclic"], 152 ], 153 additiveSymbols: [ 154 [null, "", "x", "0", "\"x\"", "1 x, 0", "0 x, 1 y"], 155 ["0 x", "x 0"], 156 ["1 y, 0 x", "y 1, 0 x", "1 y, x 0", "y 1, x 0"], 157 ["1 \"0\"", "\"0\" 1", "1 '0'"], 158 ] 159 } 160 }, 161 { 162 system: "extends decimal", 163 base: "", 164 base_tests: { 165 system: "extends decimal", 166 symbols: "", 167 additiveSymbols: "" 168 }, 169 tests: { 170 system: [ 171 [null, "extends", "fixed", "cyclic", "extends symbols('*')"], 172 ["extends cjk-decimal", "ExTends cjk-decimal", "extends CJK-decimal"], 173 ], 174 symbols: [ 175 [null, "x", "x y"], 176 ], 177 additiveSymbols: [ 178 [null, "0 x", "1 y, 0 x"], 179 ] 180 } 181 } 182 ]; 183 for (var i = 0; i < info.length; i++) { 184 var item = info[i]; 185 set_rule("system: " + item.system + "; " + item.base); 186 for (var desc in item.base_tests) { 187 is(gRule[desc], item.base_tests[desc], 188 "checking base value of '" + desc + "' " + 189 "for system '" + item.system + "'"); 190 } 191 run_tests(item.tests); 192 } 193 } 194 195 function test_system_indep_desc() { 196 var tests = { 197 name: [ 198 [null, "", "-", " ", "a b"], 199 [null, "decimal", "none", "Decimal", "NONE"], 200 ["cjk-decimal", "CJK-Decimal", "cjk-Decimal"], 201 ["X"], 202 ["x", "\\78"], 203 ["\\-", "\\2D"], 204 ], 205 negative: [ 206 [null, "-", "", "0", "a b c"], 207 ["\"-\"", "'-'", "\"\\2D\""], 208 ["\\-", "\\2D"], 209 ["a b"], 210 ["\"(\" \")\"", "'(' ')'"], 211 ], 212 prefix: [ 213 [null, "0", "-", " ", "a b"], 214 ["a"], 215 ["\"a\""], 216 ], 217 suffix: [ 218 [null, "0", "-", " ", "a b"], 219 ["a"], 220 ["\"a\""], 221 ], 222 range: [ 223 ["auto", "auTO"], 224 ["infinite infinite", "INFinite inFinite"], 225 ["0 infinite", "0 INFINITE"], 226 ["infinite 100"], 227 ["1 1"], 228 ["0 100", "0 100"], 229 ["0 100, 2 300, -1 1, infinite -100"], 230 [null, "0", "0 a", "a 0"], 231 [null, "1 -1", "1 -1, 0 100", "-1 1, 100 0"], 232 ], 233 pad: [ 234 ["0 \"\"", "\"\" 0"], 235 ["1 a", "a 1", "1 a", "\\61 1"], 236 [null, "0", "\"\"", "0 0", "a a", "0 a a"], 237 ], 238 fallback: [ 239 [null, "", "-", "0", "a b", "symbols('*')"], 240 ["a"], 241 ["A"], 242 ["decimal", "Decimal"], 243 ], 244 speakAs: [ 245 [null, "", "-", "0", "a b", "symbols('*')"], 246 ["auto", "AuTo"], 247 ["bullets", "BULLETs"], 248 ["numbers", "NumBers"], 249 ["words", "WordS"], 250 // Currently spell-out is not supported, so it should be treated 251 // as an invalid value. 252 [null, "spell-out", "Spell-Out"], 253 ["a"], 254 ["A"], 255 ["decimal", "Decimal"], 256 ], 257 }; 258 set_rule("system: extends decimal"); 259 run_tests(tests); 260 } 261 262 test_system_dep_desc(); 263 test_system_indep_desc(); 264 265 </script> 266 </pre> 267 </body> 268 </html>