layout/style/test/test_rules_out_of_sheets.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial