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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 let startingNode = nodes[label]; | 110 let startingNode = nodes[label]; |
111 for (let node = startingNode; node; node = node.parentNode) { | 111 for (let node = startingNode; node; node = node.parentNode) { |
112 if (attachedNodes.indexOf(node) >= 0) | 112 if (attachedNodes.indexOf(node) >= 0) |
113 continue; | 113 continue; |
114 let id = node.id; | 114 let id = node.id; |
115 if (!id) | 115 if (!id) |
116 continue; | 116 continue; |
117 attachedNodes.push(node); | 117 attachedNodes.push(node); |
118 node.addEventListener(event.type, (e) => { | 118 node.addEventListener(event.type, (e) => { |
119 log.push([id, | 119 log.push([id, |
120 event.relatedTarget ? labelFor(event.relatedTarget) : null, | 120 e.relatedTarget ? labelFor(e.relatedTarget) : null, |
121 event.composedPath().map((n) => { | 121 e.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) { | 131 function dispatchUAEventWithLog(nodes, target, eventType, callback) { |
132 | 132 |
133 function labelFor(e) { | 133 function labelFor(e) { |
134 return e.id || e.tagName; | 134 return e.id || e.tagName; |
135 } | 135 } |
136 | 136 |
137 let log = []; | 137 let log = []; |
138 let attachedNodes = []; | 138 let attachedNodes = []; |
139 for (let label in nodes) { | 139 for (let label in nodes) { |
140 let startingNode = nodes[label]; | 140 let startingNode = nodes[label]; |
141 for (let node = startingNode; node; node = node.parentNode) { | 141 for (let node = startingNode; node; node = node.parentNode) { |
142 if (attachedNodes.indexOf(node) >= 0) | 142 if (attachedNodes.indexOf(node) >= 0) |
143 continue; | 143 continue; |
144 let id = node.id; | 144 let id = node.id; |
145 if (!id) | 145 if (!id) |
146 continue; | 146 continue; |
147 attachedNodes.push(node); | 147 attachedNodes.push(node); |
148 node.addEventListener(eventType, (e) => { | 148 node.addEventListener(eventType, (e) => { |
149 log.push([id, | 149 log.push([id, |
150 event.relatedTarget ? labelFor(event.relatedTarget) : null, | 150 e.relatedTarget ? labelFor(e.relatedTarget) : null, |
151 event.composedPath().map((n) => { | 151 e.composedPath().map((n) => { |
152 return labelFor(n); | 152 return labelFor(n); |
153 })]); | 153 })]); |
154 }); | 154 }); |
155 } | 155 } |
156 } | 156 } |
157 callback(target); | 157 callback(target); |
158 return log; | 158 return log; |
159 } | 159 } |
160 | 160 |
161 // This function assumes that testharness.js is available. | 161 // This function assumes that testharness.js is available. |
162 function assert_event_path_equals(actual, expected) { | 162 function assert_event_path_equals(actual, expected) { |
163 assert_equals(actual.length, expected.length); | 163 assert_equals(actual.length, expected.length); |
164 for (let i = 0; i < actual.length; ++i) { | 164 for (let i = 0; i < actual.length; ++i) { |
165 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'); |
166 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'); |
167 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'); |
168 } | 168 } |
169 } | 169 } |
OLD | NEW |