Skip to content

Commit

Permalink
tests: Add button_keypress_vs_press test
Browse files Browse the repository at this point in the history
This test ensures that button key press events take precedence
over pressing focused buttons with keyboard.
  • Loading branch information
kjarosh committed May 10, 2024
1 parent 114a05f commit efa5e5e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_press/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{ "type": "KeyDown", "key_code": 13 },
{ "type": "TextControl", "code": "Enter" },
{ "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 },
{ "type": "TextInput", "codepoint": " " },
{ "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 9 },
{ "type": "TextInput", "codepoint": "\t" },
{ "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 13 },
{ "type": "TextControl", "code": "Enter" },
{ "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 },
{ "type": "TextInput", "codepoint": " " },
{ "type": "KeyUp", "key_code": 32 }
]
25 changes: 25 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_press/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
button.onKeyDown: 13
Enter pressed
keyPress 2 enter
button.onKeyUp: 13
button.onKeyDown: 32
Space pressed
press 1
button.onPress: 32
release 1
button.onRelease: 32
button.onKeyUp: 32
button.onKeyDown: 9
Tab pressed
button2.onKeyUp: 9
button2.onKeyDown: 13
Enter pressed
keyPress 2 enter
button2.onKeyUp: 13
button2.onKeyDown: 32
Space pressed
press 2
button2.onPress: 32
release 2
button2.onRelease: 32
button2.onKeyUp: 32
25 changes: 25 additions & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_press/test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var listener = new Object();
listener.onKeyDown = function() {
if (Key.getCode() == 32) {
trace("Space pressed");
}
if (Key.getCode() == 13) {
trace("Enter pressed");
}
if (Key.getCode() == 9) {
trace("Tab pressed");
}
};
Key.addListener(listener);

button.onKeyDown = function () { trace("button.onKeyDown: " + Key.getCode()); }
button.onKeyUp = function () { trace("button.onKeyUp: " + Key.getCode()); }
button.onPress = function () { trace("button.onPress: " + Key.getCode()); }
button.onRelease = function () { trace("button.onRelease: " + Key.getCode()); }

button2.onKeyDown = function () { trace("button2.onKeyDown: " + Key.getCode()); }
button2.onKeyUp = function () { trace("button2.onKeyUp: " + Key.getCode()); }
button2.onPress = function () { trace("button2.onPress: " + Key.getCode()); }
button2.onRelease = function () { trace("button2.onRelease: " + Key.getCode()); }

Selection.setFocus(button);
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tests/swfs/avm1/button_keypress_vs_press/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_ticks = 1

0 comments on commit efa5e5e

Please sign in to comment.