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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 event.composedPath().map((n) => { | 121 event.composedPath().map((n) => { |
122 return labelFor(n); | 122 return labelFor(n); |
123 })]); | 123 })]); |
124 }); | 124 }); |
125 } | 125 } |
126 } | 126 } |
127 target.dispatchEvent(event); | 127 target.dispatchEvent(event); |
128 return log; | 128 return log; |
129 } | 129 } |
130 | 130 |
| 131 function dispatchUAEventWithLog(nodes, target, eventType, callback) { |
| 132 |
| 133 function labelFor(e) { |
| 134 return e.id || e.tagName; |
| 135 } |
| 136 |
| 137 let log = []; |
| 138 let attachedNodes = []; |
| 139 for (let label in nodes) { |
| 140 let startingNode = nodes[label]; |
| 141 for (let node = startingNode; node; node = node.parentNode) { |
| 142 if (attachedNodes.indexOf(node) >= 0) |
| 143 continue; |
| 144 let id = node.id; |
| 145 if (!id) |
| 146 continue; |
| 147 attachedNodes.push(node); |
| 148 node.addEventListener(eventType, (e) => { |
| 149 log.push([id, |
| 150 event.relatedTarget ? labelFor(event.relatedTarget) : null, |
| 151 event.composedPath().map((n) => { |
| 152 return labelFor(n); |
| 153 })]); |
| 154 }); |
| 155 } |
| 156 } |
| 157 callback(target); |
| 158 return log; |
| 159 } |
| 160 |
131 // This function assumes that testharness.js is available. | 161 // This function assumes that testharness.js is available. |
132 function assert_event_path_equals(actual, expected) { | 162 function assert_event_path_equals(actual, expected) { |
133 assert_equals(actual.length, expected.length); | 163 assert_equals(actual.length, expected.length); |
134 for (let i = 0; i < actual.length; ++i) { | 164 for (let i = 0; i < actual.length; ++i) { |
135 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou
ld be same'); | 165 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou
ld be same'); |
136 assert_equals(actual[i][1], expected[i][1], 'relatedTarget at ' + i + ' shou
ld be same'); | 166 assert_equals(actual[i][1], expected[i][1], 'relatedTarget at ' + i + ' shou
ld be same'); |
137 assert_array_equals(actual[i][2], expected[i][2], 'composedPath at ' + i + '
should be same'); | 167 assert_array_equals(actual[i][2], expected[i][2], 'composedPath at ' + i + '
should be same'); |
138 } | 168 } |
139 } | 169 } |
OLD | NEW |