diff --git a/tests/unit/storage-registry.test.ts b/tests/unit/storage-registry.test.ts index 7259492e..44e03db1 100644 --- a/tests/unit/storage-registry.test.ts +++ b/tests/unit/storage-registry.test.ts @@ -11,7 +11,7 @@ import { type StorageKeyInput, } from "../../src/contracts/storage-keys.ts"; -type StorageFailureMode = "none" | "quota" | "security"; +type StorageFailureMode = "none" | "quota" | "firefox-quota" | "security"; function createStorage(options: { initial?: Readonly>; @@ -54,6 +54,10 @@ function throwFor(mode: StorageFailureMode): void { if (mode === "quota") { throw new DOMException("private quota detail", "QuotaExceededError"); } + if (mode === "firefox-quota") { + // Older Firefox names the quota error this way, with code 1014. + throw new DOMException("private quota detail", "NS_ERROR_DOM_QUOTA_REACHED"); + } if (mode === "security") { throw new DOMException("private security detail", "SecurityError"); } @@ -278,6 +282,22 @@ describe("storage registry", () => { ); }); + // 2026-11-01 05-06. The second quota name was in the adapter's list but no + // test sent it, so dropping it went unseen. + it("falls back to memory on Firefox's quota error name too", () => { + const { storage: localStorage } = createStorage({ + writeFailure: "firefox-quota", + }); + const adapter = createBrowserStorageAdapter({ localStorage }); + + expect(adapter.write("COLOR_SCHEME", "dark")).toMatchObject({ + ok: false, + fallback: "memory", + error: { kind: "STORAGE_QUOTA_EXCEEDED" }, + }); + expect(adapter.read("COLOR_SCHEME")).toEqual({ ok: true, value: "dark" }); + }); + it("discards data from a previous schema version", () => { const { storage: localStorage, values, removeItem } = createStorage({ initial: { @@ -396,6 +416,41 @@ describe("storage registry", () => { expect(removeItem).toHaveBeenCalledWith(expiring.physicalKey); }); + // 2026-11-01 05-06. A record is expired at its expiry instant, not after it. + it.each([ + [100, undefined], + [101, "private-expiring"], + ])("reads a record expiring at %i at time 100 as %s", (expiresAt, value) => { + const expiring = defineStorageKey({ + logicalName: "EXPIRING_PREFERENCE", + scope: "preference", + name: "expiring", + backend: "localStorage", + classification: "public-preference", + schemaVersion: 1, + valueCodec: "opaque-string-v1", + ttl: 10, + migration: "discard", + quotaFallback: "memory", + }); + const { storage } = createStorage({ + initial: { + [expiring.physicalKey]: serializedEnvelope("private-expiring", { + expiresAt, + }), + }, + }); + const adapter = createBrowserStorageAdapter({ + localStorage: storage, + now: () => 100, + resolveDefinition: definitionResolver({ + EXPIRING_PREFERENCE: expiring, + }), + }); + + expect(adapter.read("EXPIRING_PREFERENCE")).toEqual({ ok: true, value }); + }); + it("prioritizes a failed-write memory envelope over stale persistent data and expires it", () => { let timestamp = 100; const expiring = defineStorageKey({