Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
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 CSS 'initial' on all properties and 'unset' on reset properties</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.waitForExplicitFinish(); |
michael@0 | 17 | |
michael@0 | 18 | var load_count = 0; |
michael@0 | 19 | function load_done() { |
michael@0 | 20 | if (++load_count == 3) |
michael@0 | 21 | run_tests(); |
michael@0 | 22 | } |
michael@0 | 23 | </script> |
michael@0 | 24 | </head> |
michael@0 | 25 | <body> |
michael@0 | 26 | <p id="display"><span><span id="elementf"></span></span> |
michael@0 | 27 | <iframe id="unstyledn" src="unstyled.xml" height="10" width="10" onload="load_done()"></iframe> |
michael@0 | 28 | <iframe id="unstyledf" src="unstyled-frame.xml" height="10" width="10" onload="load_done()"></iframe> |
michael@0 | 29 | </p> |
michael@0 | 30 | <div id="content" style="display: none"> |
michael@0 | 31 | |
michael@0 | 32 | <div><span id="elementn"></span></div> |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | </div> |
michael@0 | 36 | <pre id="test"> |
michael@0 | 37 | <script class="testbody" type="text/javascript"> |
michael@0 | 38 | |
michael@0 | 39 | /** Test for computation of CSS 'initial' on all properties and 'unset' on |
michael@0 | 40 | reset properties **/ |
michael@0 | 41 | |
michael@0 | 42 | var gBrokenInitial = { |
michael@0 | 43 | }; |
michael@0 | 44 | |
michael@0 | 45 | function xfail_initial(property) { |
michael@0 | 46 | return property in gBrokenInitial; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | var gElementN = document.getElementById("elementn"); |
michael@0 | 50 | var gElementF = document.getElementById("elementf"); |
michael@0 | 51 | var gStyleSheet = document.getElementById("stylesheet").sheet; |
michael@0 | 52 | var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)]; |
michael@0 | 53 | var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)]; |
michael@0 | 54 | |
michael@0 | 55 | var gInitialValuesN; |
michael@0 | 56 | var gInitialValuesF; |
michael@0 | 57 | var gInitialPrereqsRuleN; |
michael@0 | 58 | var gInitialPrereqsRuleF; |
michael@0 | 59 | |
michael@0 | 60 | var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled"); |
michael@0 | 61 | |
michael@0 | 62 | function setup_initial_values(id, ivalprop, prereqprop) { |
michael@0 | 63 | var iframe = document.getElementById(id); |
michael@0 | 64 | window[ivalprop] = iframe.contentWindow.getComputedStyle( |
michael@0 | 65 | iframe.contentDocument.documentElement.firstChild, ""); |
michael@0 | 66 | var sheet = iframe.contentDocument.styleSheets[0]; |
michael@0 | 67 | // For 'width', 'height', etc., need a constant size container. |
michael@0 | 68 | sheet.insertRule(":root { height: 200px; width: 500px }", sheet.cssRules.length); |
michael@0 | 69 | |
michael@0 | 70 | window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)]; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | function test_property(property) |
michael@0 | 74 | { |
michael@0 | 75 | var info = gCSSProperties[property]; |
michael@0 | 76 | if (info.backend_only) |
michael@0 | 77 | return; |
michael@0 | 78 | |
michael@0 | 79 | var keywords = ["initial"]; |
michael@0 | 80 | if (!info.inherited && gTestUnset) |
michael@0 | 81 | keywords.push("unset"); |
michael@0 | 82 | |
michael@0 | 83 | keywords.forEach(function(keyword) { |
michael@0 | 84 | if ("prerequisites" in info) { |
michael@0 | 85 | var prereqs = info.prerequisites; |
michael@0 | 86 | for (var prereq in prereqs) { |
michael@0 | 87 | gRule1.style.setProperty(prereq, prereqs[prereq], ""); |
michael@0 | 88 | gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq], ""); |
michael@0 | 89 | gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq], ""); |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | if (info.inherited) { |
michael@0 | 93 | gElementN.parentNode.style.setProperty(property, info.other_values[0], ""); |
michael@0 | 94 | gElementF.parentNode.style.setProperty(property, info.other_values[0], ""); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | var initial_computed_n = get_computed_value(gInitialValuesN, property); |
michael@0 | 98 | var initial_computed_f = get_computed_value(gInitialValuesF, property); |
michael@0 | 99 | gRule1.style.setProperty(property, info.other_values[0], ""); |
michael@0 | 100 | var other_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property); |
michael@0 | 101 | var other_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property); |
michael@0 | 102 | isnot(other_computed_n, initial_computed_n, |
michael@0 | 103 | "should be testing with values that compute to different things " + |
michael@0 | 104 | "for '" + property + "'"); |
michael@0 | 105 | isnot(other_computed_f, initial_computed_f, |
michael@0 | 106 | "should be testing with values that compute to different things " + |
michael@0 | 107 | "for '" + property + "'"); |
michael@0 | 108 | // It's important (given the current design of nsRuleNode) that we're |
michael@0 | 109 | // modifying the most specific rule that matches the element, and that |
michael@0 | 110 | // we've already requested style while that rule was empty. This |
michael@0 | 111 | // means we'll have a cached aStartStruct from the parent in the rule |
michael@0 | 112 | // tree (caching the "other" value), so we'll make sure we don't get |
michael@0 | 113 | // the initial value from the luck of default-initialization. |
michael@0 | 114 | // This means that it's important that we set the prereqs on |
michael@0 | 115 | // gRule1.style rather than on gElement.style. |
michael@0 | 116 | gRule2.style.setProperty(property, keyword, ""); |
michael@0 | 117 | var initial_val_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property); |
michael@0 | 118 | var initial_val_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property); |
michael@0 | 119 | (xfail_initial(property) ? todo_is : is)( |
michael@0 | 120 | initial_val_computed_n, initial_computed_n, |
michael@0 | 121 | keyword + " should cause initial value for '" + property + "'"); |
michael@0 | 122 | (xfail_initial(property) ? todo_is : is)( |
michael@0 | 123 | initial_val_computed_f, initial_computed_f, |
michael@0 | 124 | keyword + " should cause initial value for '" + property + "'"); |
michael@0 | 125 | gRule1.style.removeProperty(property); |
michael@0 | 126 | gRule2.style.removeProperty(property); |
michael@0 | 127 | |
michael@0 | 128 | if ("prerequisites" in info) { |
michael@0 | 129 | var prereqs = info.prerequisites; |
michael@0 | 130 | for (var prereq in prereqs) { |
michael@0 | 131 | gRule1.style.removeProperty(prereq); |
michael@0 | 132 | gInitialPrereqsRuleN.style.removeProperty(prereq); |
michael@0 | 133 | gInitialPrereqsRuleF.style.removeProperty(prereq); |
michael@0 | 134 | } |
michael@0 | 135 | } |
michael@0 | 136 | if (info.inherited) { |
michael@0 | 137 | gElementN.parentNode.style.removeProperty(property); |
michael@0 | 138 | gElementF.parentNode.style.removeProperty(property); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | // FIXME: Something (maybe with the -moz-binding values in |
michael@0 | 142 | // test_value_computation.html, but may as well do it here to match) |
michael@0 | 143 | // causes gElementF's frame to get lost. Force it to get recreated |
michael@0 | 144 | // after each property. |
michael@0 | 145 | gElementF.parentNode.style.display = "none"; |
michael@0 | 146 | get_computed_value(getComputedStyle(gElementF, ""), "width"); |
michael@0 | 147 | gElementF.parentNode.style.display = ""; |
michael@0 | 148 | get_computed_value(getComputedStyle(gElementF, ""), "width"); |
michael@0 | 149 | }); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | function run_tests() { |
michael@0 | 153 | setup_initial_values("unstyledn", "gInitialValuesN", "gInitialPrereqsRuleN"); |
michael@0 | 154 | setup_initial_values("unstyledf", "gInitialValuesF", "gInitialPrereqsRuleF"); |
michael@0 | 155 | for (var prop in gCSSProperties) |
michael@0 | 156 | test_property(prop); |
michael@0 | 157 | SimpleTest.finish(); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | load_done(); |
michael@0 | 161 | |
michael@0 | 162 | </script> |
michael@0 | 163 | </pre> |
michael@0 | 164 | </body> |
michael@0 | 165 | </html> |