34 lines
2.2 KiB
JavaScript
34 lines
2.2 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { normalizeAppearance, parseAppearance, exportAppearanceTheme } from '../src/lib/theme/appearance.ts';
|
|
|
|
test('New tab backgrounds retain supported data while rejecting active and remote content', () => {
|
|
const value = { theme: 'claude', mode: 'light', newTabBackground: { image: 'data:image/png;base64,YQ==', overlay: 0 } };
|
|
assert.deepEqual(parseAppearance(JSON.stringify(value)), value);
|
|
for (const image of ['https://example.com/photo.png', 'javascript:alert(1)', 'data:image/svg+xml;base64,YQ==', 'data:image/png;base64,' + 'A'.repeat(3_000_000)]) {
|
|
assert.equal(normalizeAppearance({ ...value, newTabBackground: { color: '#224466', image } }).newTabBackground, undefined);
|
|
}
|
|
assert.equal(normalizeAppearance({ ...value, newTabBackground: { color: 'red' } }).newTabBackground, undefined);
|
|
assert.equal(normalizeAppearance({ ...value, newTabBackground: undefined }).newTabBackground, undefined);
|
|
});
|
|
test('Background storage references retain overlay limits and discard obsolete colors', () => {
|
|
const imageId = 'd10adda6-a2ec-4d73-a0a6-2cb1ed43bebc';
|
|
assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, color: '#224466', overlay: 3 } }).newTabBackground, { imageId, overlay: 1 });
|
|
assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, overlay: -3 } }).newTabBackground, { imageId, overlay: -1 });
|
|
assert.deepEqual(normalizeAppearance({ newTabBackground: { imageId, overlay: NaN } }).newTabBackground, { imageId, overlay: 0 });
|
|
assert.equal(normalizeAppearance({ newTabBackground: { imageId: 'invalid' } }).newTabBackground, undefined);
|
|
});
|
|
|
|
test('Export follows the selected built-in palette and can be imported as a custom theme', async () => {
|
|
const { parseCustomTheme } = await import('../src/lib/theme/customThemes.ts');
|
|
globalThis.localStorage = { getItem: () => null };
|
|
try {
|
|
const claude = exportAppearanceTheme('claude');
|
|
assert.equal(claude.light.bg, '#faf9f5');
|
|
assert.equal(claude.dark.accent, '#d97757');
|
|
assert.deepEqual(parseCustomTheme(claude), claude);
|
|
const sakura = exportAppearanceTheme('sakura');
|
|
assert.deepEqual(sakura.light, sakura.dark);
|
|
} finally { delete globalThis.localStorage; }
|
|
});
|