Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions tests/ax-settings-select.test.js

This file was deleted.

231 changes: 0 additions & 231 deletions tests/ax-settings-win-finder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import { test } from "node:test";

const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const axSrc = readFileSync(join(root, "scripts/ax-settings-win.ps1"), "utf8");
const phase2Src = readFileSync(
join(root, "scripts/verify-settings-webview-phase2-win.ps1"),
"utf8",
);

function extractFunction(src, name) {
const marker = `function ${name}`;
Expand Down Expand Up @@ -78,16 +74,13 @@ function matches(el, conds) {
}

const finder = extractFunction(axSrc, "Find-SettingsWindow");
assert.doesNotMatch(finder, /FidgetSettings/);

const webviewConds = parsePropertyConditions(finder);
const webviewByVar = new Map(webviewConds.map((c) => [c.var, c]));
const webviewAnds = parseAndConditionArgs(finder, "webviewCond");

const noPidAnd = webviewAnds.find((args) => !args.includes("pidCond"));
const withPidAnd = webviewAnds.find((args) => args.includes("pidCond"));
assert.ok(noPidAnd, "webview arm must have a no-ProcessId AndCondition");
assert.ok(withPidAnd, "webview arm must And ProcessId when the caller has one");

const webviewUnconditional = noPidAnd.map((name) => {
const cond = webviewByVar.get(name);
Expand All @@ -113,16 +106,6 @@ const otherTauri = {
controlType: "Window",
};

test("webview AndCondition requires ClassName Tauri Window, Name Settings, and ControlType Window", () => {
const props = webviewUnconditional.map((c) => c.property).sort();
assert.deepEqual(props, ["ClassNameProperty", "ControlTypeProperty", "NameProperty"]);

const byProp = Object.fromEntries(webviewUnconditional.map((c) => [c.property, c.value]));
assert.equal(unquote(byProp.ClassNameProperty), "Tauri Window");
assert.equal(unquote(byProp.NameProperty), "Settings");
assert.match(byProp.ControlTypeProperty, /ControlType\]::Window/);
});

test("Name-only is insufficient: the Windows Settings app is not a match", () => {
const nameOnly = webviewUnconditional.filter(
(c) => c.property === "NameProperty" || c.property === "ControlTypeProperty",
Expand All @@ -137,217 +120,3 @@ test("Name-only is insufficient: the Windows Settings app is not a match", () =>
assert.equal(matches(tauriSettings, webviewUnconditional), true);
assert.equal(matches(otherTauri, webviewUnconditional), false);
});

test("optional ProcessId is AND-ed onto the finder and is not named Pid", () => {
assert.match(axSrc, /\[Parameter\(Position=1\)\]\s*\[int\]\$ProcessId = 0/);
assert.doesNotMatch(axSrc, /param\([^)]*\$Pid\b/s);

assert.deepEqual(withPidAnd.slice(0, 3), noPidAnd);
assert.equal(withPidAnd.at(-1), "pidCond");

const pidCond = webviewByVar.get("pidCond");
assert.equal(pidCond.property, "ProcessIdProperty");
assert.equal(pidCond.value, "$ProcessId");
});

test("FromHandle helper is the multi-monitor UIA entry, not RootElement", () => {
const helper = extractFunction(axSrc, "Get-AutomationElementFromHandle");
assert.match(helper, /AutomationElement\]::FromHandle/);
assert.doesNotMatch(helper, /AutomationElement\]::RootElement/);
assert.match(helper, /multi-monitor/);
assert.match(finder, /WindowHandle/);
assert.match(finder, /Get-AutomationElementFromHandle/);
assert.match(finder, /multi-monitor/);
});

test("phase2 relies on the webview default", () => {
assert.doesNotMatch(phase2Src, /FIDGET_SETTINGS_WEBVIEW/);
assert.doesNotMatch(phase2Src, /FIDGET_SETTINGS_NATIVE/);
assert.doesNotMatch(phase2Src, /FidgetSettings/);
});

test("phase2 smoke never assigns $PID and uses ProcessId names", () => {
assert.doesNotMatch(phase2Src, /\$pid\s*=/i);
assert.match(phase2Src, /\$targetProcessId/);
assert.match(phase2Src, /Constant\+AllScope/);
});

test("phase2 UIA is FromHandle-only and parks via work area", () => {
assert.match(phase2Src, /AutomationElement\]::FromHandle/);
assert.doesNotMatch(phase2Src, /AutomationElement\]::RootElement/);
assert.match(phase2Src, /EnumDisplayMonitors/);
assert.match(phase2Src, /No secondary monitor/);
assert.match(phase2Src, /GetWindowRect/);
assert.doesNotMatch(phase2Src, /VirtualScreen/);
assert.doesNotMatch(phase2Src, /::SetCursorPos/);
});

test("phase2 CHECK2 tries LegacyIAccessible before PostMessage", () => {
const activate = extractFunction(phase2Src, "Invoke-UiaActivate");
const invokeAt = activate.indexOf("InvokePattern");
const selectAt = activate.indexOf("SelectionItemPattern");
const legacyAt = activate.indexOf("LegacyIAccessiblePattern");
const postAt = activate.indexOf("[Phase2Win]::PostMessage");
assert.ok(invokeAt >= 0 && selectAt > invokeAt, "Invoke then SelectionItem");
assert.ok(legacyAt > selectAt, "LegacyIAccessible after the two missing WebView2 patterns");
assert.match(activate, /DoDefaultAction/);
assert.ok(postAt > legacyAt, "PostMessage last, still no SetCursorPos");
});

test("phase2 CHECK2 waits for TabItem names then finds TabItem AND Name", () => {
const waiter = extractFunction(phase2Src, "Wait-SettingsTabs");
assert.match(waiter, /TimeoutMs = 8000/);
assert.match(waiter, /PollMs = 350/);
assert.match(waiter, /Find-SettingsTab/);
assert.doesNotMatch(waiter, /AutomationElement\]::RootElement/);

const tabFinder = extractFunction(phase2Src, "Find-SettingsTab");
assert.match(tabFinder, /New-TabItemAndNameCondition/);
assert.doesNotMatch(tabFinder, /AutomationElement\]::RootElement/);

const condFn = extractFunction(phase2Src, "New-TabItemAndNameCondition");
const conds = parsePropertyConditions(condFn);
const byVar = new Map(conds.map((c) => [c.var, c]));
const ands = parseAndConditionArgs(condFn, "andCond");
assert.equal(ands.length, 1);
assert.deepEqual(ands[0].slice().sort(), ["nameCond", "typeCond"]);
assert.equal(byVar.get("nameCond").property, "NameProperty");
assert.equal(byVar.get("nameCond").value, "$Name");
assert.equal(byVar.get("typeCond").property, "ControlTypeProperty");
assert.match(byVar.get("typeCond").value, /ControlType\]::TabItem/);

const tabItemAndName = [
{ property: "NameProperty", value: '"Presence"' },
byVar.get("typeCond"),
];
const presencePane = { name: "Presence", controlType: "Pane" };
const presenceTab = { name: "Presence", controlType: "TabItem" };
assert.equal(matches(presencePane, tabItemAndName), false, "Pane named Presence is not a tab");
assert.equal(matches(presenceTab, tabItemAndName), true);
assert.match(phase2Src, /already selected \(activate no-op/);
});

test("phase2 reports the four #715 checks and crops evidence to HWND", () => {
assert.match(phase2Src, /1_window_opens/);
assert.match(phase2Src, /2_all_tabs/);
assert.match(phase2Src, /3_roundtrip/);
assert.match(phase2Src, /4_zorder/);
assert.match(phase2Src, /fidget\\settings\.json/);
const capture = extractFunction(phase2Src, "Capture");
assert.match(capture, /GetWindowRect/);
assert.match(capture, /CopyFromScreen/);
assert.match(capture, /\/ 3\.0/);
});

function hwndAbove(front, back, stack) {
const fi = stack.indexOf(front);
const bi = stack.indexOf(back);
return fi >= 0 && bi >= 0 && fi < bi;
}

function settingsAboveOverlays(settings, overlays, stack) {
if (!overlays.length) return false;
return overlays.every((ov) => hwndAbove(settings, ov, stack));
}

function isOverlay(el, settingsHwnd, minW, minH) {
if (el.hwnd === settingsHwnd) return false;
if (el.title === "Settings") return false;
if (el.title !== "Fidget") return false;
if (el.processId !== el.boundProcessId) return false;
return el.width >= minW && el.height >= minH;
}

test("phase2 check 4 is PASS/FAIL from GetWindow stacking, not REVIEW", () => {
const walk = extractFunction(phase2Src, "Get-ZOrderHwnds");
assert.match(walk, /GetTopWindow/);
assert.match(walk, /GW_HWNDNEXT/);
assert.match(phase2Src, /public const uint GW_HWNDNEXT = 2/);

const above = extractFunction(phase2Src, "Test-HwndAbove");
assert.match(above, /Get-HwndStackIndex/);
assert.match(above, /-lt/);

const find = extractFunction(phase2Src, "Find-OverlayHwnds");
assert.match(find, /\$t -ne 'Fidget'/);
assert.match(find, /GetWindowRect/);
assert.match(find, /\$t -eq 'Settings'/);

assert.match(phase2Src, /Capture '04-zorder\.png'/);
assert.match(
phase2Src,
/\$Report\.checks\['4_zorder'\] = \$\(if \(\$zOk\) \{ 'PASS' \} else \{ 'FAIL' \}\)/,
);
assert.doesNotMatch(phase2Src, /4_zorder'\] = 'REVIEW'/);
assert.doesNotMatch(phase2Src, /Judge Settings above/);
});

test("stacking fixtures: Settings before overlay is above; missing HWND is not", () => {
assert.equal(hwndAbove("settings", "overlay", ["settings", "overlay", "other"]), true);
assert.equal(hwndAbove("settings", "overlay", ["overlay", "settings"]), false);
assert.equal(hwndAbove("settings", "overlay", ["settings"]), false);
assert.equal(hwndAbove("settings", "overlay", ["overlay"]), false);
assert.equal(
settingsAboveOverlays("settings", ["ov1", "ov2"], ["settings", "ov1", "ov2"]),
true,
);
assert.equal(
settingsAboveOverlays("settings", ["ov1", "ov2"], ["ov1", "settings", "ov2"]),
false,
);
assert.equal(settingsAboveOverlays("settings", [], ["settings"]), false);

const all = extractFunction(phase2Src, "Test-SettingsAboveOverlays");
assert.match(all, /Test-HwndAbove/);
assert.match(all, /Count -eq 0/);
});

test("overlay finder fixtures: large Fidget matches; Settings, 1x1 anchor, and Chat do not", () => {
const minW = 400;
const minH = 400;
const settingsHwnd = 1;
const tauriSettings = {
hwnd: 1,
title: "Settings",
width: 600,
height: 520,
processId: 4242,
boundProcessId: 4242,
};
const overlay = {
hwnd: 2,
title: "Fidget",
width: 1920,
height: 1080,
processId: 4242,
boundProcessId: 4242,
};
const anchor = {
hwnd: 3,
title: "Fidget",
width: 1,
height: 1,
processId: 4242,
boundProcessId: 4242,
};
const chat = {
hwnd: 4,
title: "Timber Wolf",
width: 420,
height: 560,
processId: 4242,
boundProcessId: 4242,
};
const otherPid = { ...overlay, hwnd: 5, processId: 99, boundProcessId: 4242 };
assert.equal(isOverlay(overlay, settingsHwnd, minW, minH), true);
assert.equal(isOverlay(tauriSettings, settingsHwnd, minW, minH), false);
assert.equal(isOverlay(anchor, settingsHwnd, minW, minH), false);
assert.equal(isOverlay(chat, settingsHwnd, minW, minH), false);
assert.equal(isOverlay(otherPid, settingsHwnd, minW, minH), false);

const find = extractFunction(phase2Src, "Find-OverlayHwnds");
assert.match(find, /\$t -ne 'Fidget'/);
assert.match(find, /\$w -ge \$script:overlayMinW/);
assert.match(find, /\$hgt -ge \$script:overlayMinH/);
assert.match(find, /\$processId -ne \$script:overlayPid/);
});
62 changes: 18 additions & 44 deletions tests/bubble.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Run with `node --test tests/`.

import assert from "node:assert/strict";
import { test } from "node:test";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";

import {
Expand Down Expand Up @@ -156,33 +156,6 @@ test("inverted Speech bubble reports inverted so the tail can point up", () => {
assert.equal(pos.inverted, true);
});

// #903: the inverted class flips the same ring/fill sandwich to the top.
// Default stays bottom + border-top; inverted uses top + border-bottom.
test("inverted Speech bubble tail CSS points up at the Character", () => {
const css = readFileSync(join(dirname(fileURLToPath(import.meta.url)), "../src/main.css"), "utf8");

assert.match(
css,
/\.bubble::before\s*\{[^}]*bottom:\s*-10px;[^}]*border-top:/s,
"default ring hangs off the bottom and points down",
);
assert.match(
css,
/\.bubble::after\s*\{[^}]*bottom:\s*-7px;[^}]*border-top:/s,
"default fill sits on that ring",
);
assert.match(
css,
/\.bubble\.inverted::before\s*\{[^}]*top:\s*-10px;[^}]*border-bottom:/s,
"inverted ring sits on the top edge and points up",
);
assert.match(
css,
/\.bubble\.inverted::after\s*\{[^}]*top:\s*-7px;[^}]*border-bottom:/s,
"inverted fill sits on that ring",
);
});

// The clamp is the only thing that moves the bubble off the head: with room
// above, the same sprite height gets the untouched 10px gap.
test("bubble keeps its 10px gap over the head when there is room", () => {
Expand Down Expand Up @@ -560,22 +533,6 @@ test("a line crossing the seam hides on the old display before it shows on the n
assert.equal(b.surface(), "speech", "and the new one shows the same line");
});

// The control draws only where the Shell says a reported rectangle wins the
// click, asked by name across a language boundary. A typo on either side is
// silent: `invoke` rejects, the flag stays false, and the control never appears.
test("the capability the renderer asks for is a command the Shell registers", () => {
const dir = dirname(fileURLToPath(import.meta.url));
const renderer = readFileSync(join(dir, "../src/main.js"), "utf8");
const shell = readFileSync(join(dir, "../src-tauri/src/main.rs"), "utf8");

const asked = renderer.match(/invoke\(\s*"(overlay_hit_tests_hotspots)"/);
assert.ok(asked, "the renderer asks the Shell whether it hit-tests hotspots");
assert.match(
shell,
new RegExp(`generate_handler!\\[[^\\]]*\\b${asked[1]}\\b`, "s"),
`${asked[1]} is registered in generate_handler!`,
);
});
// A reply the token cap ended is still spoken. The mark rides in the
// remembered text, not in the bubble.
test("a truncated reply is spoken without the mark visible", () => {
Expand All @@ -593,3 +550,20 @@ test("a truncated reply is spoken without the mark visible", () => {
"the next whole line is not marked with the last one's mark",
);
});

// The control draws only where the Shell says a reported rectangle wins the
// click, asked by name across a language boundary. A typo on either side is
// silent: `invoke` rejects, the flag stays false, and the control never appears.
test("the capability the renderer asks for is a command the Shell registers", () => {
const dir = dirname(fileURLToPath(import.meta.url));
const renderer = readFileSync(join(dir, "../src/main.js"), "utf8");
const shell = readFileSync(join(dir, "../src-tauri/src/main.rs"), "utf8");

const asked = renderer.match(/invoke\(\s*"(overlay_hit_tests_hotspots)"/);
assert.ok(asked, "the renderer asks the Shell whether it hit-tests hotspots");
assert.match(
shell,
new RegExp(`generate_handler!\\[[^\\]]*\\b${asked[1]}\\b`, "s"),
`${asked[1]} is registered in generate_handler!`,
);
});
22 changes: 0 additions & 22 deletions tests/chat-appearance-paint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,6 @@ const SRC = fileURLToPath(new URL("../src/", import.meta.url));
const CSS = readFileSync(new URL("../src/chat-ui.css", import.meta.url), "utf8");
const DESIGNS = ["minimal", "terminal", "glass"];

test("chat-ui.css has no prefers-color-scheme", () => {
assert.doesNotMatch(CSS, /prefers-color-scheme/);
});

test("each design has a light palette block, and glass covers of and what", () => {
for (const design of DESIGNS) {
assert.match(
CSS,
new RegExp(String.raw`\[data-chat-palette="light"\]\.chat-ui-${design}\b`),
design,
);
}
assert.match(
CSS,
/\[data-chat-palette="light"\]\.chat-ui-glass \.tb \.of\s*\{[^}]*color:\s*rgba\(26,\s*31,\s*43,\s*\.62\)/s,
);
assert.match(
CSS,
/\[data-chat-palette="light"\]\.chat-ui-glass \.ask \.what\s*\{[^}]*color:\s*rgba\(26,\s*31,\s*43,\s*\.82\)/s,
);
});

function declaredToken(selector, name) {
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const block = CSS.match(new RegExp(`${escaped}\\s*\\{([^}]+)\\}`));
Expand Down
Loading
Loading