Skip to content

Commit

Permalink
tests: Add AutomatedEvent::SetClipboardText
Browse files Browse the repository at this point in the history
Currently in tests (input.json) it is possible to trigger Ctrl-V using:

    { "type": "TextControl", "code": "Paste" },

But there is no way of populating the clipboard.
This patch adds AutomatedEvent::SetClipboardText, so the clipboard
may be populated before pasting:

    { "type": "SetClipboardText", "text": "<value>" },
    { "type": "TextControl", "code": "Paste" },
  • Loading branch information
kjarosh authored and Dinnerbone committed Jan 11, 2024
1 parent 2ef63d3 commit 1db3499
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
13 changes: 10 additions & 3 deletions tests/framework/src/backends/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,18 @@ impl FileDialogResult for TestFileDialogResult {
/// otherwise a user cancellation will be simulated
/// * Attempting to display a file save dialog with a file name hint of "debug-success.txt" will simulate successfully selecting a destination
/// otherwise a user cancellation will be simulated
/// * Simulated in-memory clipboard
pub struct TestUiBackend {
fonts: Vec<Font>,
clipboard: String,
}

impl TestUiBackend {
pub fn new(fonts: Vec<Font>) -> Self {
Self { fonts }
Self {
fonts,
clipboard: "".to_string(),
}
}
}

Expand All @@ -97,10 +102,12 @@ impl UiBackend for TestUiBackend {
fn set_mouse_cursor(&mut self, _cursor: MouseCursor) {}

fn clipboard_content(&mut self) -> String {
"".to_string()
self.clipboard.clone()
}

fn set_clipboard_content(&mut self, _content: String) {}
fn set_clipboard_content(&mut self, content: String) {
self.clipboard = content;
}

fn set_fullscreen(&mut self, _is_full: bool) -> Result<(), FullscreenError> {
Ok(())
Expand Down
11 changes: 10 additions & 1 deletion tests/framework/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ pub fn run_swf(
}

injector.next(|evt, _btns_down| {
if let AutomatedEvent::SetClipboardText { text } = evt {
player
.lock()
.unwrap()
.ui_mut()
.set_clipboard_content(text.to_owned());
return;
}

player.lock().unwrap().handle_event(match evt {
AutomatedEvent::MouseDown { pos, btn } => PlayerEvent::MouseDown {
x: pos.0,
Expand Down Expand Up @@ -202,7 +211,7 @@ pub fn run_swf(
InputTextControlCode::Delete => RuffleTextControlCode::Delete,
},
},
AutomatedEvent::Wait => unreachable!(),
AutomatedEvent::Wait | AutomatedEvent::SetClipboardText { .. } => unreachable!(),
});
});
// Rendering has side-effects (such as processing 'DisplayObject.scrollRect' updates)
Expand Down
3 changes: 3 additions & 0 deletions tests/input-format/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ pub enum AutomatedEvent {

/// Input a control character code
TextControl { code: TextControlCode },

/// Populate clipboard with the given text
SetClipboardText { text: String },
}
3 changes: 2 additions & 1 deletion tests/input-format/src/injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ impl InputInjector {
AutomatedEvent::MouseMove { .. }
| AutomatedEvent::KeyDown { .. }
| AutomatedEvent::TextInput { .. }
| AutomatedEvent::TextControl { .. } => {}
| AutomatedEvent::TextControl { .. }
| AutomatedEvent::SetClipboardText { .. } => {}
AutomatedEvent::MouseDown { btn, .. } => {
self.buttons |= (*btn).into();
}
Expand Down

0 comments on commit 1db3499

Please sign in to comment.