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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements_test_runner/ElementsTestRunner.js

Issue 2975523002: DevTools: add console test helpers to new test runner & migrate a console test (Closed)
Patch Set: fix Created 3 years, 5 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
(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 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698