Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions frame/src/app/browser/tests/NewTabCustomization.component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ afterEach(() => {
preferences.dispose();
retryImage();
delete document.documentElement.dataset.theme;
delete document.documentElement.dataset.material;
});
async function tab() {
const { default: NewTab } = await loadNewTab();
Expand Down Expand Up @@ -186,6 +187,116 @@ test("a custom background uses one sized local image, no sky decode or frost, an
expect(preferences.value("ui.newtab-dim")).toBe("false");
});

test.each(["light", "dark"])(
"custom-image figures follow the native material in %s",
async (theme) => {
native.settings = { "ui.newtab-background": "image", "ui.newtab-image": digest };
document.documentElement.dataset.theme = theme;
await preferences.init();
const ntp = await tab();
await expect
.poll(() => ntp.container.querySelector("img")?.naturalWidth ?? 0)
.toBeGreaterThan(0);
const figures = [...ntp.container.querySelectorAll<HTMLElement>(".figure")];
expect(figures).toHaveLength(3);
const paint = document.createElement("canvas").getContext("2d")!;
for (const material of [
null,
"none",
"vibrancy",
"liquid_glass",
"acrylic",
"mica",
"mica_alt",
]) {
if (material === null) delete document.documentElement.dataset.material;
else document.documentElement.dataset.material = material;
const translucent = material !== null && material !== "none";
for (const figure of figures) {
const style = getComputedStyle(figure);
expect(style.backdropFilter, material ?? "bootstrap").toBe("none");
const alpha = () => {
paint.clearRect(0, 0, 1, 1);
paint.fillStyle = getComputedStyle(figure).backgroundColor;
paint.fillRect(0, 0, 1, 1);
return paint.getImageData(0, 0, 1, 1).data[3]!;
};
if (translucent) {
await expect.poll(alpha).toBeLessThan(255);
expect(alpha()).toBeGreaterThan(0);
} else await expect.poll(alpha).toBe(255);
expect(style.transitionProperty).not.toContain("backdrop-filter");
}
}
document.documentElement.dataset.material = "liquid_glass";
const button = ntp.container.querySelector<HTMLButtonElement>("button.figure")!;
// WebKit's Tab skips buttons by default, so focus it as the keyboard would.
button.focus({ focusVisible: true } as FocusOptions);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
expect(document.activeElement).toBe(button);
expect(button.matches(":focus-visible")).toBe(true);
expect(getComputedStyle(button).outlineStyle).toBe("solid");
await page.elementLocator(ntp.container).screenshot({
path: `../../../../../target/newtab/custom-figures-${theme}.png`,
});
await preferences.set("ui.newtab-background", "sky");
await expect.poll(() => ntp.container.querySelector(".sky")).not.toBeNull();
for (const figure of figures) expect(getComputedStyle(figure).backdropFilter).toBe("none");
},
);

test.each(["light", "dark"])(
"custom-image figures stay readable on extreme wallpaper in %s",
async (theme) => {
native.settings = { "ui.newtab-background": "image", "ui.newtab-image": digest };
const wallpaper = theme === "dark" ? [255, 255, 255] : [0, 0, 0];
native.media.mockReturnValue(
`data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="900"><rect width="1600" height="900" fill="${theme === "dark" ? "white" : "black"}"/></svg>`)}`,
);
document.documentElement.dataset.theme = theme;
document.documentElement.dataset.material = "liquid_glass";
await preferences.init();
const ntp = await tab();
await expect
.poll(() => ntp.container.querySelector("img")?.naturalWidth ?? 0)
.toBeGreaterThan(0);
const paint = document.createElement("canvas").getContext("2d")!;
const rgba = (color: string) => {
paint.clearRect(0, 0, 1, 1);
paint.fillStyle = color;
paint.fillRect(0, 0, 1, 1);
return [...paint.getImageData(0, 0, 1, 1).data];
};
const over = (front: number[], back: number[]) => {
const alpha = front[3]! / 255;
return front
.slice(0, 3)
.map((channel, index) => channel * alpha + back[index]! * (1 - alpha));
};
const luminance = (rgb: number[]) => {
const linear = rgb.map((channel) => {
const value = channel / 255;
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
});
return linear[0]! * 0.2126 + linear[1]! * 0.7152 + linear[2]! * 0.0722;
};
const figures = [...ntp.container.querySelectorAll<HTMLElement>(".figure")];
expect(figures).toHaveLength(3);
for (const figure of figures) {
for (const text of figure.querySelectorAll<HTMLElement>(".name, .value, .foot")) {
await expect
.poll(() => {
const background = over(rgba(getComputedStyle(figure).backgroundColor), wallpaper);
const foreground = over(rgba(getComputedStyle(text).color), background);
const first = luminance(background);
const second = luminance(foreground);
return (Math.max(first, second) + 0.05) / (Math.min(first, second) + 0.05);
})
.toBeGreaterThanOrEqual(4.5);
}
}
},
);

test("native image import commits only the admitted digest, and cancellation keeps the sky", async () => {
await preferences.init();
const settings = await settingsScreen();
Expand Down
26 changes: 25 additions & 1 deletion frame/src/features/newtab/components/NewTab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,25 @@
}

.custom .figure {
background: var(--color-surface);
background: var(--figure-surface, var(--color-surface));
color: var(--color-label-secondary);
}

.custom .figure .foot:not(.late) {
color: var(--color-label-secondary);
}

/* A wash, not a live blur: it keeps arbitrary wallpaper legible at no GPU cost. */
:global(:root:not([data-material="none"])[data-material]) .newtab.custom {
--figure-surface: color-mix(in srgb, var(--color-surface) 92%, transparent);
}

.custom button.figure:hover {
background: color-mix(
in srgb,
var(--color-text) 9%,
var(--figure-surface, var(--color-surface))
);
}

/* A narrow pane keeps each figure to its icon and value on one row; the
Expand Down Expand Up @@ -970,6 +988,12 @@
display: none;
}

.custom .figure,
.custom button.figure:hover {
background: Canvas;
color: CanvasText;
}

.name {
fill: CanvasText;
}
Expand Down
Loading