Skip to content

Commit

Permalink
tests: Add button_keypress_vs_tab test
Browse files Browse the repository at this point in the history
This test verifies that the KeyPress event handling
has precedence over tabbing.
  • Loading branch information
kjarosh committed May 22, 2024
1 parent 5ce2cf2 commit 3f16763
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_tab/input.json
Original file line number Diff line number Diff line change
@@ -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 }
]
20 changes: 20 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_tab/output.txt
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_tab/test.as
Original file line number Diff line number Diff line change
@@ -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);
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_tab/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_ticks = 1

0 comments on commit 3f16763

Please sign in to comment.