Skip to content

Commit

Permalink
CI: Improved test coverage of mouse
Browse files Browse the repository at this point in the history
Test relative and absolute mouse moves in the CI. Run more unit tests concerning mouse movement as well
  • Loading branch information
pentamassiv committed Nov 29, 2024
1 parent 367f890 commit 5a01f34
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
18 changes: 5 additions & 13 deletions src/tests/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ use std::thread;

use super::is_ci;

// TODO: Mouse acceleration on Windows will result in the wrong coordinates when
// doing a relative mouse move The Github runner has the following settings:
// MouseSpeed 1
// MouseThreshold1 6
// MouseThreshold2 10
// Maybe they can be used to calculate the resulting location even with enabled
// mouse acceleration
fn test_mouse_move(
enigo: &mut Enigo,
test_cases: Vec<Vec<((i32, i32), (i32, i32))>>,
Expand All @@ -31,6 +24,7 @@ fn test_mouse_move(
};

enigo.move_mouse(start.0, start.1, Abs).unwrap(); // Move to absolute start position
thread::sleep(delay);

for test_case in test_cases {
for mouse_action in test_case {
Expand Down Expand Up @@ -71,7 +65,6 @@ fn unit_move_mouse_to() {
test_mouse_move(&mut enigo, test_cases, Abs, (0, 0));
}

#[ignore]
#[test]
// Test the move_mouse function and check it with the mouse_location
// function
Expand Down Expand Up @@ -105,7 +98,7 @@ fn unit_move_mouse_to_boundaries() {
let screen_boundaries = vec![
((-3, 8), (0, 8)), // Negative x coordinate
((8, -3), (8, 0)), // Negative y coordinate
((-30, -3), (0, 0)), // Try to go to negative x and y coordinates
((-30, -3), (0, 0)), // Negative x and y coordinates
((567_546_546, 20), (display_size.0 - 1, 20)), // Huge x coordinate > screen width
((20, 567_546_546), (20, display_size.1 - 1)), // Huge y coordinate > screen heigth
(
Expand All @@ -129,7 +122,7 @@ fn unit_move_mouse_to_boundaries() {
test_mouse_move(&mut enigo, test_cases, Abs, (0, 0));
}

#[ignore] // TODO: Mouse acceleration on Windows will result in the wrong coordinates
#[ignore]
#[test]
// Test the move_mouse function and check it with the mouse_location
// function
Expand All @@ -143,7 +136,7 @@ fn unit_move_mouse_rel_boundaries() {
let screen_boundaries = vec![
((-3, 8), (0, 8)), // Negative x coordinate
((8, -10), (8, 0)), // Negative y coordinate
((-30, -3), (0, 0)), // Try to go to negative x and y coordinates
((-30, -3), (0, 0)), // Negative x and y coordinates
((567_546_546, 20), (display_size.0 - 1, 20)), // Huge x coordinate > screen width
((20, 567_546_546), (display_size.0 - 1, display_size.1 - 1)), /* Huge y coordinate >
* screen heigth */
Expand Down Expand Up @@ -240,7 +233,7 @@ fn unit_10th_click() {
}
}

#[ignore] // Hangs with x11rb
#[cfg(not(feature = "x11rb"))] // For some reason it stalls
#[test]
fn unit_scroll() {
let delay = super::get_delay();
Expand All @@ -266,7 +259,6 @@ fn unit_scroll() {
}
}

#[ignore] // Contains a relative mouse move so it does not work on Windows
#[test]
// Press down and drag the mouse
fn unit_mouse_drag() {
Expand Down
45 changes: 26 additions & 19 deletions tests/integration_browser.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use enigo::{
Axis::{Horizontal, Vertical},
// Button,
Coordinate::{Abs, Rel},
Direction::{Click, Press, Release},
Key, Keyboard, Settings,
Key,
Keyboard,
Mouse as _,
Settings,
};

mod common;
Expand All @@ -10,29 +16,30 @@ use common::enigo_test::EnigoTest as Enigo;
fn integration_browser_events() {
let mut enigo = Enigo::new(&Settings::default());

enigo.text("TestText❤️").unwrap(); // Fails on Windows (Message is empty???)
enigo.text("TestText❤️").unwrap();
enigo.key(Key::F1, Click).unwrap();
enigo.key(Key::Control, Click).unwrap();
enigo.key(Key::Backspace, Click).unwrap();
enigo.key(Key::PageUp, Click).unwrap(); // Failing on Windows
enigo.key(Key::PageUp, Click).unwrap();

enigo.key(Key::Backspace, Press).unwrap();
enigo.key(Key::Backspace, Release).unwrap();

println!("Test mouse"); /*
enigo.button(Button::Left, Click).unwrap();
enigo.move_mouse(100, 100, Abs).unwrap();
enigo.move_mouse(200, 200, Abs).unwrap();
// let (x, y) = enigo.location().unwrap();
// assert_eq!((200, 200), (x, y));
// Relative moves fail on Windows
// For some reason the values are wrong
// enigo.move_mouse(20, 20, Rel).unwrap();
// enigo.move_mouse(-20, 20, Rel).unwrap();
// enigo.move_mouse(20, -20, Rel).unwrap();
// enigo.move_mouse(-20, -20, Rel).unwrap();
// enigo.scroll(1, Vertical).unwrap();
// enigo.scroll(1, Horizontal).unwrap(); Fails on Windows
enigo.main_display().unwrap();
enigo.location().unwrap(); */
println!("Test mouse");
// enigo.button(Button::Left, Click).unwrap();
enigo.move_mouse(100, 100, Abs).unwrap();
enigo.move_mouse(200, 200, Abs).unwrap();
let (x, y) = enigo.location().unwrap();
assert_eq!((200, 200), (x, y));
enigo.move_mouse(20, 20, Rel).unwrap();
enigo.move_mouse(-20, 20, Rel).unwrap();
enigo.move_mouse(20, -20, Rel).unwrap();
enigo.move_mouse(-20, -20, Rel).unwrap();

// Stalls on Windows, macOS and Linux with x11rb
// enigo.scroll(1, Vertical).unwrap();
// enigo.scroll(1, Horizontal).unwrap();

enigo.main_display().unwrap();
enigo.location().unwrap();
}

0 comments on commit 5a01f34

Please sign in to comment.