From 1080c8bffa3bedc63f33fb502d6b2f7a9bd65880 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Wed, 22 May 2024 12:59:24 +0200 Subject: [PATCH] tests: Add button_keypress_vs_tab test This test verifies that the KeyPress event handling has precedence over tabbing. --- .../avm1/button_keypress_vs_tab/input.json | 16 ++++++++ .../avm1/button_keypress_vs_tab/output.txt | 20 ++++++++++ .../swfs/avm1/button_keypress_vs_tab/test.as | 35 ++++++++++++++++++ .../swfs/avm1/button_keypress_vs_tab/test.swf | Bin 0 -> 639 bytes .../avm1/button_keypress_vs_tab/test.toml | 1 + 5 files changed, 72 insertions(+) create mode 100644 tests/tests/swfs/avm1/button_keypress_vs_tab/input.json create mode 100644 tests/tests/swfs/avm1/button_keypress_vs_tab/output.txt create mode 100644 tests/tests/swfs/avm1/button_keypress_vs_tab/test.as create mode 100644 tests/tests/swfs/avm1/button_keypress_vs_tab/test.swf create mode 100644 tests/tests/swfs/avm1/button_keypress_vs_tab/test.toml diff --git a/tests/tests/swfs/avm1/button_keypress_vs_tab/input.json b/tests/tests/swfs/avm1/button_keypress_vs_tab/input.json new file mode 100644 index 000000000000..d2d3e472eff9 --- /dev/null +++ b/tests/tests/swfs/avm1/button_keypress_vs_tab/input.json @@ -0,0 +1,16 @@ +[ + { "type": "KeyDown", "key_code": 9 }, + { "type": "TextInput", "codepoint": "\t" }, + { "type": "KeyUp", "key_code": 9 }, + { "type": "KeyDown", "key_code": 9 }, + { "type": "TextInput", "codepoint": "\t" }, + { "type": "KeyUp", "key_code": 9 }, + { "type": "KeyDown", "key_code": 27 }, + { "type": "KeyUp", "key_code": 27 }, + { "type": "KeyDown", "key_code": 9 }, + { "type": "TextInput", "codepoint": "\t" }, + { "type": "KeyUp", "key_code": 9 }, + { "type": "KeyDown", "key_code": 9 }, + { "type": "TextInput", "codepoint": "\t" }, + { "type": "KeyUp", "key_code": 9 } +] diff --git a/tests/tests/swfs/avm1/button_keypress_vs_tab/output.txt b/tests/tests/swfs/avm1/button_keypress_vs_tab/output.txt new file mode 100644 index 000000000000..a8dcc1cb5b00 --- /dev/null +++ b/tests/tests/swfs/avm1/button_keypress_vs_tab/output.txt @@ -0,0 +1,20 @@ +Focus changed: null -> _level0.button1 +button.onKeyDown: 9 +Tab pressed +Focus changed: _level0.button1 -> _level0.button2 +button.onKeyUp: 9 +button.onKeyDown: 9 +Tab pressed +Focus changed: _level0.button2 -> _level0.button1 +button.onKeyUp: 9 +button.onKeyDown: 27 +===== Escape pressed +button.onKeyUp: 27 +button.onKeyDown: 9 +Tab pressed +keyPress 3 tab +button.onKeyUp: 9 +button.onKeyDown: 9 +Tab pressed +keyPress 3 tab +button.onKeyUp: 9 diff --git a/tests/tests/swfs/avm1/button_keypress_vs_tab/test.as b/tests/tests/swfs/avm1/button_keypress_vs_tab/test.as new file mode 100644 index 000000000000..a7adcb0e9511 --- /dev/null +++ b/tests/tests/swfs/avm1/button_keypress_vs_tab/test.as @@ -0,0 +1,35 @@ +var listener = new Object(); +listener.onKeyDown = function() { + if (Key.getCode() == 9) { + trace("Tab pressed"); + } + if (Key.getCode() == 27) { + trace("===== Escape pressed"); + + button2._visible = false; + button3._visible = true; + Selection.setFocus(button1); + } +}; +listener.onSetFocus = function(oldFocus, newFocus) { + if (newFocus) { + trace("Focus changed: " + oldFocus + " -> " + newFocus); + } +}; +Key.addListener(listener); +Selection.addListener(listener); + +button1.tabIndex = 1; +button2.tabIndex = 2; +button3.tabIndex = 3; + +var buttons = [button1, button2, button3]; +for (var i in buttons) { + buttons[i].onKeyDown = function () { trace("button.onKeyDown: " + Key.getCode()); } + buttons[i].onKeyUp = function () { trace("button.onKeyUp: " + Key.getCode()); } + buttons[i].onPress = function () { trace("button.onPress: " + Key.getCode()); } + buttons[i].onRelease = function () { trace("button.onRelease: " + Key.getCode()); } +} + +button3._visible = false; +Selection.setFocus(button1); diff --git a/tests/tests/swfs/avm1/button_keypress_vs_tab/test.swf b/tests/tests/swfs/avm1/button_keypress_vs_tab/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..852acf847cae7e5d5fbf3c75b20502a5ac082b8f GIT binary patch literal 639 zcmV-_0)YKPS5pX>1pokeoTZb`YZE~f$KUQIX_7|sLu+CabU}$AC^Wf=+G5&{z2=H)OY_)q}ltLC{-3MDU`2gdoAAe}hLa-n@H>Z{F@?H`SJcdzgLm{k&f@ zZ+8d6n*hlV00{|}(|}J!9*@T(IFDusHhyX4FV3C>k8qos>#jJzFTMCQ_?&z7(b*eC z7f}rZ#3301iTlq(6r2Rweb!|yi>V7Rlu;{EHYbjx*JqaH>!aucWRWA2l!S9`I!Vb- z4jCtf`ct-h*G1}v?U#6n4m1B<;-ZrdmME)sOPkb)Ob`%nQc~ zp-7RhGvp8*^6}TX8S@2+gm{4mOJ2fR!ih$;9=olZ6)ZHAQF{AGjgzVL87= zGsqO0`