1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_value_cloning.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,189 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=375363 1.8 +--> 1.9 +<head> 1.10 + <title>Test for cloning of CSS property values (including 'inherit', 'initial' and 'unset')</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="property_database.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 +<p id="display"><iframe id="iframe" src="about:blank"></iframe></p> 1.17 +<pre id="test"> 1.18 +<script class="testbody" type="text/javascript"> 1.19 + 1.20 +/** Test for cloning of CSS property values (including 'inherit', 'initial' and 'unset') **/ 1.21 +var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled"); 1.22 +var test_queue = []; 1.23 +var iframe = document.getElementById("iframe"); 1.24 + 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 + 1.27 +for (var prop in gCSSProperties) { 1.28 + var info = gCSSProperties[prop]; 1.29 + 1.30 + test_queue.push({ prop: prop, value: "inherit", 1.31 + inherited_value: info.initial_values[0] }); 1.32 + test_queue.push({ prop: prop, value: "inherit", 1.33 + inherited_value: info.other_values[0] }); 1.34 + test_queue.push({ prop: prop, value: "initial" }); 1.35 + if (gTestUnset) { 1.36 + if (info.inherited) { 1.37 + test_queue.push({ prop: prop, value: "unset", 1.38 + inherited_value: info.initial_values[0] }); 1.39 + test_queue.push({ prop: prop, value: "unset", 1.40 + inherited_value: info.other_values[0] }); 1.41 + } else { 1.42 + test_queue.push({ prop: prop, value: "unset" }); 1.43 + } 1.44 + } 1.45 + for (var idx in info.initial_values) { 1.46 + test_queue.push({ prop: prop, value: info.initial_values[idx] }); 1.47 + } 1.48 + for (var idx in info.other_values) { 1.49 + test_queue.push({ prop: prop, value: info.other_values[idx] }); 1.50 + } 1.51 +} 1.52 + 1.53 +test_queue.reverse(); 1.54 + 1.55 +doTest(); 1.56 + 1.57 +function doTest() 1.58 +{ 1.59 + var sheet_data = ""; 1.60 + 1.61 + for (var idx = 0; idx < test_queue.length; ++idx) { 1.62 + var current_item = test_queue[idx]; 1.63 + 1.64 + var info = gCSSProperties[current_item.prop]; 1.65 + 1.66 + sheet_data += "#parent"+idx+", #test"+idx+" { "; 1.67 + for (var prereq in info.prereqs) { 1.68 + sheet_data += prereq + ": " + info.prereqs[prereq] + ";"; 1.69 + } 1.70 + sheet_data += " }"; 1.71 + 1.72 + sheet_data += "#parent"+idx+" { "; 1.73 + if ("inherited_value" in current_item) { 1.74 + sheet_data += current_item.prop + ": " + current_item.inherited_value; 1.75 + } 1.76 + sheet_data += "}"; 1.77 + 1.78 + sheet_data += "#test"+idx+" { "; 1.79 + sheet_data += current_item.prop + ": " + current_item.value; 1.80 + sheet_data += "}"; 1.81 + } 1.82 + 1.83 + var sheet_url = "data:text/css," + escape(sheet_data); 1.84 + 1.85 + var doc_data = 1.86 + "<!DOCTYPE HTML>\n" + 1.87 + "<link rel='stylesheet' type='text/css' href='" + sheet_url + "'>\n" + 1.88 + "<link rel='stylesheet' type='text/css' href='" + sheet_url + "'>\n" + 1.89 + "<body>\n"; 1.90 + 1.91 + 1.92 + for (var idx = 0; idx < test_queue.length; ++idx) { 1.93 + var current_item = test_queue[idx]; 1.94 + 1.95 + if ("inherited_value" in current_item) { 1.96 + doc_data += "<span id='parent"+idx+"'>"; 1.97 + } 1.98 + doc_data += "<span id='test"+idx+"'></span>"; 1.99 + if ("inherited_value" in current_item) { 1.100 + doc_data += "</span>"; 1.101 + } 1.102 + } 1.103 + 1.104 + var doc_url = "data:text/html," + escape(doc_data); 1.105 + iframe.onload = iframe_loaded; 1.106 + iframe.src = doc_url; 1.107 +} 1.108 + 1.109 +function iframe_loaded(event) 1.110 +{ 1.111 + if (event.target != iframe) 1.112 + return; 1.113 + 1.114 + var start_ser = []; 1.115 + var start_compute = []; 1.116 + var test_cs = []; 1.117 + var ifdoc = iframe.contentDocument; 1.118 + 1.119 + for (var idx = 0; idx < test_queue.length; ++idx) { 1.120 + var current_item = test_queue[idx]; 1.121 + var info = gCSSProperties[current_item.prop]; 1.122 + 1.123 + var test = ifdoc.getElementById("test" + idx); 1.124 + var cur_cs = iframe.contentWindow.getComputedStyle(test, ""); 1.125 + test_cs.push(cur_cs); 1.126 + var cur_ser = ifdoc.styleSheets[0].cssRules[3*idx+2].style.getPropertyValue(current_item.prop); 1.127 + if (cur_ser == "") { 1.128 + isnot(cur_ser, "", 1.129 + "serialization should be nonempty for " + 1.130 + current_item.prop + ": " + current_item.value); 1.131 + } 1.132 + start_ser.push(cur_ser); 1.133 + 1.134 + var cur_compute; 1.135 + if (!("backend_only" in info)) { 1.136 + cur_compute = get_computed_value(cur_cs, current_item.prop); 1.137 + if (cur_compute == "") { 1.138 + isnot(cur_compute, "", 1.139 + "computed value should be nonempty for " + 1.140 + current_item.prop + ": " + current_item.value); 1.141 + } 1.142 + } else { 1.143 + cur_compute = undefined; 1.144 + } 1.145 + start_compute.push(cur_compute); 1.146 + } 1.147 + 1.148 + // In case the above access didn't force a clone already (though it 1.149 + // currently does), clone the second style sheet's inner and then 1.150 + // remove the first. 1.151 + ifdoc.styleSheets[1].insertRule("#nonexistent { color: red }", 0); 1.152 + var firstlink = ifdoc.getElementsByTagName("link")[0]; 1.153 + firstlink.parentNode.removeChild(firstlink); 1.154 + 1.155 + // Force a flush 1.156 + ifdoc.body.style.display="none"; 1.157 + var ow = ifdoc.body.offsetWidth; 1.158 + ifdoc.body.style.display=""; 1.159 + 1.160 + for (var idx = 0; idx < test_queue.length; ++idx) { 1.161 + var current_item = test_queue[idx]; 1.162 + var info = gCSSProperties[current_item.prop]; 1.163 + 1.164 + var end_ser = 1.165 + ifdoc.styleSheets[0].cssRules[3*idx+3].style.getPropertyValue(current_item.prop); 1.166 + is(end_ser, start_ser[idx], 1.167 + "serialization should match when cloning " + 1.168 + current_item.prop + ": " + current_item.value); 1.169 + 1.170 + if (!("backend_only" in info)) { 1.171 + var end_compute = get_computed_value(test_cs[idx], current_item.prop); 1.172 + // Output computed values only when the test failed. 1.173 + // Computed values may be very long. 1.174 + if (end_compute == start_compute[idx]) { 1.175 + ok(true, 1.176 + "computed values should match when cloning " + 1.177 + current_item.prop + ": " + current_item.value); 1.178 + } else { 1.179 + is(end_compute, start_compute[idx], 1.180 + "computed values should match when cloning " + 1.181 + current_item.prop + ": " + current_item.value); 1.182 + } 1.183 + } 1.184 + } 1.185 + 1.186 + SimpleTest.finish(); 1.187 +} 1.188 + 1.189 +</script> 1.190 +</pre> 1.191 +</body> 1.192 +</html>