1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
6 span.c1:nth-of-type(
2n -
1){ color: red; }
7 span.c1:nth-of-type(
2n){ color: green; }
8 span.c2:nth-of-type(odd){ color: red; }
9 span.c2:nth-of-type(even){ color: green; }
10 span.c3:nth-of-type(n3){ color: red; }
11 span.c3:nth-of-type(foo){ color: green; }
12 span.c4:nth-of-type(
2n3){ color: red; }
13 span.c4:nth-of-type(foon + bar ){ color: green; }
19 <p id=
"description"></p>
20 debug(
"These spans should alternate red and green");
21 <div id=
"test1"></div>
22 debug(
"These spans should alternate red and green");
23 <div id=
"test2"></div>
24 debug(
"These spans should be black");
25 <div id=
"test3"></div>
26 debug(
"These spans should be black");
27 <div id=
"test4"></div>
35 str
+= '<span class="c' + i
+ '" id="span' + i
+ j
+ '"> span </span>';
37 document
.getElementById("test"+i
).innerHTML
= str
;
42 <div id=
"console"></div>
44 description('This test passes if the nth-of-type can accept a parameter that is an+b, odd or even. But it does not accept any other parameter.');
46 el
= document
.querySelector("span.c1:nth-of-type(2n -1)");
47 shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(255, 0, 0)'");
49 el
= document
.querySelector("span.c1:nth-of-type(2n)");
50 shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 128, 0)'");
52 el
= document
.querySelector("span.c2:nth-of-type(odd)");
53 shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(255, 0, 0)'");
55 el
= document
.querySelector("span.c2:nth-of-type(even)");
56 shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('color')", "'rgb(0, 128, 0)'");
58 shouldThrow('document.querySelector("span.c3:nth-of-type(n3)")', '"SyntaxError: Failed to execute \'querySelector\' on \'Document\': \'span.c3:nth-of-type(n3)\' is not a valid selector."');
60 shouldThrow('document.querySelector("span.c3:nth-of-type(foo)")', '"SyntaxError: Failed to execute \'querySelector\' on \'Document\': \'span.c3:nth-of-type(foo)\' is not a valid selector."');
62 shouldThrow('document.querySelector("span.c3:nth-of-type(2n3)")', '"SyntaxError: Failed to execute \'querySelector\' on \'Document\': \'span.c3:nth-of-type(2n3)\' is not a valid selector."');
64 shouldThrow('document.querySelector("span.c3:nth-of-type(foon + bar)")', '"SyntaxError: Failed to execute \'querySelector\' on \'Document\': \'span.c3:nth-of-type(foon + bar)\' is not a valid selector."');