layout/style/test/test_rules_out_of_sheets.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 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=634373
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 634373</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=634373">Mozilla Bug 634373</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script type="application/javascript">
michael@0 19
michael@0 20 /** Test for Bug 634373 **/
michael@0 21
michael@0 22 function make_rule_and_remove_sheet(text, getter) {
michael@0 23 var style = document.createElement("style");
michael@0 24 style.setAttribute("type", "text/css");
michael@0 25 style.appendChild(document.createTextNode(text));
michael@0 26 document.head.appendChild(style);
michael@0 27 var result = style.sheet.cssRules[0];
michael@0 28 if (getter) {
michael@0 29 result = getter(result);
michael@0 30 }
michael@0 31 document.head.removeChild(style);
michael@0 32 style = null;
michael@0 33 SpecialPowers.DOMWindowUtils.garbageCollect();
michael@0 34 return result;
michael@0 35 }
michael@0 36
michael@0 37 var gDisplayCS = getComputedStyle(document.getElementById("display"), "");
michael@0 38
michael@0 39 function keep_rule_alive_by_matching(rule) {
michael@0 40 // It's the caller's job to guarantee that the rule matches a p.
michael@0 41 // This just causes a style flush, which in turn keeps the rule alive
michael@0 42 // until the next style flush.
michael@0 43 var color = gDisplayCS.color;
michael@0 44 return rule;
michael@0 45 }
michael@0 46
michael@0 47 function get_rule_and_child(rule) {
michael@0 48 return [rule, rule.cssRules[0]];
michael@0 49 }
michael@0 50
michael@0 51 function get_only_child(rule) {
michael@0 52 return rule.cssRules[0];
michael@0 53 }
michael@0 54
michael@0 55 var rule;
michael@0 56
michael@0 57 // In this case, the rule goes away immediately, so we're testing
michael@0 58 // the DOM wrapper's handling of a null rule, rather than the rule's
michael@0 59 // handling of a null sheet.
michael@0 60 rule = make_rule_and_remove_sheet("p { color: blue }");
michael@0 61 rule.style.color = "";
michael@0 62 try {
michael@0 63 rule.style.color = "fuchsia";
michael@0 64 } catch(ex) {}
michael@0 65
michael@0 66 rule = make_rule_and_remove_sheet("p { color: blue }",
michael@0 67 keep_rule_alive_by_matching);
michael@0 68 try {
michael@0 69 rule.style.color = "";
michael@0 70 } catch(ex) {}
michael@0 71 try {
michael@0 72 rule.style.color = "fuchsia";
michael@0 73 } catch(ex) {}
michael@0 74
michael@0 75 rule = make_rule_and_remove_sheet("@media screen { p { color: blue } }",
michael@0 76 get_rule_and_child);
michael@0 77 rule[1].style.color = "";
michael@0 78 try {
michael@0 79 rule[1].style.color = "fuchsia";
michael@0 80 } catch(ex) {}
michael@0 81
michael@0 82 // In this case, the rule goes away immediately, so we're testing
michael@0 83 // the DOM wrapper's handling of a null rule, rather than the rule's
michael@0 84 // handling of a null sheet.
michael@0 85 rule = make_rule_and_remove_sheet("@media screen { p { color: blue } }",
michael@0 86 get_only_child);
michael@0 87 rule.style.color = "";
michael@0 88 try {
michael@0 89 rule.style.color = "fuchsia";
michael@0 90 } catch(ex) {}
michael@0 91
michael@0 92 rule = make_rule_and_remove_sheet("@media screen { p { color: blue } }",
michael@0 93 function(rule) {
michael@0 94 return keep_rule_alive_by_matching(
michael@0 95 get_only_child(rule));
michael@0 96 });
michael@0 97 try {
michael@0 98 rule.style.color = "";
michael@0 99 } catch(ex) {}
michael@0 100 try {
michael@0 101 rule.style.color = "fuchsia";
michael@0 102 } catch(ex) {}
michael@0 103
michael@0 104 rule = make_rule_and_remove_sheet("@keyframes a { from { color: blue } }");
michael@0 105 rule.appendRule("from { color: fuchsia}");
michael@0 106 rule.deleteRule("from");
michael@0 107 rule.name = "b";
michael@0 108 rule.cssRules[0].keyText = "50%";
michael@0 109
michael@0 110 ok(true, "didn't crash");
michael@0 111
michael@0 112 </script>
michael@0 113 </pre>
michael@0 114 </body>
michael@0 115 </html>

mercurial