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

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

Issue 2051373002: Rewrite and organize tests in LayoutTests/shadow-dom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clean-test2-3
Patch Set: clean up 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return node; 65 return node;
66 } 66 }
67 67
68 function createTestTree(node) { 68 function createTestTree(node) {
69 69
70 let ids = {}; 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;
76 if (template.getAttribute('data-mode') === 'v0') {
77 // For legacy Shadow DOM
78 shadowRoot = parent.createShadowRoot();
79 } else {
80 shadowRoot = parent.attachShadow({mode: template.getAttribute('data-mode') });
81 }
76 let id = template.id; 82 let id = template.id;
77 if (id) { 83 if (id) {
78 shadowRoot.id = id; 84 shadowRoot.id = id;
79 ids[id] = shadowRoot; 85 ids[id] = shadowRoot;
80 } 86 }
81 shadowRoot.appendChild(document.importNode(template.content, true)); 87 shadowRoot.appendChild(document.importNode(template.content, true));
82 return shadowRoot; 88 return shadowRoot;
83 } 89 }
84 90
85 function walk(root) { 91 function walk(root) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 e.composedPath().map((n) => { 157 e.composedPath().map((n) => {
152 return labelFor(n); 158 return labelFor(n);
153 })]); 159 })]);
154 }); 160 });
155 } 161 }
156 } 162 }
157 callback(target); 163 callback(target);
158 return log; 164 return log;
159 } 165 }
160 166
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) {
176 for (let i = 0; i < log.length; i++) {
177 console.log('[' + i + '] currentTarget: ' + log[i][0] + ' relatedTarget: ' + log[i][1] + ' composedPath(): ' + log[i][2]);
178 }
179 }
180
181 function debugCreateTestTree(nodes) {
182 for (let k in nodes) {
183 console.log(k + ' -> ' + nodes[k]);
184 }
185 }
186
161 // This function assumes that testharness.js is available. 187 // This function assumes that testharness.js is available.
162 function assert_event_path_equals(actual, expected) { 188 function assert_event_path_equals(actual, expected) {
163 assert_equals(actual.length, expected.length); 189 assert_equals(actual.length, expected.length);
164 for (let i = 0; i < actual.length; ++i) { 190 for (let i = 0; i < actual.length; ++i) {
165 assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' shou ld be same'); 191 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'); 192 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'); 193 assert_array_equals(actual[i][2], expected[i][2], 'composedPath at ' + i + ' should be same');
168 } 194 }
169 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698