From 0c88bf895c12cc42592ccd01ccf2c5c60ce68e9f Mon Sep 17 00:00:00 2001 From: lutz-grex Date: Mon, 16 Nov 2026 19:38:19 +0100 Subject: [PATCH 1/2] test(conformance): replay shared fixtures Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ci.yml | 33 + README.md | 5 + conformance/VERSION | 1 + conformance/fixtures/constants.json | 335 ++ conformance/fixtures/control/hover.json | 70 + conformance/fixtures/control/keycode.json | 204 + conformance/fixtures/control/scroll.json | 238 + .../fixtures/control/set-clipboard.json | 356 ++ conformance/fixtures/control/text.json | 158 + conformance/fixtures/control/touch.json | 439 ++ conformance/fixtures/input/geometry.json | 359 ++ conformance/fixtures/input/ime.json | 378 ++ conformance/fixtures/input/keys.json | 4571 +++++++++++++++++ conformance/fixtures/input/pointers.json | 1223 +++++ conformance/fixtures/input/scroll.json | 315 ++ conformance/fixtures/reconnect/policy.json | 136 + conformance/fixtures/reconnect/scenarios.json | 1298 +++++ .../fixtures/signalling/client-candidate.json | 47 + .../signalling/client-keep-alive.json | 26 + .../fixtures/signalling/client-offer.json | 32 + .../fixtures/signalling/client-open-url.json | 36 + .../signalling/client-request-frame.json | 26 + .../client-request-rtc-configuration.json | 33 + .../signalling/client-screenshot-request.json | 31 + conformance/fixtures/signalling/sequence.json | 204 + .../fixtures/signalling/server-answer.json | 29 + .../fixtures/signalling/server-candidate.json | 41 + .../signalling/server-rtc-configuration.json | 59 + .../signalling/server-screenshot-error.json | 36 + .../signalling/server-screenshot.json | 37 + scripts/sync-conformance.sh | 43 + src/conformance/control.test.ts | 66 + src/conformance/fixtures.ts | 16 + src/conformance/input.test.ts | 155 + src/conformance/reconnect.test.ts | 137 + src/conformance/signalling.test.ts | 207 + src/hooks/use-scrcpy-input.ts | 464 +- src/hooks/use-task-approval.test.ts | 82 + src/hooks/use-task-approval.ts | 24 +- src/hooks/use-webrtc-connection.test.ts | 105 +- src/hooks/webrtc-test-fixture.ts | 110 + src/lib/input-routing.ts | 345 ++ 42 files changed, 12045 insertions(+), 465 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 conformance/VERSION create mode 100644 conformance/fixtures/constants.json create mode 100644 conformance/fixtures/control/hover.json create mode 100644 conformance/fixtures/control/keycode.json create mode 100644 conformance/fixtures/control/scroll.json create mode 100644 conformance/fixtures/control/set-clipboard.json create mode 100644 conformance/fixtures/control/text.json create mode 100644 conformance/fixtures/control/touch.json create mode 100644 conformance/fixtures/input/geometry.json create mode 100644 conformance/fixtures/input/ime.json create mode 100644 conformance/fixtures/input/keys.json create mode 100644 conformance/fixtures/input/pointers.json create mode 100644 conformance/fixtures/input/scroll.json create mode 100644 conformance/fixtures/reconnect/policy.json create mode 100644 conformance/fixtures/reconnect/scenarios.json create mode 100644 conformance/fixtures/signalling/client-candidate.json create mode 100644 conformance/fixtures/signalling/client-keep-alive.json create mode 100644 conformance/fixtures/signalling/client-offer.json create mode 100644 conformance/fixtures/signalling/client-open-url.json create mode 100644 conformance/fixtures/signalling/client-request-frame.json create mode 100644 conformance/fixtures/signalling/client-request-rtc-configuration.json create mode 100644 conformance/fixtures/signalling/client-screenshot-request.json create mode 100644 conformance/fixtures/signalling/sequence.json create mode 100644 conformance/fixtures/signalling/server-answer.json create mode 100644 conformance/fixtures/signalling/server-candidate.json create mode 100644 conformance/fixtures/signalling/server-rtc-configuration.json create mode 100644 conformance/fixtures/signalling/server-screenshot-error.json create mode 100644 conformance/fixtures/signalling/server-screenshot.json create mode 100755 scripts/sync-conformance.sh create mode 100644 src/conformance/control.test.ts create mode 100644 src/conformance/fixtures.ts create mode 100644 src/conformance/input.test.ts create mode 100644 src/conformance/reconnect.test.ts create mode 100644 src/conformance/signalling.test.ts create mode 100644 src/hooks/use-task-approval.test.ts create mode 100644 src/hooks/webrtc-test-fixture.ts create mode 100644 src/lib/input-routing.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8d9d22d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + with: + bun-version: 1.4.4 + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Type check + run: bun run typecheck + + - name: Test (includes conformance fixtures) + run: bun test + + - name: Build + run: bun run build diff --git a/README.md b/README.md index c3d4578..2343284 100644 --- a/README.md +++ b/README.md @@ -328,8 +328,13 @@ Retheme by overriding the CSS variables on an ancestor (e.g. `--background`, `-- bun install bun run build # tsup (JS + d.ts) + Tailwind (styles.css) → dist/ bun run typecheck +bun test ``` +## 🧬 Conformance + +The control messages, signalling frames, reconnect policy and input routing are replayed against the shared [conformance fixtures](https://github.com/droidrun/mobilerun-sdk-conformance) that the native SDKs also pass. The vendored copy lives in `conformance/fixtures` (version in `conformance/VERSION`, currently v0.2.0) and runs with `bun test`. To move to another release, run `scripts/sync-conformance.sh TAG`. + ## 📄 License [Apache-2.0](./LICENSE) diff --git a/conformance/VERSION b/conformance/VERSION new file mode 100644 index 0000000..1474d00 --- /dev/null +++ b/conformance/VERSION @@ -0,0 +1 @@ +v0.2.0 diff --git a/conformance/fixtures/constants.json b/conformance/fixtures/constants.json new file mode 100644 index 0000000..aa51e89 --- /dev/null +++ b/conformance/fixtures/constants.json @@ -0,0 +1,335 @@ +{ + "control_msg_type": { + "INJECT_KEYCODE": 0, + "INJECT_TEXT": 1, + "INJECT_TOUCH_EVENT": 2, + "INJECT_SCROLL_EVENT": 3, + "BACK_OR_SCREEN_ON": 4, + "EXPAND_NOTIFICATION_PANEL": 5, + "EXPAND_SETTINGS_PANEL": 6, + "COLLAPSE_PANELS": 7, + "GET_CLIPBOARD": 8, + "SET_CLIPBOARD": 9, + "SET_DISPLAY_POWER": 10, + "ROTATE_DEVICE": 11, + "INJECT_MOUSE_HOVER_EVENT": 21 + }, + "amotion_event": { + "ACTION_DOWN": 0, + "ACTION_UP": 1, + "ACTION_MOVE": 2, + "ACTION_CANCEL": 3, + "ACTION_POINTER_DOWN": 5, + "ACTION_POINTER_UP": 6, + "BUTTON_PRIMARY": 1, + "BUTTON_SECONDARY": 2, + "BUTTON_TERTIARY": 4 + }, + "android_keys": { + "ACTION_DOWN": 0, + "ACTION_UP": 1, + "META_NONE": 0, + "META_SHIFT_ON": 1, + "META_ALT_ON": 2, + "META_CTRL_ON": 4096, + "META_META_ON": 65536, + "KEYCODE_UNKNOWN": 0, + "KEYCODE_SOFT_LEFT": 1, + "KEYCODE_SOFT_RIGHT": 2, + "KEYCODE_HOME": 3, + "KEYCODE_BACK": 4, + "KEYCODE_CALL": 5, + "KEYCODE_ENDCALL": 6, + "KEYCODE_0": 7, + "KEYCODE_1": 8, + "KEYCODE_2": 9, + "KEYCODE_3": 10, + "KEYCODE_4": 11, + "KEYCODE_5": 12, + "KEYCODE_6": 13, + "KEYCODE_7": 14, + "KEYCODE_8": 15, + "KEYCODE_9": 16, + "KEYCODE_STAR": 17, + "KEYCODE_POUND": 18, + "DPAD_UP": 19, + "DPAD_DOWN": 20, + "DPAD_LEFT": 21, + "DPAD_RIGHT": 22, + "KEYCODE_DPAD_CENTER": 23, + "KEYCODE_VOLUME_UP": 24, + "KEYCODE_VOLUME_DOWN": 25, + "KEYCODE_POWER": 26, + "KEYCODE_CAMERA": 27, + "KEYCODE_CLEAR": 28, + "KEYCODE_A": 29, + "KEYCODE_B": 30, + "KEYCODE_C": 31, + "KEYCODE_D": 32, + "KEYCODE_E": 33, + "KEYCODE_F": 34, + "KEYCODE_G": 35, + "KEYCODE_H": 36, + "KEYCODE_I": 37, + "KEYCODE_J": 38, + "KEYCODE_K": 39, + "KEYCODE_L": 40, + "KEYCODE_M": 41, + "KEYCODE_N": 42, + "KEYCODE_O": 43, + "KEYCODE_P": 44, + "KEYCODE_Q": 45, + "KEYCODE_R": 46, + "KEYCODE_S": 47, + "KEYCODE_T": 48, + "KEYCODE_U": 49, + "KEYCODE_V": 50, + "KEYCODE_W": 51, + "KEYCODE_X": 52, + "KEYCODE_Y": 53, + "KEYCODE_Z": 54, + "KEYCODE_COMMA": 55, + "KEYCODE_PERIOD": 56, + "KEYCODE_ALT_LEFT": 57, + "KEYCODE_ALT_RIGHT": 58, + "KEYCODE_SHIFT_LEFT": 59, + "KEYCODE_SHIFT_RIGHT": 60, + "KEYCODE_TAB": 61, + "KEYCODE_SPACE": 62, + "KEYCODE_SYM": 63, + "KEYCODE_EXPLORER": 64, + "KEYCODE_ENVELOPE": 65, + "ENTER": 66, + "DEL": 67, + "KEYCODE_GRAVE": 68, + "KEYCODE_MINUS": 69, + "KEYCODE_EQUALS": 70, + "KEYCODE_LEFT_BRACKET": 71, + "KEYCODE_RIGHT_BRACKET": 72, + "KEYCODE_BACKSLASH": 73, + "KEYCODE_SEMICOLON": 74, + "KEYCODE_APOSTROPHE": 75, + "KEYCODE_SLASH": 76, + "KEYCODE_AT": 77, + "KEYCODE_NUM": 78, + "KEYCODE_HEADSETHOOK": 79, + "KEYCODE_FOCUS": 80, + "KEYCODE_PLUS": 81, + "MENU": 82, + "KEYCODE_NOTIFICATION": 83, + "KEYCODE_SEARCH": 84, + "KEYCODE_MEDIA_PLAY_PAUSE": 85, + "KEYCODE_MEDIA_STOP": 86, + "KEYCODE_MEDIA_NEXT": 87, + "KEYCODE_MEDIA_PREVIOUS": 88, + "KEYCODE_MEDIA_REWIND": 89, + "KEYCODE_MEDIA_FAST_FORWARD": 90, + "KEYCODE_MUTE": 91, + "KEYCODE_PAGE_UP": 92, + "KEYCODE_PAGE_DOWN": 93, + "KEYCODE_PICTSYMBOLS": 94, + "KEYCODE_SWITCH_CHARSET": 95, + "KEYCODE_BUTTON_A": 96, + "KEYCODE_BUTTON_B": 97, + "KEYCODE_BUTTON_C": 98, + "KEYCODE_BUTTON_X": 99, + "KEYCODE_BUTTON_Y": 100, + "KEYCODE_BUTTON_Z": 101, + "KEYCODE_BUTTON_L1": 102, + "KEYCODE_BUTTON_R1": 103, + "KEYCODE_BUTTON_L2": 104, + "KEYCODE_BUTTON_R2": 105, + "KEYCODE_BUTTON_THUMBL": 106, + "KEYCODE_BUTTON_THUMBR": 107, + "KEYCODE_BUTTON_START": 108, + "KEYCODE_BUTTON_SELECT": 109, + "KEYCODE_BUTTON_MODE": 110, + "KEYCODE_ESCAPE": 111, + "FORWARD_DEL": 112, + "KEYCODE_CTRL_LEFT": 113, + "KEYCODE_CTRL_RIGHT": 114, + "KEYCODE_CAPS_LOCK": 115, + "KEYCODE_SCROLL_LOCK": 116, + "KEYCODE_META_LEFT": 117, + "KEYCODE_META_RIGHT": 118, + "KEYCODE_FUNCTION": 119, + "KEYCODE_SYSRQ": 120, + "KEYCODE_BREAK": 121, + "KEYCODE_MOVE_HOME": 122, + "KEYCODE_MOVE_END": 123, + "KEYCODE_INSERT": 124, + "KEYCODE_FORWARD": 125, + "KEYCODE_MEDIA_PLAY": 126, + "KEYCODE_MEDIA_PAUSE": 127, + "KEYCODE_MEDIA_CLOSE": 128, + "KEYCODE_MEDIA_EJECT": 129, + "KEYCODE_MEDIA_RECORD": 130, + "KEYCODE_F1": 131, + "KEYCODE_F2": 132, + "KEYCODE_F3": 133, + "KEYCODE_F4": 134, + "KEYCODE_F5": 135, + "KEYCODE_F6": 136, + "KEYCODE_F7": 137, + "KEYCODE_F8": 138, + "KEYCODE_F9": 139, + "KEYCODE_F10": 140, + "KEYCODE_F11": 141, + "KEYCODE_F12": 142, + "KEYCODE_NUM_LOCK": 143, + "KEYCODE_NUMPAD_0": 144, + "KEYCODE_NUMPAD_1": 145, + "KEYCODE_NUMPAD_2": 146, + "KEYCODE_NUMPAD_3": 147, + "KEYCODE_NUMPAD_4": 148, + "KEYCODE_NUMPAD_5": 149, + "KEYCODE_NUMPAD_6": 150, + "KEYCODE_NUMPAD_7": 151, + "KEYCODE_NUMPAD_8": 152, + "KEYCODE_NUMPAD_9": 153, + "KEYCODE_NUMPAD_DIVIDE": 154, + "KEYCODE_NUMPAD_MULTIPLY": 155, + "KEYCODE_NUMPAD_SUBTRACT": 156, + "KEYCODE_NUMPAD_ADD": 157, + "KEYCODE_NUMPAD_DOT": 158, + "KEYCODE_NUMPAD_COMMA": 159, + "KEYCODE_NUMPAD_ENTER": 160, + "KEYCODE_NUMPAD_EQUALS": 161, + "KEYCODE_NUMPAD_LEFT_PAREN": 162, + "KEYCODE_NUMPAD_RIGHT_PAREN": 163, + "KEYCODE_VOLUME_MUTE": 164, + "KEYCODE_INFO": 165, + "KEYCODE_CHANNEL_UP": 166, + "KEYCODE_CHANNEL_DOWN": 167, + "KEYCODE_ZOOM_IN": 168, + "KEYCODE_ZOOM_OUT": 169, + "KEYCODE_TV": 170, + "KEYCODE_WINDOW": 171, + "KEYCODE_GUIDE": 172, + "KEYCODE_DVR": 173, + "KEYCODE_BOOKMARK": 174, + "KEYCODE_CAPTIONS": 175, + "KEYCODE_SETTINGS": 176, + "KEYCODE_TV_POWER": 177, + "KEYCODE_TV_INPUT": 178, + "KEYCODE_STB_POWER": 179, + "KEYCODE_STB_INPUT": 180, + "KEYCODE_AVR_POWER": 181, + "KEYCODE_AVR_INPUT": 182, + "KEYCODE_PROG_RED": 183, + "KEYCODE_PROG_GREEN": 184, + "KEYCODE_PROG_YELLOW": 185, + "KEYCODE_PROG_BLUE": 186, + "KEYCODE_APP_SWITCH": 187, + "KEYCODE_LANGUAGE_SWITCH": 204, + "KEYCODE_ASSIST": 219, + "KEYCODE_BRIGHTNESS_DOWN": 220, + "KEYCODE_BRIGHTNESS_UP": 221, + "KEYCODE_SLEEP": 223, + "KEYCODE_WAKEUP": 224, + "KEYCODE_SOFT_SLEEP": 276 + }, + "code_map": { + "KeyA": 29, + "KeyB": 30, + "KeyC": 31, + "KeyD": 32, + "KeyE": 33, + "KeyF": 34, + "KeyG": 35, + "KeyH": 36, + "KeyI": 37, + "KeyJ": 38, + "KeyK": 39, + "KeyL": 40, + "KeyM": 41, + "KeyN": 42, + "KeyO": 43, + "KeyP": 44, + "KeyQ": 45, + "KeyR": 46, + "KeyS": 47, + "KeyT": 48, + "KeyU": 49, + "KeyV": 50, + "KeyW": 51, + "KeyX": 52, + "KeyY": 53, + "KeyZ": 54, + "Digit0": 7, + "Digit1": 8, + "Digit2": 9, + "Digit3": 10, + "Digit4": 11, + "Digit5": 12, + "Digit6": 13, + "Digit7": 14, + "Digit8": 15, + "Digit9": 16, + "Backquote": 68, + "Minus": 69, + "Equal": 70, + "BracketLeft": 71, + "BracketRight": 72, + "Backslash": 73, + "Semicolon": 74, + "Quote": 75, + "Comma": 55, + "Period": 56, + "Slash": 76, + "Space": 62, + "Tab": 61, + "Escape": 111, + "ArrowUp": 19, + "ArrowDown": 20, + "ArrowLeft": 21, + "ArrowRight": 22, + "Enter": 66, + "Backspace": 67, + "Delete": 112, + "Home": 122, + "End": 123, + "PageUp": 92, + "PageDown": 93, + "Insert": 124, + "F1": 131, + "F2": 132, + "F3": 133, + "F4": 134, + "F5": 135, + "F6": 136, + "F7": 137, + "F8": 138, + "F9": 139, + "F10": 140, + "F11": 141, + "F12": 142, + "ShiftLeft": 59, + "ShiftRight": 60, + "ControlLeft": 113, + "ControlRight": 114, + "AltLeft": 57, + "AltRight": 58, + "MetaLeft": 117, + "MetaRight": 118, + "ContextMenu": 82, + "Numpad0": 144, + "Numpad1": 145, + "Numpad2": 146, + "Numpad3": 147, + "Numpad4": 148, + "Numpad5": 149, + "Numpad6": 150, + "Numpad7": 151, + "Numpad8": 152, + "Numpad9": 153, + "NumpadDivide": 154, + "NumpadMultiply": 155, + "NumpadSubtract": 156, + "NumpadAdd": 157, + "NumpadDecimal": 158, + "NumpadComma": 159, + "NumpadEnter": 160, + "NumpadEqual": 161 + } +} diff --git a/conformance/fixtures/control/hover.json b/conformance/fixtures/control/hover.json new file mode 100644 index 0000000..49ce51e --- /dev/null +++ b/conformance/fixtures/control/hover.json @@ -0,0 +1,70 @@ +{ + "cases": [ + { + "name": "center", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "buttons": 0 + }, + "hex": "151c020000b00400003804600900000000" + }, + { + "name": "origin", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 0, + "y": 0, + "buttons": 0 + }, + "hex": "1500000000000000003804600900000000" + }, + { + "name": "max corner", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 1080, + "y": 2400, + "buttons": 0 + }, + "hex": "1538040000600900003804600900000000" + }, + { + "name": "fractional rounds", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 12.5, + "y": 99.49, + "buttons": 0 + }, + "hex": "150d000000630000003804600900000000" + }, + { + "name": "with primary button", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 100, + "y": 100, + "buttons": 1 + }, + "hex": "1564000000640000003804600901000000" + }, + { + "name": "landscape", + "args": { + "videoWidth": 2400, + "videoHeight": 1080, + "x": 1200, + "y": 400, + "buttons": 0 + }, + "hex": "15b0040000900100006009380400000000" + } + ] +} diff --git a/conformance/fixtures/control/keycode.json b/conformance/fixtures/control/keycode.json new file mode 100644 index 0000000..5e3cebb --- /dev/null +++ b/conformance/fixtures/control/keycode.json @@ -0,0 +1,204 @@ +{ + "cases": [ + { + "name": "home down", + "args": { + "action": 0, + "keycode": 3, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000030000000000000000000000" + }, + { + "name": "home up", + "args": { + "action": 1, + "keycode": 3, + "repeat": 0, + "metaState": 0 + }, + "hex": "0001030000000000000000000000" + }, + { + "name": "back down", + "args": { + "action": 0, + "keycode": 4, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000040000000000000000000000" + }, + { + "name": "app switch down", + "args": { + "action": 0, + "keycode": 187, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000bb0000000000000000000000" + }, + { + "name": "menu down", + "args": { + "action": 0, + "keycode": 82, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000520000000000000000000000" + }, + { + "name": "enter down", + "args": { + "action": 0, + "keycode": 66, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000420000000000000000000000" + }, + { + "name": "backspace down", + "args": { + "action": 0, + "keycode": 67, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000430000000000000000000000" + }, + { + "name": "letter a down, no meta", + "args": { + "action": 0, + "keycode": 29, + "repeat": 0, + "metaState": 0 + }, + "hex": "00001d0000000000000000000000" + }, + { + "name": "letter a down, shift", + "args": { + "action": 0, + "keycode": 29, + "repeat": 0, + "metaState": 1 + }, + "hex": "00001d0000000000000001000000" + }, + { + "name": "letter c down, ctrl", + "args": { + "action": 0, + "keycode": 31, + "repeat": 0, + "metaState": 4096 + }, + "hex": "00001f0000000000000000100000" + }, + { + "name": "letter c up, ctrl", + "args": { + "action": 1, + "keycode": 31, + "repeat": 0, + "metaState": 4096 + }, + "hex": "00011f0000000000000000100000" + }, + { + "name": "letter z down, alt", + "args": { + "action": 0, + "keycode": 54, + "repeat": 0, + "metaState": 2 + }, + "hex": "0000360000000000000002000000" + }, + { + "name": "letter v down, meta (command)", + "args": { + "action": 0, + "keycode": 50, + "repeat": 0, + "metaState": 65536 + }, + "hex": "0000320000000000000000000100" + }, + { + "name": "all modifiers", + "args": { + "action": 0, + "keycode": 29, + "repeat": 0, + "metaState": 69635 + }, + "hex": "00001d0000000000000003100100" + }, + { + "name": "shift+ctrl", + "args": { + "action": 0, + "keycode": 61, + "repeat": 0, + "metaState": 4097 + }, + "hex": "00003d0000000000000001100000" + }, + { + "name": "repeat 5", + "args": { + "action": 0, + "keycode": 67, + "repeat": 5, + "metaState": 0 + }, + "hex": "0000430000000500000000000000" + }, + { + "name": "arrow up", + "args": { + "action": 0, + "keycode": 19, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000130000000000000000000000" + }, + { + "name": "f12", + "args": { + "action": 0, + "keycode": 142, + "repeat": 0, + "metaState": 0 + }, + "hex": "00008e0000000000000000000000" + }, + { + "name": "highest keycode (soft sleep 276)", + "args": { + "action": 0, + "keycode": 276, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000140100000000000000000000" + }, + { + "name": "unknown keycode 0", + "args": { + "action": 0, + "keycode": 0, + "repeat": 0, + "metaState": 0 + }, + "hex": "0000000000000000000000000000" + } + ] +} diff --git a/conformance/fixtures/control/scroll.json b/conformance/fixtures/control/scroll.json new file mode 100644 index 0000000..0e0dc70 --- /dev/null +++ b/conformance/fixtures/control/scroll.json @@ -0,0 +1,238 @@ +{ + "cases": [ + { + "name": "zero", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 0, + "vscrollTicks": 0, + "buttons": 0 + }, + "hex": "031c020000b0040000380460090000000000000000" + }, + { + "name": "one tick up (vscroll +1)", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 0, + "vscrollTicks": 1, + "buttons": 0 + }, + "hex": "031c020000b0040000380460090000000800000000" + }, + { + "name": "one tick down (vscroll -1)", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 0, + "vscrollTicks": -1, + "buttons": 0 + }, + "hex": "031c020000b004000038046009000000f800000000" + }, + { + "name": "one tick left (hscroll +1)", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 1, + "vscrollTicks": 0, + "buttons": 0 + }, + "hex": "031c020000b0040000380460090008000000000000" + }, + { + "name": "one tick right (hscroll -1)", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": -1, + "vscrollTicks": 0, + "buttons": 0 + }, + "hex": "031c020000b00400003804600900f8000000000000" + }, + { + "name": "both axes", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 2, + "vscrollTicks": -3, + "buttons": 0 + }, + "hex": "031c020000b004000038046009001000e800000000" + }, + { + "name": "fractional trackpad ticks", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 0.3, + "vscrollTicks": -0.07, + "buttons": 0 + }, + "hex": "031c020000b004000038046009660271ff00000000" + }, + { + "name": "half tick", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 0.5, + "vscrollTicks": -0.5, + "buttons": 0 + }, + "hex": "031c020000b004000038046009000400fc00000000" + }, + { + "name": "eight ticks", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 8, + "vscrollTicks": -8, + "buttons": 0 + }, + "hex": "031c020000b004000038046009004000c000000000" + }, + { + "name": "15 ticks", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 0, + "vscrollTicks": 15, + "buttons": 0 + }, + "hex": "031c020000b0040000380460090000007800000000" + }, + { + "name": "exactly 16 ticks clamps positive (0x7fff)", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 16, + "vscrollTicks": 16, + "buttons": 0 + }, + "hex": "031c020000b004000038046009ff7fff7f00000000" + }, + { + "name": "exactly -16 ticks (-0x8000)", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": -16, + "vscrollTicks": -16, + "buttons": 0 + }, + "hex": "031c020000b0040000380460090080008000000000" + }, + { + "name": "positive extreme clamped", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 1000, + "vscrollTicks": 1000, + "buttons": 0 + }, + "hex": "031c020000b004000038046009ff7fff7f00000000" + }, + { + "name": "negative extreme clamped", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": -1000, + "vscrollTicks": -1000, + "buttons": 0 + }, + "hex": "031c020000b0040000380460090080008000000000" + }, + { + "name": "mixed extremes", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 1000, + "vscrollTicks": -1000, + "buttons": 0 + }, + "hex": "031c020000b004000038046009ff7f008000000000" + }, + { + "name": "with primary button held", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "hscrollTicks": 0, + "vscrollTicks": 1, + "buttons": 1 + }, + "hex": "031c020000b0040000380460090000000801000000" + }, + { + "name": "at origin", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 0, + "y": 0, + "hscrollTicks": 0, + "vscrollTicks": 1, + "buttons": 0 + }, + "hex": "030000000000000000380460090000000800000000" + }, + { + "name": "fractional position rounds", + "args": { + "videoWidth": 1080, + "videoHeight": 2400, + "x": 10.5, + "y": 20.5, + "hscrollTicks": 0, + "vscrollTicks": 1, + "buttons": 0 + }, + "hex": "030b00000015000000380460090000000800000000" + } + ] +} diff --git a/conformance/fixtures/control/set-clipboard.json b/conformance/fixtures/control/set-clipboard.json new file mode 100644 index 0000000..59c5669 --- /dev/null +++ b/conformance/fixtures/control/set-clipboard.json @@ -0,0 +1,356 @@ +{ + "cases": [ + { + "name": "empty, paste true", + "args": { + "text": "", + "paste": true + }, + "hex": "0900000000000000000100000000" + }, + { + "name": "empty, paste false", + "args": { + "text": "", + "paste": false + }, + "hex": "0900000000000000000000000000" + }, + { + "name": "single ascii char, paste true", + "args": { + "text": "a", + "paste": true + }, + "hex": "090000000000000000010000000161" + }, + { + "name": "single ascii char, paste false", + "args": { + "text": "a", + "paste": false + }, + "hex": "090000000000000000000000000161" + }, + { + "name": "ascii sentence, paste true", + "args": { + "text": "Hello, World!", + "paste": true + }, + "hex": "090000000000000000010000000d48656c6c6f2c20576f726c6421" + }, + { + "name": "ascii sentence, paste false", + "args": { + "text": "Hello, World!", + "paste": false + }, + "hex": "090000000000000000000000000d48656c6c6f2c20576f726c6421" + }, + { + "name": "ascii punctuation and symbols, paste true", + "args": { + "text": "!@#$%^&*()_+-=[]{}|;':\",./<>?`~\\", + "paste": true + }, + "hex": "090000000000000000010000002021402324255e262a28295f2b2d3d5b5d7b7d7c3b273a222c2e2f3c3e3f607e5c" + }, + { + "name": "ascii punctuation and symbols, paste false", + "args": { + "text": "!@#$%^&*()_+-=[]{}|;':\",./<>?`~\\", + "paste": false + }, + "hex": "090000000000000000000000002021402324255e262a28295f2b2d3d5b5d7b7d7c3b273a222c2e2f3c3e3f607e5c" + }, + { + "name": "digits, paste true", + "args": { + "text": "0123456789", + "paste": true + }, + "hex": "090000000000000000010000000a30313233343536373839" + }, + { + "name": "digits, paste false", + "args": { + "text": "0123456789", + "paste": false + }, + "hex": "090000000000000000000000000a30313233343536373839" + }, + { + "name": "space only, paste true", + "args": { + "text": " ", + "paste": true + }, + "hex": "090000000000000000010000000120" + }, + { + "name": "space only, paste false", + "args": { + "text": " ", + "paste": false + }, + "hex": "090000000000000000000000000120" + }, + { + "name": "newline and tab, paste true", + "args": { + "text": "line1\nline2\tend", + "paste": true + }, + "hex": "090000000000000000010000000f6c696e65310a6c696e653209656e64" + }, + { + "name": "newline and tab, paste false", + "args": { + "text": "line1\nline2\tend", + "paste": false + }, + "hex": "090000000000000000000000000f6c696e65310a6c696e653209656e64" + }, + { + "name": "latin-1 two-byte, paste true", + "args": { + "text": "héllo wörld ñ", + "paste": true + }, + "hex": "090000000000000000010000001068c3a96c6c6f2077c3b6726c6420c3b1" + }, + { + "name": "latin-1 two-byte, paste false", + "args": { + "text": "héllo wörld ñ", + "paste": false + }, + "hex": "090000000000000000000000001068c3a96c6c6f2077c3b6726c6420c3b1" + }, + { + "name": "cyrillic, paste true", + "args": { + "text": "Привет", + "paste": true + }, + "hex": "090000000000000000010000000cd09fd180d0b8d0b2d0b5d182" + }, + { + "name": "cyrillic, paste false", + "args": { + "text": "Привет", + "paste": false + }, + "hex": "090000000000000000000000000cd09fd180d0b8d0b2d0b5d182" + }, + { + "name": "cjk three-byte, paste true", + "args": { + "text": "日本語のテキスト", + "paste": true + }, + "hex": "0900000000000000000100000018e697a5e69cace8aa9ee381aee38386e382ade382b9e38388" + }, + { + "name": "cjk three-byte, paste false", + "args": { + "text": "日本語のテキスト", + "paste": false + }, + "hex": "0900000000000000000000000018e697a5e69cace8aa9ee381aee38386e382ade382b9e38388" + }, + { + "name": "emoji four-byte, paste true", + "args": { + "text": "😀", + "paste": true + }, + "hex": "0900000000000000000100000004f09f9880" + }, + { + "name": "emoji four-byte, paste false", + "args": { + "text": "😀", + "paste": false + }, + "hex": "0900000000000000000000000004f09f9880" + }, + { + "name": "emoji between ascii, paste true", + "args": { + "text": "a😀b", + "paste": true + }, + "hex": "090000000000000000010000000661f09f988062" + }, + { + "name": "emoji between ascii, paste false", + "args": { + "text": "a😀b", + "paste": false + }, + "hex": "090000000000000000000000000661f09f988062" + }, + { + "name": "emoji zwj sequence, paste true", + "args": { + "text": "👨‍👩‍👧‍👦", + "paste": true + }, + "hex": "0900000000000000000100000019f09f91a8e2808df09f91a9e2808df09f91a7e2808df09f91a6" + }, + { + "name": "emoji zwj sequence, paste false", + "args": { + "text": "👨‍👩‍👧‍👦", + "paste": false + }, + "hex": "0900000000000000000000000019f09f91a8e2808df09f91a9e2808df09f91a7e2808df09f91a6" + }, + { + "name": "emoji with skin tone, paste true", + "args": { + "text": "👍🏽", + "paste": true + }, + "hex": "0900000000000000000100000008f09f918df09f8fbd" + }, + { + "name": "emoji with skin tone, paste false", + "args": { + "text": "👍🏽", + "paste": false + }, + "hex": "0900000000000000000000000008f09f918df09f8fbd" + }, + { + "name": "flag regional indicators, paste true", + "args": { + "text": "🇩🇪", + "paste": true + }, + "hex": "0900000000000000000100000008f09f87a9f09f87aa" + }, + { + "name": "flag regional indicators, paste false", + "args": { + "text": "🇩🇪", + "paste": false + }, + "hex": "0900000000000000000000000008f09f87a9f09f87aa" + }, + { + "name": "combining accent, paste true", + "args": { + "text": "é", + "paste": true + }, + "hex": "090000000000000000010000000365cc81" + }, + { + "name": "combining accent, paste false", + "args": { + "text": "é", + "paste": false + }, + "hex": "090000000000000000000000000365cc81" + }, + { + "name": "nul character, paste true", + "args": { + "text": "a\u0000b", + "paste": true + }, + "hex": "0900000000000000000100000003610062" + }, + { + "name": "nul character, paste false", + "args": { + "text": "a\u0000b", + "paste": false + }, + "hex": "0900000000000000000000000003610062" + }, + { + "name": "long ascii (300 chars), paste true", + "args": { + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "paste": true + }, + "hex": "090000000000000000010000012c787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878" + }, + { + "name": "long ascii (300 chars), paste false", + "args": { + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "paste": false + }, + "hex": "090000000000000000000000012c787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878" + }, + { + "name": "lone high surrogate, paste true", + "args": { + "text": "\ud83d", + "paste": true + }, + "hex": "0900000000000000000100000003efbfbd" + }, + { + "name": "lone high surrogate, paste false", + "args": { + "text": "\ud83d", + "paste": false + }, + "hex": "0900000000000000000000000003efbfbd" + }, + { + "name": "lone low surrogate inside text, paste true", + "args": { + "text": "a\udc00b", + "paste": true + }, + "hex": "090000000000000000010000000561efbfbd62" + }, + { + "name": "lone low surrogate inside text, paste false", + "args": { + "text": "a\udc00b", + "paste": false + }, + "hex": "090000000000000000000000000561efbfbd62" + }, + { + "name": "high surrogate at end after ascii, paste true", + "args": { + "text": "ok\ud83d", + "paste": true + }, + "hex": "09000000000000000001000000056f6befbfbd" + }, + { + "name": "high surrogate at end after ascii, paste false", + "args": { + "text": "ok\ud83d", + "paste": false + }, + "hex": "09000000000000000000000000056f6befbfbd" + }, + { + "name": "reversed surrogate pair, paste true", + "args": { + "text": "\ude00\ud83d", + "paste": true + }, + "hex": "0900000000000000000100000006efbfbdefbfbd" + }, + { + "name": "reversed surrogate pair, paste false", + "args": { + "text": "\ude00\ud83d", + "paste": false + }, + "hex": "0900000000000000000000000006efbfbdefbfbd" + } + ] +} diff --git a/conformance/fixtures/control/text.json b/conformance/fixtures/control/text.json new file mode 100644 index 0000000..2622361 --- /dev/null +++ b/conformance/fixtures/control/text.json @@ -0,0 +1,158 @@ +{ + "cases": [ + { + "name": "empty", + "args": { + "text": "" + }, + "hex": "0100000000" + }, + { + "name": "single ascii char", + "args": { + "text": "a" + }, + "hex": "010100000061" + }, + { + "name": "ascii sentence", + "args": { + "text": "Hello, World!" + }, + "hex": "010d00000048656c6c6f2c20576f726c6421" + }, + { + "name": "ascii punctuation and symbols", + "args": { + "text": "!@#$%^&*()_+-=[]{}|;':\",./<>?`~\\" + }, + "hex": "012000000021402324255e262a28295f2b2d3d5b5d7b7d7c3b273a222c2e2f3c3e3f607e5c" + }, + { + "name": "digits", + "args": { + "text": "0123456789" + }, + "hex": "010a00000030313233343536373839" + }, + { + "name": "space only", + "args": { + "text": " " + }, + "hex": "010100000020" + }, + { + "name": "newline and tab", + "args": { + "text": "line1\nline2\tend" + }, + "hex": "010f0000006c696e65310a6c696e653209656e64" + }, + { + "name": "latin-1 two-byte", + "args": { + "text": "héllo wörld ñ" + }, + "hex": "011000000068c3a96c6c6f2077c3b6726c6420c3b1" + }, + { + "name": "cyrillic", + "args": { + "text": "Привет" + }, + "hex": "010c000000d09fd180d0b8d0b2d0b5d182" + }, + { + "name": "cjk three-byte", + "args": { + "text": "日本語のテキスト" + }, + "hex": "0118000000e697a5e69cace8aa9ee381aee38386e382ade382b9e38388" + }, + { + "name": "emoji four-byte", + "args": { + "text": "😀" + }, + "hex": "0104000000f09f9880" + }, + { + "name": "emoji between ascii", + "args": { + "text": "a😀b" + }, + "hex": "010600000061f09f988062" + }, + { + "name": "emoji zwj sequence", + "args": { + "text": "👨‍👩‍👧‍👦" + }, + "hex": "0119000000f09f91a8e2808df09f91a9e2808df09f91a7e2808df09f91a6" + }, + { + "name": "emoji with skin tone", + "args": { + "text": "👍🏽" + }, + "hex": "0108000000f09f918df09f8fbd" + }, + { + "name": "flag regional indicators", + "args": { + "text": "🇩🇪" + }, + "hex": "0108000000f09f87a9f09f87aa" + }, + { + "name": "combining accent", + "args": { + "text": "é" + }, + "hex": "010300000065cc81" + }, + { + "name": "nul character", + "args": { + "text": "a\u0000b" + }, + "hex": "0103000000610062" + }, + { + "name": "long ascii (300 chars)", + "args": { + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + }, + "hex": "012c010000787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878" + }, + { + "name": "lone high surrogate", + "args": { + "text": "\ud83d" + }, + "hex": "0103000000efbfbd" + }, + { + "name": "lone low surrogate inside text", + "args": { + "text": "a\udc00b" + }, + "hex": "010500000061efbfbd62" + }, + { + "name": "high surrogate at end after ascii", + "args": { + "text": "ok\ud83d" + }, + "hex": "01050000006f6befbfbd" + }, + { + "name": "reversed surrogate pair", + "args": { + "text": "\ude00\ud83d" + }, + "hex": "0106000000efbfbdefbfbd" + } + ] +} diff --git a/conformance/fixtures/control/touch.json b/conformance/fixtures/control/touch.json new file mode 100644 index 0000000..c385017 --- /dev/null +++ b/conformance/fixtures/control/touch.json @@ -0,0 +1,439 @@ +{ + "cases": [ + { + "name": "mouse down", + "args": { + "action": 0, + "pointerId": -1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 540, + "y": 1200, + "pressure": 1, + "actionButton": 1, + "buttons": 1 + }, + "hex": "0200ffffffffffffffff1c020000b004000038046009ffff0100000001000000" + }, + { + "name": "mouse move", + "args": { + "action": 2, + "pointerId": -1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 541.25, + "y": 1210.75, + "pressure": 1, + "actionButton": 1, + "buttons": 1 + }, + "hex": "0202ffffffffffffffff1d020000bb04000038046009ffff0100000001000000" + }, + { + "name": "mouse up", + "args": { + "action": 1, + "pointerId": -1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 541, + "y": 1211, + "pressure": 1, + "actionButton": 1, + "buttons": 1 + }, + "hex": "0201ffffffffffffffff1d020000bb04000038046009ffff0100000001000000" + }, + { + "name": "mouse cancel", + "args": { + "action": 3, + "pointerId": -1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 541, + "y": 1211, + "pressure": 1, + "actionButton": 1, + "buttons": 1 + }, + "hex": "0203ffffffffffffffff1d020000bb04000038046009ffff0100000001000000" + }, + { + "name": "mouse defaults only (no buttons)", + "args": { + "action": 0, + "pointerId": -1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 10, + "y": 20, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "0200ffffffffffffffff0a0000001400000038046009ffff0000000000000000" + }, + { + "name": "touch id 0 down", + "args": { + "action": 0, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 100, + "y": 200, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "0200000000000000000064000000c800000038046009ffff0000000000000000" + }, + { + "name": "touch id 0 move", + "args": { + "action": 2, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 110, + "y": 220, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "020200000000000000006e000000dc00000038046009ffff0000000000000000" + }, + { + "name": "touch id 0 up", + "args": { + "action": 1, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 110, + "y": 220, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "020100000000000000006e000000dc00000038046009ffff0000000000000000" + }, + { + "name": "touch id 1 down", + "args": { + "action": 0, + "pointerId": 1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 300, + "y": 400, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "020000000000000000012c0100009001000038046009ffff0000000000000000" + }, + { + "name": "touch id 1 move", + "args": { + "action": 2, + "pointerId": 1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 310, + "y": 410, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02020000000000000001360100009a01000038046009ffff0000000000000000" + }, + { + "name": "touch id 1 up", + "args": { + "action": 1, + "pointerId": 1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 310, + "y": 410, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02010000000000000001360100009a01000038046009ffff0000000000000000" + }, + { + "name": "touch id 1 cancel", + "args": { + "action": 3, + "pointerId": 1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 310, + "y": 410, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02030000000000000001360100009a01000038046009ffff0000000000000000" + }, + { + "name": "touch id 9 down", + "args": { + "action": 0, + "pointerId": 9, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 800, + "y": 900, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02000000000000000009200300008403000038046009ffff0000000000000000" + }, + { + "name": "touch id 9 up", + "args": { + "action": 1, + "pointerId": 9, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 800, + "y": 900, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02010000000000000009200300008403000038046009ffff0000000000000000" + }, + { + "name": "touch id 1 pointer down", + "args": { + "action": 5, + "pointerId": 1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 300, + "y": 400, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "020500000000000000012c0100009001000038046009ffff0000000000000000" + }, + { + "name": "touch id 1 pointer up", + "args": { + "action": 6, + "pointerId": 1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 300, + "y": 400, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "020600000000000000012c0100009001000038046009ffff0000000000000000" + }, + { + "name": "x,y round half up (2.5, 3.5)", + "args": { + "action": 2, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 2.5, + "y": 3.5, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02020000000000000000030000000400000038046009ffff0000000000000000" + }, + { + "name": "x,y round negative half (-0.5, -1.5)", + "args": { + "action": 2, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": -0.5, + "y": -1.5, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "0202000000000000000000000000ffffffff38046009ffff0000000000000000" + }, + { + "name": "x,y round down (10.4, 10.49)", + "args": { + "action": 2, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 10.4, + "y": 10.49, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "020200000000000000000a0000000a00000038046009ffff0000000000000000" + }, + { + "name": "origin", + "args": { + "action": 0, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 0, + "y": 0, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02000000000000000000000000000000000038046009ffff0000000000000000" + }, + { + "name": "max coordinates", + "args": { + "action": 0, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 1080, + "y": 2400, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02000000000000000000380400006009000038046009ffff0000000000000000" + }, + { + "name": "negative coordinates", + "args": { + "action": 2, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": -5, + "y": -10, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02020000000000000000fbfffffff6ffffff38046009ffff0000000000000000" + }, + { + "name": "large video size", + "args": { + "action": 0, + "pointerId": 0, + "videoWidth": 4096, + "videoHeight": 3072, + "x": 4000, + "y": 3000, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02000000000000000000a00f0000b80b00000010000cffff0000000000000000" + }, + { + "name": "landscape video size", + "args": { + "action": 0, + "pointerId": 0, + "videoWidth": 2400, + "videoHeight": 1080, + "x": 1000, + "y": 500, + "pressure": 1, + "actionButton": 0, + "buttons": 0 + }, + "hex": "02000000000000000000e8030000f401000060093804ffff0000000000000000" + }, + { + "name": "pressure 0.5", + "args": { + "action": 2, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 50, + "y": 50, + "pressure": 0.5, + "actionButton": 0, + "buttons": 0 + }, + "hex": "0202000000000000000032000000320000003804600900800000000000000000" + }, + { + "name": "pressure 0", + "args": { + "action": 2, + "pointerId": 0, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 50, + "y": 50, + "pressure": 0, + "actionButton": 0, + "buttons": 0 + }, + "hex": "0202000000000000000032000000320000003804600900000000000000000000" + }, + { + "name": "secondary button", + "args": { + "action": 0, + "pointerId": -1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 50, + "y": 50, + "pressure": 1, + "actionButton": 2, + "buttons": 2 + }, + "hex": "0200ffffffffffffffff320000003200000038046009ffff0200000002000000" + }, + { + "name": "tertiary button", + "args": { + "action": 0, + "pointerId": -1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 50, + "y": 50, + "pressure": 1, + "actionButton": 4, + "buttons": 4 + }, + "hex": "0200ffffffffffffffff320000003200000038046009ffff0400000004000000" + }, + { + "name": "combined buttons", + "args": { + "action": 2, + "pointerId": -1, + "videoWidth": 1080, + "videoHeight": 2400, + "x": 50, + "y": 50, + "pressure": 1, + "actionButton": 0, + "buttons": 3 + }, + "hex": "0202ffffffffffffffff320000003200000038046009ffff0000000003000000" + } + ] +} diff --git a/conformance/fixtures/input/geometry.json b/conformance/fixtures/input/geometry.json new file mode 100644 index 0000000..7234315 --- /dev/null +++ b/conformance/fixtures/input/geometry.json @@ -0,0 +1,359 @@ +{ + "cases": [ + { + "name": "matching aspect center", + "view_width": 540, + "view_height": 1200, + "video_width": 1080, + "video_height": 2400, + "rotation": 0, + "x": 270, + "y": 600, + "expect": { + "width": 1080, + "height": 2400, + "x": 540, + "y": 1200 + } + }, + { + "name": "pillarbox center", + "view_width": 1000, + "view_height": 1000, + "video_width": 100, + "video_height": 200, + "rotation": 0, + "x": 500, + "y": 500, + "expect": { + "width": 100, + "height": 200, + "x": 50, + "y": 100 + } + }, + { + "name": "pillarbox x 249", + "view_width": 1000, + "view_height": 1000, + "video_width": 100, + "video_height": 200, + "rotation": 0, + "x": 249, + "y": 500, + "expect": null + }, + { + "name": "pillarbox x 250", + "view_width": 1000, + "view_height": 1000, + "video_width": 100, + "video_height": 200, + "rotation": 0, + "x": 250, + "y": 500, + "expect": { + "width": 100, + "height": 200, + "x": 0, + "y": 100 + } + }, + { + "name": "pillarbox x 750", + "view_width": 1000, + "view_height": 1000, + "video_width": 100, + "video_height": 200, + "rotation": 0, + "x": 750, + "y": 500, + "expect": { + "width": 100, + "height": 200, + "x": 100, + "y": 100 + } + }, + { + "name": "pillarbox x 751", + "view_width": 1000, + "view_height": 1000, + "video_width": 100, + "video_height": 200, + "rotation": 0, + "x": 751, + "y": 500, + "expect": null + }, + { + "name": "letterbox center", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 500, + "y": 500, + "expect": { + "width": 200, + "height": 100, + "x": 100, + "y": 50 + } + }, + { + "name": "letterbox y 249", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 500, + "y": 249, + "expect": null + }, + { + "name": "letterbox y 250", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 500, + "y": 250, + "expect": { + "width": 200, + "height": 100, + "x": 100, + "y": 0 + } + }, + { + "name": "letterbox y 750", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 500, + "y": 750, + "expect": { + "width": 200, + "height": 100, + "x": 100, + "y": 100 + } + }, + { + "name": "letterbox y 751", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 500, + "y": 751, + "expect": null + }, + { + "name": "fractional point", + "view_width": 200, + "view_height": 100, + "video_width": 400, + "video_height": 200, + "rotation": 0, + "x": 10.25, + "y": 20.75, + "expect": { + "width": 400, + "height": 200, + "x": 20.5, + "y": 41.5 + } + }, + { + "name": "rotation 0 center", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 500, + "y": 500, + "expect": { + "width": 200, + "height": 100, + "x": 100, + "y": 50 + } + }, + { + "name": "rotation 0 offset", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 500, + "y": 300, + "expect": { + "width": 200, + "height": 100, + "x": 100, + "y": 10 + } + }, + { + "name": "rotation 90 center", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 90, + "x": 500, + "y": 500, + "expect": { + "width": 100, + "height": 200, + "x": 50, + "y": 100 + } + }, + { + "name": "rotation 90 offset", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 90, + "x": 500, + "y": 300, + "expect": { + "width": 100, + "height": 200, + "x": 50, + "y": 60 + } + }, + { + "name": "rotation 180 center", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 180, + "x": 500, + "y": 500, + "expect": { + "width": 200, + "height": 100, + "x": 100, + "y": 50 + } + }, + { + "name": "rotation 180 offset", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 180, + "x": 500, + "y": 300, + "expect": { + "width": 200, + "height": 100, + "x": 100, + "y": 10 + } + }, + { + "name": "rotation 270 center", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 270, + "x": 500, + "y": 500, + "expect": { + "width": 100, + "height": 200, + "x": 50, + "y": 100 + } + }, + { + "name": "rotation 270 offset", + "view_width": 1000, + "view_height": 1000, + "video_width": 200, + "video_height": 100, + "rotation": 270, + "x": 500, + "y": 300, + "expect": { + "width": 100, + "height": 200, + "x": 50, + "y": 60 + } + }, + { + "name": "zero view width", + "view_width": 0, + "view_height": 100, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 0, + "y": 0, + "expect": null + }, + { + "name": "zero view height", + "view_width": 100, + "view_height": 0, + "video_width": 200, + "video_height": 100, + "rotation": 0, + "x": 0, + "y": 0, + "expect": null + }, + { + "name": "zero video width", + "view_width": 100, + "view_height": 100, + "video_width": 0, + "video_height": 100, + "rotation": 0, + "x": 0, + "y": 0, + "expect": null + }, + { + "name": "zero video height rotated", + "view_width": 100, + "view_height": 100, + "video_width": 200, + "video_height": 0, + "rotation": 90, + "x": 0, + "y": 0, + "expect": null + }, + { + "name": "negative point", + "view_width": 100, + "view_height": 100, + "video_width": 100, + "video_height": 100, + "rotation": 0, + "x": -1, + "y": -1, + "expect": null + } + ] +} diff --git a/conformance/fixtures/input/ime.json b/conformance/fixtures/input/ime.json new file mode 100644 index 0000000..762119e --- /dev/null +++ b/conformance/fixtures/input/ime.json @@ -0,0 +1,378 @@ +{ + "cases": [ + { + "name": "empty", + "operation": "commit", + "text": "", + "expect": [] + }, + { + "name": "ascii", + "operation": "commit", + "text": "hello", + "expect": [ + { + "channel": "control", + "hex": "010500000068656c6c6f" + } + ] + }, + { + "name": "unicode", + "operation": "commit", + "text": "é中😀é", + "expect": [ + { + "channel": "control", + "hex": "010c000000c3a9e4b8adf09f988065cc81" + } + ] + }, + { + "name": "lf", + "operation": "commit", + "text": "\n", + "expect": [ + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + } + ] + }, + { + "name": "cr", + "operation": "commit", + "text": "\r", + "expect": [ + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + } + ] + }, + { + "name": "crlf", + "operation": "commit", + "text": "\r\n", + "expect": [ + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + } + ] + }, + { + "name": "tab", + "operation": "commit", + "text": "\t", + "expect": [ + { + "channel": "control", + "hex": "00003d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00013d0000000000000000000000" + } + ] + }, + { + "name": "mixed", + "operation": "commit", + "text": "a\r\nb\rc\nd\te", + "expect": [ + { + "channel": "control", + "hex": "010100000061" + }, + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "010100000062" + }, + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "010100000063" + }, + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "010100000064" + }, + { + "channel": "control", + "hex": "00003d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00013d0000000000000000000000" + }, + { + "channel": "control", + "hex": "010100000065" + } + ] + }, + { + "name": "consecutive breaks", + "operation": "commit", + "text": "\r\n\r\n\n\r\t\t", + "expect": [ + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "00003d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00013d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00003d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00013d0000000000000000000000" + } + ] + }, + { + "name": "c0 controls dropped", + "operation": "commit", + "text": "a\u0000\u0001\b\u001bb", + "expect": [ + { + "channel": "control", + "hex": "01020000006162" + } + ] + }, + { + "name": "del and c1 dropped", + "operation": "commit", + "text": "a…Ÿb", + "expect": [ + { + "channel": "control", + "hex": "01020000006162" + } + ] + }, + { + "name": "only dropped controls", + "operation": "commit", + "text": "\u0000\u001fŸ", + "expect": [] + }, + { + "name": "controls between separators", + "operation": "commit", + "text": "a\u0000\tb\nc", + "expect": [ + { + "channel": "control", + "hex": "010100000061" + }, + { + "channel": "control", + "hex": "00003d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00013d0000000000000000000000" + }, + { + "channel": "control", + "hex": "010100000062" + }, + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "010100000063" + } + ] + }, + { + "name": "unicode line separators printable", + "operation": "commit", + "text": "a
b
c", + "expect": [ + { + "channel": "control", + "hex": "010900000061e280a862e280a963" + } + ] + }, + { + "name": "lone surrogate replacement", + "operation": "commit", + "text": "a\ud83d\tb", + "expect": [ + { + "channel": "control", + "hex": "010400000061efbfbd" + }, + { + "channel": "control", + "hex": "00003d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00013d0000000000000000000000" + }, + { + "channel": "control", + "hex": "010100000062" + } + ] + }, + { + "name": "empty marked composition delete", + "operation": "delete", + "composition_text": "", + "expect": [ + { + "channel": "control", + "hex": "0000430000000000000000000000" + }, + { + "channel": "control", + "hex": "0001430000000000000000000000" + } + ] + }, + { + "name": "nonempty marked composition delete stays local", + "operation": "delete", + "composition_text": "a", + "expect": [] + }, + { + "name": "composition update stays local", + "operation": "composition_update", + "text": "に", + "expect": [] + }, + { + "name": "composition finalized", + "operation": "composition_end", + "text": "日本語😀", + "expect": [ + { + "channel": "control", + "hex": "010d000000e697a5e69cace8aa9ef09f9880" + } + ] + }, + { + "name": "composition finalized splits and drops", + "operation": "composition_end", + "text": "a\t\nb\u0000", + "expect": [ + { + "channel": "control", + "hex": "010100000061" + }, + { + "channel": "control", + "hex": "00003d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00013d0000000000000000000000" + }, + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + }, + { + "channel": "control", + "hex": "010100000062" + } + ] + }, + { + "name": "composition empty", + "operation": "composition_end", + "text": "", + "expect": [] + } + ] +} diff --git a/conformance/fixtures/input/keys.json b/conformance/fixtures/input/keys.json new file mode 100644 index 0000000..1a7e9c9 --- /dev/null +++ b/conformance/fixtures/input/keys.json @@ -0,0 +1,4571 @@ +{ + "cases": [ + { + "name": "single character U+0061", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "a", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "a", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000061" + } + ] + }, + { + "name": "single character U+0041", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "A", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "A", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000041" + } + ] + }, + { + "name": "single character U+00e9", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "é", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "é", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0102000000c3a9" + } + ] + }, + { + "name": "single character U+4e2d", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "中", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "中", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0103000000e4b8ad" + } + ] + }, + { + "name": "single character U+0020", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": " ", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": " ", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000020" + } + ] + }, + { + "name": "single character U+0021", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "!", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "!", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000021" + } + ] + }, + { + "name": "single character U+0000", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "\u0000", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "\u0000", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000000" + } + ] + }, + { + "name": "single character U+0001", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "\u0001", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "\u0001", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000001" + } + ] + }, + { + "name": "single character U+0009", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "\t", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "\t", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000009" + } + ] + }, + { + "name": "single character U+000a", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "\n", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "\n", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "01010000000a" + } + ] + }, + { + "name": "single character U+000d", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "\r", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "\r", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "01010000000d" + } + ] + }, + { + "name": "single character U+001b", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "\u001b", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "\u001b", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "01010000001b" + } + ] + }, + { + "name": "single character U+007f", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "01010000007f" + } + ] + }, + { + "name": "single character U+0085", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "…", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "…", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0102000000c285" + } + ] + }, + { + "name": "single character U+d83d", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "\ud83d", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "\ud83d", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0103000000efbfbd" + } + ] + }, + { + "name": "unknown code printable", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Unidentified", + "key": "a", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Unidentified", + "key": "a", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000061" + } + ] + }, + { + "name": "unknown code control character", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Unidentified", + "key": "\u0001", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Unidentified", + "key": "\u0001", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000001" + } + ] + }, + { + "name": "unknown code nontext", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Unidentified", + "key": "Unidentified", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Unidentified", + "key": "Unidentified", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [] + }, + { + "name": "unknown code named control", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Unidentified", + "key": "Enter", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Unidentified", + "key": "Enter", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [] + }, + { + "name": "unknown code ctrl combo", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Unidentified", + "key": "a", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Unidentified", + "key": "a", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [] + }, + { + "name": "uppercase f control heuristic", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyF", + "key": "F", + "shift": true, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyF", + "key": "F", + "shift": true, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000220000000000000001000000" + }, + { + "channel": "control", + "hex": "0001220000000000000001000000" + } + ] + }, + { + "name": "dead key mapped fallback", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "Quote", + "key": "Dead", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Quote", + "key": "Dead", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00004b0000000000000000000000" + }, + { + "channel": "control", + "hex": "00014b0000000000000000000000" + } + ] + }, + { + "name": "dead key unknown fallback", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Unidentified", + "key": "Dead", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Unidentified", + "key": "Dead", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [] + }, + { + "name": "emoji grapheme", + "sdk_decisions": [ + "grapheme_text" + ], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "😀", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "😀", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0104000000f09f9880" + } + ] + }, + { + "name": "emoji unknown code grapheme", + "sdk_decisions": [ + "grapheme_text" + ], + "events": [ + { + "type": "keydown", + "code": "Unidentified", + "key": "😀", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Unidentified", + "key": "😀", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0104000000f09f9880" + } + ] + }, + { + "name": "emoji zwj grapheme", + "sdk_decisions": [ + "grapheme_text" + ], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "👨‍👩‍👧‍👦", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "👨‍👩‍👧‍👦", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0119000000f09f91a8e2808df09f91a9e2808df09f91a7e2808df09f91a6" + } + ] + }, + { + "name": "emoji skin tone grapheme", + "sdk_decisions": [ + "grapheme_text" + ], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "👍🏽", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "👍🏽", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0108000000f09f918df09f8fbd" + } + ] + }, + { + "name": "nfd grapheme", + "sdk_decisions": [ + "grapheme_text" + ], + "events": [ + { + "type": "keydown", + "code": "KeyE", + "key": "é", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyE", + "key": "é", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010300000065cc81" + } + ] + }, + { + "name": "multiple graphemes fallback", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "ab", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "ab", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00001d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00011d0000000000000000000000" + } + ] + }, + { + "name": "empty key fallback", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00001d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00011d0000000000000000000000" + } + ] + }, + { + "name": "caps lock unmapped", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "CapsLock", + "key": "CapsLock", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "CapsLock", + "key": "CapsLock", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [] + }, + { + "name": "context menu fallback", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "ContextMenu", + "key": "ContextMenu", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ContextMenu", + "key": "ContextMenu", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001520000000000000000000000" + } + ] + }, + { + "name": "numpad no text fallback", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "Numpad1", + "key": "Unidentified", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Numpad1", + "key": "Unidentified", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000910000000000000000000000" + }, + { + "channel": "control", + "hex": "0001910000000000000000000000" + } + ] + }, + { + "name": "numpad decimal no text fallback", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "NumpadDecimal", + "key": "", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "NumpadDecimal", + "key": "", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00009e0000000000000000000000" + }, + { + "channel": "control", + "hex": "00019e0000000000000000000000" + } + ] + }, + { + "name": "alt no char fallback", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00001d0000000000000002000000" + }, + { + "channel": "control", + "hex": "00011d0000000000000002000000" + } + ] + }, + { + "name": "alt caps no char fallback", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "KeyC", + "key": "", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": true, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyC", + "key": "", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": true, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00001f0000000000000003000000" + }, + { + "channel": "control", + "hex": "00011f0000000000000003000000" + } + ] + }, + { + "name": "backspace", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Backspace", + "key": "Backspace", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Backspace", + "key": "Backspace", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000430000000000000000000000" + }, + { + "channel": "control", + "hex": "0001430000000000000000000000" + } + ] + }, + { + "name": "delete", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Delete", + "key": "Delete", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Delete", + "key": "Delete", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000700000000000000000000000" + }, + { + "channel": "control", + "hex": "0001700000000000000000000000" + } + ] + }, + { + "name": "enter", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Enter", + "key": "Enter", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Enter", + "key": "Enter", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000420000000000000000000000" + }, + { + "channel": "control", + "hex": "0001420000000000000000000000" + } + ] + }, + { + "name": "tab", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Tab", + "key": "Tab", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Tab", + "key": "Tab", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00003d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00013d0000000000000000000000" + } + ] + }, + { + "name": "escape", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Escape", + "key": "Escape", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Escape", + "key": "Escape", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00006f0000000000000000000000" + }, + { + "channel": "control", + "hex": "00016f0000000000000000000000" + } + ] + }, + { + "name": "home", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Home", + "key": "Home", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Home", + "key": "Home", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00007a0000000000000000000000" + }, + { + "channel": "control", + "hex": "00017a0000000000000000000000" + } + ] + }, + { + "name": "end", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "End", + "key": "End", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "End", + "key": "End", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00007b0000000000000000000000" + }, + { + "channel": "control", + "hex": "00017b0000000000000000000000" + } + ] + }, + { + "name": "pageup", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "PageUp", + "key": "PageUp", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "PageUp", + "key": "PageUp", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00005c0000000000000000000000" + }, + { + "channel": "control", + "hex": "00015c0000000000000000000000" + } + ] + }, + { + "name": "pagedown", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "PageDown", + "key": "PageDown", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "PageDown", + "key": "PageDown", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00005d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00015d0000000000000000000000" + } + ] + }, + { + "name": "insert", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Insert", + "key": "Insert", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Insert", + "key": "Insert", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00007c0000000000000000000000" + }, + { + "channel": "control", + "hex": "00017c0000000000000000000000" + } + ] + }, + { + "name": "arrowup", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowUp", + "key": "ArrowUp", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowUp", + "key": "ArrowUp", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000130000000000000000000000" + }, + { + "channel": "control", + "hex": "0001130000000000000000000000" + } + ] + }, + { + "name": "arrowdown", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowDown", + "key": "ArrowDown", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowDown", + "key": "ArrowDown", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000140000000000000000000000" + }, + { + "channel": "control", + "hex": "0001140000000000000000000000" + } + ] + }, + { + "name": "arrowleft", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000000000000" + }, + { + "channel": "control", + "hex": "0001150000000000000000000000" + } + ] + }, + { + "name": "arrowright", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowRight", + "key": "ArrowRight", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowRight", + "key": "ArrowRight", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000160000000000000000000000" + }, + { + "channel": "control", + "hex": "0001160000000000000000000000" + } + ] + }, + { + "name": "numpad enter", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "NumpadEnter", + "key": "Enter", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "NumpadEnter", + "key": "Enter", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000a00000000000000000000000" + }, + { + "channel": "control", + "hex": "0001a00000000000000000000000" + } + ] + }, + { + "name": "f1", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F1", + "key": "F1", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F1", + "key": "F1", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000830000000000000000000000" + }, + { + "channel": "control", + "hex": "0001830000000000000000000000" + } + ] + }, + { + "name": "f2", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F2", + "key": "F2", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F2", + "key": "F2", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000840000000000000000000000" + }, + { + "channel": "control", + "hex": "0001840000000000000000000000" + } + ] + }, + { + "name": "f3", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F3", + "key": "F3", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F3", + "key": "F3", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000850000000000000000000000" + }, + { + "channel": "control", + "hex": "0001850000000000000000000000" + } + ] + }, + { + "name": "f4", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F4", + "key": "F4", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F4", + "key": "F4", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000860000000000000000000000" + }, + { + "channel": "control", + "hex": "0001860000000000000000000000" + } + ] + }, + { + "name": "f5", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F5", + "key": "F5", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F5", + "key": "F5", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000870000000000000000000000" + }, + { + "channel": "control", + "hex": "0001870000000000000000000000" + } + ] + }, + { + "name": "f6", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F6", + "key": "F6", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F6", + "key": "F6", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000880000000000000000000000" + }, + { + "channel": "control", + "hex": "0001880000000000000000000000" + } + ] + }, + { + "name": "f7", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F7", + "key": "F7", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F7", + "key": "F7", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000890000000000000000000000" + }, + { + "channel": "control", + "hex": "0001890000000000000000000000" + } + ] + }, + { + "name": "f8", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F8", + "key": "F8", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F8", + "key": "F8", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00008a0000000000000000000000" + }, + { + "channel": "control", + "hex": "00018a0000000000000000000000" + } + ] + }, + { + "name": "f9", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F9", + "key": "F9", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F9", + "key": "F9", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00008b0000000000000000000000" + }, + { + "channel": "control", + "hex": "00018b0000000000000000000000" + } + ] + }, + { + "name": "f10", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F10", + "key": "F10", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F10", + "key": "F10", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00008c0000000000000000000000" + }, + { + "channel": "control", + "hex": "00018c0000000000000000000000" + } + ] + }, + { + "name": "f11", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F11", + "key": "F11", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F11", + "key": "F11", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00008d0000000000000000000000" + }, + { + "channel": "control", + "hex": "00018d0000000000000000000000" + } + ] + }, + { + "name": "f12", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F12", + "key": "F12", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F12", + "key": "F12", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00008e0000000000000000000000" + }, + { + "channel": "control", + "hex": "00018e0000000000000000000000" + } + ] + }, + { + "name": "unmapped function representative", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "F13", + "key": "F13", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "F13", + "key": "F13", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [] + }, + { + "name": "shift left", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ShiftLeft", + "key": "Shift", + "shift": true, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ShiftLeft", + "key": "Shift", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00003b0000000000000001000000" + }, + { + "channel": "control", + "hex": "00013b0000000000000000000000" + } + ] + }, + { + "name": "shift right", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ShiftRight", + "key": "Shift", + "shift": true, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ShiftRight", + "key": "Shift", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00003c0000000000000001000000" + }, + { + "channel": "control", + "hex": "00013c0000000000000000000000" + } + ] + }, + { + "name": "control left", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000710000000000000000100000" + }, + { + "channel": "control", + "hex": "0001710000000000000000000000" + } + ] + }, + { + "name": "control right", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ControlRight", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ControlRight", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000720000000000000000100000" + }, + { + "channel": "control", + "hex": "0001720000000000000000000000" + } + ] + }, + { + "name": "alt left", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "AltLeft", + "key": "Alt", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "AltLeft", + "key": "Alt", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000390000000000000002000000" + }, + { + "channel": "control", + "hex": "0001390000000000000000000000" + } + ] + }, + { + "name": "alt right", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "AltRight", + "key": "Alt", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "AltRight", + "key": "Alt", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00003a0000000000000002000000" + }, + { + "channel": "control", + "hex": "00013a0000000000000000000000" + } + ] + }, + { + "name": "meta left", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000750000000000000000000100" + }, + { + "channel": "control", + "hex": "0001750000000000000000000000" + } + ] + }, + { + "name": "meta right", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "MetaRight", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "MetaRight", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000760000000000000000000100" + }, + { + "channel": "control", + "hex": "0001760000000000000000000000" + } + ] + }, + { + "name": "modifier mask 0", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000000000000" + }, + { + "channel": "control", + "hex": "0001150000000000000000000000" + } + ] + }, + { + "name": "modifier mask 1", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000001000000" + }, + { + "channel": "control", + "hex": "0001150000000000000001000000" + } + ] + }, + { + "name": "modifier mask 2", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000002000000" + }, + { + "channel": "control", + "hex": "0001150000000000000002000000" + } + ] + }, + { + "name": "modifier mask 3", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000003000000" + }, + { + "channel": "control", + "hex": "0001150000000000000003000000" + } + ] + }, + { + "name": "modifier mask 4", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000000100000" + }, + { + "channel": "control", + "hex": "0001150000000000000000100000" + } + ] + }, + { + "name": "modifier mask 5", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000001100000" + }, + { + "channel": "control", + "hex": "0001150000000000000001100000" + } + ] + }, + { + "name": "modifier mask 6", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": true, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": true, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000002100000" + }, + { + "channel": "control", + "hex": "0001150000000000000002100000" + } + ] + }, + { + "name": "modifier mask 7", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": true, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": true, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000003100000" + }, + { + "channel": "control", + "hex": "0001150000000000000003100000" + } + ] + }, + { + "name": "modifier mask 8", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000000000100" + }, + { + "channel": "control", + "hex": "0001150000000000000000000100" + } + ] + }, + { + "name": "modifier mask 9", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000001000100" + }, + { + "channel": "control", + "hex": "0001150000000000000001000100" + } + ] + }, + { + "name": "modifier mask 10", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": true, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": true, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000002000100" + }, + { + "channel": "control", + "hex": "0001150000000000000002000100" + } + ] + }, + { + "name": "modifier mask 11", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": true, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": true, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000003000100" + }, + { + "channel": "control", + "hex": "0001150000000000000003000100" + } + ] + }, + { + "name": "modifier mask 12", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": true, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": true, + "meta": true, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000000100100" + }, + { + "channel": "control", + "hex": "0001150000000000000000100100" + } + ] + }, + { + "name": "modifier mask 13", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": false, + "ctrl": true, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": false, + "ctrl": true, + "meta": true, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000001100100" + }, + { + "channel": "control", + "hex": "0001150000000000000001100100" + } + ] + }, + { + "name": "modifier mask 14", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": true, + "ctrl": true, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": true, + "ctrl": true, + "meta": true, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000002100100" + }, + { + "channel": "control", + "hex": "0001150000000000000002100100" + } + ] + }, + { + "name": "modifier mask 15", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": true, + "ctrl": true, + "meta": true, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": true, + "alt": true, + "ctrl": true, + "meta": true, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000003100100" + }, + { + "channel": "control", + "hex": "0001150000000000000003100100" + } + ] + }, + { + "name": "letter shift false caps false", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyC", + "key": "c", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyC", + "key": "c", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00001f0000000000000000100000" + }, + { + "channel": "control", + "hex": "00011f0000000000000000100000" + } + ] + }, + { + "name": "letter shift false caps true", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyC", + "key": "c", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": true, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyC", + "key": "c", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": true, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00001f0000000000000001100000" + }, + { + "channel": "control", + "hex": "00011f0000000000000001100000" + } + ] + }, + { + "name": "letter shift true caps false", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyC", + "key": "c", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyC", + "key": "c", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00001f0000000000000001100000" + }, + { + "channel": "control", + "hex": "00011f0000000000000001100000" + } + ] + }, + { + "name": "letter shift true caps true", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyC", + "key": "c", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": true, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyC", + "key": "c", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": true, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "00001f0000000000000000100000" + }, + { + "channel": "control", + "hex": "00011f0000000000000000100000" + } + ] + }, + { + "name": "caps lock nonletter", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Digit1", + "key": "Unidentified", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": true, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Digit1", + "key": "Unidentified", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": true, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000080000000000000000100000" + }, + { + "channel": "control", + "hex": "0001080000000000000000100000" + } + ] + }, + { + "name": "caps lock nonletter shift", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "Digit1", + "key": "Unidentified", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": true, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Digit1", + "key": "Unidentified", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": true, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000080000000000000001100000" + }, + { + "channel": "control", + "hex": "0001080000000000000001100000" + } + ] + }, + { + "name": "alt printable", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyQ", + "key": "@", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyQ", + "key": "@", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000040" + } + ] + }, + { + "name": "ctrl v letter released first", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keydown", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000710000000000000000100000" + }, + { + "channel": "control", + "hex": "090000000000000000010000000b68c3a96c6c6f0af09f9880" + }, + { + "channel": "control", + "hex": "0001710000000000000000000000" + } + ] + }, + { + "name": "ctrl v modifier released first", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keydown", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000710000000000000000100000" + }, + { + "channel": "control", + "hex": "090000000000000000010000000b68c3a96c6c6f0af09f9880" + }, + { + "channel": "control", + "hex": "0001710000000000000000000000" + } + ] + }, + { + "name": "ctrl m letter released first", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keydown", + "code": "KeyM", + "key": "m", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "KeyM", + "key": "m", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000710000000000000000100000" + }, + { + "channel": "control", + "hex": "0000520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001710000000000000000000000" + } + ] + }, + { + "name": "ctrl m modifier released first", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keydown", + "code": "KeyM", + "key": "m", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyM", + "key": "m", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000710000000000000000100000" + }, + { + "channel": "control", + "hex": "0000520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001710000000000000000000000" + } + ] + }, + { + "name": "meta v letter released first", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keydown", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000750000000000000000000100" + }, + { + "channel": "control", + "hex": "090000000000000000010000000b68c3a96c6c6f0af09f9880" + }, + { + "channel": "control", + "hex": "0001750000000000000000000000" + } + ] + }, + { + "name": "meta v modifier released first", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keydown", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000750000000000000000000100" + }, + { + "channel": "control", + "hex": "090000000000000000010000000b68c3a96c6c6f0af09f9880" + }, + { + "channel": "control", + "hex": "0001750000000000000000000000" + } + ] + }, + { + "name": "meta m letter released first", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keydown", + "code": "KeyM", + "key": "m", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "KeyM", + "key": "m", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000750000000000000000000100" + }, + { + "channel": "control", + "hex": "0000520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001750000000000000000000000" + } + ] + }, + { + "name": "meta m modifier released first", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keydown", + "code": "KeyM", + "key": "m", + "shift": false, + "alt": false, + "ctrl": false, + "meta": true, + "caps_lock": false, + "clipboard": "héllo\n😀" + }, + { + "type": "keyup", + "code": "MetaLeft", + "key": "Meta", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyM", + "key": "m", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000750000000000000000000100" + }, + { + "channel": "control", + "hex": "0000520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001750000000000000000000000" + } + ] + }, + { + "name": "ctrl uppercase paste", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "KeyV", + "key": "V", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "text" + }, + { + "type": "keyup", + "code": "KeyV", + "key": "V", + "shift": true, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "text" + } + ], + "expect": [ + { + "channel": "control", + "hex": "090000000000000000010000000474657874" + } + ] + }, + { + "name": "ctrl empty paste", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyV", + "key": "v", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [] + }, + { + "name": "ctrl paste matches key not code", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "Period", + "key": "v", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "text" + }, + { + "type": "keyup", + "code": "Period", + "key": "v", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "text" + } + ], + "expect": [ + { + "channel": "control", + "hex": "090000000000000000010000000474657874" + } + ] + }, + { + "name": "ctrl period on v code is keycode", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyV", + "key": ".", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyV", + "key": ".", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000320000000000000000100000" + }, + { + "channel": "control", + "hex": "0001320000000000000000100000" + } + ] + }, + { + "name": "ctrl menu matches key not code", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "Period", + "key": "m", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "Period", + "key": "m", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000520000000000000000000000" + }, + { + "channel": "control", + "hex": "0001520000000000000000000000" + } + ] + }, + { + "name": "ctrl period on m code is keycode", + "sdk_decisions": [], + "events": [ + { + "type": "keydown", + "code": "KeyM", + "key": ".", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyM", + "key": ".", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000290000000000000000100000" + }, + { + "channel": "control", + "hex": "0001290000000000000000100000" + } + ] + }, + { + "name": "alt released before fallback letter", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "AltLeft", + "key": "Alt", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keydown", + "code": "KeyA", + "key": "", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "AltLeft", + "key": "Alt", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "a", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000390000000000000002000000" + }, + { + "channel": "control", + "hex": "00001d0000000000000002000000" + }, + { + "channel": "control", + "hex": "0001390000000000000000000000" + }, + { + "channel": "control", + "hex": "00011d0000000000000000000000" + } + ] + }, + { + "name": "cross modifier release uses current metadata", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keydown", + "code": "AltLeft", + "key": "Alt", + "shift": false, + "alt": true, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keydown", + "code": "KeyA", + "key": "a", + "shift": false, + "alt": true, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "a", + "shift": false, + "alt": true, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "AltLeft", + "key": "Alt", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000710000000000000000100000" + }, + { + "channel": "control", + "hex": "0000390000000000000002100000" + }, + { + "channel": "control", + "hex": "00001d0000000000000002100000" + }, + { + "channel": "control", + "hex": "0001710000000000000002000000" + }, + { + "channel": "control", + "hex": "00011d0000000000000002000000" + }, + { + "channel": "control", + "hex": "0001390000000000000000000000" + } + ] + }, + { + "name": "text before ctrl has no orphan up", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "KeyA", + "key": "a", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keydown", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "KeyA", + "key": "a", + "shift": false, + "alt": false, + "ctrl": true, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "010100000061" + }, + { + "channel": "control", + "hex": "0000710000000000000000100000" + }, + { + "channel": "control", + "hex": "0001710000000000000000000000" + } + ] + }, + { + "name": "orphan control up ignored", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keyup", + "code": "ControlLeft", + "key": "Control", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [] + }, + { + "name": "repeat down and duplicate up", + "sdk_decisions": [ + "tracked_key_release" + ], + "events": [ + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keydown", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + }, + { + "type": "keyup", + "code": "ArrowLeft", + "key": "ArrowLeft", + "shift": false, + "alt": false, + "ctrl": false, + "meta": false, + "caps_lock": false, + "clipboard": "" + } + ], + "expect": [ + { + "channel": "control", + "hex": "0000150000000000000000000000" + }, + { + "channel": "control", + "hex": "0000150000000000000000000000" + }, + { + "channel": "control", + "hex": "0001150000000000000000000000" + } + ] + } + ] +} diff --git a/conformance/fixtures/input/pointers.json b/conformance/fixtures/input/pointers.json new file mode 100644 index 0000000..ba9136a --- /dev/null +++ b/conformance/fixtures/input/pointers.json @@ -0,0 +1,1223 @@ +{ + "cases": [ + { + "name": "single touch last position", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 42, + "x": 100, + "y": 200, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 42, + "x": 110, + "y": 220, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 42, + "x": 900, + "y": 900, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "0200000000000000000064000000c800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020200000000000000006e000000dc00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020100000000000000006e000000dc00000038046009ffff0100000001000000" + } + ] + }, + { + "name": "two fingers independent slots", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 42, + "x": 100, + "y": 200, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 7, + "x": 300, + "y": 400, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 42, + "x": 120, + "y": 220, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 7, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 42, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "0200000000000000000064000000c800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020000000000000000012c0100009001000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0202000000000000000078000000dc00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020100000000000000012c0100009001000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0201000000000000000078000000dc00000038046009ffff0100000001000000" + } + ] + }, + { + "name": "lowest free slot reused", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 8, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 9, + "x": 30, + "y": 40, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 8, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 10, + "x": 50, + "y": 60, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 9, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 10, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "020000000000000000000a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020000000000000000011e0000002800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020100000000000000000a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02000000000000000000320000003c00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020300000000000000011e0000002800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02010000000000000000320000003c00000038046009ffff0100000001000000" + } + ] + }, + { + "name": "outside down ignored", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 4, + "x": -1, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 4, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 4, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [] + }, + { + "name": "outside movement release at last inside", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 4, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 4, + "x": 20, + "y": 30, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 4, + "x": 1081, + "y": 30, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 4, + "x": 1081, + "y": 30, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "020000000000000000000a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02020000000000000000140000001e00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02010000000000000000140000001e00000038046009ffff0100000001000000" + } + ] + }, + { + "name": "cancel last position", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 4, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 4, + "x": 20, + "y": 30, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 4, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 4, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "020000000000000000000a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02020000000000000000140000001e00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02030000000000000000140000001e00000038046009ffff0100000001000000" + } + ] + }, + { + "name": "mouse hover drag hover channels", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "move", + "id": 99, + "x": 10, + "y": 20, + "mouse": true, + "button": 0, + "buttons": 2 + }, + { + "type": "down", + "id": 99, + "x": 10, + "y": 20, + "mouse": true, + "button": 0, + "buttons": 1 + }, + { + "type": "move", + "id": 99, + "x": 30, + "y": 40, + "mouse": true, + "button": 0, + "buttons": 1 + }, + { + "type": "up", + "id": 99, + "x": 900, + "y": 900, + "mouse": true, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 99, + "x": 50, + "y": 60, + "mouse": true, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "hover", + "hex": "150a000000140000003804600902000000" + }, + { + "channel": "control", + "hex": "0200ffffffffffffffff0a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0202ffffffffffffffff1e0000002800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0201ffffffffffffffff1e0000002800000038046009ffff0100000001000000" + }, + { + "channel": "hover", + "hex": "15320000003c0000003804600900000000" + } + ] + }, + { + "name": "mouse and finger independent", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 5, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 5, + "x": 30, + "y": 40, + "mouse": true, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 5, + "x": 0, + "y": 0, + "mouse": true, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 5, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "020000000000000000000a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0200ffffffffffffffff1e0000002800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0201ffffffffffffffff1e0000002800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020300000000000000000a0000001400000038046009ffff0100000001000000" + } + ] + }, + { + "name": "hover outside ignored", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "move", + "id": 0, + "x": -1, + "y": 0, + "mouse": true, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 0, + "x": 1081, + "y": 0, + "mouse": true, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 0, + "x": 1080, + "y": 2400, + "mouse": true, + "button": 0, + "buttons": 6 + } + ], + "expect": [ + { + "channel": "hover", + "hex": "1538040000600900003804600906000000" + } + ] + }, + { + "name": "unmatched touch events", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "move", + "id": 77, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 77, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 77, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [] + }, + { + "name": "duplicate down ignored", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 77, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 77, + "x": 30, + "y": 40, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 77, + "x": 30, + "y": 40, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "020000000000000000000a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020100000000000000000a0000001400000038046009ffff0100000001000000" + } + ] + }, + { + "name": "inclusive bounds and rounding", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 1, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 1, + "x": 2.5, + "y": 3.49, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 1, + "x": 1080, + "y": 2400, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 1, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "02000000000000000000000000000000000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02020000000000000000030000000300000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02020000000000000000380400006009000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02010000000000000000380400006009000038046009ffff0100000001000000" + } + ] + }, + { + "name": "ten slots capacity and recovery", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 100, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 101, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 102, + "x": 20, + "y": 40, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 103, + "x": 30, + "y": 60, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 104, + "x": 40, + "y": 80, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 105, + "x": 50, + "y": 100, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 106, + "x": 60, + "y": 120, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 107, + "x": 70, + "y": 140, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 108, + "x": 80, + "y": 160, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 109, + "x": 90, + "y": 180, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 110, + "x": 100, + "y": 200, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 110, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "up", + "id": 103, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "down", + "id": 110, + "x": 80, + "y": 90, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 100, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 101, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 102, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 103, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 104, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 105, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 106, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 107, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 108, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 109, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 110, + "x": -1, + "y": -1, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "02000000000000000000000000000000000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020000000000000000010a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02000000000000000002140000002800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020000000000000000031e0000003c00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02000000000000000004280000005000000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02000000000000000005320000006400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020000000000000000063c0000007800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02000000000000000007460000008c00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0200000000000000000850000000a000000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020000000000000000095a000000b400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020100000000000000031e0000003c00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02000000000000000003500000005a00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02030000000000000000000000000000000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020300000000000000010a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02030000000000000002140000002800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02030000000000000004280000005000000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02030000000000000005320000006400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020300000000000000063c0000007800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02030000000000000007460000008c00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0203000000000000000850000000a000000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "020300000000000000095a000000b400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02030000000000000003500000005a00000038046009ffff0100000001000000" + } + ] + }, + { + "name": "video not ready", + "video_width": 0, + "video_height": 0, + "events": [ + { + "type": "down", + "id": 1, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 0, + "x": 0, + "y": 0, + "mouse": true, + "button": 0, + "buttons": 0 + } + ], + "expect": [] + }, + { + "name": "nonprimary button 1 hover only", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 0, + "x": 10, + "y": 20, + "mouse": true, + "button": 1, + "buttons": 4 + }, + { + "type": "move", + "id": 0, + "x": 30, + "y": 40, + "mouse": true, + "button": 0, + "buttons": 4 + }, + { + "type": "up", + "id": 0, + "x": 50, + "y": 60, + "mouse": true, + "button": 1, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "hover", + "hex": "151e000000280000003804600904000000" + } + ] + }, + { + "name": "nonprimary button 2 hover only", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 0, + "x": 10, + "y": 20, + "mouse": true, + "button": 2, + "buttons": 2 + }, + { + "type": "move", + "id": 0, + "x": 30, + "y": 40, + "mouse": true, + "button": 0, + "buttons": 2 + }, + { + "type": "up", + "id": 0, + "x": 50, + "y": 60, + "mouse": true, + "button": 2, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "hover", + "hex": "151e000000280000003804600902000000" + } + ] + }, + { + "name": "nonprimary up does not end primary gesture", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 0, + "x": 10, + "y": 20, + "mouse": true, + "button": 0, + "buttons": 1 + }, + { + "type": "up", + "id": 0, + "x": 20, + "y": 30, + "mouse": true, + "button": 2, + "buttons": 1 + }, + { + "type": "move", + "id": 0, + "x": 30, + "y": 40, + "mouse": true, + "button": 0, + "buttons": 1 + }, + { + "type": "up", + "id": 0, + "x": 50, + "y": 60, + "mouse": true, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "0200ffffffffffffffff0a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0202ffffffffffffffff1e0000002800000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "0201ffffffffffffffff1e0000002800000038046009ffff0100000001000000" + } + ] + }, + { + "name": "hover while touch slot active", + "video_width": 1080, + "video_height": 2400, + "events": [ + { + "type": "down", + "id": 42, + "x": 10, + "y": 20, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "move", + "id": 999, + "x": 30, + "y": 40, + "mouse": true, + "button": 0, + "buttons": 6 + }, + { + "type": "move", + "id": 42, + "x": 50, + "y": 60, + "mouse": false, + "button": 0, + "buttons": 0 + }, + { + "type": "cancel", + "id": 42, + "x": 0, + "y": 0, + "mouse": false, + "button": 0, + "buttons": 0 + } + ], + "expect": [ + { + "channel": "control", + "hex": "020000000000000000000a0000001400000038046009ffff0100000001000000" + }, + { + "channel": "hover", + "hex": "151e000000280000003804600906000000" + }, + { + "channel": "control", + "hex": "02020000000000000000320000003c00000038046009ffff0100000001000000" + }, + { + "channel": "control", + "hex": "02030000000000000000320000003c00000038046009ffff0100000001000000" + } + ] + } + ] +} diff --git a/conformance/fixtures/input/scroll.json b/conformance/fixtures/input/scroll.json new file mode 100644 index 0000000..8133a56 --- /dev/null +++ b/conformance/fixtures/input/scroll.json @@ -0,0 +1,315 @@ +{ + "cases": [ + { + "name": "zero", + "h": 0, + "v": 0, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b00000014000000380460090000000000000000" + } + ] + }, + { + "name": "up", + "h": 0, + "v": 1, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b00000014000000380460090000000800000000" + } + ] + }, + { + "name": "down", + "h": 0, + "v": -1, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b0000001400000038046009000000f800000000" + } + ] + }, + { + "name": "left", + "h": 1, + "v": 0, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b00000014000000380460090008000000000000" + } + ] + }, + { + "name": "right", + "h": -1, + "v": 0, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b000000140000003804600900f8000000000000" + } + ] + }, + { + "name": "fractional", + "h": 0.3, + "v": -0.07, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b0000001400000038046009660271ff00000000" + } + ] + }, + { + "name": "half", + "h": 0.5, + "v": -0.5, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b0000001400000038046009000400fc00000000" + } + ] + }, + { + "name": "both axes", + "h": 2, + "v": -3, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b0000001400000038046009001000e800000000" + } + ] + }, + { + "name": "positive limit", + "h": 16, + "v": 16, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b0000001400000038046009ff7fff7f00000000" + } + ] + }, + { + "name": "negative limit", + "h": -16, + "v": -16, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b00000014000000380460090080008000000000" + } + ] + }, + { + "name": "saturated", + "h": 1000, + "v": -1000, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b0000001400000038046009ff7f008000000000" + } + ] + }, + { + "name": "positive half quantum", + "h": 0.000244140625, + "v": 0, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b00000014000000380460090100000000000000" + } + ] + }, + { + "name": "negative half quantum", + "h": -0.000244140625, + "v": 0, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b00000014000000380460090000000000000000" + } + ] + }, + { + "name": "below quantum", + "h": 0.0001220703125, + "v": -0.0001220703125, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 20.49, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030b00000014000000380460090000000000000000" + } + ] + }, + { + "name": "buttons and bounds", + "h": 0, + "v": 1, + "video_width": 2400, + "video_height": 1080, + "x": 2400, + "y": 1080, + "buttons": 3, + "expect": [ + { + "channel": "control", + "hex": "036009000038040000600938040000000803000000" + } + ] + }, + { + "name": "origin inclusive", + "h": 0, + "v": 1, + "video_width": 1080, + "video_height": 2400, + "x": 0, + "y": 0, + "buttons": 0, + "expect": [ + { + "channel": "control", + "hex": "030000000000000000380460090000000800000000" + } + ] + }, + { + "name": "outside left", + "h": 0, + "v": 1, + "video_width": 1080, + "video_height": 2400, + "x": -1, + "y": 20.49, + "buttons": 0, + "expect": [] + }, + { + "name": "outside right", + "h": 0, + "v": 1, + "video_width": 1080, + "video_height": 2400, + "x": 1081, + "y": 20.49, + "buttons": 0, + "expect": [] + }, + { + "name": "outside top", + "h": 0, + "v": 1, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": -1, + "buttons": 0, + "expect": [] + }, + { + "name": "outside bottom", + "h": 0, + "v": 1, + "video_width": 1080, + "video_height": 2400, + "x": 10.5, + "y": 2401, + "buttons": 0, + "expect": [] + }, + { + "name": "video not ready", + "h": 0, + "v": 1, + "video_width": 0, + "video_height": 0, + "x": 0, + "y": 0, + "buttons": 0, + "expect": [] + } + ] +} diff --git a/conformance/fixtures/reconnect/policy.json b/conformance/fixtures/reconnect/policy.json new file mode 100644 index 0000000..889cddb --- /dev/null +++ b/conformance/fixtures/reconnect/policy.json @@ -0,0 +1,136 @@ +{ + "max_attempts": 6, + "connect_timeout_ms": 45000, + "stability_ms": 30000, + "backoff": { + "base_delay_ms": 1000, + "max_delay_ms": 30000, + "formula": "round(min(base_delay_ms * 2^(max(1, attempt) - 1), max_delay_ms) * (0.75 + random * 0.5)); random in [0, 1), random = 1 only as the upper-bound limit case", + "rounding": "round half toward +infinity (Math.round)" + }, + "delay_cases": [ + { + "attempt": 1, + "random": 0, + "delay_ms": 750 + }, + { + "attempt": 1, + "random": 0.5, + "delay_ms": 1000 + }, + { + "attempt": 1, + "random": 1, + "delay_ms": 1250 + }, + { + "attempt": 2, + "random": 0, + "delay_ms": 1500 + }, + { + "attempt": 2, + "random": 0.5, + "delay_ms": 2000 + }, + { + "attempt": 2, + "random": 1, + "delay_ms": 2500 + }, + { + "attempt": 3, + "random": 0, + "delay_ms": 3000 + }, + { + "attempt": 3, + "random": 0.5, + "delay_ms": 4000 + }, + { + "attempt": 3, + "random": 1, + "delay_ms": 5000 + }, + { + "attempt": 4, + "random": 0, + "delay_ms": 6000 + }, + { + "attempt": 4, + "random": 0.5, + "delay_ms": 8000 + }, + { + "attempt": 4, + "random": 1, + "delay_ms": 10000 + }, + { + "attempt": 5, + "random": 0, + "delay_ms": 12000 + }, + { + "attempt": 5, + "random": 0.5, + "delay_ms": 16000 + }, + { + "attempt": 5, + "random": 1, + "delay_ms": 20000 + }, + { + "attempt": 6, + "random": 0, + "delay_ms": 22500 + }, + { + "attempt": 6, + "random": 0.5, + "delay_ms": 30000 + }, + { + "attempt": 6, + "random": 1, + "delay_ms": 37500 + }, + { + "attempt": 7, + "random": 0, + "delay_ms": 22500 + }, + { + "attempt": 7, + "random": 0.5, + "delay_ms": 30000 + }, + { + "attempt": 7, + "random": 1, + "delay_ms": 37500 + }, + { + "attempt": 10, + "random": 0, + "delay_ms": 22500 + }, + { + "attempt": 10, + "random": 0.5, + "delay_ms": 30000 + }, + { + "attempt": 10, + "random": 1, + "delay_ms": 37500 + } + ], + "invariants": [ + "connect_timeout_ms > ws_open_timeout_ms + rtc_config_timeout_ms (the two handshake timeouts are defined in signalling/sequence.json timing)" + ] +} diff --git a/conformance/fixtures/reconnect/scenarios.json b/conformance/fixtures/reconnect/scenarios.json new file mode 100644 index 0000000..4cbfd63 --- /dev/null +++ b/conformance/fixtures/reconnect/scenarios.json @@ -0,0 +1,1298 @@ +{ + "events": [ + "attempt_mounted", + "connected", + "disconnected", + "failure", + "wake", + "retry", + "disable", + "dispose" + ], + "scenarios": [ + { + "name": "connect watchdog › an attempt that never connects fails after the timeout and schedules a retry", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 1, + "status": "connecting", + "attempt": 0, + "heal_calls": 0, + "remount_calls": 0 + }, + { + "at_ms": 45000, + "after_steps": 1, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 46000, + "after_steps": 1, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 1 + } + ] + }, + { + "name": "connect watchdog › terminal failure signal retries faster than the watchdog", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 100, + "event": "failure" + } + ], + "expect": [ + { + "at_ms": 100, + "after_steps": 2, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 1100, + "after_steps": 2, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 1 + } + ] + }, + { + "name": "backoff escalation and exhaustion › consecutive failures escalate delays and end unavailable", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 1000, + "event": "attempt_mounted" + }, + { + "at_ms": 1000, + "event": "failure" + }, + { + "at_ms": 3000, + "event": "attempt_mounted" + }, + { + "at_ms": 3000, + "event": "failure" + }, + { + "at_ms": 7000, + "event": "attempt_mounted" + }, + { + "at_ms": 7000, + "event": "failure" + }, + { + "at_ms": 15000, + "event": "attempt_mounted" + }, + { + "at_ms": 15000, + "event": "failure" + }, + { + "at_ms": 31000, + "event": "attempt_mounted" + }, + { + "at_ms": 31000, + "event": "failure" + }, + { + "at_ms": 61000, + "event": "attempt_mounted" + }, + { + "at_ms": 61000, + "event": "failure" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 2, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 999, + "after_steps": 2, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 1000, + "after_steps": 2, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 1 + }, + { + "at_ms": 1000, + "after_steps": 4, + "status": "reconnecting", + "attempt": 2, + "heal_calls": 1, + "remount_calls": 1 + }, + { + "at_ms": 2999, + "after_steps": 4, + "status": "reconnecting", + "attempt": 2, + "heal_calls": 1, + "remount_calls": 1 + }, + { + "at_ms": 3000, + "after_steps": 4, + "status": "reconnecting", + "attempt": 2, + "heal_calls": 1, + "remount_calls": 2 + }, + { + "at_ms": 3000, + "after_steps": 6, + "status": "reconnecting", + "attempt": 3, + "heal_calls": 1, + "remount_calls": 2 + }, + { + "at_ms": 6999, + "after_steps": 6, + "status": "reconnecting", + "attempt": 3, + "heal_calls": 1, + "remount_calls": 2 + }, + { + "at_ms": 7000, + "after_steps": 6, + "status": "reconnecting", + "attempt": 3, + "heal_calls": 1, + "remount_calls": 3 + }, + { + "at_ms": 7000, + "after_steps": 8, + "status": "reconnecting", + "attempt": 4, + "heal_calls": 1, + "remount_calls": 3 + }, + { + "at_ms": 14999, + "after_steps": 8, + "status": "reconnecting", + "attempt": 4, + "heal_calls": 1, + "remount_calls": 3 + }, + { + "at_ms": 15000, + "after_steps": 8, + "status": "reconnecting", + "attempt": 4, + "heal_calls": 1, + "remount_calls": 4 + }, + { + "at_ms": 15000, + "after_steps": 10, + "status": "reconnecting", + "attempt": 5, + "heal_calls": 1, + "remount_calls": 4 + }, + { + "at_ms": 30999, + "after_steps": 10, + "status": "reconnecting", + "attempt": 5, + "heal_calls": 1, + "remount_calls": 4 + }, + { + "at_ms": 31000, + "after_steps": 10, + "status": "reconnecting", + "attempt": 5, + "heal_calls": 1, + "remount_calls": 5 + }, + { + "at_ms": 31000, + "after_steps": 12, + "status": "reconnecting", + "attempt": 6, + "heal_calls": 1, + "remount_calls": 5 + }, + { + "at_ms": 60999, + "after_steps": 12, + "status": "reconnecting", + "attempt": 6, + "heal_calls": 1, + "remount_calls": 5 + }, + { + "at_ms": 61000, + "after_steps": 12, + "status": "reconnecting", + "attempt": 6, + "heal_calls": 1, + "remount_calls": 6 + }, + { + "at_ms": 61000, + "after_steps": 14, + "status": "unavailable", + "attempt": 7, + "heal_calls": 1, + "remount_calls": 6 + }, + { + "at_ms": 661000, + "after_steps": 14, + "status": "unavailable", + "attempt": 7, + "heal_calls": 1, + "remount_calls": 6 + } + ] + }, + { + "name": "backoff escalation and exhaustion › failure signals collapse into one backoff step per attempt", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 0, + "event": "disconnected" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 4, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + } + ] + }, + { + "name": "disconnect handling › non-connected states during negotiation are not failures", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "disconnected" + }, + { + "at_ms": 0, + "event": "disconnected" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 3, + "status": "connecting", + "attempt": 0, + "heal_calls": 0, + "remount_calls": 0 + } + ] + }, + { + "name": "disconnect handling › a drop after connecting counts and reconnects", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "connected" + }, + { + "at_ms": 0, + "event": "disconnected" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 2, + "status": "connected", + "attempt": 0, + "heal_calls": 0, + "remount_calls": 0 + }, + { + "at_ms": 0, + "after_steps": 3, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 1000, + "after_steps": 3, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 1 + } + ] + }, + { + "name": "disconnect handling › a stable connection refills the retry budget", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 1000, + "event": "attempt_mounted" + }, + { + "at_ms": 1000, + "event": "failure" + }, + { + "at_ms": 3000, + "event": "attempt_mounted" + }, + { + "at_ms": 3000, + "event": "connected" + }, + { + "at_ms": 33000, + "event": "disconnected" + } + ], + "expect": [ + { + "at_ms": 3000, + "after_steps": 6, + "status": "connected", + "attempt": 2, + "heal_calls": 1, + "remount_calls": 2 + }, + { + "at_ms": 33000, + "after_steps": 6, + "status": "connected", + "attempt": 0, + "heal_calls": 1, + "remount_calls": 2 + }, + { + "at_ms": 33000, + "after_steps": 7, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 2, + "remount_calls": 2 + } + ] + }, + { + "name": "disconnect handling › a quick drop before stability keeps escalating", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 1000, + "event": "attempt_mounted" + }, + { + "at_ms": 1000, + "event": "connected" + }, + { + "at_ms": 2000, + "event": "disconnected" + } + ], + "expect": [ + { + "at_ms": 2000, + "after_steps": 5, + "status": "reconnecting", + "attempt": 2, + "heal_calls": 1, + "remount_calls": 1 + } + ] + }, + { + "name": "disconnect handling › self-recovery during a backoff wait cancels the pending remount", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "connected" + }, + { + "at_ms": 0, + "event": "disconnected" + }, + { + "at_ms": 0, + "event": "connected" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 3, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 0, + "after_steps": 4, + "status": "connected", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 60000, + "after_steps": 4, + "status": "connected", + "attempt": 0, + "heal_calls": 1, + "remount_calls": 0 + } + ] + }, + { + "name": "wake and manual retry › wake during a backoff wait retries immediately", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "connected" + }, + { + "at_ms": 0, + "event": "disconnected" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 0, + "event": "wake" + }, + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "connected" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 4, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 0, + "after_steps": 5, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 1 + }, + { + "at_ms": 60000, + "after_steps": 7, + "status": "connected", + "attempt": 0, + "heal_calls": 1, + "remount_calls": 1 + } + ] + }, + { + "name": "wake and manual retry › wake while unavailable starts a fresh cycle", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 1000, + "event": "attempt_mounted" + }, + { + "at_ms": 1000, + "event": "failure" + }, + { + "at_ms": 3000, + "event": "attempt_mounted" + }, + { + "at_ms": 3000, + "event": "failure" + }, + { + "at_ms": 7000, + "event": "attempt_mounted" + }, + { + "at_ms": 7000, + "event": "failure" + }, + { + "at_ms": 15000, + "event": "attempt_mounted" + }, + { + "at_ms": 15000, + "event": "failure" + }, + { + "at_ms": 31000, + "event": "attempt_mounted" + }, + { + "at_ms": 31000, + "event": "failure" + }, + { + "at_ms": 61000, + "event": "attempt_mounted" + }, + { + "at_ms": 61000, + "event": "failure" + }, + { + "at_ms": 91000, + "event": "wake" + }, + { + "at_ms": 91000, + "event": "attempt_mounted" + }, + { + "at_ms": 91000, + "event": "connected" + } + ], + "expect": [ + { + "at_ms": 91000, + "after_steps": 14, + "status": "unavailable", + "attempt": 7, + "heal_calls": 1, + "remount_calls": 6 + }, + { + "at_ms": 91000, + "after_steps": 15, + "status": "reconnecting", + "attempt": 0, + "heal_calls": 2, + "remount_calls": 7 + }, + { + "at_ms": 91000, + "after_steps": 17, + "status": "connected", + "attempt": 0, + "heal_calls": 2, + "remount_calls": 7 + } + ] + }, + { + "name": "wake and manual retry › retry() only acts when unavailable", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "retry" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 2, + "status": "connecting", + "attempt": 0, + "heal_calls": 0, + "remount_calls": 0 + } + ] + }, + { + "name": "wake and manual retry › wake while connected is a no-op", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "connected" + }, + { + "at_ms": 0, + "event": "wake" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 3, + "status": "connected", + "attempt": 0, + "heal_calls": 0, + "remount_calls": 0 + } + ] + }, + { + "name": "target changes › applies target changes immediately while connected or connecting", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "connected" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 1, + "status": "connecting", + "attempt": 0, + "heal_calls": 0, + "remount_calls": 0, + "defer_target_change": false + }, + { + "at_ms": 0, + "after_steps": 2, + "status": "connected", + "attempt": 0, + "heal_calls": 0, + "remount_calls": 0, + "defer_target_change": false + } + ] + }, + { + "name": "target changes › defers target changes during a backoff wait and while unavailable", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 1000, + "event": "attempt_mounted" + }, + { + "at_ms": 1000, + "event": "failure" + }, + { + "at_ms": 3000, + "event": "attempt_mounted" + }, + { + "at_ms": 3000, + "event": "failure" + }, + { + "at_ms": 7000, + "event": "attempt_mounted" + }, + { + "at_ms": 7000, + "event": "failure" + }, + { + "at_ms": 15000, + "event": "attempt_mounted" + }, + { + "at_ms": 15000, + "event": "failure" + }, + { + "at_ms": 31000, + "event": "attempt_mounted" + }, + { + "at_ms": 31000, + "event": "failure" + }, + { + "at_ms": 61000, + "event": "attempt_mounted" + }, + { + "at_ms": 61000, + "event": "failure" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 2, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0, + "defer_target_change": true + }, + { + "at_ms": 91000, + "after_steps": 14, + "status": "unavailable", + "attempt": 7, + "heal_calls": 1, + "remount_calls": 6, + "defer_target_change": true + } + ] + }, + { + "name": "target changes › applies credentials that arrive after the backoff to the in-flight retry", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 1000, + "event": "attempt_mounted" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 2, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0, + "defer_target_change": true + }, + { + "at_ms": 1000, + "after_steps": 3, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 1, + "defer_target_change": false + } + ] + }, + { + "name": "target changes › applies credentials that arrive after wake to the in-flight fresh cycle", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 1000, + "event": "attempt_mounted" + }, + { + "at_ms": 1000, + "event": "failure" + }, + { + "at_ms": 3000, + "event": "attempt_mounted" + }, + { + "at_ms": 3000, + "event": "failure" + }, + { + "at_ms": 7000, + "event": "attempt_mounted" + }, + { + "at_ms": 7000, + "event": "failure" + }, + { + "at_ms": 15000, + "event": "attempt_mounted" + }, + { + "at_ms": 15000, + "event": "failure" + }, + { + "at_ms": 31000, + "event": "attempt_mounted" + }, + { + "at_ms": 31000, + "event": "failure" + }, + { + "at_ms": 61000, + "event": "attempt_mounted" + }, + { + "at_ms": 61000, + "event": "failure" + }, + { + "at_ms": 91000, + "event": "wake" + }, + { + "at_ms": 91000, + "event": "attempt_mounted" + } + ], + "expect": [ + { + "at_ms": 91000, + "after_steps": 14, + "status": "unavailable", + "attempt": 7, + "heal_calls": 1, + "remount_calls": 6 + }, + { + "at_ms": 91000, + "after_steps": 16, + "status": "reconnecting", + "attempt": 0, + "heal_calls": 2, + "remount_calls": 7, + "defer_target_change": false + } + ] + }, + { + "name": "target changes › a rotation remount flips connected back to connecting", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "connected" + }, + { + "at_ms": 0, + "event": "attempt_mounted" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 3, + "status": "connecting", + "attempt": 0, + "heal_calls": 0, + "remount_calls": 0 + } + ] + }, + { + "name": "disable and dispose › disabling stops timers and resets state", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 0, + "event": "disable" + }, + { + "at_ms": 600000, + "event": "failure" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 3, + "status": "connecting", + "attempt": 0, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 600000, + "after_steps": 3, + "status": "connecting", + "attempt": 0, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 600000, + "after_steps": 4, + "status": "connecting", + "attempt": 0, + "heal_calls": 1, + "remount_calls": 0 + } + ] + }, + { + "name": "disable and dispose › dispose clears all pending timers", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 0, + "event": "dispose" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 3, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0, + "pending_timers": 0 + } + ] + }, + { + "name": "disable and dispose › a StrictMode-style mount during a wait does not disturb it", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "connected" + }, + { + "at_ms": 0, + "event": "disconnected" + }, + { + "at_ms": 0, + "event": "attempt_mounted" + } + ], + "expect": [ + { + "at_ms": 999, + "after_steps": 4, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 1000, + "after_steps": 4, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 1 + } + ] + }, + { + "name": "heal cadence › one heal per recovery cycle, again after stability reset and on wake", + "random": 0.5, + "steps": [ + { + "at_ms": 0, + "event": "attempt_mounted" + }, + { + "at_ms": 0, + "event": "failure" + }, + { + "at_ms": 1000, + "event": "attempt_mounted" + }, + { + "at_ms": 1000, + "event": "failure" + }, + { + "at_ms": 3000, + "event": "attempt_mounted" + }, + { + "at_ms": 3000, + "event": "connected" + }, + { + "at_ms": 33000, + "event": "disconnected" + }, + { + "at_ms": 35000, + "event": "attempt_mounted" + }, + { + "at_ms": 35000, + "event": "failure" + }, + { + "at_ms": 39000, + "event": "attempt_mounted" + }, + { + "at_ms": 39000, + "event": "failure" + }, + { + "at_ms": 47000, + "event": "attempt_mounted" + }, + { + "at_ms": 47000, + "event": "failure" + }, + { + "at_ms": 63000, + "event": "attempt_mounted" + }, + { + "at_ms": 63000, + "event": "failure" + }, + { + "at_ms": 93000, + "event": "attempt_mounted" + }, + { + "at_ms": 93000, + "event": "failure" + }, + { + "at_ms": 123000, + "event": "attempt_mounted" + }, + { + "at_ms": 123000, + "event": "failure" + }, + { + "at_ms": 123000, + "event": "wake" + }, + { + "at_ms": 123000, + "event": "attempt_mounted" + }, + { + "at_ms": 123000, + "event": "failure" + } + ], + "expect": [ + { + "at_ms": 0, + "after_steps": 2, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 1, + "remount_calls": 0 + }, + { + "at_ms": 1000, + "after_steps": 4, + "status": "reconnecting", + "attempt": 2, + "heal_calls": 1, + "remount_calls": 1 + }, + { + "at_ms": 33000, + "after_steps": 7, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 2, + "remount_calls": 2 + }, + { + "at_ms": 123000, + "after_steps": 19, + "status": "unavailable", + "attempt": 7, + "heal_calls": 2, + "remount_calls": 8 + }, + { + "at_ms": 123000, + "after_steps": 20, + "status": "reconnecting", + "attempt": 0, + "heal_calls": 3, + "remount_calls": 9 + }, + { + "at_ms": 123000, + "after_steps": 22, + "status": "reconnecting", + "attempt": 1, + "heal_calls": 3, + "remount_calls": 9 + } + ] + } + ] +} diff --git a/conformance/fixtures/signalling/client-candidate.json b/conformance/fixtures/signalling/client-candidate.json new file mode 100644 index 0000000..0bbb5ca --- /dev/null +++ b/conformance/fixtures/signalling/client-candidate.json @@ -0,0 +1,47 @@ +{ + "type": "candidate", + "direction": "client_to_server", + "description": "A locally gathered ICE candidate, sent as soon as it is gathered (trickle ICE). The end-of-candidates null event is not sent.", + "fields": [ + { + "name": "type", + "type": "string (constant \"candidate\")", + "required": true + }, + { + "name": "candidate", + "type": "string", + "required": true, + "notes": "SDP candidate line, passed as RTCIceCandidateInit.candidate" + }, + { + "name": "sdpMid", + "type": "string | null", + "required": true, + "notes": "May be null" + }, + { + "name": "sdpMLineIndex", + "type": "integer | null", + "required": true, + "notes": "May be null" + }, + { + "name": "sessionId", + "type": "string", + "required": true + } + ], + "examples": [ + { + "name": "srflx candidate", + "json": { + "type": "candidate", + "candidate": "candidate:842163049 1 udp 1677729535 203.0.113.7 46154 typ srflx raddr 0.0.0.0 rport 0 generation 0", + "sdpMid": "0", + "sdpMLineIndex": 0, + "sessionId": "sess_0123456789abcdef" + } + } + ] +} diff --git a/conformance/fixtures/signalling/client-keep-alive.json b/conformance/fixtures/signalling/client-keep-alive.json new file mode 100644 index 0000000..02147c0 --- /dev/null +++ b/conformance/fixtures/signalling/client-keep-alive.json @@ -0,0 +1,26 @@ +{ + "type": "keepAlive", + "direction": "client_to_server", + "description": "Sent every 10000 ms while the page is visible and the socket is open.", + "fields": [ + { + "name": "type", + "type": "string (constant \"keepAlive\")", + "required": true + }, + { + "name": "sessionId", + "type": "string", + "required": true + } + ], + "examples": [ + { + "name": "keepAlive", + "json": { + "type": "keepAlive", + "sessionId": "sess_0123456789abcdef" + } + } + ] +} diff --git a/conformance/fixtures/signalling/client-offer.json b/conformance/fixtures/signalling/client-offer.json new file mode 100644 index 0000000..ffd114c --- /dev/null +++ b/conformance/fixtures/signalling/client-offer.json @@ -0,0 +1,32 @@ +{ + "type": "offer", + "direction": "client_to_server", + "description": "SDP offer. Sent once after the peer connection is set up, and again for every mid-session ICE-restart.", + "fields": [ + { + "name": "type", + "type": "string (constant \"offer\")", + "required": true + }, + { + "name": "sdp", + "type": "string", + "required": true + }, + { + "name": "sessionId", + "type": "string", + "required": true + } + ], + "examples": [ + { + "name": "initial offer", + "json": { + "type": "offer", + "sdp": "v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0 1\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111\r\nm=video 9 UDP/TLS/RTP/SAVPF 96\r\n", + "sessionId": "sess_0123456789abcdef" + } + } + ] +} diff --git a/conformance/fixtures/signalling/client-open-url.json b/conformance/fixtures/signalling/client-open-url.json new file mode 100644 index 0000000..a5d8066 --- /dev/null +++ b/conformance/fixtures/signalling/client-open-url.json @@ -0,0 +1,36 @@ +{ + "type": "openUrl", + "direction": "client_to_server", + "description": "Optional. Sent once when the control data channel opens, only if the embedding app supplied a URL to open.", + "fields": [ + { + "name": "type", + "type": "string (constant \"openUrl\")", + "required": true + }, + { + "name": "url", + "type": "string", + "required": true, + "notes": "The supplied URL after decodeURIComponent; if decoding throws, the supplied value unchanged" + }, + { + "name": "sessionId", + "type": "string", + "required": true + } + ], + "examples": [ + { + "name": "percent-encoded input", + "json": { + "type": "openUrl", + "url": "https://example.test/path?q=a b", + "sessionId": "sess_0123456789abcdef" + } + } + ], + "notes": [ + "Input \"https%3A%2F%2Fexample.test%2Fpath%3Fq%3Da%20b\" yields the shown url." + ] +} diff --git a/conformance/fixtures/signalling/client-request-frame.json b/conformance/fixtures/signalling/client-request-frame.json new file mode 100644 index 0000000..dfe14f6 --- /dev/null +++ b/conformance/fixtures/signalling/client-request-frame.json @@ -0,0 +1,26 @@ +{ + "type": "requestFrame", + "direction": "client_to_server", + "description": "Asks the encoder for a fresh frame. Sent 12 times, 125 ms apart, starting when the control data channel opens.", + "fields": [ + { + "name": "type", + "type": "string (constant \"requestFrame\")", + "required": true + }, + { + "name": "sessionId", + "type": "string", + "required": true + } + ], + "examples": [ + { + "name": "requestFrame", + "json": { + "type": "requestFrame", + "sessionId": "sess_0123456789abcdef" + } + } + ] +} diff --git a/conformance/fixtures/signalling/client-request-rtc-configuration.json b/conformance/fixtures/signalling/client-request-rtc-configuration.json new file mode 100644 index 0000000..5cd825d --- /dev/null +++ b/conformance/fixtures/signalling/client-request-rtc-configuration.json @@ -0,0 +1,33 @@ +{ + "type": "requestRtcConfiguration", + "direction": "client_to_server", + "description": "First message after the WebSocket opens. Asks the server for the RTCConfiguration (ICE servers).", + "fields": [ + { + "name": "type", + "type": "string (constant \"requestRtcConfiguration\")", + "required": true + }, + { + "name": "sessionId", + "type": "string", + "required": true + }, + { + "name": "supportsLiveRtcRefresh", + "type": "boolean (constant true)", + "required": true, + "notes": "Opt-in to unsolicited mid-session rtcConfiguration pushes. The client always sends true." + } + ], + "examples": [ + { + "name": "as produced by createRTCConfigurationRequest", + "json": { + "type": "requestRtcConfiguration", + "sessionId": "sess_0123456789abcdef", + "supportsLiveRtcRefresh": true + } + } + ] +} diff --git a/conformance/fixtures/signalling/client-screenshot-request.json b/conformance/fixtures/signalling/client-screenshot-request.json new file mode 100644 index 0000000..16227f5 --- /dev/null +++ b/conformance/fixtures/signalling/client-screenshot-request.json @@ -0,0 +1,31 @@ +{ + "type": "screenshot", + "direction": "client_to_server", + "description": "Requests a screenshot. The reply (screenshot or screenshotError) carries the same id.", + "fields": [ + { + "name": "type", + "type": "string (constant \"screenshot\")", + "required": true + }, + { + "name": "id", + "type": "string", + "required": true, + "notes": "Client-chosen correlation id; React uses \"ui-ss--<7 random base36 chars>\"" + } + ], + "examples": [ + { + "name": "screenshot request", + "json": { + "type": "screenshot", + "id": "ui-ss-1700000000000-k3j9x2a" + } + } + ], + "notes": [ + "No sessionId in this message.", + "The client rejects the pending request after 30000 ms without a reply." + ] +} diff --git a/conformance/fixtures/signalling/sequence.json b/conformance/fixtures/signalling/sequence.json new file mode 100644 index 0000000..634abd9 --- /dev/null +++ b/conformance/fixtures/signalling/sequence.json @@ -0,0 +1,204 @@ +{ + "timing": { + "ws_open_timeout_ms": 15000, + "rtc_config_timeout_ms": 15000, + "request_frame_count": 12, + "request_frame_interval_ms": 125, + "keep_alive_interval_ms": 10000, + "ice_restart_grace_ms": 15000, + "screenshot_timeout_ms": 30000 + }, + "channels": { + "control": { + "label": "control", + "id": 1, + "negotiated": true, + "ordered": true, + "maxRetransmits": null, + "notes": "reliable, ordered; carries all binary control messages" + }, + "hover": { + "label": "hover", + "id": 2, + "negotiated": true, + "ordered": false, + "maxRetransmits": 0, + "notes": "unordered, no retransmits; carries hover messages only, dropped (never sent on control) while not open" + } + }, + "peer_connection": { + "transceivers": [ + { + "kind": "audio", + "direction": "recvonly" + }, + { + "kind": "video", + "direction": "recvonly", + "notes": "codec preference order: VP9, H265/HEVC, H264/AVC, then the rest" + } + ], + "ice_servers_from": "rtcConfiguration reply" + }, + "happy_path": [ + { + "n": 1, + "actor": "client", + "action": "open WebSocket (token, if any, as query parameter \"token\")", + "message": null, + "notes": "fail if not open within 15000 ms or if closed before open" + }, + { + "n": 2, + "actor": "client", + "action": "start keepAlive timer (first tick 10000 ms after mount), paused while the page is hidden", + "message": null, + "notes": "timer is armed at mount, not after the control channel opens; ticks are skipped unless the socket is open" + }, + { + "n": 3, + "actor": "client", + "action": "send", + "message": "client-request-rtc-configuration" + }, + { + "n": 4, + "actor": "server", + "action": "send", + "message": "server-rtc-configuration", + "notes": "fail if no reply within 15000 ms" + }, + { + "n": 5, + "actor": "client", + "action": "create peer connection with the received configuration; add recvonly audio and video transceivers; create negotiated data channels control (id 1) and hover (id 2)", + "message": null + }, + { + "n": 6, + "actor": "client", + "action": "attach message handler (answer, candidate, screenshot, screenshotError, later rtcConfiguration)", + "message": null + }, + { + "n": 7, + "actor": "client", + "action": "create offer, set local description, send", + "message": "client-offer" + }, + { + "n": 8, + "actor": "client", + "action": "send each locally gathered ICE candidate immediately", + "message": "client-candidate", + "notes": "may start before the answer arrives" + }, + { + "n": 9, + "actor": "server", + "action": "send", + "message": "server-answer" + }, + { + "n": 10, + "actor": "server", + "action": "send zero or more (may arrive before the answer)", + "message": "server-candidate", + "notes": "candidates arriving before the answer is applied are buffered, then added in arrival order right after setRemoteDescription" + }, + { + "n": 11, + "actor": "client", + "action": "set remote description from the answer, then flush buffered remote candidates", + "message": null + }, + { + "n": 12, + "actor": "client", + "action": "control data channel opens: send requestFrame 12 times, 125 ms apart (+0, +125, ... +1375 ms)", + "message": "client-request-frame" + }, + { + "n": 13, + "actor": "client", + "action": "if an URL to open was supplied, send right after step 12 scheduling", + "message": "client-open-url" + }, + { + "n": 14, + "actor": "client", + "action": "peer connection state \"connected\": report connected", + "message": null + }, + { + "n": 15, + "actor": "client", + "action": "keepAlive every 10000 ms", + "message": "client-keep-alive" + } + ], + "refresh": [ + { + "n": 1, + "actor": "server", + "action": "send unsolicited credential refresh (only effective once happy_path step 6 is done: before that the next rtcConfiguration is the initial reply)", + "message": "server-rtc-configuration" + }, + { + "n": 2, + "actor": "client", + "action": "ignore if rtcConfiguration.iceServers is missing; otherwise setConfiguration({iceServers}); if that throws, stop here", + "message": null + }, + { + "n": 3, + "actor": "client", + "action": "suppress non-terminal connection-state dips for 15000 ms (grace window)", + "message": null, + "notes": "\"failed\" and \"closed\" always pass through; a re-check at the end of the window reports a non-connected state" + }, + { + "n": 4, + "actor": "client", + "action": "create offer with iceRestart: true, set local description", + "message": null + }, + { + "n": 5, + "actor": "client", + "action": "mark remote description as not set; drop buffered candidates; send", + "message": "client-offer", + "notes": "candidates arriving from now on are buffered until the answer" + }, + { + "n": 6, + "actor": "server", + "action": "send", + "message": "server-answer" + }, + { + "n": 7, + "actor": "client", + "action": "set remote description; flush buffered candidates", + "message": null + }, + { + "n": 8, + "actor": "client", + "action": "on \"connected\" the grace window ends immediately", + "message": null + } + ], + "failure_triggers": [ + "WebSocket fails to open in time or closes before open", + "rtcConfiguration reply missing after the timeout, or a message received while awaiting it is not valid JSON", + "offer creation / negotiation setup throws", + "WebSocket closes while the peer connection state is not \"connected\"", + "peer connection state becomes \"failed\" or \"closed\"" + ], + "ignored": [ + "Per connection phase. While awaiting the initial rtcConfiguration (happy_path steps 3-4): a message that is not valid JSON fails startup (a failure, see failure_triggers); valid messages of any other type are ignored.", + "After the general message handler is attached (happy_path step 6 onward): messages that are not valid JSON are dropped, and so are messages with an unknown type.", + "answer or candidate while there is no peer connection is dropped." + ] +} diff --git a/conformance/fixtures/signalling/server-answer.json b/conformance/fixtures/signalling/server-answer.json new file mode 100644 index 0000000..5bfc136 --- /dev/null +++ b/conformance/fixtures/signalling/server-answer.json @@ -0,0 +1,29 @@ +{ + "type": "answer", + "direction": "server_to_client", + "description": "SDP answer to the latest offer (initial or ICE-restart).", + "fields": [ + { + "name": "type", + "type": "string (constant \"answer\")", + "required": true + }, + { + "name": "sdp", + "type": "string", + "required": true + } + ], + "examples": [ + { + "name": "answer", + "json": { + "type": "answer", + "sdp": "v=0\r\no=- 7614219274584779017 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0 1\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111\r\nm=video 9 UDP/TLS/RTP/SAVPF 96\r\n" + } + } + ], + "notes": [ + "A failing setRemoteDescription (e.g. a stale answer) is ignored; buffered candidates stay buffered." + ] +} diff --git a/conformance/fixtures/signalling/server-candidate.json b/conformance/fixtures/signalling/server-candidate.json new file mode 100644 index 0000000..cd568ee --- /dev/null +++ b/conformance/fixtures/signalling/server-candidate.json @@ -0,0 +1,41 @@ +{ + "type": "candidate", + "direction": "server_to_client", + "description": "A remote ICE candidate. Buffered until the remote description is set, then applied.", + "fields": [ + { + "name": "type", + "type": "string (constant \"candidate\")", + "required": true + }, + { + "name": "candidate", + "type": "string", + "required": true, + "notes": "SDP candidate line, passed as RTCIceCandidateInit.candidate" + }, + { + "name": "sdpMid", + "type": "string | null", + "required": true, + "notes": "May be null" + }, + { + "name": "sdpMLineIndex", + "type": "integer | null", + "required": true, + "notes": "May be null" + } + ], + "examples": [ + { + "name": "remote candidate", + "json": { + "type": "candidate", + "candidate": "candidate:842163049 1 udp 1677729535 203.0.113.7 46154 typ srflx raddr 0.0.0.0 rport 0 generation 0", + "sdpMid": "0", + "sdpMLineIndex": 0 + } + } + ] +} diff --git a/conformance/fixtures/signalling/server-rtc-configuration.json b/conformance/fixtures/signalling/server-rtc-configuration.json new file mode 100644 index 0000000..e434310 --- /dev/null +++ b/conformance/fixtures/signalling/server-rtc-configuration.json @@ -0,0 +1,59 @@ +{ + "type": "rtcConfiguration", + "direction": "server_to_client", + "description": "ICE configuration. The first one is the reply to requestRtcConfiguration. Later ones are unsolicited mid-session credential refreshes (only sent to clients that advertised supportsLiveRtcRefresh).", + "fields": [ + { + "name": "type", + "type": "string (constant \"rtcConfiguration\")", + "required": true + }, + { + "name": "rtcConfiguration", + "type": "object (RTCConfiguration)", + "required": true, + "notes": "Initial reply: the whole object is given to the RTCPeerConnection constructor. Refresh: only iceServers is read." + }, + { + "name": "rtcConfiguration.iceServers", + "type": "array of {urls: string | string[], username?: string, credential?: string}", + "required": false, + "notes": "Required for a refresh to have any effect: a refresh without iceServers is ignored." + } + ], + "examples": [ + { + "name": "initial reply or refresh", + "json": { + "type": "rtcConfiguration", + "rtcConfiguration": { + "iceServers": [ + { + "urls": [ + "stun:stun.example.test:3478" + ] + }, + { + "urls": [ + "turn:turn.example.test:3478?transport=udp", + "turns:turn.example.test:5349?transport=tcp" + ], + "username": "1700000000:user", + "credential": "cred-example" + } + ] + } + } + }, + { + "name": "refresh without iceServers (ignored)", + "json": { + "type": "rtcConfiguration", + "rtcConfiguration": {} + } + } + ], + "notes": [ + "Which of the two it is depends on the connection phase, not on the content: the first rtcConfiguration after requestRtcConfiguration is the initial reply. Once the peer connection and the general message handler exist (happy_path step 6) any further rtcConfiguration is a refresh. A refresh can therefore never be handled before that point." + ] +} diff --git a/conformance/fixtures/signalling/server-screenshot-error.json b/conformance/fixtures/signalling/server-screenshot-error.json new file mode 100644 index 0000000..d026e77 --- /dev/null +++ b/conformance/fixtures/signalling/server-screenshot-error.json @@ -0,0 +1,36 @@ +{ + "type": "screenshotError", + "direction": "server_to_client", + "description": "Failed screenshot reply.", + "fields": [ + { + "name": "type", + "type": "string (constant \"screenshotError\")", + "required": true + }, + { + "name": "id", + "type": "string", + "required": true, + "notes": "Must match a pending request, otherwise ignored" + }, + { + "name": "message", + "type": "string", + "required": true + } + ], + "examples": [ + { + "name": "error", + "json": { + "type": "screenshotError", + "id": "ui-ss-1700000000000-k3j9x2a", + "message": "capture failed" + } + } + ], + "notes": [ + "A message missing a string id or string message is ignored." + ] +} diff --git a/conformance/fixtures/signalling/server-screenshot.json b/conformance/fixtures/signalling/server-screenshot.json new file mode 100644 index 0000000..53c673d --- /dev/null +++ b/conformance/fixtures/signalling/server-screenshot.json @@ -0,0 +1,37 @@ +{ + "type": "screenshot", + "direction": "server_to_client", + "description": "Successful screenshot reply.", + "fields": [ + { + "name": "type", + "type": "string (constant \"screenshot\")", + "required": true + }, + { + "name": "id", + "type": "string", + "required": true, + "notes": "Must match a pending request, otherwise ignored" + }, + { + "name": "dataUri", + "type": "string", + "required": true, + "notes": "e.g. \"data:image/png;base64,...\"" + } + ], + "examples": [ + { + "name": "screenshot", + "json": { + "type": "screenshot", + "id": "ui-ss-1700000000000-k3j9x2a", + "dataUri": "data:image/png;base64,iVBORw0KGgo=" + } + } + ], + "notes": [ + "A message missing a string id or string dataUri is ignored." + ] +} diff --git a/scripts/sync-conformance.sh b/scripts/sync-conformance.sh new file mode 100755 index 0000000..ac90458 --- /dev/null +++ b/scripts/sync-conformance.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# Copyright 2026 Mobilerun +# SPDX-License-Identifier: Apache-2.0 +# Refresh the vendored conformance fixtures. +# +# Usage: scripts/sync-conformance.sh TAG [CLONE_DIR] +# +# Without CLONE_DIR the public repository is cloned into a temporary directory. +# The copy lives in conformance/fixtures and the tag is recorded in +# conformance/VERSION. Always pass a release tag, never a branch. +set -euo pipefail + +if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then + echo "usage: $0 TAG [CLONE_DIR]" >&2 + exit 2 +fi + +tag="$1" +root="$(cd "$(dirname "$0")/.." && pwd)" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +clone="${2:-}" +if [ -z "$clone" ]; then + clone="$tmp/clone" + git clone --quiet https://github.com/droidrun/mobilerun-sdk-conformance "$clone" +else + git -C "$clone" fetch --tags --quiet +fi + +git -C "$clone" rev-parse --verify --quiet "refs/tags/$tag" >/dev/null || { + echo "unknown tag: $tag" >&2 + exit 1 +} + +mkdir "$tmp/out" +git -C "$clone" archive "$tag" fixtures | tar -x -C "$tmp/out" + +rm -rf "$root/conformance/fixtures" +mkdir -p "$root/conformance" +mv "$tmp/out/fixtures" "$root/conformance/fixtures" +printf '%s\n' "$tag" > "$root/conformance/VERSION" +echo "conformance fixtures now at $tag" diff --git a/src/conformance/control.test.ts b/src/conformance/control.test.ts new file mode 100644 index 0000000..f93d771 --- /dev/null +++ b/src/conformance/control.test.ts @@ -0,0 +1,66 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, test } from 'bun:test'; +import { AMOTION_EVENT, ANDROID_KEYS, CONTROL_MSG_TYPE, codeMap } from '../constants'; +import { + createInjectKeycodeMessage, + createInjectMouseHoverMessage, + createInjectScrollEventMessage, + createInjectTextMessage, + createSetClipboardMessage, + createTouchControlMessage, +} from '../webrtc-messages'; +import { loadFixture, toHex } from './fixtures'; + +interface Case { + name: string; + args: Record; + hex: string; +} + +const builders: Record) => ArrayBuffer> = { + touch: (a) => + createTouchControlMessage( + a.action, + a.pointerId, + a.videoWidth, + a.videoHeight, + a.x, + a.y, + a.pressure, + a.actionButton, + a.buttons, + ), + scroll: (a) => + createInjectScrollEventMessage( + a.videoWidth, + a.videoHeight, + a.x, + a.y, + a.hscrollTicks, + a.vscrollTicks, + a.buttons, + ), + hover: (a) => + createInjectMouseHoverMessage(a.videoWidth, a.videoHeight, a.x, a.y, a.buttons), + keycode: (a) => createInjectKeycodeMessage(a.action, a.keycode, a.repeat, a.metaState), + text: (a) => createInjectTextMessage(a.text), + 'set-clipboard': (a) => createSetClipboardMessage(a.text, a.paste), +}; + +describe('constants', () => { + const constants = loadFixture('constants.json'); + test('control message types', () => expect({ ...CONTROL_MSG_TYPE }).toMatchObject(constants.control_msg_type)); + test('motion event values', () => expect({ ...AMOTION_EVENT }).toMatchObject(constants.amotion_event)); + test('android keys', () => expect({ ...ANDROID_KEYS }).toMatchObject(constants.android_keys)); + test('keyboard code map', () => expect({ ...codeMap }).toEqual(constants.code_map)); +}); + +for (const [family, build] of Object.entries(builders)) { + describe(`control/${family}`, () => { + for (const c of loadFixture<{ cases: Case[] }>(`control/${family}.json`).cases) { + test(c.name, () => expect(toHex(build(c.args))).toBe(c.hex)); + } + }); +} diff --git a/src/conformance/fixtures.ts b/src/conformance/fixtures.ts new file mode 100644 index 0000000..21fb1cc --- /dev/null +++ b/src/conformance/fixtures.ts @@ -0,0 +1,16 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +const root = join(import.meta.dir, '..', '..', 'conformance', 'fixtures'); + +/** Read a vendored conformance fixture (JSON keeps lone surrogates intact). */ +export function loadFixture(path: string): T { + return JSON.parse(readFileSync(join(root, path), 'utf8')) as T; +} + +export function toHex(bytes: ArrayBuffer): string { + return [...new Uint8Array(bytes)].map((b) => b.toString(16).padStart(2, '0')).join(''); +} diff --git a/src/conformance/input.test.ts b/src/conformance/input.test.ts new file mode 100644 index 0000000..a46297f --- /dev/null +++ b/src/conformance/input.test.ts @@ -0,0 +1,155 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, test } from 'bun:test'; +import { + createKeyRouter, + createPointerRouter, + mapClientPoint, + pasteMessages, + routeScroll, + type RoutedMessage, + type VideoPoint, +} from '../lib/input-routing'; +import { loadFixture, toHex } from './fixtures'; + +interface Expected { + channel: 'control' | 'hover'; + hex: string; +} +const wire = (messages: RoutedMessage[]): Expected[] => + messages.map((m) => ({ channel: m.channel, hex: toHex(m.data) })); + +// ------------------------------------------------------------------- keys + +interface KeyCase { + name: string; + events: { + type: 'keydown' | 'keyup'; + code: string; + key: string; + shift: boolean; + alt: boolean; + ctrl: boolean; + meta: boolean; + caps_lock: boolean; + clipboard: string; + }[]; + expect: Expected[]; +} + +describe('input/keys', () => { + for (const c of loadFixture<{ cases: KeyCase[] }>('input/keys.json').cases) { + test(c.name, () => { + const router = createKeyRouter(); + const out: RoutedMessage[] = []; + for (const e of c.events) { + const routed = router.route({ ...e, capsLock: e.caps_lock }); + if (routed.kind === 'paste') out.push(...pasteMessages(e.clipboard)); + else out.push(...routed.messages); + } + expect(wire(out)).toEqual(c.expect); + }); + } +}); + +// --------------------------------------------------------------- pointers + +interface PointerCase { + name: string; + video_width: number; + video_height: number; + events: { + type: 'down' | 'move' | 'up' | 'cancel'; + id: number; + x: number; + y: number; + mouse: boolean; + button: number; + buttons: number; + }[]; + expect: Expected[]; +} + +describe('input/pointers', () => { + for (const c of loadFixture<{ cases: PointerCase[] }>('input/pointers.json').cases) { + test(c.name, () => { + const router = createPointerRouter(); + const out: RoutedMessage[] = []; + for (const e of c.events) { + // The fixture positions are upright video pixels; the DOM layer maps client points the same way. + const inside = c.video_width > 0 && c.video_height > 0 && + e.x >= 0 && e.x <= c.video_width && e.y >= 0 && e.y <= c.video_height; + const point: VideoPoint | null = inside ? { x: e.x, y: e.y } : null; + out.push(...router.route({ ...e, point }, c.video_width, c.video_height)); + } + expect(wire(out)).toEqual(c.expect); + }); + } +}); + +// --------------------------------------------------------------- geometry + +interface GeometryCase { + name: string; + view_width: number; + view_height: number; + video_width: number; + video_height: number; + rotation: 0 | 90 | 180 | 270; + x: number; + y: number; + expect: { width: number; height: number; x: number; y: number } | null; +} + +describe('input/geometry', () => { + for (const c of loadFixture<{ cases: GeometryCase[] }>('input/geometry.json').cases) { + // The browser video element is always upright; rotation is a native-SDK concern. + const run = c.rotation === 0 ? test : test.skip; + run(`${c.name}${c.rotation ? ` (rotation ${c.rotation}, not applicable)` : ''}`, () => { + const point = mapClientPoint( + { left: 0, top: 0, width: c.view_width, height: c.view_height }, + c.video_width, + c.video_height, + c.x, + c.y, + ); + expect(point).toEqual(c.expect ? { x: c.expect.x, y: c.expect.y } : null); + }); + } +}); + +// ----------------------------------------------------------------- scroll + +interface ScrollCase { + name: string; + video_width: number; + video_height: number; + x: number; + y: number; + h: number; + v: number; + buttons: number; + expect: Expected[]; +} + +describe('input/scroll', () => { + for (const c of loadFixture<{ cases: ScrollCase[] }>('input/scroll.json').cases) { + test(c.name, () => { + const inside = c.x >= 0 && c.x <= c.video_width && c.y >= 0 && c.y <= c.video_height; + const point = inside ? { x: c.x, y: c.y } : null; + expect(wire(routeScroll(c.video_width, c.video_height, point, c.h, c.v, c.buttons))).toEqual(c.expect); + }); + } +}); + +// -------------------------------------------------------------------- ime + +// Browser keyboard input has no composition or commit path in React: text +// arrives as keydown `key` values (covered by input/keys). The cases of +// input/ime.json describe SDK text-commit operations and are not applicable. +describe('input/ime', () => { + for (const c of loadFixture<{ cases: { name: string }[] }>('input/ime.json').cases) { + test.skip(`${c.name} (not applicable: no composition path in the browser input)`, () => {}); + } +}); diff --git a/src/conformance/reconnect.test.ts b/src/conformance/reconnect.test.ts new file mode 100644 index 0000000..d10617c --- /dev/null +++ b/src/conformance/reconnect.test.ts @@ -0,0 +1,137 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, test } from 'bun:test'; +import { + createStreamReconnectController, + STREAM_CONNECT_TIMEOUT_MS, + STREAM_RECONNECT_MAX_ATTEMPTS, + STREAM_RECONNECT_STABILITY_MS, + STREAM_RTC_CONFIG_TIMEOUT_MS, + STREAM_WS_OPEN_TIMEOUT_MS, + streamReconnectDelayMs, +} from '../lib/stream-reconnect'; +import { loadFixture } from './fixtures'; + +const policy = loadFixture('reconnect/policy.json'); +const { scenarios } = loadFixture<{ scenarios: Scenario[] }>('reconnect/scenarios.json'); +const timing = loadFixture('signalling/sequence.json').timing; + +interface Scenario { + name: string; + random: number; + steps: { at_ms: number; event: string }[]; + expect: { + at_ms: number; + after_steps: number; + status: string; + attempt: number; + heal_calls: number; + remount_calls: number; + defer_target_change?: boolean; + pending_timers?: number; + }[]; +} + +// Fake clock: timers fire in due-time order, ties in scheduling order. +class FakeClock { + now = 0; + private nextId = 1; + private tasks = new Map void }>(); + setTimeout = (fn: () => void, ms: number) => { + const id = this.nextId++; + this.tasks.set(id, { at: this.now + ms, fn }); + return id as unknown as ReturnType; + }; + clearTimeout = (id: ReturnType) => { + this.tasks.delete(id as unknown as number); + }; + advanceTo(target: number) { + for (;;) { + let dueId: number | null = null; + let dueAt = Infinity; + for (const [id, task] of this.tasks) { + if (task.at <= target && task.at < dueAt) { + dueAt = task.at; + dueId = id; + } + } + if (dueId === null) break; + const task = this.tasks.get(dueId)!; + this.tasks.delete(dueId); + this.now = task.at; + task.fn(); + } + this.now = target; + } + get pending() { + return this.tasks.size; + } +} + +describe('reconnect/policy', () => { + test('constants', () => { + expect(STREAM_RECONNECT_MAX_ATTEMPTS).toBe(policy.max_attempts); + expect(STREAM_CONNECT_TIMEOUT_MS).toBe(policy.connect_timeout_ms); + expect(STREAM_RECONNECT_STABILITY_MS).toBe(policy.stability_ms); + expect(STREAM_WS_OPEN_TIMEOUT_MS).toBe(timing.ws_open_timeout_ms); + expect(STREAM_RTC_CONFIG_TIMEOUT_MS).toBe(timing.rtc_config_timeout_ms); + }); + test('watchdog outlasts the handshake phases', () => { + expect(policy.connect_timeout_ms).toBeGreaterThan( + timing.ws_open_timeout_ms + timing.rtc_config_timeout_ms, + ); + }); + for (const c of policy.delay_cases as { attempt: number; random: number; delay_ms: number }[]) { + test(`delay attempt ${c.attempt} random ${c.random}`, () => { + expect(streamReconnectDelayMs(c.attempt, () => c.random)).toBe(c.delay_ms); + }); + } +}); + +describe('reconnect/scenarios', () => { + for (const s of scenarios) { + test(s.name, () => { + const clock = new FakeClock(); + const calls = { heal: 0, remount: 0 }; + const controller = createStreamReconnectController({ + onRemount: () => void (calls.remount += 1), + onHeal: () => void (calls.heal += 1), + onSnapshot: () => {}, + schedule: clock, + random: () => s.random, + }); + const apply: Record void> = { + attempt_mounted: () => controller.attemptMounted(), + connected: () => controller.handleConnected(), + disconnected: () => controller.handleDisconnected(), + failure: () => controller.handleFailure(), + wake: () => controller.handleWake(), + retry: () => controller.retry(), + disable: () => controller.setDisabled(), + dispose: () => controller.dispose(), + }; + const check = (i: number) => { + for (const e of s.expect.filter((x) => x.after_steps === i).sort((a, b) => a.at_ms - b.at_ms)) { + clock.advanceTo(e.at_ms); + const label = `@${e.at_ms}ms after ${i} steps`; + const snapshot = controller.getSnapshot(); + expect([label, snapshot.status]).toEqual([label, e.status]); + expect([label, snapshot.attempt]).toEqual([label, e.attempt]); + expect([label, calls.heal]).toEqual([label, e.heal_calls]); + expect([label, calls.remount]).toEqual([label, e.remount_calls]); + if (e.defer_target_change !== undefined) { + expect([label, controller.shouldDeferTargetChange()]).toEqual([label, e.defer_target_change]); + } + if (e.pending_timers !== undefined) expect([label, clock.pending]).toEqual([label, e.pending_timers]); + } + }; + check(0); + s.steps.forEach((step, index) => { + clock.advanceTo(step.at_ms); + apply[step.event](); + check(index + 1); + }); + }); + } +}); diff --git a/src/conformance/signalling.test.ts b/src/conformance/signalling.test.ts new file mode 100644 index 0000000..5c10429 --- /dev/null +++ b/src/conformance/signalling.test.ts @@ -0,0 +1,207 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, test } from 'bun:test'; +import { event, fixture, tick } from '../hooks/webrtc-test-fixture'; +import { createRTCConfigurationRequest } from '../webrtc-messages'; +import { loadFixture } from './fixtures'; + +interface Example { + name: string; + json: Record; +} +const examples = (file: string) => loadFixture<{ examples: Example[] }>(`signalling/${file}.json`).examples; +const sequence = loadFixture('signalling/sequence.json'); +const SESSION = 'sess_0123456789abcdef'; + +// Client frames are observed on the fake socket while the real hook runs. +describe('signalling/client frames', () => { + for (const e of examples('client-request-rtc-configuration')) { + test(`requestRtcConfiguration: ${e.name}`, () => { + expect(createRTCConfigurationRequest(e.json.sessionId)).toEqual(e.json as any); + }); + test(`requestRtcConfiguration is the first frame sent: ${e.name}`, async () => { + const f = await fixture(); + f.mount(SESSION); + f.sockets[0].open(); + await tick(); + expect(f.sockets[0].sent[0]).toEqual(e.json); + f.unmount(); + }); + } + + for (const e of examples('client-offer')) { + test(`offer: ${e.name}`, async () => { + const f = await fixture(); + f.mount(SESSION); + f.sockets[0].open(); + await tick(); + f.sockets[0].config(); + await tick(); + f.peers[0].offer.resolve({ sdp: e.json.sdp }); + await tick(); + f.peers[0].local.resolve(); + await tick(); + expect(f.sockets[0].sent.find((m) => m.type === 'offer')).toEqual(e.json); + f.unmount(); + }); + } + + for (const e of examples('client-candidate')) { + test(`candidate: ${e.name}`, async () => { + const f = await fixture(); + f.mount(SESSION); + f.sockets[0].open(); + await tick(); + f.sockets[0].config(); + await tick(); + f.peers[0].onicecandidate({ + candidate: { candidate: e.json.candidate, sdpMid: e.json.sdpMid, sdpMLineIndex: e.json.sdpMLineIndex }, + }); + expect(f.sockets[0].sent.find((m) => m.type === 'candidate')).toEqual(e.json); + f.unmount(); + }); + } + + for (const e of examples('client-request-frame')) { + test(`requestFrame x${sequence.timing.request_frame_count}: ${e.name}`, async () => { + const f = await fixture(); + f.mount(SESSION); + f.sockets[0].open(); + await tick(); + f.sockets[0].config(); + await tick(); + f.peers[0].channels[0].onopen(); + f.fireTimers(); + const frames = f.sockets[0].sent.filter((m) => m.type === 'requestFrame'); + expect(frames).toHaveLength(sequence.timing.request_frame_count); + for (const frame of frames) expect(frame).toEqual(e.json); + f.unmount(); + }); + } + + for (const e of examples('client-open-url')) { + test(`openUrl: ${e.name}`, async () => { + const f = await fixture(); + f.mount(SESSION, encodeURIComponent(e.json.url)); + f.sockets[0].open(); + await tick(); + f.sockets[0].config(); + await tick(); + f.peers[0].channels[0].onopen(); + expect(f.sockets[0].sent.find((m) => m.type === 'openUrl')).toEqual(e.json); + f.unmount(); + }); + } + + for (const e of examples('client-keep-alive')) { + test(`keepAlive: ${e.name}`, async () => { + const f = await fixture(); + f.mount(SESSION); + f.sockets[0].open(); + await tick(); + f.fireTimers(); + expect(f.sockets[0].sent.find((m) => m.type === 'keepAlive')).toEqual(e.json); + f.unmount(); + }); + } +}); + +describe('signalling/server frames', () => { + for (const e of examples('server-answer')) { + test(`answer: ${e.name}`, async () => { + const f = await fixture(); + await f.negotiate(); + const answer = f.sockets[0].onmessage!(event(e.json)); + f.peers[0].remote.resolve(); + await answer; + expect(f.peers[0].remoteArgs).toEqual([{ type: 'answer', sdp: e.json.sdp }]); + f.unmount(); + }); + } + + for (const e of examples('server-candidate')) { + test(`candidate after answer: ${e.name}`, async () => { + const f = await fixture(); + await f.negotiate(); + const answer = f.sockets[0].onmessage!(event({ type: 'answer', sdp: 'v=0' })); + f.peers[0].remote.resolve(); + await answer; + const added = f.sockets[0].onmessage!(event(e.json)); + f.peers[0].ice.resolve(); + await added; + const { type: _type, ...candidate } = e.json; + expect(f.peers[0].iceArgs).toEqual([candidate]); + f.unmount(); + }); + test(`candidate before answer is buffered then applied in order: ${e.name}`, async () => { + const f = await fixture(); + await f.negotiate(); + await f.sockets[0].onmessage!(event(e.json)); + expect(f.peers[0].iceArgs).toEqual([]); + const answer = f.sockets[0].onmessage!(event({ type: 'answer', sdp: 'v=0' })); + f.peers[0].remote.resolve(); + await tick(); + f.peers[0].ice.resolve(); + await answer; + const { type: _type, ...candidate } = e.json; + expect(f.peers[0].iceArgs).toEqual([candidate]); + f.unmount(); + }); + } + + for (const e of examples('server-rtc-configuration')) { + test(`rtcConfiguration refresh: ${e.name}`, async () => { + const f = await fixture(); + await f.negotiate(); + const iceServers = e.json.rtcConfiguration?.iceServers; + const refresh = f.sockets[0].onmessage!(event(e.json)); + if (iceServers) { + f.peers[0].offer.resolve({ sdp: 'restart' }); + await tick(); + f.peers[0].local.resolve(); + } + await refresh; + if (iceServers) { + expect(f.peers[0].configArgs).toEqual([{ iceServers }]); + expect(f.sockets[0].sent.some((m) => m.type === 'offer' && m.sdp === 'restart')).toBe(true); + } else { + expect(f.peers[0].configArgs).toEqual([]); + expect(f.peers[0].localCalls).toBe(0); + } + f.unmount(); + }); + } + + for (const e of examples('server-screenshot')) { + test(`screenshot: ${e.name}`, async () => { + const f = await fixture(); + const result = f.mount(SESSION) as any; + const received: unknown[] = []; + result.pendingScreenshotResolversRef.current.set(e.json.id, (v: unknown) => received.push(v)); + f.sockets[0].open(); + await tick(); + f.sockets[0].config(); + await tick(); + await f.sockets[0].onmessage!(event(e.json)); + expect(received).toEqual([{ dataUri: e.json.dataUri }]); + f.unmount(); + }); + } + + for (const e of examples('server-screenshot-error')) { + test(`screenshotError: ${e.name}`, async () => { + const f = await fixture(); + const result = f.mount(SESSION) as any; + const received: unknown[] = []; + result.pendingScreenshotRejectersRef.current.set(e.json.id, (v: unknown) => received.push(v)); + f.sockets[0].open(); + await tick(); + f.sockets[0].config(); + await tick(); + await f.sockets[0].onmessage!(event(e.json)); + expect((received[0] as Error).message).toBe(e.json.message); + f.unmount(); + }); + } +}); diff --git a/src/hooks/use-scrcpy-input.ts b/src/hooks/use-scrcpy-input.ts index b37274b..b9ffb80 100644 --- a/src/hooks/use-scrcpy-input.ts +++ b/src/hooks/use-scrcpy-input.ts @@ -5,15 +5,17 @@ import type React from 'react'; import { useEffect, useRef } from 'react'; -import { AMOTION_EVENT, ANDROID_KEYS, codeMap } from '../constants'; import { - createInjectKeycodeMessage, - createInjectMouseHoverMessage, - createInjectScrollEventMessage, - createInjectTextMessage, - createSetClipboardMessage, - createTouchControlMessage, -} from '../webrtc-messages'; + createKeyRouter, + createPointerRouter, + mapClientPoint, + pasteMessages, + routeScroll, + wheelToTicks, + type PointerInput, + type RoutedMessage, + type VideoPoint, +} from '../lib/input-routing'; declare global { interface Window { @@ -35,93 +37,25 @@ const debugWarn = (...args: any[]) => { }; /** - * Map a client-coordinate point onto the video's pixel space, accounting for - * the letterboxing object-fit:contain introduces. Returns null when the point - * falls outside the rendered video area. + * Read the video element's current bounding rect and intrinsic dimensions and + * map a client point into video pixels. Returns null when the video element + * isn't ready; `point` is null when the point is outside the letterboxed area. */ -function computeVideoCoords( - clientX: number, - clientY: number, - rect: DOMRect, - videoWidth: number, - videoHeight: number, -): { videoX: number; videoY: number } | null { - const displayWidth = rect.width; - const displayHeight = rect.height; - const videoAspectRatio = videoWidth / videoHeight; - const containerAspectRatio = displayWidth / displayHeight; - let actualWidth = displayWidth; - let actualHeight = displayHeight; - if (videoAspectRatio > containerAspectRatio) { - actualHeight = displayWidth / videoAspectRatio; - } else { - actualWidth = displayHeight * videoAspectRatio; - } - const offsetX = (displayWidth - actualWidth) / 2; - const offsetY = (displayHeight - actualHeight) / 2; - const relativeX = clientX - rect.left - offsetX; - const relativeY = clientY - rect.top - offsetY; - if (relativeX < 0 || relativeX > actualWidth || relativeY < 0 || relativeY > actualHeight) { - return null; - } - return { - videoX: Math.max(0, Math.min(videoWidth, (relativeX / actualWidth) * videoWidth)), - videoY: Math.max(0, Math.min(videoHeight, (relativeY / actualHeight) * videoHeight)), - }; -} - -/** - * Read the video element's current bounding rect and intrinsic dimensions, - * then delegate to `computeVideoCoords`. Collapses the repeated boilerplate - * (getBoundingClientRect + videoWidth/videoHeight guard + coord mapping) - * that appears in every input-handler path. - * - * Returns null when the video element isn't ready or the point is outside - * the letterboxed area. - */ -function getVideoCoords( +function getVideoPoint( video: HTMLVideoElement, clientX: number, clientY: number, -): { videoX: number; videoY: number; videoWidth: number; videoHeight: number } | null { +): { point: VideoPoint | null; videoWidth: number; videoHeight: number } | null { const { videoWidth, videoHeight } = video; if (!videoWidth || !videoHeight) return null; - const rect = video.getBoundingClientRect(); - const coords = computeVideoCoords(clientX, clientY, rect, videoWidth, videoHeight); - if (!coords) return null; - return { ...coords, videoWidth, videoHeight }; -} - -function getAndroidKeycodeAndMeta( - event: React.KeyboardEvent, -): { keycode: number; metaState: number } | null { - const code = event.code; - const keycode = codeMap[code]; - - if (!keycode) { - // Use the wrapper for conditional warning - debugWarn(`Unknown event.code: ${code}, key: ${event.key}`); - return null; - } - - let metaState = ANDROID_KEYS.META_NONE; - const isLetter = code >= 'KeyA' && code <= 'KeyZ'; - const isCapsLock = event.getModifierState('CapsLock'); - const isShiftPressed = event.shiftKey; - - // Determine effective shift state - let effectiveShift = isShiftPressed; - if (isLetter) { - effectiveShift = isShiftPressed !== isCapsLock; // Logical XOR for booleans - } - - // Apply meta states - if (effectiveShift) metaState |= ANDROID_KEYS.META_SHIFT_ON; - if (event.ctrlKey) metaState |= ANDROID_KEYS.META_CTRL_ON; - if (event.altKey) metaState |= ANDROID_KEYS.META_ALT_ON; - if (event.metaKey) metaState |= ANDROID_KEYS.META_META_ON; // Command on Mac, Windows key on Win - - return { keycode, metaState }; + const point = mapClientPoint( + video.getBoundingClientRect(), + videoWidth, + videoHeight, + clientX, + clientY, + ); + return { point, videoWidth, videoHeight }; } interface UseScrcpyInputOptions { @@ -136,15 +70,17 @@ interface UseScrcpyInputResult { handleKeyboard: (event: React.KeyboardEvent) => void; } +/** + * DOM wiring only: every routing decision lives in `lib/input-routing`. + */ export function useScrcpyInput({ containerRef, videoRef, dataChannelRef, hoverChannelRef, }: UseScrcpyInputOptions): UseScrcpyInputResult { - // Map to track active pointers (mouse or touch) and their last known position inside the video - // Key: pointerId (-1 for mouse, touch.identifier for touch), Value: { x: number, y: number } - const activePointers = useRef>(new Map()); + const pointerRouter = useRef(createPointerRouter()); + const keyRouter = useRef(createKeyRouter()); const sendBinaryControlMessage = (data: ArrayBuffer) => { if (!dataChannelRef.current || dataChannelRef.current.readyState !== 'open') { @@ -164,6 +100,13 @@ export function useScrcpyInput({ hoverChannelRef.current.send(data); }; + const send = (messages: RoutedMessage[]) => { + for (const { channel, data } of messages) { + if (channel === 'hover') sendHoverMessage(data); + else sendBinaryControlMessage(data); + } + }; + // Unified handler for both mouse and touch interactions const handleInteraction = (event: React.MouseEvent | React.TouchEvent) => { event.preventDefault(); @@ -178,162 +121,75 @@ export function useScrcpyInput({ } const video = videoRef.current; - const videoWidth = video.videoWidth; - const videoHeight = video.videoHeight; - if (!videoWidth || !videoHeight) return; // Video dimensions not ready - - // Helper to process a single pointer event (either mouse or a single touch point) - const processPointer = ( - pointerId: number, - clientX: number, - clientY: number, - eventType: 'down' | 'move' | 'up' | 'cancel', - ) => { - const coords = getVideoCoords(video, clientX, clientY); - const isInside = coords !== null; - const videoX = coords?.videoX ?? 0; - const videoY = coords?.videoY ?? 0; - - let action: number | null = null; - let positionToSend: { x: number; y: number } | null = null; - const pressure = 1.0; // Default pressure - const buttons = AMOTION_EVENT.BUTTON_PRIMARY; // Assume primary button - - switch (eventType) { - case 'down': - if (isInside) { - action = AMOTION_EVENT.ACTION_DOWN; - positionToSend = { x: videoX, y: videoY }; - activePointers.current.set(pointerId, positionToSend); - if (pointerId === -1) { - // Focus on mouse down - videoRef.current?.focus(); - } - } else { - // If the initial down event is outside, ignore it for this pointer - activePointers.current.delete(pointerId); - } - break; - - case 'move': - if (activePointers.current.has(pointerId)) { - if (isInside) { - action = AMOTION_EVENT.ACTION_MOVE; - positionToSend = { x: videoX, y: videoY }; - // Update the last known position for this active pointer - activePointers.current.set(pointerId, positionToSend); - } else { - // Moved outside while active - do nothing, UP/CANCEL will use last known pos - } - } - break; + if (!video.videoWidth || !video.videoHeight) return; // Video dimensions not ready - case 'up': - case 'cancel': // Treat cancel like up, but use ACTION_CANCEL - if (activePointers.current.has(pointerId)) { - action = eventType === 'cancel' ? AMOTION_EVENT.ACTION_CANCEL : AMOTION_EVENT.ACTION_UP; - // IMPORTANT: Send the UP/CANCEL at the *last known position* inside the video - positionToSend = activePointers.current.get(pointerId)!; - activePointers.current.delete(pointerId); // Remove pointer as it's no longer active - } - break; - } - - // Send message if action and position determined - if (action !== null && positionToSend !== null) { - const message = createTouchControlMessage( - action, - pointerId, - videoWidth, - videoHeight, - positionToSend.x, - positionToSend.y, - pressure, - buttons, - buttons, - ); - if (message) { - sendBinaryControlMessage(message); - } - } else if (eventType === 'up' || eventType === 'cancel') { - // Clean up map just in case if 'down' was outside and 'up'/'cancel' is triggered - activePointers.current.delete(pointerId); + const route = (input: Omit, clientX: number, clientY: number) => { + const mapped = getVideoPoint(video, clientX, clientY); + if (!mapped) return; + if (input.mouse && input.type === 'down' && input.button === 0 && mapped.point) { + video.focus(); } + send( + pointerRouter.current.route( + { ...input, point: mapped.point }, + mapped.videoWidth, + mapped.videoHeight, + ), + ); }; - // --- Event Type Handling --- - if ('touches' in event) { - // Touch Events - const touches = event.changedTouches; // Use changedTouches for start/end/cancel - let eventType: 'down' | 'move' | 'up' | 'cancel'; - + // Touch Events: changedTouches carries the points of start/end/cancel. + let type: PointerInput['type']; switch (event.type) { case 'touchstart': - eventType = 'down'; + type = 'down'; break; case 'touchmove': - eventType = 'move'; + type = 'move'; break; case 'touchend': - eventType = 'up'; + type = 'up'; break; case 'touchcancel': - eventType = 'cancel'; + type = 'cancel'; break; default: - return; // Should not happen - } - - for (let i = 0; i < touches.length; i++) { - const touch = touches[i]; - processPointer(touch.identifier, touch.clientX, touch.clientY, eventType); - } - } else { - // Mouse Events - const pointerId = -1; // Use -1 for mouse pointer - let eventType: 'down' | 'move' | 'up' | 'cancel' | null = null; - - switch (event.type) { - case 'mousedown': - if (event.button === 0) eventType = 'down'; // Only primary button - break; - case 'mousemove': - // Only process move if primary button is down (check map) - if (activePointers.current.has(pointerId)) { - eventType = 'move'; - } - break; - case 'mouseup': - if (event.button === 0) eventType = 'up'; // Only primary button - break; - case 'mouseleave': - // Treat leave like up only if button was down - if (activePointers.current.has(pointerId)) { - eventType = 'up'; - } - break; - } - - if (eventType) { - processPointer(pointerId, event.clientX, event.clientY, eventType); - } else if (event.type === 'mousemove') { - // No active touch — emit a hover/cursor message instead. - const coords = getVideoCoords(video, event.clientX, event.clientY); - if (!coords) { return; - } - sendHoverMessage( - createInjectMouseHoverMessage( - videoWidth, - videoHeight, - coords.videoX, - coords.videoY, - event.buttons, - ), + } + for (let i = 0; i < event.changedTouches.length; i++) { + const touch = event.changedTouches[i]; + route( + { type, id: touch.identifier, mouse: false, button: 0, buttons: 0 }, + touch.clientX, + touch.clientY, ); } + return; } + + // Mouse Events + let type: PointerInput['type']; + let button = event.button; + switch (event.type) { + case 'mousedown': + type = 'down'; + break; + case 'mousemove': + type = 'move'; + break; + case 'mouseup': + type = 'up'; + break; + case 'mouseleave': + // Leaving the video releases a held gesture like a primary release. + type = 'up'; + button = 0; + break; + default: + return; + } + route({ type, id: -1, mouse: true, button, buttons: event.buttons }, event.clientX, event.clientY); }; // Native wheel listener — attached with passive:false in an effect so we @@ -355,45 +211,10 @@ export function useScrcpyInput({ return; } - const video = videoRef.current; - const coords = getVideoCoords(video, event.clientX, event.clientY); - if (!coords) return; - const { videoX, videoY, videoWidth, videoHeight } = coords; - - // Browser deltaX/deltaY → wheel ticks (1 tick ≈ one notch). - // deltaMode 0 (pixel) is the common case: Chrome/Edge ~100px per notch, - // Firefox uses smaller values. /100 is the de-facto convention used by - // ya-webadb/Tango and works well for both mice and trackpads. - let dx = event.deltaX; - let dy = event.deltaY; - switch (event.deltaMode) { - case 0: // DOM_DELTA_PIXEL - dx /= 100; - dy /= 100; - break; - case 1: // DOM_DELTA_LINE — already roughly in tick units - break; - case 2: // DOM_DELTA_PAGE - dx *= 3; - dy *= 3; - break; - } - - // scrcpy/Android: positive vscroll = scroll up, hscroll = scroll left. - // Browsers: positive deltaY = content scrolls down. Invert. - const hscrollTicks = -dx; - const vscrollTicks = -dy; - - const message = createInjectScrollEventMessage( - videoWidth, - videoHeight, - videoX, - videoY, - hscrollTicks, - vscrollTicks, - event.buttons, - ); - sendBinaryControlMessage(message); + const mapped = getVideoPoint(videoRef.current, event.clientX, event.clientY); + if (!mapped) return; + const { h, v } = wheelToTicks(event.deltaMode, event.deltaX, event.deltaY); + send(routeScroll(mapped.videoWidth, mapped.videoHeight, mapped.point, h, v, event.buttons)); }; container.addEventListener('wheel', handleWheel, { passive: false }); @@ -428,95 +249,28 @@ export function useScrcpyInput({ return; } - // Handle special shortcuts first (Paste, Menu) - if (event.type === 'keydown') { - // Paste (Cmd+V / Ctrl+V) - if (event.key.toLowerCase() === 'v' && (event.metaKey || event.ctrlKey)) { - debugLog('Paste shortcut detected'); - navigator.clipboard - .readText() - .then((text) => { - if (text) { - debugLog( - 'Pasting text via SET_CLIPBOARD:', - text.substring(0, 20) + (text.length > 20 ? '...' : ''), - ); - const message = createSetClipboardMessage(text, true); // paste=true - sendBinaryControlMessage(message); - } - }) - .catch((err) => { - console.error('Failed to read clipboard contents: ', err); - }); - return; // Don't process 'v' keycode further - } - - // Menu (Cmd+M / Ctrl+M) - Send down and up immediately - if (event.key.toLowerCase() === 'm' && (event.metaKey || event.ctrlKey)) { - debugLog('Menu shortcut detected'); - const messageDown = createInjectKeycodeMessage( - ANDROID_KEYS.ACTION_DOWN, - ANDROID_KEYS.MENU, - 0, - ANDROID_KEYS.META_NONE, // Modifiers are handled by the shortcut check, not passed down - ); - sendBinaryControlMessage(messageDown); - const messageUp = createInjectKeycodeMessage( - ANDROID_KEYS.ACTION_UP, - ANDROID_KEYS.MENU, - 0, - ANDROID_KEYS.META_NONE, - ); - sendBinaryControlMessage(messageUp); - return; // Don't process 'm' keycode further - } - } - - // Determine if this is a non-printable/control key that needs keycode injection - const isControlKey = - event.key === 'Backspace' || - event.key === 'Delete' || - event.key === 'Enter' || - event.key === 'Tab' || - event.key === 'Escape' || - event.key === 'Home' || - event.key === 'End' || - event.key === 'PageUp' || - event.key === 'PageDown' || - event.key === 'Insert' || - event.key.startsWith('Arrow') || - (event.key.startsWith('F') && event.key.length <= 3) || - event.key.startsWith('Shift') || - event.key.startsWith('Control') || - event.key.startsWith('Alt') || - event.key.startsWith('Meta') || - event.ctrlKey || - event.metaKey; + const routed = keyRouter.current.route({ + type: event.type === 'keydown' ? 'keydown' : 'keyup', + code: event.code, + key: event.key, + shift: event.shiftKey, + alt: event.altKey, + ctrl: event.ctrlKey, + meta: event.metaKey, // Command on Mac, Windows key on Win + capsLock: event.getModifierState('CapsLock'), + }); - if (isControlKey) { - // Use keycode injection for control/navigation keys - const keyInfo = getAndroidKeycodeAndMeta(event); - if (keyInfo) { - const { keycode, metaState } = keyInfo; - const action = event.type === 'keydown' ? ANDROID_KEYS.ACTION_DOWN : ANDROID_KEYS.ACTION_UP; - const message = createInjectKeycodeMessage(action, keycode, 0, metaState); - sendBinaryControlMessage(message); - } - } else if (event.type === 'keydown' && event.key.length === 1) { - // Use text injection for printable characters (supports Unicode, special chars, fast typing) - const message = createInjectTextMessage(event.key); - sendBinaryControlMessage(message); - } else if (event.type === 'keydown') { - // Fallback for other keydown events (Dead keys, etc.) - const keyInfo = getAndroidKeycodeAndMeta(event); - if (keyInfo) { - const { keycode, metaState } = keyInfo; - const message = createInjectKeycodeMessage(ANDROID_KEYS.ACTION_DOWN, keycode, 0, metaState); - sendBinaryControlMessage(message); - } + if (routed.kind === 'paste') { + debugLog('Paste shortcut detected'); + navigator.clipboard + .readText() + .then((text) => send(pasteMessages(text))) + .catch((err) => { + console.error('Failed to read clipboard contents: ', err); + }); + return; } - // keyup events for non-control keys are intentionally not sent - // since we use text injection which doesn't need up/down pairs + send(routed.messages); }; return { handleInteraction, handleKeyboard }; diff --git a/src/hooks/use-task-approval.test.ts b/src/hooks/use-task-approval.test.ts new file mode 100644 index 0000000..2c54700 --- /dev/null +++ b/src/hooks/use-task-approval.test.ts @@ -0,0 +1,82 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, test } from 'bun:test'; +import type { UseTaskApprovalOptions } from './use-task-approval'; +import { runHook } from './test-hook-runner'; + +const tick = async () => { for (let i = 0; i < 8; i++) await Promise.resolve(); }; + +async function setup(options: Partial) { + const timers = new Map void; ms: number }>(); + let nextTimer = 0; + const setTimer = (fn: () => void, ms: number) => { timers.set(++nextTimer, { fn, ms }); return nextTimer; }; + const clearTimer = (id: number) => { timers.delete(id); }; + const runner = await runHook<{ useTaskApproval: (o: UseTaskApprovalOptions) => unknown }>( + import.meta.dir + '/use-task-approval.ts', { setTimeout: setTimer, clearTimeout: clearTimer }, + ); + const errors: unknown[] = []; + let fetches = 0; + runner.beginRender(); + runner.module.exports.useTaskApproval({ + taskId: 't1', + fetchApproval: async () => { fetches++; return null; }, + decide: async () => {}, + onError: (e) => errors.push(e), + ...options, + }); + runner.flushEffects(); + await tick(); + return { + errors, timers, + get fetches() { return fetches; }, + // Runs the pending poll timer, like the clock reaching it. + async fire() { const [id, t] = [...timers][0]; timers.delete(id); t.fn(); await tick(); }, + unmount: runner.unmount, + }; +} + +const failing = () => { throw new Error('stream down'); }; + +describe('subscribe failure', () => { + test('is reported once and polling starts at 3 s', async () => { + const f = await setup({ subscribe: failing }); + expect(f.errors).toHaveLength(1); + expect((f.errors[0] as Error).message).toBe('stream down'); + expect([...f.timers.values()].map((t) => t.ms)).toEqual([3000]); + await f.fire(); + expect(f.fetches).toBe(2); + expect([...f.timers.values()].map((t) => t.ms)).toEqual([3000]); + expect(f.errors).toHaveLength(1); + f.unmount(); + }); + + test('polls at the given interval', async () => { + const f = await setup({ subscribe: failing, pollIntervalMs: 500 }); + expect([...f.timers.values()].map((t) => t.ms)).toEqual([500]); + f.unmount(); + }); + + test('polls at 3 s even when 0 was given, since 0 only means "no polling" while subscribe works', async () => { + const f = await setup({ subscribe: failing, pollIntervalMs: 0 }); + expect([...f.timers.values()].map((t) => t.ms)).toEqual([3000]); + f.unmount(); + }); +}); + +describe('working subscribe', () => { + test('does not poll by default or with an explicit 0', async () => { + for (const pollIntervalMs of [undefined, 0]) { + const f = await setup({ subscribe: () => () => {}, pollIntervalMs }); + expect(f.timers.size).toBe(0); + expect(f.errors).toEqual([]); + f.unmount(); + } + }); + + test('without subscribe the default is 3 s', async () => { + const f = await setup({}); + expect([...f.timers.values()].map((t) => t.ms)).toEqual([3000]); + f.unmount(); + }); +}); diff --git a/src/hooks/use-task-approval.ts b/src/hooks/use-task-approval.ts index 8dd1442..492ecf6 100644 --- a/src/hooks/use-task-approval.ts +++ b/src/hooks/use-task-approval.ts @@ -13,7 +13,7 @@ export interface UseTaskApprovalOptions { decide: (input: { taskId: string; approvalId: string; decision: ApprovalDecision }) => Promise; /** Optional push source (e.g. SSE fed by your webhook handler). Call onChange when an approval event for this task arrives; return an unsubscribe. */ subscribe?: (taskId: string, onChange: () => void) => () => void; - /** Poll interval while enabled. Default 0 (off) when `subscribe` is given, else 3000. */ + /** Poll interval while enabled. Default 0 (off) when `subscribe` is given, else 3000. If `subscribe` throws, the error goes to `onError` and polling runs at this interval (3000 when unset or 0). */ pollIntervalMs?: number; enabled?: boolean; onError?: (error: unknown) => void; @@ -35,6 +35,8 @@ export interface UseTaskApprovalResult { refetch: () => void; } +const DEFAULT_POLL_INTERVAL_MS = 3000; + /** * Loads a task's pending approval through your backend and sends the decision * back through it, so the API key never reaches the browser. Events (webhook → @@ -84,7 +86,7 @@ export function useTaskApproval({ const reloadRef = useRef<() => void>(() => {}); const hasSubscribe = !!subscribe; - const interval = pollIntervalMs ?? (hasSubscribe ? 0 : 3000); + const interval = pollIntervalMs ?? (hasSubscribe ? 0 : DEFAULT_POLL_INTERVAL_MS); useEffect(() => { // A different task starts with a clean decide state. @@ -105,6 +107,8 @@ export function useTaskApproval({ let cancelled = false; let pollTimer: ReturnType | undefined; + // Switches to the plain polling default when `subscribe` throws. + let pollMs = interval; // An older overlapping fetch never overwrites a newer one. let latest = 0; @@ -124,7 +128,7 @@ export function useTaskApproval({ } finally { if (isCurrent()) { setIsLoading(false); - if (interval > 0) pollTimer = setTimeout(load, interval); + if (pollMs > 0) pollTimer = setTimeout(load, pollMs); } } }; @@ -132,9 +136,17 @@ export function useTaskApproval({ reloadRef.current = () => void load(); setIsLoading(true); void load(); - const unsubscribe = subscribeRef.current?.(taskId, () => { - if (!cancelled) void load(); - }); + let unsubscribe: (() => void) | undefined; + try { + unsubscribe = subscribeRef.current?.(taskId, () => { + if (!cancelled) void load(); + }); + } catch (err) { + // Without a working push source the approval would never refresh: report + // it and poll as if no `subscribe` was given. + onErrorRef.current?.(err); + pollMs = pollIntervalMs || DEFAULT_POLL_INTERVAL_MS; + } return () => { cancelled = true; diff --git a/src/hooks/use-webrtc-connection.test.ts b/src/hooks/use-webrtc-connection.test.ts index 1e2d5d2..f491dc3 100644 --- a/src/hooks/use-webrtc-connection.test.ts +++ b/src/hooks/use-webrtc-connection.test.ts @@ -2,110 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { expect, test } from 'bun:test'; -import { runHook } from './test-hook-runner'; - -const tick = async () => { for (let i = 0; i < 8; i++) await Promise.resolve(); }; -const event = (message: object) => ({ data: JSON.stringify(message) }); - -function deferred() { - let resolve!: (value: T) => void; - let reject!: (reason: Error) => void; - const promise = new Promise((yes, no) => { resolve = yes; reject = no; }); - return { promise, resolve, reject }; -} - -async function fixture() { - const sockets: FakeSocket[] = []; - const peers: FakePeer[] = []; - const timers = new Map void>(); - let nextTimer = 0; - const setTimer = (fn: () => void) => { timers.set(++nextTimer, fn); return nextTimer; }; - const clearTimer = (id: number) => { timers.delete(id); }; - class FakeSocket { - static OPEN = 1; - readyState = 0; - sent: Record[] = []; - listeners = new Set<(event: { data: string }) => void>(); - onopen: (() => void) | null = null; - onclose: (() => void) | null = null; - onerror: (() => void) | null = null; - onmessage: ((event: { data: string }) => Promise) | null = null; - constructor() { sockets.push(this); } - open() { this.readyState = 1; this.onopen?.(); } - config() { for (const fn of this.listeners) fn(event({ type: 'rtcConfiguration', rtcConfiguration: {} })); } - addEventListener(_name: string, fn: (event: { data: string }) => void) { this.listeners.add(fn); } - removeEventListener(_name: string, fn: (event: { data: string }) => void) { this.listeners.delete(fn); } - send(data: string) { this.sent.push(JSON.parse(data)); } - close() { this.readyState = 3; this.onclose?.(); } - } - class FakeChannel { - closed = false; - onopen = () => {}; - onclose = () => {}; - onerror = () => {}; - close() { this.closed = true; this.onclose(); } - } - class FakePeer { - closed = false; - connectionState = 'new'; - channels: FakeChannel[] = []; - offer = deferred<{ sdp: string }>(); - local = deferred(); - remote = deferred(); - ice = deferred(); - localCalls = 0; - iceCalls = 0; - onconnectionstatechange: (() => void) | null = null; - oniceconnectionstatechange = () => {}; - onicecandidate = (_event: object) => {}; - ontrack = (_event: object) => {}; - constructor() { peers.push(this); } - addTransceiver() { return { receiver: {} }; } - createDataChannel() { const c = new FakeChannel(); this.channels.push(c); return c; } - createOffer() { return this.offer.promise; } - setLocalDescription() { this.localCalls++; return this.local.promise; } - setRemoteDescription() { return this.remote.promise; } - addIceCandidate() { this.iceCalls++; return this.ice.promise; } - setConfiguration() {} - close() { this.closed = true; this.onconnectionstatechange?.(); } - } - const stateWrites: boolean[] = []; - const states: boolean[] = []; - const failures: boolean[] = []; - const bindings: (FakePeer | null)[] = []; - const video = { current: { srcObject: null, muted: true } }; - const context = { - window: { setTimeout: setTimer, clearTimeout: clearTimer, setInterval: setTimer, clearInterval: clearTimer }, - document: { hidden: false, addEventListener() {}, removeEventListener() {} }, - WebSocket: FakeSocket, RTCPeerConnection: FakePeer, - RTCRtpReceiver: { getCapabilities: () => null }, - RTCSessionDescription: class { constructor(value: object) { Object.assign(this, value); } }, - RTCIceCandidate: class { constructor(value: object) { Object.assign(this, value); } }, - setTimeout: setTimer, clearTimeout: clearTimer, - console, stateWrites, - }; - const runner = await runHook<{ useWebRtcConnection: (options: object) => { wsRef: { current: FakeSocket | null } } }>( - import.meta.dir + '/use-webrtc-connection.ts', context, { compareEffectDeps: false }, - ); - const mount = (id = 'a', openUrl?: string) => { - runner.unmount(); - runner.beginRender(); - const result = runner.module.exports.useWebRtcConnection({ - url: 'wss://example.invalid/' + id, sessionId: id, videoRef: video, openUrl, - onConnectionStateChange: (state: boolean) => states.push(state), - onConnectionFailed: () => failures.push(true), - onPeerConnectionChange: (pc: FakePeer | null) => bindings.push(pc), - }); - runner.flushEffects(); - return result; - }; - return { - sockets, peers, timers, states, failures, bindings, stateWrites, video, mount, - unmount: runner.unmount, - fireTimers() { const tasks = [...timers.values()]; timers.clear(); tasks.forEach(fn => fn()); }, - async negotiate(openUrl?: string) { mount('a', openUrl); sockets[0].open(); await tick(); sockets[0].config(); await tick(); }, - }; -} +import { deferred, event, fixture, tick } from './webrtc-test-fixture'; for (const end of ['unmount', 'switch'] as const) { for (const boundary of ['open', 'config', 'offer', 'local'] as const) { diff --git a/src/hooks/webrtc-test-fixture.ts b/src/hooks/webrtc-test-fixture.ts new file mode 100644 index 0000000..b7dae59 --- /dev/null +++ b/src/hooks/webrtc-test-fixture.ts @@ -0,0 +1,110 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +import { runHook } from './test-hook-runner'; + +export const tick = async () => { for (let i = 0; i < 8; i++) await Promise.resolve(); }; +export const event = (message: object) => ({ data: JSON.stringify(message) }); + +export function deferred() { + let resolve!: (value: T) => void; + let reject!: (reason: Error) => void; + const promise = new Promise((yes, no) => { resolve = yes; reject = no; }); + return { promise, resolve, reject }; +} + +export async function fixture() { + const sockets: FakeSocket[] = []; + const peers: FakePeer[] = []; + const timers = new Map void>(); + let nextTimer = 0; + const setTimer = (fn: () => void) => { timers.set(++nextTimer, fn); return nextTimer; }; + const clearTimer = (id: number) => { timers.delete(id); }; + class FakeSocket { + static OPEN = 1; + readyState = 0; + sent: Record[] = []; + listeners = new Set<(event: { data: string }) => void>(); + onopen: (() => void) | null = null; + onclose: (() => void) | null = null; + onerror: (() => void) | null = null; + onmessage: ((event: { data: string }) => Promise) | null = null; + constructor() { sockets.push(this); } + open() { this.readyState = 1; this.onopen?.(); } + config() { for (const fn of this.listeners) fn(event({ type: 'rtcConfiguration', rtcConfiguration: {} })); } + addEventListener(_name: string, fn: (event: { data: string }) => void) { this.listeners.add(fn); } + removeEventListener(_name: string, fn: (event: { data: string }) => void) { this.listeners.delete(fn); } + send(data: string) { this.sent.push(JSON.parse(data)); } + close() { this.readyState = 3; this.onclose?.(); } + } + class FakeChannel { + closed = false; + onopen = () => {}; + onclose = () => {}; + onerror = () => {}; + close() { this.closed = true; this.onclose(); } + } + class FakePeer { + closed = false; + connectionState = 'new'; + channels: FakeChannel[] = []; + offer = deferred<{ sdp: string }>(); + local = deferred(); + remote = deferred(); + ice = deferred(); + localCalls = 0; + iceCalls = 0; + remoteArgs: Record[] = []; + iceArgs: Record[] = []; + configArgs: Record[] = []; + onconnectionstatechange: (() => void) | null = null; + oniceconnectionstatechange = () => {}; + onicecandidate = (_event: object) => {}; + ontrack = (_event: object) => {}; + constructor() { peers.push(this); } + addTransceiver() { return { receiver: {} }; } + createDataChannel() { const c = new FakeChannel(); this.channels.push(c); return c; } + createOffer() { return this.offer.promise; } + setLocalDescription() { this.localCalls++; return this.local.promise; } + setRemoteDescription(arg: Record) { this.remoteArgs.push(arg); return this.remote.promise; } + addIceCandidate(arg: Record) { this.iceArgs.push(arg); this.iceCalls++; return this.ice.promise; } + setConfiguration(arg: Record) { this.configArgs.push(arg); } + close() { this.closed = true; this.onconnectionstatechange?.(); } + } + const stateWrites: boolean[] = []; + const states: boolean[] = []; + const failures: boolean[] = []; + const bindings: (FakePeer | null)[] = []; + const video = { current: { srcObject: null, muted: true } }; + const context = { + window: { setTimeout: setTimer, clearTimeout: clearTimer, setInterval: setTimer, clearInterval: clearTimer }, + document: { hidden: false, addEventListener() {}, removeEventListener() {} }, + WebSocket: FakeSocket, RTCPeerConnection: FakePeer, + RTCRtpReceiver: { getCapabilities: () => null }, + RTCSessionDescription: class { constructor(value: object) { Object.assign(this, value); } }, + RTCIceCandidate: class { constructor(value: object) { Object.assign(this, value); } }, + setTimeout: setTimer, clearTimeout: clearTimer, + console, stateWrites, + }; + const runner = await runHook<{ useWebRtcConnection: (options: object) => { wsRef: { current: FakeSocket | null } } }>( + import.meta.dir + '/use-webrtc-connection.ts', context, { compareEffectDeps: false }, + ); + const mount = (id = 'a', openUrl?: string) => { + runner.unmount(); + runner.beginRender(); + const result = runner.module.exports.useWebRtcConnection({ + url: 'wss://example.invalid/' + id, sessionId: id, videoRef: video, openUrl, + onConnectionStateChange: (state: boolean) => states.push(state), + onConnectionFailed: () => failures.push(true), + onPeerConnectionChange: (pc: FakePeer | null) => bindings.push(pc), + }); + runner.flushEffects(); + return result; + }; + return { + sockets, peers, timers, states, failures, bindings, stateWrites, video, mount, + unmount: runner.unmount, + fireTimers() { const tasks = [...timers.values()]; timers.clear(); tasks.forEach(fn => fn()); }, + async negotiate(openUrl?: string) { mount('a', openUrl); sockets[0].open(); await tick(); sockets[0].config(); await tick(); }, + }; +} diff --git a/src/lib/input-routing.ts b/src/lib/input-routing.ts new file mode 100644 index 0000000..d65bf20 --- /dev/null +++ b/src/lib/input-routing.ts @@ -0,0 +1,345 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +/** + * Pure input routing for the device stream: browser input facts in, wire + * messages out. No DOM access, so the decisions are table-testable against the + * shared conformance vectors; `use-scrcpy-input` only translates DOM events. + */ + +import { AMOTION_EVENT, ANDROID_KEYS, codeMap } from '../constants'; +import { + createInjectKeycodeMessage, + createInjectMouseHoverMessage, + createInjectScrollEventMessage, + createInjectTextMessage, + createSetClipboardMessage, + createTouchControlMessage, +} from '../webrtc-messages'; + +export interface RoutedMessage { + /** `control` is the ordered reliable channel, `hover` the lossy hover channel. */ + channel: 'control' | 'hover'; + data: ArrayBuffer; +} + +export interface VideoPoint { + x: number; + y: number; +} + +// ---------------------------------------------------------------- geometry + +export interface ViewRect { + left: number; + top: number; + width: number; + height: number; +} + +/** + * Map a client-coordinate point onto the video's pixel space, accounting for + * the letterboxing object-fit:contain introduces. Returns null when the point + * falls outside the rendered video area. + */ +export function mapClientPoint( + rect: ViewRect, + videoWidth: number, + videoHeight: number, + clientX: number, + clientY: number, +): VideoPoint | null { + const displayWidth = rect.width; + const displayHeight = rect.height; + if (displayWidth <= 0 || displayHeight <= 0 || videoWidth <= 0 || videoHeight <= 0) return null; + const videoAspectRatio = videoWidth / videoHeight; + const containerAspectRatio = displayWidth / displayHeight; + let actualWidth = displayWidth; + let actualHeight = displayHeight; + if (videoAspectRatio > containerAspectRatio) { + actualHeight = displayWidth / videoAspectRatio; + } else { + actualWidth = displayHeight * videoAspectRatio; + } + const offsetX = (displayWidth - actualWidth) / 2; + const offsetY = (displayHeight - actualHeight) / 2; + const relativeX = clientX - rect.left - offsetX; + const relativeY = clientY - rect.top - offsetY; + if (relativeX < 0 || relativeX > actualWidth || relativeY < 0 || relativeY > actualHeight) { + return null; + } + return { + x: Math.max(0, Math.min(videoWidth, (relativeX / actualWidth) * videoWidth)), + y: Math.max(0, Math.min(videoHeight, (relativeY / actualHeight) * videoHeight)), + }; +} + +// ---------------------------------------------------------------- keyboard + +export interface KeyInput { + type: 'keydown' | 'keyup'; + /** Physical key (`KeyboardEvent.code`). */ + code: string; + /** Produced key value (`KeyboardEvent.key`). */ + key: string; + shift: boolean; + alt: boolean; + ctrl: boolean; + meta: boolean; + capsLock: boolean; +} + +export type KeyRoute = + | { kind: 'messages'; messages: RoutedMessage[] } + /** Ctrl/Cmd+V: the caller reads the clipboard and sends `pasteMessages(text)`. */ + | { kind: 'paste' }; + +const control = (data: ArrayBuffer): RoutedMessage => ({ channel: 'control', data }); + +const CONTROL_KEYS = new Set([ + 'Backspace', + 'Delete', + 'Enter', + 'Tab', + 'Escape', + 'Home', + 'End', + 'PageUp', + 'PageDown', + 'Insert', +]); +const MODIFIER_PREFIXES = ['Shift', 'Control', 'Alt', 'Meta']; + +const graphemes = + typeof Intl !== 'undefined' && 'Segmenter' in Intl + ? new Intl.Segmenter(undefined, { granularity: 'grapheme' }) + : null; + +// A named key (`ContextMenu`, `Dead`) is more than one UTF-16 unit but is not text. +function isGraphemeText(key: string): boolean { + if (key.length < 2 || !graphemes || /\p{Cc}/u.test(key)) return false; + const iterator = graphemes.segment(key)[Symbol.iterator](); + iterator.next(); + return iterator.next().done === true; +} + +function isControlKey(e: KeyInput): boolean { + return ( + CONTROL_KEYS.has(e.key) || + e.key.startsWith('Arrow') || + (e.key.startsWith('F') && e.key.length <= 3) || + MODIFIER_PREFIXES.some((prefix) => e.key.startsWith(prefix)) || + e.ctrl || + e.meta + ); +} + +function metaState(e: KeyInput): number { + const isLetter = e.code >= 'KeyA' && e.code <= 'KeyZ'; + // CapsLock flips shift for letters only. + const shift = isLetter ? e.shift !== e.capsLock : e.shift; + let state = ANDROID_KEYS.META_NONE; + if (shift) state |= ANDROID_KEYS.META_SHIFT_ON; + if (e.ctrl) state |= ANDROID_KEYS.META_CTRL_ON; + if (e.alt) state |= ANDROID_KEYS.META_ALT_ON; + if (e.meta) state |= ANDROID_KEYS.META_META_ON; + return state; +} + +function keycodeMessage(action: number, keycode: number, meta: number): RoutedMessage { + return control(createInjectKeycodeMessage(action, keycode, 0, meta)); +} + +export function pasteMessages(clipboardText: string): RoutedMessage[] { + return clipboardText ? [control(createSetClipboardMessage(clipboardText, true))] : []; +} + +/** + * Keyboard routing with the pressed-key bookkeeping that keeps every keycode + * DOWN paired with exactly one UP. + */ +export function createKeyRouter() { + const pressed = new Set(); + + return { + route(e: KeyInput): KeyRoute { + const keycode = codeMap[e.code]; + + if (e.type === 'keyup') { + if (!pressed.delete(e.code) || !keycode) return { kind: 'messages', messages: [] }; + return { + kind: 'messages', + messages: [keycodeMessage(ANDROID_KEYS.ACTION_UP, keycode, metaState(e))], + }; + } + + if (e.ctrl || e.meta) { + const key = e.key.toLowerCase(); + if (key === 'v') return { kind: 'paste' }; + if (key === 'm') { + return { + kind: 'messages', + messages: [ + keycodeMessage(ANDROID_KEYS.ACTION_DOWN, ANDROID_KEYS.MENU, ANDROID_KEYS.META_NONE), + keycodeMessage(ANDROID_KEYS.ACTION_UP, ANDROID_KEYS.MENU, ANDROID_KEYS.META_NONE), + ], + }; + } + } + + // Printable characters go as text (Unicode, fast typing, no up/down pairs). + if (!isControlKey(e) && (e.key.length === 1 || isGraphemeText(e.key))) { + return { kind: 'messages', messages: [control(createInjectTextMessage(e.key))] }; + } + + if (!keycode) return { kind: 'messages', messages: [] }; + pressed.add(e.code); + return { + kind: 'messages', + messages: [keycodeMessage(ANDROID_KEYS.ACTION_DOWN, keycode, metaState(e))], + }; + }, + }; +} + +// ---------------------------------------------------------------- pointers + +export interface PointerInput { + type: 'down' | 'move' | 'up' | 'cancel'; + /** Touch identifier; ignored for the mouse. */ + id: number; + /** Position in video pixels, or null when outside the rendered video. */ + point: VideoPoint | null; + mouse: boolean; + /** Changed button: 0 primary, 1 middle, 2 secondary. */ + button: number; + /** Held-button mask, only used by hover. */ + buttons: number; +} + +export const MAX_TOUCH_SLOTS = 10; +export const MOUSE_POINTER_ID = -1; + +/** + * Touch and mouse gesture routing. Each touch gets the lowest free slot + * (0..9) for the length of its gesture; the mouse always uses id -1. + */ +export function createPointerRouter() { + const active = new Map(); + + return { + route(e: PointerInput, videoWidth: number, videoHeight: number): RoutedMessage[] { + if (!videoWidth || !videoHeight) return []; + if ((e.type === 'down' || e.type === 'up') && e.button !== 0) return []; + + const key = e.mouse ? 'mouse' : String(e.id); + let pointer = active.get(key); + let action: number; + + if (e.type === 'down') { + if (!e.point || pointer) return []; + let slot = MOUSE_POINTER_ID; + if (!e.mouse) { + const used = new Set([...active.values()].map((p) => p.slot)); + slot = 0; + while (used.has(slot)) slot++; + if (slot >= MAX_TOUCH_SLOTS) return []; + } + pointer = { slot, x: e.point.x, y: e.point.y }; + active.set(key, pointer); + action = AMOTION_EVENT.ACTION_DOWN; + } else if (e.type === 'move') { + if (!e.point) return []; + if (!pointer) { + // Hover: a mouse moving with no gesture in progress. + if (!e.mouse) return []; + return [ + { + channel: 'hover', + data: createInjectMouseHoverMessage( + videoWidth, + videoHeight, + e.point.x, + e.point.y, + e.buttons, + ), + }, + ]; + } + pointer.x = e.point.x; + pointer.y = e.point.y; + action = AMOTION_EVENT.ACTION_MOVE; + } else { + if (!pointer) return []; + // UP/CANCEL go out at the last position seen inside the video. + action = e.type === 'cancel' ? AMOTION_EVENT.ACTION_CANCEL : AMOTION_EVENT.ACTION_UP; + active.delete(key); + } + + return [ + control( + createTouchControlMessage( + action, + pointer.slot, + videoWidth, + videoHeight, + pointer.x, + pointer.y, + 1.0, + AMOTION_EVENT.BUTTON_PRIMARY, + AMOTION_EVENT.BUTTON_PRIMARY, + ), + ), + ]; + }, + /** Whether the mouse currently holds a gesture. */ + hasMouseGesture: () => active.has('mouse'), + }; +} + +// ------------------------------------------------------------------ scroll + +/** + * Browser wheel deltas → wheel ticks (1 tick ≈ one notch), with the sign + * flipped: Android scrolls up on positive v and left on positive h, browsers + * report positive deltaY when content moves down. + * + * Pixel mode uses /100 (Chrome ~100px per notch), the de-facto convention of + * ya-webadb/Tango; it suits mice and trackpads alike. + */ +export function wheelToTicks( + deltaMode: number, + deltaX: number, + deltaY: number, +): { h: number; v: number } { + let dx = deltaX; + let dy = deltaY; + switch (deltaMode) { + case 0: // DOM_DELTA_PIXEL + dx /= 100; + dy /= 100; + break; + case 2: // DOM_DELTA_PAGE + dx *= 3; + dy *= 3; + break; + // DOM_DELTA_LINE (1) is already roughly in tick units. + } + return { h: -dx, v: -dy }; +} + +export function routeScroll( + videoWidth: number, + videoHeight: number, + point: VideoPoint | null, + h: number, + v: number, + buttons: number, +): RoutedMessage[] { + if (!videoWidth || !videoHeight || !point) return []; + return [ + control( + createInjectScrollEventMessage(videoWidth, videoHeight, point.x, point.y, h, v, buttons), + ), + ]; +} From bec46c974d0d72de133bce40ab89e29a48bfb82d Mon Sep 17 00:00:00 2001 From: lutz-grex Date: Mon, 16 Nov 2026 19:48:14 +0100 Subject: [PATCH 2/2] fix(conformance): review fixes Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ci.yml | 4 +- README.md | 2 +- src/components/remote-control.tsx | 7 +- src/conformance/control.test.ts | 4 +- src/conformance/fixtures.ts | 16 +++- src/conformance/input.test.ts | 42 ++++++++-- src/conformance/reconnect.test.ts | 50 ++---------- src/conformance/signalling.test.ts | 102 ++++++++++++++++-------- src/hooks/test-hook-runner.ts | 3 + src/hooks/use-device-stream.test.ts | 3 +- src/hooks/use-scrcpy-input.test.ts | 74 +++++++++++++++++ src/hooks/use-scrcpy-input.ts | 23 ++---- src/hooks/use-task-approval.test.ts | 20 ++++- src/hooks/use-task-approval.ts | 5 +- src/hooks/use-webrtc-connection.test.ts | 5 +- src/hooks/webrtc-test-fixture.ts | 22 +++-- src/lib/input-routing.ts | 13 +-- src/lib/stream-reconnect.test.ts | 42 +--------- src/lib/test-clock.ts | 47 +++++++++++ src/webrtc-messages.ts | 4 + 20 files changed, 313 insertions(+), 175 deletions(-) create mode 100644 src/hooks/use-scrcpy-input.test.ts create mode 100644 src/lib/test-clock.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d9d22d..a31e19e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 - name: Setup Bun - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 with: bun-version: 1.4.4 diff --git a/README.md b/README.md index 2343284..561d812 100644 --- a/README.md +++ b/README.md @@ -333,7 +333,7 @@ bun test ## 🧬 Conformance -The control messages, signalling frames, reconnect policy and input routing are replayed against the shared [conformance fixtures](https://github.com/droidrun/mobilerun-sdk-conformance) that the native SDKs also pass. The vendored copy lives in `conformance/fixtures` (version in `conformance/VERSION`, currently v0.2.0) and runs with `bun test`. To move to another release, run `scripts/sync-conformance.sh TAG`. +The control messages, signalling frames, reconnect policy and input routing are replayed against the shared [conformance fixtures](https://github.com/droidrun/mobilerun-sdk-conformance) that the native SDKs also pass. The vendored copy lives in `conformance/fixtures` (release tag in `conformance/VERSION`) and runs with `bun test`. To move to another release, run `scripts/sync-conformance.sh TAG`. ## 📄 License diff --git a/src/components/remote-control.tsx b/src/components/remote-control.tsx index 4c5a9e3..329cee7 100644 --- a/src/components/remote-control.tsx +++ b/src/components/remote-control.tsx @@ -7,7 +7,7 @@ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'rea import { StreamStatusPill } from './stream-status-pill'; import { ANDROID_KEYS, codeMap } from '../constants'; -import { createInjectKeycodeMessage } from '../webrtc-messages'; +import { createInjectKeycodeMessage, createScreenshotRequest } from '../webrtc-messages'; import { useScrcpyInput } from '../hooks/use-scrcpy-input'; import { useWebRtcConnection } from '../hooks/use-webrtc-connection'; @@ -280,10 +280,7 @@ export const RemoteControl = forwardRef } const id = `ui-ss-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`; - const request = { - type: 'screenshot', // Matches the type expected by instance API - id: id, - }; + const request = createScreenshotRequest(id); pendingScreenshotResolversRef.current.set(id, resolve); pendingScreenshotRejectersRef.current.set(id, reject); diff --git a/src/conformance/control.test.ts b/src/conformance/control.test.ts index f93d771..9c6e257 100644 --- a/src/conformance/control.test.ts +++ b/src/conformance/control.test.ts @@ -11,7 +11,7 @@ import { createSetClipboardMessage, createTouchControlMessage, } from '../webrtc-messages'; -import { loadFixture, toHex } from './fixtures'; +import { expectAllFixturesUsed, loadFixture, toHex } from './fixtures'; interface Case { name: string; @@ -49,6 +49,8 @@ const builders: Record) => ArrayBuffer> = { 'set-clipboard': (a) => createSetClipboardMessage(a.text, a.paste), }; +expectAllFixturesUsed('control', Object.keys(builders)); + describe('constants', () => { const constants = loadFixture('constants.json'); test('control message types', () => expect({ ...CONTROL_MSG_TYPE }).toMatchObject(constants.control_msg_type)); diff --git a/src/conformance/fixtures.ts b/src/conformance/fixtures.ts index 21fb1cc..a1e0569 100644 --- a/src/conformance/fixtures.ts +++ b/src/conformance/fixtures.ts @@ -1,7 +1,7 @@ // Copyright 2026 Mobilerun // SPDX-License-Identifier: Apache-2.0 -import { readFileSync } from 'node:fs'; +import { readdirSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; const root = join(import.meta.dir, '..', '..', 'conformance', 'fixtures'); @@ -14,3 +14,17 @@ export function loadFixture(path: string): T { export function toHex(bytes: ArrayBuffer): string { return [...new Uint8Array(bytes)].map((b) => b.toString(16).padStart(2, '0')).join(''); } + +/** + * Fail when a fixture directory holds a file no test claims, so a file added by + * a later release cannot be silently ignored. + */ +export function expectAllFixturesUsed(dir: string, used: string[]): void { + const files = readdirSync(join(root, dir)) + .filter((f) => f.endsWith('.json')) + .map((f) => f.slice(0, -'.json'.length)) + .sort(); + if (JSON.stringify(files) !== JSON.stringify([...used].sort())) { + throw new Error(`fixtures in ${dir}/ changed: found [${files}], tests cover [${[...used].sort()}]`); + } +} diff --git a/src/conformance/input.test.ts b/src/conformance/input.test.ts index a46297f..2514492 100644 --- a/src/conformance/input.test.ts +++ b/src/conformance/input.test.ts @@ -8,10 +8,13 @@ import { mapClientPoint, pasteMessages, routeScroll, + wheelToTicks, type RoutedMessage, type VideoPoint, } from '../lib/input-routing'; -import { loadFixture, toHex } from './fixtures'; +import { expectAllFixturesUsed, loadFixture, toHex } from './fixtures'; + +expectAllFixturesUsed('input', ['geometry', 'ime', 'keys', 'pointers', 'scroll']); interface Expected { channel: 'control' | 'hover'; @@ -77,10 +80,11 @@ describe('input/pointers', () => { const router = createPointerRouter(); const out: RoutedMessage[] = []; for (const e of c.events) { - // The fixture positions are upright video pixels; the DOM layer maps client points the same way. - const inside = c.video_width > 0 && c.video_height > 0 && - e.x >= 0 && e.x <= c.video_width && e.y >= 0 && e.y <= c.video_height; - const point: VideoPoint | null = inside ? { x: e.x, y: e.y } : null; + // Fixture positions are upright video pixels: view == video, no letterbox. + const point = mapClientPoint( + { left: 0, top: 0, width: c.video_width, height: c.video_height }, + c.video_width, c.video_height, e.x, e.y, + ); out.push(...router.route({ ...e, point }, c.video_width, c.video_height)); } expect(wire(out)).toEqual(c.expect); @@ -136,13 +140,37 @@ interface ScrollCase { describe('input/scroll', () => { for (const c of loadFixture<{ cases: ScrollCase[] }>('input/scroll.json').cases) { test(c.name, () => { - const inside = c.x >= 0 && c.x <= c.video_width && c.y >= 0 && c.y <= c.video_height; - const point = inside ? { x: c.x, y: c.y } : null; + const point = mapClientPoint( + { left: 0, top: 0, width: c.video_width, height: c.video_height }, + c.video_width, c.video_height, c.x, c.y, + ); expect(wire(routeScroll(c.video_width, c.video_height, point, c.h, c.v, c.buttons))).toEqual(c.expect); }); } }); +// Browser wheel deltas → scroll bytes. Literal expectations: the vectors above start +// at abstract ticks, so sign and per-mode scaling are pinned here. +// Frame: type 3, x=540, y=1200, 1080x2400, hscroll i16, vscroll i16, buttons 0. +describe('wheel conversion', () => { + const frame = (h: string, v: string) => `031c020000b004000038046009${h}${v}00000000`; + const table: [string, number, number, number, string][] = [ + ['pixel: 100px down is one tick down', 0, 0, 100, frame('0000', '00f8')], + ['pixel: 100px up is one tick up', 0, 0, -100, frame('0000', '0008')], + ['pixel: 100px right scrolls left', 0, 100, 0, frame('00f8', '0000')], + ['pixel: 50px left is half a tick', 0, -50, 0, frame('0004', '0000')], + ['line: 3 lines down are 3 ticks', 1, 0, 3, frame('0000', '00e8')], + ['page: one page is 3 ticks', 2, 0, 1, frame('0000', '00e8')], + ]; + for (const [name, mode, dx, dy, hex] of table) { + test(name, () => { + const { h, v } = wheelToTicks(mode, dx, dy); + const point = { x: 540, y: 1200 }; + expect(wire(routeScroll(1080, 2400, point, h, v, 0))).toEqual([{ channel: 'control', hex }]); + }); + } +}); + // -------------------------------------------------------------------- ime // Browser keyboard input has no composition or commit path in React: text diff --git a/src/conformance/reconnect.test.ts b/src/conformance/reconnect.test.ts index d10617c..aff423f 100644 --- a/src/conformance/reconnect.test.ts +++ b/src/conformance/reconnect.test.ts @@ -11,7 +11,10 @@ import { STREAM_WS_OPEN_TIMEOUT_MS, streamReconnectDelayMs, } from '../lib/stream-reconnect'; -import { loadFixture } from './fixtures'; +import { FakeSchedule } from '../lib/test-clock'; +import { expectAllFixturesUsed, loadFixture } from './fixtures'; + +expectAllFixturesUsed('reconnect', ['policy', 'scenarios']); const policy = loadFixture('reconnect/policy.json'); const { scenarios } = loadFixture<{ scenarios: Scenario[] }>('reconnect/scenarios.json'); @@ -33,42 +36,6 @@ interface Scenario { }[]; } -// Fake clock: timers fire in due-time order, ties in scheduling order. -class FakeClock { - now = 0; - private nextId = 1; - private tasks = new Map void }>(); - setTimeout = (fn: () => void, ms: number) => { - const id = this.nextId++; - this.tasks.set(id, { at: this.now + ms, fn }); - return id as unknown as ReturnType; - }; - clearTimeout = (id: ReturnType) => { - this.tasks.delete(id as unknown as number); - }; - advanceTo(target: number) { - for (;;) { - let dueId: number | null = null; - let dueAt = Infinity; - for (const [id, task] of this.tasks) { - if (task.at <= target && task.at < dueAt) { - dueAt = task.at; - dueId = id; - } - } - if (dueId === null) break; - const task = this.tasks.get(dueId)!; - this.tasks.delete(dueId); - this.now = task.at; - task.fn(); - } - this.now = target; - } - get pending() { - return this.tasks.size; - } -} - describe('reconnect/policy', () => { test('constants', () => { expect(STREAM_RECONNECT_MAX_ATTEMPTS).toBe(policy.max_attempts); @@ -77,11 +44,6 @@ describe('reconnect/policy', () => { expect(STREAM_WS_OPEN_TIMEOUT_MS).toBe(timing.ws_open_timeout_ms); expect(STREAM_RTC_CONFIG_TIMEOUT_MS).toBe(timing.rtc_config_timeout_ms); }); - test('watchdog outlasts the handshake phases', () => { - expect(policy.connect_timeout_ms).toBeGreaterThan( - timing.ws_open_timeout_ms + timing.rtc_config_timeout_ms, - ); - }); for (const c of policy.delay_cases as { attempt: number; random: number; delay_ms: number }[]) { test(`delay attempt ${c.attempt} random ${c.random}`, () => { expect(streamReconnectDelayMs(c.attempt, () => c.random)).toBe(c.delay_ms); @@ -92,7 +54,7 @@ describe('reconnect/policy', () => { describe('reconnect/scenarios', () => { for (const s of scenarios) { test(s.name, () => { - const clock = new FakeClock(); + const clock = new FakeSchedule(); const calls = { heal: 0, remount: 0 }; const controller = createStreamReconnectController({ onRemount: () => void (calls.remount += 1), @@ -123,7 +85,7 @@ describe('reconnect/scenarios', () => { if (e.defer_target_change !== undefined) { expect([label, controller.shouldDeferTargetChange()]).toEqual([label, e.defer_target_change]); } - if (e.pending_timers !== undefined) expect([label, clock.pending]).toEqual([label, e.pending_timers]); + if (e.pending_timers !== undefined) expect([label, clock.pendingCount]).toEqual([label, e.pending_timers]); } }; check(0); diff --git a/src/conformance/signalling.test.ts b/src/conformance/signalling.test.ts index 5c10429..c83fe34 100644 --- a/src/conformance/signalling.test.ts +++ b/src/conformance/signalling.test.ts @@ -2,9 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import { describe, expect, test } from 'bun:test'; -import { event, fixture, tick } from '../hooks/webrtc-test-fixture'; -import { createRTCConfigurationRequest } from '../webrtc-messages'; -import { loadFixture } from './fixtures'; +import { tick } from '../hooks/test-hook-runner'; +import { event, fixture } from '../hooks/webrtc-test-fixture'; +import { createRTCConfigurationRequest, createScreenshotRequest } from '../webrtc-messages'; +import { expectAllFixturesUsed, loadFixture } from './fixtures'; interface Example { name: string; @@ -12,7 +13,14 @@ interface Example { } const examples = (file: string) => loadFixture<{ examples: Example[] }>(`signalling/${file}.json`).examples; const sequence = loadFixture('signalling/sequence.json'); -const SESSION = 'sess_0123456789abcdef'; +const { timing, channels } = sequence; + +const COVERED = [ + 'client-candidate', 'client-keep-alive', 'client-offer', 'client-open-url', 'client-request-frame', + 'client-request-rtc-configuration', 'client-screenshot-request', 'sequence', 'server-answer', + 'server-candidate', 'server-rtc-configuration', 'server-screenshot-error', 'server-screenshot', +]; +expectAllFixturesUsed('signalling', COVERED); // Client frames are observed on the fake socket while the real hook runs. describe('signalling/client frames', () => { @@ -22,7 +30,7 @@ describe('signalling/client frames', () => { }); test(`requestRtcConfiguration is the first frame sent: ${e.name}`, async () => { const f = await fixture(); - f.mount(SESSION); + f.mount(e.json.sessionId); f.sockets[0].open(); await tick(); expect(f.sockets[0].sent[0]).toEqual(e.json); @@ -30,14 +38,16 @@ describe('signalling/client frames', () => { }); } + for (const e of examples('client-screenshot-request')) { + test(`screenshot: ${e.name}`, () => { + expect(createScreenshotRequest(e.json.id)).toEqual(e.json as any); + }); + } + for (const e of examples('client-offer')) { test(`offer: ${e.name}`, async () => { const f = await fixture(); - f.mount(SESSION); - f.sockets[0].open(); - await tick(); - f.sockets[0].config(); - await tick(); + await f.negotiate(e.json.sessionId); f.peers[0].offer.resolve({ sdp: e.json.sdp }); await tick(); f.peers[0].local.resolve(); @@ -50,11 +60,7 @@ describe('signalling/client frames', () => { for (const e of examples('client-candidate')) { test(`candidate: ${e.name}`, async () => { const f = await fixture(); - f.mount(SESSION); - f.sockets[0].open(); - await tick(); - f.sockets[0].config(); - await tick(); + await f.negotiate(e.json.sessionId); f.peers[0].onicecandidate({ candidate: { candidate: e.json.candidate, sdpMid: e.json.sdpMid, sdpMLineIndex: e.json.sdpMLineIndex }, }); @@ -64,17 +70,20 @@ describe('signalling/client frames', () => { } for (const e of examples('client-request-frame')) { - test(`requestFrame x${sequence.timing.request_frame_count}: ${e.name}`, async () => { + test(`requestFrame burst: ${e.name}`, async () => { const f = await fixture(); - f.mount(SESSION); - f.sockets[0].open(); - await tick(); - f.sockets[0].config(); - await tick(); + await f.negotiate(e.json.sessionId); + const before = f.scheduled.length; f.peers[0].channels[0].onopen(); + // Scheduled offsets of the burst: +0, +125, ... (the first one may be immediate). + const offsets = f.scheduled.slice(before).filter((s) => s.kind === 'timeout').map((s) => s.ms); + expect(offsets).toHaveLength(timing.request_frame_count); + expect(offsets).toEqual( + Array.from({ length: timing.request_frame_count }, (_, i) => i * timing.request_frame_interval_ms), + ); f.fireTimers(); const frames = f.sockets[0].sent.filter((m) => m.type === 'requestFrame'); - expect(frames).toHaveLength(sequence.timing.request_frame_count); + expect(frames).toHaveLength(timing.request_frame_count); for (const frame of frames) expect(frame).toEqual(e.json); f.unmount(); }); @@ -83,11 +92,7 @@ describe('signalling/client frames', () => { for (const e of examples('client-open-url')) { test(`openUrl: ${e.name}`, async () => { const f = await fixture(); - f.mount(SESSION, encodeURIComponent(e.json.url)); - f.sockets[0].open(); - await tick(); - f.sockets[0].config(); - await tick(); + await f.negotiate(e.json.sessionId, encodeURIComponent(e.json.url)); f.peers[0].channels[0].onopen(); expect(f.sockets[0].sent.find((m) => m.type === 'openUrl')).toEqual(e.json); f.unmount(); @@ -97,9 +102,12 @@ describe('signalling/client frames', () => { for (const e of examples('client-keep-alive')) { test(`keepAlive: ${e.name}`, async () => { const f = await fixture(); - f.mount(SESSION); + f.mount(e.json.sessionId); f.sockets[0].open(); await tick(); + expect(f.scheduled.filter((s) => s.kind === 'interval').map((s) => s.ms)).toEqual([ + timing.keep_alive_interval_ms, + ]); f.fireTimers(); expect(f.sockets[0].sent.find((m) => m.type === 'keepAlive')).toEqual(e.json); f.unmount(); @@ -107,6 +115,33 @@ describe('signalling/client frames', () => { } }); +describe('signalling/sequence', () => { + for (const [name, spec] of Object.entries(channels) as [string, any][]) { + test(`${name} data channel options`, async () => { + const f = await fixture(); + await f.negotiate(); + const created = f.peers[0].channelOptions.find((c) => c.label === spec.label)!; + expect(created.options).toEqual({ + ordered: spec.ordered, + ...(spec.maxRetransmits === null ? {} : { maxRetransmits: spec.maxRetransmits }), + negotiated: spec.negotiated, + id: spec.id, + }); + f.unmount(); + }); + } + + test('handshake timeouts', async () => { + const f = await fixture(); + f.mount(); + expect(f.scheduled.map((s) => s.ms)).toContain(timing.ws_open_timeout_ms); + f.sockets[0].open(); + await tick(); + expect(f.scheduled.map((s) => s.ms)).toContain(timing.rtc_config_timeout_ms); + f.unmount(); + }); +}); + describe('signalling/server frames', () => { for (const e of examples('server-answer')) { test(`answer: ${e.name}`, async () => { @@ -121,16 +156,16 @@ describe('signalling/server frames', () => { } for (const e of examples('server-candidate')) { + const { type: _type, ...candidate } = e.json; test(`candidate after answer: ${e.name}`, async () => { const f = await fixture(); await f.negotiate(); - const answer = f.sockets[0].onmessage!(event({ type: 'answer', sdp: 'v=0' })); + const answer = f.sockets[0].onmessage!(event(examples('server-answer')[0].json)); f.peers[0].remote.resolve(); await answer; const added = f.sockets[0].onmessage!(event(e.json)); f.peers[0].ice.resolve(); await added; - const { type: _type, ...candidate } = e.json; expect(f.peers[0].iceArgs).toEqual([candidate]); f.unmount(); }); @@ -139,12 +174,11 @@ describe('signalling/server frames', () => { await f.negotiate(); await f.sockets[0].onmessage!(event(e.json)); expect(f.peers[0].iceArgs).toEqual([]); - const answer = f.sockets[0].onmessage!(event({ type: 'answer', sdp: 'v=0' })); + const answer = f.sockets[0].onmessage!(event(examples('server-answer')[0].json)); f.peers[0].remote.resolve(); await tick(); f.peers[0].ice.resolve(); await answer; - const { type: _type, ...candidate } = e.json; expect(f.peers[0].iceArgs).toEqual([candidate]); f.unmount(); }); @@ -176,7 +210,7 @@ describe('signalling/server frames', () => { for (const e of examples('server-screenshot')) { test(`screenshot: ${e.name}`, async () => { const f = await fixture(); - const result = f.mount(SESSION) as any; + const result = f.mount() as any; const received: unknown[] = []; result.pendingScreenshotResolversRef.current.set(e.json.id, (v: unknown) => received.push(v)); f.sockets[0].open(); @@ -192,7 +226,7 @@ describe('signalling/server frames', () => { for (const e of examples('server-screenshot-error')) { test(`screenshotError: ${e.name}`, async () => { const f = await fixture(); - const result = f.mount(SESSION) as any; + const result = f.mount() as any; const received: unknown[] = []; result.pendingScreenshotRejectersRef.current.set(e.json.id, (v: unknown) => received.push(v)); f.sockets[0].open(); diff --git a/src/hooks/test-hook-runner.ts b/src/hooks/test-hook-runner.ts index 9479194..11954a1 100644 --- a/src/hooks/test-hook-runner.ts +++ b/src/hooks/test-hook-runner.ts @@ -36,6 +36,9 @@ const fixtureSource = ` }; `; +/** Let queued promise continuations run. */ +export const tick = async () => { for (let i = 0; i < 8; i++) await Promise.resolve(); }; + const bundles = new Map>(); async function bundleHook(entry: string): Promise { diff --git a/src/hooks/use-device-stream.test.ts b/src/hooks/use-device-stream.test.ts index d462c05..7f84a82 100644 --- a/src/hooks/use-device-stream.test.ts +++ b/src/hooks/use-device-stream.test.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { expect, mock, test } from 'bun:test'; -import { runHook } from './test-hook-runner'; +import { runHook, tick } from './test-hook-runner'; import type { UseDeviceStreamOptions, UseDeviceStreamResult } from './use-device-stream'; // Type-only check: extending the legacy options interface keeps compiling. @@ -38,7 +38,6 @@ async function harness() { const info = { streamUrl: 'wss://stream.example/ws', streamToken: 'tok', state: 'ready' }; const noStream = { state: 'booting' }; -const tick = async () => { for (let i = 0; i < 8; i++) await Promise.resolve(); }; test('a fresh device handle with the same id does not refetch on rerender', async () => { const refresh = mock(async () => info); diff --git a/src/hooks/use-scrcpy-input.test.ts b/src/hooks/use-scrcpy-input.test.ts new file mode 100644 index 0000000..b966fdb --- /dev/null +++ b/src/hooks/use-scrcpy-input.test.ts @@ -0,0 +1,74 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, test } from 'bun:test'; +import { runHook } from './test-hook-runner'; + +type Handlers = { + handleInteraction: (event: object) => void; +}; + +async function setup() { + const sent: Uint8Array[] = []; + const channel = { readyState: 'open', send: (data: ArrayBuffer) => void sent.push(new Uint8Array(data)) }; + const video = { + videoWidth: 100, + videoHeight: 100, + getBoundingClientRect: () => ({ left: 0, top: 0, width: 100, height: 100 }), + focus() {}, + }; + const runner = await runHook<{ useScrcpyInput: (o: object) => Handlers }>( + import.meta.dir + '/use-scrcpy-input.ts', + { window: {}, document: {}, navigator: {} }, + ); + runner.beginRender(); + const handlers = runner.module.exports.useScrcpyInput({ + containerRef: { current: null }, + videoRef: { current: video }, + dataChannelRef: { current: channel }, + hoverChannelRef: { current: null }, + }); + const base = { preventDefault() {}, stopPropagation() {} }; + return { + sent, channel, + mouse: (type: string, x = 50, y = 50) => + handlers.handleInteraction({ ...base, type, button: 0, buttons: 1, clientX: x, clientY: y }), + touch: (type: string, ids: number[]) => + handlers.handleInteraction({ + ...base, type, touches: [], + changedTouches: ids.map((identifier) => ({ identifier, clientX: 50, clientY: 50 })), + }), + // Touch frame: byte 1 is the action, bytes 2-9 the big-endian pointer id. + actions: () => sent.map((m) => m[1]), + pointerIds: () => sent.map((m) => new DataView(m.buffer).getBigInt64(2)), + }; +} + +const DOWN = 0, UP = 1; + +describe('release while the control channel is closed', () => { + test('mouse: the next down after reopening still produces DOWN', async () => { + const f = await setup(); + f.mouse('mousedown'); + f.channel.readyState = 'closed'; + f.mouse('mouseup'); // dropped on the wire, but the router must see it + f.channel.readyState = 'open'; + f.mouse('mousedown'); + expect(f.actions()).toEqual([DOWN, DOWN]); + }); + + test('touch: slots are freed for the next gesture', async () => { + const f = await setup(); + const ids = Array.from({ length: 10 }, (_, i) => 1000 + i); + f.touch('touchstart', ids); + f.channel.readyState = 'closed'; + f.touch('touchend', ids); + f.channel.readyState = 'open'; + f.sent.length = 0; + f.touch('touchstart', ids.map((id) => id + 100)); + expect(f.actions()).toEqual(Array(10).fill(DOWN)); + expect(f.pointerIds()).toEqual(Array.from({ length: 10 }, (_, i) => BigInt(i))); + f.touch('touchend', [1100]); + expect(f.actions().at(-1)).toBe(UP); + }); +}); diff --git a/src/hooks/use-scrcpy-input.ts b/src/hooks/use-scrcpy-input.ts index b9ffb80..b85fe92 100644 --- a/src/hooks/use-scrcpy-input.ts +++ b/src/hooks/use-scrcpy-input.ts @@ -8,6 +8,7 @@ import { useEffect, useRef } from 'react'; import { createKeyRouter, createPointerRouter, + MOUSE_POINTER_ID, mapClientPoint, pasteMessages, routeScroll, @@ -112,16 +113,10 @@ export function useScrcpyInput({ event.preventDefault(); event.stopPropagation(); - if ( - !dataChannelRef.current || - dataChannelRef.current.readyState !== 'open' || - !videoRef.current - ) { - return; - } - + // No channel check: the router must see every release, or a gesture ended + // while the channel was closed would stay active. `send` drops while closed. const video = videoRef.current; - if (!video.videoWidth || !video.videoHeight) return; // Video dimensions not ready + if (!video) return; const route = (input: Omit, clientX: number, clientY: number) => { const mapped = getVideoPoint(video, clientX, clientY); @@ -189,7 +184,7 @@ export function useScrcpyInput({ default: return; } - route({ type, id: -1, mouse: true, button, buttons: event.buttons }, event.clientX, event.clientY); + route({ type, id: MOUSE_POINTER_ID, mouse: true, button, buttons: event.buttons }, event.clientX, event.clientY); }; // Native wheel listener — attached with passive:false in an effect so we @@ -203,13 +198,7 @@ export function useScrcpyInput({ event.preventDefault(); event.stopPropagation(); - if ( - !dataChannelRef.current || - dataChannelRef.current.readyState !== 'open' || - !videoRef.current - ) { - return; - } + if (!videoRef.current) return; const mapped = getVideoPoint(videoRef.current, event.clientX, event.clientY); if (!mapped) return; diff --git a/src/hooks/use-task-approval.test.ts b/src/hooks/use-task-approval.test.ts index 2c54700..c47d882 100644 --- a/src/hooks/use-task-approval.test.ts +++ b/src/hooks/use-task-approval.test.ts @@ -3,9 +3,7 @@ import { describe, expect, test } from 'bun:test'; import type { UseTaskApprovalOptions } from './use-task-approval'; -import { runHook } from './test-hook-runner'; - -const tick = async () => { for (let i = 0; i < 8; i++) await Promise.resolve(); }; +import { runHook, tick } from './test-hook-runner'; async function setup(options: Partial) { const timers = new Map void; ms: number }>(); @@ -80,3 +78,19 @@ describe('working subscribe', () => { f.unmount(); }); }); + +describe('subscribe failure with a synchronously throwing fetch', () => { + test('still arms the fallback poll, and firing it fetches again', async () => { + let attempts = 0; + const f = await setup({ + subscribe: failing, + fetchApproval: () => { attempts++; throw new Error('fetch down'); }, + }); + expect(attempts).toBe(1); + expect(f.errors.map((e) => (e as Error).message)).toEqual(['stream down', 'fetch down']); + expect([...f.timers.values()].map((t) => t.ms)).toEqual([3000]); + await f.fire(); + expect(attempts).toBe(2); + f.unmount(); + }); +}); diff --git a/src/hooks/use-task-approval.ts b/src/hooks/use-task-approval.ts index 492ecf6..3372194 100644 --- a/src/hooks/use-task-approval.ts +++ b/src/hooks/use-task-approval.ts @@ -13,7 +13,7 @@ export interface UseTaskApprovalOptions { decide: (input: { taskId: string; approvalId: string; decision: ApprovalDecision }) => Promise; /** Optional push source (e.g. SSE fed by your webhook handler). Call onChange when an approval event for this task arrives; return an unsubscribe. */ subscribe?: (taskId: string, onChange: () => void) => () => void; - /** Poll interval while enabled. Default 0 (off) when `subscribe` is given, else 3000. If `subscribe` throws, the error goes to `onError` and polling runs at this interval (3000 when unset or 0). */ + /** Poll interval while enabled. Default 0 (off) when `subscribe` is given, else 3000. If `subscribe` throws, the error goes to `onError` and polling runs at this interval; an explicit 0 then falls back to 3000 (0 only means "no polling" while `subscribe` works). */ pollIntervalMs?: number; enabled?: boolean; onError?: (error: unknown) => void; @@ -135,7 +135,6 @@ export function useTaskApproval({ reloadRef.current = () => void load(); setIsLoading(true); - void load(); let unsubscribe: (() => void) | undefined; try { unsubscribe = subscribeRef.current?.(taskId, () => { @@ -147,6 +146,8 @@ export function useTaskApproval({ onErrorRef.current?.(err); pollMs = pollIntervalMs || DEFAULT_POLL_INTERVAL_MS; } + // After the subscription setup, so `pollMs` is final when the first load settles. + void load(); return () => { cancelled = true; diff --git a/src/hooks/use-webrtc-connection.test.ts b/src/hooks/use-webrtc-connection.test.ts index f491dc3..fc5c5a3 100644 --- a/src/hooks/use-webrtc-connection.test.ts +++ b/src/hooks/use-webrtc-connection.test.ts @@ -2,7 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { expect, test } from 'bun:test'; -import { deferred, event, fixture, tick } from './webrtc-test-fixture'; +import { tick } from './test-hook-runner'; +import { deferred, event, fixture } from './webrtc-test-fixture'; for (const end of ['unmount', 'switch'] as const) { for (const boundary of ['open', 'config', 'offer', 'local'] as const) { @@ -53,7 +54,7 @@ test('stop removes a pending configuration listener and both startup deadlines', test('stale channel, peer, socket callbacks and queued frame requests are silent', async () => { const f = await fixture(); - await f.negotiate('https%3A%2F%2Fexample.invalid'); + await f.negotiate('a', 'https%3A%2F%2Fexample.invalid'); const ws = f.sockets[0], pc = f.peers[0]; const lateMessage = ws.onmessage!; pc.channels[0].onopen(); diff --git a/src/hooks/webrtc-test-fixture.ts b/src/hooks/webrtc-test-fixture.ts index b7dae59..20a3c17 100644 --- a/src/hooks/webrtc-test-fixture.ts +++ b/src/hooks/webrtc-test-fixture.ts @@ -1,9 +1,8 @@ // Copyright 2026 Mobilerun // SPDX-License-Identifier: Apache-2.0 -import { runHook } from './test-hook-runner'; +import { runHook, tick } from './test-hook-runner'; -export const tick = async () => { for (let i = 0; i < 8; i++) await Promise.resolve(); }; export const event = (message: object) => ({ data: JSON.stringify(message) }); export function deferred() { @@ -18,7 +17,15 @@ export async function fixture() { const peers: FakePeer[] = []; const timers = new Map void>(); let nextTimer = 0; - const setTimer = (fn: () => void) => { timers.set(++nextTimer, fn); return nextTimer; }; + // Every scheduled delay, in order, so tests can check timings the fake never waits out. + const scheduled: { kind: 'timeout' | 'interval'; ms: number }[] = []; + const schedule = (kind: 'timeout' | 'interval') => (fn: () => void, ms: number) => { + scheduled.push({ kind, ms }); + timers.set(++nextTimer, fn); + return nextTimer; + }; + const setTimer = schedule('timeout'); + const setIntervalTimer = schedule('interval'); const clearTimer = (id: number) => { timers.delete(id); }; class FakeSocket { static OPEN = 1; @@ -48,6 +55,7 @@ export async function fixture() { closed = false; connectionState = 'new'; channels: FakeChannel[] = []; + channelOptions: { label: string; options: Record }[] = []; offer = deferred<{ sdp: string }>(); local = deferred(); remote = deferred(); @@ -63,7 +71,7 @@ export async function fixture() { ontrack = (_event: object) => {}; constructor() { peers.push(this); } addTransceiver() { return { receiver: {} }; } - createDataChannel() { const c = new FakeChannel(); this.channels.push(c); return c; } + createDataChannel(label: string, options: Record) { this.channelOptions.push({ label, options }); const c = new FakeChannel(); this.channels.push(c); return c; } createOffer() { return this.offer.promise; } setLocalDescription() { this.localCalls++; return this.local.promise; } setRemoteDescription(arg: Record) { this.remoteArgs.push(arg); return this.remote.promise; } @@ -77,7 +85,7 @@ export async function fixture() { const bindings: (FakePeer | null)[] = []; const video = { current: { srcObject: null, muted: true } }; const context = { - window: { setTimeout: setTimer, clearTimeout: clearTimer, setInterval: setTimer, clearInterval: clearTimer }, + window: { setTimeout: setTimer, clearTimeout: clearTimer, setInterval: setIntervalTimer, clearInterval: clearTimer }, document: { hidden: false, addEventListener() {}, removeEventListener() {} }, WebSocket: FakeSocket, RTCPeerConnection: FakePeer, RTCRtpReceiver: { getCapabilities: () => null }, @@ -102,9 +110,9 @@ export async function fixture() { return result; }; return { - sockets, peers, timers, states, failures, bindings, stateWrites, video, mount, + sockets, peers, timers, scheduled, states, failures, bindings, stateWrites, video, mount, unmount: runner.unmount, fireTimers() { const tasks = [...timers.values()]; timers.clear(); tasks.forEach(fn => fn()); }, - async negotiate(openUrl?: string) { mount('a', openUrl); sockets[0].open(); await tick(); sockets[0].config(); await tick(); }, + async negotiate(id = 'a', openUrl?: string) { mount(id, openUrl); sockets[0].open(); await tick(); sockets[0].config(); await tick(); }, }; } diff --git a/src/lib/input-routing.ts b/src/lib/input-routing.ts index d65bf20..b2ff7f0 100644 --- a/src/lib/input-routing.ts +++ b/src/lib/input-routing.ts @@ -115,8 +115,11 @@ const graphemes = ? new Intl.Segmenter(undefined, { granularity: 'grapheme' }) : null; -// A named key (`ContextMenu`, `Dead`) is more than one UTF-16 unit but is not text. -function isGraphemeText(key: string): boolean { +// One UTF-16 unit is always text; a longer value only when it is exactly one +// printable grapheme (emoji, ZWJ/skin-tone sequence, NFD pair). Named keys +// (`ContextMenu`, `Dead`) are several graphemes and stay keys. +function isText(key: string): boolean { + if (key.length === 1) return true; if (key.length < 2 || !graphemes || /\p{Cc}/u.test(key)) return false; const iterator = graphemes.segment(key)[Symbol.iterator](); iterator.next(); @@ -188,7 +191,7 @@ export function createKeyRouter() { } // Printable characters go as text (Unicode, fast typing, no up/down pairs). - if (!isControlKey(e) && (e.key.length === 1 || isGraphemeText(e.key))) { + if (!isControlKey(e) && isText(e.key)) { return { kind: 'messages', messages: [control(createInjectTextMessage(e.key))] }; } @@ -217,7 +220,7 @@ export interface PointerInput { buttons: number; } -export const MAX_TOUCH_SLOTS = 10; +const MAX_TOUCH_SLOTS = 10; export const MOUSE_POINTER_ID = -1; /** @@ -292,8 +295,6 @@ export function createPointerRouter() { ), ]; }, - /** Whether the mouse currently holds a gesture. */ - hasMouseGesture: () => active.has('mouse'), }; } diff --git a/src/lib/stream-reconnect.test.ts b/src/lib/stream-reconnect.test.ts index c49e8d4..3f6af39 100644 --- a/src/lib/stream-reconnect.test.ts +++ b/src/lib/stream-reconnect.test.ts @@ -12,47 +12,7 @@ import { streamReconnectDelayMs, type StreamReconnectSnapshot, } from './stream-reconnect'; - -// Deterministic scheduler: timers fire in due-time order via advance(). -class FakeSchedule { - now = 0; - private nextId = 1; - private tasks = new Map void }>(); - - setTimeout = (fn: () => void, ms: number) => { - const id = this.nextId++; - this.tasks.set(id, { at: this.now + ms, fn }); - return id as unknown as ReturnType; - }; - - clearTimeout = (id: ReturnType) => { - this.tasks.delete(id as unknown as number); - }; - - advance(ms: number) { - const target = this.now + ms; - for (;;) { - let dueId: number | null = null; - let dueAt = Infinity; - for (const [id, task] of this.tasks) { - if (task.at <= target && task.at < dueAt) { - dueAt = task.at; - dueId = id; - } - } - if (dueId === null) break; - const task = this.tasks.get(dueId)!; - this.tasks.delete(dueId); - this.now = task.at; - task.fn(); - } - this.now = target; - } - - get pendingCount() { - return this.tasks.size; - } -} +import { FakeSchedule } from './test-clock'; // random() => 0.5 makes the jitter factor exactly 1.0. const NO_JITTER = () => 0.5; diff --git a/src/lib/test-clock.ts b/src/lib/test-clock.ts new file mode 100644 index 0000000..b7342d2 --- /dev/null +++ b/src/lib/test-clock.ts @@ -0,0 +1,47 @@ +// Copyright 2026 Mobilerun +// SPDX-License-Identifier: Apache-2.0 + +// Deterministic scheduler: timers fire in due-time order (ties in scheduling +// order) as the clock advances. +export class FakeSchedule { + now = 0; + private nextId = 1; + private tasks = new Map void }>(); + + setTimeout = (fn: () => void, ms: number) => { + const id = this.nextId++; + this.tasks.set(id, { at: this.now + ms, fn }); + return id as unknown as ReturnType; + }; + + clearTimeout = (id: ReturnType) => { + this.tasks.delete(id as unknown as number); + }; + + advance(ms: number) { + this.advanceTo(this.now + ms); + } + + advanceTo(target: number) { + for (;;) { + let dueId: number | null = null; + let dueAt = Infinity; + for (const [id, task] of this.tasks) { + if (task.at <= target && task.at < dueAt) { + dueAt = task.at; + dueId = id; + } + } + if (dueId === null) break; + const task = this.tasks.get(dueId)!; + this.tasks.delete(dueId); + this.now = task.at; + task.fn(); + } + this.now = target; + } + + get pendingCount() { + return this.tasks.size; + } +} diff --git a/src/webrtc-messages.ts b/src/webrtc-messages.ts index f51dd1e..d30b082 100644 --- a/src/webrtc-messages.ts +++ b/src/webrtc-messages.ts @@ -14,6 +14,10 @@ export function createRTCConfigurationRequest(sessionId: string) { } as const; } +export function createScreenshotRequest(id: string) { + return { type: 'screenshot', id } as const; +} + export function createTouchControlMessage( action: number, pointerId: number,