|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test for CSS Selectors</title> |
|
5 <!-- |
|
6 Separate from test_selectors.html so we don't need to deal with |
|
7 waiting for the binding document to load. |
|
8 --> |
|
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
11 <style type="text/css"> |
|
12 |
|
13 #display { -moz-binding: url(xbl_bindings.xml#onedivchild); } |
|
14 |
|
15 </style> |
|
16 </head> |
|
17 <body onload="run()"> |
|
18 <div id="display"></div> |
|
19 <pre id="test"> |
|
20 <script class="testbody" type="text/javascript"> |
|
21 |
|
22 SimpleTest.waitForExplicitFinish(); |
|
23 |
|
24 function run() { |
|
25 |
|
26 function setup_style() { |
|
27 var style_elem = document.createElement("style"); |
|
28 style_elem.setAttribute("type", "text/css"); |
|
29 document.getElementsByTagName("head")[0].appendChild(style_elem); |
|
30 var style_text = document.createTextNode(""); |
|
31 style_elem.appendChild(style_text); |
|
32 return style_text; |
|
33 } |
|
34 |
|
35 var style_text = setup_style(); |
|
36 |
|
37 var gCounter = 0; |
|
38 |
|
39 function test_selector(selector, matches_docdiv, matches_anondiv) |
|
40 { |
|
41 var zi = ++gCounter; |
|
42 style_text.data = selector + "{ z-index: " + zi + " }"; |
|
43 |
|
44 var doc_div = document.getElementById("display"); |
|
45 var anon_div = SpecialPowers.wrap(document).getAnonymousNodes(doc_div)[0]; |
|
46 var should_match = []; |
|
47 var should_not_match = []; |
|
48 (matches_docdiv ? should_match : should_not_match).push(doc_div); |
|
49 (matches_anondiv ? should_match : should_not_match).push(anon_div); |
|
50 |
|
51 for (var i = 0; i < should_match.length; ++i) { |
|
52 var e = should_match[i]; |
|
53 is(SpecialPowers.wrap(window).getComputedStyle(e, "").zIndex, zi, |
|
54 "element matched " + selector); |
|
55 } |
|
56 for (var i = 0; i < should_not_match.length; ++i) { |
|
57 var e = should_not_match[i]; |
|
58 is(SpecialPowers.wrap(window).getComputedStyle(e, "").zIndex, "auto", |
|
59 "element did not match " + selector); |
|
60 } |
|
61 |
|
62 style_text.data = ""; |
|
63 } |
|
64 |
|
65 // Test that the root of an XBL1 anonymous content subtree doesn't |
|
66 // match :nth-child(). |
|
67 test_selector("div.anondiv", false, true); |
|
68 test_selector("div:nth-child(odd)", true, false); |
|
69 test_selector("div:nth-child(even)", false, false); |
|
70 |
|
71 SimpleTest.finish(); |
|
72 } |
|
73 |
|
74 </script> |
|
75 </pre> |
|
76 </body> |
|
77 </html> |
|
78 |