| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { browserChromeIdentity } from "./browserChromeIdentity.ts"; |
| 3 | |
| 4 | const host = { platform: "darwin", arch: "arm64" } as const; |
| 5 | |
| 6 | describe("browserChromeIdentity", () => { |
| 7 | it("keeps HTTP and navigator identity consistent with current Chrome client hints", () => { |
| 8 | const identity = browserChromeIdentity( |
| 9 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) T3Code(Preview)/0.0.45 Chrome/148.0.7734.19 Electron/42.0.0 Safari/537.36", |
| 10 | host, |
| 11 | ); |
| 12 | expect(identity?.userAgent).toBe( |
| 13 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36", |
| 14 | ); |
| 15 | expect(identity?.userAgentMetadata).toMatchObject({ |
| 16 | platform: "macOS", |
| 17 | architecture: "arm", |
| 18 | bitness: "64", |
| 19 | mobile: false, |
| 20 | brands: expect.arrayContaining([{ brand: "Google Chrome", version: "148" }]), |
| 21 | fullVersionList: expect.arrayContaining([ |
| 22 | { brand: "Google Chrome", version: "148.0.7734.19" }, |
| 23 | ]), |
| 24 | }); |
| 25 | }); |
| 26 | |
| 27 | it("uses the same identity for headless pages and popup control sessions", () => { |
| 28 | const identity = browserChromeIdentity( |
| 29 | "Mozilla/5.0 HeadlessChrome/151.0.8000.20 Safari/537.36", |
| 30 | host, |
| 31 | ); |
| 32 | expect(identity?.userAgent).toBe("Mozilla/5.0 Chrome/151.0.0.0 Safari/537.36"); |
| 33 | const popup = browserChromeIdentity(identity!.userAgent, { |
| 34 | ...host, |
| 35 | chromeVersion: "151.0.8000.20", |
| 36 | }); |
| 37 | expect(popup).toEqual(identity); |
| 38 | }); |
| 39 | |
| 40 | it("does not invent a Chrome version when Chromium reports none", () => { |
| 41 | expect(browserChromeIdentity("Electron", host)).toBeNull(); |
| 42 | }); |
| 43 | }); |