1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_garbage_at_end_of_declarations.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +--> 1.8 +<head> 1.9 + <title>Test handling of garbage at the end of CSS declarations</title> 1.10 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <script type="text/javascript" src="property_database.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.13 +</head> 1.14 +<body> 1.15 +<p id="display"></p> 1.16 +<div id="content" style="display: none"> 1.17 + 1.18 +<div id="testnode"></div> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script class="testbody" type="text/javascript"> 1.23 + 1.24 +/** Test for correct ExpectEndProperty calls in CSS parser **/ 1.25 + 1.26 +/* 1.27 + * Inspired by review comments on bug 378217. 1.28 + * 1.29 + * The original idea was to test that ExpectEndProperty calls are made 1.30 + * in the correct places in the CSS parser so that we don't accept 1.31 + * garbage at the end of property values. 1.32 + * 1.33 + * However, there's actually other code (in ParseDeclaration) that 1.34 + * ensures that we don't accept garbage. 1.35 + * 1.36 + * Despite that, I'm checking it in anyway, since it caught an infinite 1.37 + * loop in the patch for bug 435441. 1.38 + */ 1.39 + 1.40 +var gElement = document.getElementById("testnode"); 1.41 +var gDeclaration = gElement.style; 1.42 + 1.43 +/* 1.44 + * This lists properties where garbage identifiers are allowed at the 1.45 + * end, with values in property_database.js that are exceptions that 1.46 + * should be tested anyway. "inherit", "initial" and "unset" are always 1.47 + * tested. 1.48 + */ 1.49 +var gAllowsExtra = { 1.50 + "counter-increment": { "none": true }, 1.51 + "counter-reset": { "none": true }, 1.52 + "font-family": {}, 1.53 + "font": { "caption": true, "icon": true, "menu": true, "message-box": true, 1.54 + "small-caption": true, "status-bar": true }, 1.55 + "voice-family": {}, 1.56 +}; 1.57 + 1.58 +/* These are the reverse of the above list; they're the unusual values 1.59 + that do allow extra keywords afterwards */ 1.60 +var gAllowsExtraUnusual = { 1.61 + "transition": { "all": true, "0s": true, "0s 0s": true, "ease": true, 1.62 + "1s 2s linear": true, "1s linear 2s": true, 1.63 + "linear 1s 2s": true, "linear 1s": true, 1.64 + "1s linear": true, "1s 2s": true, "2s 1s": true, 1.65 + "linear": true, "1s": true, "2s": true, 1.66 + "ease-in-out": true, "2s ease-in": true, 1.67 + "ease-out 2s": true, "1s width, 2s": true }, 1.68 + "animation": { "none": true, "0s": true, "ease": true, 1.69 + "normal": true, "running": true, "1.0": true, 1.70 + "1s 2s linear": true, "1s linear 2s": true, 1.71 + "linear 1s 2s": true, "linear 1s": true, 1.72 + "1s linear": true, "1s 2s": true, "2s 1s": true, 1.73 + "linear": true, "1s": true, "2s": true, 1.74 + "ease-in-out": true, "2s ease-in": true, 1.75 + "ease-out 2s": true, "1s bounce, 2s": true, 1.76 + "1s bounce, 2s none": true }, 1.77 + "font-family": { "inherit": true, "initial": true, "unset": true } 1.78 +}; 1.79 + 1.80 +gAllowsExtraUnusual["-moz-transition"] = gAllowsExtraUnusual["transition"]; 1.81 +gAllowsExtraUnusual["-moz-animation"] = gAllowsExtraUnusual["animation"]; 1.82 + 1.83 +function test_property(property) 1.84 +{ 1.85 + var info = gCSSProperties[property]; 1.86 + 1.87 + function test_value(value) { 1.88 + if (property in gAllowsExtra && 1.89 + value != "inherit" && value != "initial" && value != "unset" && 1.90 + !(value in gAllowsExtra[property])) { 1.91 + return; 1.92 + } 1.93 + if (property in gAllowsExtraUnusual && 1.94 + value in gAllowsExtraUnusual[property]) { 1.95 + return; 1.96 + } 1.97 + 1.98 + // Include non-identifier characters in the garbage 1.99 + // in case |value| would also be valid with a <custom-ident> added. 1.100 + gElement.setAttribute("style", property + ": " + value + " +blah/"); 1.101 + if ("subproperties" in info) { 1.102 + for (idx in info.subproperties) { 1.103 + var subprop = info.subproperties[idx]; 1.104 + is(gDeclaration.getPropertyValue(subprop), "", 1.105 + ["expected garbage ignored after '", property, ": ", value, 1.106 + "' when looking at subproperty '", subprop, "'"].join("")); 1.107 + } 1.108 + } else { 1.109 + is(gDeclaration.getPropertyValue(property), "", 1.110 + ["expected garbage ignored after '", property, ": ", value, 1.111 + "'"].join("")); 1.112 + } 1.113 + } 1.114 + 1.115 + var idx; 1.116 + test_value("inherit"); 1.117 + test_value("initial"); 1.118 + if (SpecialPowers.getBoolPref("layout.css.unset-value.enabled")) 1.119 + test_value("unset"); 1.120 + for (idx in info.initial_values) 1.121 + test_value(info.initial_values[idx]); 1.122 + for (idx in info.other_values) 1.123 + test_value(info.other_values[idx]); 1.124 +} 1.125 + 1.126 +// To avoid triggering the slow script dialog, we have to test one 1.127 +// property at a time. 1.128 +SimpleTest.waitForExplicitFinish(); 1.129 +var props = []; 1.130 +for (var prop in gCSSProperties) 1.131 + props.push(prop); 1.132 +props = props.reverse(); 1.133 +function do_one() { 1.134 + if (props.length == 0) { 1.135 + SimpleTest.finish(); 1.136 + return; 1.137 + } 1.138 + test_property(props.pop()); 1.139 + SimpleTest.executeSoon(do_one); 1.140 +} 1.141 +SimpleTest.executeSoon(do_one); 1.142 + 1.143 +</script> 1.144 +</pre> 1.145 +</body> 1.146 +</html>