4 https://bugzilla.mozilla.org/show_bug.cgi?id=319374
7 <title>Test for Bug
319374</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
12 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=319374">Mozilla Bug
319374</a>
14 <div id=
"content"><custom-el></custom-el><custom-el></custom-el><custom-el></custom-el></div>
16 <script class=
"testbody" type=
"text/javascript">
18 customElements.define(
"custom-el", class extends HTMLElement {
21 this.attachShadow({ mode:
"open" });
22 this.shadowRoot.innerHTML =
23 `
<span attr=
"attribute"><span></span></span><span> anon text
</span><br>`;
27 function testChangesInShadowDOM() {
28 // Test
1: Make sure that modifying anonymous content doesn't
29 // cause non-anonymous XPath result to throw exceptions..
33 var xp = new XPathEvaluator();
34 var result = xp.evaluate(
"*",
35 document.getElementById('content'),
37 XPathResult.UNORDERED_NODE_ITERATOR_TYPE,
40 while ((res = result.iterateNext())) {
42 let anon = res.shadowRoot.childNodes;
43 anon[
0].firstChild.remove(); // Removing a child node
44 anon[
0].removeAttribute(
"attr1"); // Removing an attribute
45 anon[
1].firstChild.data =
"anon text changed" // Modifying text data
51 ok(counter ==
3,
"XPathEvaluator should have found 3 elements.")
53 // Test
2: If the context node is in anonymous content, changing some
54 // other anonymous tree shouldn't cause XPath result to throw.
55 let shadowAttr1 = document.getElementById(
"content").firstChild.
56 shadowRoot.firstChild.getAttributeNode(
"attr");
57 let shadowAttr2 = document.getElementById(
"content").lastChild.
58 shadowRoot.firstChild.getAttributeNode(
"attr");
59 var resultAttr = null;
61 var xp2 = xp.evaluate(
".",
64 XPathResult.UNORDERED_NODE_ITERATOR_TYPE,
66 // Attribute changing in a different anonymous tree.
67 shadowAttr2.value =
"foo";
68 resultAttr = xp2.iterateNext();
69 is(resultAttr, shadowAttr1,
"XPathEvaluator returned wrong attribute!");
74 // Test
3: If the anonymous tree in which context node is in is modified,
75 // XPath result should throw when iterateNext() is called.
78 var xp3 = xp.evaluate(
".",
81 XPathResult.UNORDERED_NODE_ITERATOR_TYPE,
83 // Attribute changing in the same anonymous tree.
84 shadowAttr1.ownerElement.setAttribute(
"foo",
"bar");
85 resultAttr = xp3.iterateNext();
86 ok(resultAttr == shadowAttr1,
87 "XPathEvaluator should have thrown an exception!")
95 SimpleTest.waitForExplicitFinish();
96 addLoadEvent(testChangesInShadowDOM);