|
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | +import { resolve } from "node:path"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | + |
| 5 | +// The two manifests are maintained by hand; these assertions keep the parts |
| 6 | +// that must not drift (version, entry points, content scripts, resources) in |
| 7 | +// lockstep and pin the deliberate per-browser differences. |
| 8 | + |
| 9 | +type Manifest = { |
| 10 | + manifest_version: number; |
| 11 | + name: string; |
| 12 | + short_name: string; |
| 13 | + version: string; |
| 14 | + homepage_url: string; |
| 15 | + icons: Record<string, string>; |
| 16 | + action: unknown; |
| 17 | + background: { |
| 18 | + service_worker?: string; |
| 19 | + scripts?: string[]; |
| 20 | + type?: string; |
| 21 | + }; |
| 22 | + permissions: string[]; |
| 23 | + host_permissions: string[]; |
| 24 | + content_scripts: unknown[]; |
| 25 | + web_accessible_resources: Array<{ |
| 26 | + resources: string[]; |
| 27 | + matches: string[]; |
| 28 | + use_dynamic_url?: boolean; |
| 29 | + }>; |
| 30 | + options_page?: string; |
| 31 | + options_ui?: { page: string }; |
| 32 | + browser_specific_settings?: { |
| 33 | + gecko?: { |
| 34 | + id?: string; |
| 35 | + strict_min_version?: string; |
| 36 | + }; |
| 37 | + }; |
| 38 | +}; |
| 39 | + |
| 40 | +const loadManifest = (target: "chrome" | "firefox"): Manifest => |
| 41 | + JSON.parse( |
| 42 | + readFileSync( |
| 43 | + resolve(__dirname, `../../manifests/manifest.${target}.json`), |
| 44 | + "utf8", |
| 45 | + ), |
| 46 | + ); |
| 47 | + |
| 48 | +const chrome = loadManifest("chrome"); |
| 49 | +const firefox = loadManifest("firefox"); |
| 50 | + |
| 51 | +describe("manifest parity", () => { |
| 52 | + it("keeps shared identity fields in sync", () => { |
| 53 | + expect(firefox.manifest_version).toBe(chrome.manifest_version); |
| 54 | + expect(firefox.name).toBe(chrome.name); |
| 55 | + expect(firefox.short_name).toBe(chrome.short_name); |
| 56 | + expect(firefox.version).toBe(chrome.version); |
| 57 | + expect(firefox.homepage_url).toBe(chrome.homepage_url); |
| 58 | + expect(firefox.icons).toEqual(chrome.icons); |
| 59 | + expect(firefox.action).toEqual(chrome.action); |
| 60 | + }); |
| 61 | + |
| 62 | + it("keeps content scripts and host permissions in sync", () => { |
| 63 | + expect(firefox.content_scripts).toEqual(chrome.content_scripts); |
| 64 | + expect(firefox.host_permissions).toEqual(chrome.host_permissions); |
| 65 | + }); |
| 66 | + |
| 67 | + it("exposes the same web accessible resources (modulo use_dynamic_url)", () => { |
| 68 | + const strip = (entries: Manifest["web_accessible_resources"]) => |
| 69 | + entries.map(({ resources, matches }) => ({ resources, matches })); |
| 70 | + expect(strip(firefox.web_accessible_resources)).toEqual( |
| 71 | + strip(chrome.web_accessible_resources), |
| 72 | + ); |
| 73 | + // use_dynamic_url is Chromium-only. |
| 74 | + expect( |
| 75 | + firefox.web_accessible_resources.every( |
| 76 | + (entry) => entry.use_dynamic_url === undefined, |
| 77 | + ), |
| 78 | + ).toBe(true); |
| 79 | + }); |
| 80 | + |
| 81 | + it("points both backgrounds at the same script", () => { |
| 82 | + expect(chrome.background.service_worker).toBe("assets/service-worker.js"); |
| 83 | + expect(firefox.background.scripts).toEqual(["assets/service-worker.js"]); |
| 84 | + expect(firefox.background.service_worker).toBeUndefined(); |
| 85 | + }); |
| 86 | + |
| 87 | + it("only differs in the Chrome-only permissions", () => { |
| 88 | + expect(chrome.permissions).toEqual( |
| 89 | + expect.arrayContaining(["offscreen", "tabCapture"]), |
| 90 | + ); |
| 91 | + const chromeOnly = ["offscreen", "tabCapture"]; |
| 92 | + expect(firefox.permissions.filter((p) => chromeOnly.includes(p))).toEqual( |
| 93 | + [], |
| 94 | + ); |
| 95 | + expect([...firefox.permissions].sort()).toEqual( |
| 96 | + chrome.permissions.filter((p) => !chromeOnly.includes(p)).sort(), |
| 97 | + ); |
| 98 | + }); |
| 99 | + |
| 100 | + it("declares Firefox-specific settings and options_ui", () => { |
| 101 | + expect(firefox.browser_specific_settings?.gecko?.id).toBeTruthy(); |
| 102 | + expect( |
| 103 | + firefox.browser_specific_settings?.gecko?.strict_min_version, |
| 104 | + ).toBeTruthy(); |
| 105 | + expect(firefox.options_ui?.page).toBe(chrome.options_page); |
| 106 | + expect(firefox.options_page).toBeUndefined(); |
| 107 | + expect(chrome.browser_specific_settings).toBeUndefined(); |
| 108 | + }); |
| 109 | +}); |
0 commit comments