| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function initialize_DumpAccessibilityNodesTest() { | 5 function initialize_DumpAccessibilityNodesTest() { |
| 6 | 6 |
| 7 var nodeInfo = {}; | 7 var nodeInfo = {}; |
| 8 InspectorTest.trackGetChildNodesEvents(nodeInfo); | 8 InspectorTest.trackGetChildNodesEvents(nodeInfo); |
| 9 | 9 |
| 10 InspectorTest.dumpAccessibilityNodesBySelectorAndCompleteTest = function(selecto
r, msg) { | 10 InspectorTest.dumpAccessibilityNodesBySelectorAndCompleteTest = function(selecto
r, msg) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 { | 47 { |
| 48 return sendCommandPromise("DOM.querySelectorAll", { "nodeId": nodeId, "selec
tor": | 48 return sendCommandPromise("DOM.querySelectorAll", { "nodeId": nodeId, "selec
tor": |
| 49 selector }); | 49 selector }); |
| 50 } | 50 } |
| 51 | 51 |
| 52 function getAXNodes(msg) | 52 function getAXNodes(msg) |
| 53 { | 53 { |
| 54 var promise; | 54 var promise; |
| 55 msg.result.nodeIds.forEach((id) => { | 55 msg.result.nodeIds.forEach((id) => { |
| 56 if (promise) | 56 if (promise) |
| 57 promise = promise.then(() => { return sendCommandPromise("Accessibil
ity.getAXNodeChain", { "nodeId": id, "fetchAncestors": false }); }); | 57 promise = promise.then(() => { return sendCommandPromise("Accessibil
ity.getAXNode", { "nodeId": id }); }); |
| 58 else | 58 else |
| 59 promise = sendCommandPromise("Accessibility.getAXNodeChain", { "node
Id": id, "fetchAncestors": false }); | 59 promise = sendCommandPromise("Accessibility.getAXNode", { "nodeId":
id }); |
| 60 promise = promise.then((msg) => { return rewriteRelatedNodes(msg); }) | 60 promise = promise.then((msg) => { return rewriteRelatedNodes(msg); }) |
| 61 .then((msg) => { return dumpNode(null, msg); }); | 61 .then((msg) => { return dumpNode(null, msg); }); |
| 62 }); | 62 }); |
| 63 return promise; | 63 return promise; |
| 64 } | 64 } |
| 65 | 65 |
| 66 function describeRelatedNode(nodeData) | 66 function describeRelatedNode(nodeData) |
| 67 { | 67 { |
| 68 var description = nodeData.nodeName.toLowerCase(); | 68 var description = nodeData.nodeName.toLowerCase(); |
| 69 switch (nodeData.nodeType) { | 69 switch (nodeData.nodeType) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 return new Promise(rewriteRelatedNodePromise); | 103 return new Promise(rewriteRelatedNodePromise); |
| 104 } | 104 } |
| 105 | 105 |
| 106 function checkExists(path, obj) | 106 function checkExists(path, obj) |
| 107 { | 107 { |
| 108 var pathComponents = path.split("."); | 108 var pathComponents = path.split("."); |
| 109 var currentPath = []; | 109 var currentPath = []; |
| 110 var currentObject = obj; | 110 var currentObject = obj; |
| 111 for (var component of pathComponents) { | 111 for (var component of pathComponents) { |
| 112 var isArray = false; | |
| 113 var index = -1; | |
| 114 var matches = component.match(/(\w+)\[(\d+)\]/); | |
| 115 if (matches) { | |
| 116 isArray = true; | |
| 117 component = matches[1]; | |
| 118 index = Number.parseInt(matches[2], 10); | |
| 119 } | |
| 120 currentPath.push(component); | 112 currentPath.push(component); |
| 121 if (!(component in currentObject)) { | 113 if (!(component in currentObject)) { |
| 122 InspectorTest.log("Could not find " + currentPath.join(".") + " in "
+ JSON.stringify(obj, null, " ")); | 114 throw new Error("Could not find " + currentPath.join(".") + " in " +
JSON.stringify(obj, null, " ")); |
| 123 InspectorTest.completeTest(); | 115 return false; |
| 124 } | 116 } |
| 125 if (isArray) | 117 currentObject = currentObject[component]; |
| 126 currentObject = currentObject[component][index]; | |
| 127 else | |
| 128 currentObject = currentObject[component]; | |
| 129 } | 118 } |
| 130 return true; | 119 return true; |
| 131 } | 120 } |
| 132 | 121 |
| 133 function check(condition, errorMsg, obj) | 122 function check(condition, errorMsg, obj) |
| 134 { | 123 { |
| 135 if (condition) | 124 if (condition) |
| 136 return true; | 125 return true; |
| 137 throw new Error(errorMsg + " in " + JSON.stringify(obj, null, " ")); | 126 throw new Error(errorMsg + " in " + JSON.stringify(obj, null, " ")); |
| 138 } | 127 } |
| 139 | 128 |
| 140 function rewriteRelatedNodeValue(value, promises) | 129 function rewriteRelatedNodeValue(value, promises) |
| 141 { | 130 { |
| 142 checkExists("relatedNodes", value); | 131 checkExists("relatedNodes", value); |
| 143 var relatedNodeArray = value.relatedNodes; | 132 var relatedNodeArray = value.relatedNodes; |
| 144 check(Array.isArray(relatedNodeArray), "relatedNodes should be an array", JS
ON.stringify(value)); | 133 check(Array.isArray(relatedNodeArray), "relatedNodes should be an array", JS
ON.stringify(value)); |
| 145 for (var relatedNode of relatedNodeArray) { | 134 for (var relatedNode of relatedNodeArray) { |
| 146 promises.push(rewriteRelatedNode(relatedNode)); | 135 promises.push(rewriteRelatedNode(relatedNode)); |
| 147 } | 136 } |
| 148 } | 137 } |
| 149 | 138 |
| 150 function rewriteRelatedNodes(msg) | 139 function rewriteRelatedNodes(msg) |
| 151 { | 140 { |
| 152 if (msg.error) { | 141 if (msg.error) { |
| 153 throw new Error(msg.error.message); | 142 throw new Error(msg.error.message); |
| 154 } | 143 } |
| 155 | 144 |
| 156 var node = msg.result.nodes[0]; | 145 var node = msg.result.accessibilityNode; |
| 157 | |
| 158 if (node.ignored) { | 146 if (node.ignored) { |
| 159 checkExists("result.nodes[0].ignoredReasons", msg); | 147 checkExists("result.accessibilityNode.ignoredReasons", msg); |
| 160 var properties = node.ignoredReasons; | 148 var properties = node.ignoredReasons; |
| 161 } else { | 149 } else { |
| 162 checkExists("result.nodes[0].properties", msg); | 150 checkExists("result.accessibilityNode.properties", msg); |
| 163 var properties = node.properties; | 151 var properties = node.properties; |
| 164 } | 152 } |
| 165 var promises = []; | 153 var promises = []; |
| 166 if (node.name && node.name.sources) { | 154 if (node.name && node.name.sources) { |
| 167 for (var source of node.name.sources) { | 155 for (var source of node.name.sources) { |
| 168 var value; | 156 var value; |
| 169 if (source.value) | 157 if (source.value) |
| 170 value = source.value; | 158 value = source.value; |
| 171 if (source.attributeValue) | 159 if (source.attributeValue) |
| 172 value = source.attributeValue; | 160 value = source.attributeValue; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 195 return "<int>" | 183 return "<int>" |
| 196 if (key == "backendNodeId") | 184 if (key == "backendNodeId") |
| 197 return "<string>" | 185 return "<string>" |
| 198 if (key == "nodeId") | 186 if (key == "nodeId") |
| 199 return "<string>" | 187 return "<string>" |
| 200 return value; | 188 return value; |
| 201 } | 189 } |
| 202 InspectorTest.log((selector ? selector + ": " : "") + JSON.stringify(msg, st
ripIds, " ")); | 190 InspectorTest.log((selector ? selector + ": " : "") + JSON.stringify(msg, st
ripIds, " ")); |
| 203 } | 191 } |
| 204 } | 192 } |
| OLD | NEW |