Clean gpui harness clippy debt

This commit is contained in:
2026-05-13 01:26:52 -04:00
parent 5bdb2871ad
commit c19e6923c3
+213 -279
View File
@@ -28,11 +28,11 @@ use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use ely_domain::{TabId, UrlText}; use ely_domain::{TabId, UrlText};
use gpui::{
Bounds, Context, IntoElement, Modifiers, MouseButton, ParentElement, Pixels, Render,
Styled, TestAppContext, Window, canvas, div, point, px,
};
use gpui::InteractiveElement; use gpui::InteractiveElement;
use gpui::{
Bounds, Context, IntoElement, Modifiers, MouseButton, ParentElement, Pixels, Render, Styled,
TestAppContext, Window, canvas, div, point, px,
};
use super::ShellState; use super::ShellState;
use super::web_surface::WebSurfaceStore; use super::web_surface::WebSurfaceStore;
@@ -40,6 +40,9 @@ use super::web_surface_frame::WebSurfaceFrame;
use super::web_surface_geometry::WebSurfaceScrollOffset; use super::web_surface_geometry::WebSurfaceScrollOffset;
use crate::services::servo_live::ServoLiveFrame; use crate::services::servo_live::ServoLiveFrame;
type OverlayState = (TabId, String, Option<Bounds<Pixels>>);
type ProbeHit = (f32, f32, Option<(u32, u32)>);
#[cfg(test)] #[cfg(test)]
impl super::ElyShell { impl super::ElyShell {
pub(super) fn web_surfaces_for_test(&self) -> &WebSurfaceStore { pub(super) fn web_surfaces_for_test(&self) -> &WebSurfaceStore {
@@ -53,35 +56,46 @@ impl super::ElyShell {
#[gpui::test] #[gpui::test]
async fn ely_shell_external_canvas_lays_out_inside_window(cx: &mut TestAppContext) { async fn ely_shell_external_canvas_lays_out_inside_window(cx: &mut TestAppContext) {
cx.update(|cx| gpui_component::init(cx)); cx.update(gpui_component::init);
let (shell, cx) = cx.add_window_view(|window, cx| super::ElyShell::new(window, cx)); let (shell, cx) = cx.add_window_view(super::ElyShell::new);
cx.run_until_parked(); cx.run_until_parked();
let url = example_url();
assert!(url.is_ok(), "example URL literal must parse");
let Ok(url) = url else {
return;
};
cx.update(|window, app_cx| { cx.update(|window, app_cx| {
shell.update(app_cx, |shell, ctx| { shell.update(app_cx, |shell, ctx| {
shell.navigate_active_tab( shell.navigate_active_tab(url, window, ctx);
UrlText::parse("https://example.com/".to_string()).expect("valid URL"),
window,
ctx,
);
}); });
}); });
cx.run_until_parked(); cx.run_until_parked();
let (_active_tab_id, active_tab_url, viewport_bounds) = active_tab_overlay_state(&shell, cx); let overlay_state = active_tab_overlay_state(&shell, cx);
assert!(
overlay_state.is_ok(),
"active tab overlay state must be readable: {:?}",
overlay_state.as_ref().err(),
);
let Ok((_active_tab_id, active_tab_url, viewport_bounds)) = overlay_state else {
return;
};
assert!( assert!(
active_tab_url.starts_with("https://"), active_tab_url.starts_with("https://"),
"active tab URL must be external https for render_external_web_canvas \ "active tab URL must be external https for render_external_web_canvas \
to render the input_overlay (got {active_tab_url:?})." to render the input_overlay (got {active_tab_url:?})."
); );
let bounds = viewport_bounds.unwrap_or_else(|| { assert!(
panic!( viewport_bounds.is_some(),
"viewport_bounds for the active tab is None. The canvas tracker \ "viewport_bounds for the active tab is None. The canvas tracker \
in render_input_overlay's sibling never fired its layout \ in render_input_overlay's sibling never fired its layout callback — \
callback — render_external_web_canvas was not reached." render_external_web_canvas was not reached.",
) );
}); let Some(bounds) = viewport_bounds else {
return;
};
let window_size = cx.update(|window, _| window.bounds().size); let window_size = cx.update(|window, _| window.bounds().size);
assert!( assert!(
bounds.origin.y + bounds.size.height <= window_size.height + px(1.0) bounds.origin.y + bounds.size.height <= window_size.height + px(1.0)
@@ -110,17 +124,18 @@ async fn ely_shell_external_canvas_lays_out_inside_window(cx: &mut TestAppContex
#[gpui::test] #[gpui::test]
#[ignore = "T13 diagnostic — run with --ignored --nocapture to see heatmap"] #[ignore = "T13 diagnostic — run with --ignored --nocapture to see heatmap"]
async fn diagnose_t7_hitbox_reachability_heatmap(cx: &mut TestAppContext) { async fn diagnose_t7_hitbox_reachability_heatmap(cx: &mut TestAppContext) {
cx.update(|cx| gpui_component::init(cx)); cx.update(gpui_component::init);
let (shell, cx) = cx.add_window_view(|window, cx| super::ElyShell::new(window, cx)); let (shell, cx) = cx.add_window_view(super::ElyShell::new);
cx.run_until_parked(); cx.run_until_parked();
let url = example_url();
assert!(url.is_ok(), "example URL literal must parse");
let Ok(url) = url else {
return;
};
cx.update(|window, app_cx| { cx.update(|window, app_cx| {
shell.update(app_cx, |shell, ctx| { shell.update(app_cx, |shell, ctx| {
shell.navigate_active_tab( shell.navigate_active_tab(url, window, ctx);
UrlText::parse("https://example.com/".to_string()).expect("valid URL"),
window,
ctx,
);
}); });
}); });
cx.run_until_parked(); cx.run_until_parked();
@@ -134,8 +149,19 @@ async fn diagnose_t7_hitbox_reachability_heatmap(cx: &mut TestAppContext) {
cx.executor().advance_clock(std::time::Duration::from_millis(500)); cx.executor().advance_clock(std::time::Duration::from_millis(500));
cx.run_until_parked(); cx.run_until_parked();
let (active_tab_id, _url, viewport_bounds) = active_tab_overlay_state(&shell, cx); let overlay_state = active_tab_overlay_state(&shell, cx);
let bounds = viewport_bounds.expect("viewport_bounds must be Some"); assert!(
overlay_state.is_ok(),
"active tab overlay state must be readable: {:?}",
overlay_state.as_ref().err(),
);
let Ok((active_tab_id, _url, viewport_bounds)) = overlay_state else {
return;
};
assert!(viewport_bounds.is_some(), "viewport_bounds must be Some");
let Some(bounds) = viewport_bounds else {
return;
};
let window_size = cx.update(|window, _| window.bounds().size); let window_size = cx.update(|window, _| window.bounds().size);
eprintln!("[T13] window size = {window_size:?}"); eprintln!("[T13] window size = {window_size:?}");
eprintln!("[T13] viewport bounds = {bounds:?}"); eprintln!("[T13] viewport bounds = {bounds:?}");
@@ -154,7 +180,7 @@ async fn diagnose_t7_hitbox_reachability_heatmap(cx: &mut TestAppContext) {
let height = f32::from(window_size.height); let height = f32::from(window_size.height);
let cols = 6u32; let cols = 6u32;
let rows = 6u32; let rows = 6u32;
let mut hits: Vec<(f32, f32, Option<(u32, u32)>)> = Vec::new(); let mut hits: Vec<ProbeHit> = Vec::new();
for row in 0..rows { for row in 0..rows {
for col in 0..cols { for col in 0..cols {
@@ -165,11 +191,7 @@ async fn diagnose_t7_hitbox_reachability_heatmap(cx: &mut TestAppContext) {
// Reset hover_point by moving the cursor far outside, then // Reset hover_point by moving the cursor far outside, then
// reading what's recorded after a move to probe_at. This // reading what's recorded after a move to probe_at. This
// makes each grid point an independent measurement. // makes each grid point an independent measurement.
cx.simulate_mouse_move( cx.simulate_mouse_move(point(px(-10.0), px(-10.0)), None, Modifiers::default());
point(px(-10.0), px(-10.0)),
None,
Modifiers::default(),
);
cx.run_until_parked(); cx.run_until_parked();
cx.simulate_mouse_move(probe_at, None, Modifiers::default()); cx.simulate_mouse_move(probe_at, None, Modifiers::default());
cx.run_until_parked(); cx.run_until_parked();
@@ -285,31 +307,41 @@ async fn diagnose_t7_hitbox_reachability_heatmap(cx: &mut TestAppContext) {
handler that gates on the viewport bounds — which would \ handler that gates on the viewport bounds — which would \
sidestep hit_test for input_overlay's nested div entirely. \ sidestep hit_test for input_overlay's nested div entirely. \
Remove this attribute outright when one of those lands."] Remove this attribute outright when one of those lands."]
async fn user_click_in_rendered_web_canvas_reaches_input_pipeline( async fn user_click_in_rendered_web_canvas_reaches_input_pipeline(cx: &mut TestAppContext) {
cx: &mut TestAppContext, cx.update(gpui_component::init);
) {
cx.update(|cx| gpui_component::init(cx));
let (shell, cx) = cx.add_window_view(|window, cx| super::ElyShell::new(window, cx)); let (shell, cx) = cx.add_window_view(super::ElyShell::new);
cx.run_until_parked(); cx.run_until_parked();
let url = example_url();
assert!(url.is_ok(), "example URL literal must parse");
let Ok(url) = url else {
return;
};
cx.update(|window, app_cx| { cx.update(|window, app_cx| {
shell.update(app_cx, |shell, ctx| { shell.update(app_cx, |shell, ctx| {
shell.navigate_active_tab( shell.navigate_active_tab(url, window, ctx);
UrlText::parse("https://example.com/".to_string()).expect("valid URL"),
window,
ctx,
);
}); });
}); });
cx.run_until_parked(); cx.run_until_parked();
let (active_tab_id, _active_tab_url, viewport_bounds) = let overlay_state = active_tab_overlay_state(&shell, cx);
active_tab_overlay_state(&shell, cx); assert!(
let bounds = viewport_bounds.expect( overlay_state.is_ok(),
"active tab overlay state must be readable: {:?}",
overlay_state.as_ref().err(),
);
let Ok((active_tab_id, _active_tab_url, viewport_bounds)) = overlay_state else {
return;
};
assert!(
viewport_bounds.is_some(),
"viewport_bounds must be Some before T7 can be exercised — the layout \ "viewport_bounds must be Some before T7 can be exercised — the layout \
regression test catches the upstream failure mode separately", regression test catches the upstream failure mode separately",
); );
let Some(bounds) = viewport_bounds else {
return;
};
let surface_state_label = shell.read_with(cx, |shell, _| { let surface_state_label = shell.read_with(cx, |shell, _| {
match shell match shell
@@ -367,9 +399,7 @@ async fn user_click_in_rendered_web_canvas_reaches_input_pipeline(
/// fix in 840255f. If this passes, the bug is upstream of the /// fix in 840255f. If this passes, the bug is upstream of the
/// relative wrapper itself. /// relative wrapper itself.
#[gpui::test] #[gpui::test]
async fn baseline_overlay_under_overflow_hidden_relative_receives_click( async fn baseline_overlay_under_overflow_hidden_relative_receives_click(cx: &mut TestAppContext) {
cx: &mut TestAppContext,
) {
let click_count = Rc::new(RefCell::new(0u32)); let click_count = Rc::new(RefCell::new(0u32));
let counter_for_render = click_count.clone(); let counter_for_render = click_count.clone();
@@ -379,29 +409,23 @@ async fn baseline_overlay_under_overflow_hidden_relative_receives_click(
impl Render for WrappedProbe { impl Render for WrappedProbe {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let counter = self.on_up_counter.clone(); let counter = self.on_up_counter.clone();
div() div().relative().size_full().min_w_0().overflow_hidden().child(
.relative() div()
.size_full() .absolute()
.min_w_0() .size_full()
.overflow_hidden() .occlude()
.child( .on_mouse_down(MouseButton::Left, |_event, _window, _cx| {})
div() .capture_any_mouse_up(move |_event, _window, _cx| {
.absolute() *counter.borrow_mut() += 1;
.size_full() })
.occlude() .on_mouse_move(|_event, _window, _cx| {})
.on_mouse_down(MouseButton::Left, |_event, _window, _cx| {}) .on_scroll_wheel(|_event, _window, _cx| {}),
.capture_any_mouse_up(move |_event, _window, _cx| { )
*counter.borrow_mut() += 1;
})
.on_mouse_move(|_event, _window, _cx| {})
.on_scroll_wheel(|_event, _window, _cx| {}),
)
} }
} }
let (_probe, cx) = cx.add_window_view(|_window, _cx| WrappedProbe { let (_probe, cx) =
on_up_counter: counter_for_render, cx.add_window_view(|_window, _cx| WrappedProbe { on_up_counter: counter_for_render });
});
cx.run_until_parked(); cx.run_until_parked();
cx.simulate_mouse_move(point(px(100.0), px(100.0)), None, Modifiers::default()); cx.simulate_mouse_move(point(px(100.0), px(100.0)), None, Modifiers::default());
@@ -441,70 +465,44 @@ async fn baseline_overlay_under_full_elyshell_wrapper_chain_receives_click(
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let counter = self.on_up_counter.clone(); let counter = self.on_up_counter.clone();
// Root: matches render_browser's outer div. // Root: matches render_browser's outer div.
div() div().size_full().child(
.size_full() // Absolute flex container matches render_browser's child layout.
.child( div().absolute().inset_0().p(px(16.0)).gap(px(12.0)).flex().child(
// Absolute flex container matches render_browser's child layout. // Main pane: matches render_main_pane.
div() div()
.absolute() .flex_1()
.inset_0() .h_full()
.p(px(16.0)) .min_w_0()
.gap(px(12.0))
.flex() .flex()
.flex_col()
.rounded(px(18.0))
.border_1()
.overflow_hidden()
.child( .child(
// Main pane: matches render_main_pane. // Content wrapper: matches the flex_1 child of main_pane.
div() div().flex_1().overflow_hidden().child(
.flex_1() // Surface wrapper: matches render_web_surface root.
.h_full() div().relative().size_full().min_w_0().overflow_hidden().child(
.min_w_0()
.flex()
.flex_col()
.rounded(px(18.0))
.border_1()
.overflow_hidden()
.child(
// Content wrapper: matches the flex_1 child of main_pane.
div() div()
.flex_1() .absolute()
.overflow_hidden() .size_full()
.child( .occlude()
// Surface wrapper: matches render_web_surface root. .on_mouse_down(MouseButton::Left, |_event, _window, _cx| {})
div() .capture_any_mouse_up(move |_event, _window, _cx| {
.relative() *counter.borrow_mut() += 1;
.size_full() })
.min_w_0() .on_mouse_move(|_event, _window, _cx| {})
.overflow_hidden() .on_scroll_wheel(|_event, _window, _cx| {}),
.child(
div()
.absolute()
.size_full()
.occlude()
.on_mouse_down(
MouseButton::Left,
|_event, _window, _cx| {},
)
.capture_any_mouse_up(
move |_event, _window, _cx| {
*counter.borrow_mut() += 1;
},
)
.on_mouse_move(
|_event, _window, _cx| {},
)
.on_scroll_wheel(
|_event, _window, _cx| {},
),
),
),
), ),
),
), ),
) ),
)
} }
} }
let (_probe, cx) = cx.add_window_view(|_window, _cx| DeepProbe { let (_probe, cx) =
on_up_counter: counter_for_render, cx.add_window_view(|_window, _cx| DeepProbe { on_up_counter: counter_for_render });
});
cx.run_until_parked(); cx.run_until_parked();
cx.simulate_mouse_move(point(px(400.0), px(400.0)), None, Modifiers::default()); cx.simulate_mouse_move(point(px(400.0), px(400.0)), None, Modifiers::default());
@@ -538,15 +536,13 @@ async fn baseline_overlay_under_full_elyshell_wrapper_chain_receives_click(
/// or its subscription is what breaks hit_test for descendant /// or its subscription is what breaks hit_test for descendant
/// occlude divs. /// occlude divs.
#[gpui::test] #[gpui::test]
async fn baseline_overlay_with_input_state_construction_receives_click( async fn baseline_overlay_with_input_state_construction_receives_click(cx: &mut TestAppContext) {
cx: &mut TestAppContext,
) {
use gpui::AppContext; use gpui::AppContext;
use gpui::Entity; use gpui::Entity;
use gpui::Subscription; use gpui::Subscription;
use gpui_component::input::{InputEvent, InputState}; use gpui_component::input::{InputEvent, InputState};
cx.update(|cx| gpui_component::init(cx)); cx.update(gpui_component::init);
let click_count = Rc::new(RefCell::new(0u32)); let click_count = Rc::new(RefCell::new(0u32));
let counter_for_render = click_count.clone(); let counter_for_render = click_count.clone();
@@ -559,23 +555,18 @@ async fn baseline_overlay_with_input_state_construction_receives_click(
impl Render for ProbeWithInput { impl Render for ProbeWithInput {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let counter = self.on_up_counter.clone(); let counter = self.on_up_counter.clone();
div() div().relative().size_full().min_w_0().overflow_hidden().child(
.relative() div()
.size_full() .absolute()
.min_w_0() .size_full()
.overflow_hidden() .occlude()
.child( .on_mouse_down(MouseButton::Left, |_e, _w, _c| {})
div() .capture_any_mouse_up(move |_e, _w, _c| {
.absolute() *counter.borrow_mut() += 1;
.size_full() })
.occlude() .on_mouse_move(|_e, _w, _c| {})
.on_mouse_down(MouseButton::Left, |_e, _w, _c| {}) .on_scroll_wheel(|_e, _w, _c| {}),
.capture_any_mouse_up(move |_e, _w, _c| { )
*counter.borrow_mut() += 1;
})
.on_mouse_move(|_e, _w, _c| {})
.on_scroll_wheel(|_e, _w, _c| {}),
)
} }
} }
@@ -619,10 +610,8 @@ async fn baseline_overlay_with_input_state_construction_receives_click(
/// the App is what breaks the rendered_frame's hitbox registration /// the App is what breaks the rendered_frame's hitbox registration
/// for descendant occlude divs. /// for descendant occlude divs.
#[gpui::test] #[gpui::test]
async fn baseline_overlay_after_gpui_component_init_receives_click( async fn baseline_overlay_after_gpui_component_init_receives_click(cx: &mut TestAppContext) {
cx: &mut TestAppContext, cx.update(gpui_component::init);
) {
cx.update(|cx| gpui_component::init(cx));
let click_count = Rc::new(RefCell::new(0u32)); let click_count = Rc::new(RefCell::new(0u32));
let counter_for_render = click_count.clone(); let counter_for_render = click_count.clone();
@@ -633,29 +622,23 @@ async fn baseline_overlay_after_gpui_component_init_receives_click(
impl Render for AfterInitProbe { impl Render for AfterInitProbe {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let counter = self.on_up_counter.clone(); let counter = self.on_up_counter.clone();
div() div().relative().size_full().min_w_0().overflow_hidden().child(
.relative() div()
.size_full() .absolute()
.min_w_0() .size_full()
.overflow_hidden() .occlude()
.child( .on_mouse_down(MouseButton::Left, |_e, _w, _c| {})
div() .capture_any_mouse_up(move |_e, _w, _c| {
.absolute() *counter.borrow_mut() += 1;
.size_full() })
.occlude() .on_mouse_move(|_e, _w, _c| {})
.on_mouse_down(MouseButton::Left, |_e, _w, _c| {}) .on_scroll_wheel(|_e, _w, _c| {}),
.capture_any_mouse_up(move |_e, _w, _c| { )
*counter.borrow_mut() += 1;
})
.on_mouse_move(|_e, _w, _c| {})
.on_scroll_wheel(|_e, _w, _c| {}),
)
} }
} }
let (_probe, cx) = cx.add_window_view(|_window, _cx| AfterInitProbe { let (_probe, cx) =
on_up_counter: counter_for_render, cx.add_window_view(|_window, _cx| AfterInitProbe { on_up_counter: counter_for_render });
});
cx.run_until_parked(); cx.run_until_parked();
cx.simulate_mouse_move(point(px(400.0), px(400.0)), None, Modifiers::default()); cx.simulate_mouse_move(point(px(400.0), px(400.0)), None, Modifiers::default());
@@ -683,9 +666,7 @@ async fn baseline_overlay_after_gpui_component_init_receives_click(
/// capture-specific — every listener on input_overlay is missing /// capture-specific — every listener on input_overlay is missing
/// its hit. /// its hit.
#[gpui::test] #[gpui::test]
async fn baseline_overlay_under_root_with_track_focus_receives_click( async fn baseline_overlay_under_root_with_track_focus_receives_click(cx: &mut TestAppContext) {
cx: &mut TestAppContext,
) {
use gpui::FocusHandle; use gpui::FocusHandle;
let click_count = Rc::new(RefCell::new(0u32)); let click_count = Rc::new(RefCell::new(0u32));
@@ -707,74 +688,46 @@ async fn baseline_overlay_under_root_with_track_focus_receives_click(
.track_focus(&self.focus) .track_focus(&self.focus)
.on_mouse_up(MouseButton::Left, |_event, _window, _cx| {}) .on_mouse_up(MouseButton::Left, |_event, _window, _cx| {})
.child( .child(
div() div().absolute().inset_0().p(px(16.0)).gap(px(12.0)).flex().child(
.absolute() div()
.inset_0() .flex_1()
.p(px(16.0)) .h_full()
.gap(px(12.0)) .min_w_0()
.flex() .flex()
.child( .flex_col()
div() .rounded(px(18.0))
.flex_1() .border_1()
.h_full() .overflow_hidden()
.min_w_0() .child(
.flex() div().flex_1().overflow_hidden().child(
.flex_col()
.rounded(px(18.0))
.border_1()
.overflow_hidden()
.child(
div() div()
.flex_1() .relative()
.size_full()
.min_w_0()
.overflow_hidden() .overflow_hidden()
.child(div().absolute().inset_0().child(div().size_full()))
.child(
canvas(move |_b, _w, _c| {}, |_, _, _, _| {})
.absolute()
.size_full(),
)
.child( .child(
div() div()
.relative() .absolute()
.size_full() .size_full()
.min_w_0() .occlude()
.overflow_hidden() .on_mouse_down(MouseButton::Left, |_e, _w, _c| {})
.child( .capture_any_mouse_up(move |_e, _w, _c| {
div() *counter_up.borrow_mut() += 1;
.absolute() })
.inset_0() .on_mouse_move(move |_e, _w, _c| {
.child(div().size_full()), *counter_move.borrow_mut() += 1;
) })
.child( .on_scroll_wheel(|_e, _w, _c| {}),
canvas(
move |_b, _w, _c| {},
|_, _, _, _| {},
)
.absolute()
.size_full(),
)
.child(
div()
.absolute()
.size_full()
.occlude()
.on_mouse_down(
MouseButton::Left,
|_e, _w, _c| {},
)
.capture_any_mouse_up(
move |_e, _w, _c| {
*counter_up
.borrow_mut() += 1;
},
)
.on_mouse_move(
move |_e, _w, _c| {
*counter_move
.borrow_mut() += 1;
},
)
.on_scroll_wheel(
|_e, _w, _c| {},
),
),
), ),
), ),
), ),
),
) )
} }
} }
@@ -818,9 +771,7 @@ async fn baseline_overlay_under_root_with_track_focus_receives_click(
/// frame whose hitboxes no longer match the listeners' captured /// frame whose hitboxes no longer match the listeners' captured
/// snapshots, and this test will go red. /// snapshots, and this test will go red.
#[gpui::test] #[gpui::test]
async fn baseline_overlay_with_entity_update_in_mouse_down_receives_click( async fn baseline_overlay_with_entity_update_in_mouse_down_receives_click(cx: &mut TestAppContext) {
cx: &mut TestAppContext,
) {
let click_count = Rc::new(RefCell::new(0u32)); let click_count = Rc::new(RefCell::new(0u32));
let counter_for_render = click_count.clone(); let counter_for_render = click_count.clone();
@@ -839,12 +790,7 @@ async fn baseline_overlay_with_entity_update_in_mouse_down_receives_click(
.overflow_hidden() .overflow_hidden()
.child(div().absolute().inset_0().child(div().size_full())) .child(div().absolute().inset_0().child(div().size_full()))
.child( .child(
canvas( canvas(move |_bounds, _window, _cx| {}, |_, _, _, _| {}).absolute().size_full(),
move |_bounds, _window, _cx| {},
|_, _, _, _| {},
)
.absolute()
.size_full(),
) )
.child( .child(
div() div()
@@ -891,9 +837,7 @@ async fn baseline_overlay_with_entity_update_in_mouse_down_receives_click(
/// somehow disturbs hitbox registration or mouse_listeners ordering, /// somehow disturbs hitbox registration or mouse_listeners ordering,
/// this test will go red and pinpoint the suspect. /// this test will go red and pinpoint the suspect.
#[gpui::test] #[gpui::test]
async fn baseline_overlay_with_canvas_sibling_receives_click( async fn baseline_overlay_with_canvas_sibling_receives_click(cx: &mut TestAppContext) {
cx: &mut TestAppContext,
) {
let click_count = Rc::new(RefCell::new(0u32)); let click_count = Rc::new(RefCell::new(0u32));
let counter_for_render = click_count.clone(); let counter_for_render = click_count.clone();
@@ -908,19 +852,9 @@ async fn baseline_overlay_with_canvas_sibling_receives_click(
.size_full() .size_full()
.min_w_0() .min_w_0()
.overflow_hidden() .overflow_hidden()
.child(div().absolute().inset_0().child(div().size_full()))
.child( .child(
div() canvas(move |_bounds, _window, _cx| {}, |_, _, _, _| {}).absolute().size_full(),
.absolute()
.inset_0()
.child(div().size_full()),
)
.child(
canvas(
move |_bounds, _window, _cx| {},
|_, _, _, _| {},
)
.absolute()
.size_full(),
) )
.child( .child(
div() div()
@@ -937,9 +871,8 @@ async fn baseline_overlay_with_canvas_sibling_receives_click(
} }
} }
let (_probe, cx) = cx.add_window_view(|_window, _cx| CanvasSiblingProbe { let (_probe, cx) =
on_up_counter: counter_for_render, cx.add_window_view(|_window, _cx| CanvasSiblingProbe { on_up_counter: counter_for_render });
});
cx.run_until_parked(); cx.run_until_parked();
cx.simulate_mouse_move(point(px(400.0), px(400.0)), None, Modifiers::default()); cx.simulate_mouse_move(point(px(400.0), px(400.0)), None, Modifiers::default());
@@ -958,9 +891,7 @@ async fn baseline_overlay_with_canvas_sibling_receives_click(
} }
#[gpui::test] #[gpui::test]
async fn baseline_overlay_with_full_listener_combo_receives_click( async fn baseline_overlay_with_full_listener_combo_receives_click(cx: &mut TestAppContext) {
cx: &mut TestAppContext,
) {
let click_count = Rc::new(RefCell::new(0u32)); let click_count = Rc::new(RefCell::new(0u32));
let counter_for_render = click_count.clone(); let counter_for_render = click_count.clone();
@@ -985,9 +916,8 @@ async fn baseline_overlay_with_full_listener_combo_receives_click(
} }
} }
let (_probe, cx) = cx.add_window_view(|_window, _cx| ComboProbe { let (_probe, cx) =
on_up_counter: counter_for_render, cx.add_window_view(|_window, _cx| ComboProbe { on_up_counter: counter_for_render });
});
cx.run_until_parked(); cx.run_until_parked();
cx.simulate_mouse_move(point(px(100.0), px(100.0)), None, Modifiers::default()); cx.simulate_mouse_move(point(px(100.0), px(100.0)), None, Modifiers::default());
@@ -1024,9 +954,8 @@ async fn baseline_overlay_div_receives_simulated_click(cx: &mut TestAppContext)
} }
} }
let (_probe, cx) = cx.add_window_view(|_window, _cx| Probe { let (_probe, cx) =
on_up_counter: counter_for_render, cx.add_window_view(|_window, _cx| Probe { on_up_counter: counter_for_render });
});
cx.run_until_parked(); cx.run_until_parked();
cx.simulate_mouse_move(point(px(100.0), px(100.0)), None, Modifiers::default()); cx.simulate_mouse_move(point(px(100.0), px(100.0)), None, Modifiers::default());
@@ -1065,7 +994,7 @@ async fn baseline_overlay_div_receives_simulated_click(cx: &mut TestAppContext)
/// returns to ~960 MB/s of host-side RGBA cloning + per-frame GPUI /// returns to ~960 MB/s of host-side RGBA cloning + per-frame GPUI
/// texture allocations. /// texture allocations.
#[test] #[test]
fn identical_live_frames_share_render_image_arc() { fn identical_live_frames_share_render_image_arc() -> Result<(), String> {
let width = 16u32; let width = 16u32;
let height = 8u32; let height = 8u32;
let rgba_bytes = vec![0xAAu8; (width as usize) * (height as usize) * 4]; let rgba_bytes = vec![0xAAu8; (width as usize) * (height as usize) * 4];
@@ -1076,23 +1005,23 @@ fn identical_live_frames_share_render_image_arc() {
100, 100,
ServoLiveFrame::for_test(width, height, rgba_bytes.clone()), ServoLiveFrame::for_test(width, height, rgba_bytes.clone()),
) )
.expect("first frame builds from identical bytes"); .map_err(|error| error.to_string())?;
let second = WebSurfaceFrame::from_live_frame( let second = WebSurfaceFrame::from_live_frame(
"https://example.com/".to_string(), "https://example.com/".to_string(),
WebSurfaceScrollOffset::default(), WebSurfaceScrollOffset::default(),
100, 100,
ServoLiveFrame::for_test(width, height, rgba_bytes), ServoLiveFrame::for_test(width, height, rgba_bytes),
) )
.expect("second frame builds from identical bytes"); .map_err(|error| error.to_string())?;
let first_image = first let first_image = first
.image .image
.as_ref() .as_ref()
.expect("software path always produces an Arc<RenderImage>"); .ok_or_else(|| "software path must produce an Arc<RenderImage>".to_string())?;
let second_image = second let second_image = second
.image .image
.as_ref() .as_ref()
.expect("software path always produces an Arc<RenderImage>"); .ok_or_else(|| "software path must produce an Arc<RenderImage>".to_string())?;
assert!( assert!(
Arc::ptr_eq(first_image, second_image), Arc::ptr_eq(first_image, second_image),
"TDD red: two ServoLiveFrames with byte-identical RGBA produced \ "TDD red: two ServoLiveFrames with byte-identical RGBA produced \
@@ -1104,17 +1033,18 @@ fn identical_live_frames_share_render_image_arc() {
Arc::as_ptr(first_image), Arc::as_ptr(first_image),
Arc::as_ptr(second_image), Arc::as_ptr(second_image),
); );
Ok(())
} }
fn active_tab_overlay_state( fn active_tab_overlay_state(
shell: &gpui::Entity<super::ElyShell>, shell: &gpui::Entity<super::ElyShell>,
cx: &mut gpui::VisualTestContext, cx: &mut gpui::VisualTestContext,
) -> (TabId, String, Option<Bounds<Pixels>>) { ) -> Result<OverlayState, String> {
shell.read_with(cx, |shell, _cx| { shell.read_with(cx, |shell, _cx| {
let tab = match &shell.state { let tab = match &shell.state {
ShellState::Ready(core) => core.active_tab().expect("active tab exists"), ShellState::Ready(core) => core.active_tab().map_err(|error| error.to_string())?,
ShellState::StartupError(message) => { ShellState::StartupError(message) => {
panic!("ElyShell failed to start in test: {message}") return Err(format!("ElyShell failed to start in test: {message}"));
} }
}; };
let tab_id = tab.id().clone(); let tab_id = tab.id().clone();
@@ -1123,6 +1053,10 @@ fn active_tab_overlay_state(
.web_surfaces_for_test() .web_surfaces_for_test()
.surface_for_test(&tab_id) .surface_for_test(&tab_id)
.and_then(|surface| surface.viewport_bounds); .and_then(|surface| surface.viewport_bounds);
(tab_id, url, bounds) Ok((tab_id, url, bounds))
}) })
} }
fn example_url() -> Result<UrlText, ely_domain::DomainError> {
UrlText::parse("https://example.com/".to_string())
}