From 00b96d37970a8464ad6253f069f4894b869059e1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 31 Mar 2026 16:47:43 -0400 Subject: [PATCH] Improve tooltip leak regression test --- crates/gpui/src/elements/div.rs | 49 ++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index 1dc18ad86c1e1a9fc23e3763b25145f27206d3ed..41ed75beefebd8b5501bc05a302ca4ad4f585bf2 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -3639,23 +3639,46 @@ mod tests { #[test] fn tooltip_is_released_when_its_owner_disappears() { let mut test_app = TestAppContext::single(); + let window = test_app.add_window(|_, _| crate::Empty); + let any_window = window.into(); let active_tooltip: Rc>> = Rc::new(RefCell::new(None)); let weak_active_tooltip = Rc::downgrade(&active_tooltip); - let tooltip_view = test_app.update(|cx| cx.new(|_| TestTooltipView).into()); - - *active_tooltip.borrow_mut() = Some(ActiveTooltip::Visible { - tooltip: AnyTooltip { - view: tooltip_view, - mouse_position: point(px(0.), px(0.)), - check_visible_and_update: Rc::new(move |_, _, _| { - weak_active_tooltip.upgrade().is_some() - }), - }, - is_hoverable: false, - }); + let build_tooltip: Rc Option<(AnyView, bool)>> = + Rc::new(|_, cx| Some((cx.new(|_| TestTooltipView).into(), false))); + let check_is_hovered: Rc bool> = Rc::new(|_: &Window| true); + let check_is_hovered_during_prepaint: Rc bool> = + Rc::new(|_: &Window| true); + + test_app + .update_window(any_window, |_, window, cx| { + handle_tooltip_mouse_move( + &active_tooltip, + &build_tooltip, + &check_is_hovered, + &check_is_hovered_during_prepaint, + DispatchPhase::Bubble, + window, + cx, + ); + }) + .unwrap(); + + assert!(matches!( + active_tooltip.borrow().as_ref(), + Some(ActiveTooltip::WaitingForShow { .. }) + )); + assert_eq!(Rc::strong_count(&active_tooltip), 1); + + test_app.dispatcher.advance_clock(TOOLTIP_SHOW_DELAY); + test_app.run_until_parked(); + + assert!(matches!( + active_tooltip.borrow().as_ref(), + Some(ActiveTooltip::Visible { .. }) + )); + assert_eq!(Rc::strong_count(&active_tooltip), 1); - let weak_active_tooltip = Rc::downgrade(&active_tooltip); drop(active_tooltip); assert!(weak_active_tooltip.upgrade().is_none());