forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_of_type_selectors.xhtml
98 lines (84 loc) · 3.36 KB
/
test_of_type_selectors.xhtml
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
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=75375
-->
<head>
<title>Test for *-of-type selectors in Bug 75375</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=75375">Mozilla Bug 75375</a>
<div id="content" style="display: none"
xmlns:html="http://www.w3.org/1999/xhtml">
<p>This is a <code>p</code> element in the HTML namespace.</p>
<p>This is a second <code>p</code> element in the HTML namespace.</p>
<html:p>This is an <code>html:p</code> element in the HTML namespace.</html:p>
<p xmlns="http://www.example.com/ns">This is a <code>p</code> element in the <code>http://www.example.com/ns</code> namespace.</p>
<html:address>This is an <code>html:address</code> element in the HTML namespace.</html:address>
<address xmlns="">This is a <code>address</code> element in no namespace.</address>
<address xmlns="">This is a <code>address</code> element in no namespace.</address>
<p xmlns="">This is a <code>p</code> element in no namespace.</p>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for *-of-type selectors in Bug 75375 **/
var HTML_NS = "http://www.w3.org/1999/xhtml";
function setup_style_text() {
var result = document.createCDATASection("");
var style = document.createElementNS(HTML_NS, "style");
style.appendChild(result);
document.getElementsByTagName("head")[0].appendChild(style);
return result;
}
function run() {
var styleText = setup_style_text();
var elements = [];
var div = document.getElementById("content");
for (var i = 0; i < div.childNodes.length; ++i) {
var child = div.childNodes[i];
if (child.nodeType == Node.ELEMENT_NODE)
elements.push(child);
}
var counter = 0;
function test_selector(selector, match_indices, notmatch_indices)
{
var zi = ++counter;
styleText.data = selector + " { z-index: " + zi + " }";
var i;
for (i in match_indices) {
var e = elements[match_indices[i]];
is(getComputedStyle(e, "").zIndex, zi,
"element " + match_indices[i] + " matched " + selector);
}
for (i in notmatch_indices) {
var e = elements[notmatch_indices[i]];
is(getComputedStyle(e, "").zIndex, "auto",
"element " + notmatch_indices[i] + " did not match " + selector);
}
}
// 0 - html:p
// 1 - html:p
// 2 - html:p
// 3 - example:p
// 4 - html:address
// 5 - :address
// 6 - :address
// 7 - :p
test_selector(":nth-of-type(1)", [0, 3, 4, 5, 7], [1, 2, 6]);
test_selector(":nth-last-of-type(1)", [2, 3, 4, 6, 7], [0, 1, 5]);
test_selector(":nth-last-of-type(-n+1)", [2, 3, 4, 6, 7], [0, 1, 5]);
test_selector(":nth-of-type(even)", [1, 6], [0, 2, 3, 4, 5, 7]);
test_selector(":nth-last-of-type(odd)", [0, 2, 3, 4, 6, 7], [1, 5]);
test_selector(":nth-last-of-type(n+2)", [0, 1, 5], [2, 3, 4, 6, 7]);
test_selector(":first-of-type", [0, 3, 4, 5, 7], [1, 2, 6]);
test_selector(":last-of-type", [2, 3, 4, 6, 7], [0, 1, 5]);
test_selector(":only-of-type", [3, 4, 7], [0, 1, 2, 5, 6]);
}
run();
]]>
</script>
</pre>
</body>
</html>