diff options
Diffstat (limited to 'test-suite/unit/background-policy.test.mjs')
| -rw-r--r-- | test-suite/unit/background-policy.test.mjs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/test-suite/unit/background-policy.test.mjs b/test-suite/unit/background-policy.test.mjs index efbca78..ea08be0 100644 --- a/test-suite/unit/background-policy.test.mjs +++ b/test-suite/unit/background-policy.test.mjs @@ -297,6 +297,14 @@ function workerHarness({ withWindows = true } = {}) { }; return h; } +// A new Pi tab must not take over the user's window: it is either inactive, or the only tab of a +// new, unfocused window of the session's own (so it is visible to the agent without stealing focus). +function assertNewTabStaysOutOfTheWay(h, tab) { + if (tab.active === false) return; + assert.notEqual(tab.windowId, 1, "an active new tab must not be in the user's window"); + assert.ok(h.calls.some((c) => c.action === "windows.create" && c.params.focused === false), "its window was created unfocused"); +} + function assertNoFocus(h) { assert.equal(h.focusedWindow(), 1); assert.equal(h.tabs.get(1).active, true); @@ -325,7 +333,7 @@ test("worker advertises support, keeps new tabs inactive, and rejects activation assert.equal((await h.w.dispatch("tab.version", {})).capabilities.hardBackground, true); for (const flags of [{}, { foreground: false }, { background: true, foreground: true }]) { const result = await h.w.dispatch("tab.new", { ...flags, sessionKey: "alpha", groupTitle: "Pi Session: alpha" }); - assert.equal(result.tab.active, false); + assertNewTabStaysOutOfTheWay(h, result.tab); await assert.rejects(h.w.dispatch("tab.activate", { ...flags, targetId: "missing" }), /background mode/); } assertNoFocus(h); @@ -339,7 +347,7 @@ test("worker advertises support, keeps new tabs inactive, and rejects activation test("background-only worker aliases force safe behavior even with foreground flags", async () => { const h = workerHarness(); const opened = await h.w.dispatch("tab.new.background", { foreground: true, background: false }); - assert.equal(opened.tab.active, false); + assertNewTabStaysOutOfTheWay(h, opened.tab); const shot = await h.w.dispatch("page.screenshot.background", { targetId: "2", foreground: true, background: false }); assert.equal(shot.method, "cdp"); assertNoFocus(h); |
