1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_initial_computation.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,165 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +--> 1.8 +<head> 1.9 + <title>Test for computation of CSS 'initial' on all properties and 'unset' on reset properties</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 + <style type="text/css" id="stylesheet"></style> 1.13 + <style type="text/css"> 1.14 + /* For 'width', 'height', etc., need a constant size container. */ 1.15 + #display { width: 500px; height: 200px } 1.16 + </style> 1.17 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.18 + <script type="text/javascript"> 1.19 + SimpleTest.waitForExplicitFinish(); 1.20 + 1.21 + var load_count = 0; 1.22 + function load_done() { 1.23 + if (++load_count == 3) 1.24 + run_tests(); 1.25 + } 1.26 + </script> 1.27 +</head> 1.28 +<body> 1.29 +<p id="display"><span><span id="elementf"></span></span> 1.30 +<iframe id="unstyledn" src="unstyled.xml" height="10" width="10" onload="load_done()"></iframe> 1.31 +<iframe id="unstyledf" src="unstyled-frame.xml" height="10" width="10" onload="load_done()"></iframe> 1.32 +</p> 1.33 +<div id="content" style="display: none"> 1.34 + 1.35 +<div><span id="elementn"></span></div> 1.36 + 1.37 + 1.38 +</div> 1.39 +<pre id="test"> 1.40 +<script class="testbody" type="text/javascript"> 1.41 + 1.42 +/** Test for computation of CSS 'initial' on all properties and 'unset' on 1.43 + reset properties **/ 1.44 + 1.45 +var gBrokenInitial = { 1.46 +}; 1.47 + 1.48 +function xfail_initial(property) { 1.49 + return property in gBrokenInitial; 1.50 +} 1.51 + 1.52 +var gElementN = document.getElementById("elementn"); 1.53 +var gElementF = document.getElementById("elementf"); 1.54 +var gStyleSheet = document.getElementById("stylesheet").sheet; 1.55 +var gRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)]; 1.56 +var gRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#elementn, #elementf {}", gStyleSheet.cssRules.length)]; 1.57 + 1.58 +var gInitialValuesN; 1.59 +var gInitialValuesF; 1.60 +var gInitialPrereqsRuleN; 1.61 +var gInitialPrereqsRuleF; 1.62 + 1.63 +var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled"); 1.64 + 1.65 +function setup_initial_values(id, ivalprop, prereqprop) { 1.66 + var iframe = document.getElementById(id); 1.67 + window[ivalprop] = iframe.contentWindow.getComputedStyle( 1.68 + iframe.contentDocument.documentElement.firstChild, ""); 1.69 + var sheet = iframe.contentDocument.styleSheets[0]; 1.70 + // For 'width', 'height', etc., need a constant size container. 1.71 + sheet.insertRule(":root { height: 200px; width: 500px }", sheet.cssRules.length); 1.72 + 1.73 + window[prereqprop] = sheet.cssRules[sheet.insertRule(":root > * {}", sheet.cssRules.length)]; 1.74 +} 1.75 + 1.76 +function test_property(property) 1.77 +{ 1.78 + var info = gCSSProperties[property]; 1.79 + if (info.backend_only) 1.80 + return; 1.81 + 1.82 + var keywords = ["initial"]; 1.83 + if (!info.inherited && gTestUnset) 1.84 + keywords.push("unset"); 1.85 + 1.86 + keywords.forEach(function(keyword) { 1.87 + if ("prerequisites" in info) { 1.88 + var prereqs = info.prerequisites; 1.89 + for (var prereq in prereqs) { 1.90 + gRule1.style.setProperty(prereq, prereqs[prereq], ""); 1.91 + gInitialPrereqsRuleN.style.setProperty(prereq, prereqs[prereq], ""); 1.92 + gInitialPrereqsRuleF.style.setProperty(prereq, prereqs[prereq], ""); 1.93 + } 1.94 + } 1.95 + if (info.inherited) { 1.96 + gElementN.parentNode.style.setProperty(property, info.other_values[0], ""); 1.97 + gElementF.parentNode.style.setProperty(property, info.other_values[0], ""); 1.98 + } 1.99 + 1.100 + var initial_computed_n = get_computed_value(gInitialValuesN, property); 1.101 + var initial_computed_f = get_computed_value(gInitialValuesF, property); 1.102 + gRule1.style.setProperty(property, info.other_values[0], ""); 1.103 + var other_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property); 1.104 + var other_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property); 1.105 + isnot(other_computed_n, initial_computed_n, 1.106 + "should be testing with values that compute to different things " + 1.107 + "for '" + property + "'"); 1.108 + isnot(other_computed_f, initial_computed_f, 1.109 + "should be testing with values that compute to different things " + 1.110 + "for '" + property + "'"); 1.111 + // It's important (given the current design of nsRuleNode) that we're 1.112 + // modifying the most specific rule that matches the element, and that 1.113 + // we've already requested style while that rule was empty. This 1.114 + // means we'll have a cached aStartStruct from the parent in the rule 1.115 + // tree (caching the "other" value), so we'll make sure we don't get 1.116 + // the initial value from the luck of default-initialization. 1.117 + // This means that it's important that we set the prereqs on 1.118 + // gRule1.style rather than on gElement.style. 1.119 + gRule2.style.setProperty(property, keyword, ""); 1.120 + var initial_val_computed_n = get_computed_value(getComputedStyle(gElementN, ""), property); 1.121 + var initial_val_computed_f = get_computed_value(getComputedStyle(gElementF, ""), property); 1.122 + (xfail_initial(property) ? todo_is : is)( 1.123 + initial_val_computed_n, initial_computed_n, 1.124 + keyword + " should cause initial value for '" + property + "'"); 1.125 + (xfail_initial(property) ? todo_is : is)( 1.126 + initial_val_computed_f, initial_computed_f, 1.127 + keyword + " should cause initial value for '" + property + "'"); 1.128 + gRule1.style.removeProperty(property); 1.129 + gRule2.style.removeProperty(property); 1.130 + 1.131 + if ("prerequisites" in info) { 1.132 + var prereqs = info.prerequisites; 1.133 + for (var prereq in prereqs) { 1.134 + gRule1.style.removeProperty(prereq); 1.135 + gInitialPrereqsRuleN.style.removeProperty(prereq); 1.136 + gInitialPrereqsRuleF.style.removeProperty(prereq); 1.137 + } 1.138 + } 1.139 + if (info.inherited) { 1.140 + gElementN.parentNode.style.removeProperty(property); 1.141 + gElementF.parentNode.style.removeProperty(property); 1.142 + } 1.143 + 1.144 + // FIXME: Something (maybe with the -moz-binding values in 1.145 + // test_value_computation.html, but may as well do it here to match) 1.146 + // causes gElementF's frame to get lost. Force it to get recreated 1.147 + // after each property. 1.148 + gElementF.parentNode.style.display = "none"; 1.149 + get_computed_value(getComputedStyle(gElementF, ""), "width"); 1.150 + gElementF.parentNode.style.display = ""; 1.151 + get_computed_value(getComputedStyle(gElementF, ""), "width"); 1.152 + }); 1.153 +} 1.154 + 1.155 +function run_tests() { 1.156 + setup_initial_values("unstyledn", "gInitialValuesN", "gInitialPrereqsRuleN"); 1.157 + setup_initial_values("unstyledf", "gInitialValuesF", "gInitialPrereqsRuleF"); 1.158 + for (var prop in gCSSProperties) 1.159 + test_property(prop); 1.160 + SimpleTest.finish(); 1.161 +} 1.162 + 1.163 +load_done(); 1.164 + 1.165 +</script> 1.166 +</pre> 1.167 +</body> 1.168 +</html>