Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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 type="text/javascript" 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 + " }"; };
20 var testset = [
21 // CSS 2.1 only allows margin properties in the page rule.
23 // Check a bad property.
24 { rule: "position: absolute;" },
26 // Check good properties with invalid units.
27 { rule: _("margin: 2in; margin: 2vw;"), expected: {
28 "margin-top": "2in",
29 "margin-right-value": "2in",
30 "margin-bottom": "2in",
31 "margin-left-value": "2in",
32 "margin-left-ltr-source": "physical",
33 "margin-left-rtl-source": "physical",
34 "margin-right-ltr-source": "physical",
35 "margin-right-rtl-source": "physical"
36 }},
37 { rule: _("margin-top: 2in; margin-top: 2vw;"), expected: {"margin-top": "2in"}},
38 { rule: _("margin-top: 2in; margin-top: 2vh;"), expected: {"margin-top": "2in"}},
39 { rule: _("margin-top: 2in; margin-top: 2vmax;"), expected: {"margin-top": "2in"}},
40 { rule: _("margin-top: 2in; margin-top: 2vmin;"), expected: {"margin-top": "2in"}},
42 // Check good properties.
43 // NOTE: The margin-*-value and margin-*-source properties are not really
44 // expected and will need to be removed once bug 241234 is addressed.
45 { rule: _("margin: 2in;"), expected: {
46 "margin-top": "2in",
47 "margin-right-value": "2in",
48 "margin-bottom": "2in",
49 "margin-left-value": "2in",
50 "margin-left-ltr-source": "physical",
51 "margin-left-rtl-source": "physical",
52 "margin-right-ltr-source": "physical",
53 "margin-right-rtl-source": "physical"
54 }},
55 { rule: _("margin-top: 2in;"), expected: {"margin-top": "2in"}},
56 { rule: _("margin-left: 2in;"), expected: {
57 "margin-left-value": "2in",
58 "margin-left-ltr-source": "physical",
59 "margin-left-rtl-source": "physical",
60 }},
61 { rule: _("margin-bottom: 2in;"), expected: {"margin-bottom": "2in"}},
62 { rule: _("margin-right: 2in;"), expected: {
63 "margin-right-value": "2in",
64 "margin-right-ltr-source": "physical",
65 "margin-right-rtl-source": "physical",
66 }}
67 ];
69 var display = document.getElementById("display");
70 var sheet = document.styleSheets[1];
72 for (var curTest = 0; curTest < testset.length; curTest++) {
73 try {
74 while(sheet.cssRules.length > 0)
75 sheet.deleteRule(0);
76 sheet.insertRule(testset[curTest].rule, 0);
77 } catch (e) {
78 ok(e.name == "SyntaxError"
79 && e instanceof DOMException
80 && e.code == DOMException.SYNTAX_ERR
81 && !('expected' in testset[curTest]),
82 testset[curTest].rule + " syntax error thrown", e);
83 }
85 try {
86 if (testset[curTest].expected) {
87 is(sheet.cssRules.length, 1,
88 testset[curTest].rule + " rule count");
89 is(sheet.cssRules[0].type, CSSRule.PAGE_RULE,
90 testset[curTest].rule + " rule type");
92 var expected = testset[curTest].expected;
93 var s = sheet.cssRules[0].style;
94 var n = 0;
96 // everything is set that should be
97 for (var name in expected) {
98 is(s.getPropertyValue(name), expected[name],
99 testset[curTest].rule + " (prop " + name + ")");
100 n++;
101 }
102 // nothing else is set
103 is(s.length, n, testset[curTest].rule + "prop count");
104 for (var i = 0; i < s.length; i++) {
105 ok(s[i] in expected, testset[curTest].rule,
106 "Unexpected item #" + i + ": " + s[i]);
107 }
108 } else {
109 if (sheet.cssRules.length == 0) {
110 is(sheet.cssRules.length, 0,
111 testset[curTest].rule + " rule count (0)");
112 } else {
113 is(sheet.cssRules.length, 1,
114 testset[curTest].rule + " rule count (1 non-page)");
115 isnot(sheet.cssRules[0].type, CSSRule.PAGE_RULE,
116 testset[curTest].rule + " rule type (1 non-page)");
117 }
118 }
119 } catch (e) {
120 ok(false, testset[curTest].rule, "During test: " + e);
121 }
122 }
123 </script>
124 </body>
125 </html>