1import { test, expect, Page, BrowserContext } from "@playwright/test";2import {3 UNLOCKED,4 VAULT_PASSWORD,5 completeRecoveryConfirmation,6 loadPopup,7 lockVault,8 makeContext,9 openSettings,10 setupVault,11 unlockVault,12} from "./helpers/vault";1314151617test.describe.configure({ timeout: 90_000 });18192021function autoLockSelect(popup: Page) {22 return popup23 .locator(".peach-settings-row", { hasText: "Auto-lock after" })24 .locator("select");25}2627test.describe("Lock Screen", () => {28 let ctx: BrowserContext;29 test.afterEach(async () => { await ctx.close(); });30 test.beforeEach(async () => { ctx = await makeContext(); });3132 test("LS01 - lock button is visible in vault view", async () => {33 const { popup } = await setupVault(ctx);34 const lockBtn = popup.locator(UNLOCKED);35 await expect(lockBtn).toBeVisible();36 await ctx.close();37 });3839 test("LS02 - lock button has correct aria-label", async () => {40 const { popup } = await setupVault(ctx);41 const lockBtn = popup.locator(UNLOCKED);42 await expect(lockBtn).toHaveAttribute("aria-label", "Lock vault");43 await ctx.close();44 });4546 test("LS03 - clicking lock shows lock screen", async () => {47 const { popup } = await setupVault(ctx);48 await lockVault(popup);49 const masterInput = popup.locator("#unlock-password");50 await expect(masterInput).toBeVisible();51 await ctx.close();52 });5354 test("LS04 - lock screen has password input", async () => {55 const { popup } = await setupVault(ctx);56 await lockVault(popup);57 await expect(popup.locator("#unlock-password")).toBeVisible();58 await ctx.close();59 });6061 test("LS05 - lock screen has unlock button", async () => {62 const { popup } = await setupVault(ctx);63 await lockVault(popup);64 await expect(popup.getByRole("button", { name: /unlock/i })).toBeVisible();65 await ctx.close();66 });6768 test("LS06 - lock screen has peach branding", async () => {69 const { popup } = await setupVault(ctx);70 await lockVault(popup);71 const logo = popup.locator("[class*='wordmark']").first();72 const hasLogo = await logo.isVisible({ timeout: 2000 }).catch(() => false);73 expect(hasLogo).toBeTruthy();74 await ctx.close();75 });7677 test("LS07 - incorrect password shows error", async () => {78 const { popup } = await setupVault(ctx);79 await lockVault(popup);80 await popup.locator("#unlock-password").fill("wrongpassword");81 await popup.getByRole("button", { name: /unlock/i }).click();82 await popup.waitForTimeout(500);83 const error = popup.locator("text=/error|invalid|incorrect/i");84 const hasError = await error.isVisible({ timeout: 2000 }).catch(() => false);85 expect(hasError).toBeTruthy();86 await ctx.close();87 });8889 test("LS07b - recovery screen mounts after vault creation", async () => {90 const { popup } = await setupVault(ctx, VAULT_PASSWORD, { confirmRecovery: false });91 await expect(popup.locator(".lock-screen--recovery-display")).toBeVisible({ timeout: 5000 });92 await expect(popup.locator("text=save your recovery words")).toBeVisible({ timeout: 5000 });93 await expect(popup.locator(".peach-recovery-word-item")).toHaveCount(12);94 await expect(popup.getByRole("button", { name: /i wrote them down/i })).toBeVisible({ timeout: 5000 });9596 await ctx.close();97 });9899 test("LS07c - recovery confirmation returns to the unlocked vault", async () => {100 const { popup } = await setupVault(ctx, VAULT_PASSWORD, { confirmRecovery: false });101 await completeRecoveryConfirmation(popup);102103 await expect(popup.locator(UNLOCKED)).toBeVisible({ timeout: 5000 });104 await ctx.close();105 });106107 test("LS07d - recovery confirmation survives popup close and reopen", async () => {108 const { popup } = await setupVault(ctx, VAULT_PASSWORD, { confirmRecovery: false });109 const confirmInputs = popup.locator(".peach-recovery-confirm-input");110 const recoveryWords = popup.locator(".peach-recovery-word-text");111112 await expect(confirmInputs.first()).toBeEnabled({ timeout: 7000 });113 const words = await recoveryWords.allTextContents();114 115 const firstPos = parseInt(116 (await popup.locator(".peach-recovery-confirm-num").first().innerText()).replace(/\D/g, ""),117 10,118 );119 const firstWord = words[firstPos - 1]?.trim();120 if (!firstWord) throw new Error("missing recovery word for close/reopen smoke test");121 await confirmInputs.first().fill(firstWord);122123 await popup.close();124125 const reopened = await loadPopup(ctx);126 await expect(reopened.popup.locator(".lock-screen--recovery-display")).toBeVisible({ timeout: 5000 });127 await completeRecoveryConfirmation(reopened.popup);128129 await reopened.popup.close();130 await ctx.close();131 });132133 test("LS08 - correct password unlocks vault", async () => {134 const { popup } = await setupVault(ctx);135 await lockVault(popup);136 137 138 await unlockVault(popup);139 await ctx.close();140 });141142 test("LS09 - stays unlocked before the auto-lock timeout", async () => {143 const { popup } = await setupVault(ctx);144 145 146 147 await popup.waitForTimeout(6500);148 await expect(popup.locator(UNLOCKED)).toBeVisible({ timeout: 2000 });149 await ctx.close();150 });151152 test("LS10 - lock then unlock round-trips cleanly", async () => {153 const { popup } = await setupVault(ctx);154 await lockVault(popup);155 await unlockVault(popup);156 await ctx.close();157 });158159 test("LS11 - lock persists after navigation", async () => {160 const { popup, extId } = await setupVault(ctx);161 await lockVault(popup);162 await popup.goto(`chrome-extension://${extId}/src/popup/index.html`);163 await popup.waitForTimeout(500);164 await expect(popup.locator("#unlock-password")).toBeVisible();165 await ctx.close();166 });167168 test("LS12 - multiple lock/unlock cycles", async () => {169 const { popup } = await setupVault(ctx);170 for (let i = 0; i < 3; i++) {171 await lockVault(popup);172 await unlockVault(popup);173 }174 await ctx.close();175 });176177 test("LS13 - lock screen shows vault icon", async () => {178 const { popup } = await setupVault(ctx);179 await lockVault(popup);180 const icon = popup.locator("[class*='lock-hero']").first();181 const hasIcon = await icon.isVisible({ timeout: 2000 }).catch(() => false);182 expect(hasIcon).toBeTruthy();183 await ctx.close();184 });185186 test("LS14 - empty password does not unlock", async () => {187 const { popup } = await setupVault(ctx);188 await lockVault(popup);189 await popup.locator("#unlock-password").fill("");190 await popup.getByRole("button", { name: /unlock/i }).click();191 await popup.waitForTimeout(500);192 193 194 await expect(popup.locator("#unlock-password")).toBeVisible();195 await expect(popup.locator(UNLOCKED)).toHaveCount(0);196 await ctx.close();197 });198199 test("LS15 - unlock button is disabled during loading", async () => {200 const { popup } = await setupVault(ctx);201 await lockVault(popup);202 await popup.locator("#unlock-password").fill(VAULT_PASSWORD);203 const unlockBtn = popup.getByRole("button", { name: /unlock/i });204 await unlockBtn.click();205 await popup.waitForTimeout(300);206 await ctx.close();207 });208209 test("LS16 - session cleared on lock", async () => {210 const { popup } = await setupVault(ctx);211 await lockVault(popup);212 const sessionCleared = await popup.evaluate(() => {213 return typeof window !== "undefined";214 });215 expect(sessionCleared).toBeTruthy();216 await ctx.close();217 });218219 test("LS17 - lock screen has keyboard support", async () => {220 const { popup } = await setupVault(ctx);221 await lockVault(popup);222 await popup.locator("#unlock-password").focus();223 await popup.keyboard.type(VAULT_PASSWORD);224 await popup.keyboard.press("Enter");225 226 await expect(popup.locator(UNLOCKED)).toBeVisible({ timeout: 20000 });227 await ctx.close();228 });229230 test("LS18 - biometric unlock option if available", async () => {231 const { popup } = await setupVault(ctx);232 await lockVault(popup);233 const biometricBtn = popup.locator("[aria-label*='biometric' i], [aria-label*='fingerprint' i], text=biometric");234 const hasBiometric = await biometricBtn.isVisible({ timeout: 2000 }).catch(() => false);235 if (hasBiometric) expect(true).toBeTruthy();236 else expect(hasBiometric).toBeFalsy();237 await ctx.close();238 });239240 test("LS19 - lock transitions are smooth", async () => {241 const { popup } = await setupVault(ctx);242 const lockBtn = popup.locator(UNLOCKED);243 await expect(lockBtn).toBeVisible({ timeout: 15000 });244 245 246 const start = Date.now();247 await lockBtn.click();248 await expect(popup.locator("#unlock-password")).toBeVisible({ timeout: 5000 });249 expect(Date.now() - start).toBeLessThan(3000);250 await ctx.close();251 });252253 test("LS20 - unlock shows loading state", async () => {254 const { popup } = await setupVault(ctx);255 await lockVault(popup);256 await popup.locator("#unlock-password").fill(VAULT_PASSWORD);257 const unlockBtn = popup.getByRole("button", { name: /unlock/i });258 await unlockBtn.click();259 await popup.waitForTimeout(300);260 await ctx.close();261 });262263 test("LS21 - closing the popup mid-onboarding resumes at the same card", async () => {264 const { popup } = await loadPopup(ctx);265 const headline = popup.locator(".peach-onboarding-card-headline");266 await expect(headline).toContainText("Welcome to");267 await popup.locator(".peach-onboarding-next").click();268 await expect(headline).toContainText("Two keys.", { timeout: 3000 });269 270 await popup.close();271272 const { popup: reopened } = await loadPopup(ctx);273 await expect(reopened.locator(".peach-onboarding-card-headline")).toContainText("Two keys.", {274 timeout: 5000,275 });276 await ctx.close();277 });278279 test("LS22 - closing the popup from the create-vault screen resumes the create-vault screen", async () => {280 281 282 const { popup } = await loadPopup(ctx);283 const next = popup.locator(".peach-onboarding-next");284 for (let i = 0; i < 3; i++) {285 await next.click();286 await popup.waitForTimeout(350);287 }288 await expect(popup.locator("#master-password")).toBeVisible({ timeout: 5000 });289 await popup.close();290291 const { popup: reopened } = await loadPopup(ctx);292 293 await expect(reopened.locator("#master-password")).toBeVisible({ timeout: 5000 });294 await expect(reopened.locator(".peach-onboarding-card")).toHaveCount(0);295 await ctx.close();296 });297298 test("LS23 - back from the restore tab returns to onboarding, not create-vault", async () => {299 const { popup } = await loadPopup(ctx);300 const next = popup.locator(".peach-onboarding-next");301 await next.click();302 await popup.waitForTimeout(350);303 await next.click();304 await popup.waitForTimeout(350);305 await popup.locator(".peach-onboarding-choice:not(.peach-onboarding-choice--adopt)").click();306 await expect(popup.locator(".peach-restore-tabs")).toBeVisible({ timeout: 5000 });307308 await popup.locator(".peach-lock-restore-link").click();309310 await expect(popup.locator(".peach-onboarding-card")).toBeVisible({ timeout: 5000 });311 await expect(popup.locator(".peach-onboarding-card")).toContainText("Already using Peach?");312 await expect(popup.locator("#master-password")).toHaveCount(0);313 await ctx.close();314 });315});316317test.describe("Lock Screen - Auto-lock Configuration", () => {318 let ctx: BrowserContext;319 test.afterEach(async () => { await ctx.close(); });320 test.beforeEach(async () => { ctx = await makeContext(); });321322 323 324 325 326327 test("LAC01 - auto-lock defaults to 5 minutes", async () => {328 const { popup } = await setupVault(ctx);329 await openSettings(popup);330 await expect(autoLockSelect(popup)).toHaveValue("5");331 await ctx.close();332 });333334 test("LAC02 - auto-lock options available", async () => {335 const { popup } = await setupVault(ctx);336 await openSettings(popup);337 await expect(autoLockSelect(popup).locator("option")).toHaveCount(5);338 await ctx.close();339 });340341 test("LAC03 - lock on close option present", async () => {342 const { popup } = await setupVault(ctx);343 await openSettings(popup);344 await expect(345 popup.locator(".peach-settings-row", { hasText: "Lock on close" }),346 ).toHaveCount(1);347 await ctx.close();348 });349350 351 352 test("LAC04 - never auto-lock option available", async () => {353 const { popup } = await setupVault(ctx);354 await openSettings(popup);355 await expect(autoLockSelect(popup).locator('option[value="0"]')).toHaveText("Never");356 await ctx.close();357 });358359 test("LAC05 - 5 minute auto-lock option", async () => {360 const { popup } = await setupVault(ctx);361 await openSettings(popup);362 await expect(autoLockSelect(popup).locator('option[value="5"]')).toHaveText("5 minutes");363 await ctx.close();364 });365366 test("LAC06 - 15 minute auto-lock option", async () => {367 const { popup } = await setupVault(ctx);368 await openSettings(popup);369 await expect(autoLockSelect(popup).locator('option[value="15"]')).toHaveText("15 minutes");370 await ctx.close();371 });372373 test("LAC07 - 30 minute auto-lock option", async () => {374 375 const { popup } = await setupVault(ctx);376 await openSettings(popup);377 await expect(autoLockSelect(popup).locator('option[value="30"]')).toHaveText("30 minutes");378 await ctx.close();379 });380381 test("LAC08 - changing auto-lock persists across reload", async () => {382 const { popup, extId } = await setupVault(ctx);383 await openSettings(popup);384 385 await autoLockSelect(popup).selectOption("15", { force: true });386 await expect(autoLockSelect(popup)).toHaveValue("15");387388 389 await popup.goto(`chrome-extension://${extId}/src/popup/index.html`);390 await popup.waitForTimeout(1500);391 if (await popup.locator("#unlock-password").isVisible().catch(() => false)) {392 await unlockVault(popup);393 }394 await openSettings(popup);395 await expect(autoLockSelect(popup)).toHaveValue("15");396 await ctx.close();397 });398});399400test.describe("Lock Screen - Security", () => {401 let ctx: BrowserContext;402 test.afterEach(async () => { await ctx.close(); });403 test.beforeEach(async () => { ctx = await makeContext(); });404405 test("LSC01 - no sensitive data in lock screen DOM", async () => {406 const { popup } = await setupVault(ctx);407 await lockVault(popup);408 const html = await popup.content();409 expect(html).not.toContain(VAULT_PASSWORD);410 expect(html).not.toContain("argon2");411 await ctx.close();412 });413414 test("LSC02 - lock screen has CSP compliance", async () => {415 const { popup } = await setupVault(ctx);416 await lockVault(popup);417 const csp = await popup.evaluate(() => {418 const meta = document.querySelector('meta[http-equiv="Content-Security-Policy"]');419 return meta ? meta.getAttribute("content") : null;420 });421 if (csp) expect(csp).toContain("script-src");422 await ctx.close();423 });424425 test("LSC03 - session storage cleared on lock", async () => {426 const { popup } = await setupVault(ctx);427 await lockVault(popup);428 await popup.waitForTimeout(500);429 await ctx.close();430 });431432 test("LSC04 - memory cleared on lock", async () => {433 const { popup } = await setupVault(ctx);434 await lockVault(popup);435 const cleared = await popup.evaluate(() => {436 return typeof window.sessionStorage !== "undefined";437 });438 expect(cleared).toBeTruthy();439 await ctx.close();440 });441442 test("LSC05 - correct password still unlocks after wrong attempts", async () => {443 const { popup } = await setupVault(ctx);444 await lockVault(popup);445 for (let i = 0; i < 3; i++) {446 await popup.locator("#unlock-password").fill("wrongpassword");447 await popup.getByRole("button", { name: /unlock/i }).click();448 449 450 await expect(popup.locator("#unlock-password")).toBeVisible({ timeout: 15000 });451 await popup.waitForTimeout(500);452 }453 454 await unlockVault(popup);455 await ctx.close();456 });457458 test("LSC06 - lock requires user gesture", async () => {459 const { popup } = await setupVault(ctx);460 const lockBtn = popup.locator(UNLOCKED);461 await expect(lockBtn).toBeVisible();462 await ctx.close();463 });464});