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

Side by Side Diff: third_party/WebKit/LayoutTests/resources/dump-as-markup.js

Issue 2643773007: Remove internals.address(node) (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/testing/Internals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * There are three basic use cases of dumpAsMarkup 2 * There are three basic use cases of dumpAsMarkup
3 * 3 *
4 * 1. Dump the entire DOM when the page is loaded 4 * 1. Dump the entire DOM when the page is loaded
5 * When this script is included but no method of Markup is called, 5 * When this script is included but no method of Markup is called,
6 * it dumps the DOM of each frame loaded. 6 * it dumps the DOM of each frame loaded.
7 * 7 *
8 * 2. Dump the content of a specific element when the page is loaded 8 * 2. Dump the content of a specific element when the page is loaded
9 * When Markup.setNodeToDump is called with some element or the id of some el ement, 9 * When Markup.setNodeToDump is called with some element or the id of some el ement,
10 * it dumps the content of the specified element as supposed to the entire DO M tree. 10 * it dumps the content of the specified element as supposed to the entire DO M tree.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 testRunner.notifyDone(); 119 testRunner.notifyDone();
120 } 120 }
121 121
122 Markup.useHTML5libOutputFormat = function() 122 Markup.useHTML5libOutputFormat = function()
123 { 123 {
124 Markup._useHTML5libOutputFormat = true; 124 Markup._useHTML5libOutputFormat = true;
125 } 125 }
126 126
127 Markup.get = function(node) 127 Markup.get = function(node)
128 { 128 {
129 var shadowRootList = {}; 129 var markup = Markup._getShadowHostIfPossible(node, 0);
130 var markup = Markup._getShadowHostIfPossible(node, 0, shadowRootList);
131 if (markup) 130 if (markup)
132 return markup.substring(1); 131 return markup.substring(1);
133 132
134 if (!node.firstChild) 133 if (!node.firstChild)
135 return '| '; 134 return '| ';
136 135
137 // Don't print any markup for the root node. 136 // Don't print any markup for the root node.
138 for (var i = 0, len = node.childNodes.length; i < len; i++) 137 for (var i = 0, len = node.childNodes.length; i < len; i++)
139 markup += Markup._get(node.childNodes[i], 0, shadowRootList); 138 markup += Markup._get(node.childNodes[i], 0);
140 return markup.substring(1); 139 return markup.substring(1);
141 } 140 }
142 141
143 // Returns the markup for the given node. To be used for cases where a test need s 142 // Returns the markup for the given node. To be used for cases where a test need s
144 // to get the markup but not clobber the whole page. 143 // to get the markup but not clobber the whole page.
145 Markup._get = function(node, depth, shadowRootList) 144 Markup._get = function(node, depth)
146 { 145 {
147 var str = Markup._indent(depth); 146 var str = Markup._indent(depth);
148 147
149 switch (node.nodeType) { 148 switch (node.nodeType) {
150 case Node.DOCUMENT_TYPE_NODE: 149 case Node.DOCUMENT_TYPE_NODE:
151 str += '<!DOCTYPE ' + node.nodeName; 150 str += '<!DOCTYPE ' + node.nodeName;
152 if (node.publicId || node.systemId) { 151 if (node.publicId || node.systemId) {
153 str += ' "' + node.publicId + '"'; 152 str += ' "' + node.publicId + '"';
154 str += ' "' + node.systemId + '"'; 153 str += ' "' + node.systemId + '"';
155 } 154 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (pseudoId) 209 if (pseudoId)
211 str += Markup._indent(depth + 1) + 'shadow:pseudoId="' + pseudoI d + '"'; 210 str += Markup._indent(depth + 1) + 'shadow:pseudoId="' + pseudoI d + '"';
212 } 211 }
213 212
214 if (!Markup._useHTML5libOutputFormat) 213 if (!Markup._useHTML5libOutputFormat)
215 if (node.nodeName == "INPUT" || node.nodeName == "TEXTAREA") 214 if (node.nodeName == "INPUT" || node.nodeName == "TEXTAREA")
216 str += Markup._indent(depth + 1) + 'this.value="' + node.value + '"'; 215 str += Markup._indent(depth + 1) + 'this.value="' + node.value + '"';
217 216
218 break; 217 break;
219 case Node.DOCUMENT_FRAGMENT_NODE: 218 case Node.DOCUMENT_FRAGMENT_NODE:
220 if (shadowRootList && internals.address(node) in shadowRootList) 219 if (node.constructor.name == "ShadowRoot")
221 str += "<shadow:root>"; 220 str += "<shadow:root>";
222 else 221 else
223 str += "content"; 222 str += "content";
224 } 223 }
225 224
225 // TODO(esprehn): This should definitely be ==.
dglazkov 2017/01/20 16:37:26 Could you expand on this comment? What does it mea
esprehn 2017/01/20 17:51:50 It's using single equal instead of double equal. S
dglazkov 2017/01/23 04:29:36 Oh, I missed it. I was looking at the node.tagName
226 if (node.namespaceURI = 'http://www.w3.org/1999/xhtml' && node.tagName == 'T EMPLATE') 226 if (node.namespaceURI = 'http://www.w3.org/1999/xhtml' && node.tagName == 'T EMPLATE')
227 str += Markup._get(node.content, depth + 1, shadowRootList); 227 str += Markup._get(node.content, depth + 1);
228 228
229 for (var i = 0, len = node.childNodes.length; i < len; i++) { 229 for (var i = 0, len = node.childNodes.length; i < len; i++) {
230 var selection = Markup._getSelectionMarker(node, i); 230 var selection = Markup._getSelectionMarker(node, i);
231 if (selection) 231 if (selection)
232 str += Markup._indent(depth + 1) + selection; 232 str += Markup._indent(depth + 1) + selection;
233 233
234 str += Markup._get(node.childNodes[i], depth + 1, shadowRootList); 234 str += Markup._get(node.childNodes[i], depth + 1);
235 } 235 }
236 236
237 str += Markup._getShadowHostIfPossible(node, depth, shadowRootList); 237 str += Markup._getShadowHostIfPossible(node, depth);
238 238
239 var selection = Markup._getSelectionMarker(node, i); 239 var selection = Markup._getSelectionMarker(node, i);
240 if (selection) 240 if (selection)
241 str += Markup._indent(depth + 1) + selection; 241 str += Markup._indent(depth + 1) + selection;
242 242
243 return str; 243 return str;
244 } 244 }
245 245
246 Markup._getShadowHostIfPossible = function (node, depth, shadowRootList) 246 Markup._getShadowHostIfPossible = function (node, depth)
247 { 247 {
248 if (!Markup._useHTML5libOutputFormat && node.nodeType == Node.ELEMENT_NODE & & window.internals) { 248 if (!Markup._useHTML5libOutputFormat && node.nodeType == Node.ELEMENT_NODE & & window.internals) {
249 var root = window.internals.shadowRoot(node); 249 var root = window.internals.shadowRoot(node);
250 if (root) { 250 if (root) {
251 shadowRootList[internals.address(root)] = true; 251 return Markup._get(root, depth + 1);
252 return Markup._get(root, depth + 1, shadowRootList);
253 } 252 }
254 } 253 }
255 return ''; 254 return '';
256 } 255 }
257 256
258 Markup._namespace = function(node) 257 Markup._namespace = function(node)
259 { 258 {
260 if (Markup._NAMESPACE_URI_MAP[node.namespaceURI]) 259 if (Markup._NAMESPACE_URI_MAP[node.namespaceURI])
261 return Markup._NAMESPACE_URI_MAP[node.namespaceURI] + ' '; 260 return Markup._NAMESPACE_URI_MAP[node.namespaceURI] + ' ';
262 return ''; 261 return '';
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 return Markup._SELECTION_CARET; 356 return Markup._SELECTION_CARET;
358 else 357 else
359 return Markup._SELECTION_ANCHOR; 358 return Markup._SELECTION_ANCHOR;
360 } else if (index == sel.focusOffset && node == sel.focusNode) 359 } else if (index == sel.focusOffset && node == sel.focusNode)
361 return Markup._SELECTION_FOCUS; 360 return Markup._SELECTION_FOCUS;
362 361
363 return ''; 362 return '';
364 } 363 }
365 364
366 window.addEventListener('load', Markup.notifyDone, false); 365 window.addEventListener('load', Markup.notifyDone, false);
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/testing/Internals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698