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

Unified 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: cleanup 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/elements_test_runner/ElementsTestRunner.js
diff --git a/third_party/WebKit/Source/devtools/front_end/elements_test_runner/ElementsTestRunner.js b/third_party/WebKit/Source/devtools/front_end/elements_test_runner/ElementsTestRunner.js
new file mode 100644
index 0000000000000000000000000000000000000000..e811199612129093c9bb01f33885301014b04356
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/elements_test_runner/ElementsTestRunner.js
@@ -0,0 +1,81 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview using private properties isn't a Closure violation in tests.
+ * @suppress {accessControls}
+ */
+
+/**
+ * @param {string} idValue
+ * @param {!Function} callback
+ */
+ElementsTestRunner.selectNodeWithId = function(idValue, callback) {
+ callback = TestRunner.safeWrap(callback);
+ function onNodeFound(node) {
+ ElementsTestRunner.selectNode(node).then(callback.bind(null, node));
+ }
+ ElementsTestRunner.nodeWithId(idValue, onNodeFound);
+};
+
+/**
+ * @param {!Object} node
+ * @return {!Promise.<undefined>}
+ */
+ElementsTestRunner.selectNode = function(node) {
+ return Common.Revealer.revealPromise(node);
+};
+
+/**
+ * @param {string} idValue
+ * @param {!Function} callback
+ */
+ElementsTestRunner.nodeWithId = function(idValue, callback) {
+ ElementsTestRunner.findNode(node => node.getAttribute('id') === idValue, callback);
+};
+
+/**
+ * @param {function(!Element): boolean} matchFunction
+ * @param {!Function} callback
+ */
+ElementsTestRunner.findNode = function(matchFunction, callback) {
+ callback = TestRunner.safeWrap(callback);
+ var result = null;
+ var pendingRequests = 0;
+ function processChildren(node) {
+ try {
+ if (result)
+ return;
+
+ var pseudoElementsMap = node.pseudoElements();
+ var pseudoElements = pseudoElementsMap ? pseudoElementsMap.valuesArray() : [];
+ var children = (node.children() || []).concat(node.shadowRoots()).concat(pseudoElements);
+ if (node.templateContent())
+ children.push(node.templateContent());
+ else if (node.importedDocument())
+ children.push(node.importedDocument());
+
+ for (var i = 0; i < children.length; ++i) {
+ var childNode = children[i];
+ if (matchFunction(childNode)) {
+ result = childNode;
+ callback(result);
+ return;
+ }
+ pendingRequests++;
+ childNode.getChildNodes(processChildren.bind(null, childNode));
+ }
+ } finally {
+ pendingRequests--;
+ }
+
+ if (!result && !pendingRequests)
+ callback(null);
+ }
+
+ TestRunner.domModel.requestDocument(doc => {
+ pendingRequests++;
+ doc.getChildNodes(processChildren.bind(null, doc));
+ });
+};

Powered by Google App Engine
This is Rietveld 408576698