Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: third_party/WebKit/LayoutTests/shadow-dom/resources/shadow-dom.js

Issue 2056213002: Add tests for retargeted event.target in LayoutTests/shadow-dom/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@events-1
Patch Set: rebased Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 for (let label in nodes) { 115 for (let label in nodes) {
116 let startingNode = nodes[label]; 116 let startingNode = nodes[label];
117 for (let node = startingNode; node; node = node.parentNode) { 117 for (let node = startingNode; node; node = node.parentNode) {
118 if (attachedNodes.indexOf(node) >= 0) 118 if (attachedNodes.indexOf(node) >= 0)
119 continue; 119 continue;
120 let id = node.id; 120 let id = node.id;
121 if (!id) 121 if (!id)
122 continue; 122 continue;
123 attachedNodes.push(node); 123 attachedNodes.push(node);
124 node.addEventListener(event.type, (e) => { 124 node.addEventListener(event.type, (e) => {
125 // Record [currentTarget, target, relatedTarget, composedPath()]
125 log.push([id, 126 log.push([id,
127 labelFor(e.target),
126 e.relatedTarget ? labelFor(e.relatedTarget) : null, 128 e.relatedTarget ? labelFor(e.relatedTarget) : null,
127 e.composedPath().map((n) => { 129 e.composedPath().map((n) => {
128 return labelFor(n); 130 return labelFor(n);
129 })]); 131 })]);
130 }); 132 });
131 } 133 }
132 } 134 }
133 target.dispatchEvent(event); 135 target.dispatchEvent(event);
134 return log; 136 return log;
135 } 137 }
136 138
139 // TODO(hayato): Merge this into dispatchEventWithLog
137 function dispatchUAEventWithLog(nodes, target, eventType, callback) { 140 function dispatchUAEventWithLog(nodes, target, eventType, callback) {
138 141
139 function labelFor(e) { 142 function labelFor(e) {
140 return e.id || e.tagName; 143 return e.id || e.tagName;
141 } 144 }
142 145
143 let log = []; 146 let log = [];
144 let attachedNodes = []; 147 let attachedNodes = [];
145 for (let label in nodes) { 148 for (let label in nodes) {
146 let startingNode = nodes[label]; 149 let startingNode = nodes[label];
147 for (let node = startingNode; node; node = node.parentNode) { 150 for (let node = startingNode; node; node = node.parentNode) {
148 if (attachedNodes.indexOf(node) >= 0) 151 if (attachedNodes.indexOf(node) >= 0)
149 continue; 152 continue;
150 let id = node.id; 153 let id = node.id;
151 if (!id) 154 if (!id)
152 continue; 155 continue;
153 attachedNodes.push(node); 156 attachedNodes.push(node);
154 node.addEventListener(eventType, (e) => { 157 node.addEventListener(eventType, (e) => {
158 // Record [currentTarget, target, relatedTarget, composedPath()]
155 log.push([id, 159 log.push([id,
160 labelFor(e.target),
156 e.relatedTarget ? labelFor(e.relatedTarget) : null, 161 e.relatedTarget ? labelFor(e.relatedTarget) : null,
157 e.composedPath().map((n) => { 162 e.composedPath().map((n) => {
158 return labelFor(n); 163 return labelFor(n);
159 })]); 164 })]);
160 }); 165 });
161 } 166 }
162 } 167 }
163 callback(target); 168 callback(target);
164 return log; 169 return log;
165 } 170 }
166 171
167 function makeExpectedEventPathLog(path) {
168 let expectedLog = [];
169 for (let i of path) {
170 expectedLog.push([i, null, path]);
171 }
172 return expectedLog;
173 }
174
175 function debugEventLog(log) { 172 function debugEventLog(log) {
176 for (let i = 0; i < log.length; i++) { 173 for (let i = 0; i < log.length; i++) {
177 console.log('[' + i + '] currentTarget: ' + log[i][0] + ' relatedTarget: ' + log[i][1] + ' composedPath(): ' + log[i][2]); 174 console.log('[' + i + '] currentTarget: ' + log[i][0] + ' target: ' + log[i] [1] + ' relatedTarget: ' + log[i][2] + ' composedPath(): ' + log[i][3]);
178 } 175 }
179 } 176 }
180 177
181 function debugCreateTestTree(nodes) { 178 function debugCreateTestTree(nodes) {
182 for (let k in nodes) { 179 for (let k in nodes) {
183 console.log(k + ' -> ' + nodes[k]); 180 console.log(k + ' -> ' + nodes[k]);
184 } 181 }
185 } 182 }
186 183
187 // This function assumes that testharness.js is available. 184 // This function assumes that testharness.js is available.
188 function assert_event_path_equals(actual, expected) { 185 function assert_event_path_equals(actual, expected) {
189 assert_equals(actual.length, expected.length); 186 assert_equals(actual.length, expected.length);
190 for (let i = 0; i < actual.length; ++i) { 187 for (let i = 0; i < actual.length; ++i) {
191 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou ld be same'); 188 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou ld be same');
192 assert_equals(actual[i][1], expected[i][1], 'relatedTarget at ' + i + ' shou ld be same'); 189 assert_equals(actual[i][1], expected[i][1], 'target at ' + i + ' should be s ame');
193 assert_array_equals(actual[i][2], expected[i][2], 'composedPath at ' + i + ' should be same'); 190 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');
194 } 192 }
195 } 193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698