1// Copyright 2020 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45use crate::{input_device, input_handler};
6use async_trait::async_trait;
7use futures::channel::mpsc::Sender;
8use std::cell::RefCell;
9use std::rc::Rc;
1011/// A fake [`InputHandler`] used for testing.
12/// A [`ObserveFakeEventsInputHandler`] does not consume InputEvents.
13pub struct ObserveFakeEventsInputHandler {
14/// Events received by [`handle_input_event()`] are sent to this channel.
15event_sender: RefCell<Sender<input_device::InputEvent>>,
16}
1718#[cfg(test)]
19impl ObserveFakeEventsInputHandler {
20pub fn new(event_sender: Sender<input_device::InputEvent>) -> Rc<Self> {
21 Rc::new(ObserveFakeEventsInputHandler { event_sender: RefCell::new(event_sender) })
22 }
23}
2425#[async_trait(?Send)]
26impl input_handler::InputHandler for ObserveFakeEventsInputHandler {
27async fn handle_input_event(
28self: Rc<Self>,
29 input_event: input_device::InputEvent,
30 ) -> Vec<input_device::InputEvent> {
31match self.event_sender.borrow_mut().try_send(input_event.clone()) {
32Err(_) => assert!(false),
33_ => {}
34 };
3536vec![input_event]
37 }
3839fn set_handler_healthy(self: std::rc::Rc<Self>) {
40// No inspect data on ObserveFakeEventsInputHandler. Do nothing.
41}
4243fn set_handler_unhealthy(self: std::rc::Rc<Self>, _msg: &str) {
44// No inspect data on ObserveFakeEventsInputHandler. Do nothing.
45}
46}