test
This commit is contained in:
@@ -241,7 +241,7 @@ impl EditorTestContext {
|
||||
// so you can use it to test detailed timing
|
||||
pub fn simulate_keystroke(&mut self, keystroke_text: &str) {
|
||||
let keyboard_mapper = self.keyboard_mapper();
|
||||
let keystroke = Keystroke::parse(keystroke_text, keyboard_mapper).unwrap();
|
||||
let keystroke = Keystroke::parse(keystroke_text, keyboard_mapper.as_ref()).unwrap();
|
||||
self.cx.dispatch_keystroke(self.window, keystroke);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ pub struct TestAppContext {
|
||||
pub dispatcher: TestDispatcher,
|
||||
test_platform: Rc<TestPlatform>,
|
||||
text_system: Arc<TextSystem>,
|
||||
keyboard_mapper: Rc<Box<dyn PlatformKeyboardMapper>>,
|
||||
fn_name: Option<&'static str>,
|
||||
on_quit: Rc<RefCell<Vec<Box<dyn FnOnce() + 'static>>>>,
|
||||
}
|
||||
@@ -122,7 +121,6 @@ impl TestAppContext {
|
||||
let asset_source = Arc::new(());
|
||||
let http_client = http_client::FakeHttpClient::with_404_response();
|
||||
let text_system = Arc::new(TextSystem::new(platform.text_system()));
|
||||
let keyboard_mapper = std::rc::Rc::new(platform.keyboard_mapper());
|
||||
|
||||
Self {
|
||||
app: App::new_app(platform.clone(), asset_source, http_client),
|
||||
@@ -131,7 +129,6 @@ impl TestAppContext {
|
||||
dispatcher: dispatcher.clone(),
|
||||
test_platform: platform,
|
||||
text_system,
|
||||
keyboard_mapper,
|
||||
fn_name,
|
||||
on_quit: Rc::new(RefCell::new(Vec::default())),
|
||||
}
|
||||
@@ -401,8 +398,8 @@ impl TestAppContext {
|
||||
}
|
||||
|
||||
/// Returns the current keyboard mapper for this platform.
|
||||
pub fn keyboard_mapper(&self) -> Rc<Box<dyn PlatformKeyboardMapper>> {
|
||||
self.keyboard_mapper.clone()
|
||||
pub fn keyboard_mapper(&self) -> Rc<dyn PlatformKeyboardMapper> {
|
||||
self.test_platform.keyboard_mapper()
|
||||
}
|
||||
|
||||
/// simulate_keystrokes takes a space-separated list of keys to type.
|
||||
|
||||
@@ -541,11 +541,11 @@ mod test {
|
||||
let keyboard_mapper = cx.keyboard_mapper();
|
||||
cx.dispatch_keystroke(
|
||||
*window,
|
||||
Keystroke::parse("a", keyboard_mapper.as_ref().as_ref()).unwrap(),
|
||||
Keystroke::parse("a", keyboard_mapper.as_ref()).unwrap(),
|
||||
);
|
||||
cx.dispatch_keystroke(
|
||||
*window,
|
||||
Keystroke::parse("ctrl-g", keyboard_mapper.as_ref().as_ref()).unwrap(),
|
||||
Keystroke::parse("ctrl-g", keyboard_mapper.as_ref()).unwrap(),
|
||||
);
|
||||
|
||||
window
|
||||
|
||||
@@ -236,7 +236,7 @@ pub(crate) trait Platform: 'static {
|
||||
fn read_credentials(&self, url: &str) -> Task<Result<Option<(String, Vec<u8>)>>>;
|
||||
fn delete_credentials(&self, url: &str) -> Task<Result<()>>;
|
||||
|
||||
fn keyboard_mapper(&self) -> Box<dyn PlatformKeyboardMapper>;
|
||||
fn keyboard_mapper(&self) -> Rc<dyn PlatformKeyboardMapper>;
|
||||
fn keyboard_layout(&self) -> Box<dyn PlatformKeyboardLayout>;
|
||||
fn on_keyboard_layout_change(&self, callback: Box<dyn FnMut()>);
|
||||
}
|
||||
|
||||
@@ -139,14 +139,14 @@ impl<P: LinuxClient + 'static> Platform for P {
|
||||
self.with_common(|common| common.text_system.clone())
|
||||
}
|
||||
|
||||
fn keyboard_mapper(&self) -> Box<dyn PlatformKeyboardMapper> {
|
||||
fn keyboard_mapper(&self) -> Rc<dyn PlatformKeyboardMapper> {
|
||||
#[cfg(any(feature = "wayland", feature = "x11"))]
|
||||
{
|
||||
Box::new(super::LinuxKeyboardMapper::new())
|
||||
Rc::new(super::LinuxKeyboardMapper::new())
|
||||
}
|
||||
#[cfg(not(any(feature = "wayland", feature = "x11")))]
|
||||
{
|
||||
Box::new(crate::EmptyKeyboardMapper)
|
||||
Rc::new(crate::EmptyKeyboardMapper)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ pub(crate) struct TestPlatform {
|
||||
screen_capture_sources: RefCell<Vec<TestScreenCaptureSource>>,
|
||||
pub opened_url: RefCell<Option<String>>,
|
||||
pub text_system: Arc<dyn PlatformTextSystem>,
|
||||
keyboard_mapper: Rc<dyn PlatformKeyboardMapper>,
|
||||
#[cfg(target_os = "windows")]
|
||||
bitmap_factory: std::mem::ManuallyDrop<IWICImagingFactory>,
|
||||
weak: Weak<Self>,
|
||||
@@ -93,6 +94,7 @@ impl TestPlatform {
|
||||
};
|
||||
|
||||
let text_system = Arc::new(NoopTextSystem);
|
||||
let keyboard_mapper = Rc::new(TestKeyboardMapper::new());
|
||||
|
||||
Rc::new_cyclic(|weak| TestPlatform {
|
||||
background_executor: executor,
|
||||
@@ -110,6 +112,7 @@ impl TestPlatform {
|
||||
#[cfg(target_os = "windows")]
|
||||
bitmap_factory,
|
||||
text_system,
|
||||
keyboard_mapper,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -224,8 +227,8 @@ impl Platform for TestPlatform {
|
||||
self.text_system.clone()
|
||||
}
|
||||
|
||||
fn keyboard_mapper(&self) -> Box<dyn PlatformKeyboardMapper> {
|
||||
Box::new(TestKeyboardMapper::new())
|
||||
fn keyboard_mapper(&self) -> Rc<dyn PlatformKeyboardMapper> {
|
||||
self.keyboard_mapper.clone()
|
||||
}
|
||||
|
||||
fn keyboard_layout(&self) -> Box<dyn PlatformKeyboardLayout> {
|
||||
|
||||
Reference in New Issue
Block a user