test_page_parser.html (3181B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- https://bugzilla.mozilla.org/show_bug.cgi?id=115199 --> 4 <head> 5 <meta charset="UTF-8"> 6 <title>Test of @page parser</title> 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 9 </head> 10 <body> 11 <p>@page parsing (<a 12 target="_blank" 13 href="https://bugzilla.mozilla.org/show_bug.cgi?id=115199" 14 >bug 115199</a>)</p> 15 <pre id="display"></pre> 16 <style type="text/css" id="testbox"></style> 17 <script class="testbody" type="text/javascript"> 18 function _(b) { return "@page { " + b + " }"; }; 19 20 var testset = [ 21 // CSS 2.1 only allows margin properties in the page rule. 22 23 // Check a bad property. 24 { rule: _("position: absolute;") }, 25 26 // Check good properties with invalid units. 27 { rule: _("margin: 2in; margin: 2vw;"), expected: { 28 "margin-top": "2in", 29 "margin-right": "2in", 30 "margin-bottom": "2in", 31 "margin-left": "2in" 32 }}, 33 { rule: _("margin-top: 2in; margin-top: 2vw;"), expected: {"margin-top": "2in"}}, 34 { rule: _("margin-top: 2in; margin-top: 2vh;"), expected: {"margin-top": "2in"}}, 35 { rule: _("margin-top: 2in; margin-top: 2vmax;"), expected: {"margin-top": "2in"}}, 36 { rule: _("margin-top: 2in; margin-top: 2vmin;"), expected: {"margin-top": "2in"}}, 37 38 // Check good properties. 39 { rule: _("margin: 2in;"), expected: { 40 "margin-top": "2in", 41 "margin-right": "2in", 42 "margin-bottom": "2in", 43 "margin-left": "2in" 44 }}, 45 { rule: _("margin-top: 2in;"), expected: {"margin-top": "2in"}}, 46 { rule: _("margin-left: 2in;"), expected: {"margin-left": "2in"}}, 47 { rule: _("margin-bottom: 2in;"), expected: {"margin-bottom": "2in"}}, 48 { rule: _("margin-right: 2in;"), expected: {"margin-right": "2in"}} 49 ]; 50 51 var display = document.getElementById("display"); 52 var sheet = document.styleSheets[1]; 53 54 for (var curTest = 0; curTest < testset.length; curTest++) { 55 while(sheet.cssRules.length > 0) { 56 sheet.deleteRule(0); 57 } 58 sheet.insertRule(testset[curTest].rule, 0); 59 60 try { 61 is(sheet.cssRules.length, 1, 62 testset[curTest].rule + " rule count"); 63 is(sheet.cssRules[0].type, CSSRule.PAGE_RULE, 64 testset[curTest].rule + " rule type"); 65 66 if (testset[curTest].expected) { 67 var expected = testset[curTest].expected; 68 var s = sheet.cssRules[0].style; 69 var n = 0; 70 71 // everything is set that should be 72 for (var name in expected) { 73 is(s.getPropertyValue(name), expected[name], 74 testset[curTest].rule + " (prop " + name + ")"); 75 n++; 76 } 77 // nothing else is set 78 is(s.length, n, testset[curTest].rule + " prop count"); 79 for (var i = 0; i < s.length; i++) { 80 ok(s[i] in expected, testset[curTest].rule + 81 " - Unexpected item #" + i + ": " + s[i]); 82 } 83 } else { 84 is(Object.keys(sheet.cssRules[0].style).length, 0, 85 testset[curTest].rule + " rule has no properties"); 86 } 87 } catch (e) { 88 ok(false, testset[curTest].rule + " - During test: " + e); 89 } 90 } 91 </script> 92 </body> 93 </html>