132 | | If your UI-side script is very simple and only accesses uiController properties, then it doesn't need to call uiScriptComplete(). If you call any uiController functions that are asynchronous (i.e. take a callback), then you need to call uiScriptComplete() at some point. |
| 132 | UIScriptController also supports sending key events. However, the keyboard must first be shown for the key events to be properly handled. First, your UI-side script must perform some action that will cause the keyboard to be shown. Your script must then bind uiController.didShowKeyboardCallback to a function which is invoked after the keyboard is shown and is ready to accept key inputs. This callback should call one of the typeCharacter methods (currently, there is only typeCharacterUsingHardwareKeyboard, but we intend on supporting software key events as well). In the below example, suppose that tapping at (50, 25) touches an input element. |
| 133 | |
| 134 | {{{ |
| 135 | (function() { |
| 136 | uiController.singleTapAtPoint(50, 25, function() { }); |
| 137 | uiController.didShowKeyboardCallback = function() { |
| 138 | uiController.typeCharacterUsingHardwareKeyboard("a", function() { }); |
| 139 | } |
| 140 | })(); |
| 141 | }}} |
| 142 | |
| 143 | Observe that we didn't call uiController.uiScriptComplete. This is because when the key event is handled by the UI process, there is no guarantee that the web process has received the resulting editing event, so the value of the element may not be updated. Instead of waiting on the UI-side script to complete, we can instead invoke testRunner.notifyDone when the element itself has received an oninput event. |
| 144 | |
| 145 | If your UI-side script is very simple and only accesses uiController properties, then it doesn't need to call uiScriptComplete(). If you call any uiController functions that are asynchronous (i.e. take a callback), then you need to call uiScriptComplete() at some point unless you are waiting to invoke testRunner.notifyDone from the web process. |