test_property_syntax_errors.html (5557B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 --> 5 <head> 6 <title>Test that we reject syntax errors listed in property_database.js</title> 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 <script type="text/javascript" src="property_database.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body onload="run()"> 12 <p id="display"></p> 13 <iframe id="quirks" src="data:text/html,<div id='testnode'></div>"></iframe> 14 <div id="content" style="display: none"> 15 16 <div id="testnode"></div> 17 18 </div> 19 <pre id="test"> 20 <script class="testbody" type="text/javascript"> 21 22 SimpleTest.waitForExplicitFinish(); 23 SimpleTest.requestLongerTimeout(4); 24 25 function check_not_accepted(decl, property, info, badval) 26 { 27 decl.setProperty(property, badval, ""); 28 29 is(decl.getPropertyValue(property), "", 30 "invalid value '" + badval + "' not accepted for '" + property + 31 "' property"); 32 33 if ("subproperties" in info) { 34 for (var sidx in info.subproperties) { 35 var subprop = info.subproperties[sidx]; 36 is(decl.getPropertyValue(subprop), "", 37 "invalid value '" + badval + "' not accepted for '" + property + 38 "' property when testing subproperty '" + subprop + "'"); 39 } 40 } 41 42 decl.removeProperty(property); 43 } 44 45 function check_value_balanced(decl, property, badval) 46 { 47 var goodProp = 48 (property == "background-color") ? "color" : "background-color"; 49 decl.cssText = goodProp + ": red; " + property + ": " + badval + "; " + 50 goodProp + ": green"; 51 is(decl.getPropertyValue(goodProp), "green", 52 "invalid value '" + property + ": " + badval + 53 "' is balanced and does not lead to parsing errors afterwards"); 54 decl.cssText = ""; 55 } 56 57 function check_value_unbalanced(decl, property, badval) 58 { 59 var goodProp = 60 (property == "background-color") ? "color" : "background-color"; 61 decl.cssText = goodProp + ": green; " + property + ": " + badval + "; " + 62 goodProp + ": red"; 63 is(decl.getPropertyValue(goodProp), "green", 64 "invalid value '" + property + ": " + badval + 65 "' is unbalanced and absorbs what follows it"); 66 decl.cssText = ""; 67 } 68 69 function check_empty_value_rejected(decl, emptyval, property) 70 { 71 var goodProp = 72 (property == "background-color") ? "color" : "background-color"; 73 decl.cssText = goodProp + ": red; " + property + ":" + emptyval + "; " + 74 goodProp + ": green"; 75 is(decl.length, 1, 76 "empty value '" + property + ":" + emptyval + 77 "' is not accepted"); 78 is(decl.getPropertyValue(goodProp), "green", 79 "empty value '" + property + ":" + emptyval + 80 "' is balanced and does not lead to parsing errors afterwards"); 81 decl.cssText = ""; 82 } 83 84 function run() 85 { 86 var gDeclaration = document.getElementById("testnode").style; 87 var quirksFrame = document.getElementById("quirks"); 88 var wrappedFrame = SpecialPowers.wrap(quirksFrame); 89 var gQuirksDeclaration = wrappedFrame.contentDocument 90 .getElementById("testnode").style; 91 92 for (var property in gCSSProperties) { 93 var info = gCSSProperties[property]; 94 95 check_empty_value_rejected(gDeclaration, "", property); 96 check_empty_value_rejected(gDeclaration, " ", property); 97 98 for (var idx in info.invalid_values) { 99 check_not_accepted(gDeclaration, property, info, 100 info.invalid_values[idx]); 101 check_not_accepted(gQuirksDeclaration, property, info, 102 info.invalid_values[idx]); 103 check_value_balanced(gDeclaration, property, 104 info.invalid_values[idx]); 105 } 106 107 if ("quirks_values" in info) { 108 for (var quirkval in info.quirks_values) { 109 var standardval = info.quirks_values[quirkval]; 110 check_not_accepted(gDeclaration, property, info, quirkval); 111 check_value_balanced(gDeclaration, property, quirkval); 112 113 gQuirksDeclaration.setProperty(property, quirkval, ""); 114 gDeclaration.setProperty(property, standardval, ""); 115 var quirkret = gQuirksDeclaration.getPropertyValue(property); 116 var standardret = gDeclaration.getPropertyValue(property); 117 isnot(quirkret, "", property + ": " + quirkval + 118 " should be accepted in quirks mode"); 119 is(quirkret, standardret, property + ": " + quirkval + " result"); 120 121 if ("subproperties" in info) { 122 for (var sidx in info.subproperties) { 123 var subprop = info.subproperties[sidx]; 124 var quirksub = gQuirksDeclaration.getPropertyValue(subprop); 125 var standardsub = gDeclaration.getPropertyValue(subprop); 126 isnot(quirksub, "", property + ": " + quirkval + 127 " should be accepted in quirks mode" + 128 " when testing subproperty " + subprop); 129 is(quirksub, standardsub, property + ": " + quirkval + " result" + 130 " when testing subproperty " + subprop); 131 } 132 } 133 134 gQuirksDeclaration.removeProperty(property); 135 gDeclaration.removeProperty(property); 136 } 137 } 138 139 for (var idx in info.unbalanced_values) { 140 check_not_accepted(gDeclaration, property, info, 141 info.invalid_values[idx]); 142 check_not_accepted(gQuirksDeclaration, property, info, 143 info.invalid_values[idx]); 144 check_value_unbalanced(gDeclaration, property, 145 info.unbalanced_values[idx]); 146 } 147 } 148 149 SimpleTest.finish(); 150 } 151 152 </script> 153 </pre> 154 </body> 155 </html>