test_initial_storage.html (5089B)
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 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"> 16 17 <div id="testnode"></div> 18 19 </div> 20 <pre id="test"> 21 <script class="testbody" type="text/javascript"> 22 23 /** 24 * Test for parsing, storage, and serialization of CSS 'initial' on all 25 * properties and 'unset' on reset properties 26 */ 27 28 var gDeclaration = document.getElementById("testnode").style; 29 30 /** 31 * Checks that the passed-in property-value (returned by getPropertyValue) is 32 * consistent with the DOM accessors that we know about for the given sproperty. 33 */ 34 function check_consistency(sproperty, valFromGetPropertyValue, messagePrefix) 35 { 36 var sinfo = gCSSProperties[sproperty]; 37 if (sinfo.domPropDisabled) { 38 return; 39 } 40 is(valFromGetPropertyValue, gDeclaration[sinfo.domProp], 41 `(${messagePrefix}) consistency between ` + 42 `decl.getPropertyValue(${sproperty}) and decl.${sinfo.domProp}`); 43 44 if (sinfo.domProp.startsWith("webkit")) { 45 // For webkit-prefixed DOM accessors, test with lowercase and uppercase 46 // first letter. 47 var uppercaseDomProp = "W" + sinfo.domProp.substring(1); 48 is(valFromGetPropertyValue, gDeclaration[uppercaseDomProp], 49 `(${messagePrefix}) consistency between ` + 50 `decl.getPropertyValue(${sproperty}) and decl.${uppercaseDomProp}`); 51 } 52 } 53 54 function test_property(property) 55 { 56 var info = gCSSProperties[property]; 57 58 var keywords = ["initial"]; 59 if (!info.inherited) 60 keywords.push("unset"); 61 62 keywords.forEach(function(keyword) { 63 function check_initial(sproperty) { 64 var val = gDeclaration.getPropertyValue(sproperty); 65 is(val, "", "value of '" + sproperty + "' before we do anything"); 66 check_consistency(sproperty, val, "initial"); 67 } 68 check_initial(property); 69 if ("subproperties" in info) 70 for (var idx in info.subproperties) 71 check_initial(info.subproperties[idx]); 72 73 gDeclaration.setProperty(property, keyword, ""); 74 75 function check_set(sproperty) { 76 val = gDeclaration.getPropertyValue(sproperty); 77 is(val, keyword, 78 keyword + " reported back for property '" + sproperty + "'"); 79 check_consistency(sproperty, val, "set"); 80 } 81 check_set(property); 82 if ("subproperties" in info) 83 for (var idx in info.subproperties) 84 check_set(info.subproperties[idx]); 85 86 // We don't care particularly about the whitespace or the placement of 87 // semicolons, but for simplicity we'll test the current behavior. 88 if ("alias_for" in info) { 89 is(gDeclaration.cssText, info.alias_for + ": " + keyword + ";", 90 "declaration should serialize to exactly what went in (for " + keyword + ")"); 91 } else if (info.type == CSS_TYPE_LEGACY_SHORTHAND) { 92 // We can't assert anything more meaningful here, really. 93 is(property, "zoom", "Zoom is a bit special because it never " + 94 "serializes as-is, we always serialize the longhands, " + 95 "but it doesn't just map to a single property " + 96 "(and thus we can't use the 'alias_for' mechanism)"); 97 } else { 98 is(gDeclaration.cssText, property + ": " + keyword + ";", 99 "declaration should serialize to exactly what went in (for " + keyword + ")"); 100 } 101 102 gDeclaration.removeProperty(property); 103 104 function check_final(sproperty) { 105 var val = gDeclaration.getPropertyValue(sproperty); 106 is(val, "", "value of '" + sproperty + "' after removal of value"); 107 check_consistency(sproperty, val, "final"); 108 } 109 check_final(property); 110 if ("subproperties" in info) 111 for (var idx in info.subproperties) 112 check_final(info.subproperties[idx]); 113 114 // can all properties be removed from the style? 115 function test_remove_all_properties(propName, value) { 116 var i, p = []; 117 for (i = 0; i < gDeclaration.length; i++) p.push(gDeclaration[i]); 118 for (i = 0; i < p.length; i++) gDeclaration.removeProperty(p[i]); 119 var errstr = "when setting property " + propName + " to " + value; 120 is(gDeclaration.length, 0, "unremovable properties " + errstr); 121 is(gDeclaration.cssText, "", "non-empty serialization after removing all properties " + errstr); 122 } 123 124 // sanity check shorthands to make sure disabled props aren't exposed 125 if (info.type != CSS_TYPE_LONGHAND) { 126 gDeclaration.setProperty(property, keyword, ""); 127 test_remove_all_properties(property, keyword); 128 gDeclaration.removeProperty(property); 129 } 130 }); 131 } 132 133 for (var prop in gCSSProperties) 134 test_property(prop); 135 136 </script> 137 </pre> 138 </body> 139 </html>