Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 1 addition & 63 deletions packages/rsnap-overlay/src/overlay/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::overlay::{
SELECTION_SIZE_BADGE_INSIDE_MARGIN_PX, SELECTION_SIZE_BADGE_SCREEN_MARGIN_PX,
SelectionDashedBorderCache, SelectionDashedBorderMetrics, SelectionFlowGeometryCache,
SelectionSizeBadgeTarget, SurfaceFrameSkipReason, TOOLBAR_CAPTURE_GAP_PX,
TOOLBAR_SCREEN_MARGIN_PX, ToolbarPlacement, Vec2, WindowRenderer, hud_helpers, regular,
TOOLBAR_SCREEN_MARGIN_PX, ToolbarPlacement, Vec2, WindowRenderer, hud_helpers,
};
#[cfg(target_os = "macos")]
use crate::overlay::{
Expand Down Expand Up @@ -1201,26 +1201,6 @@ fn downward_frame_motion_commits_even_with_legacy_upward_input_direction() {
);
}

#[cfg(target_os = "macos")]
#[test]
fn positive_pixel_delta_maps_to_upward_scroll_capture() {
assert_eq!(
OverlaySession::scroll_capture_direction_from_wheel_delta(&MouseScrollDelta::PixelDelta(
PhysicalPosition::new(0.0, 2.0)
)),
Some(ScrollDirection::Up)
);
}

#[cfg(target_os = "macos")]
#[test]
fn macos_scroll_wheel_events_use_hid_system_source_state() {
assert_eq!(
super::macos_hid_event_source_state_id(),
super::KCG_EVENT_SOURCE_STATE_HID_SYSTEM_STATE
);
}

#[cfg(target_os = "macos")]
#[test]
fn pixel_delta_residuals_accumulate_until_whole_pixels_emit() {
Expand All @@ -1245,48 +1225,6 @@ fn pixel_delta_residuals_accumulate_until_whole_pixels_emit() {
assert!((second.residual.y + 0.2).abs() < 1e-9);
}

#[test]
fn frozen_toolbar_mode_tools_are_identifiable() {
assert!(FrozenToolbarTool::Pointer.is_mode_tool());
assert!(FrozenToolbarTool::Pen.is_mode_tool());
assert!(FrozenToolbarTool::Text.is_mode_tool());
assert!(FrozenToolbarTool::Mosaic.is_mode_tool());
}

#[test]
fn frozen_toolbar_action_tools_are_not_mode_tools() {
assert!(!FrozenToolbarTool::Undo.is_mode_tool());
assert!(!FrozenToolbarTool::Redo.is_mode_tool());
assert!(!FrozenToolbarTool::AutoCenter.is_mode_tool());
assert!(!FrozenToolbarTool::Scroll.is_mode_tool());
assert!(!FrozenToolbarTool::Copy.is_mode_tool());
assert!(!FrozenToolbarTool::Save.is_mode_tool());
#[cfg(target_os = "macos")]
assert!(!FrozenToolbarTool::Ocr.is_mode_tool());
}

#[test]
fn frozen_toolbar_scroll_tool_uses_scroll_specific_iconography() {
assert_eq!(FrozenToolbarTool::Scroll.label(), "Scroll Capture");
assert_eq!(FrozenToolbarTool::Scroll.icon(), regular::MOUSE_SCROLL);
}

#[test]
fn frozen_toolbar_export_tools_require_final_capture() {
assert!(!FrozenToolbarTool::Pointer.requires_final_capture());
assert!(!FrozenToolbarTool::Pen.requires_final_capture());
assert!(!FrozenToolbarTool::Text.requires_final_capture());
assert!(!FrozenToolbarTool::Mosaic.requires_final_capture());
assert!(!FrozenToolbarTool::Undo.requires_final_capture());
assert!(!FrozenToolbarTool::Redo.requires_final_capture());
assert!(!FrozenToolbarTool::AutoCenter.requires_final_capture());
assert!(FrozenToolbarTool::Scroll.requires_final_capture());
assert!(FrozenToolbarTool::Copy.requires_final_capture());
assert!(FrozenToolbarTool::Save.requires_final_capture());
#[cfg(target_os = "macos")]
assert!(FrozenToolbarTool::Ocr.requires_final_capture());
}

#[test]
fn frozen_toolbar_selected_mode_uses_fill_without_border() {
for theme in [HudTheme::Dark, HudTheme::Light] {
Expand Down
221 changes: 0 additions & 221 deletions packages/rsnap-overlay/src/overlay/tests/rendering_behaviors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,227 +345,6 @@ fn scroll_capture_and_export_wait_for_authoritative_frozen_capture() {
assert_eq!(session.state.error_message.as_deref(), Some("Preparing capture..."));
}

#[test]
fn frozen_selection_scrim_rects_frame_focus_rect_without_covering_it() {
let screen_rect = Rect::from_min_size(Pos2::ZERO, Vec2::new(100.0, 80.0));
let focus_rect = Rect::from_min_size(Pos2::new(20.0, 10.0), Vec2::new(40.0, 30.0));
let scrim_rects = WindowRenderer::frozen_selection_scrim_rects(screen_rect, focus_rect);

assert_eq!(
scrim_rects,
[
Rect::from_min_max(Pos2::new(0.0, 0.0), Pos2::new(100.0, 10.0)),
Rect::from_min_max(Pos2::new(0.0, 40.0), Pos2::new(100.0, 80.0)),
Rect::from_min_max(Pos2::new(0.0, 10.0), Pos2::new(20.0, 40.0)),
Rect::from_min_max(Pos2::new(60.0, 10.0), Pos2::new(100.0, 40.0)),
]
);
assert!(scrim_rects.into_iter().all(|rect| !rect.contains(focus_rect.center())));
}

#[test]
fn frozen_selection_scrim_rects_leave_zero_area_regions_at_screen_edges() {
let screen_rect = Rect::from_min_size(Pos2::ZERO, Vec2::new(100.0, 80.0));
let focus_rect = Rect::from_min_size(Pos2::new(0.0, 10.0), Vec2::new(40.0, 30.0));
let scrim_rects = WindowRenderer::frozen_selection_scrim_rects(screen_rect, focus_rect);
let non_empty =
scrim_rects.iter().filter(|rect| rect.width() > 0.0 && rect.height() > 0.0).count();

assert_eq!(scrim_rects[2].width(), 0.0);
assert_eq!(non_empty, 3);
}

#[test]
fn frozen_selection_scrim_rects_are_empty_for_fullscreen_rect() {
let screen_rect = Rect::from_min_size(Pos2::ZERO, Vec2::new(100.0, 80.0));
let scrim_rects = WindowRenderer::frozen_selection_scrim_rects(screen_rect, screen_rect);

assert!(scrim_rects.into_iter().all(|rect| rect.width() <= 0.0 || rect.height() <= 0.0));
}

#[test]
fn selection_dashed_border_rect_is_absent_for_fullscreen_rect() {
let screen_rect = Rect::from_min_size(Pos2::ZERO, Vec2::new(100.0, 80.0));
let border_outset =
WindowRenderer::selection_dashed_border_outset(SELECTION_DASHED_BORDER_WIDTH_PX, 1.0);

assert_eq!(
WindowRenderer::selection_dashed_border_rect(screen_rect, screen_rect, border_outset,),
None
);
}

#[test]
fn selection_dashed_border_rect_expands_focus_rect_outward() {
let screen_rect = Rect::from_min_size(Pos2::ZERO, Vec2::new(100.0, 80.0));
let focus_rect = Rect::from_min_size(Pos2::new(20.0, 10.0), Vec2::new(40.0, 30.0));
let border_outset =
WindowRenderer::selection_dashed_border_outset(SELECTION_DASHED_BORDER_WIDTH_PX, 1.0);

assert_eq!(
WindowRenderer::selection_dashed_border_rect(screen_rect, focus_rect, border_outset,),
Some(Rect::from_min_max(Pos2::new(18.5, 8.5), Pos2::new(61.5, 41.5),))
);
}

#[test]
fn selection_dashed_border_rect_can_extend_beyond_screen_edge() {
let screen_rect = Rect::from_min_size(Pos2::ZERO, Vec2::new(100.0, 80.0));
let focus_rect = Rect::from_min_size(Pos2::new(0.0, 10.0), Vec2::new(40.0, 30.0));
let border_outset =
WindowRenderer::selection_dashed_border_outset(SELECTION_DASHED_BORDER_WIDTH_PX, 1.0);

assert_eq!(
WindowRenderer::selection_dashed_border_rect(screen_rect, focus_rect, border_outset,),
Some(Rect::from_min_max(Pos2::new(-1.5, 8.5), Pos2::new(41.5, 41.5),))
);
}

#[test]
fn selection_dashed_border_dash_ranges_distribute_remainder_evenly() {
const EPSILON: f32 = 1e-4;

let rect = Rect::from_min_max(Pos2::new(18.5, 8.5), Pos2::new(61.5, 41.5));
let perimeter = WindowRenderer::selection_dashed_border_perimeter(rect);
let ranges = WindowRenderer::selection_dashed_border_dash_ranges(
perimeter,
SELECTION_DASHED_BORDER_DASH_LENGTH_PX,
SELECTION_DASHED_BORDER_GAP_LENGTH_PX,
);

assert_eq!(ranges.len(), 15);

let dash_length = ranges[0].1 - ranges[0].0;
let gap_length = ranges[1].0 - ranges[0].1;

assert!((dash_length - SELECTION_DASHED_BORDER_DASH_LENGTH_PX).abs() < EPSILON);

for window in ranges.windows(2) {
let current_dash_length = window[0].1 - window[0].0;
let current_gap_length = window[1].0 - window[0].1;

assert!((current_dash_length - dash_length).abs() < EPSILON);
assert!((current_gap_length - gap_length).abs() < EPSILON);
}

let seam_gap_length = perimeter - ranges.last().unwrap().1 + ranges[0].0;

assert!((seam_gap_length - gap_length).abs() < EPSILON);
}

#[test]
fn selection_dashed_border_segments_split_at_square_corners() {
let rect = Rect::from_min_max(Pos2::new(18.5, 8.5), Pos2::new(38.5, 18.5));

assert_eq!(
WindowRenderer::selection_dashed_border_segments(rect, 25.0, 5.0),
vec![
[Pos2::new(18.5, 8.5), Pos2::new(38.5, 8.5)],
[Pos2::new(38.5, 8.5), Pos2::new(38.5, 13.5)],
[Pos2::new(38.5, 18.5), Pos2::new(18.5, 18.5)],
[Pos2::new(18.5, 18.5), Pos2::new(18.5, 13.5)],
]
);
}

#[test]
fn selection_dashed_border_cache_reuses_geometry_for_same_rect() {
let rect = Rect::from_min_max(Pos2::new(18.5, 8.5), Pos2::new(61.5, 41.5));
let other_rect = Rect::from_min_max(Pos2::new(18.5, 8.5), Pos2::new(41.5, 41.5));
let sentinel = [Pos2::new(-1.0, -1.0), Pos2::new(-2.0, -2.0)];
let mut cache = SelectionDashedBorderCache::default();
let initial = WindowRenderer::selection_dashed_border_cached_segments(
&mut cache,
rect,
SELECTION_DASHED_BORDER_DASH_LENGTH_PX,
SELECTION_DASHED_BORDER_GAP_LENGTH_PX,
)
.to_vec();

assert!(!initial.is_empty());

cache.segments[0] = sentinel;

let cached = WindowRenderer::selection_dashed_border_cached_segments(
&mut cache,
rect,
SELECTION_DASHED_BORDER_DASH_LENGTH_PX,
SELECTION_DASHED_BORDER_GAP_LENGTH_PX,
);

assert_eq!(cached[0], sentinel);

let rebuilt = WindowRenderer::selection_dashed_border_cached_segments(
&mut cache,
other_rect,
SELECTION_DASHED_BORDER_DASH_LENGTH_PX,
SELECTION_DASHED_BORDER_GAP_LENGTH_PX,
);

assert_ne!(rebuilt[0], sentinel);
}

#[test]
fn selection_dashed_border_outset_accounts_for_feathering() {
assert_eq!(
WindowRenderer::selection_dashed_border_outset(SELECTION_DASHED_BORDER_WIDTH_PX, 1.0),
1.5
);
assert_eq!(
WindowRenderer::selection_dashed_border_outset(SELECTION_DASHED_BORDER_WIDTH_PX, 2.0),
1.25
);
}

#[test]
fn selection_dashed_border_metrics_track_physical_pixels() {
assert_eq!(
WindowRenderer::selection_dashed_border_metrics(1.0),
SelectionDashedBorderMetrics { stroke_width: 2.0, dash_length: 6.0, gap_length: 4.0 }
);
assert_eq!(
WindowRenderer::selection_dashed_border_metrics(2.0),
SelectionDashedBorderMetrics { stroke_width: 1.0, dash_length: 3.0, gap_length: 2.0 }
);
assert_eq!(
WindowRenderer::selection_dashed_border_metrics(1.5),
SelectionDashedBorderMetrics {
stroke_width: 2.0 / 1.5,
dash_length: 6.0 / 1.5,
gap_length: 4.0 / 1.5,
}
);
}

#[test]
fn frozen_selection_scrim_is_stronger_than_live_drag_scrim_in_light_theme() {
let frozen_scrim = WindowRenderer::frozen_selection_scrim_color(HudTheme::Light);
let drag_scrim = WindowRenderer::live_drag_selection_scrim_color(HudTheme::Light);

assert!(frozen_scrim.a() > drag_scrim.a());
}

#[test]
fn selection_flow_palette_tracks_hud_theme() {
assert_eq!(
WindowRenderer::selection_flow_palette(HudTheme::Dark),
&crate::overlay::SELECTION_FLOW_PALETTE
);
assert_eq!(
WindowRenderer::selection_flow_palette(HudTheme::Light),
&crate::overlay::SELECTION_FLOW_LIGHT_PALETTE
);
}

#[test]
fn selection_flow_color_can_share_theme_rgb() {
let dark = WindowRenderer::selection_flow_color(0.17, HudTheme::Dark, 0.4, 1.0);
let light = WindowRenderer::selection_flow_color(0.17, HudTheme::Light, 0.4, 1.0);

assert_eq!((dark.r(), dark.g(), dark.b()), (light.r(), light.g(), light.b()));
assert_eq!(dark.a(), light.a());
}

#[test]
fn frozen_toolbar_default_position_fits_below_capture_rect() {
let monitor = Rect::from_min_size(Pos2::ZERO, Vec2::new(800.0, 600.0));
Expand Down
Loading
Loading