| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 67 |
| 68 function createTestTree(node) { | 68 function createTestTree(node) { |
| 69 | 69 |
| 70 let labels = {}; | 70 let ids = {}; |
| 71 | 71 |
| 72 function attachShadowFromTemplate(template) { | 72 function attachShadowFromTemplate(template) { |
| 73 let parent = template.parentNode; | 73 let parent = template.parentNode; |
| 74 parent.removeChild(template); | 74 parent.removeChild(template); |
| 75 let shadowRoot = parent.attachShadow({mode: template.getAttribute('data-mode
')}); | 75 let shadowRoot = parent.attachShadow({mode: template.getAttribute('data-mode
')}); |
| 76 let label = template.getAttribute('label'); | 76 let id = template.id; |
| 77 if (label) { | 77 if (id) { |
| 78 shadowRoot.id = label; | 78 shadowRoot.id = id; |
| 79 labels[label] = shadowRoot; | 79 ids[id] = shadowRoot; |
| 80 } | 80 } |
| 81 shadowRoot.appendChild(document.importNode(template.content, true)); | 81 shadowRoot.appendChild(document.importNode(template.content, true)); |
| 82 return shadowRoot; | 82 return shadowRoot; |
| 83 } | 83 } |
| 84 | 84 |
| 85 function walk(root) { | 85 function walk(root) { |
| 86 if (root.getAttribute && root.getAttribute('label')) { | 86 if (root.id) { |
| 87 labels[root.getAttribute('label')] = root; | 87 ids[root.id] = root; |
| 88 } | 88 } |
| 89 for (let e of Array.from(root.querySelectorAll('[label]'))) { | 89 for (let e of Array.from(root.querySelectorAll('[id]'))) { |
| 90 labels[e.getAttribute('label')] = e; | 90 ids[e.id] = e; |
| 91 } | 91 } |
| 92 for (let e of Array.from(root.querySelectorAll('template'))) { | 92 for (let e of Array.from(root.querySelectorAll('template'))) { |
| 93 walk(attachShadowFromTemplate(e)); | 93 walk(attachShadowFromTemplate(e)); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 walk(node.cloneNode(true)); | 97 walk(node.cloneNode(true)); |
| 98 return labels; | 98 return ids; |
| 99 } | 99 } |
| 100 | 100 |
| 101 function dispatchEventWithLog(nodes, target, event) { | 101 function dispatchEventWithLog(nodes, target, event) { |
| 102 | 102 |
| 103 function labelFor(e) { | 103 function labelFor(e) { |
| 104 if (e.getAttribute && e.getAttribute('label')) { | |
| 105 return e.getAttribute('label'); | |
| 106 } | |
| 107 return e.id || e.tagName; | 104 return e.id || e.tagName; |
| 108 } | 105 } |
| 109 | 106 |
| 110 let log = []; | 107 let log = []; |
| 111 let attachedNodes = []; | 108 let attachedNodes = []; |
| 112 for (let label in nodes) { | 109 for (let label in nodes) { |
| 113 let startingNode = nodes[label]; | 110 let startingNode = nodes[label]; |
| 114 for (let node = startingNode; node; node = node.parentNode) { | 111 for (let node = startingNode; node; node = node.parentNode) { |
| 115 if (attachedNodes.indexOf(node) >= 0) | 112 if (attachedNodes.indexOf(node) >= 0) |
| 116 continue; | 113 continue; |
| 117 let label = labelFor(node); | 114 let id = node.id; |
| 118 if (!label) | 115 if (!id) |
| 119 continue; | 116 continue; |
| 120 attachedNodes.push(node); | 117 attachedNodes.push(node); |
| 121 node.addEventListener(event.type, (e) => { | 118 node.addEventListener(event.type, (e) => { |
| 122 log.push([label, | 119 log.push([id, |
| 123 event.relatedTarget ? labelFor(event.relatedTarget) : null, | 120 event.relatedTarget ? labelFor(event.relatedTarget) : null, |
| 124 event.composedPath().map((n) => { | 121 event.composedPath().map((n) => { |
| 125 return labelFor(n); | 122 return labelFor(n); |
| 126 })]); | 123 })]); |
| 127 }); | 124 }); |
| 128 } | 125 } |
| 129 } | 126 } |
| 130 target.dispatchEvent(event); | 127 target.dispatchEvent(event); |
| 131 return log; | 128 return log; |
| 132 } | 129 } |
| 133 | 130 |
| 134 // This function assumes that testharness.js is available. | 131 // This function assumes that testharness.js is available. |
| 135 function assert_event_path_equals(actual, expected) { | 132 function assert_event_path_equals(actual, expected) { |
| 136 assert_equals(actual.length, expected.length); | 133 assert_equals(actual.length, expected.length); |
| 137 for (let i = 0; i < actual.length; ++i) { | 134 for (let i = 0; i < actual.length; ++i) { |
| 138 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou
ld be same'); | 135 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou
ld be same'); |
| 139 assert_equals(actual[i][1], expected[i][1], 'relatedTarget at ' + i + ' shou
ld be same'); | 136 assert_equals(actual[i][1], expected[i][1], 'relatedTarget at ' + i + ' shou
ld be same'); |
| 140 assert_array_equals(actual[i][2], expected[i][2], 'composedPath at ' + i + '
should be same'); | 137 assert_array_equals(actual[i][2], expected[i][2], 'composedPath at ' + i + '
should be same'); |
| 141 } | 138 } |
| 142 } | 139 } |
| OLD | NEW |