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 | https://bugzilla.mozilla.org/show_bug.cgi?id=375363 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for cloning of CSS property values (including 'inherit', 'initial' and 'unset')</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="text/javascript" src="property_database.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <p id="display"><iframe id="iframe" src="about:blank"></iframe></p> |
michael@0 | 14 | <pre id="test"> |
michael@0 | 15 | <script class="testbody" type="text/javascript"> |
michael@0 | 16 | |
michael@0 | 17 | /** Test for cloning of CSS property values (including 'inherit', 'initial' and 'unset') **/ |
michael@0 | 18 | var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled"); |
michael@0 | 19 | var test_queue = []; |
michael@0 | 20 | var iframe = document.getElementById("iframe"); |
michael@0 | 21 | |
michael@0 | 22 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 23 | |
michael@0 | 24 | for (var prop in gCSSProperties) { |
michael@0 | 25 | var info = gCSSProperties[prop]; |
michael@0 | 26 | |
michael@0 | 27 | test_queue.push({ prop: prop, value: "inherit", |
michael@0 | 28 | inherited_value: info.initial_values[0] }); |
michael@0 | 29 | test_queue.push({ prop: prop, value: "inherit", |
michael@0 | 30 | inherited_value: info.other_values[0] }); |
michael@0 | 31 | test_queue.push({ prop: prop, value: "initial" }); |
michael@0 | 32 | if (gTestUnset) { |
michael@0 | 33 | if (info.inherited) { |
michael@0 | 34 | test_queue.push({ prop: prop, value: "unset", |
michael@0 | 35 | inherited_value: info.initial_values[0] }); |
michael@0 | 36 | test_queue.push({ prop: prop, value: "unset", |
michael@0 | 37 | inherited_value: info.other_values[0] }); |
michael@0 | 38 | } else { |
michael@0 | 39 | test_queue.push({ prop: prop, value: "unset" }); |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | for (var idx in info.initial_values) { |
michael@0 | 43 | test_queue.push({ prop: prop, value: info.initial_values[idx] }); |
michael@0 | 44 | } |
michael@0 | 45 | for (var idx in info.other_values) { |
michael@0 | 46 | test_queue.push({ prop: prop, value: info.other_values[idx] }); |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | test_queue.reverse(); |
michael@0 | 51 | |
michael@0 | 52 | doTest(); |
michael@0 | 53 | |
michael@0 | 54 | function doTest() |
michael@0 | 55 | { |
michael@0 | 56 | var sheet_data = ""; |
michael@0 | 57 | |
michael@0 | 58 | for (var idx = 0; idx < test_queue.length; ++idx) { |
michael@0 | 59 | var current_item = test_queue[idx]; |
michael@0 | 60 | |
michael@0 | 61 | var info = gCSSProperties[current_item.prop]; |
michael@0 | 62 | |
michael@0 | 63 | sheet_data += "#parent"+idx+", #test"+idx+" { "; |
michael@0 | 64 | for (var prereq in info.prereqs) { |
michael@0 | 65 | sheet_data += prereq + ": " + info.prereqs[prereq] + ";"; |
michael@0 | 66 | } |
michael@0 | 67 | sheet_data += " }"; |
michael@0 | 68 | |
michael@0 | 69 | sheet_data += "#parent"+idx+" { "; |
michael@0 | 70 | if ("inherited_value" in current_item) { |
michael@0 | 71 | sheet_data += current_item.prop + ": " + current_item.inherited_value; |
michael@0 | 72 | } |
michael@0 | 73 | sheet_data += "}"; |
michael@0 | 74 | |
michael@0 | 75 | sheet_data += "#test"+idx+" { "; |
michael@0 | 76 | sheet_data += current_item.prop + ": " + current_item.value; |
michael@0 | 77 | sheet_data += "}"; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | var sheet_url = "data:text/css," + escape(sheet_data); |
michael@0 | 81 | |
michael@0 | 82 | var doc_data = |
michael@0 | 83 | "<!DOCTYPE HTML>\n" + |
michael@0 | 84 | "<link rel='stylesheet' type='text/css' href='" + sheet_url + "'>\n" + |
michael@0 | 85 | "<link rel='stylesheet' type='text/css' href='" + sheet_url + "'>\n" + |
michael@0 | 86 | "<body>\n"; |
michael@0 | 87 | |
michael@0 | 88 | |
michael@0 | 89 | for (var idx = 0; idx < test_queue.length; ++idx) { |
michael@0 | 90 | var current_item = test_queue[idx]; |
michael@0 | 91 | |
michael@0 | 92 | if ("inherited_value" in current_item) { |
michael@0 | 93 | doc_data += "<span id='parent"+idx+"'>"; |
michael@0 | 94 | } |
michael@0 | 95 | doc_data += "<span id='test"+idx+"'></span>"; |
michael@0 | 96 | if ("inherited_value" in current_item) { |
michael@0 | 97 | doc_data += "</span>"; |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | var doc_url = "data:text/html," + escape(doc_data); |
michael@0 | 102 | iframe.onload = iframe_loaded; |
michael@0 | 103 | iframe.src = doc_url; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | function iframe_loaded(event) |
michael@0 | 107 | { |
michael@0 | 108 | if (event.target != iframe) |
michael@0 | 109 | return; |
michael@0 | 110 | |
michael@0 | 111 | var start_ser = []; |
michael@0 | 112 | var start_compute = []; |
michael@0 | 113 | var test_cs = []; |
michael@0 | 114 | var ifdoc = iframe.contentDocument; |
michael@0 | 115 | |
michael@0 | 116 | for (var idx = 0; idx < test_queue.length; ++idx) { |
michael@0 | 117 | var current_item = test_queue[idx]; |
michael@0 | 118 | var info = gCSSProperties[current_item.prop]; |
michael@0 | 119 | |
michael@0 | 120 | var test = ifdoc.getElementById("test" + idx); |
michael@0 | 121 | var cur_cs = iframe.contentWindow.getComputedStyle(test, ""); |
michael@0 | 122 | test_cs.push(cur_cs); |
michael@0 | 123 | var cur_ser = ifdoc.styleSheets[0].cssRules[3*idx+2].style.getPropertyValue(current_item.prop); |
michael@0 | 124 | if (cur_ser == "") { |
michael@0 | 125 | isnot(cur_ser, "", |
michael@0 | 126 | "serialization should be nonempty for " + |
michael@0 | 127 | current_item.prop + ": " + current_item.value); |
michael@0 | 128 | } |
michael@0 | 129 | start_ser.push(cur_ser); |
michael@0 | 130 | |
michael@0 | 131 | var cur_compute; |
michael@0 | 132 | if (!("backend_only" in info)) { |
michael@0 | 133 | cur_compute = get_computed_value(cur_cs, current_item.prop); |
michael@0 | 134 | if (cur_compute == "") { |
michael@0 | 135 | isnot(cur_compute, "", |
michael@0 | 136 | "computed value should be nonempty for " + |
michael@0 | 137 | current_item.prop + ": " + current_item.value); |
michael@0 | 138 | } |
michael@0 | 139 | } else { |
michael@0 | 140 | cur_compute = undefined; |
michael@0 | 141 | } |
michael@0 | 142 | start_compute.push(cur_compute); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | // In case the above access didn't force a clone already (though it |
michael@0 | 146 | // currently does), clone the second style sheet's inner and then |
michael@0 | 147 | // remove the first. |
michael@0 | 148 | ifdoc.styleSheets[1].insertRule("#nonexistent { color: red }", 0); |
michael@0 | 149 | var firstlink = ifdoc.getElementsByTagName("link")[0]; |
michael@0 | 150 | firstlink.parentNode.removeChild(firstlink); |
michael@0 | 151 | |
michael@0 | 152 | // Force a flush |
michael@0 | 153 | ifdoc.body.style.display="none"; |
michael@0 | 154 | var ow = ifdoc.body.offsetWidth; |
michael@0 | 155 | ifdoc.body.style.display=""; |
michael@0 | 156 | |
michael@0 | 157 | for (var idx = 0; idx < test_queue.length; ++idx) { |
michael@0 | 158 | var current_item = test_queue[idx]; |
michael@0 | 159 | var info = gCSSProperties[current_item.prop]; |
michael@0 | 160 | |
michael@0 | 161 | var end_ser = |
michael@0 | 162 | ifdoc.styleSheets[0].cssRules[3*idx+3].style.getPropertyValue(current_item.prop); |
michael@0 | 163 | is(end_ser, start_ser[idx], |
michael@0 | 164 | "serialization should match when cloning " + |
michael@0 | 165 | current_item.prop + ": " + current_item.value); |
michael@0 | 166 | |
michael@0 | 167 | if (!("backend_only" in info)) { |
michael@0 | 168 | var end_compute = get_computed_value(test_cs[idx], current_item.prop); |
michael@0 | 169 | // Output computed values only when the test failed. |
michael@0 | 170 | // Computed values may be very long. |
michael@0 | 171 | if (end_compute == start_compute[idx]) { |
michael@0 | 172 | ok(true, |
michael@0 | 173 | "computed values should match when cloning " + |
michael@0 | 174 | current_item.prop + ": " + current_item.value); |
michael@0 | 175 | } else { |
michael@0 | 176 | is(end_compute, start_compute[idx], |
michael@0 | 177 | "computed values should match when cloning " + |
michael@0 | 178 | current_item.prop + ": " + current_item.value); |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | SimpleTest.finish(); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | </script> |
michael@0 | 187 | </pre> |
michael@0 | 188 | </body> |
michael@0 | 189 | </html> |