tests: Add TextField Event.CHANGE test and update test input format

This commit is contained in:
Aaron Hill 2023-07-04 14:52:06 -04:00
parent 4695d1fa63
commit bbb5619bc9
11 changed files with 110 additions and 5 deletions

View File

@ -1,4 +1,5 @@
use crate::display_object::InteractiveObject;
use serde::Deserialize;
use swf::ClipEventFlag;
#[derive(Debug, Clone, Copy)]
@ -334,7 +335,7 @@ impl<'gc> ClipEvent<'gc> {
}
/// Control inputs to a text field
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize)]
pub enum TextControlCode {
// TODO: Add control codes for Ctrl+Arrows and Home/End keys
MoveLeft,

View File

@ -19,6 +19,23 @@ pub enum MouseButton {
Right,
}
/// Control inputs to a text field
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum TextControlCode {
// TODO: Add control codes for Ctrl+Arrows and Home/End keys
MoveLeft,
MoveRight,
SelectLeft,
SelectRight,
SelectAll,
Copy,
Paste,
Cut,
Backspace,
Enter,
Delete,
}
/// All automated event types supported by FlashTAS.
///
/// A FlashTAS input file consists of a string of `AutomatedEvent`s which are
@ -47,4 +64,10 @@ pub enum AutomatedEvent {
/// Press a key
KeyDown { key_code: u8 },
/// Input a character code
TextInput { codepoint: char },
/// Input a control character code
TextControl { code: TextControlCode },
}

View File

@ -81,7 +81,10 @@ impl InputInjector {
match event {
AutomatedEvent::Wait => break,
AutomatedEvent::MouseMove { .. } | AutomatedEvent::KeyDown { .. } => {}
AutomatedEvent::MouseMove { .. }
| AutomatedEvent::KeyDown { .. }
| AutomatedEvent::TextInput { .. }
| AutomatedEvent::TextControl { .. } => {}
AutomatedEvent::MouseDown { btn, .. } => {
self.buttons |= (*btn).into();
}

View File

@ -1,5 +1,5 @@
mod format;
mod injector;
pub use format::{AutomatedEvent, MouseButton};
pub use format::{AutomatedEvent, MouseButton, TextControlCode};
pub use injector::{InputInjector, MouseButtons};

View File

@ -0,0 +1,14 @@
package {
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.InteractiveObject;
public class Main extends MovieClip {
public function Main() {
this.getChildAt(0).addEventListener("change", function(e) {
trace("New text: " + e.target.text);
});
this.stage.focus = this.getChildAt(0) as InteractiveObject;
}
}
}

View File

@ -0,0 +1,34 @@
[
{
"type": "TextInput",
"codepoint": "R"
},
{
"type": "TextInput",
"codepoint": "u"
},
{
"type": "TextInput",
"codepoint": "f"
},
{
"type": "TextInput",
"codepoint": "f"
},
{
"type": "TextInput",
"codepoint": "l"
},
{
"type": "TextInput",
"codepoint": "e"
},
{
"type": "TextControl",
"code": "Backspace"
},
{
"type": "TextInput",
"codepoint": "!"
}
]

View File

@ -0,0 +1,8 @@
New text: R
New text: Ru
New text: Ruf
New text: Ruff
New text: Ruffl
New text: Ruffle
New text: Ruffl
New text: Ruffl!

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
num_ticks = 1

View File

@ -7,13 +7,16 @@ use ruffle_core::backend::audio::{
};
use ruffle_core::backend::log::LogBackend;
use ruffle_core::backend::navigator::NullExecutor;
use ruffle_core::events::KeyCode;
use ruffle_core::events::MouseButton as RuffleMouseButton;
use ruffle_core::events::{KeyCode, TextControlCode as RuffleTextControlCode};
use ruffle_core::impl_audio_mixer_backend;
use ruffle_core::limits::ExecutionLimit;
use ruffle_core::tag_utils::SwfMovie;
use ruffle_core::{Player, PlayerBuilder, PlayerEvent};
use ruffle_input_format::{AutomatedEvent, InputInjector, MouseButton as InputMouseButton};
use ruffle_input_format::{
AutomatedEvent, InputInjector, MouseButton as InputMouseButton,
TextControlCode as InputTextControlCode,
};
use std::cell::RefCell;
use std::path::Path;
use std::rc::Rc;
@ -194,6 +197,24 @@ pub fn run_swf(
key_code: KeyCode::from_u8(*key_code).expect("Invalid keycode in test"),
key_char: None,
},
AutomatedEvent::TextInput { codepoint } => PlayerEvent::TextInput {
codepoint: *codepoint,
},
AutomatedEvent::TextControl { code } => PlayerEvent::TextControl {
code: match code {
InputTextControlCode::MoveLeft => RuffleTextControlCode::Backspace,
InputTextControlCode::MoveRight => RuffleTextControlCode::Delete,
InputTextControlCode::SelectLeft => RuffleTextControlCode::SelectLeft,
InputTextControlCode::SelectRight => RuffleTextControlCode::SelectRight,
InputTextControlCode::SelectAll => RuffleTextControlCode::SelectAll,
InputTextControlCode::Copy => RuffleTextControlCode::Copy,
InputTextControlCode::Paste => RuffleTextControlCode::Paste,
InputTextControlCode::Cut => RuffleTextControlCode::Cut,
InputTextControlCode::Backspace => RuffleTextControlCode::Backspace,
InputTextControlCode::Enter => RuffleTextControlCode::Enter,
InputTextControlCode::Delete => RuffleTextControlCode::Delete,
},
},
AutomatedEvent::Wait => unreachable!(),
});
});