diff --git a/README.md b/README.md index baada4f..cece269 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,78 @@ A small, local-first Chrome / Chromium extension for GitHub's published service health. Manifest V3, no account, no backend, no telemetry. -The first version includes the overall status, affected-first service list, active incidents and scheduled maintenance, a colored toolbar marker with textual badge, background polling, persistent cache, manual refresh, system/light/dark themes, and update interval settings. Only `storage`, `alarms`, and access to `https://www.githubstatus.com/*` are requested. +The first version includes the overall status, affected-first service list, active incidents and scheduled maintenance, a GitHub toolbar icon colored by status, background polling, persistent cache, manual refresh, system/light/dark themes, and update interval settings. Only `storage`, `alarms`, and access to `https://www.githubstatus.com/*` are requested. -## Build and install +## Install a release in Chrome + +Download a ready-to-use ZIP from [GitHub Releases](https://github.com/cpanato/github-status-extension/releases). You do not need Node.js, Go, npm, or a copy of the source repository to use a release. + +### Choose where to keep the extension + +Chrome loads an unpacked extension directly from the folder you select. **Keep that extracted folder in a permanent location while the extension is installed.** The ZIP can be deleted after extraction. + +Suggested locations for this project: + +| System | Suggested installation folder | +| ------- | ---------------------------------------- | +| macOS | `~/Applications/github-status-extension` | +| Linux | `~/.local/share/github-status-extension` | +| Windows | `%LOCALAPPDATA%\GitHubStatusExtension` | + +These are suggestions, not required Chrome locations. You can choose another permanent folder, including a directory on another drive. The destination is selected when you click **Load unpacked**; there is no installation-path setting inside the extension. Use the same folder for later updates. Chrome manages its own profile folders; you do not need to copy files into them. + +### Download, extract, and load + +1. Open the release you want to test. Under **Assets**, download `github-status-extension-.zip` and, optionally, its matching `.zip.sha256` checksum. The automatically generated **Source code** archives contain the development source, not the ready-to-use extension. +2. Create your permanent installation folder and extract the ZIP contents into it. +3. Check that `manifest.json` is directly inside that folder: + + ```text + github-status-extension/ + manifest.json + popup.html + options.html + background/ + icons/ + ui/ + ... + ``` + +4. Open `chrome://extensions` in Chrome and enable **Developer mode**. +5. Click **Load unpacked** and select the folder containing `manifest.json`. +6. Open Chrome's extensions menu (the puzzle icon), find **GitHub Status Indicator**, and pin it to the toolbar. Click the GitHub icon to view status; use the gear in the popup for preferences. + +On macOS, for example, after downloading the ZIP to Downloads: + +```bash +release_version=0.1.0-rc.3 # Replace with the version you downloaded. +extension_dir="$HOME/Applications/github-status-extension" # Change to your preferred folder. +mkdir -p "$extension_dir" +unzip "$HOME/Downloads/github-status-extension-$release_version.zip" -d "$extension_dir" +open "$extension_dir" +``` + +In Chrome, select that `github-status-extension` folder. In the folder picker, **Command–Shift–G** lets you paste its full path. For the suggested location, enter `~/Applications/github-status-extension`. + +For an optional checksum check on macOS, keep the ZIP and its checksum in the same directory and run: + +```bash +cd "$HOME/Downloads" +release_version=0.1.0-rc.3 # Replace with the version you downloaded. +shasum -a 256 -c "github-status-extension-$release_version.zip.sha256" +``` + +### Update an installed release + +1. Download the next release's ZIP and extract its contents into the **same installation folder**, replacing the existing extension files. Keep `manifest.json` at the same location; avoid adding a nested folder named after the new version. +2. Open `chrome://extensions`, find **GitHub Status Indicator**, and click its **Reload** button (the circular arrow). +3. Open **Details** to check the displayed version, then open the popup to confirm the update. Use **Reload** for updates rather than removing and re-adding the extension. + +Updates are manual while releases are installed this way. If you move or delete the extracted folder, Chrome can no longer load that installation. Choose the permanent location before the first install; keep Downloads and temporary build/worktree directories for downloads and development. + +This uses Chrome's documented [Load unpacked and Reload workflow](https://developer.chrome.com/docs/extensions/get-started/tutorial/hello-world#load-unpacked), also used for local builds of extensions such as [Bitwarden](https://contributing.bitwarden.com/getting-started/clients/browser/) and [Stylus](https://github.com/openstyles/stylus/wiki/Install-Stylus-from-GitHub). + +## Build from source (development) Requires Node.js 26 LTS or newer and npm. The `.nvmrc` file selects Node 26 for local development and CI; run `nvm install && nvm use` if you use nvm. Bash, jq, zip, and shasum are used for packaging. @@ -13,7 +82,7 @@ npm ci --ignore-scripts npm run build ``` -Open `chrome://extensions`, enable **Developer mode**, choose **Load unpacked**, and select this worktree's `dist` directory. Pin **GitHub Status Indicator** to the toolbar. No login or configuration is needed. Open settings using the gear in the popup. +For development, open `chrome://extensions`, enable **Developer mode**, click **Load unpacked**, and select the generated `dist` directory inside your checkout/worktree. This directory contains `manifest.json`. Rebuild and click **Reload** after code changes. For an installation independent of the checkout, copy the contents of `dist` into your chosen permanent folder and follow the release installation steps above. ```bash npm run package @@ -29,7 +98,7 @@ The dedicated Release workflow runs only when a version tag is pushed; it has no The repository enables release immutability. Publication creates a draft, uploads every asset, downloads and verifies the uploaded package, and only then publishes the draft. Published assets and tags are never replaced. If publication fails, the release stays unpublished; fix the issue and cut a new RC instead of overwriting assets. Future cosign signatures must be included before publication. -To test a published RC, download and extract its ZIP, open `chrome://extensions`, enable **Developer mode**, and choose **Load unpacked** with the extracted directory. To verify the download, put the ZIP and checksum in the same directory and run `shasum -a 256 -c github-status-extension-0.1.0-rc.1.zip.sha256`. +To test a published RC, follow [Install a release in Chrome](#install-a-release-in-chrome) above. RC and stable ZIPs use the same installation and update procedure. To prepare an RC locally without publishing: @@ -58,6 +127,7 @@ Playwright loads the built extension into a real Chromium profile. Tests replace - The default check interval is one minute; settings offer 1, 2, 5, or 10 minutes. Chrome can delay alarms during sleep. Freshness is checked whenever the worker or popup runs. - A failed check retains the last successful snapshot, marks it stale, and changes the toolbar to unknown. Expired data is never treated as fresh operational status. Cached service rows are labeled explicitly. +- The GitHub toolbar icon is green for operational status, yellow for degraded performance or maintenance, red for partial or major outages, and gray for unknown, stale, or failed checks. Attention/outage badges and tooltip text provide status information beyond color. The Chrome Extensions page uses a neutral GitHub icon. Icon sources and regeneration instructions are in [assets/README.md](assets/README.md). - Manual refresh respects the next permitted check time. Failed checks use exponential backoff with jitter and honor bounded `Retry-After` values. Requests time out after ten seconds, reject redirects, omit credentials, and cap response size at 1 MiB. - The summary API supplies unresolved incidents, not resolved incident history. This MVP does not request extra historical feeds or invent uptime metrics. - GitHub is the only configured source in this release. Multiple sources, GitLab, and runtime host permissions are deferred to later milestones. The normalized domain and provider interface are separate from the GitHub schema. diff --git a/assets/README.md b/assets/README.md new file mode 100644 index 0000000..7989877 --- /dev/null +++ b/assets/README.md @@ -0,0 +1,19 @@ +# GitHub icon source + +`mark-github.svg` is the official `mark-github-16` icon from [Primer Octicons](https://github.com/primer/octicons). The exact source revision is recorded in `octicons-commit.txt`. Its MIT license is bundled in `public/licenses/octicons-LICENSE.txt` and included in the extension package. + +`mark-github-mask.png` is a 512 × 512 black-on-white rasterization of that SVG. It is a build source, not a runtime asset. The Go generator converts coverage to transparency and produces neutral application icons plus green, yellow, red, and gray toolbar variants. PNGs are committed so building the extension does not require Go or browser-based asset generation. + +Regenerate the color variants from the mask with: + +```bash +go run scripts/icons.go +``` + +To regenerate the mask, use the installed Playwright Chromium (the same external tool used for browser tests): + +```bash +sed 's/width="16" height="16"/width="512" height="512"/' assets/mark-github.svg > /tmp/github-status-mark.svg +npm exec --no -- playwright screenshot --channel chromium --viewport-size '512,512' file:///tmp/github-status-mark.svg assets/mark-github-mask.png +go run scripts/icons.go +``` diff --git a/assets/mark-github-mask.png b/assets/mark-github-mask.png new file mode 100644 index 0000000..ae692b3 Binary files /dev/null and b/assets/mark-github-mask.png differ diff --git a/assets/mark-github.svg b/assets/mark-github.svg new file mode 100644 index 0000000..0e55a8e --- /dev/null +++ b/assets/mark-github.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/octicons-commit.txt b/assets/octicons-commit.txt new file mode 100644 index 0000000..70338d8 --- /dev/null +++ b/assets/octicons-commit.txt @@ -0,0 +1 @@ +b3e95564299217e1bcc6cd07d62e57d74fb9bc09 diff --git a/public/icons/128.png b/public/icons/128.png index 4b3f484..1260b1d 100644 Binary files a/public/icons/128.png and b/public/icons/128.png differ diff --git a/public/icons/16.png b/public/icons/16.png index 974ae10..d483d08 100644 Binary files a/public/icons/16.png and b/public/icons/16.png differ diff --git a/public/icons/32.png b/public/icons/32.png index 92ae6b3..7f59fc3 100644 Binary files a/public/icons/32.png and b/public/icons/32.png differ diff --git a/public/icons/48.png b/public/icons/48.png index 625deff..b6e30c0 100644 Binary files a/public/icons/48.png and b/public/icons/48.png differ diff --git a/public/icons/attention-16.png b/public/icons/attention-16.png new file mode 100644 index 0000000..a145632 Binary files /dev/null and b/public/icons/attention-16.png differ diff --git a/public/icons/attention-24.png b/public/icons/attention-24.png new file mode 100644 index 0000000..6a132e0 Binary files /dev/null and b/public/icons/attention-24.png differ diff --git a/public/icons/attention-32.png b/public/icons/attention-32.png new file mode 100644 index 0000000..dcc327c Binary files /dev/null and b/public/icons/attention-32.png differ diff --git a/public/icons/operational-16.png b/public/icons/operational-16.png new file mode 100644 index 0000000..f5763ca Binary files /dev/null and b/public/icons/operational-16.png differ diff --git a/public/icons/operational-24.png b/public/icons/operational-24.png new file mode 100644 index 0000000..fb3a952 Binary files /dev/null and b/public/icons/operational-24.png differ diff --git a/public/icons/operational-32.png b/public/icons/operational-32.png new file mode 100644 index 0000000..ec3ff31 Binary files /dev/null and b/public/icons/operational-32.png differ diff --git a/public/icons/outage-16.png b/public/icons/outage-16.png new file mode 100644 index 0000000..5531b9b Binary files /dev/null and b/public/icons/outage-16.png differ diff --git a/public/icons/outage-24.png b/public/icons/outage-24.png new file mode 100644 index 0000000..c59b531 Binary files /dev/null and b/public/icons/outage-24.png differ diff --git a/public/icons/outage-32.png b/public/icons/outage-32.png new file mode 100644 index 0000000..a10e03a Binary files /dev/null and b/public/icons/outage-32.png differ diff --git a/public/icons/unknown-16.png b/public/icons/unknown-16.png new file mode 100644 index 0000000..d483d08 Binary files /dev/null and b/public/icons/unknown-16.png differ diff --git a/public/icons/unknown-24.png b/public/icons/unknown-24.png new file mode 100644 index 0000000..58cc3c8 Binary files /dev/null and b/public/icons/unknown-24.png differ diff --git a/public/icons/unknown-32.png b/public/icons/unknown-32.png new file mode 100644 index 0000000..7f59fc3 Binary files /dev/null and b/public/icons/unknown-32.png differ diff --git a/public/licenses/octicons-LICENSE.txt b/public/licenses/octicons-LICENSE.txt new file mode 100644 index 0000000..aa1fa80 --- /dev/null +++ b/public/licenses/octicons-LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 GitHub Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/public/manifest.json b/public/manifest.json index bb69ba1..f838d05 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -9,7 +9,11 @@ "action": { "default_popup": "popup.html", "default_title": "GitHub: Status Unavailable", - "default_icon": { "16": "icons/16.png", "32": "icons/32.png" } + "default_icon": { + "16": "icons/unknown-16.png", + "24": "icons/unknown-24.png", + "32": "icons/unknown-32.png" + } }, "icons": { "16": "icons/16.png", diff --git a/scripts/icons.go b/scripts/icons.go index 0089297..dca62f6 100644 --- a/scripts/icons.go +++ b/scripts/icons.go @@ -1,25 +1,91 @@ //go:build ignore -// Generate the extension's local PNG assets with the Go standard library. +// Generate transparent GitHub status icons from the checked-in Octicons mask. package main import ( - "fmt" - "image" - "image/color" - "image/png" - "os" + "fmt" + "image" + "image/color" + "image/png" + "os" ) func main() { - for _, size := range []int{16, 32, 48, 128} { - img := image.NewNRGBA(image.Rect(0, 0, size, size)) - for y := 0; y < size; y++ { for x := 0; x < size; x++ { - dx, dy := float64(x)-float64(size-1)/2, float64(y)-float64(size-1)/2 - if dx*dx+dy*dy < float64(size*size)*.21 { img.Set(x,y,color.NRGBA{R:110,G:119,B:129,A:255}) } - if dx*dx+dy*dy < float64(size*size)*.025 { img.Set(x,y,color.NRGBA{R:255,G:255,B:255,A:255}) } - } } - f, err := os.Create(fmt.Sprintf("public/icons/%d.png",size)); if err != nil { panic(err) } - if err := png.Encode(f,img); err != nil { panic(err) }; if err := f.Close(); err != nil { panic(err) } - } + if err := generate(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +func generate() error { + f, err := os.Open("assets/mark-github-mask.png") + if err != nil { + return err + } + mask, err := png.Decode(f) + closeErr := f.Close() + if err != nil { + return err + } + if closeErr != nil { + return closeErr + } + palette := map[string]color.NRGBA{ + "operational": {R: 35, G: 134, B: 54, A: 255}, + "attention": {R: 191, G: 135, B: 0, A: 255}, + "outage": {R: 207, G: 34, B: 46, A: 255}, + "unknown": {R: 110, G: 119, B: 129, A: 255}, + } + for name, tint := range palette { + for _, size := range []int{16, 24, 32} { + if err := writeIcon(mask, tint, size, fmt.Sprintf("public/icons/%s-%d.png", name, size)); err != nil { + return err + } + } + } + for _, size := range []int{16, 32, 48, 128} { + if err := writeIcon(mask, palette["unknown"], size, fmt.Sprintf("public/icons/%d.png", size)); err != nil { + return err + } + } + return nil +} + +func writeIcon(mask image.Image, tint color.NRGBA, size int, path string) error { + out := image.NewNRGBA(image.Rect(0, 0, size, size)) + bounds := mask.Bounds() + // Area-average the high-resolution mask with transparent padding. This keeps + // the GitHub silhouette legible at 16px and avoids clipping its outer circle. + const samples = 32 + for y := 0; y < size; y++ { + for x := 0; x < size; x++ { + var coverage uint64 + for sy := 0; sy < samples; sy++ { + for sx := 0; sx < samples; sx++ { + u := (float64(x) + (float64(sx)+0.5)/samples) / float64(size) + v := (float64(y) + (float64(sy)+0.5)/samples) / float64(size) + u = (u-0.5)/0.9 + 0.5 + v = (v-0.5)/0.9 + 0.5 + if u < 0 || u >= 1 || v < 0 || v >= 1 { + continue + } + p := color.GrayModel.Convert(mask.At(bounds.Min.X+int(u*float64(bounds.Dx())), bounds.Min.Y+int(v*float64(bounds.Dy())))).(color.Gray) + coverage += uint64(255 - p.Y) + } + } + pixel := tint + pixel.A = uint8((coverage + samples*samples/2) / (samples * samples)) + out.SetNRGBA(x, y, pixel) + } + } + f, err := os.Create(path) + if err != nil { + return err + } + if err := png.Encode(f, out); err != nil { + _ = f.Close() + return err + } + return f.Close() } diff --git a/src/background/index.ts b/src/background/index.ts index 24574f1..959b75f 100644 --- a/src/background/index.ts +++ b/src/background/index.ts @@ -4,7 +4,7 @@ import { ProviderError, type StatusProvider, } from "../providers/github.js"; -import { readCache, readSettings } from "../storage.js"; +import { emptyCache, readCache, readSettings } from "../storage.js"; import { fetchCache } from "./polling.js"; const alarmName = "github-refresh"; let inFlight: Promise | undefined; @@ -20,19 +20,8 @@ const authorizedProvider: StatusProvider = { }; async function updateToolbar(cache: Cache) { const state = toolbar(cache); - const canvas = new OffscreenCanvas(32, 32); - const ctx = canvas.getContext("2d")!; - ctx.fillStyle = state.color; - ctx.beginPath(); - ctx.arc(16, 16, 13, 0, Math.PI * 2); - ctx.fill(); - ctx.fillStyle = "#ffffff"; - ctx.font = "bold 23px sans-serif"; - ctx.textAlign = "center"; - ctx.textBaseline = "middle"; - ctx.fillText(state.text, 16, 17); await Promise.all([ - chrome.action.setIcon({ imageData: ctx.getImageData(0, 0, 32, 32) }), + chrome.action.setIcon({ path: state.icon }), chrome.action.setTitle({ title: state.title }), chrome.action.setBadgeText({ text: state.state === "operational" ? "" : state.text, @@ -76,10 +65,7 @@ function refresh(): Promise { } function run() { void refresh().catch(() => { - /* Storage/API failures must not leave a green badge. */ void chrome.action.setBadgeText( - { text: "?" }, - ); - void chrome.action.setTitle({ title: "GitHub: Status Unavailable" }); + void updateToolbar(emptyCache()).catch(() => {}); }); } chrome.alarms.onAlarm.addListener((alarm) => { @@ -124,5 +110,5 @@ void (async () => { await chrome.alarms.create(alarmName, { periodInMinutes: 1 }); run(); })().catch(() => { - void chrome.action.setBadgeText({ text: "?" }); + void updateToolbar(emptyCache()).catch(() => {}); }); diff --git a/src/domain.ts b/src/domain.ts index 3bcd464..dccf973 100644 --- a/src/domain.ts +++ b/src/domain.ts @@ -80,9 +80,9 @@ export const rank: Record = { }; export const colors: Record = { operational: "#238636", - maintenance: "#8250df", - degraded: "#9a6700", - partial_outage: "#9a6700", + maintenance: "#bf8700", + degraded: "#bf8700", + partial_outage: "#cf222e", major_outage: "#cf222e", unknown: "#6e7781", }; @@ -97,10 +97,23 @@ export function stale(cache: Cache, now = Date.now()): boolean { } export function toolbar(cache: Cache, now = Date.now()) { const state = stale(cache, now) ? "unknown" : cache.snapshot!.overall; + const icon = + state === "operational" + ? "operational" + : state === "unknown" + ? "unknown" + : state === "major_outage" || state === "partial_outage" + ? "outage" + : "attention"; return { state, color: colors[state], - text: state === "operational" ? "✓" : state === "unknown" ? "?" : "!", + icon: { + 16: `/icons/${icon}-16.png`, + 24: `/icons/${icon}-24.png`, + 32: `/icons/${icon}-32.png`, + }, + text: state === "operational" ? "" : state === "unknown" ? "?" : "!", title: `GitHub: ${labels[state]}${cache.snapshot && stale(cache, now) ? " · last known: " + labels[cache.snapshot.overall] : ""}`, }; } diff --git a/tests/e2e/extension.spec.ts b/tests/e2e/extension.spec.ts index 80abd5e..214bb86 100644 --- a/tests/e2e/extension.spec.ts +++ b/tests/e2e/extension.spec.ts @@ -41,6 +41,16 @@ test.beforeAll(async () => { { timeout: 15_000 }, ) .toBeTruthy(); + await worker.evaluate(() => { + const nativeFetch = globalThis.fetch.bind(globalThis); + Object.assign(globalThis, { statusFetch: nativeFetch }); + globalThis.fetch = (input, init) => { + const url = input instanceof Request ? input.url : String(input); + return url.startsWith("https://www.githubstatus.com/") + ? Reflect.get(globalThis, "statusFetch")(input, init) + : nativeFetch(input, init); + }; + }); }); test.afterAll(async () => { await context?.close(); @@ -49,10 +59,12 @@ test.afterAll(async () => { async function seed(state = "operational", indicator = "none") { await worker.evaluate( async (payload) => { - globalThis.fetch = async () => - new Response(JSON.stringify(payload), { - headers: { "content-type": "application/json" }, - }); + Object.assign(globalThis, { + statusFetch: async () => + new Response(JSON.stringify(payload), { + headers: { "content-type": "application/json" }, + }), + }); await chrome.storage.local.set({ cache: { failures: 0, nextAttemptAt: 0 }, }); @@ -113,9 +125,11 @@ test("degraded and outage status update the popup and toolbar", async () => { test("failed request retains cached rows and marks toolbar unknown", async () => { await seed(); await worker.evaluate(async () => { - globalThis.fetch = async () => { - throw new TypeError("offline"); - }; + Object.assign(globalThis, { + statusFetch: async () => { + throw new TypeError("offline"); + }, + }); const { cache } = await chrome.storage.local.get("cache"); cache.nextAttemptAt = 0; await chrome.storage.local.set({ cache }); @@ -131,19 +145,21 @@ test("failed request retains cached rows and marks toolbar unknown", async () => }); test("remote incident text is inert and unsafe links are omitted", async () => { await worker.evaluate(async (payload) => { - globalThis.fetch = async () => - Response.json({ - ...payload, - incidents: [ - { - id: "x", - name: "", - status: "investigating", - impact: "major", - shortlink: "javascript:alert(1)", - }, - ], - }); + Object.assign(globalThis, { + statusFetch: async () => + Response.json({ + ...payload, + incidents: [ + { + id: "x", + name: "", + status: "investigating", + impact: "major", + shortlink: "javascript:alert(1)", + }, + ], + }), + }); await chrome.storage.local.set({ cache: { failures: 0, nextAttemptAt: 0 }, }); @@ -188,3 +204,71 @@ test("expired cache is marked unknown even during a deferred refresh", async () expect(await worker.evaluate(() => chrome.action.getBadgeText({}))).toBe("?"); await page.close(); }); + +test("Chrome Extensions displays the packaged GitHub icon", async () => { + const page = await context.newPage(); + await page.goto("chrome://extensions/"); + const icon = page + .locator(`extensions-item[id="${extensionId}"]`) + .locator("img#icon"); + await expect(icon).toBeVisible(); + await expect + .poll(() => + icon.evaluate( + (img: HTMLImageElement) => img.complete && img.naturalWidth > 0, + ), + ) + .toBe(true); + await page.screenshot({ path: "test-results/chrome-extensions-icon.png" }); + await page.close(); +}); + +test("toolbar installs the correct colored GitHub PNGs for every health category", async () => { + await worker.evaluate(() => { + const original = chrome.action.setIcon.bind(chrome.action); + chrome.action.setIcon = async (details) => { + Object.assign(chrome.action, { lastIcon: details.path }); + await original(details); + }; + }); + for (const [state, variant, rgb] of [ + ["operational", "operational", [35, 134, 54]], + ["degraded_performance", "attention", [191, 135, 0]], + ["under_maintenance", "attention", [191, 135, 0]], + ["partial_outage", "outage", [207, 34, 46]], + ["major_outage", "outage", [207, 34, 46]], + ["unrecognized", "unknown", [110, 119, 129]], + ] as const) { + await seed(state); + const icon = await worker.evaluate(() => + Reflect.get(chrome.action, "lastIcon"), + ); + expect(icon).toEqual({ + 16: `/icons/${variant}-16.png`, + 24: `/icons/${variant}-24.png`, + 32: `/icons/${variant}-32.png`, + }); + const page = await context.newPage(); + await page.goto(`chrome-extension://${extensionId}/options.html`); + const image = await page.evaluate(async (name) => { + const bitmap = await createImageBitmap( + await (await fetch(`icons/${name}-32.png`)).blob(), + ); + const canvas = document.createElement("canvas"); + canvas.width = 32; + canvas.height = 32; + const ctx = canvas.getContext("2d")!; + ctx.drawImage(bitmap, 0, 0); + bitmap.close(); + return { + edge: Array.from(ctx.getImageData(0, 0, 1, 1).data), + ring: Array.from(ctx.getImageData(16, 3, 1, 1).data), + center: Array.from(ctx.getImageData(16, 16, 1, 1).data), + }; + }, variant); + expect(image.edge[3]).toBe(0); + expect(image.center[3]).toBe(0); + expect(image.ring).toEqual([...rgb, 255]); + await page.close(); + } +});