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 === No
de.DOCUMENT_FRAGMENT_NODE) { | 8 } else if (child.nodeType === Node.ELEMENT_NODE || child.nodeType === No
de.DOCUMENT_FRAGMENT_NODE) { |
9 removeWhiteSpaceOnlyTextNodes(child); | 9 removeWhiteSpaceOnlyTextNodes(child); |
10 } | 10 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 for (var i = 1; node != null && i < ids.length; ++i) { | 57 for (var i = 1; node != null && i < ids.length; ++i) { |
58 if (isIFrameElement(node)) | 58 if (isIFrameElement(node)) |
59 node = node.contentDocument.getElementById(ids[i]); | 59 node = node.contentDocument.getElementById(ids[i]); |
60 else if (isShadowHost(node)) | 60 else if (isShadowHost(node)) |
61 node = node.shadowRoot.getElementById(ids[i]); | 61 node = node.shadowRoot.getElementById(ids[i]); |
62 else | 62 else |
63 return null; | 63 return null; |
64 } | 64 } |
65 return node; | 65 return node; |
66 } | 66 } |
| 67 |
| 68 function createTestTree(node) { |
| 69 |
| 70 let labels = {}; |
| 71 |
| 72 function attachShadowFromTemplate(template) { |
| 73 let parent = template.parentNode; |
| 74 parent.removeChild(template); |
| 75 let shadowRoot = parent.attachShadow({mode: template.getAttribute('data-mode
')}); |
| 76 let label = template.getAttribute('label'); |
| 77 if (label) { |
| 78 shadowRoot.id = label; |
| 79 labels[label] = shadowRoot; |
| 80 } |
| 81 shadowRoot.appendChild(document.importNode(template.content, true)); |
| 82 return shadowRoot; |
| 83 } |
| 84 |
| 85 function walk(root) { |
| 86 if (root.getAttribute && root.getAttribute('label')) { |
| 87 labels[root.getAttribute('label')] = root; |
| 88 } |
| 89 for (let e of Array.from(root.querySelectorAll('[label]'))) { |
| 90 labels[e.getAttribute('label')] = e; |
| 91 } |
| 92 for (let e of Array.from(root.querySelectorAll('template'))) { |
| 93 walk(attachShadowFromTemplate(e)); |
| 94 } |
| 95 } |
| 96 |
| 97 walk(node.cloneNode(true)); |
| 98 return labels; |
| 99 } |
| 100 |
| 101 function dispatchEventWithLog(nodes, target, event) { |
| 102 |
| 103 function labelFor(e) { |
| 104 if (e.getAttribute && e.getAttribute('label')) { |
| 105 return e.getAttribute('label'); |
| 106 } |
| 107 return e.id || e.tagName; |
| 108 } |
| 109 |
| 110 let log = []; |
| 111 let attachedNodes = []; |
| 112 for (let label in nodes) { |
| 113 let startingNode = nodes[label]; |
| 114 for (let node = startingNode; node; node = node.parentNode) { |
| 115 if (attachedNodes.indexOf(node) >= 0) |
| 116 continue; |
| 117 let label = labelFor(node); |
| 118 if (!label) |
| 119 continue; |
| 120 attachedNodes.push(node); |
| 121 node.addEventListener(event.type, (e) => { |
| 122 log.push([label, |
| 123 event.relatedTarget ? labelFor(event.relatedTarget) : null, |
| 124 event.composedPath().map((n) => { |
| 125 return labelFor(n); |
| 126 })]); |
| 127 }); |
| 128 } |
| 129 } |
| 130 target.dispatchEvent(event); |
| 131 return log; |
| 132 } |
OLD | NEW |