layout/style/test/test_page_parser.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!-- https://bugzilla.mozilla.org/show_bug.cgi?id=115199 -->
michael@0 4 <head>
michael@0 5 <meta charset="UTF-8">
michael@0 6 <title>Test of @page parser</title>
michael@0 7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 <p>@page parsing (<a
michael@0 12 target="_blank"
michael@0 13 href="https://bugzilla.mozilla.org/show_bug.cgi?id=115199"
michael@0 14 >bug 115199</a>)</p>
michael@0 15 <pre id="display"></pre>
michael@0 16 <style type="text/css" id="testbox"></style>
michael@0 17 <script class="testbody" type="text/javascript">
michael@0 18 function _(b) { return "@page { " + b + " }"; };
michael@0 19
michael@0 20 var testset = [
michael@0 21 // CSS 2.1 only allows margin properties in the page rule.
michael@0 22
michael@0 23 // Check a bad property.
michael@0 24 { rule: "position: absolute;" },
michael@0 25
michael@0 26 // Check good properties with invalid units.
michael@0 27 { rule: _("margin: 2in; margin: 2vw;"), expected: {
michael@0 28 "margin-top": "2in",
michael@0 29 "margin-right-value": "2in",
michael@0 30 "margin-bottom": "2in",
michael@0 31 "margin-left-value": "2in",
michael@0 32 "margin-left-ltr-source": "physical",
michael@0 33 "margin-left-rtl-source": "physical",
michael@0 34 "margin-right-ltr-source": "physical",
michael@0 35 "margin-right-rtl-source": "physical"
michael@0 36 }},
michael@0 37 { rule: _("margin-top: 2in; margin-top: 2vw;"), expected: {"margin-top": "2in"}},
michael@0 38 { rule: _("margin-top: 2in; margin-top: 2vh;"), expected: {"margin-top": "2in"}},
michael@0 39 { rule: _("margin-top: 2in; margin-top: 2vmax;"), expected: {"margin-top": "2in"}},
michael@0 40 { rule: _("margin-top: 2in; margin-top: 2vmin;"), expected: {"margin-top": "2in"}},
michael@0 41
michael@0 42 // Check good properties.
michael@0 43 // NOTE: The margin-*-value and margin-*-source properties are not really
michael@0 44 // expected and will need to be removed once bug 241234 is addressed.
michael@0 45 { rule: _("margin: 2in;"), expected: {
michael@0 46 "margin-top": "2in",
michael@0 47 "margin-right-value": "2in",
michael@0 48 "margin-bottom": "2in",
michael@0 49 "margin-left-value": "2in",
michael@0 50 "margin-left-ltr-source": "physical",
michael@0 51 "margin-left-rtl-source": "physical",
michael@0 52 "margin-right-ltr-source": "physical",
michael@0 53 "margin-right-rtl-source": "physical"
michael@0 54 }},
michael@0 55 { rule: _("margin-top: 2in;"), expected: {"margin-top": "2in"}},
michael@0 56 { rule: _("margin-left: 2in;"), expected: {
michael@0 57 "margin-left-value": "2in",
michael@0 58 "margin-left-ltr-source": "physical",
michael@0 59 "margin-left-rtl-source": "physical",
michael@0 60 }},
michael@0 61 { rule: _("margin-bottom: 2in;"), expected: {"margin-bottom": "2in"}},
michael@0 62 { rule: _("margin-right: 2in;"), expected: {
michael@0 63 "margin-right-value": "2in",
michael@0 64 "margin-right-ltr-source": "physical",
michael@0 65 "margin-right-rtl-source": "physical",
michael@0 66 }}
michael@0 67 ];
michael@0 68
michael@0 69 var display = document.getElementById("display");
michael@0 70 var sheet = document.styleSheets[1];
michael@0 71
michael@0 72 for (var curTest = 0; curTest < testset.length; curTest++) {
michael@0 73 try {
michael@0 74 while(sheet.cssRules.length > 0)
michael@0 75 sheet.deleteRule(0);
michael@0 76 sheet.insertRule(testset[curTest].rule, 0);
michael@0 77 } catch (e) {
michael@0 78 ok(e.name == "SyntaxError"
michael@0 79 && e instanceof DOMException
michael@0 80 && e.code == DOMException.SYNTAX_ERR
michael@0 81 && !('expected' in testset[curTest]),
michael@0 82 testset[curTest].rule + " syntax error thrown", e);
michael@0 83 }
michael@0 84
michael@0 85 try {
michael@0 86 if (testset[curTest].expected) {
michael@0 87 is(sheet.cssRules.length, 1,
michael@0 88 testset[curTest].rule + " rule count");
michael@0 89 is(sheet.cssRules[0].type, CSSRule.PAGE_RULE,
michael@0 90 testset[curTest].rule + " rule type");
michael@0 91
michael@0 92 var expected = testset[curTest].expected;
michael@0 93 var s = sheet.cssRules[0].style;
michael@0 94 var n = 0;
michael@0 95
michael@0 96 // everything is set that should be
michael@0 97 for (var name in expected) {
michael@0 98 is(s.getPropertyValue(name), expected[name],
michael@0 99 testset[curTest].rule + " (prop " + name + ")");
michael@0 100 n++;
michael@0 101 }
michael@0 102 // nothing else is set
michael@0 103 is(s.length, n, testset[curTest].rule + "prop count");
michael@0 104 for (var i = 0; i < s.length; i++) {
michael@0 105 ok(s[i] in expected, testset[curTest].rule,
michael@0 106 "Unexpected item #" + i + ": " + s[i]);
michael@0 107 }
michael@0 108 } else {
michael@0 109 if (sheet.cssRules.length == 0) {
michael@0 110 is(sheet.cssRules.length, 0,
michael@0 111 testset[curTest].rule + " rule count (0)");
michael@0 112 } else {
michael@0 113 is(sheet.cssRules.length, 1,
michael@0 114 testset[curTest].rule + " rule count (1 non-page)");
michael@0 115 isnot(sheet.cssRules[0].type, CSSRule.PAGE_RULE,
michael@0 116 testset[curTest].rule + " rule type (1 non-page)");
michael@0 117 }
michael@0 118 }
michael@0 119 } catch (e) {
michael@0 120 ok(false, testset[curTest].rule, "During test: " + e);
michael@0 121 }
michael@0 122 }
michael@0 123 </script>
michael@0 124 </body>
michael@0 125 </html>

mercurial