refactor(shared): test favicon selection through public API (#10005)
This commit is contained in:
1 parent
4e59b06b84
commit
3e544f8cda
2 files changed
+18
-13
No files matched your search
@@ -1,11 +1,6 @@
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
|
||||
import {
|
||||
explicitFaviconUrl,
|
||||
faviconUrlForOrigin,
|
||||
faviconUrlForPage,
|
||||
toolActivityFaviconUrl,
|
||||
} from "./favicon.ts";
|
||||
import { faviconUrlForOrigin, toolActivityFaviconUrl } from "./favicon.ts";
|
||||
|
||||
describe("faviconUrlForOrigin", () => {
|
||||
it.each([
|
||||
@@ -46,12 +41,12 @@ describe("faviconUrlForOrigin", () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe("faviconUrlForPage", () => {
|
||||
describe("toolActivityFaviconUrl", () => {
|
||||
it("uses the page origin instead of a third-party favicon service", () => {
|
||||
expect(faviconUrlForPage("https://example.com/docs/page?q=1")).toBe(
|
||||
expect(toolActivityFaviconUrl({ pageUrl: "https://example.com/docs/page?q=1" }, "light")).toBe(
|
||||
"https://example.com/favicon.ico",
|
||||
);
|
||||
expect(faviconUrlForPage("http://localhost:5173/app")).toBe(
|
||||
expect(toolActivityFaviconUrl({ pageUrl: "http://localhost:5173/app" }, "light")).toBe(
|
||||
"http://localhost:5173/favicon.ico",
|
||||
);
|
||||
});
|
||||
@@ -86,7 +81,17 @@ describe("faviconUrlForPage", () => {
|
||||
});
|
||||
|
||||
it("accepts provider-supplied image URLs but rejects extension URLs", () => {
|
||||
expect(explicitFaviconUrl("https://example.com/icon.png")).toBe("https://example.com/icon.png");
|
||||
expect(explicitFaviconUrl("chrome-extension://example/_favicon/")).toBeNull();
|
||||
expect(
|
||||
toolActivityFaviconUrl(
|
||||
{ pageUrl: "https://example.com/docs", faviconUrl: "https://example.com/icon.png" },
|
||||
"light",
|
||||
),
|
||||
).toBe("https://example.com/icon.png");
|
||||
expect(
|
||||
toolActivityFaviconUrl(
|
||||
{ pageUrl: "https://example.com/docs", faviconUrl: "chrome-extension://example/_favicon/" },
|
||||
"light",
|
||||
),
|
||||
).toBe("https://example.com/favicon.ico");
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,7 @@ import { isPublicFaviconHost } from "./hostClassification.ts";
|
||||
* conventional favicon and let the image element fall back to a browser glyph.
|
||||
* Chrome-backed tools can pass their tab's explicit favicon URL separately.
|
||||
*/
|
||||
export function faviconUrlForPage(rawUrl: string | null | undefined, _size = 32): string | null {
|
||||
function faviconUrlForPage(rawUrl: string | null | undefined, _size = 32): string | null {
|
||||
if (!rawUrl || rawUrl.length > 4096) return null;
|
||||
try {
|
||||
const pageUrl = new URL(rawUrl);
|
||||
@@ -40,7 +40,7 @@ function themedFaviconUrlForPage(
|
||||
}
|
||||
|
||||
/** Accepts image URLs supplied by a trusted provider event. */
|
||||
export function explicitFaviconUrl(rawUrl: string | null | undefined): string | null {
|
||||
function explicitFaviconUrl(rawUrl: string | null | undefined): string | null {
|
||||
if (!rawUrl || rawUrl.length > 4096) return null;
|
||||
try {
|
||||
const url = new URL(rawUrl);
|
||||
|
||||
Reference in new issue
Block a user