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": "<value>" }, { "type": "TextControl", "code": "Paste" },
This commit is contained in:
parent
2ef63d3a61
commit
1db34993a2
|
@ -77,13 +77,18 @@ impl FileDialogResult for TestFileDialogResult {
|
||||||
/// otherwise a user cancellation will be simulated
|
/// 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
|
/// * 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
|
/// otherwise a user cancellation will be simulated
|
||||||
|
/// * Simulated in-memory clipboard
|
||||||
pub struct TestUiBackend {
|
pub struct TestUiBackend {
|
||||||
fonts: Vec<Font>,
|
fonts: Vec<Font>,
|
||||||
|
clipboard: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestUiBackend {
|
impl TestUiBackend {
|
||||||
pub fn new(fonts: Vec<Font>) -> Self {
|
pub fn new(fonts: Vec<Font>) -> 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 set_mouse_cursor(&mut self, _cursor: MouseCursor) {}
|
||||||
|
|
||||||
fn clipboard_content(&mut self) -> String {
|
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> {
|
fn set_fullscreen(&mut self, _is_full: bool) -> Result<(), FullscreenError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -160,6 +160,15 @@ pub fn run_swf(
|
||||||
}
|
}
|
||||||
|
|
||||||
injector.next(|evt, _btns_down| {
|
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 {
|
player.lock().unwrap().handle_event(match evt {
|
||||||
AutomatedEvent::MouseDown { pos, btn } => PlayerEvent::MouseDown {
|
AutomatedEvent::MouseDown { pos, btn } => PlayerEvent::MouseDown {
|
||||||
x: pos.0,
|
x: pos.0,
|
||||||
|
@ -202,7 +211,7 @@ pub fn run_swf(
|
||||||
InputTextControlCode::Delete => RuffleTextControlCode::Delete,
|
InputTextControlCode::Delete => RuffleTextControlCode::Delete,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AutomatedEvent::Wait => unreachable!(),
|
AutomatedEvent::Wait | AutomatedEvent::SetClipboardText { .. } => unreachable!(),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Rendering has side-effects (such as processing 'DisplayObject.scrollRect' updates)
|
// Rendering has side-effects (such as processing 'DisplayObject.scrollRect' updates)
|
||||||
|
|
|
@ -70,4 +70,7 @@ pub enum AutomatedEvent {
|
||||||
|
|
||||||
/// Input a control character code
|
/// Input a control character code
|
||||||
TextControl { code: TextControlCode },
|
TextControl { code: TextControlCode },
|
||||||
|
|
||||||
|
/// Populate clipboard with the given text
|
||||||
|
SetClipboardText { text: String },
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,8 @@ impl InputInjector {
|
||||||
AutomatedEvent::MouseMove { .. }
|
AutomatedEvent::MouseMove { .. }
|
||||||
| AutomatedEvent::KeyDown { .. }
|
| AutomatedEvent::KeyDown { .. }
|
||||||
| AutomatedEvent::TextInput { .. }
|
| AutomatedEvent::TextInput { .. }
|
||||||
| AutomatedEvent::TextControl { .. } => {}
|
| AutomatedEvent::TextControl { .. }
|
||||||
|
| AutomatedEvent::SetClipboardText { .. } => {}
|
||||||
AutomatedEvent::MouseDown { btn, .. } => {
|
AutomatedEvent::MouseDown { btn, .. } => {
|
||||||
self.buttons |= (*btn).into();
|
self.buttons |= (*btn).into();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue