Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | --> |
michael@0 | 5 | <head> |
michael@0 | 6 | <title>Test for computation of values in property database</title> |
michael@0 | 7 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 8 | <script type="text/javascript" src="property_database.js"></script> |
michael@0 | 9 | <style type="text/css" id="stylesheet"></style> |
michael@0 | 10 | <style type="text/css"> |
michael@0 | 11 | /* For 'width', 'height', etc., need a constant size container. */ |
michael@0 | 12 | #display { width: 500px; height: 200px } |
michael@0 | 13 | </style> |
michael@0 | 14 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 15 | <script type="text/javascript"> |
michael@0 | 16 | SimpleTest.expectAssertions(9); |
michael@0 | 17 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 18 | SimpleTest.requestLongerTimeout(2); |
michael@0 | 19 | |
michael@0 | 20 | var load_count = 0; |
michael@0 | 21 | function load_done() { |
michael@0 | 22 | if (++load_count == 3) |
michael@0 | 23 | run_tests(); |
michael@0 | 24 | } |
michael@0 | 25 | </script> |
michael@0 | 26 | </head> |
michael@0 | 27 | <body> |
michael@0 | 28 | <p id="display"><span><span id="elementf"></span></span> |
michael@0 | 29 | <iframe id="unstyledn" src="unstyled.xml" height="10" width="10" onload="load_done()"></iframe> |
michael@0 | 30 | <iframe id="unstyledf" src="unstyled-frame.xml" height="10" width="10" onload="load_done()"></iframe> |
michael@0 | 31 | </p> |
michael@0 | 32 | <div id="content" style="display: none"> |
michael@0 | 33 | |
michael@0 | 34 | <div><span id="elementn"></span></div> |
michael@0 | 35 | |
michael@0 | 36 | |
michael@0 | 37 | </div> |
michael@0 | 38 | <pre id="test"> |
michael@0 | 39 | <script class="testbody" type="text/javascript"> |
michael@0 | 40 | |
michael@0 | 41 | /** Test for computation of values in property database **/ |
michael@0 | 42 | |
michael@0 | 43 | var gBadComputed = { |
michael@0 | 44 | // The CSS parser will accept these weird URLs. However, we'll fail to |
michael@0 | 45 | // resolve them when computing style, so we'll fall back to the initial |
michael@0 | 46 | // value ("none"). |
michael@0 | 47 | "filter": [ "url('feed:javascript:5')", "blur(3px) url('feed:javascript:5') grayscale(50%)" ], |
michael@0 | 48 | |
michael@0 | 49 | // These values are treated as auto. |
michael@0 | 50 | "page-break-after": [ "avoid" ], |
michael@0 | 51 | "page-break-before": [ "avoid" ], |
michael@0 | 52 | |
michael@0 | 53 | // This is the only SVG-length property (i.e., length allowing |
michael@0 | 54 | // unitless lengths) whose initial value is zero. |
michael@0 | 55 | "stroke-dashoffset": [ "0", "-moz-objectValue" ], |
michael@0 | 56 | }; |
michael@0 | 57 | |
michael@0 | 58 | var gBadComputedNoFrame = { |
michael@0 | 59 | // These are probably bogus tests... |
michael@0 | 60 | "border-radius": [ "0%", "calc(-1%)", "calc(0px) calc(0pt) calc(0%) calc(0em)" ], |
michael@0 | 61 | "border-bottom-left-radius": [ "0%", "calc(-1%)" ], |
michael@0 | 62 | "border-bottom-right-radius": [ "0%", "calc(-1%)" ], |
michael@0 | 63 | "border-top-left-radius": [ "0%", "calc(-1%)" ], |
michael@0 | 64 | "border-top-right-radius": [ "0%", "calc(-1%)" ], |
michael@0 | 65 | "-moz-margin-end": [ "0%", "calc(0% + 0px)", "calc(-1%)" ], |
michael@0 | 66 | "-moz-margin-start": [ "0%", "calc(0% + 0px)", "calc(-1%)" ], |
michael@0 | 67 | "-moz-outline-radius": [ "0%", "calc(-1%)", "calc(0px) calc(0pt) calc(0%) calc(0em)" ], |
michael@0 | 68 | "-moz-outline-radius-bottomleft": [ "0%", "calc(-1%)" ], |
michael@0 | 69 | "-moz-outline-radius-bottomright": [ "0%", "calc(-1%)" ], |
michael@0 | 70 | "-moz-outline-radius-topleft": [ "0%", "calc(-1%)" ], |
michael@0 | 71 | "-moz-outline-radius-topright": [ "0%", "calc(-1%)" ], |
michael@0 | 72 | "-moz-padding-end": [ "0%", "calc(0% + 0px)", "calc(-1%)" ], |
michael@0 | 73 | "-moz-padding-start": [ "0%", "calc(0% + 0px)", "calc(-1%)" ], |
michael@0 | 74 | "margin": [ "0% 0px 0em 0pt" ], |
michael@0 | 75 | "margin-bottom": [ "0%", "calc(0% + 0px)" ], |
michael@0 | 76 | "margin-left": [ "0%", "calc(0% + 0px)" ], |
michael@0 | 77 | "margin-right": [ "0%", "calc(0% + 0px)" ], |
michael@0 | 78 | "margin-top": [ "0%", "calc(0% + 0px)" ], |
michael@0 | 79 | "min-height": [ "calc(-1%)" ], |
michael@0 | 80 | "min-width": [ "calc(-1%)" ], |
michael@0 | 81 | "padding": [ "0% 0px 0em 0pt", "calc(0px) calc(0em) calc(-2px) calc(-1%)" ], |
michael@0 | 82 | "padding-bottom": [ "0%", "calc(0% + 0px)", "calc(-1%)" ], |
michael@0 | 83 | "padding-left": [ "0%", "calc(0% + 0px)", "calc(-1%)" ], |
michael@0 | 84 | "padding-right": [ "0%", "calc(0% + 0px)", "calc(-1%)" ], |
michael@0 | 85 | "padding-top": [ "0%", "calc(0% + 0px)", "calc(-1%)" ], |
michael@0 | 86 | }; |
michael@0 | 87 | |
michael@0 | 88 | function xfail_value(property, value, is_initial, has_frame) { |
michael@0 | 89 | if ((property in gBadComputed) && |
michael@0 | 90 | gBadComputed[property].indexOf(value) != -1) |
michael@0 | 91 | return true; |
michael@0 | 92 | |
michael@0 | 93 | if (!has_frame && (property in gBadComputedNoFrame) && |
michael@0 | 94 | gBadComputedNoFrame[property].indexOf(value) != -1) |
michael@0 | 95 | return true; |
michael@0 | 96 | |
michael@0 | 97 | return false; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | var gSwapInitialWhenHaveFrame = { |
michael@0 | 101 | // When there's a frame, '-moz-available' works out to the same as |
michael@0 | 102 | // 'auto' given the prerequisites of only 'display: block'. |
michael@0 | 103 | "width": [ "-moz-available" ], |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | function swap_when_frame(property, value) { |
michael@0 | 107 | return (property in gSwapInitialWhenHaveFrame) && |
michael@0 | 108 | gSwapInitialWhenHaveFrame[property].indexOf(value) != -1; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | var gElementN = document.getElementById("elementn"); |
michael@0 | 112 | var gElementF = document.getElementById("elementf"); |
michael@0 | 113 | var gStyleSheet = document.getElementById("stylesheet").sheet; |
michael@0 | 114 | var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)]; |
michael@0 | 115 | var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)]; |
michael@0 | 116 | |
michael@0 | 117 | var gInitialValuesN; |
michael@0 | 118 | var gInitialValuesF; |
michael@0 | 119 | var gInitialPrereqsRuleN; |
michael@0 | 120 | var gInitialPrereqsRuleF; |
michael@0 | 121 | |
michael@0 | 122 | function setup_initial_values(id, ivalprop, prereqprop) { |
michael@0 | 123 | var iframe = document.getElementById(id); |
michael@0 | 124 | window[ivalprop] = iframe.contentWindow.getComputedStyle( |
michael@0 | 125 | iframe.contentDocument.documentElement.firstChild, ""); |
michael@0 | 126 | var sheet = iframe.contentDocument.styleSheets[0]; |
michael@0 | 127 | // For 'width', 'height', etc., need a constant size container. |
michael@0 | 128 | sheet.insertRule(":root { height: 200px; width: 500px }", sheet.cssRules.length); |
michael@0 | 129 | |
michael@0 | 130 | window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)]; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | function test_value(property, val, is_initial) |
michael@0 | 134 | { |
michael@0 | 135 | var info = gCSSProperties[property]; |
michael@0 | 136 | if (info.backend_only) |
michael@0 | 137 | return; |
michael@0 | 138 | |
michael@0 | 139 | if ("prerequisites" in info) { |
michael@0 | 140 | var prereqs = info.prerequisites; |
michael@0 | 141 | for (var prereq in prereqs) { |
michael@0 | 142 | gRule1.style.setProperty(prereq, prereqs[prereq], ""); |
michael@0 | 143 | gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq], ""); |
michael@0 | 144 | gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq], ""); |
michael@0 | 145 | } |
michael@0 | 146 | } |
michael@0 | 147 | if (info.inherited && is_initial) { |
michael@0 | 148 | gElementN.parentNode.style.setProperty(property, info.other_values[0], ""); |
michael@0 | 149 | gElementF.parentNode.style.setProperty(property, info.other_values[0], ""); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | var initial_computed_n = get_computed_value(gInitialValuesN, property); |
michael@0 | 153 | var initial_computed_f = get_computed_value(gInitialValuesF, property); |
michael@0 | 154 | if (is_initial) { |
michael@0 | 155 | gRule1.style.setProperty(property, info.other_values[0], ""); |
michael@0 | 156 | var other_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property); |
michael@0 | 157 | var other_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property); |
michael@0 | 158 | isnot(other_computed_n, initial_computed_n, |
michael@0 | 159 | "should be testing with values that compute to different things " + |
michael@0 | 160 | "for '" + property + "'"); |
michael@0 | 161 | isnot(other_computed_f, initial_computed_f, |
michael@0 | 162 | "should be testing with values that compute to different things " + |
michael@0 | 163 | "for '" + property + "'"); |
michael@0 | 164 | } |
michael@0 | 165 | // It's important for values that are supposed to compute to the |
michael@0 | 166 | // initial value (given the current design of nsRuleNode) that we're |
michael@0 | 167 | // modifying the most specific rule that matches the element, and that |
michael@0 | 168 | // we've already requested style while that rule was empty. This |
michael@0 | 169 | // means we'll have a cached aStartStruct from the parent in the rule |
michael@0 | 170 | // tree (caching the "other" value), so we'll make sure we don't get |
michael@0 | 171 | // the initial value from the luck of default-initialization. |
michael@0 | 172 | // This means that it's important that we set the prereqs on |
michael@0 | 173 | // gRule1.style rather than on gElement.style. |
michael@0 | 174 | gRule2.style.setProperty(property, val, ""); |
michael@0 | 175 | var val_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property); |
michael@0 | 176 | var val_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property); |
michael@0 | 177 | isnot(val_computed_n, "", |
michael@0 | 178 | "should not get empty value for '" + property + ":" + val + "'"); |
michael@0 | 179 | isnot(val_computed_f, "", |
michael@0 | 180 | "should not get empty value for '" + property + ":" + val + "'"); |
michael@0 | 181 | if (is_initial) { |
michael@0 | 182 | (xfail_value(property, val, is_initial, false) ? todo_is : is)( |
michael@0 | 183 | val_computed_n, initial_computed_n, |
michael@0 | 184 | "should get initial value for '" + property + ":" + val + "'"); |
michael@0 | 185 | (xfail_value(property, val, is_initial, true) ? todo_is : is)( |
michael@0 | 186 | val_computed_f, initial_computed_f, |
michael@0 | 187 | "should get initial value for '" + property + ":" + val + "'"); |
michael@0 | 188 | } else { |
michael@0 | 189 | (xfail_value(property, val, is_initial, false) ? todo_isnot : isnot)( |
michael@0 | 190 | val_computed_n, initial_computed_n, |
michael@0 | 191 | "should not get initial value for '" + property + ":" + val + "' on elementn."); |
michael@0 | 192 | var swap = swap_when_frame(property, val); |
michael@0 | 193 | (xfail_value(property, val, is_initial, true) ? todo_isnot : (swap ? is : isnot))( |
michael@0 | 194 | val_computed_f, initial_computed_f, |
michael@0 | 195 | "should " + (swap ? "" : "not ") + |
michael@0 | 196 | "get initial value for '" + property + ":" + val + "' on elementf."); |
michael@0 | 197 | } |
michael@0 | 198 | if (is_initial) |
michael@0 | 199 | gRule1.style.removeProperty(property); |
michael@0 | 200 | gRule2.style.removeProperty(property); |
michael@0 | 201 | |
michael@0 | 202 | if ("prerequisites" in info) { |
michael@0 | 203 | var prereqs = info.prerequisites; |
michael@0 | 204 | for (var prereq in prereqs) { |
michael@0 | 205 | gRule1.style.removeProperty(prereq); |
michael@0 | 206 | gInitialPrereqsRuleN.style.removeProperty(prereq); |
michael@0 | 207 | gInitialPrereqsRuleF.style.removeProperty(prereq); |
michael@0 | 208 | } |
michael@0 | 209 | } |
michael@0 | 210 | if (info.inherited && is_initial) { |
michael@0 | 211 | gElementN.parentNode.style.removeProperty(property); |
michael@0 | 212 | gElementF.parentNode.style.removeProperty(property); |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | // FIXME: Something (maybe with the -moz-binding values) causes |
michael@0 | 216 | // gElementF's frame to get lost. Force it to get recreated after |
michael@0 | 217 | // each property. |
michael@0 | 218 | gElementF.parentNode.style.display = "none"; |
michael@0 | 219 | get_computed_value(getComputedStyle(gElementF, ""), "width"); |
michael@0 | 220 | gElementF.parentNode.style.display = ""; |
michael@0 | 221 | get_computed_value(getComputedStyle(gElementF, ""), "width"); |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | function test_property(prop) { |
michael@0 | 225 | var info = gCSSProperties[prop]; |
michael@0 | 226 | for (var idx in info.initial_values) |
michael@0 | 227 | test_value(prop, info.initial_values[idx], true); |
michael@0 | 228 | for (var idx in info.other_values) |
michael@0 | 229 | test_value(prop, info.other_values[idx], false); |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | function run_tests() { |
michael@0 | 233 | setup_initial_values("unstyledn", "gInitialValuesN", "gInitialPrereqsRuleN"); |
michael@0 | 234 | setup_initial_values("unstyledf", "gInitialValuesF", "gInitialPrereqsRuleF"); |
michael@0 | 235 | var props = []; |
michael@0 | 236 | for (var prop in gCSSProperties) |
michael@0 | 237 | props.push(prop); |
michael@0 | 238 | props = props.reverse(); |
michael@0 | 239 | function do_one() { |
michael@0 | 240 | if (props.length == 0) { |
michael@0 | 241 | SimpleTest.finish(); |
michael@0 | 242 | return; |
michael@0 | 243 | } |
michael@0 | 244 | test_property(props.pop()); |
michael@0 | 245 | SimpleTest.executeSoon(do_one); |
michael@0 | 246 | } |
michael@0 | 247 | SimpleTest.executeSoon(do_one); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | load_done(); |
michael@0 | 251 | |
michael@0 | 252 | </script> |
michael@0 | 253 | </pre> |
michael@0 | 254 | </body> |
michael@0 | 255 | </html> |