| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 var AutomationEvent = require('automationEvent').AutomationEvent; | 5 var AutomationEvent = require('automationEvent').AutomationEvent; |
| 6 var automationInternal = | 6 var automationInternal = |
| 7 require('binding').Binding.create('automationInternal').generate(); | 7 require('binding').Binding.create('automationInternal').generate(); |
| 8 var IsInteractPermitted = | 8 var IsInteractPermitted = |
| 9 requireNative('automationInternal').IsInteractPermitted; | 9 requireNative('automationInternal').IsInteractPermitted; |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 makeVisible: function() { | 88 makeVisible: function() { |
| 89 this.performAction_('makeVisible'); | 89 this.performAction_('makeVisible'); |
| 90 }, | 90 }, |
| 91 | 91 |
| 92 setSelection: function(startIndex, endIndex) { | 92 setSelection: function(startIndex, endIndex) { |
| 93 this.performAction_('setSelection', | 93 this.performAction_('setSelection', |
| 94 { startIndex: startIndex, | 94 { startIndex: startIndex, |
| 95 endIndex: endIndex }); | 95 endIndex: endIndex }); |
| 96 }, | 96 }, |
| 97 | 97 |
| 98 query: function(queryParams, callback) { |
| 99 if ('selector' in queryParams) { |
| 100 automationInternal.querySelector( |
| 101 { processID: this.rootImpl.processID, |
| 102 routingID: this.rootImpl.routingID, |
| 103 automationNodeID: this.id, |
| 104 selector: queryParams.selector }, |
| 105 this.querySelectorCallback_.bind(this, callback)); |
| 106 } |
| 107 }, |
| 108 |
| 98 addEventListener: function(eventType, callback, capture) { | 109 addEventListener: function(eventType, callback, capture) { |
| 99 this.removeEventListener(eventType, callback); | 110 this.removeEventListener(eventType, callback); |
| 100 if (!this.listeners[eventType]) | 111 if (!this.listeners[eventType]) |
| 101 this.listeners[eventType] = []; | 112 this.listeners[eventType] = []; |
| 102 this.listeners[eventType].push({callback: callback, capture: !!capture}); | 113 this.listeners[eventType].push({callback: callback, capture: !!capture}); |
| 103 }, | 114 }, |
| 104 | 115 |
| 105 // TODO(dtseng/aboxhall): Check this impl against spec. | 116 // TODO(dtseng/aboxhall): Check this impl against spec. |
| 106 removeEventListener: function(eventType, callback) { | 117 removeEventListener: function(eventType, callback) { |
| 107 if (this.listeners[eventType]) { | 118 if (this.listeners[eventType]) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 129 // - bubbling: starting from the target's parent, going back up to the root. | 140 // - bubbling: starting from the target's parent, going back up to the root. |
| 130 // At any stage, a listener may call stopPropagation() on the event, which | 141 // At any stage, a listener may call stopPropagation() on the event, which |
| 131 // will immediately stop event propagation through this path. | 142 // will immediately stop event propagation through this path. |
| 132 if (this.dispatchEventAtCapturing_(event, path)) { | 143 if (this.dispatchEventAtCapturing_(event, path)) { |
| 133 if (this.dispatchEventAtTargeting_(event, path)) | 144 if (this.dispatchEventAtTargeting_(event, path)) |
| 134 this.dispatchEventAtBubbling_(event, path); | 145 this.dispatchEventAtBubbling_(event, path); |
| 135 } | 146 } |
| 136 }, | 147 }, |
| 137 | 148 |
| 138 toString: function() { | 149 toString: function() { |
| 139 return 'node id=' + this.id + | 150 var impl = privates(this).impl; |
| 151 if (!impl) |
| 152 impl = this; |
| 153 return 'node id=' + impl.id + |
| 140 ' role=' + this.role + | 154 ' role=' + this.role + |
| 141 ' state=' + $JSON.stringify(this.state) + | 155 ' state=' + $JSON.stringify(this.state) + |
| 142 ' parentID=' + this.parentID + | 156 ' parentID=' + impl.parentID + |
| 143 ' childIds=' + $JSON.stringify(this.childIds) + | 157 ' childIds=' + $JSON.stringify(impl.childIds) + |
| 144 ' attributes=' + $JSON.stringify(this.attributes); | 158 ' attributes=' + $JSON.stringify(this.attributes); |
| 145 }, | 159 }, |
| 146 | 160 |
| 147 dispatchEventAtCapturing_: function(event, path) { | 161 dispatchEventAtCapturing_: function(event, path) { |
| 148 privates(event).impl.eventPhase = Event.CAPTURING_PHASE; | 162 privates(event).impl.eventPhase = Event.CAPTURING_PHASE; |
| 149 for (var i = path.length - 1; i >= 0; i--) { | 163 for (var i = path.length - 1; i >= 0; i--) { |
| 150 this.fireEventListeners_(path[i], event); | 164 this.fireEventListeners_(path[i], event); |
| 151 if (privates(event).impl.propagationStopped) | 165 if (privates(event).impl.propagationStopped) |
| 152 return false; | 166 return false; |
| 153 } | 167 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (!IsInteractPermitted()) { | 218 if (!IsInteractPermitted()) { |
| 205 throw new Error(actionType + ' requires {"desktop": true} or' + | 219 throw new Error(actionType + ' requires {"desktop": true} or' + |
| 206 ' {"interact": true} in the "automation" manifest key.'); | 220 ' {"interact": true} in the "automation" manifest key.'); |
| 207 } | 221 } |
| 208 | 222 |
| 209 automationInternal.performAction({ processID: this.rootImpl.processID, | 223 automationInternal.performAction({ processID: this.rootImpl.processID, |
| 210 routingID: this.rootImpl.routingID, | 224 routingID: this.rootImpl.routingID, |
| 211 automationNodeID: this.id, | 225 automationNodeID: this.id, |
| 212 actionType: actionType }, | 226 actionType: actionType }, |
| 213 opt_args || {}); | 227 opt_args || {}); |
| 228 }, |
| 229 |
| 230 querySelectorCallback_: function(userCallback, resultAutomationNodeID) { |
| 231 if (resultAutomationNodeID == 0) { |
| 232 userCallback(null); |
| 233 return; |
| 234 } |
| 235 var resultNode = this.rootImpl.get(resultAutomationNodeID); |
| 236 if (!resultNode) { |
| 237 logging.WARNING('Query selector result not in tree: ' + |
| 238 resultAutomationNodeID) |
| 239 } |
| 240 userCallback(resultNode); |
| 214 } | 241 } |
| 215 }; | 242 }; |
| 216 | 243 |
| 217 // Maps an attribute to its default value in an invalidated node. | 244 // Maps an attribute to its default value in an invalidated node. |
| 218 // These attributes are taken directly from the Automation idl. | 245 // These attributes are taken directly from the Automation idl. |
| 219 var AutomationAttributeDefaults = { | 246 var AutomationAttributeDefaults = { |
| 220 'id': -1, | 247 'id': -1, |
| 221 'role': '', | 248 'role': '', |
| 222 'state': {}, | 249 'state': {}, |
| 223 'location': { left: 0, top: 0, width: 0, height: 0 } | 250 'location': { left: 0, top: 0, width: 0, height: 0 } |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 'firstChild', | 619 'firstChild', |
| 593 'lastChild', | 620 'lastChild', |
| 594 'children', | 621 'children', |
| 595 'previousSibling', | 622 'previousSibling', |
| 596 'nextSibling', | 623 'nextSibling', |
| 597 'doDefault', | 624 'doDefault', |
| 598 'focus', | 625 'focus', |
| 599 'makeVisible', | 626 'makeVisible', |
| 600 'setSelection', | 627 'setSelection', |
| 601 'addEventListener', | 628 'addEventListener', |
| 602 'removeEventListener'], | 629 'removeEventListener', |
| 630 'query', |
| 631 'toString'], |
| 603 readonly: ['isRootNode', | 632 readonly: ['isRootNode', |
| 604 'role', | 633 'role', |
| 605 'state', | 634 'state', |
| 606 'location', | 635 'location', |
| 607 'attributes', | 636 'attributes', |
| 608 'root'] }); | 637 'root'] }); |
| 609 | 638 |
| 610 var AutomationRootNode = utils.expose('AutomationRootNode', | 639 var AutomationRootNode = utils.expose('AutomationRootNode', |
| 611 AutomationRootNodeImpl, | 640 AutomationRootNodeImpl, |
| 612 { superclass: AutomationNode, | 641 { superclass: AutomationNode, |
| 613 functions: ['load'], | 642 functions: ['load', |
| 643 'toString'], |
| 614 readonly: ['loaded'] }); | 644 readonly: ['loaded'] }); |
| 615 | 645 |
| 616 exports.AutomationNode = AutomationNode; | 646 exports.AutomationNode = AutomationNode; |
| 617 exports.AutomationRootNode = AutomationRootNode; | 647 exports.AutomationRootNode = AutomationRootNode; |
| OLD | NEW |