From 1db34993a2060cd874380c640132244300d39e47 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Thu, 11 Jan 2024 13:22:08 +0100 Subject: [PATCH] tests: Add AutomatedEvent::SetClipboardText 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": "" }, { "type": "TextControl", "code": "Paste" }, --- tests/framework/src/backends/ui.rs | 13 ++++++++++--- tests/framework/src/runner.rs | 11 ++++++++++- tests/input-format/src/format.rs | 3 +++ tests/input-format/src/injector.rs | 3 ++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/framework/src/backends/ui.rs b/tests/framework/src/backends/ui.rs index 19909f8ae621..9232c759d87a 100644 --- a/tests/framework/src/backends/ui.rs +++ b/tests/framework/src/backends/ui.rs @@ -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, + clipboard: String, } impl TestUiBackend { pub fn new(fonts: Vec) -> Self { - Self { fonts } + Self { + fonts, + clipboard: "".to_string(), + } } } @@ -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(()) diff --git a/tests/framework/src/runner.rs b/tests/framework/src/runner.rs index e9bc81a8fe73..58572047ee37 100644 --- a/tests/framework/src/runner.rs +++ b/tests/framework/src/runner.rs @@ -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, @@ -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) diff --git a/tests/input-format/src/format.rs b/tests/input-format/src/format.rs index 853ac38a5a81..a60ac59bed44 100644 --- a/tests/input-format/src/format.rs +++ b/tests/input-format/src/format.rs @@ -70,4 +70,7 @@ pub enum AutomatedEvent { /// Input a control character code TextControl { code: TextControlCode }, + + /// Populate clipboard with the given text + SetClipboardText { text: String }, } diff --git a/tests/input-format/src/injector.rs b/tests/input-format/src/injector.rs index 700c3105b7af..3486e132a160 100644 --- a/tests/input-format/src/injector.rs +++ b/tests/input-format/src/injector.rs @@ -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(); }