summaryrefslogtreecommitdiff
path: root/layout/style/test/test_inherit_computation.html
blob: a4407418cac234b9eac1472a431dc3b6de6f6eef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
  <title>Test for computation of CSS 'inherit' on all properties and 'unset' on inherited properties</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="property_database.js"></script>
  <style type="text/css" id="stylesheet"></style>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"><span id="fparent"><span id="fchild"></span></span></p>
<div id="content" style="display: none">

<div id="testnode"><span id="nparent"><span id="nchild"></span></span></div>
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for computation of CSS 'inherit' on all properties and 'unset' on
    inherited properties **/

// elements without a frame
var gNParent = document.getElementById("nparent");
var gNChild = document.getElementById("nchild");
// elements with a frame
var gFParent = document.getElementById("fparent");
var gFChild = document.getElementById("fchild");

var gStyleSheet = document.getElementById("stylesheet").sheet;
var gChildRule1 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #fchild {}", gStyleSheet.cssRules.length)];
var gChildRule2 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #fchild {}", gStyleSheet.cssRules.length)];
var gChildRule3 = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild.allother, #fchild.allother {}", gStyleSheet.cssRules.length)];
var gChildRuleTop = gStyleSheet.cssRules[gStyleSheet.insertRule("#nchild, #nchild.allother, #fchild, #fchild.allother {}", gStyleSheet.cssRules.length)];
var gParentRuleTop = gStyleSheet.cssRules[gStyleSheet.insertRule("#nparent, #fparent {}", gStyleSheet.cssRules.length)];

var gTestUnset = SpecialPowers.getBoolPref("layout.css.unset-value.enabled");

function get_computed_value_node(node, property)
{
  var cs = getComputedStyle(node, "");
  return get_computed_value(cs, property);
}

function test_property(property)
{
  var info = gCSSProperties[property];

  var keywords = ["inherit"];
  if (info.inherited && gTestUnset)
    keywords.push("unset");

  keywords.forEach(function(keyword) {
    if ("prerequisites" in info) {
      var prereqs = info.prerequisites;
      for (var prereq in prereqs) {
        gParentRuleTop.style.setProperty(prereq, prereqs[prereq], "");
        gChildRuleTop.style.setProperty(prereq, prereqs[prereq], "");
      }
    }

    if (info.inherited) {
      gParentRuleTop.style.setProperty(property, info.initial_values[0], "");
      var initial_computed_n = get_computed_value_node(gNChild, property);
      var initial_computed_f = get_computed_value_node(gFChild, property);
      gChildRule1.style.setProperty(property, info.other_values[0], "");
      var other_computed_n = get_computed_value_node(gNChild, property);
      var other_computed_f = get_computed_value_node(gFChild, property);
      isnot(other_computed_n, initial_computed_n,
            "should be testing with values that compute to different things " +
            "for '" + property + "'");
      isnot(other_computed_f, initial_computed_f,
            "should be testing with values that compute to different things " +
            "for '" + property + "'");
      gChildRule3.style.setProperty(property, keyword, "");
      gFChild.className="allother";
      gNChild.className="allother";
      var inherit_initial_computed_n = get_computed_value_node(gNChild, property);
      var inherit_initial_computed_f = get_computed_value_node(gFChild, property);
      is(inherit_initial_computed_n, initial_computed_n,
         keyword + " should cause inheritance of initial value for '" +
         property + "'");
      is(inherit_initial_computed_f, initial_computed_f,
         keyword + " should cause inheritance of initial value for '" +
         property + "'");
      gParentRuleTop.style.setProperty(property, info.other_values[0], "");
      var inherit_other_computed_n = get_computed_value_node(gNChild, property);
      var inherit_other_computed_f = get_computed_value_node(gFChild, property);
      is(inherit_other_computed_n, other_computed_n,
         keyword + " should cause inheritance of other value for '" +
         property + "'");
      is(inherit_other_computed_f, other_computed_f,
         keyword + " should cause inheritance of other value for '" +
         property + "'");
      gParentRuleTop.style.removeProperty(property);
      gChildRule1.style.removeProperty(property);
      gChildRule3.style.setProperty(property, info.other_values[0], "");
      gFChild.className="";
      gNChild.className="";
    } else {
      gParentRuleTop.style.setProperty(property, info.other_values[0], "");
      var initial_computed_n = get_computed_value_node(gNChild, property);
      var initial_computed_f = get_computed_value_node(gFChild, property);
      var other_computed_n = get_computed_value_node(gNParent, property);
      var other_computed_f = get_computed_value_node(gFParent, property);
      isnot(other_computed_n, initial_computed_n,
            "should be testing with values that compute to different things " +
            "for '" + property + "'");
      isnot(other_computed_f, initial_computed_f,
            "should be testing with values that compute to different things " +
            "for '" + property + "'");
      gChildRule2.style.setProperty(property, keyword, "");
      var inherit_other_computed_n = get_computed_value_node(gNChild, property);
      var inherit_other_computed_f = get_computed_value_node(gFChild, property);
      is(inherit_other_computed_n, other_computed_n,
         keyword + " should cause inheritance of other value for '" +
         property + "'");
      is(inherit_other_computed_f, other_computed_f,
         keyword + " should cause inheritance of other value for '" +
         property + "'");
      gParentRuleTop.style.removeProperty(property);
      gChildRule1.style.setProperty(property, info.other_values[0], "");
      var inherit_initial_computed_n = get_computed_value_node(gNChild, property);
      var inherit_initial_computed_f = get_computed_value_node(gFChild, property);
      is(inherit_initial_computed_n, initial_computed_n,
         keyword + " should cause inheritance of initial value for '" +
         property + "'");
      is(inherit_initial_computed_f, initial_computed_f,
         keyword + " should cause inheritance of initial value for '" +
         property + "'");
      gParentRuleTop.style.removeProperty(property);
      gChildRule1.style.removeProperty(property);
      gChildRule2.style.removeProperty(property);
    }

    if ("prerequisites" in info) {
      var prereqs = info.prerequisites;
      for (var prereq in prereqs) {
        gParentRuleTop.style.removeProperty(prereq);
        gChildRuleTop.style.removeProperty(prereq);
      }
    }
  });
}

for (var prop in gCSSProperties) {
  var info = gCSSProperties[prop];
  gChildRule3.style.setProperty(prop, info.other_values[0], "");
}

for (var prop in gCSSProperties)
  test_property(prop);

</script>
</pre>
</body>
</html>