This commit is contained in:
2026-10-17 18:54:57 +07:00
parent d3683ac6cf
commit 8b29b4f24e
5 changed files with 74 additions and 10 deletions
+50 -8
View File
@@ -9,18 +9,39 @@ app.setPath(
),
)
const delay = (ms) => new Promise((r) => setTimeout(r, ms))
let targetDisplay
let isSyntheticDisplay = false
const boundsBeforeFullscreen = new Map()
const fullscreenEntered = new Set()
app.on('browser-window-created', (_event, window) => {
window.on('enter-full-screen', () => fullscreenEntered.add(window.id))
let requestedBounds
const setBounds = window.setBounds.bind(window)
window.setBounds = (bounds, ...args) => {
requestedBounds = { ...bounds }
return setBounds(bounds, ...args)
}
const setFullScreen = window.setFullScreen.bind(window)
window.setFullScreen = (flag) => {
if (flag) boundsBeforeFullscreen.set(window.id, requestedBounds)
return setFullScreen(flag)
}
})
app.whenReady().then(() => {
const original = screen.getAllDisplays.bind(screen)
screen.getAllDisplays = () => [
...original(),
{
...original()[0],
const displays = original()
targetDisplay = displays.find((display) => display.id !== screen.getPrimaryDisplay().id)
if (!targetDisplay) {
isSyntheticDisplay = true
targetDisplay = {
...displays[0],
id: 424242,
label: 'Synthetic test display',
bounds: { x: 1280, y: 0, width: 1280, height: 720 },
size: { width: 1280, height: 720 },
},
]
}
screen.getAllDisplays = () => [...original(), targetDisplay]
}
})
require(root + '/dist-electron/electron/main.js')
async function poll(check, label) {
@@ -47,7 +68,7 @@ app.whenReady().then(async () => {
)
const evaluate = (s) => control.webContents.executeJavaScript(s)
assert.equal(await evaluate('typeof window.require'), 'undefined')
await evaluate('window.screenBridge.show(424242)')
await evaluate(`window.screenBridge.show(${targetDisplay.id})`)
const output = await poll(
() => BrowserWindow.getAllWindows().find((w) => w !== control),
'output',
@@ -63,6 +84,15 @@ app.whenReady().then(async () => {
)),
'metadata',
)
if (process.platform === 'linux')
assert.equal(app.commandLine.getSwitchValue('ozone-platform'), 'x11')
await poll(() => boundsBeforeFullscreen.has(output.id), 'output fullscreen requested')
assert.deepEqual(boundsBeforeFullscreen.get(output.id), targetDisplay.bounds)
if (!isSyntheticDisplay) {
await poll(() => fullscreenEntered.has(output.id), 'output entered fullscreen')
assert.ok(output.isFullScreen())
assert.equal(screen.getDisplayMatching(output.getBounds()).id, targetDisplay.id)
}
const range = await output.webContents.executeJavaScript(
`fetch('screen-app://app/media/video', {headers: {Range: 'bytes=100-199'}}).then(async r => ({status:r.status, size:(await r.arrayBuffer()).byteLength, range:r.headers.get('content-range')}))`,
)
@@ -117,7 +147,7 @@ app.whenReady().then(async () => {
assert.equal(await evaluate('typeof window.screenBridge.lan'), 'undefined')
assert.equal(await evaluate('typeof window.screenBridge.approve'), 'undefined')
output.close()
await evaluate('window.screenBridge.show(424242)')
await evaluate(`window.screenBridge.show(${targetDisplay.id})`)
const reopened = await poll(
() => BrowserWindow.getAllWindows().find((w) => w !== control),
'reopened output',
@@ -128,6 +158,13 @@ app.whenReady().then(async () => {
(await reopened.webContents.executeJavaScript('!!document.querySelector("video")')),
'reopened ready',
)
await poll(() => boundsBeforeFullscreen.has(reopened.id), 'reopened fullscreen requested')
assert.deepEqual(boundsBeforeFullscreen.get(reopened.id), targetDisplay.bounds)
if (!isSyntheticDisplay) {
await poll(() => fullscreenEntered.has(reopened.id), 'reopened entered fullscreen')
assert.ok(reopened.isFullScreen())
assert.equal(screen.getDisplayMatching(reopened.getBounds()).id, targetDisplay.id)
}
assert.equal(
await reopened.webContents.executeJavaScript('document.querySelector("video").paused'),
true,
@@ -136,6 +173,11 @@ app.whenReady().then(async () => {
'SCREEN_SMOKE_PASS',
JSON.stringify({
range,
display: {
id: targetDisplay.id,
bounds: targetDisplay.bounds,
synthetic: isSyntheticDisplay,
},
seek: position,
samples: (await evaluate('window.screenBridge.state()')).samples,
electron: process.versions.electron,