hermes-agent/apps/desktop/electron/link-title-window.test.cjs
xxxigm 7eb9678c54 test(desktop): cover link-title window audio muting
Verify createLinkTitleWindow mutes audio (regression guard for #49505) and
keeps the hardened offscreen defaults, and register the new test file in the
desktop platforms test script.
2026-06-20 14:53:05 +05:30

56 lines
1.8 KiB
JavaScript

const assert = require('node:assert/strict')
const test = require('node:test')
const { createLinkTitleWindow, linkTitleWindowOptions } = require('./link-title-window.cjs')
function makeFakeBrowserWindow() {
const calls = { audioMuted: [] }
const FakeBrowserWindow = function (options) {
this.options = options
this.webContents = {
setAudioMuted(value) {
calls.audioMuted.push(value)
}
}
}
return { FakeBrowserWindow, calls }
}
test('linkTitleWindowOptions keeps the offscreen, hardened defaults', () => {
const session = { id: 'link-titles' }
const options = linkTitleWindowOptions(session)
assert.equal(options.show, false)
assert.equal(options.webPreferences.session, session)
assert.equal(options.webPreferences.contextIsolation, true)
assert.equal(options.webPreferences.sandbox, true)
assert.equal(options.webPreferences.nodeIntegration, false)
})
test('createLinkTitleWindow mutes audio so historical links never autoplay sound', () => {
// Regression for #49505: the hidden title-fetch window loaded YouTube/watch
// URLs (to read their <title>) without muting, leaking ~2s of audio on every
// history re-render.
const { FakeBrowserWindow, calls } = makeFakeBrowserWindow()
const window = createLinkTitleWindow(FakeBrowserWindow, { id: 'link-titles' })
assert.ok(window instanceof FakeBrowserWindow)
assert.deepEqual(calls.audioMuted, [true])
})
test('createLinkTitleWindow still returns the window if muting throws', () => {
const ThrowingBrowserWindow = function (options) {
this.options = options
this.webContents = {
setAudioMuted() {
throw new Error('webContents unavailable')
}
}
}
const window = createLinkTitleWindow(ThrowingBrowserWindow, { id: 'link-titles' })
assert.ok(window instanceof ThrowingBrowserWindow)
})