Skip to content

Commit 106eae5

Browse files
committed
tests: Decouple input.json from Flash key codes
This refactor removes key codes from input.json aiming at moving key code mapping to core and creating a common, Flash-independent interface for input.
1 parent 78fd707 commit 106eae5

File tree

71 files changed

+2054
-1995
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2054
-1995
lines changed

tests/framework/src/runner.rs

+48-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ruffle_core::limits::ExecutionLimit;
1515
use ruffle_core::tag_utils::SwfMovie;
1616
use ruffle_core::{Player, PlayerBuilder, PlayerEvent};
1717
use ruffle_input_format::{
18-
AutomatedEvent, InputInjector, MouseButton as InputMouseButton,
18+
AutomatedEvent, AutomatedKey, InputInjector, MouseButton as InputMouseButton,
1919
TextControlCode as InputTextControlCode,
2020
};
2121
use ruffle_render::backend::{RenderBackend, ViewportDimensions};
@@ -235,12 +235,12 @@ impl TestRunner {
235235
_ => panic!("MouseWheel: expected only one of 'lines' or 'pixels'"),
236236
},
237237
},
238-
AutomatedEvent::KeyDown { key_code } => PlayerEvent::KeyDown {
239-
key_code: KeyCode::from_code(*key_code),
238+
AutomatedEvent::KeyDown { key } => PlayerEvent::KeyDown {
239+
key_code: automated_key_to_key_code(*key),
240240
key_char: None,
241241
},
242-
AutomatedEvent::KeyUp { key_code } => PlayerEvent::KeyUp {
243-
key_code: KeyCode::from_code(*key_code),
242+
AutomatedEvent::KeyUp { key } => PlayerEvent::KeyUp {
243+
key_code: automated_key_to_key_code(*key),
244244
key_char: None,
245245
},
246246
AutomatedEvent::TextInput { codepoint } => PlayerEvent::TextInput {
@@ -574,3 +574,46 @@ fn assert_text_matches(ruffle: &str, flash: &str) -> Result<()> {
574574
Ok(())
575575
}
576576
}
577+
578+
fn automated_key_to_key_code(automated_key: AutomatedKey) -> KeyCode {
579+
match automated_key {
580+
AutomatedKey::Char(ch) => KeyCode::from_code(ch.to_ascii_uppercase() as u32),
581+
AutomatedKey::Numpad(ch) => match ch {
582+
'0' => KeyCode::NUMPAD_0,
583+
'1' => KeyCode::NUMPAD_1,
584+
'2' => KeyCode::NUMPAD_2,
585+
'3' => KeyCode::NUMPAD_3,
586+
'4' => KeyCode::NUMPAD_4,
587+
'5' => KeyCode::NUMPAD_5,
588+
'6' => KeyCode::NUMPAD_6,
589+
'7' => KeyCode::NUMPAD_7,
590+
'8' => KeyCode::NUMPAD_8,
591+
'9' => KeyCode::NUMPAD_9,
592+
'*' => KeyCode::NUMPAD_MULTIPLY,
593+
'+' => KeyCode::NUMPAD_ADD,
594+
'-' => KeyCode::NUMPAD_SUBTRACT,
595+
'.' | ',' => KeyCode::NUMPAD_DECIMAL,
596+
'/' => KeyCode::NUMPAD_DIVIDE,
597+
ch => panic!("Unknown numpad key: {}", ch),
598+
},
599+
AutomatedKey::ArrowDown => KeyCode::DOWN,
600+
AutomatedKey::ArrowLeft => KeyCode::LEFT,
601+
AutomatedKey::ArrowRight => KeyCode::RIGHT,
602+
AutomatedKey::ArrowUp => KeyCode::UP,
603+
AutomatedKey::Backspace => KeyCode::BACKSPACE,
604+
AutomatedKey::CapsLock => KeyCode::CAPS_LOCK,
605+
AutomatedKey::Control => KeyCode::CONTROL,
606+
AutomatedKey::Delete => KeyCode::DELETE,
607+
AutomatedKey::End => KeyCode::END,
608+
AutomatedKey::Enter => KeyCode::ENTER,
609+
AutomatedKey::Escape => KeyCode::ESCAPE,
610+
AutomatedKey::Home => KeyCode::HOME,
611+
AutomatedKey::Insert => KeyCode::INSERT,
612+
AutomatedKey::PageDown => KeyCode::PAGE_DOWN,
613+
AutomatedKey::PageUp => KeyCode::PAGE_UP,
614+
AutomatedKey::Shift => KeyCode::SHIFT,
615+
AutomatedKey::Space => KeyCode::SPACE,
616+
AutomatedKey::Tab => KeyCode::TAB,
617+
AutomatedKey::Unknown => KeyCode::UNKNOWN,
618+
}
619+
}

tests/input-format/src/format.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ pub enum TextControlCode {
4747
Delete,
4848
}
4949

50+
/// All possible keys which can be simulated in tests.
51+
///
52+
/// Note: Add more keys if needed.
53+
#[derive(Serialize, Deserialize, Debug, Copy, Clone)]
54+
pub enum AutomatedKey {
55+
Char(char),
56+
Numpad(char),
57+
ArrowDown,
58+
ArrowLeft,
59+
ArrowRight,
60+
ArrowUp,
61+
Backspace,
62+
CapsLock,
63+
Control,
64+
Delete,
65+
End,
66+
Enter,
67+
Escape,
68+
Home,
69+
Insert,
70+
PageDown,
71+
PageUp,
72+
Shift,
73+
Space,
74+
Tab,
75+
Unknown,
76+
}
77+
5078
/// All automated event types supported by FlashTAS.
5179
///
5280
/// A FlashTAS input file consists of a string of `AutomatedEvent`s which are
@@ -82,10 +110,10 @@ pub enum AutomatedEvent {
82110
},
83111

84112
/// Press a key
85-
KeyDown { key_code: u32 },
113+
KeyDown { key: AutomatedKey },
86114

87115
/// Release a key
88-
KeyUp { key_code: u32 },
116+
KeyUp { key: AutomatedKey },
89117

90118
/// Input a character code
91119
TextInput { codepoint: char },

tests/input-format/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod format;
22
mod injector;
33

4-
pub use format::{AutomatedEvent, MouseButton, TextControlCode};
4+
pub use format::{AutomatedEvent, AutomatedKey, MouseButton, TextControlCode};
55
pub use injector::{InputInjector, MouseButtons};
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
[
2-
{ "type": "KeyDown", "key_code": 65 },
2+
{ "type": "KeyDown", "key": { "Char": "a" } },
33
{ "type": "TextInput", "codepoint": "a" },
4-
{ "type": "KeyUp", "key_code": 65 },
5-
{ "type": "KeyDown", "key_code": 66 },
4+
{ "type": "KeyUp", "key": { "Char": "a" } },
5+
{ "type": "KeyDown", "key": { "Char": "b" } },
66
{ "type": "TextInput", "codepoint": "b" },
7-
{ "type": "KeyDown", "key_code": 65 },
7+
{ "type": "KeyDown", "key": { "Char": "a" } },
88
{ "type": "TextInput", "codepoint": "a" },
9-
{ "type": "KeyUp", "key_code": 66 },
10-
{ "type": "KeyUp", "key_code": 65 },
11-
{ "type": "KeyDown", "key_code": 9 },
9+
{ "type": "KeyUp", "key": { "Char": "b" } },
10+
{ "type": "KeyUp", "key": { "Char": "a" } },
11+
{ "type": "KeyDown", "key": "Tab" },
1212
{ "type": "TextInput", "codepoint": "\t" },
13-
{ "type": "KeyUp", "key_code": 9 },
14-
{ "type": "KeyDown", "key_code": 65 },
13+
{ "type": "KeyUp", "key": "Tab" },
14+
{ "type": "KeyDown", "key": { "Char": "a" } },
1515
{ "type": "TextInput", "codepoint": "a" },
16-
{ "type": "KeyUp", "key_code": 65 }
16+
{ "type": "KeyUp", "key": { "Char": "a" } }
1717
]
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
[
2-
{ "type": "KeyDown", "key_code": 37 },
2+
{ "type": "KeyDown", "key": "ArrowLeft" },
33
{ "type": "TextControl", "code": "MoveLeft" },
4-
{ "type": "KeyUp", "key_code": 37 },
4+
{ "type": "KeyUp", "key": "ArrowLeft" },
55

6-
{ "type": "KeyDown", "key_code": 39 },
6+
{ "type": "KeyDown", "key": "ArrowRight" },
77
{ "type": "TextControl", "code": "MoveRight" },
8-
{ "type": "KeyUp", "key_code": 39 },
8+
{ "type": "KeyUp", "key": "ArrowRight" },
99

10-
{ "type": "KeyDown", "key_code": 36 },
10+
{ "type": "KeyDown", "key": "Home" },
1111
{ "type": "TextControl", "code": "MoveLeftLine" },
12-
{ "type": "KeyUp", "key_code": 36 },
12+
{ "type": "KeyUp", "key": "Home" },
1313

14-
{ "type": "KeyDown", "key_code": 35 },
14+
{ "type": "KeyDown", "key": "End" },
1515
{ "type": "TextControl", "code": "MoveRightLine" },
16-
{ "type": "KeyUp", "key_code": 35 },
16+
{ "type": "KeyUp", "key": "End" },
1717

18-
{ "type": "KeyDown", "key_code": 45 },
19-
{ "type": "KeyUp", "key_code": 45 },
18+
{ "type": "KeyDown", "key": "Insert" },
19+
{ "type": "KeyUp", "key": "Insert" },
2020

21-
{ "type": "KeyDown", "key_code": 46 },
21+
{ "type": "KeyDown", "key": "Delete" },
2222
{ "type": "TextControl", "code": "Delete" },
23-
{ "type": "KeyUp", "key_code": 46 },
23+
{ "type": "KeyUp", "key": "Delete" },
2424

25-
{ "type": "KeyDown", "key_code": 8 },
25+
{ "type": "KeyDown", "key": "Backspace" },
2626
{ "type": "TextControl", "code": "Backspace" },
27-
{ "type": "KeyUp", "key_code": 8 },
27+
{ "type": "KeyUp", "key": "Backspace" },
2828

29-
{ "type": "KeyDown", "key_code": 9 },
29+
{ "type": "KeyDown", "key": "Tab" },
3030
{ "type": "TextInput", "codepoint": "\t" },
31-
{ "type": "KeyUp", "key_code": 9 },
31+
{ "type": "KeyUp", "key": "Tab" },
3232

33-
{ "type": "KeyDown", "key_code": 13 },
33+
{ "type": "KeyDown", "key": "Enter" },
3434
{ "type": "TextControl", "code": "Enter" },
35-
{ "type": "KeyUp", "key_code": 13 },
35+
{ "type": "KeyUp", "key": "Enter" },
3636

37-
{ "type": "KeyDown", "key_code": 38 },
38-
{ "type": "KeyUp", "key_code": 38 },
37+
{ "type": "KeyDown", "key": "ArrowUp" },
38+
{ "type": "KeyUp", "key": "ArrowUp" },
3939

40-
{ "type": "KeyDown", "key_code": 40 },
41-
{ "type": "KeyUp", "key_code": 40 },
40+
{ "type": "KeyDown", "key": "ArrowDown" },
41+
{ "type": "KeyUp", "key": "ArrowDown" },
4242

43-
{ "type": "KeyDown", "key_code": 33 },
44-
{ "type": "KeyUp", "key_code": 33 },
43+
{ "type": "KeyDown", "key": "PageUp" },
44+
{ "type": "KeyUp", "key": "PageUp" },
4545

46-
{ "type": "KeyDown", "key_code": 34 },
47-
{ "type": "KeyUp", "key_code": 34 },
46+
{ "type": "KeyDown", "key": "PageDown" },
47+
{ "type": "KeyUp", "key": "PageDown" },
4848

49-
{ "type": "KeyDown", "key_code": 27 },
49+
{ "type": "KeyDown", "key": "Escape" },
5050
{ "type": "TextInput", "codepoint": "\u001b" },
51-
{ "type": "KeyUp", "key_code": 27 },
51+
{ "type": "KeyUp", "key": "Escape" },
5252

53-
{ "type": "KeyDown", "key_code": 32 },
53+
{ "type": "KeyDown", "key": "Space" },
5454
{ "type": "TextInput", "codepoint": " " },
55-
{ "type": "KeyUp", "key_code": 32 }
55+
{ "type": "KeyUp", "key": "Space" }
5656
]

tests/tests/swfs/avm1/button_keypress/input.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
{
2929
"type": "KeyDown",
30-
"key_code": 13
30+
"key": "Enter"
3131
},
3232
{
3333
"type": "Wait"
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
[
2-
{ "type": "KeyDown", "key_code": 13 },
2+
{ "type": "KeyDown", "key": "Enter" },
33
{ "type": "TextControl", "code": "Enter" },
4-
{ "type": "KeyUp", "key_code": 13 },
5-
{ "type": "KeyDown", "key_code": 32 },
4+
{ "type": "KeyUp", "key": "Enter" },
5+
{ "type": "KeyDown", "key": "Space" },
66
{ "type": "TextInput", "codepoint": " " },
7-
{ "type": "KeyUp", "key_code": 32 },
8-
{ "type": "KeyDown", "key_code": 9 },
7+
{ "type": "KeyUp", "key": "Space" },
8+
{ "type": "KeyDown", "key": "Tab" },
99
{ "type": "TextInput", "codepoint": "\t" },
10-
{ "type": "KeyUp", "key_code": 9 },
11-
{ "type": "KeyDown", "key_code": 13 },
10+
{ "type": "KeyUp", "key": "Tab" },
11+
{ "type": "KeyDown", "key": "Enter" },
1212
{ "type": "TextControl", "code": "Enter" },
13-
{ "type": "KeyUp", "key_code": 13 },
14-
{ "type": "KeyDown", "key_code": 32 },
13+
{ "type": "KeyUp", "key": "Enter" },
14+
{ "type": "KeyDown", "key": "Space" },
1515
{ "type": "TextInput", "codepoint": " " },
16-
{ "type": "KeyUp", "key_code": 32 }
16+
{ "type": "KeyUp", "key": "Space" }
1717
]
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
[
2-
{ "type": "KeyDown", "key_code": 9 },
2+
{ "type": "KeyDown", "key": "Tab" },
33
{ "type": "TextInput", "codepoint": "\t" },
4-
{ "type": "KeyUp", "key_code": 9 },
5-
{ "type": "KeyDown", "key_code": 9 },
4+
{ "type": "KeyUp", "key": "Tab" },
5+
{ "type": "KeyDown", "key": "Tab" },
66
{ "type": "TextInput", "codepoint": "\t" },
7-
{ "type": "KeyUp", "key_code": 9 },
8-
{ "type": "KeyDown", "key_code": 27 },
9-
{ "type": "KeyUp", "key_code": 27 },
10-
{ "type": "KeyDown", "key_code": 9 },
7+
{ "type": "KeyUp", "key": "Tab" },
8+
{ "type": "KeyDown", "key": "Escape" },
9+
{ "type": "KeyUp", "key": "Escape" },
10+
{ "type": "KeyDown", "key": "Tab" },
1111
{ "type": "TextInput", "codepoint": "\t" },
12-
{ "type": "KeyUp", "key_code": 9 },
13-
{ "type": "KeyDown", "key_code": 9 },
12+
{ "type": "KeyUp", "key": "Tab" },
13+
{ "type": "KeyDown", "key": "Tab" },
1414
{ "type": "TextInput", "codepoint": "\t" },
15-
{ "type": "KeyUp", "key_code": 9 }
15+
{ "type": "KeyUp", "key": "Tab" }
1616
]
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[
2-
{ "type": "KeyDown", "key_code": 65 },
2+
{ "type": "KeyDown", "key": { "Char": "a" } },
33
{ "type": "TextInput", "codepoint": "a" },
4-
{ "type": "KeyUp", "key_code": 65 },
5-
{ "type": "KeyDown", "key_code": 66 },
4+
{ "type": "KeyUp", "key": { "Char": "a" } },
5+
{ "type": "KeyDown", "key": { "Char": "b" } },
66
{ "type": "TextInput", "codepoint": "b" },
7-
{ "type": "KeyUp", "key_code": 66 }
7+
{ "type": "KeyUp", "key": { "Char": "b" } }
88
]

tests/tests/swfs/avm1/edittext_input/input.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@
112112
{ "type": "TextInput", "codepoint": "𝼙" },
113113
{ "type": "TextInput", "codepoint": "𝼞" },
114114
{ "type": "TextInput", "codepoint": "" },
115-
{ "type": "KeyDown", "key_code": 27 }
115+
{ "type": "KeyDown", "key": "Escape" }
116116
]

tests/tests/swfs/avm1/edittext_input/input.json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
for ch in characters:
1414
print(f' {{ "type": "TextInput", "codepoint": "{ch}" }},')
1515

16-
print(f' {{ "type": "KeyDown", "key_code": 27 }}')
16+
print(f' {{ "type": "KeyDown", "key": "Escape" }}')
1717

1818
print(']')

tests/tests/swfs/avm1/edittext_input_newlines/input.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
{ "type": "TextInput", "codepoint": "a" },
33
{ "type": "TextControl", "code": "Enter" },
44
{ "type": "TextInput", "codepoint": "a" },
5-
{ "type": "KeyDown", "key_code": 27 },
5+
{ "type": "KeyDown", "key": "Escape" },
66
{ "type": "TextInput", "codepoint": "a" },
77
{ "type": "TextControl", "code": "Enter" },
88
{ "type": "TextInput", "codepoint": "a" },
9-
{ "type": "KeyDown", "key_code": 27 }
9+
{ "type": "KeyDown", "key": "Escape" }
1010
]

tests/tests/swfs/avm1/edittext_password_copy/input.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
{ "type": "SetClipboardText", "text": "password" },
33
{ "type": "TextControl", "code": "Paste" },
44
{ "type": "SetClipboardText", "text": "" },
5-
{ "type": "KeyDown", "key_code": 27 },
5+
{ "type": "KeyDown", "key": "Escape" },
66
{ "type": "TextControl", "code": "SelectAll" },
77
{ "type": "TextControl", "code": "Copy" },
88
{ "type": "TextControl", "code": "Paste" },
99
{ "type": "TextControl", "code": "Paste" },
10-
{ "type": "KeyDown", "key_code": 27 },
10+
{ "type": "KeyDown", "key": "Escape" },
1111
{ "type": "SetClipboardText", "text": "password" },
1212
{ "type": "TextControl", "code": "Paste" },
1313
{ "type": "SetClipboardText", "text": "" },
14-
{ "type": "KeyDown", "key_code": 27 },
14+
{ "type": "KeyDown", "key": "Escape" },
1515
{ "type": "TextControl", "code": "SelectAll" },
1616
{ "type": "TextControl", "code": "Cut" },
1717
{ "type": "TextControl", "code": "Paste" },
1818
{ "type": "TextControl", "code": "Paste" },
19-
{ "type": "KeyDown", "key_code": 27 }
19+
{ "type": "KeyDown", "key": "Escape" }
2020
]
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[
22
{ "type": "SetClipboardText", "text": "test" },
33
{ "type": "TextControl", "code": "Paste" },
4-
{ "type": "KeyDown", "key_code": 27 },
4+
{ "type": "KeyDown", "key": "Escape" },
55
{ "type": "SetClipboardText", "text": "" },
66
{ "type": "TextControl", "code": "SelectAll" },
77
{ "type": "TextControl", "code": "Paste" },
8-
{ "type": "KeyDown", "key_code": 27 }
8+
{ "type": "KeyDown", "key": "Escape" }
99
]
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[
2-
{ "type": "KeyDown", "key_code": 27 },
2+
{ "type": "KeyDown", "key": "Escape" },
33
{ "type": "MouseMove", "pos": [400, 10] },
44
{ "type": "MouseDown", "pos": [400, 10], "btn": "Left" },
55
{ "type": "MouseUp", "pos": [400, 10], "btn": "Left" },
66
{ "type": "TextInput", "codepoint": "a" },
77
{ "type": "TextInput", "codepoint": "s" },
88
{ "type": "TextInput", "codepoint": "d" },
99
{ "type": "TextInput", "codepoint": "f" },
10-
{ "type": "KeyDown", "key_code": 27 }
10+
{ "type": "KeyDown", "key": "Escape" }
1111
]

0 commit comments

Comments
 (0)