From 9b7ea2b255f8f15acd1937f55f8a7b74cd02b6ba Mon Sep 17 00:00:00 2001 From: astar76 Date: Wed, 18 Nov 2026 04:00:18 -0600 Subject: [PATCH] S059: tab lifecycle: page dialogs and views go with a tab's web page, shortcut recording ends, message handler unregistered Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- Plans/09 Fix round/S059-tab-lifecycle.md | 12 +-- Plans/INDEX.md | 2 +- docs/PROGRESS.md | 9 ++ src/actions.rs | 30 +++++-- src/app.rs | 24 ++--- src/engine/host.rs | 33 ++++++- src/engine/mod.rs | 2 + src/engine/view.rs | 15 ++++ src/selftest.rs | 6 +- src/tabs.rs | 54 ++++++++++- src/ui/mod.rs | 5 ++ src/ui/pages/mod.rs | 2 + src/ui/pages/settings.rs | 2 + tests/smoke/pages/chatty.html | 9 ++ tests/smoke/stuck.txt | 110 +++++++++++++++++++++++ 16 files changed, 285 insertions(+), 32 deletions(-) create mode 100644 tests/smoke/pages/chatty.html create mode 100644 tests/smoke/stuck.txt diff --git a/CLAUDE.md b/CLAUDE.md index d529a94..5f27db0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -64,7 +64,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl | `nice cargo build --release -j 2` | compile check, produces `target/release/nacre` | now | | `nice cargo test --release -j 2` | unit tests (44, ~16 s test-profile build then <1 s run; shares the S001 build) (util, settings, history, bookmarks, permissions, vault, dns, bridge loopback, download, adblock, keys, scripts, updates, inject, hub, theme, ui::widgets input, ui::paint, ui::pages::newtab) | first successful build; not alongside a build | | `src/selftest.rs` | in-app self test: `NACRE_SCRIPT=` runs script commands (listed at its top) | now | -| `tools/smoke.sh + diff --git a/tests/smoke/stuck.txt b/tests/smoke/stuck.txt new file mode 100644 index 0000000..6470e39 --- /dev/null +++ b/tests/smoke/stuck.txt @@ -0,0 +1,110 @@ +# Tab lifecycle (S059): a tab that asked "Leave this page?" and stayed takes Reload again; Reload while the question +# is up is ignored with a log line; Nacre's pages hold no web view (navigating there frees it, Back brings the page +# back with its history); closing a tab whose page posts messages frees its view without a GLib CRITICAL; a shortcut +# being recorded in settings stops when its tab is left. Offline. +# Run: SMOKE_SIZE=1280x900 tools/smoke.sh tests/smoke/stuck.txt ; then `grep -c CRITICAL /nacre.log` = 0. +wait 3 +resize 1280 900 +open @PAGES@/dialogs.html +waitload +# The page's beforeunload only asks after a click in it. +locate #t +wait 0.5 +click @ +wait 0.5 +cmd close_tab +wait 1.2 +expect /active/dialog true +expect /active/closing true +shot leave-ask +# Reload while the question is up: ignored (log line), the view isn't loaded into while WebKit closes it. +cmd reload +wait 0.5 +expect /tab_count 1 +key Escape +wait 0.5 +expect /active/dialog false +expect /active/closing false +expect /tab_count 1 +# Stayed: Reload works again (the marker set now is gone after it). +js window.__mark = 1 +assert window.__mark === 1 +# The page was clicked, so the Reload asks too: Leave (the dialog's second button). +cmd reload +wait 1.2 +expect /active/dialog true +expect /active/closing false +shot reload-ask +tap 700 542 +wait 1.5 +waitfor 10 window.__mark === undefined && document.readyState === "complete" +expect /active/dialog false +js window.onbeforeunload = null +open @PAGES@/hello.html +waitload +expect /active/title "Smoke page" +# A web page navigating to one of Nacre's pages lets its view go; Back loads it again, history kept. +open @PAGES@/basics.html +waitload +expect /lifecycle/views 1 +cmd navigate nacre://settings +wait 1 +expect /active/has_web false +expect /active/history_state true +expect /active/can_back true +wait 2 +expect /lifecycle/views 0 +expect /lifecycle/views_leaked 0 +status on-settings +cmd back +waitload +expect /active/has_web true +expect /active/title "Basics" +wait 1 +expect /active/can_back true +cmd back +waitload +expect /active/title "Smoke page" +# A nacre:// tab closes at once and leaves nothing behind. +newtab nacre://history +wait 1 +expect /tab_count 2 +cmd close_tab +wait 1 +expect /tab_count 1 +# A tab whose page keeps posting messages closes and frees its view, and WebKit drops the late messages. +newtab @PAGES@/chatty.html +waitload +wait 1 +expect /lifecycle/views 2 +cmd close_tab +wait 3 +expect /tab_count 1 +expect /lifecycle/views 1 +expect /lifecycle/views_leaked 0 +# A shortcut being recorded stops when its tab is left (else every shortcut of the window stays dead). +newtab nacre://settings/keys +wait 1.5 +tap 1091 313 +wait 0.5 +expect /lifecycle/capture_key true +shot keys +cmd select 0 +wait 0.5 +expect /lifecycle/capture_key false +# And a web page's question left on the tab goes with its view when the tab opens one of Nacre's pages. +open @PAGES@/dialogs.html +waitload +locate #t +wait 0.5 +click @ +wait 0.5 +cmd reload +wait 1.2 +expect /active/dialog true +cmd navigate nacre://settings +wait 2 +expect /active/dialog false +expect /lifecycle/views_leaked 0 +status done +quit