Files
image-workbench-desktop/tests/native-overlay-park-test.js
qiqi 4b70e4029f
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 31s
docs+test: 原生浮层生命周期规范 + 守门测试(防面板切换残留)
2026-11-22 09:16:52 +08:00

49 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 原生浮层生命周期守门(v3.26.33 事故规范):
// 1) detach() 必须在「延迟 close」之前同步 park;
// 2) setSuspended(true) 必须 parkAll;
// 3) 离开画布视图时必须 parkAll。
// 任何一条退化,都会重新出现“切换面板后旧网页滞留”的问题。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const src = fs.readFileSync(path.join(__dirname, '..', 'src', 'canvas-webview.js'), 'utf8')
function fnBody (name) {
const i = src.indexOf('function ' + name)
assert.ok(i >= 0, name + '() 不存在')
const open = src.indexOf('{', i)
let depth = 0
for (let k = open; k < src.length; k++) {
if (src[k] === '{') depth++
else if (src[k] === '}') { depth--; if (depth === 0) return src.slice(open, k + 1) }
}
return ''
}
// 1) detach:park 必须在 setTimeout(close) 之前
{
const body = fnBody('detach')
const parkAt = body.indexOf('shown !== false')
const timerAt = body.indexOf('setTimeout')
assert.ok(parkAt >= 0, 'detach() 缺少「锚点消失立即 park」分支')
assert.ok(timerAt > parkAt, 'detach() 的 park 必须写在 setTimeout(close) 之前')
assert.ok(/push\(\s*st[\s\S]{0,200}?false\s*,\s*null\s*\)/.test(body.slice(parkAt)), 'detach() 的 park 必须以 visible=false 调 push')
}
// 2) setSuspended:暂停时 parkAll
{
const body = fnBody('setSuspended')
assert.ok(/if \(suspended\) parkAll\(\)/.test(body), 'setSuspended(true) 必须调用 parkAll()')
}
// 3) 视图切换:离开 canvas 时 parkAll
{
assert.ok(/iwb-view-canvas[\s\S]{0,200}?parkAll\(\)/.test(src), '离开画布视图时必须 parkAll()')
}
// 4) 宽限期常量仍在(用于“先隐藏后销毁”,不能被改成 0/删除)
assert.ok(/CLOSE_GRACE_MS\s*=\s*\d+/.test(src), 'CLOSE_GRACE_MS 应保留(用于避免重建时重载网页)')
console.log('native overlay park checks passed(detach 先 park 再 close / suspend parkAll / 离开视图 parkAll / 宽限期保留)')