From 326dde8a97f9a65453f831cdcbb5dfda0956bcbc Mon Sep 17 00:00:00 2001 From: astar76 Date: Thu, 12 Nov 2026 09:45:19 -0600 Subject: [PATCH] S006: keys, cache, site-doctor smokes; single instance check; view source of file://; timed window requests Co-Authored-By: Claude Opus 5.5 --- src/actions.rs | 4 ++ src/app.rs | 4 +- src/selftest.rs | 23 ++++++++ tests/smoke/basics.txt | 15 ++++- tests/smoke/cache.txt | 15 +++++ tests/smoke/cache/server.py | 33 +++++++++++ tests/smoke/keys.txt | 115 ++++++++++++++++++++++++++++++++++++ tests/smoke/site-doctor.txt | 85 ++++++++++++++++++++++++++ 8 files changed, 290 insertions(+), 4 deletions(-) create mode 100644 tests/smoke/cache.txt create mode 100644 tests/smoke/cache/server.py create mode 100644 tests/smoke/keys.txt create mode 100644 tests/smoke/site-doctor.txt diff --git a/src/actions.rs b/src/actions.rs index f9d271a..1132ad6 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -779,6 +779,10 @@ impl App { let headers = Url::parse(&url).map(|u| self.request_headers(&u, "")).unwrap_or_default(); let fetch_url = url.clone(); self.spawn("source", move || { + // Local files are read from disk: the HTTP client only speaks http(s). + if let Some(path) = Url::parse(&fetch_url).ok().filter(|u| u.scheme() == "file").and_then(|u| u.to_file_path().ok()) { + return std::fs::read(&path).map(|bytes| String::from_utf8_lossy(&bytes).into_owned()).map_err(|e| e.to_string()); + } let refs: Vec<(&str, &str)> = headers.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect(); crate::net::fetch::get(&fetch_url, &refs, 16 * 1024 * 1024, Duration::from_secs(30)).map(|f| f.text()) }, move |app, result| { diff --git a/src/app.rs b/src/app.rs index 2d7c111..13ed469 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1700,9 +1700,11 @@ fn standard_axis(axis: gilrs::Axis) -> Option { } impl ApplicationHandler for App { - fn new_events(&mut self, _event_loop: &ActiveEventLoop, cause: StartCause) { + fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause) { if let StartCause::ResumeTimeReached { .. } = cause { self.tick(); + // A timed step (selftest, scheduled jobs) may have asked for a window. + self.open_pending_windows(event_loop); } } diff --git a/src/selftest.rs b/src/selftest.rs index ce21bd3..5ae6e5d 100644 --- a/src/selftest.rs +++ b/src/selftest.rs @@ -40,6 +40,8 @@ //! scroll turn the wheel over x,y in the window by dy points (positive scrolls down) //! welcome show step 0..5 of the welcome page //! customize [close] open (or close) the new tab page's Customize panel +//! launch start a second Nacre with these arguments (same profile, no script); it must hand +//! them to this one and exit within 10 s (single instance), else the run fails //! log write a line to the log //! quit @@ -594,6 +596,27 @@ impl App { } self.redraw(window); }, + "launch" => { + // Single instance check: the second process must find this one, hand over and exit. + let child = std::env::current_exe().and_then(|exe| std::process::Command::new(exe).args(rest.split_whitespace()).env_remove("NACRE_SCRIPT").spawn()); + let result = match child { + Ok(mut child) => { + let deadline = Instant::now() + Duration::from_secs(10); + loop { + match child.try_wait() { + Ok(Some(status)) => break format!("launch exited: {status}"), + Ok(None) if Instant::now() < deadline => std::thread::sleep(Duration::from_millis(100)), + _ => { + let _ = child.kill(); + break "ASSERT FAILED: launch did not hand off and exit".to_owned(); + }, + } + } + }, + Err(error) => format!("ASSERT FAILED: launch: {error}"), + }; + self.selftest_log(&result); + }, "log" => self.selftest_log(rest), "quit" => self.quit(), _ => self.selftest_log(&format!("unknown line: {line}")), diff --git a/tests/smoke/basics.txt b/tests/smoke/basics.txt index e795028..5adc6b9 100644 --- a/tests/smoke/basics.txt +++ b/tests/smoke/basics.txt @@ -83,14 +83,18 @@ assert window.marker === undefined cmd navigate @PAGES@/hello.html waitload expect /active/title "Smoke page" +# The search engine is a local page here, so the check stays offline. +set /startup/custom_engines [["Local", "@PAGES@/hello.html?q=%s"]] +set /startup/search_engine "custom:Local" cmd navigate nacre smoke words -waitload 30 -wait 1 -expect /active/url "https://duckduckgo.com/?q=nacre+smoke+words" +waitload +wait 0.5 +expect /active/url "@PAGES@/hello.html?q=nacre+smoke+words" status search # Find in page: 3 matches, 2 with match case is the bar's job (count only here). open @PAGES@/basics.html waitload +waitfor 10 document.title === "Basics" cmd find needle wait 1 expect /active/find [1,3] @@ -134,6 +138,11 @@ wait 1.5 expect /tab_count 5 status popup shot popup +# Single instance: a second launch hands its link to this browser (a new tab) and exits. +launch @PAGES@/input.html +wait 1.5 +expect /tab_count 6 +expect /active/url "@PAGES@/input.html" # New window. do new_window wait 2 diff --git a/tests/smoke/cache.txt b/tests/smoke/cache.txt new file mode 100644 index 0000000..3d3a66a --- /dev/null +++ b/tests/smoke/cache.txt @@ -0,0 +1,15 @@ +# HTTP cache (S006): a stylesheet sent with `Cache-Control: max-age=3600` is fetched once for two visits. +# Offline. Start the server first: python3 tests/smoke/cache/server.py & then tools/smoke.sh tests/smoke/cache.txt +wait 3 +open http://127.0.0.1:8765/ +waitfor 20 document.title === "Cache" && getComputedStyle(document.body).backgroundColor === "rgb(34, 170, 119)" +open @PAGES@/hello.html +waitload +open http://127.0.0.1:8765/ +waitfor 20 document.title === "Cache" && getComputedStyle(document.body).backgroundColor === "rgb(34, 170, 119)" +js fetch("/count").then(r => r.text()).then(t => { window.count = t; }) +waitfor 5 window.count !== undefined +js window.count +assert window.count === "1" +status done +quit diff --git a/tests/smoke/cache/server.py b/tests/smoke/cache/server.py new file mode 100644 index 0000000..d9c7c57 --- /dev/null +++ b/tests/smoke/cache/server.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +"""HTTP cache check server for tests/smoke/cache.txt: serves a page whose stylesheet may be cached for an hour, +and /count, the number of times the stylesheet was fetched. Listens on 127.0.0.1:8765 until killed.""" +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer + +fetches = 0 + + +class Handler(BaseHTTPRequestHandler): + def do_GET(self): + global fetches + if self.path == "/style.css": + fetches += 1 + self.reply(b"body { background: #2a7; }", "text/css", "max-age=3600") + elif self.path == "/count": + self.reply(str(fetches).encode(), "text/plain", "no-store") + else: + page = b'Cache

Cache check

' + self.reply(page, "text/html", "no-cache") + + def reply(self, body, kind, cache): + self.send_response(200) + self.send_header("Content-Type", kind) + self.send_header("Cache-Control", cache) + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + def log_message(self, *args): + pass + + +ThreadingHTTPServer(("127.0.0.1", 8765), Handler).serve_forever() diff --git a/tests/smoke/keys.txt b/tests/smoke/keys.txt new file mode 100644 index 0000000..5af5b40 --- /dev/null +++ b/tests/smoke/keys.txt @@ -0,0 +1,115 @@ +# Shortcut actions (S006) not covered by basics.txt: bookmarks, pages, developer tools, source, QR code, +# hard reload, home, address bar, zoom out, find previous, media, close window. Offline. +# Save page / Save as PDF open a native file dialog (rfd), and incognito starts a second process (which would +# inherit NACRE_SCRIPT), so they are not run here. +wait 3 +open @PAGES@/basics.html +waitload +expect /bookmarks 0 +do bookmark +wait 0.5 +expect /bookmarks 1 +do new_tab +wait 0.5 +open @PAGES@/hello.html +waitload +do bookmark_all +wait 0.5 +expect /bookmarks 3 +do toggle_bookmarks_bar +wait 0.5 +shot bookmarks-bar +do toggle_bookmarks_bar +do bookmarks_manager +wait 1 +expect /active/url "nacre://bookmarks" +do history +wait 1 +expect /active/url "nacre://history" +do downloads +wait 1 +expect /active/url "nacre://downloads" +do passwords +wait 1 +expect /active/url "nacre://passwords" +do settings +wait 1 +expect /active/url "nacre://settings" +do clear_data +wait 1 +expect /active/url "nacre://clear-data" +do task_manager +wait 1 +expect /active/url "nacre://task-manager" +shot task-manager +# Pages open in their own tab (or reuse it): count what the tab strip has now. +status pages +do tab_1 +wait 0.5 +expect /active/title "Basics" +do view_source +wait 1.5 +status source +shot source +do tab_1 +wait 0.5 +do devtools +wait 1.5 +shot devtools +do tab_1 +wait 0.5 +do qr_code +wait 1 +shot qr +flyout none +# Hard reload, home, address bar focus. +js window.marker = 1 +do hard_reload +waitload +wait 0.5 +assert window.marker === undefined +do zoom_out +wait 0.5 +status zoom-out +do zoom_reset +wait 0.5 +expect /active/zoom 1.0 +cmd find needle +wait 1 +expect /active/find [1,3] +do find_prev +wait 0.5 +expect /active/find [3,3] +key Escape +do focus_address +wait 0.5 +shot focus-address +blur +do home +waitload +wait 0.5 +expect /active/url "nacre://newtab" +# Media: play the local video, then pause it with the shortcut. +open @PAGES@/video.html +waitload +js document.querySelector("video").play() +waitfor 15 !document.querySelector("video").paused && document.querySelector("video").currentTime > 0.5 +wait 1.5 +do media_play_pause +waitfor 5 document.querySelector("video").paused +status media +# Network error page: nothing listens on port 9. +open http://127.0.0.1:9/ +wait 4 +expect /active/title "Couldn't open this page" +status error-page +shot error-page +# Close window keeps the other one. +do new_window +wait 2 +expect /windows 2 +do close_window +wait 1 +expect /windows 1 +status done +quit diff --git a/tests/smoke/site-doctor.txt b/tests/smoke/site-doctor.txt new file mode 100644 index 0000000..80a0be5 --- /dev/null +++ b/tests/smoke/site-doctor.txt @@ -0,0 +1,85 @@ +# Site doctor (R1-04/R1-14, S006): heavy sites people sign in to or that guard themselves. Each one loads, +# gets a shot and a `js` line in selftest.log saying what the page has; `waitfor` fails the run when a page never +# gets that far. NEEDS INTERNET. Direct connections only: never a VPN, Tor or proxy (keep Nacre's VPN off). +# Nothing is submitted and no captcha is clicked: this checks that the pages and widgets work, not that a person +# can get past them. HTTP caching is tests/smoke/cache.txt (offline). Run with SMOKE_TIMEOUT=900 tools/smoke.sh tests/smoke/site-doctor.txt; read the PNGs. +wait 3 +# DuckDuckGo: one search, then a result (a fresh profile, one search only, so its rate limit stays out of it). +open https://duckduckgo.com/ +waitfor 60 !!document.querySelector("textarea[name=q], input[name=q]") +wait 1 +locate textarea[name=q], input[name=q] +wait 1 +click @ +wait 0.5 +pagetype servo browser engine +wait 1 +pagetype {enter} +waitfor 60 location.search.includes("q=servo") && document.querySelectorAll("a[data-testid=result-title-a]").length > 0 +wait 2 +js JSON.stringify({ results: document.querySelectorAll("a[data-testid=result-title-a]").length, oops: document.body.innerText.includes("Oops") }) +shot ddg-results +locate a[data-testid=result-title-a] +wait 1 +click @ +waitfor 60 location.hostname !== "duckduckgo.com" && document.readyState !== "loading" +wait 2 +js location.href +shot ddg-result-opened +# Google sign-in: the page, its email field takes typing. Nothing is sent (no Next). +open https://accounts.google.com/ +waitfor 60 !!document.querySelector("#identifierId") +wait 3 +shot google-signin +locate #identifierId +wait 1 +click @ +wait 0.5 +pagetype nacre.smoke.test +wait 1 +js JSON.stringify({ url: location.href.slice(0, 80), field: document.querySelector("#identifierId").value, next: [...document.querySelectorAll("button")].map(b => b.innerText.trim()).filter(Boolean).slice(0, 5), text: document.body.innerText.slice(0, 200) }) +shot google-signin-typed +# reCAPTCHA v2 demo: the widget's iframe loads and has a size (its checkbox is not clicked). +open https://www.google.com/recaptcha/api2/demo +waitfor 60 [...document.querySelectorAll("iframe[src*=recaptcha]")].some(f => f.getBoundingClientRect().width > 0) +wait 6 +js JSON.stringify([...document.querySelectorAll("iframe")].map(f => ({ src: f.src.slice(0, 60), w: f.getBoundingClientRect().width, h: f.getBoundingClientRect().height }))) +shot recaptcha +# hCaptcha demo. +open https://accounts.hcaptcha.com/demo +waitfor 60 [...document.querySelectorAll("iframe[src*=hcaptcha]")].some(f => f.getBoundingClientRect().width > 0) +wait 6 +js JSON.stringify([...document.querySelectorAll("iframe")].map(f => ({ src: f.src.slice(0, 60), w: f.getBoundingClientRect().width, h: f.getBoundingClientRect().height }))) +shot hcaptcha +# Cloudflare Turnstile demo (it may pass by itself: that is what Turnstile does for a normal browser). The widget +# lives in a shadow root, so the check looks at the API object, the container and the response field. +open https://demo.turnstile.workers.dev/ +waitfor 60 document.readyState !== "loading" +wait 20 +js JSON.stringify({ api: typeof turnstile, container: (document.querySelector(".cf-turnstile") || {}).outerHTML?.slice(0, 200), h: document.querySelector(".cf-turnstile")?.getBoundingClientRect().height, shadow: !!document.querySelector(".cf-turnstile div")?.shadowRoot, token: (document.querySelector("input[name=cf-turnstile-response]") || {}).value ? "set" : "empty", scripts: [...document.scripts].map(s => s.src.slice(0, 70)).filter(Boolean) }) +shot turnstile +# Reddit: a subreddit, scroll. +open https://www.reddit.com/r/rust/ +waitfor 90 document.readyState === "complete" +wait 4 +js JSON.stringify({ title: document.title, posts: document.querySelectorAll("shreddit-post, article").length, blocked: /blocked|whoa there/i.test(document.body.innerText.slice(0, 2000)) }) +shot reddit +pagescroll 400 300 1500 +wait 2 +js window.scrollY +shot reddit-scrolled +# GitHub: a repository, its README, a file. +open https://github.com/servo/servo +waitfor 90 document.readyState === "complete" && !!document.querySelector("article.markdown-body, [data-testid=readme], #readme") +wait 2 +shot github-repo +pagescroll 400 300 1500 +wait 2 +shot github-readme +open https://github.com/servo/servo/blob/main/README.md +waitfor 90 document.readyState === "complete" +wait 3 +js JSON.stringify({ title: document.title, code: !!document.querySelector("article.markdown-body, react-app, [data-testid=read-only-cursor-text-area]") }) +shot github-file +status done +quit