2026-07-26 19:41:03 +08:00
|
|
|
import assert from 'node:assert/strict'
|
|
|
|
|
import test from 'node:test'
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
getXWebViewSnapshot,
|
|
|
|
|
mountXWebViewHost,
|
|
|
|
|
openWebView,
|
|
|
|
|
resetXWebViewRuntimeForTests,
|
|
|
|
|
updatePageNavigation,
|
|
|
|
|
} from '../src/runtime'
|
|
|
|
|
|
|
|
|
|
test('openWebView owns an independent page stack and restores the lower page', async () => {
|
|
|
|
|
resetXWebViewRuntimeForTests()
|
|
|
|
|
const unmount = mountXWebViewHost()
|
|
|
|
|
const first = openWebView({
|
|
|
|
|
source: { uri: 'https://first.test' },
|
|
|
|
|
})
|
|
|
|
|
const second = openWebView({
|
|
|
|
|
source: { uri: 'https://second.test' },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
|
getXWebViewSnapshot().pages.map(page => page.id),
|
|
|
|
|
[first.id, second.id],
|
|
|
|
|
)
|
|
|
|
|
second.close()
|
|
|
|
|
assert.deepEqual(
|
|
|
|
|
getXWebViewSnapshot().pages.map(page => page.id),
|
|
|
|
|
[first.id],
|
|
|
|
|
)
|
|
|
|
|
assert.equal((await second.closed).reason, 'api')
|
|
|
|
|
unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('dynamic navigation state belongs only to its page', () => {
|
|
|
|
|
resetXWebViewRuntimeForTests()
|
|
|
|
|
const unmount = mountXWebViewHost()
|
|
|
|
|
const first = openWebView({
|
|
|
|
|
navigationBar: { title: { text: 'first' } },
|
|
|
|
|
source: { uri: 'https://first.test' },
|
|
|
|
|
})
|
|
|
|
|
const second = openWebView({
|
|
|
|
|
navigationBar: { title: { text: 'second' } },
|
|
|
|
|
source: { uri: 'https://second.test' },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
updatePageNavigation(second.id, {
|
|
|
|
|
title: { color: '#ffffff', text: 'changed' },
|
|
|
|
|
})
|
|
|
|
|
const pages = getXWebViewSnapshot().pages
|
|
|
|
|
assert.equal(pages[0].presentation.titleText, 'first')
|
|
|
|
|
assert.equal(pages[1].presentation.titleText, 'changed')
|
|
|
|
|
first.close()
|
|
|
|
|
second.close()
|
|
|
|
|
unmount()
|
|
|
|
|
})
|
2026-07-27 15:11:08 +08:00
|
|
|
|
|
|
|
|
test('suspend and resume preserve the same page and handle', () => {
|
|
|
|
|
resetXWebViewRuntimeForTests()
|
|
|
|
|
const unmount = mountXWebViewHost()
|
|
|
|
|
const page = openWebView({
|
|
|
|
|
source: { uri: 'https://suspend.test' },
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
page.suspend()
|
|
|
|
|
assert.equal(getXWebViewSnapshot().pages[0].suspended, true)
|
|
|
|
|
assert.equal(getXWebViewSnapshot().pages[0].handle, page)
|
|
|
|
|
|
|
|
|
|
page.resume()
|
|
|
|
|
assert.equal(getXWebViewSnapshot().pages[0].suspended, false)
|
|
|
|
|
assert.equal(getXWebViewSnapshot().pages[0].handle, page)
|
|
|
|
|
|
|
|
|
|
page.close()
|
|
|
|
|
unmount()
|
|
|
|
|
})
|