26 lines
1.0 KiB
JavaScript
26 lines
1.0 KiB
JavaScript
const { test } = require('node:test');
|
|||
|
|
const assert = require('node:assert');
|
||
|
|
const zlib = require('node:zlib');
|
||
|
|
const { TRAY_ICON_BASE64 } = require('../tray-icon');
|
||
|
|
|
||
|
|
test('tray icon is a structurally valid PNG (every chunk CRC checks out)', () => {
|
||
|
|
const prefix = 'data:image/png;base64,';
|
||
|
|
assert.ok(TRAY_ICON_BASE64.startsWith(prefix));
|
||
|
|
const png = Buffer.from(TRAY_ICON_BASE64.slice(prefix.length), 'base64');
|
||
|
|
assert.strictEqual(png.subarray(0, 8).toString('hex'), '89504e470d0a1a0a');
|
||
|
|
|
||
|
|
const types = [];
|
||
|
|
let off = 8;
|
||
|
|
while (off < png.length) {
|
||
|
|
const len = png.readUInt32BE(off);
|
||
|
|
const type = png.subarray(off + 4, off + 8);
|
||
|
|
const body = png.subarray(off + 8, off + 8 + len);
|
||
|
|
const crc = png.readUInt32BE(off + 8 + len);
|
||
|
|
assert.strictEqual(zlib.crc32(Buffer.concat([type, body])), crc, `bad CRC in ${type}`);
|
||
|
|
types.push(type.toString());
|
||
|
|
off += 12 + len;
|
||
|
|
}
|
||
|
|
assert.strictEqual(off, png.length, 'trailing bytes after last chunk');
|
||
|
|
assert.deepStrictEqual([types[0], types.at(-1)], ['IHDR', 'IEND']);
|
||
|
|
});
|