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.getAXNode", { "nodeId": id }); }); | 57 promise = promise.then(() => { return sendCommandPromise("Accessibil
ity.getAXNodeChain", { "nodeId": id, "fetchAncestors": false }); }); |
58 else | 58 else |
59 promise = sendCommandPromise("Accessibility.getAXNode", { "nodeId":
id }); | 59 promise = sendCommandPromise("Accessibility.getAXNodeChain", { "node
Id": id, "fetchAncestors": false }); |
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 } |
112 currentPath.push(component); | 120 currentPath.push(component); |
113 if (!(component in currentObject)) { | 121 if (!(component in currentObject)) { |
114 throw new Error("Could not find " + currentPath.join(".") + " in " +
JSON.stringify(obj, null, " ")); | 122 InspectorTest.log("Could not find " + currentPath.join(".") + " in "
+ JSON.stringify(obj, null, " ")); |
115 return false; | 123 InspectorTest.completeTest(); |
116 } | 124 } |
117 currentObject = currentObject[component]; | 125 if (isArray) |
| 126 currentObject = currentObject[component][index]; |
| 127 else |
| 128 currentObject = currentObject[component]; |
118 } | 129 } |
119 return true; | 130 return true; |
120 } | 131 } |
121 | 132 |
122 function check(condition, errorMsg, obj) | 133 function check(condition, errorMsg, obj) |
123 { | 134 { |
124 if (condition) | 135 if (condition) |
125 return true; | 136 return true; |
126 throw new Error(errorMsg + " in " + JSON.stringify(obj, null, " ")); | 137 throw new Error(errorMsg + " in " + JSON.stringify(obj, null, " ")); |
127 } | 138 } |
128 | 139 |
129 function rewriteRelatedNodeValue(value, promises) | 140 function rewriteRelatedNodeValue(value, promises) |
130 { | 141 { |
131 checkExists("relatedNodes", value); | 142 checkExists("relatedNodes", value); |
132 var relatedNodeArray = value.relatedNodes; | 143 var relatedNodeArray = value.relatedNodes; |
133 check(Array.isArray(relatedNodeArray), "relatedNodes should be an array", JS
ON.stringify(value)); | 144 check(Array.isArray(relatedNodeArray), "relatedNodes should be an array", JS
ON.stringify(value)); |
134 for (var relatedNode of relatedNodeArray) { | 145 for (var relatedNode of relatedNodeArray) { |
135 promises.push(rewriteRelatedNode(relatedNode)); | 146 promises.push(rewriteRelatedNode(relatedNode)); |
136 } | 147 } |
137 } | 148 } |
138 | 149 |
139 function rewriteRelatedNodes(msg) | 150 function rewriteRelatedNodes(msg) |
140 { | 151 { |
141 if (msg.error) { | 152 if (msg.error) { |
142 throw new Error(msg.error.message); | 153 throw new Error(msg.error.message); |
143 } | 154 } |
144 | 155 |
145 var node = msg.result.accessibilityNode; | 156 var node = msg.result.nodes[0]; |
| 157 |
146 if (node.ignored) { | 158 if (node.ignored) { |
147 checkExists("result.accessibilityNode.ignoredReasons", msg); | 159 checkExists("result.nodes[0].ignoredReasons", msg); |
148 var properties = node.ignoredReasons; | 160 var properties = node.ignoredReasons; |
149 } else { | 161 } else { |
150 checkExists("result.accessibilityNode.properties", msg); | 162 checkExists("result.nodes[0].properties", msg); |
151 var properties = node.properties; | 163 var properties = node.properties; |
152 } | 164 } |
153 var promises = []; | 165 var promises = []; |
154 if (node.name && node.name.sources) { | 166 if (node.name && node.name.sources) { |
155 for (var source of node.name.sources) { | 167 for (var source of node.name.sources) { |
156 var value; | 168 var value; |
157 if (source.value) | 169 if (source.value) |
158 value = source.value; | 170 value = source.value; |
159 if (source.attributeValue) | 171 if (source.attributeValue) |
160 value = source.attributeValue; | 172 value = source.attributeValue; |
(...skipping 22 matching lines...) Expand all Loading... |
183 return "<int>" | 195 return "<int>" |
184 if (key == "backendNodeId") | 196 if (key == "backendNodeId") |
185 return "<string>" | 197 return "<string>" |
186 if (key == "nodeId") | 198 if (key == "nodeId") |
187 return "<string>" | 199 return "<string>" |
188 return value; | 200 return value; |
189 } | 201 } |
190 InspectorTest.log((selector ? selector + ": " : "") + JSON.stringify(msg, st
ripIds, " ")); | 202 InspectorTest.log((selector ? selector + ": " : "") + JSON.stringify(msg, st
ripIds, " ")); |
191 } | 203 } |
192 } | 204 } |
OLD | NEW |