layout/style/test/test_initial_storage.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

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

mercurial