| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 string | 5 import string |
| 6 | 6 |
| 7 from telemetry.internal.actions import page_action | 7 from telemetry.internal.actions import page_action |
| 8 | 8 |
| 9 | 9 |
| 10 # Map from DOM key values | 10 # Map from DOM key values |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 class KeyPressAction(page_action.PageAction): | 72 class KeyPressAction(page_action.PageAction): |
| 73 | 73 |
| 74 def __init__(self, dom_key, timeout=60): | 74 def __init__(self, dom_key, timeout=60): |
| 75 super(KeyPressAction, self).__init__() | 75 super(KeyPressAction, self).__init__() |
| 76 self._dom_key = dom_key | 76 self._dom_key = dom_key |
| 77 if dom_key not in _KEY_MAP: | 77 if dom_key not in _KEY_MAP: |
| 78 raise ValueError('No mapping for key: %s' % dom_key) | 78 raise ValueError('No mapping for key: %s' % dom_key) |
| 79 self._windows_virtual_key_code, self._text = _KEY_MAP[dom_key] | 79 self._windows_virtual_key_code, self._text = _KEY_MAP[dom_key] |
| 80 self._timeout = timeout | 80 self._timeout = timeout |
| 81 | 81 |
| 82 def SimulatesUserInput(self): |
| 83 return True |
| 84 |
| 82 def RunAction(self, tab): | 85 def RunAction(self, tab): |
| 83 tab.DispatchKeyEvent(keyEventType='rawKeyDown', | 86 tab.DispatchKeyEvent(keyEventType='rawKeyDown', |
| 84 domKey=self._dom_key, | 87 domKey=self._dom_key, |
| 85 windowsVirtualKeyCode=self._windows_virtual_key_code, | 88 windowsVirtualKeyCode=self._windows_virtual_key_code, |
| 86 timeout=self._timeout) | 89 timeout=self._timeout) |
| 87 if self._text: | 90 if self._text: |
| 88 tab.DispatchKeyEvent(keyEventType='char', | 91 tab.DispatchKeyEvent(keyEventType='char', |
| 89 text=self._text, | 92 text=self._text, |
| 90 domKey=self._dom_key, | 93 domKey=self._dom_key, |
| 91 windowsVirtualKeyCode=ord(self._text), | 94 windowsVirtualKeyCode=ord(self._text), |
| 92 timeout=self._timeout) | 95 timeout=self._timeout) |
| 93 tab.DispatchKeyEvent(keyEventType='keyUp', | 96 tab.DispatchKeyEvent(keyEventType='keyUp', |
| 94 domKey=self._dom_key, | 97 domKey=self._dom_key, |
| 95 windowsVirtualKeyCode=self._windows_virtual_key_code, | 98 windowsVirtualKeyCode=self._windows_virtual_key_code, |
| 96 timeout=self._timeout) | 99 timeout=self._timeout) |
| OLD | NEW |