| 1 | import { test } from 'node:test'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import { readFile } from 'node:fs/promises'; |
| 4 | import vm from 'node:vm'; |
| 5 | |
| 6 | test('empty cursor uses opt-in fallback and real cursor shapes still win', async () => { |
| 7 | const source = (await readFile(new URL('../vendor/novnc/core/util/cursor.js', import.meta.url), 'utf8')) |
| 8 | .replace(/^import .*;$/m, 'const supportsCursorURIs = true, isTouchDevice = false;') |
| 9 | .replace('export default class Cursor', 'globalThis.Cursor = class Cursor'); |
| 10 | const context = vm.createContext({ |
| 11 | document: { createElement: () => ({ style: {}, width: 0, height: 0, |
| 12 | getContext: () => ({ clearRect() {}, putImageData() {} }), |
| 13 | toDataURL: () => 'data:image/png;base64,test' }) }, |
| 14 | ImageData: class {}, Uint8ClampedArray, |
| 15 | }); |
| 16 | vm.runInContext(source, context); |
| 17 | for (const fallback of ['default', 'none']) { |
| 18 | const target = { style: {} }; |
| 19 | const cursor = new context.Cursor(fallback); |
| 20 | cursor.attach(target); |
| 21 | assert.equal(target.style.cursor, fallback); |
| 22 | cursor.change(new Uint8Array([0, 0, 0, 255]), 0, 0, 1, 1); |
| 23 | assert.match(target.style.cursor, /^url\(/); |
| 24 | cursor.change(new Uint8Array(), 0, 0, 0, 0); |
| 25 | assert.equal(target.style.cursor, fallback); |
| 26 | } |
| 27 | }); |