OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 import functools | 5 import functools |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import socket | 8 import socket |
9 import sys | 9 import sys |
10 | 10 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 268 |
269 if interactionMarkerName is not None: | 269 if interactionMarkerName is not None: |
270 params['interactionMarkerName'] = interactionMarkerName | 270 params['interactionMarkerName'] = interactionMarkerName |
271 | 271 |
272 scroll_command = { | 272 scroll_command = { |
273 'method': 'Input.synthesizeScrollGesture', | 273 'method': 'Input.synthesizeScrollGesture', |
274 'params': params | 274 'params': params |
275 } | 275 } |
276 return self._runtime.RunInspectorCommand(scroll_command, timeout) | 276 return self._runtime.RunInspectorCommand(scroll_command, timeout) |
277 | 277 |
| 278 @_HandleInspectorWebSocketExceptions |
| 279 def DispatchKeyEvent(self, keyEventType='char', modifiers=None, |
| 280 timestamp=None, text=None, unmodifiedText=None, |
| 281 keyIdentifier=None, domCode=None, domKey=None, |
| 282 windowsVirtualKeyCode=None, nativeVirtualKeyCode=None, |
| 283 autoRepeat=None, isKeypad=None, isSystemKey=None, |
| 284 timeout=60): |
| 285 """Dispatches a key event to the page. |
| 286 |
| 287 Args: |
| 288 type: Type of the key event. Allowed values: 'keyDown', 'keyUp', |
| 289 'rawKeyDown', 'char'. |
| 290 modifiers: Bit field representing pressed modifier keys. Alt=1, Ctrl=2, |
| 291 Meta/Command=4, Shift=8 (default: 0). |
| 292 timestamp: Time at which the event occurred. Measured in UTC time in |
| 293 seconds since January 1, 1970 (default: current time). |
| 294 text: Text as generated by processing a virtual key code with a keyboard |
| 295 layout. Not needed for for keyUp and rawKeyDown events (default: ''). |
| 296 unmodifiedText: Text that would have been generated by the keyboard if no |
| 297 modifiers were pressed (except for shift). Useful for shortcut |
| 298 (accelerator) key handling (default: ""). |
| 299 keyIdentifier: Unique key identifier (e.g., 'U+0041') (default: ''). |
| 300 windowsVirtualKeyCode: Windows virtual key code (default: 0). |
| 301 nativeVirtualKeyCode: Native virtual key code (default: 0). |
| 302 autoRepeat: Whether the event was generated from auto repeat (default: |
| 303 False). |
| 304 isKeypad: Whether the event was generated from the keypad (default: |
| 305 False). |
| 306 isSystemKey: Whether the event was a system key event (default: False). |
| 307 |
| 308 Raises: |
| 309 exceptions.TimeoutException |
| 310 exceptions.DevtoolsTargetCrashException |
| 311 """ |
| 312 params = { |
| 313 'type': keyEventType, |
| 314 } |
| 315 |
| 316 if modifiers is not None: |
| 317 params['modifiers'] = modifiers |
| 318 if timestamp is not None: |
| 319 params['timestamp'] = timestamp |
| 320 if text is not None: |
| 321 params['text'] = text |
| 322 if unmodifiedText is not None: |
| 323 params['unmodifiedText'] = unmodifiedText |
| 324 if keyIdentifier is not None: |
| 325 params['keyIdentifier'] = keyIdentifier |
| 326 if domCode is not None: |
| 327 params['code'] = domCode |
| 328 if domKey is not None: |
| 329 params['key'] = domKey |
| 330 if windowsVirtualKeyCode is not None: |
| 331 params['windowsVirtualKeyCode'] = windowsVirtualKeyCode |
| 332 if nativeVirtualKeyCode is not None: |
| 333 params['nativeVirtualKeyCode'] = nativeVirtualKeyCode |
| 334 if autoRepeat is not None: |
| 335 params['autoRepeat'] = autoRepeat |
| 336 if isKeypad is not None: |
| 337 params['isKeypad'] = isKeypad |
| 338 if isSystemKey is not None: |
| 339 params['isSystemKey'] = isSystemKey |
| 340 |
| 341 key_command = { |
| 342 'method': 'Input.dispatchKeyEvent', |
| 343 'params': params |
| 344 } |
| 345 return self._runtime.RunInspectorCommand(key_command, timeout) |
| 346 |
278 # Methods used internally by other backends. | 347 # Methods used internally by other backends. |
279 | 348 |
280 def _HandleInspectorDomainNotification(self, res): | 349 def _HandleInspectorDomainNotification(self, res): |
281 if (res['method'] == 'Inspector.detached' and | 350 if (res['method'] == 'Inspector.detached' and |
282 res.get('params', {}).get('reason', '') == 'replaced_with_devtools'): | 351 res.get('params', {}).get('reason', '') == 'replaced_with_devtools'): |
283 self._WaitForInspectorToGoAway() | 352 self._WaitForInspectorToGoAway() |
284 return | 353 return |
285 if res['method'] == 'Inspector.targetCrashed': | 354 if res['method'] == 'Inspector.targetCrashed': |
286 exception = exceptions.DevtoolsTargetCrashException(self.app) | 355 exception = exceptions.DevtoolsTargetCrashException(self.app) |
287 self._AddDebuggingInformation(exception) | 356 self._AddDebuggingInformation(exception) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 msg = ( | 406 msg = ( |
338 'Received a socket error in the browser connection and the tab no ' | 407 'Received a socket error in the browser connection and the tab no ' |
339 'longer exists. The tab probably crashed.' | 408 'longer exists. The tab probably crashed.' |
340 ) | 409 ) |
341 error.AddDebuggingMessage(msg) | 410 error.AddDebuggingMessage(msg) |
342 error.AddDebuggingMessage('Debugger url: %s' % self.debugger_url) | 411 error.AddDebuggingMessage('Debugger url: %s' % self.debugger_url) |
343 | 412 |
344 @_HandleInspectorWebSocketExceptions | 413 @_HandleInspectorWebSocketExceptions |
345 def CollectGarbage(self): | 414 def CollectGarbage(self): |
346 self._page.CollectGarbage() | 415 self._page.CollectGarbage() |
OLD | NEW |