layout/style/test/test_inherit_storage.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=375363
     5 -->
     6 <head>
     7   <title>Test for parsing, storage, and serialization of CSS 'inherit' on all properties and 'unset' on inherited properties</title>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="text/javascript" src="property_database.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375363">Mozilla Bug 375363</a>
    14 <p id="display"></p>
    15 <div id="content" style="display: none">
    17 <div id="testnode"></div>
    19 </div>
    20 <pre id="test">
    21 <script class="testbody" type="text/javascript">
    23 /** Test for parsing, storage, and serialization of CSS 'inherit' on all
    24     properties and 'unset' on inherited properties **/
    26 var gDeclaration = document.getElementById("testnode").style;
    28 var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled");
    30 function test_property(property)
    31 {
    32   var info = gCSSProperties[property];
    34   var keywords = ["inherit"];
    35   if (info.inherited && gTestUnset)
    36     keywords.push("unset");
    38   keywords.forEach(function(keyword) {
    39     function check_initial(sproperty) {
    40       var sinfo = gCSSProperties[sproperty];
    41       var val = gDeclaration.getPropertyValue(sproperty);
    42       is(val, "", "value of '" + sproperty + "' before we do anything");
    43       is(val, gDeclaration[sinfo.domProp],
    44          "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp);
    45     }
    46     check_initial(property);
    47     if ("subproperties" in info)
    48       for (var idx in info.subproperties)
    49         check_initial(info.subproperties[idx]);
    51     gDeclaration.setProperty(property, keyword, "");
    53     function check_set(sproperty) {
    54       var sinfo = gCSSProperties[sproperty];
    55       val = gDeclaration.getPropertyValue(sproperty);
    56       is(val, keyword,
    57          keyword + " reported back for property '" + sproperty + "'");
    58       is(val, gDeclaration[sinfo.domProp],
    59          "consistency between decl.getPropertyValue('" + sproperty +
    60          "') and decl." + sinfo.domProp);
    61     }
    62     check_set(property);
    63     if ("subproperties" in info)
    64       for (var idx in info.subproperties)
    65         check_set(info.subproperties[idx]);
    67     // We don't care particularly about the whitespace or the placement of
    68     // semicolons, but for simplicity we'll test the current behavior.
    69     if ("alias_for" in info) {
    70       is(gDeclaration.cssText, info.alias_for + ": " + keyword + ";",
    71         "declaration should serialize to exactly what went in (for " + keyword + ")");
    72     } else {
    73       is(gDeclaration.cssText, property + ": " + keyword + ";",
    74         "declaration should serialize to exactly what went in (for " + keyword + ")");
    75     }
    77     gDeclaration.removeProperty(property);
    79     function check_final(sproperty) {
    80       var sinfo = gCSSProperties[sproperty];
    81       var val = gDeclaration.getPropertyValue(sproperty);
    82       is(val, "", "value of '" + sproperty + "' after removal of value");
    83       is(val, gDeclaration[sinfo.domProp],
    84          "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp);
    85     }
    86     check_final(property);
    87     if ("subproperties" in info)
    88       for (var idx in info.subproperties)
    89         check_final(info.subproperties[idx]);
    91     // can all properties be removed from the style?
    92     function test_remove_all_properties(property, value) {
    93       var i, p = [];
    94       for (i = 0; i < gDeclaration.length; i++) p.push(gDeclaration[i]);
    95       for (i = 0; i < p.length; i++) gDeclaration.removeProperty(p[i]);
    96       var errstr = "when setting property " + property + " to " + value;
    97       is(gDeclaration.length, 0, "unremovable properties " + errstr);
    98       is(gDeclaration.cssText, "", "non-empty serialization after removing all properties " + errstr);
    99     }
   101     // sanity check shorthands to make sure disabled props aren't exposed
   102     if (info.type != CSS_TYPE_LONGHAND) {
   103       gDeclaration.setProperty(property, keyword, "");
   104       test_remove_all_properties(property, keyword);
   105       gDeclaration.removeProperty(property);
   106     }
   107   });
   108 }
   110 for (var prop in gCSSProperties)
   111   test_property(prop);
   113 </script>
   114 </pre>
   115 </body>
   116 </html>

mercurial