1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/test/test_selectors_on_anonymous_content.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test for CSS Selectors</title> 1.8 + <!-- 1.9 + Separate from test_selectors.html so we don't need to deal with 1.10 + waiting for the binding document to load. 1.11 + --> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 + <style type="text/css"> 1.15 + 1.16 + #display { -moz-binding: url(xbl_bindings.xml#onedivchild); } 1.17 + 1.18 + </style> 1.19 +</head> 1.20 +<body onload="run()"> 1.21 +<div id="display"></div> 1.22 +<pre id="test"> 1.23 +<script class="testbody" type="text/javascript"> 1.24 + 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 + 1.27 +function run() { 1.28 + 1.29 + function setup_style() { 1.30 + var style_elem = document.createElement("style"); 1.31 + style_elem.setAttribute("type", "text/css"); 1.32 + document.getElementsByTagName("head")[0].appendChild(style_elem); 1.33 + var style_text = document.createTextNode(""); 1.34 + style_elem.appendChild(style_text); 1.35 + return style_text; 1.36 + } 1.37 + 1.38 + var style_text = setup_style(); 1.39 + 1.40 + var gCounter = 0; 1.41 + 1.42 + function test_selector(selector, matches_docdiv, matches_anondiv) 1.43 + { 1.44 + var zi = ++gCounter; 1.45 + style_text.data = selector + "{ z-index: " + zi + " }"; 1.46 + 1.47 + var doc_div = document.getElementById("display"); 1.48 + var anon_div = SpecialPowers.wrap(document).getAnonymousNodes(doc_div)[0]; 1.49 + var should_match = []; 1.50 + var should_not_match = []; 1.51 + (matches_docdiv ? should_match : should_not_match).push(doc_div); 1.52 + (matches_anondiv ? should_match : should_not_match).push(anon_div); 1.53 + 1.54 + for (var i = 0; i < should_match.length; ++i) { 1.55 + var e = should_match[i]; 1.56 + is(SpecialPowers.wrap(window).getComputedStyle(e, "").zIndex, zi, 1.57 + "element matched " + selector); 1.58 + } 1.59 + for (var i = 0; i < should_not_match.length; ++i) { 1.60 + var e = should_not_match[i]; 1.61 + is(SpecialPowers.wrap(window).getComputedStyle(e, "").zIndex, "auto", 1.62 + "element did not match " + selector); 1.63 + } 1.64 + 1.65 + style_text.data = ""; 1.66 + } 1.67 + 1.68 + // Test that the root of an XBL1 anonymous content subtree doesn't 1.69 + // match :nth-child(). 1.70 + test_selector("div.anondiv", false, true); 1.71 + test_selector("div:nth-child(odd)", true, false); 1.72 + test_selector("div:nth-child(even)", false, false); 1.73 + 1.74 + SimpleTest.finish(); 1.75 +} 1.76 + 1.77 +</script> 1.78 +</pre> 1.79 +</body> 1.80 +</html> 1.81 +