OLD | NEW |
1 function removeWhiteSpaceOnlyTextNodes(node) | 1 function removeWhiteSpaceOnlyTextNodes(node) |
2 { | 2 { |
3 for (var i = 0; i < node.childNodes.length; i++) { | 3 for (var i = 0; i < node.childNodes.length; i++) { |
4 var child = node.childNodes[i]; | 4 var child = node.childNodes[i]; |
5 if (child.nodeType === Node.TEXT_NODE && child.nodeValue.trim().length == 0)
{ | 5 if (child.nodeType === Node.TEXT_NODE && child.nodeValue.trim().length == 0)
{ |
6 node.removeChild(child); | 6 node.removeChild(child); |
7 i--; | 7 i--; |
8 } else if (child.nodeType === Node.ELEMENT_NODE || child.nodeType === Node.D
OCUMENT_FRAGMENT_NODE) { | 8 } else if (child.nodeType === Node.ELEMENT_NODE || child.nodeType === Node.D
OCUMENT_FRAGMENT_NODE) { |
9 removeWhiteSpaceOnlyTextNodes(child); | 9 removeWhiteSpaceOnlyTextNodes(child); |
10 } | 10 } |
11 } | 11 } |
12 if (node.shadowRoot) { | 12 if (node.shadowRoot) { |
13 removeWhiteSpaceOnlyTextNodes(node.shadowRoot); | 13 removeWhiteSpaceOnlyTextNodes(node.shadowRoot); |
14 } | 14 } |
15 } | 15 } |
16 | 16 |
17 function convertTemplatesToShadowRootsWithin(node) { | |
18 var nodes = node.querySelectorAll("template"); | |
19 for (var i = 0; i < nodes.length; ++i) { | |
20 var template = nodes[i]; | |
21 var mode = template.getAttribute("data-mode"); | |
22 var parent = template.parentNode; | |
23 parent.removeChild(template); | |
24 var shadowRoot; | |
25 if (!mode || mode == 'v0'){ | |
26 shadowRoot = parent.createShadowRoot(); | |
27 } else { | |
28 shadowRoot = parent.attachShadow({'mode': mode}); | |
29 } | |
30 var expose = template.getAttribute("data-expose-as"); | |
31 if (expose) | |
32 window[expose] = shadowRoot; | |
33 if (template.id) | |
34 shadowRoot.id = template.id; | |
35 var fragments = document.importNode(template.content, true); | |
36 shadowRoot.appendChild(fragments); | |
37 | |
38 convertTemplatesToShadowRootsWithin(shadowRoot); | |
39 } | |
40 } | |
41 | |
42 function isShadowHost(node) | |
43 { | |
44 return node && node.nodeType == Node.ELEMENT_NODE && node.shadowRoot; | |
45 } | |
46 | |
47 function isIFrameElement(element) | |
48 { | |
49 return element && element.nodeName == 'IFRAME'; | |
50 } | |
51 | |
52 // Returns node from shadow/iframe tree "path". | |
53 function getNodeInComposedTree(path) | |
54 { | |
55 var ids = path.split('/'); | |
56 var node = document.getElementById(ids[0]); | |
57 for (var i = 1; node != null && i < ids.length; ++i) { | |
58 if (isIFrameElement(node)) | |
59 node = node.contentDocument.getElementById(ids[i]); | |
60 else if (isShadowHost(node)) | |
61 node = node.shadowRoot.getElementById(ids[i]); | |
62 else | |
63 return null; | |
64 } | |
65 return node; | |
66 } | |
67 | |
68 function createTestTree(node) { | 17 function createTestTree(node) { |
69 | 18 |
70 let ids = {}; | 19 let ids = {}; |
71 | 20 |
72 function attachShadowFromTemplate(template) { | 21 function attachShadowFromTemplate(template) { |
73 let parent = template.parentNode; | 22 let parent = template.parentNode; |
74 parent.removeChild(template); | 23 parent.removeChild(template); |
75 let shadowRoot; | 24 let shadowRoot; |
76 if (template.getAttribute('data-mode') === 'v0') { | 25 if (template.getAttribute('data-mode') === 'v0') { |
77 // For legacy Shadow DOM | 26 // For legacy Shadow DOM |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 e.composedPath().map((n) => { | 111 e.composedPath().map((n) => { |
163 return labelFor(n); | 112 return labelFor(n); |
164 })]); | 113 })]); |
165 }); | 114 }); |
166 } | 115 } |
167 } | 116 } |
168 callback(target); | 117 callback(target); |
169 return log; | 118 return log; |
170 } | 119 } |
171 | 120 |
172 function debugEventLog(log) { | |
173 for (let i = 0; i < log.length; i++) { | |
174 console.log('[' + i + '] currentTarget: ' + log[i][0] + ' target: ' + log[i]
[1] + ' relatedTarget: ' + log[i][2] + ' composedPath(): ' + log[i][3]); | |
175 } | |
176 } | |
177 | |
178 function debugCreateTestTree(nodes) { | |
179 for (let k in nodes) { | |
180 console.log(k + ' -> ' + nodes[k]); | |
181 } | |
182 } | |
183 | |
184 // This function assumes that testharness.js is available. | 121 // This function assumes that testharness.js is available. |
185 function assert_event_path_equals(actual, expected) { | 122 function assert_event_path_equals(actual, expected) { |
186 assert_equals(actual.length, expected.length); | 123 assert_equals(actual.length, expected.length); |
187 for (let i = 0; i < actual.length; ++i) { | 124 for (let i = 0; i < actual.length; ++i) { |
188 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou
ld be same'); | 125 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou
ld be same'); |
189 assert_equals(actual[i][1], expected[i][1], 'target at ' + i + ' should be s
ame'); | 126 assert_equals(actual[i][1], expected[i][1], 'target at ' + i + ' should be s
ame'); |
190 assert_equals(actual[i][2], expected[i][2], 'relatedTarget at ' + i + ' shou
ld be same'); | 127 assert_equals(actual[i][2], expected[i][2], 'relatedTarget at ' + i + ' shou
ld be same'); |
191 assert_array_equals(actual[i][3], expected[i][3], 'composedPath at ' + i + '
should be same'); | 128 assert_array_equals(actual[i][3], expected[i][3], 'composedPath at ' + i + '
should be same'); |
192 } | 129 } |
193 } | 130 } |
OLD | NEW |