1 // Copyright 2015 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.
5 function initialize_IgnoredNodesTests() {
6 InspectorTest.dumpAccessibilityNodesByIdrefAndCompleteTest = function(ids, msg)
9 InspectorTest.log(msg.error.message);
10 InspectorTest.completeTest();
15 var rootNode = msg.result.root;
18 var selector = "#" + id;
19 var promise = InspectorTest._sendQuerySelector(rootNode.nodeId, selector)
20 .then(InspectorTest._getAXNode)
21 .then(InspectorTest._rewriteNodes)
22 .then(InspectorTest._dumpNode.bind(null, selector))
23 .catch(function(msg) {
24 InspectorTest.log("Error: " + JSON.stringify(msg));
26 promises.push(promise);
29 Promise.all(promises).then(function() { InspectorTest.completeTest(); });
32 InspectorTest._sendCommandPromise = function(command, params)
34 return new Promise(function(resolve, reject) {
35 InspectorTest.sendCommand(command, params, function(msg) {
47 InspectorTest._sendQuerySelector = function(nodeId, selector)
49 return InspectorTest._sendCommandPromise("DOM.querySelector", { "nodeId": nodeId, "selector": selector });
52 InspectorTest._getAXNode = function(msg)
54 var node = msg.result;
55 return InspectorTest._sendCommandPromise("Accessibility.getAXNode", { "nodeId": node.nodeId });
58 InspectorTest._describeNode = function(nodeData)
60 var description = nodeData.nodeName.toLowerCase();
61 switch (nodeData.nodeType) {
62 case Node.ELEMENT_NODE:
63 var p = nodeData.attributes.indexOf("id");
65 description += "#" + nodeData.attributes[p + 1];
70 InspectorTest._rewriteNode = function(relatedNode)
72 function rewriteNodePromise(resolve, reject)
74 if (!("backendNodeId" in relatedNode)) {
75 reject("Could not find backendNodeId in " + JSON.stringify(relatedNode));
78 var backendNodeId = relatedNode.backendNodeId;
80 function onNodeResolved(backendNodeId, message)
82 var nodeId = message.result.nodeIds[0];
83 if (!(nodeId in nodeInfo)) {
84 relatedNode.nodeResult = "[NODE NOT FOUND]";
88 var node = nodeInfo[nodeId];
89 delete relatedNode.backendNodeId;
90 relatedNode.nodeResult = InspectorTest._describeNode(node);
93 InspectorTest.sendCommand("DOM.pushNodesByBackendIdsToFrontend", { "backendNodeIds": [ backendNodeId ] }, onNodeResolved.bind(null, backendNodeId));
95 return new Promise(rewriteNodePromise);
98 InspectorTest._checkExists = function(path, obj, reject)
100 var pathComponents = path.split(".");
101 var currentPath = [];
102 var currentObject = obj;
103 for (var component of pathComponents) {
104 currentPath.push(component);
105 if (!(component in currentObject)) {
106 reject("Could not find " + currentPath.join(".") + " in " + JSON.stringify(obj, null, " "));
109 currentObject = currentObject[component];
114 InspectorTest._check = function(condition, errorMsg, obj, reject)
118 reject(errorMsg + " in " + JSON.stringify(obj, null, " "));
121 InspectorTest._rewriteNodes = function(msg)
123 function rewriteNodesPromise(resolve, reject)
126 reject(msg.error.message);
130 if (msg.result.accessibilityNode.ignored) {
131 InspectorTest._checkExists("result.accessibilityNode.ignoredReasons", msg);
132 var properties = msg.result.accessibilityNode.ignoredReasons;
134 InspectorTest._checkExists("result.accessibilityNode.properties", msg);
135 var properties = msg.result.accessibilityNode.properties;
138 for (var property of properties) {
139 if (property.value.type === "idrefList") {
140 if (!InspectorTest._checkExists("value.relatedNodeArrayValue", property, reject))
142 var relatedNodeArray = property.value.relatedNodeArrayValue;
143 InspectorTest._check(Array.isArray(relatedNodeArray), "value.relatedNodeArrayValue should be an array", JSON.stringify(property), reject);
144 for (var relatedNode of relatedNodeArray)
145 promises.push(InspectorTest._rewriteNode(relatedNode));
146 } else if (property.value.type === "idref") {
147 if (!InspectorTest._checkExists("value.relatedNodeValue", property, reject))
149 var relatedNode = property.value.relatedNodeValue;
150 promises.push(InspectorTest._rewriteNode(relatedNode));
154 Promise.all(promises).then(resolve(msg));
156 return new Promise(rewriteNodesPromise);
159 InspectorTest._dumpNode = function(selector, msg)
161 function stripIds(key, value)
165 if (key == "backendNodeId")
171 InspectorTest.log(selector + ": " + JSON.stringify(msg, stripIds, " "));