加固宿主事件订阅门禁
新增原生壳检查脚本对 H5 HostBridge 事件订阅双能力门控的静态反查 补齐 HostBridge 事件订阅测试矩阵里的返回栈事件负向覆盖 更新宿主壳协议、壳方案和共享记忆中的事件门禁说明
This commit is contained in:
@@ -341,6 +341,7 @@ describe('hostBridge', () => {
|
||||
test('事件类能力缺少宿主事件通道时不订阅原生事件', () => {
|
||||
const lifecycleListener = vi.fn();
|
||||
const networkListener = vi.fn();
|
||||
const navigationListener = vi.fn();
|
||||
const imageDropListener = vi.fn();
|
||||
|
||||
window.history.replaceState(null, '', nativeAppPath(['app.lifecycle']));
|
||||
@@ -388,6 +389,29 @@ describe('hostBridge', () => {
|
||||
);
|
||||
unsubscribeNetwork();
|
||||
|
||||
window.history.replaceState(
|
||||
null,
|
||||
'',
|
||||
nativeAppPath(['navigation.canGoBack']),
|
||||
);
|
||||
const unsubscribeNavigation =
|
||||
subscribeHostNavigationCanGoBack(navigationListener);
|
||||
window.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
data: JSON.stringify({
|
||||
bridge: 'GenarrativeHostBridge',
|
||||
version: 1,
|
||||
event: 'navigation.canGoBack',
|
||||
payload: {
|
||||
canGoBack: true,
|
||||
},
|
||||
}),
|
||||
origin: window.location.origin,
|
||||
source: window,
|
||||
}),
|
||||
);
|
||||
unsubscribeNavigation();
|
||||
|
||||
window.history.replaceState(
|
||||
null,
|
||||
'',
|
||||
@@ -417,12 +441,14 @@ describe('hostBridge', () => {
|
||||
|
||||
expect(lifecycleListener).not.toHaveBeenCalled();
|
||||
expect(networkListener).not.toHaveBeenCalled();
|
||||
expect(navigationListener).not.toHaveBeenCalled();
|
||||
expect(imageDropListener).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('事件通道缺少具体事件能力时不订阅原生事件', () => {
|
||||
const lifecycleListener = vi.fn();
|
||||
const networkListener = vi.fn();
|
||||
const navigationListener = vi.fn();
|
||||
const imageDropListener = vi.fn();
|
||||
|
||||
window.history.replaceState(null, '', nativeAppPath(['host.events']));
|
||||
@@ -431,6 +457,8 @@ describe('hostBridge', () => {
|
||||
subscribeHostAppLifecycle(lifecycleListener);
|
||||
const unsubscribeNetwork =
|
||||
subscribeHostNetworkStatusChange(networkListener);
|
||||
const unsubscribeNavigation =
|
||||
subscribeHostNavigationCanGoBack(navigationListener);
|
||||
const unsubscribeImageDrop =
|
||||
subscribeHostImageDrop(imageDropListener);
|
||||
|
||||
@@ -450,6 +478,12 @@ describe('hostBridge', () => {
|
||||
connectionType: 'wifi',
|
||||
},
|
||||
},
|
||||
{
|
||||
event: 'navigation.canGoBack',
|
||||
payload: {
|
||||
canGoBack: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
event: 'file.imageDropped',
|
||||
payload: {
|
||||
@@ -477,10 +511,12 @@ describe('hostBridge', () => {
|
||||
|
||||
unsubscribeLifecycle();
|
||||
unsubscribeNetwork();
|
||||
unsubscribeNavigation();
|
||||
unsubscribeImageDrop();
|
||||
|
||||
expect(lifecycleListener).not.toHaveBeenCalled();
|
||||
expect(networkListener).not.toHaveBeenCalled();
|
||||
expect(navigationListener).not.toHaveBeenCalled();
|
||||
expect(imageDropListener).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user