test_garbage_at_end_of_declarations.html (5613B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 --> 5 <head> 6 <title>Test handling of garbage at the end of CSS declarations</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> 12 <p id="display"></p> 13 <div id="content" style="display: none"> 14 15 <div id="testnode"></div> 16 17 </div> 18 <pre id="test"> 19 <script class="testbody" type="text/javascript"> 20 21 /* eslint-disable dot-notation */ 22 /** Test for correct ExpectEndProperty calls in CSS parser */ 23 24 25 /* 26 * Inspired by review comments on bug 378217. 27 * 28 * The original idea was to test that ExpectEndProperty calls are made 29 * in the correct places in the CSS parser so that we don't accept 30 * garbage at the end of property values. 31 * 32 * However, there's actually other code (in ParseDeclaration) that 33 * ensures that we don't accept garbage. 34 * 35 * Despite that, I'm checking it in anyway, since it caught an infinite 36 * loop in the patch for bug 435441. 37 */ 38 39 var gElement = document.getElementById("testnode"); 40 var gDeclaration = gElement.style; 41 42 /* 43 * This lists properties where garbage identifiers are allowed at the 44 * end, with values in property_database.js that are exceptions that 45 * should be tested anyway. "inherit", "initial" and "unset" are always 46 * tested. 47 */ 48 var gAllowsExtra = { 49 "counter-increment": { "none": true }, 50 "counter-reset": { "none": true }, 51 "font-family": {}, 52 "font": { "caption": true, "icon": true, "menu": true, "message-box": true, 53 "small-caption": true, "status-bar": true }, 54 "voice-family": {}, 55 "list-style": { 56 "inside none": true, "none inside": true, "none": true, 57 "none outside": true, "outside none": true, 58 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAKElEQVR42u3NQQ0AAAgEoNP+nTWFDzcoQE1udQQCgUAgEAgEAsGTYAGjxAE/G/Q2tQAAAABJRU5ErkJggg==")': true, 59 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAKElEQVR42u3NQQ0AAAgEoNP+nTWFDzcoQE1udQQCgUAgEAgEAsGTYAGjxAE/G/Q2tQAAAABJRU5ErkJggg==") outside': true, 60 'outside url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAKElEQVR42u3NQQ0AAAgEoNP+nTWFDzcoQE1udQQCgUAgEAgEAsGTYAGjxAE/G/Q2tQAAAABJRU5ErkJggg==")': true 61 }, 62 }; 63 64 /* These are the reverse of the above list; they're the unusual values 65 that do allow extra keywords afterwards */ 66 var gAllowsExtraUnusual = { 67 "transition": { "all": true, "0s": true, "0s 0s": true, "ease": true, 68 "1s 2s linear": true, "1s linear 2s": true, 69 "linear 1s 2s": true, "linear 1s": true, 70 "1s linear": true, "1s 2s": true, "2s 1s": true, 71 "linear": true, "1s": true, "2s": true, 72 "ease-in-out": true, "2s ease-in": true, 73 "ease-out 2s": true, "1s width, 2s": true }, 74 "animation": { "none": true, "0s": true, "ease": true, 75 "normal": true, "running": true, "1.0": true, 76 "1s 2s linear": true, "1s linear 2s": true, 77 "linear 1s 2s": true, "linear 1s": true, 78 "1s linear": true, "1s 2s": true, "2s 1s": true, 79 "linear": true, "1s": true, "2s": true, 80 "ease-in-out": true, "2s ease-in": true, 81 "ease-out 2s": true, "1s bounce, 2s": true, 82 "1s bounce, 2s none": true }, 83 "font-family": { "inherit": true, "initial": true, "unset": true } 84 }; 85 86 if (IsCSSPropertyPrefEnabled("layout.css.prefixes.transitions")) { 87 gAllowsExtraUnusual["-moz-transition"] = gAllowsExtraUnusual["transition"]; 88 } 89 if (IsCSSPropertyPrefEnabled("layout.css.prefixes.animations")) { 90 gAllowsExtraUnusual["-moz-animation"] = gAllowsExtraUnusual["animation"]; 91 } 92 93 function test_property(property) 94 { 95 var info = gCSSProperties[property]; 96 97 function test_value(value) { 98 if (property in gAllowsExtra && 99 value != "inherit" && value != "initial" && value != "unset" && 100 !(value in gAllowsExtra[property])) { 101 return; 102 } 103 if (property in gAllowsExtraUnusual && 104 value in gAllowsExtraUnusual[property]) { 105 return; 106 } 107 108 // Include non-identifier characters in the garbage 109 // in case |value| would also be valid with a <custom-ident> added. 110 gElement.setAttribute("style", property + ": " + value + " +blah/"); 111 if ("subproperties" in info) { 112 for (idx in info.subproperties) { 113 var subprop = info.subproperties[idx]; 114 is(gDeclaration.getPropertyValue(subprop), "", 115 ["expected garbage ignored after '", property, ": ", value, 116 "' when looking at subproperty '", subprop, "'"].join("")); 117 } 118 } else { 119 is(gDeclaration.getPropertyValue(property), "", 120 ["expected garbage ignored after '", property, ": ", value, 121 "'"].join("")); 122 } 123 } 124 125 var idx; 126 test_value("inherit"); 127 test_value("initial"); 128 test_value("unset"); 129 for (idx in info.initial_values) 130 test_value(info.initial_values[idx]); 131 for (idx in info.other_values) 132 test_value(info.other_values[idx]); 133 } 134 135 // To avoid triggering the slow script dialog, we have to test one 136 // property at a time. 137 SimpleTest.waitForExplicitFinish(); 138 SimpleTest.requestLongerTimeout(2); 139 var props = []; 140 for (var prop in gCSSProperties) 141 props.push(prop); 142 props = props.reverse(); 143 function do_one() { 144 if (props.length == 0) { 145 SimpleTest.finish(); 146 return; 147 } 148 test_property(props.pop()); 149 SimpleTest.executeSoon(do_one); 150 } 151 SimpleTest.executeSoon(do_one); 152 153 </script> 154 </pre> 155 </body> 156 </html>