layout/style/test/test_inherit_computation.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/test/test_inherit_computation.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,161 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +-->
     1.8 +<head>
     1.9 +  <title>Test for computation of CSS 'inherit' on all properties and 'unset' on inherited 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 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.14 +</head>
    1.15 +<body>
    1.16 +<p id="display"><span id="fparent"><span id="fchild"></span></span></p>
    1.17 +<div id="content" style="display: none">
    1.18 +
    1.19 +<div id="testnode"><span id="nparent"><span id="nchild"></span></span></div>
    1.20 +  
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +
    1.25 +/** Test for computation of CSS 'inherit' on all properties and 'unset' on
    1.26 +    inherited properties **/
    1.27 +
    1.28 +// elements without a frame
    1.29 +var gNParent = document.getElementById("nparent");
    1.30 +var gNChild = document.getElementById("nchild");
    1.31 +// elements with a frame
    1.32 +var gFParent = document.getElementById("fparent");
    1.33 +var gFChild = document.getElementById("fchild");
    1.34 +
    1.35 +var gStyleSheet = document.getElementById("stylesheet").sheet;
    1.36 +var gChildRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #fchild {}", gStyleSheet.cssRules.length)];
    1.37 +var gChildRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #fchild {}", gStyleSheet.cssRules.length)];
    1.38 +var gChildRule3 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild.allother, #fchild.allother {}", gStyleSheet.cssRules.length)];
    1.39 +var gChildRuleTop = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #nchild.allother, #fchild, #fchild.allother {}", gStyleSheet.cssRules.length)];
    1.40 +var gParentRuleTop = gStyleSheet.cssRules[gStyleSheet.insertRule("#nparent, #fparent {}", gStyleSheet.cssRules.length)];
    1.41 +
    1.42 +var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled");
    1.43 +
    1.44 +function get_computed_value_node(node, property)
    1.45 +{
    1.46 +  var cs = getComputedStyle(node, "");
    1.47 +  return get_computed_value(cs, property);
    1.48 +}
    1.49 +
    1.50 +function test_property(property)
    1.51 +{
    1.52 +  var info = gCSSProperties[property];
    1.53 +  if (info.backend_only)
    1.54 +    return;
    1.55 +
    1.56 +  var keywords = ["inherit"];
    1.57 +  if (info.inherited && gTestUnset)
    1.58 +    keywords.push("unset");
    1.59 +
    1.60 +  keywords.forEach(function(keyword) {
    1.61 +    if ("prerequisites" in info) {
    1.62 +      var prereqs = info.prerequisites;
    1.63 +      for (var prereq in prereqs) {
    1.64 +        gParentRuleTop.style.setProperty(prereq, prereqs[prereq], "");
    1.65 +        gChildRuleTop.style.setProperty(prereq, prereqs[prereq], "");
    1.66 +      }
    1.67 +    }
    1.68 +
    1.69 +    if (info.inherited) {
    1.70 +      gParentRuleTop.style.setProperty(property, info.initial_values[0], "");
    1.71 +      var initial_computed_n = get_computed_value_node(gNChild, property);
    1.72 +      var initial_computed_f = get_computed_value_node(gFChild, property);
    1.73 +      gChildRule1.style.setProperty(property, info.other_values[0], "");
    1.74 +      var other_computed_n = get_computed_value_node(gNChild, property);
    1.75 +      var other_computed_f = get_computed_value_node(gFChild, property);
    1.76 +      isnot(other_computed_n, initial_computed_n,
    1.77 +            "should be testing with values that compute to different things " +
    1.78 +            "for '" + property + "'");
    1.79 +      isnot(other_computed_f, initial_computed_f,
    1.80 +            "should be testing with values that compute to different things " +
    1.81 +            "for '" + property + "'");
    1.82 +      gChildRule3.style.setProperty(property, keyword, "");
    1.83 +      gFChild.className="allother";
    1.84 +      gNChild.className="allother";
    1.85 +      var inherit_initial_computed_n = get_computed_value_node(gNChild, property);
    1.86 +      var inherit_initial_computed_f = get_computed_value_node(gFChild, property);
    1.87 +      is(inherit_initial_computed_n, initial_computed_n,
    1.88 +         keyword + " should cause inheritance of initial value for '" +
    1.89 +         property + "'");
    1.90 +      is(inherit_initial_computed_f, initial_computed_f,
    1.91 +         keyword + " should cause inheritance of initial value for '" +
    1.92 +         property + "'");
    1.93 +      gParentRuleTop.style.setProperty(property, info.other_values[0], "");
    1.94 +      var inherit_other_computed_n = get_computed_value_node(gNChild, property);
    1.95 +      var inherit_other_computed_f = get_computed_value_node(gFChild, property);
    1.96 +      is(inherit_other_computed_n, other_computed_n,
    1.97 +         keyword + " should cause inheritance of other value for '" +
    1.98 +         property + "'");
    1.99 +      is(inherit_other_computed_f, other_computed_f,
   1.100 +         keyword + " should cause inheritance of other value for '" +
   1.101 +         property + "'");
   1.102 +      gParentRuleTop.style.removeProperty(property);
   1.103 +      gChildRule1.style.removeProperty(property);
   1.104 +      gChildRule3.style.setProperty(property, info.other_values[0], "");
   1.105 +      gFChild.className="";
   1.106 +      gNChild.className="";
   1.107 +    } else {
   1.108 +      gParentRuleTop.style.setProperty(property, info.other_values[0], "");
   1.109 +      var initial_computed_n = get_computed_value_node(gNChild, property);
   1.110 +      var initial_computed_f = get_computed_value_node(gFChild, property);
   1.111 +      var other_computed_n = get_computed_value_node(gNParent, property);
   1.112 +      var other_computed_f = get_computed_value_node(gFParent, property);
   1.113 +      isnot(other_computed_n, initial_computed_n,
   1.114 +            "should be testing with values that compute to different things " +
   1.115 +            "for '" + property + "'");
   1.116 +      isnot(other_computed_f, initial_computed_f,
   1.117 +            "should be testing with values that compute to different things " +
   1.118 +            "for '" + property + "'");
   1.119 +      gChildRule2.style.setProperty(property, keyword, "");
   1.120 +      var inherit_other_computed_n = get_computed_value_node(gNChild, property);
   1.121 +      var inherit_other_computed_f = get_computed_value_node(gFChild, property);
   1.122 +      is(inherit_other_computed_n, other_computed_n,
   1.123 +         keyword + " should cause inheritance of other value for '" +
   1.124 +         property + "'");
   1.125 +      is(inherit_other_computed_f, other_computed_f,
   1.126 +         keyword + " should cause inheritance of other value for '" +
   1.127 +         property + "'");
   1.128 +      gParentRuleTop.style.removeProperty(property);
   1.129 +      gChildRule1.style.setProperty(property, info.other_values[0], "");
   1.130 +      var inherit_initial_computed_n = get_computed_value_node(gNChild, property);
   1.131 +      var inherit_initial_computed_f = get_computed_value_node(gFChild, property);
   1.132 +      is(inherit_initial_computed_n, initial_computed_n,
   1.133 +         keyword + " should cause inheritance of initial value for '" +
   1.134 +         property + "'");
   1.135 +      is(inherit_initial_computed_f, initial_computed_f,
   1.136 +         keyword + " should cause inheritance of initial value for '" +
   1.137 +         property + "'");
   1.138 +      gParentRuleTop.style.removeProperty(property);
   1.139 +      gChildRule1.style.removeProperty(property);
   1.140 +      gChildRule2.style.removeProperty(property);
   1.141 +    }
   1.142 +
   1.143 +    if ("prerequisites" in info) {
   1.144 +      var prereqs = info.prerequisites;
   1.145 +      for (var prereq in prereqs) {
   1.146 +        gParentRuleTop.style.removeProperty(prereq);
   1.147 +        gChildRuleTop.style.removeProperty(prereq);
   1.148 +      }
   1.149 +    }
   1.150 +  });
   1.151 +}
   1.152 +
   1.153 +for (var prop in gCSSProperties) {
   1.154 +  var info = gCSSProperties[prop];
   1.155 +  gChildRule3.style.setProperty(prop, info.other_values[0], "");
   1.156 +}
   1.157 +
   1.158 +for (var prop in gCSSProperties)
   1.159 +  test_property(prop);
   1.160 +
   1.161 +</script>
   1.162 +</pre>
   1.163 +</body>
   1.164 +</html>

mercurial