layout/style/test/test_initial_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 'initial' on all properties and 'unset' on reset 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 'initial' on all
    24     properties and 'unset' on reset 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 = ["initial"];
    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          "(initial) consistency between decl.getPropertyValue('" + sproperty +
    45          "') and decl." + sinfo.domProp);
    46     }
    47     check_initial(property);
    48     if ("subproperties" in info)
    49       for (var idx in info.subproperties)
    50         check_initial(info.subproperties[idx]);
    52     gDeclaration.setProperty(property, keyword, "");
    54     function check_set(sproperty) {
    55       var sinfo = gCSSProperties[sproperty];
    56       val = gDeclaration.getPropertyValue(sproperty);
    57       is(val, keyword,
    58          keyword + " reported back for property '" + sproperty + "'");
    59       is(val, gDeclaration[sinfo.domProp],
    60          "(set) consistency between decl.getPropertyValue('" + sproperty +
    61          "') and decl." + sinfo.domProp);
    62     }
    63     check_set(property);
    64     if ("subproperties" in info)
    65       for (var idx in info.subproperties)
    66         check_set(info.subproperties[idx]);
    68     // We don't care particularly about the whitespace or the placement of
    69     // semicolons, but for simplicity we'll test the current behavior.
    70     if ("alias_for" in info) {
    71       is(gDeclaration.cssText, info.alias_for + ": " + keyword + ";",
    72         "declaration should serialize to exactly what went in (for " + keyword + ")");
    73     } else {
    74       is(gDeclaration.cssText, property + ": " + keyword + ";",
    75         "declaration should serialize to exactly what went in (for " + keyword + ")");
    76     }
    78     gDeclaration.removeProperty(property);
    80     function check_final(sproperty) {
    81       var sinfo = gCSSProperties[sproperty];
    82       var val = gDeclaration.getPropertyValue(sproperty);
    83       is(val, "", "value of '" + sproperty + "' after removal of value");
    84       is(val, gDeclaration[sinfo.domProp],
    85          "(final) consistency between decl.getPropertyValue('" + sproperty +
    86          "') and decl." + sinfo.domProp);
    87     }
    88     check_final(property);
    89     if ("subproperties" in info)
    90       for (var idx in info.subproperties)
    91         check_final(info.subproperties[idx]);
    93     // can all properties be removed from the style?
    94     function test_remove_all_properties(property, value) {
    95       var i, p = [];
    96       for (i = 0; i < gDeclaration.length; i++) p.push(gDeclaration[i]);
    97       for (i = 0; i < p.length; i++) gDeclaration.removeProperty(p[i]);
    98       var errstr = "when setting property " + property + " to " + value;
    99       is(gDeclaration.length, 0, "unremovable properties " + errstr);
   100       is(gDeclaration.cssText, "", "non-empty serialization after removing all properties " + errstr);
   101     }
   103     // sanity check shorthands to make sure disabled props aren't exposed
   104     if (info.type != CSS_TYPE_LONGHAND) {
   105       gDeclaration.setProperty(property, keyword, "");
   106       test_remove_all_properties(property, keyword);
   107       gDeclaration.removeProperty(property);
   108     }
   109   });
   110 }
   112 for (var prop in gCSSProperties)
   113   test_property(prop);
   115 </script>
   116 </pre>
   117 </body>
   118 </html>

mercurial