OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview using private properties isn't a Closure violation in tests. |
| 7 * @suppress {accessControls} |
| 8 */ |
| 9 |
| 10 /** |
| 11 * @param {string} idValue |
| 12 * @param {!Function} callback |
| 13 */ |
| 14 ElementsTestRunner.selectNodeWithId = function(idValue, callback) { |
| 15 callback = TestRunner.safeWrap(callback); |
| 16 function onNodeFound(node) { |
| 17 ElementsTestRunner.selectNode(node).then(callback.bind(null, node)); |
| 18 } |
| 19 ElementsTestRunner.nodeWithId(idValue, onNodeFound); |
| 20 }; |
| 21 |
| 22 /** |
| 23 * @param {!Object} node |
| 24 * @return {!Promise.<undefined>} |
| 25 */ |
| 26 ElementsTestRunner.selectNode = function(node) { |
| 27 return Common.Revealer.revealPromise(node); |
| 28 }; |
| 29 |
| 30 /** |
| 31 * @param {string} idValue |
| 32 * @param {!Function} callback |
| 33 */ |
| 34 ElementsTestRunner.nodeWithId = function(idValue, callback) { |
| 35 ElementsTestRunner.findNode(node => node.getAttribute('id') === idValue, callb
ack); |
| 36 }; |
| 37 |
| 38 /** |
| 39 * @param {function(!Element): boolean} matchFunction |
| 40 * @param {!Function} callback |
| 41 */ |
| 42 ElementsTestRunner.findNode = function(matchFunction, callback) { |
| 43 callback = TestRunner.safeWrap(callback); |
| 44 var result = null; |
| 45 var pendingRequests = 0; |
| 46 function processChildren(node) { |
| 47 try { |
| 48 if (result) |
| 49 return; |
| 50 |
| 51 var pseudoElementsMap = node.pseudoElements(); |
| 52 var pseudoElements = pseudoElementsMap ? pseudoElementsMap.valuesArray() :
[]; |
| 53 var children = (node.children() || []).concat(node.shadowRoots()).concat(p
seudoElements); |
| 54 if (node.templateContent()) |
| 55 children.push(node.templateContent()); |
| 56 else if (node.importedDocument()) |
| 57 children.push(node.importedDocument()); |
| 58 |
| 59 for (var i = 0; i < children.length; ++i) { |
| 60 var childNode = children[i]; |
| 61 if (matchFunction(childNode)) { |
| 62 result = childNode; |
| 63 callback(result); |
| 64 return; |
| 65 } |
| 66 pendingRequests++; |
| 67 childNode.getChildNodes(processChildren.bind(null, childNode)); |
| 68 } |
| 69 } finally { |
| 70 pendingRequests--; |
| 71 } |
| 72 |
| 73 if (!result && !pendingRequests) |
| 74 callback(null); |
| 75 } |
| 76 |
| 77 TestRunner.domModel.requestDocument(doc => { |
| 78 pendingRequests++; |
| 79 doc.getChildNodes(processChildren.bind(null, doc)); |
| 80 }); |
| 81 }; |
OLD | NEW |