blob: a05684dd5fd0615fc9db735600b87372a5e64fd0 (
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
|
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<div id="sandbox"></div>
<script>
description("Should update distribution when needed for querySelector and related methods.");
function test(fn)
{
var sandbox = document.getElementById("sandbox");
sandbox.innerHTML = "<div id=host><div id=a><div id=b></div></div>";
host = document.getElementById("host");
hostRoot = host.createShadowRoot();
hostRoot.innerHTML = "<div id=c><content></content></div>";
a = document.getElementById("a");
b = document.getElementById("b");
aRoot = a.createShadowRoot();
aRoot.innerHTML = "<div id=d><div id=e></div></div>";
c = hostRoot.getElementById("c");
d = aRoot.getElementById("d");
e = aRoot.getElementById("e");
sandbox.appendChild(host);
fn();
sandbox.innerHTML = "";
}
function toArray(list)
{
return Array.prototype.slice.call(list);
}
test(function() {
shouldBe("aRoot.querySelector(':host-context(#c) #d')", "d");
});
test(function() {
shouldBe("toArray(aRoot.querySelectorAll(':host-context(#c) #d'))", "[d]");
});
test(function() {
shouldBeNull("hostRoot.querySelector('::content #a')");
});
test(function() {
shouldBe("toArray(hostRoot.querySelectorAll('::content #a'))", "[]");
});
test(function() {
shouldBeFalse("a.matches('::content #a')");
});
test(function() {
shouldBeTrue("d.matches(':host-context(#host) #d')");
});
test(function() {
shouldBeTrue("d.matches(':host-context(#c) #d')");
});
test(function() {
shouldBeNull("b.closest('::content #a')");
});
test(function() {
shouldBe("e.closest(':host-context(#host) #d')", "d");
});
</script>
|