summaryrefslogtreecommitdiff
path: root/layout/style/test/test_bug73586.html
blob: a88ae0a30168934a9ca00546c353df4050e26253 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=73586
-->
<head>
  <title>Test for Bug 73586</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <style type="text/css">

  span { background: white; color: black; border: medium solid black; }

  </style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=73586">Mozilla Bug 73586</a>
<div id="display"></div>

<div id="content" style="display: none">
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 73586 **/

const GREEN = "rgb(0, 128, 0)";
const LIME = "rgb(0, 255, 0)";
const BLACK = "rgb(0, 0, 0)";
const WHITE = "rgb(255, 255, 255)";

function cs(elt) { return getComputedStyle(elt, ""); }

function check_children(p, check_cb) {
    var len = p.childNodes.length;
    var elts = 0;
    var i, elt, child;
    for (i = 0; i < len; ++i) {
      if (p.childNodes[i].nodeType == Node.ELEMENT_NODE)
        ++elts;
    }

    elt = 0;
    for (i = 0; i < len; ++i) {
        child = p.childNodes[i];
        if (child.nodeType != Node.ELEMENT_NODE)
            continue;
        check_cb(child, elt, elts, i, len);
        ++elt;
    }
}

var display = document.getElementById("display");

function run_series(check_cb) {
    var display = document.getElementById("display");
    // Use a new parent node every time since the optimizations cause
    // bits to be set (permanently) on the parent.
    var p = document.createElement("p");
    display.appendChild(p);
    p.innerHTML = "x<span></span><span></span>";

    check_children(p, check_cb);
    var text = p.removeChild(p.childNodes[0]);
    check_children(p, check_cb);
    var span = p.removeChild(p.childNodes[0]);
    check_children(p, check_cb);
    p.appendChild(span);
    check_children(p, check_cb);
    p.removeChild(span);
    check_children(p, check_cb);
    p.insertBefore(span, p.childNodes[0]);
    check_children(p, check_cb);
    p.removeChild(span);
    check_children(p, check_cb);
    p.insertBefore(span, null);
    check_children(p, check_cb);
    p.appendChild(document.createElement("span"));
    check_children(p, check_cb);
    p.insertBefore(document.createElement("span"), p.childNodes[2]);
    check_children(p, check_cb);
    p.appendChild(text);
    check_children(p, check_cb);

    display.removeChild(p);
}

var style = document.createElement("style");
style.setAttribute("type", "text/css");
var styleText = document.createTextNode("");
style.appendChild(styleText);
document.getElementsByTagName("head")[0].appendChild(style);

styleText.data = "span:first-child { background: lime; }";
run_series(function(child, elt, elts, node, nodes) {
        is(cs(child).backgroundColor, (elt == 0) ? LIME : WHITE,
           "child " + node + " should " + ((elt == 0) ? "" : "NOT ") +
           " match :first-child");
    });

styleText.data = "span:last-child { color: green; }";
run_series(function(child, elt, elts, node, nodes) {
        is(cs(child).color, (elt == elts - 1) ? GREEN : BLACK,
           "child " + node + " should " + ((elt == elts - 1) ? "" : "NOT ") +
           " match :last-child");
    });

styleText.data = "span:only-child { border: medium solid green; }";
run_series(function(child, elt, elts, node, nodes) {
        is(cs(child).borderTopColor, (elts == 1) ? GREEN : BLACK,
           "child " + node + " should " + ((elts == 1) ? "" : "NOT ") +
           " match :only-child");
    });

styleText.data = "span:-moz-first-node { text-decoration: underline; }";
run_series(function(child, elt, elts, node, nodes) {
        is(cs(child).textDecoration, (node == 0) ? "underline" : "none",
           "child " + node + " should " + ((node == 0) ? "" : "NOT ") +
           " match :-moz-first-node");
    });

styleText.data = "span:-moz-last-node { visibility: hidden; }";
run_series(function(child, elt, elts, node, nodes) {
        is(cs(child).visibility, (node == nodes - 1) ? "hidden" : "visible",
           "child " + node + " should " + ((node == nodes - 1) ? "" : "NOT ") +
           " match :-moz-last-node");
    });

styleText.data = "span:nth-child(1) { background: lime; }";
run_series(function(child, elt, elts, node, nodes) {
        var matches = elt == 0;
        is(cs(child).backgroundColor, matches ? LIME : WHITE,
           "child " + node + " should " + (matches ? "" : "NOT ") +
           " match " + styleText.data);
    });

styleText.data = "span:nth-last-child(0n+2) { color: green; }";
run_series(function(child, elt, elts, node, nodes) {
        var matches = (elt == elts - 2);
        is(cs(child).color, matches ? GREEN : BLACK,
           "child " + node + " should " + (matches ? "" : "NOT ") +
           " match " + styleText.data);
    });

styleText.data = "span:nth-of-type(2n+3) { color: green; }";
run_series(function(child, elt, elts, node, nodes) {
        var nidx = elt + 1;
        var matches = nidx % 2 == 1 && nidx >= 3;
        is(cs(child).color, matches ? GREEN : BLACK,
           "child " + node + " should " + (matches ? "" : "NOT ") +
           " match " + styleText.data);
    });

styleText.data = "span:nth-last-of-type(-2n+5) { color: green; }";
run_series(function(child, elt, elts, node, nodes) {
        var nlidx = elts - elt;
        var matches = nlidx % 2 == 1 && nlidx <= 5;
        is(cs(child).color, matches ? GREEN : BLACK,
           "child " + node + " should " + (matches ? "" : "NOT ") +
           " match " + styleText.data);
    });

styleText.data = "span:first-of-type { color: green; }";
run_series(function(child, elt, elts, node, nodes) {
        var matches = (elt == 0);
        is(cs(child).color, matches ? GREEN : BLACK,
           "child " + node + " should " + (matches ? "" : "NOT ") +
           " match " + styleText.data);
    });

styleText.data = "span:last-of-type { color: green; }";
run_series(function(child, elt, elts, node, nodes) {
        var matches = (elt == elts - 1);
        is(cs(child).color, matches ? GREEN : BLACK,
           "child " + node + " should " + (matches ? "" : "NOT ") +
           " match " + styleText.data);
    });

styleText.data = "span:only-of-type { color: green; }";
run_series(function(child, elt, elts, node, nodes) {
        var matches = elts == 1;
        is(cs(child).color, matches ? GREEN : BLACK,
           "child " + node + " should " + (matches ? "" : "NOT ") +
           " match " + styleText.data);
    });

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