test_inherit_storage.html (4787B)
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 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 'inherit' on all 25 * properties and 'unset' on inherited properties 26 */ 27 28 var gDeclaration = document.getElementById("testnode").style; 29 30 function test_property(property) 31 { 32 var info = gCSSProperties[property]; 33 34 var keywords = ["inherit"]; 35 if (info.inherited) 36 keywords.push("unset"); 37 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 if (sinfo.domPropDisabled) { 44 return; 45 } 46 is(val, gDeclaration[sinfo.domProp], 47 "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp); 48 } 49 check_initial(property); 50 if ("subproperties" in info) 51 for (var idx in info.subproperties) 52 check_initial(info.subproperties[idx]); 53 54 gDeclaration.setProperty(property, keyword, ""); 55 56 function check_set(sproperty) { 57 var sinfo = gCSSProperties[sproperty]; 58 val = gDeclaration.getPropertyValue(sproperty); 59 is(val, keyword, 60 keyword + " reported back for property '" + sproperty + "'"); 61 if (sinfo.domPropDisabled) { 62 return; 63 } 64 is(val, gDeclaration[sinfo.domProp], 65 "consistency between decl.getPropertyValue('" + sproperty + 66 "') and decl." + sinfo.domProp); 67 } 68 check_set(property); 69 if ("subproperties" in info) 70 for (var idx in info.subproperties) 71 check_set(info.subproperties[idx]); 72 73 // We don't care particularly about the whitespace or the placement of 74 // semicolons, but for simplicity we'll test the current behavior. 75 if ("alias_for" in info) { 76 is(gDeclaration.cssText, info.alias_for + ": " + keyword + ";", 77 "declaration should serialize to exactly what went in (for " + keyword + ")"); 78 } else if (info.type == CSS_TYPE_LEGACY_SHORTHAND) { 79 // We can't assert anything more meaningful here, really. 80 is(property, "zoom", "Zoom is a bit special because it never " + 81 "serializes as-is, we always serialize the longhands, " + 82 "but it doesn't just map to a single property " + 83 "(and thus we can't use the 'alias_for' mechanism)"); 84 } else { 85 is(gDeclaration.cssText, property + ": " + keyword + ";", 86 "declaration should serialize to exactly what went in (for " + keyword + ")"); 87 } 88 89 gDeclaration.removeProperty(property); 90 91 function check_final(sproperty) { 92 var sinfo = gCSSProperties[sproperty]; 93 var val = gDeclaration.getPropertyValue(sproperty); 94 is(val, "", "value of '" + sproperty + "' after removal of value"); 95 if (sinfo.domPropDisabled) { 96 return; 97 } 98 is(val, gDeclaration[sinfo.domProp], 99 "consistency between decl.getPropertyValue('" + sproperty + "') and decl." + sinfo.domProp); 100 } 101 check_final(property); 102 if ("subproperties" in info) 103 for (var idx in info.subproperties) 104 check_final(info.subproperties[idx]); 105 106 // can all properties be removed from the style? 107 function test_remove_all_properties(propName, value) { 108 var i, p = []; 109 for (i = 0; i < gDeclaration.length; i++) p.push(gDeclaration[i]); 110 for (i = 0; i < p.length; i++) gDeclaration.removeProperty(p[i]); 111 var errstr = "when setting property " + propName + " to " + value; 112 is(gDeclaration.length, 0, "unremovable properties " + errstr); 113 is(gDeclaration.cssText, "", "non-empty serialization after removing all properties " + errstr); 114 } 115 116 // sanity check shorthands to make sure disabled props aren't exposed 117 if (info.type != CSS_TYPE_LONGHAND) { 118 gDeclaration.setProperty(property, keyword, ""); 119 test_remove_all_properties(property, keyword); 120 gDeclaration.removeProperty(property); 121 } 122 }); 123 } 124 125 for (var prop in gCSSProperties) 126 test_property(prop); 127 128 </script> 129 </pre> 130 </body> 131 </html>