diff --git a/crates/automation/src/workspace.rs b/crates/automation/src/workspace.rs index e8566b439e..12e7329180 100644 --- a/crates/automation/src/workspace.rs +++ b/crates/automation/src/workspace.rs @@ -806,6 +806,21 @@ mod tests { assert!(authorize_desktop_engine_step("file.saveACopy", &serde_json::json!({})).is_err()); } + // Regression test for #3763: `edit.installedProfiles` scans the OS and user ICC folders but + // takes no path parameter, so automation let it through until it was listed as ambient. + #[test] + fn installed_profiles_listing_is_refused_for_automation() { + for params in [serde_json::json!({}), serde_json::json!({"class": "output", "colorSpace": "cmyk"})] { + assert!(authorize_engine_command("edit.installedProfiles", ¶ms).is_err(), "authorize_engine_command allowed it with {params}"); + assert!(authorize_desktop_engine_command("edit.installedProfiles", ¶ms).is_err(), "authorize_desktop_engine_command allowed it with {params}"); + assert!(authorize_engine_step("edit.installedProfiles", ¶ms).is_err(), "authorize_engine_step allowed it with {params}"); + } + // The sandboxed session refuses it before the engine scans any folder. + let mut headless = crate::Headless::new(); + let refused = headless.command_run("edit.installedProfiles", serde_json::json!({})).unwrap_err(); + assert!(refused.to_string().contains("ambient filesystem paths"), "{refused}"); + } + #[test] fn apply_data_set_is_judged_by_the_values_it_applies() { let mut headless = crate::Headless::new(); diff --git a/crates/ui-egui/src/layer_style.rs b/crates/ui-egui/src/layer_style.rs index 084a48ffa4..b65487c4f7 100644 --- a/crates/ui-egui/src/layer_style.rs +++ b/crates/ui-egui/src/layer_style.rs @@ -1555,6 +1555,39 @@ mod tests { assert_eq!(rows, KINDS.len(), "one empty checkbox per effect row"); } + // Regression test for #2209: Make Default and Reset to Default sat in a non-wrapping row, so + // translated labels wider than the page column (Russian) pushed one button over the other + // and out of the column instead of wrapping to a second row. + #[test] + fn default_buttons_wrap_inside_the_page_column_with_long_labels() { + use egui_kittest::kittest::Queryable; + let ru = crate::i18n::Lang::from_code("ru").unwrap(); + crate::i18n::with_language(ru, || { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 32, "height": 32})).unwrap(); + let l = Layer::raster("x", photocraft_doc::PixelFormat::RGBA8); + let fields = initial_fields(&l, Some("dropShadow"), 120.0); + let mut h = egui_kittest::Harness::builder().with_size(vec2(900.0, 700.0)).build_ui_state( + move |ui, app: &mut PhotocraftApp| { + if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + let mut f = fields.clone(); + body(app, ui, &mut f); + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ProMedium); + h.run_steps(3); + let reset = h.get_by_role_and_label(egui::accesskit::Role::Button, crate::i18n::tr(ru, "Reset to Default")).rect(); + let make = h.get_by_role_and_label(egui::accesskit::Role::Button, crate::i18n::tr(ru, "Make Default")).rect(); + // Together they are wider than the page column: the second wraps to a row below + // instead of sharing the row and running left over the effect list. + assert!(make.top() >= reset.bottom(), "the buttons share one row: {make:?} {reset:?}"); + assert_eq!(make.right(), reset.right(), "the wrapped row stays right-aligned"); + }); + } + /// Double-clicking an effect row of a layer that isn't active selects that layer first, so /// the dialog holds its effects (and OK edits it), not the active layer's. #[test] diff --git a/crates/ui-egui/src/liquify_ui.rs b/crates/ui-egui/src/liquify_ui.rs index 43a792d3ff..210754ef32 100644 --- a/crates/ui-egui/src/liquify_ui.rs +++ b/crates/ui-egui/src/liquify_ui.rs @@ -1727,6 +1727,80 @@ mod tests { assert_eq!(app.distort.liquify.as_ref().unwrap().strokes.len(), 1, "Cmd+Shift+Z redoes the last stroke"); } + // Regression test for #4134: Cmd+Z and Cmd+Shift+Z were ignored in Liquify while a numeric + // field's text edit (Size, Pressure, ...) had keyboard focus, so a stroke could not be undone. + #[test] + fn liquify_undo_and_redo_work_while_a_numeric_field_is_focused() { + let ctx = egui::Context::default(); + let mut app = app_with_layer(); + open(&mut app, &ctx).unwrap(); + for ev in [ToolEvent::Down { x: 40.0, y: 40.0, pressure: 1.0 }, ToolEvent::Move { x: 52.0, y: 40.0, pressure: 1.0 }, ToolEvent::Up { x: 52.0, y: 40.0 }] + { + pointer(&mut app, ev, egui::Modifiers::NONE); + } + let strokes = |app: &PhotocraftApp| app.distort.liquify.as_ref().unwrap().strokes.len(); + assert_eq!(strokes(&app), 1); + + // One frame of the real shortcut handler, then a focused single-line text edit (the + // numeric fields are text edits), as the app orders them. + let mut text = String::from("100"); + let field = egui::Id::new("liquify-size-field"); + let mut frame = |app: &mut PhotocraftApp, events: Vec| { + let raw = egui::RawInput { events, ..Default::default() }; + let mut out = ctx.run_ui(raw, |ui| { + crate::shortcuts::handle(app, ui.ctx()); + let edit = ui.add(egui::TextEdit::singleline(&mut text).id(field)); + edit.request_focus(); + }); + out.textures_delta.clear(); + }; + frame(&mut app, Vec::new()); + assert!(ctx.text_edit_focused(), "the numeric field is a focused text edit"); + + let z = |modifiers| egui::Event::Key { key: egui::Key::Z, physical_key: None, pressed: true, repeat: false, modifiers }; + frame(&mut app, vec![z(egui::Modifiers::COMMAND)]); + assert_eq!(strokes(&app), 0, "Cmd+Z undoes the stroke with the field focused"); + frame(&mut app, vec![z(egui::Modifiers::COMMAND | egui::Modifiers::SHIFT)]); + assert_eq!(strokes(&app), 1, "Cmd+Shift+Z redoes it"); + } + + // Regression test for #4134: other Liquify keys must not steal characters from a focused + // numeric field, and the bracket keys step the brush by at least one pixel. + #[test] + fn liquify_tool_keys_leave_a_focused_field_alone_and_brackets_reach_one_pixel() { + let ctx = egui::Context::default(); + let mut app = app_with_layer(); + open(&mut app, &ctx).unwrap(); + app.distort.liquify.as_mut().unwrap().opts.size = 2.0; + let size = |app: &PhotocraftApp| app.distort.liquify.as_ref().unwrap().opts.size; + let press = |app: &mut PhotocraftApp, key: egui::Key| { + let ev = egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + let mut out = ctx.run_ui(egui::RawInput { events: vec![ev], ..Default::default() }, |ui| crate::shortcuts::handle(app, ui.ctx())); + out.textures_delta.clear(); + }; + // 2 px * 0.9 used to round back to 2, so `[` never reached 1 px; `]` steps up from 1. + press(&mut app, egui::Key::OpenBracket); + assert_eq!(size(&app), 1.0, "`[` steps a 2 px brush down to 1 px"); + press(&mut app, egui::Key::CloseBracket); + assert_eq!(size(&app), 2.0, "`]` steps it back up"); + + // With a text edit focused, `[` belongs to the field. + let mut text = String::new(); + let field = egui::Id::new("liquify-size-field"); + let focused_frame = |app: &mut PhotocraftApp, text: &mut String, events: Vec| { + let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| { + crate::shortcuts::handle(app, ui.ctx()); + ui.add(egui::TextEdit::singleline(text).id(field)).request_focus(); + }); + out.textures_delta.clear(); + }; + focused_frame(&mut app, &mut text, Vec::new()); + assert!(ctx.text_edit_focused()); + let bracket = egui::Event::Key { key: egui::Key::OpenBracket, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + focused_frame(&mut app, &mut text, vec![bracket]); + assert_eq!(size(&app), 2.0, "the focused field keeps its keys"); + } + fn key(key: egui::Key) -> egui::Event { egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND } } diff --git a/crates/ui-egui/src/mask_thumbs_ui/tests.rs b/crates/ui-egui/src/mask_thumbs_ui/tests.rs index 230d0add3a..e44bac432d 100644 --- a/crates/ui-egui/src/mask_thumbs_ui/tests.rs +++ b/crates/ui-egui/src/mask_thumbs_ui/tests.rs @@ -86,6 +86,28 @@ fn deleting_the_vector_mask_prunes_its_thumbnail() { assert!(!h.state().thumbs.contains_key(&key)); } +// Regression test for #119: the Layers panel's thumbnail textures of a deleted layer, and of +// every layer of a closed document, were kept for the rest of the session. +#[test] +fn deleting_a_layer_or_closing_its_document_releases_the_thumbnails() { + let (s, masked, shape) = session(); + let mut h = harness(s, 0, 1.0, 290.0); + let layer_key = |id: u64| (photocraft_doc::LayerId(id), crate::mask_thumbs_ui::THUMB_LAYER); + assert!(h.state().thumbs.contains_key(&layer_key(masked)) && h.state().thumbs.contains_key(&layer_key(shape)), "both rows drew a thumbnail"); + let before = h.state().thumbs.len(); + + h.state_mut().run("layer.delete", json!({"layer": shape})).unwrap(); + h.run_steps(3); + assert!(!h.state().thumbs.contains_key(&layer_key(shape)), "the deleted layer's thumbnail is released"); + assert!(h.state().thumbs.contains_key(&layer_key(masked)), "the other layer keeps its thumbnail"); + assert!(h.state().thumbs.len() < before); + + h.state_mut().run("file.close", json!({})).unwrap(); + h.run_steps(3); + assert!(h.state().session.documents().is_empty()); + assert!(h.state().thumbs.is_empty(), "no thumbnails outlive their document: {:?}", h.state().thumbs.keys().collect::>()); +} + #[test] fn footer_trash_deletes_only_the_targeted_mask_linked_or_unlinked() { for linked in [true, false] { diff --git a/crates/ui-egui/src/options_hit_area_tests.rs b/crates/ui-egui/src/options_hit_area_tests.rs index d444f06473..1498307f55 100644 --- a/crates/ui-egui/src/options_hit_area_tests.rs +++ b/crates/ui-egui/src/options_hit_area_tests.rs @@ -197,3 +197,29 @@ fn options_tab_moves_from_hardness_to_opacity_without_a_caption_stop() { assert_eq!(h.state().session.tools.brush.hardness, 0.5); assert!((h.state().session.tools.brush.opacity - 0.99).abs() < 0.0001); } + +// Regression test for #3425: the options bar drew its own 1 px top and bottom separator inside +// the panel, on top of the panel's own border, so the borders doubled (three lines, not one). +#[test] +fn options_bar_has_a_single_full_width_border() { + for kind in [crate::theme::ThemeKind::Studio, crate::theme::ThemeKind::Pro, crate::theme::ThemeKind::Classic] { + let mut h = harness(); + PhotocraftApp::setup_context(&h.ctx, kind); + h.run_steps(4); + let separator = crate::theme::Tokens::get(&h.ctx).separator; + let borders: Vec<_> = h + .output() + .shapes + .iter() + .filter_map(|c| match &c.shape { + egui::Shape::LineSegment { points, stroke } + if stroke.color == separator && (points[0].y - points[1].y).abs() < 0.01 && (points[1].x - points[0].x).abs() > 400.0 => + { + Some(*points) + } + _ => None, + }) + .collect(); + assert_eq!(borders.len(), 1, "{kind:?}: the options bar has exactly one border, the panel's (its own would double it): {borders:?}"); + } +} diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index b6bd34d9d2..bcb59b5e90 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -6509,6 +6509,38 @@ mod toolbar_tests { } } + // Regression test for #2241: Quick Mask and Screen Mode ignored the two-column toolbar and + // stayed stacked in one column; in two columns they sit side by side. + #[test] + fn quick_mask_and_screen_mode_follow_the_toolbar_columns() { + for theme in [crate::theme::ThemeKind::Pro, crate::theme::ThemeKind::Studio, crate::theme::ThemeKind::Classic] { + let app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + let mut h = egui_kittest::Harness::builder().with_size(vec2(800.0, 1400.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + toolbar(app, ui); + } + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, theme); + h.run_steps(2); + let modes = |h: &egui_kittest::Harness<'_, PhotocraftApp>| { + (h.get_by_label("Edit in Quick Mask Mode (Q)").rect(), h.get_by_label("Change Screen Mode (F)").rect()) + }; + let (quick, screen) = modes(&h); + assert_eq!(quick.left(), screen.left(), "{theme:?}: one column stacks them"); + assert!(screen.top() >= quick.bottom(), "{theme:?}: Screen Mode below Quick Mask: {quick:?} {screen:?}"); + + h.get_by_label("Toolbar").click(); + h.run_steps(2); + assert!(h.state().ui.panels.toolbar_double, "{theme:?}"); + let (quick, screen) = modes(&h); + assert_eq!(quick.top(), screen.top(), "{theme:?}: two columns put them on one row: {quick:?} {screen:?}"); + assert!(screen.left() >= quick.right(), "{theme:?}: Screen Mode beside Quick Mask: {quick:?} {screen:?}"); + } + } + fn click(h: &mut egui_kittest::Harness<'_, PhotocraftApp>, p: egui::Pos2) { h.hover_at(p); h.run_steps(1); diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs index d637f193d0..d4d0c06fa9 100644 --- a/crates/ui-egui/src/theme.rs +++ b/crates/ui-egui/src/theme.rs @@ -1131,6 +1131,29 @@ mod tests { assert_eq!(ctx.zoom_factor(), 1.0); } + // Regression test for #4630: the stock thin scroll bar fades its handle to the same opacity + // as its track while the pointer is on it, so the thumb disappeared when it was grabbed. + #[test] + fn scrollbar_thumb_stays_more_visible_than_its_track_in_every_theme() { + for kind in ThemeKind::ALL { + let ctx = egui::Context::default(); + apply(&ctx, kind); + for theme in [egui::Theme::Dark, egui::Theme::Light] { + let scroll = ctx.style_of(theme).spacing.scroll; + if !scroll.floating { + continue; + } + assert!( + scroll.interact_handle_opacity > scroll.interact_background_opacity, + "{kind:?}/{theme:?}: handle {} vs track {} under the pointer", + scroll.interact_handle_opacity, + scroll.interact_background_opacity + ); + assert_eq!(scroll.interact_handle_opacity, 1.0, "{kind:?}/{theme:?}: the thumb is opaque under the pointer"); + } + } + } + /// The desktop app installs fonts and loads the saved UI Font Size in its first frame, while /// egui's default fonts are still active. Any size but Small then panicked on the next pass /// ("FontFamily::Name("medium") is not bound to any fonts") because the plugin rescaled a diff --git a/crates/ui-egui/src/transform_tool.rs b/crates/ui-egui/src/transform_tool.rs index 61e00e8257..b43a16dda3 100644 --- a/crates/ui-egui/src/transform_tool.rs +++ b/crates/ui-egui/src/transform_tool.rs @@ -4864,6 +4864,56 @@ mod tests { assert_eq!(rotate_cursor_dir(&app, [f64::NAN, 32.0]), None); } + // Regression test for #4139: the rotate zone hides the OS pointer (`CursorIcon::None`), so the + // canvas has to draw the curved turn arrow itself where the box has no preview to draw it + // (the preview's overlay draws it otherwise); the pointer vanished over the zone. + #[test] + fn the_rotate_zone_draws_the_turn_arrow_where_the_pointer_is_hidden() { + let mut app = app_with_square(256, photocraft_geom::Rect::new(32, 32, 160, 160)); + app.ui.tool = Tool::Move; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).with_max_steps(64).build_eframe(move |cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + app + }); + h.run_steps(4); + let ctx = h.ctx.clone(); + crate::menus::invoke(h.state_mut(), &ctx, "edit.freeTransform", json!({})).unwrap(); + h.run_steps(3); + let tol = handle_tolerance(h.state()); + let xf = ViewXform::active(h.state()).unwrap(); + let accent = crate::theme::Tokens::get(&h.ctx).accent_text; + // The arrow's bright stroke: a 17-point arc in the accent colour around the pointer. + let arrows = |h: &egui_kittest::Harness<'_, PhotocraftApp>, at: egui::Pos2| { + h.output() + .shapes + .iter() + .filter(|c| match &c.shape { + egui::Shape::Path(p) => { + p.points.len() == 17 + && p.stroke.width == 1.5 + && p.stroke.color == egui::epaint::ColorMode::Solid(accent) + && p.points.iter().all(|q| q.distance(at) < 40.0) + } + _ => false, + }) + .count() + }; + let outside = xf.to_screen((32.0 - tol * 1.5) as f32, (32.0 - tol * 1.5) as f32); + + // A box with no preview (its overlay is what draws the arrow otherwise). + h.state_mut().transform_preview = None; + h.hover_at(outside); + h.run_steps(3); + assert!(h.state().ui.transform.is_some() && h.state().transform_preview.is_none()); + assert_eq!(h.output().platform_output.cursor_icon, CursorIcon::None, "the OS pointer is hidden in the rotate zone"); + assert_eq!(arrows(&h, outside), 1, "and the curved arrow is drawn in its place"); + + let inside = xf.to_screen(96.0, 96.0); + h.hover_at(inside); + h.run_steps(3); + assert_eq!(arrows(&h, inside), 0, "no arrow over the box"); + } + /// The resize arrows follow the box's turn and the view's rotation and flip: each handle /// shows the arrow it resizes along on screen, not the one it had on the upright box. #[test]