diff options
| author | Igor Soarez <igor@soarez.org> | 2026-11-14 09:15:15 +0000 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-11-14 09:15:34 +0000 |
| commit | a76fbc3b9b82038ab44c04d6379cc2d45e5cecd8 (patch) | |
| tree | 7cf7425cfbca05a99b42198f78ff3fcf1a6eb5d8 /test-suite/unit/background-policy.test.mjs | |
| parent | e18559a1240219b977ffc7da2076c09cd96d1dad (diff) | |
Measured in Brave on 2026-11-14: an inactive tab takes trusted CDP clicks,
key presses, text and mouse moves, and Page.captureScreenshot renders it
live. Only mouseWheel hangs, waiting for a frame. The upstream guard that
refused input to every hidden page was wrong for inactive tabs, and it is
what made a window per session look necessary.
- New sessions' tabs open inactive in the user's last focused window, in
the session's tab group; a window is created only when none is open.
- New groups start collapsed, unless their tab is the one showing, and
expand when a tab in them is brought forward. Existing groups keep the
user's setting.
- Input is refused up front only in a minimized window (untested there).
- chrome_scroll scrolls hidden pages by script instead of the wheel.
- Focus emulation on attach, so blur-sensitive menus stay open.
- Background mode is off by default. Calls still default to background;
background:false or chrome_tab activate brings a tab forward.
- Agent guidance, tool descriptions and docs say so.
Diffstat (limited to 'test-suite/unit/background-policy.test.mjs')
| -rw-r--r-- | test-suite/unit/background-policy.test.mjs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/test-suite/unit/background-policy.test.mjs b/test-suite/unit/background-policy.test.mjs index ea08be0..98eaa7c 100644 --- a/test-suite/unit/background-policy.test.mjs +++ b/test-suite/unit/background-policy.test.mjs @@ -71,7 +71,7 @@ function piHarness({ session = "alpha", send } = {}) { } const flagCases = [ - [{}, false], [{ background: false }, false], [{ background: true }, true], + [{}, true], [{ background: false }, false], [{ background: true }, true], [{ foreground: true }, false], [{ foreground: false }, true], [{ background: false, foreground: false }, false], [{ background: true, foreground: true }, true], ]; @@ -96,6 +96,7 @@ test("session background on overrides all per-call/legacy foreground flags; off test("every registered page tool, tab.new, and chrome_launch(url) use the central policy", async () => { const h = piHarness(); + await h.background("on"); const cases = [ ["chrome_launch", { url: "https://example.test" }, "tab.new"], ["chrome_tab", { action: "new", group: false, groupTitle: "other" }, "tab.new"], @@ -143,7 +144,11 @@ test("typing options and verification pass through real tool registrations witho test("activation is rejected before dispatch; existing on/off/toggle/status commands suffice", async () => { const h = piHarness(); - await assert.rejects(h.tool("chrome_tab", { action: "activate", targetId: "2", background: false }), /background mode.*\/chrome background off/); + await h.tool("chrome_tab", { action: "activate", targetId: "2" }); + assert.equal(h.calls.at(-1).params.foreground, true, "activation is allowed by default"); + h.calls.length = 0; + await h.background("on"); + await assert.rejects(h.tool("chrome_tab", { action: "activate", targetId: "2", background: false }), /background mode on/); assert.equal(h.calls.length, 0); await h.background("off"); await h.tool("chrome_tab", { action: "activate", targetId: "2" }); @@ -199,9 +204,9 @@ test("shared-owner sessions retain independent policies; per-call background sti const sharedCalls = []; const send = async (action, params) => { sharedCalls.push({ action, params }); return {}; }; const a = piHarness({ session: "A", send }), b = piHarness({ session: "B", send }); - await b.background("off"); + await a.background("on"); await a.send("tab.new", { background: false }); - await b.send("tab.new", {}); + await b.send("tab.new", { background: false }); assert.equal(sharedCalls[0].params.sessionKey, "session:A"); assert.equal(sharedCalls[0].params.foreground, false); assert.equal(sharedCalls[0].action, "tab.new.background"); @@ -314,6 +319,7 @@ function assertNoFocus(h) { test("Pi-to-worker background aliases preserve grouping, screenshot output, and ownership-aware cleanup", async () => { const h = workerHarness(); const pi = piHarness({ send: (action, params) => h.w.dispatch(action, params) }); + await pi.background("on"); const opened = await pi.tool("chrome_tab", { action: "new", group: false, groupTitle: "wrong", background: false }); assert.equal(opened.details.result.group.title, "Pi Session: alpha"); const launched = await pi.tool("chrome_launch", { url: "https://fixture.test" }); |
