Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / accessibility / accessibility-ignoredNodesTest.js
blob6f814b8b4275715b84420ce1cde16d290b205243
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)
8     if (msg.error) {
9         InspectorTest.log(msg.error.message);
10         InspectorTest.completeTest();
11         return;
12     }
15     var rootNode = msg.result.root;
16     var promises = [];
17     for (var id of ids) {
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));
25                    })
26         promises.push(promise);
27     }
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) {
36             if (msg.error) {
37                 reject(msg.error);
38                 return;
39             }
41             resolve(msg);
42         })
43     });
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");
64         if (p >= 0)
65             description += "#" + nodeData.attributes[p + 1];
66     }
67     return description;
70 InspectorTest._rewriteNode = function(relatedNode)
72     function rewriteNodePromise(resolve, reject)
73     {
74         if (!("backendNodeId" in relatedNode)) {
75             reject("Could not find backendNodeId in " + JSON.stringify(relatedNode));
76             return;
77         }
78         var backendNodeId = relatedNode.backendNodeId;
80         function onNodeResolved(backendNodeId, message)
81         {
82             var nodeId = message.result.nodeIds[0];
83             if (!(nodeId in nodeInfo)) {
84                 relatedNode.nodeResult = "[NODE NOT FOUND]";
85                 resolve();
86                 return;
87             }
88             var node = nodeInfo[nodeId];
89             delete relatedNode.backendNodeId;
90             relatedNode.nodeResult = InspectorTest._describeNode(node);
91             resolve();
92         }
93         InspectorTest.sendCommand("DOM.pushNodesByBackendIdsToFrontend", { "backendNodeIds": [ backendNodeId ] }, onNodeResolved.bind(null, backendNodeId));
94     }
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, "  "));
107             return false;
108         }
109         currentObject = currentObject[component];
110     }
111     return true;
114 InspectorTest._check = function(condition, errorMsg, obj, reject)
116     if (condition)
117         return true;
118     reject(errorMsg + " in " + JSON.stringify(obj, null, "  "));
121 InspectorTest._rewriteNodes = function(msg)
123     function rewriteNodesPromise(resolve, reject)
124     {
125         if (msg.error) {
126             reject(msg.error.message);
127             return;
128         }
130         if (msg.result.accessibilityNode.ignored) {
131             InspectorTest._checkExists("result.accessibilityNode.ignoredReasons", msg);
132             var properties = msg.result.accessibilityNode.ignoredReasons;
133         } else {
134             InspectorTest._checkExists("result.accessibilityNode.properties", msg);
135             var properties = msg.result.accessibilityNode.properties;
136         }
137         var promises = [];
138         for (var property of properties) {
139             if (property.value.type === "idrefList") {
140                 if (!InspectorTest._checkExists("value.relatedNodeArrayValue", property, reject))
141                     return;
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))
148                     return;
149                 var relatedNode = property.value.relatedNodeValue;
150                 promises.push(InspectorTest._rewriteNode(relatedNode));
151             }
152         }
154         Promise.all(promises).then(resolve(msg));
155     }
156     return new Promise(rewriteNodesPromise);
159 InspectorTest._dumpNode = function(selector, msg)
161     function stripIds(key, value)
162     {
163         if (key == "id")
164             return "<int>"
165         if (key == "backendNodeId")
166             return "<string>"
167         if (key == "nodeId")
168             return "<string>"
169         return value;
170     }
171     InspectorTest.log(selector + ": " + JSON.stringify(msg, stripIds, "  "));