1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_page_parser.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- https://bugzilla.mozilla.org/show_bug.cgi?id=115199 --> 1.7 +<head> 1.8 + <meta charset="UTF-8"> 1.9 + <title>Test of @page parser</title> 1.10 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> 1.12 +</head> 1.13 +<body> 1.14 +<p>@page parsing (<a 1.15 + target="_blank" 1.16 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=115199" 1.17 +>bug 115199</a>)</p> 1.18 +<pre id="display"></pre> 1.19 +<style type="text/css" id="testbox"></style> 1.20 +<script class="testbody" type="text/javascript"> 1.21 + function _(b) { return "@page { " + b + " }"; }; 1.22 + 1.23 + var testset = [ 1.24 + // CSS 2.1 only allows margin properties in the page rule. 1.25 + 1.26 + // Check a bad property. 1.27 + { rule: "position: absolute;" }, 1.28 + 1.29 + // Check good properties with invalid units. 1.30 + { rule: _("margin: 2in; margin: 2vw;"), expected: { 1.31 + "margin-top": "2in", 1.32 + "margin-right-value": "2in", 1.33 + "margin-bottom": "2in", 1.34 + "margin-left-value": "2in", 1.35 + "margin-left-ltr-source": "physical", 1.36 + "margin-left-rtl-source": "physical", 1.37 + "margin-right-ltr-source": "physical", 1.38 + "margin-right-rtl-source": "physical" 1.39 + }}, 1.40 + { rule: _("margin-top: 2in; margin-top: 2vw;"), expected: {"margin-top": "2in"}}, 1.41 + { rule: _("margin-top: 2in; margin-top: 2vh;"), expected: {"margin-top": "2in"}}, 1.42 + { rule: _("margin-top: 2in; margin-top: 2vmax;"), expected: {"margin-top": "2in"}}, 1.43 + { rule: _("margin-top: 2in; margin-top: 2vmin;"), expected: {"margin-top": "2in"}}, 1.44 + 1.45 + // Check good properties. 1.46 + // NOTE: The margin-*-value and margin-*-source properties are not really 1.47 + // expected and will need to be removed once bug 241234 is addressed. 1.48 + { rule: _("margin: 2in;"), expected: { 1.49 + "margin-top": "2in", 1.50 + "margin-right-value": "2in", 1.51 + "margin-bottom": "2in", 1.52 + "margin-left-value": "2in", 1.53 + "margin-left-ltr-source": "physical", 1.54 + "margin-left-rtl-source": "physical", 1.55 + "margin-right-ltr-source": "physical", 1.56 + "margin-right-rtl-source": "physical" 1.57 + }}, 1.58 + { rule: _("margin-top: 2in;"), expected: {"margin-top": "2in"}}, 1.59 + { rule: _("margin-left: 2in;"), expected: { 1.60 + "margin-left-value": "2in", 1.61 + "margin-left-ltr-source": "physical", 1.62 + "margin-left-rtl-source": "physical", 1.63 + }}, 1.64 + { rule: _("margin-bottom: 2in;"), expected: {"margin-bottom": "2in"}}, 1.65 + { rule: _("margin-right: 2in;"), expected: { 1.66 + "margin-right-value": "2in", 1.67 + "margin-right-ltr-source": "physical", 1.68 + "margin-right-rtl-source": "physical", 1.69 + }} 1.70 + ]; 1.71 + 1.72 + var display = document.getElementById("display"); 1.73 + var sheet = document.styleSheets[1]; 1.74 + 1.75 + for (var curTest = 0; curTest < testset.length; curTest++) { 1.76 + try { 1.77 + while(sheet.cssRules.length > 0) 1.78 + sheet.deleteRule(0); 1.79 + sheet.insertRule(testset[curTest].rule, 0); 1.80 + } catch (e) { 1.81 + ok(e.name == "SyntaxError" 1.82 + && e instanceof DOMException 1.83 + && e.code == DOMException.SYNTAX_ERR 1.84 + && !('expected' in testset[curTest]), 1.85 + testset[curTest].rule + " syntax error thrown", e); 1.86 + } 1.87 + 1.88 + try { 1.89 + if (testset[curTest].expected) { 1.90 + is(sheet.cssRules.length, 1, 1.91 + testset[curTest].rule + " rule count"); 1.92 + is(sheet.cssRules[0].type, CSSRule.PAGE_RULE, 1.93 + testset[curTest].rule + " rule type"); 1.94 + 1.95 + var expected = testset[curTest].expected; 1.96 + var s = sheet.cssRules[0].style; 1.97 + var n = 0; 1.98 + 1.99 + // everything is set that should be 1.100 + for (var name in expected) { 1.101 + is(s.getPropertyValue(name), expected[name], 1.102 + testset[curTest].rule + " (prop " + name + ")"); 1.103 + n++; 1.104 + } 1.105 + // nothing else is set 1.106 + is(s.length, n, testset[curTest].rule + "prop count"); 1.107 + for (var i = 0; i < s.length; i++) { 1.108 + ok(s[i] in expected, testset[curTest].rule, 1.109 + "Unexpected item #" + i + ": " + s[i]); 1.110 + } 1.111 + } else { 1.112 + if (sheet.cssRules.length == 0) { 1.113 + is(sheet.cssRules.length, 0, 1.114 + testset[curTest].rule + " rule count (0)"); 1.115 + } else { 1.116 + is(sheet.cssRules.length, 1, 1.117 + testset[curTest].rule + " rule count (1 non-page)"); 1.118 + isnot(sheet.cssRules[0].type, CSSRule.PAGE_RULE, 1.119 + testset[curTest].rule + " rule type (1 non-page)"); 1.120 + } 1.121 + } 1.122 + } catch (e) { 1.123 + ok(false, testset[curTest].rule, "During test: " + e); 1.124 + } 1.125 + } 1.126 +</script> 1.127 +</body> 1.128 +</html>