Skip to content

Commit

Permalink
tests: Add focus_keyboard_press test
Browse files Browse the repository at this point in the history
This test verifies the behavior of pressing buttons with a keyboard.
  • Loading branch information
kjarosh committed May 10, 2024
1 parent eaedabc commit 114a05f
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/tests/swfs/avm1/focus_keyboard_press/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[
{ "type": "KeyDown", "key_code": 9 }, { "type": "TextInput", "codepoint": "\t" }, { "type": "KeyUp", "key_code": 9 },
{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },

{ "type": "KeyDown", "key_code": 9 }, { "type": "TextInput", "codepoint": "\t" }, { "type": "KeyUp", "key_code": 9 },

{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },

{ "type": "KeyDown", "key_code": 9 }, { "type": "TextInput", "codepoint": "\t" }, { "type": "KeyUp", "key_code": 9 },

{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },

{ "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": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },

{ "type": "KeyDown", "key_code": 9 }, { "type": "TextInput", "codepoint": "\t" }, { "type": "KeyUp", "key_code": 9 },

{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },

{ "type": "KeyDown", "key_code": 9 }, { "type": "TextInput", "codepoint": "\t" }, { "type": "KeyUp", "key_code": 9 },

{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 },
{ "type": "MouseMove", "pos": [5, 5] },
{ "type": "KeyDown", "key_code": 13 }, { "type": "TextInput", "codepoint": "\n" }, { "type": "KeyUp", "key_code": 13 },
{ "type": "KeyDown", "key_code": 32 }, { "type": "TextInput", "codepoint": " " }, { "type": "KeyUp", "key_code": 32 },
{ "type": "KeyDown", "key_code": 65 }, { "type": "TextInput", "codepoint": "a" }, { "type": "KeyUp", "key_code": 65 }
]
60 changes: 60 additions & 0 deletions tests/tests/swfs/avm1/focus_keyboard_press/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Focus at: _level0.text
Tab pressed
Focus at: _level0.clip
_level0.clip.onKeyUp: 9
_level0.clip.onKeyDown: 13
_level0.clip.onPress: 13
_level0.clip.onRelease: 13
_level0.clip.onKeyUp: 13
_level0.clip.onKeyDown: 32
_level0.clip.onPress: 32
_level0.clip.onRelease: 32
_level0.clip.onKeyUp: 32
_level0.clip.onKeyDown: 65
_level0.clip.onKeyUp: 65
_level0.clip.onMouseMove
Tab pressed
Focus at: _level0.button
_level0.button.onKeyUp: 9
_level0.button.onKeyDown: 13
press
_level0.button.onPress: 13
release
_level0.button.onRelease: 13
_level0.button.onKeyUp: 13
_level0.button.onKeyDown: 32
press
_level0.button.onPress: 32
release
_level0.button.onRelease: 32
_level0.button.onKeyUp: 32
_level0.button.onKeyDown: 65
_level0.button.onKeyUp: 65
_level0.clip.onMouseMove
Tab pressed
Focus at: _level0.text
_level0.clip.onMouseMove
Escape pressed
Tab pressed
Focus at: _level0.clip
_level0.clip.onKeyUp: 9
_level0.clip.onKeyDown: 13
_level0.clip.onKeyUp: 13
_level0.clip.onKeyDown: 32
_level0.clip.onKeyUp: 32
_level0.clip.onKeyDown: 65
_level0.clip.onKeyUp: 65
_level0.clip.onMouseMove
Tab pressed
Focus at: _level0.button
_level0.button.onKeyUp: 9
_level0.button.onKeyDown: 13
_level0.button.onKeyUp: 13
_level0.button.onKeyDown: 32
_level0.button.onKeyUp: 32
_level0.button.onKeyDown: 65
_level0.button.onKeyUp: 65
_level0.clip.onMouseMove
Tab pressed
Focus at: _level0.text
_level0.clip.onMouseMove
39 changes: 39 additions & 0 deletions tests/tests/swfs/avm1/focus_keyboard_press/test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var listener = new Object();
listener.onSetFocus = function(oldFocus, newFocus) {
trace("Focus at: " + newFocus);
};
listener.onKeyDown = function() {
if (Key.getCode() == 27) {
trace("Escape pressed");
_focusrect = false;
Selection.setFocus(text);
}
if (Key.getCode() == 9) {
trace("Tab pressed");
}
};
Selection.addListener(listener);
Key.addListener(listener);

function setHandlers(obj) {
obj.onRelease = function () { trace(obj + ".onRelease: " + Key.getCode()); }
obj.onKeyDown = function () { trace(obj + ".onKeyDown: " + Key.getCode()); }
obj.onKeyUp = function () { trace(obj + ".onKeyUp: " + Key.getCode()); }
obj.onPress = function () { trace(obj + ".onPress: " + Key.getCode()); }
obj.onReleaseOutside = function () { trace(obj + ".onReleaseOutside"); }
obj.onMouseDown = function () { trace(obj + ".onMouseDown") }
obj.onMouseUp = function () { trace(obj + ".onMouseUp") }
obj.onMouseMove = function () { trace(obj + ".onMouseMove") }
}

clip.tabEnabled = true;
clip.tabIndex = 1;
setHandlers(clip);
button.tabEnabled = true;
button.tabIndex = 2;
setHandlers(button);
text.tabEnabled = true;
text.tabIndex = 3;
setHandlers(text);

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

0 comments on commit 114a05f

Please sign in to comment.