leejunyoung5819 wayland-android-remote
공개Ubuntu(Wayland/X11)에서 Android 기기 화면 미러링 및 원격 제어 (Rust)
| 1 | //! 마우스 조작 시뮬레이션: 아이콘 클릭과 빈 공간 드래그(창 이동)가 서로 가로채지 않는지 확인한다. |
| 2 | |
| 3 | use egui::{Pos2, Rect, pos2, vec2}; |
| 4 | use egui_kittest::Harness; |
| 5 | use wayland_android_remote::protocol::{AuthGrant, SystemAction}; |
| 6 | |
| 7 | use super::conn::ConnEvent; |
| 8 | use super::layout; |
| 9 | use super::view::{Actions, View}; |
| 10 | |
| 11 | #[derive(Default)] |
| 12 | struct Recorded { |
| 13 | screen: Option<Rect>, |
| 14 | drag: bool, |
| 15 | open_settings: bool, |
| 16 | system: Option<SystemAction>, |
| 17 | } |
| 18 | |
| 19 | struct State { |
| 20 | view: View, |
| 21 | rec: Recorded, |
| 22 | } |
| 23 | |
| 24 | fn harness(connected: bool) -> Harness<'static, State> { |
| 25 | let mut view = View::for_test(); |
| 26 | if connected { |
| 27 | view.start_connecting_for_test("10.0.0.2:27200".parse().unwrap()); |
| 28 | view.on_conn_event(ConnEvent::Connected { |
| 29 | grant: AuthGrant::Always, |
| 30 | }); |
| 31 | } |
| 32 | let size = view.window_size(); |
| 33 | let state = State { |
| 34 | view, |
| 35 | rec: Recorded::default(), |
| 36 | }; |
| 37 | let mut h = Harness::builder() |
| 38 | .with_size(size) |
| 39 | .with_accessibility_check(false) |
| 40 | .with_context_setup(super::fonts::install_korean_font_owned) |
| 41 | .build_ui_state( |
| 42 | |ui, s: &mut State| { |
| 43 | s.rec.screen = Some(ui.max_rect()); |
| 44 | let mut a = Actions::default(); |
| 45 | s.view.ui(ui, &mut a); |
| 46 | s.rec.drag |= a.start_drag; |
| 47 | s.rec.open_settings |= a.open_settings; |
| 48 | s.rec.system = s.rec.system.or(a.system_action); |
| 49 | }, |
| 50 | state, |
| 51 | ); |
| 52 | h.run(); |
| 53 | h |
| 54 | } |
| 55 | |
| 56 | fn layout_of(h: &Harness<'_, State>) -> layout::Layout { |
| 57 | layout::compute(h.state().rec.screen.unwrap()) |
| 58 | } |
| 59 | |
| 60 | fn click(h: &mut Harness<'_, State>, p: Pos2) { |
| 61 | // 누르고 바로 떼는 짧은 클릭. run()은 여러 프레임을 돌려 길게 누른 것처럼 될 수 있어 step()을 쓴다. |
| 62 | h.hover_at(p); |
| 63 | h.step(); |
| 64 | h.drag_at(p); |
| 65 | h.step(); |
| 66 | h.drop_at(p); |
| 67 | h.step(); |
| 68 | } |
| 69 | |
| 70 | fn drag(h: &mut Harness<'_, State>, from: Pos2) { |
| 71 | h.hover_at(from); |
| 72 | h.drag_at(from); |
| 73 | h.run(); |
| 74 | h.hover_at(from + vec2(25.0, 25.0)); |
| 75 | h.run(); |
| 76 | h.drop_at(from + vec2(25.0, 25.0)); |
| 77 | h.run(); |
| 78 | } |
| 79 | |
| 80 | #[test] |
| 81 | fn clicking_settings_icon_opens_settings_without_moving_window() { |
| 82 | let mut h = harness(false); |
| 83 | let l = layout_of(&h); |
| 84 | click(&mut h, layout::rail_slot(l.rail, 0, false).center()); |
| 85 | assert!(h.state().rec.open_settings); |
| 86 | assert!(!h.state().rec.drag); |
| 87 | } |
| 88 | |
| 89 | #[test] |
| 90 | fn dragging_empty_rail_moves_window() { |
| 91 | let mut h = harness(false); |
| 92 | let l = layout_of(&h); |
| 93 | drag(&mut h, pos2(l.rail.center().x, l.rail.center().y)); |
| 94 | assert!(h.state().rec.drag); |
| 95 | assert!(!h.state().rec.open_settings); |
| 96 | } |
| 97 | |
| 98 | #[test] |
| 99 | fn dragging_empty_nav_bar_moves_window() { |
| 100 | let mut h = harness(true); |
| 101 | let l = layout_of(&h); |
| 102 | drag(&mut h, pos2(l.nav_bar.min.x + 8.0, l.nav_bar.center().y)); |
| 103 | assert!(h.state().rec.drag); |
| 104 | assert_eq!(h.state().rec.system, None); |
| 105 | } |
| 106 | |
| 107 | #[test] |
| 108 | fn clicking_nav_button_sends_system_action() { |
| 109 | let mut h = harness(true); |
| 110 | let l = layout_of(&h); |
| 111 | let [back, home, _recents] = layout::nav_slots(l.nav_bar); |
| 112 | click(&mut h, back.center()); |
| 113 | assert_eq!(h.state().rec.system, Some(SystemAction::Back)); |
| 114 | assert!(!h.state().rec.drag); |
| 115 | |
| 116 | let mut h = harness(true); |
| 117 | click(&mut h, home.center()); |
| 118 | assert_eq!(h.state().rec.system, Some(SystemAction::Home)); |
| 119 | } |
| 120 | |
| 121 | #[test] |
| 122 | fn dragging_title_bar_still_moves_window() { |
| 123 | let mut h = harness(false); |
| 124 | let l = layout_of(&h); |
| 125 | drag(&mut h, l.title_bar.left_center() + vec2(40.0, 0.0)); |
| 126 | assert!(h.state().rec.drag); |
| 127 | } |
| 128 | |
| 129 | fn side_button(h: &mut Harness<'_, State>, p: Pos2, button: egui::PointerButton) { |
| 130 | h.hover_at(p); |
| 131 | h.step(); |
| 132 | for pressed in [true, false] { |
| 133 | h.event(egui::Event::PointerButton { |
| 134 | pos: p, |
| 135 | button, |
| 136 | pressed, |
| 137 | modifiers: egui::Modifiers::NONE, |
| 138 | }); |
| 139 | h.step(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | #[test] |
| 144 | fn mouse_back_side_button_sends_back_when_connected() { |
| 145 | let mut h = harness(true); |
| 146 | let l = layout_of(&h); |
| 147 | side_button(&mut h, l.viewport.center(), egui::PointerButton::Extra1); |
| 148 | assert_eq!(h.state().rec.system, Some(SystemAction::Back)); |
| 149 | assert!(!h.state().rec.drag); |
| 150 | } |
| 151 | |
| 152 | #[test] |
| 153 | fn other_mouse_buttons_send_nothing() { |
| 154 | let mut h = harness(true); |
| 155 | let l = layout_of(&h); |
| 156 | for button in [ |
| 157 | egui::PointerButton::Secondary, |
| 158 | egui::PointerButton::Middle, |
| 159 | egui::PointerButton::Extra2, |
| 160 | ] { |
| 161 | side_button(&mut h, l.viewport.center(), button); |
| 162 | } |
| 163 | assert_eq!(h.state().rec.system, None); |
| 164 | } |
| 165 | |
| 166 | #[test] |
| 167 | fn mouse_back_side_button_ignored_when_disconnected() { |
| 168 | let mut h = harness(false); |
| 169 | let l = layout_of(&h); |
| 170 | side_button(&mut h, l.viewport.center(), egui::PointerButton::Extra1); |
| 171 | assert_eq!(h.state().rec.system, None); |
| 172 | } |