Inner Breeze's platform services now come from their shared homes: - Kryon: file_download (runtime assets and music), file_export (data and key file downloads and Android's share sheet), android_picker (document picker and QR scanner), page_socket (live sync events in the browser), browser_viewport (canvas sizing), and Android's device, insets and input method text editing. - Daochi client: crypto (SHA-256, HMAC, ChaCha20-Poly1305), account keys (now wiping secrets as Inbe's copy did), and signed package release parsing; Inbe keeps only its own package policy. About 5,000 lines of duplicated Zi, C and JavaScript are gone. The lock pins Kryon f2c230be and the Daochi client d453a26.
59 lines
2.6 KiB
JavaScript
59 lines
2.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import vm from 'node:vm';
|
|
|
|
const source = readFileSync(new URL('../src/web_host.js', import.meta.url), 'utf8');
|
|
function host(module = {}, extras = {}) {
|
|
let library;
|
|
const context = vm.createContext({
|
|
Module: module,
|
|
Asyncify: { handleAsync: start => start() },
|
|
addToLibrary: value => { library = value; },
|
|
setTimeout, clearTimeout, Date,
|
|
console: { error() {} },
|
|
...extras
|
|
});
|
|
vm.runInContext(source, context);
|
|
return library;
|
|
}
|
|
|
|
assert.equal(await host().browser_storage_wait(10, 0), 0);
|
|
assert.equal(await host({ __inbeFlushStorageSync() {} }).browser_storage_wait(10, 0), 1);
|
|
assert.equal(await host({ __inbeFlushStorageSync: () => Promise.resolve(true) })
|
|
.browser_storage_wait(10, 1), 1);
|
|
assert.equal(await host({ __inbeFlushStorageSync: () => Promise.resolve(false) })
|
|
.browser_storage_wait(10, 0), 0);
|
|
const rejected = { __inbeFlushStorageSync: () => Promise.reject(new Error('disk full')) };
|
|
assert.equal(await host(rejected).browser_storage_wait(10, 0), 0);
|
|
assert.equal(rejected.__inbeStorageSyncLastError, 'disk full');
|
|
const stalled = { __inbeFlushStorageSync: () => new Promise(() => {}) };
|
|
assert.equal(await host(stalled).browser_storage_wait(1, 0), 0);
|
|
assert.equal(stalled.__inbeStorageSyncLastError, 'timeout');
|
|
const scheduled = {
|
|
__inbeScheduleStorageSync(delay, log) {
|
|
assert.equal(delay, 0);
|
|
assert.equal(log, true);
|
|
scheduled.__inbeFlushStorageSync = () => Promise.resolve(true);
|
|
}
|
|
};
|
|
assert.equal(await host(scheduled).browser_storage_wait(10, 1), 1);
|
|
|
|
const clickState = { __kryonContextClick: { x: 20, y: 30, time: Date.now() } };
|
|
const clicks = host(clickState);
|
|
assert.equal(clicks.web_context_click_in_bounds(30, 30, 40, 40), 0);
|
|
assert.equal(clicks.web_context_click_in_bounds(10, 20, 30, 40), 1);
|
|
assert.equal(clicks.web_context_click_in_bounds(10, 20, 30, 40), 0);
|
|
clickState.__kryonContextClick = { x: 20, y: 30, time: Date.now() - 1000 };
|
|
assert.equal(clicks.web_context_click_in_bounds(10, 20, 30, 40), 0);
|
|
assert.equal(clickState.__kryonContextClick, null);
|
|
assert.equal(host().web_extension_host_js(), 0);
|
|
assert.equal(host({}, { window: { __inbeExtension: true } }).web_extension_host_js(), 1);
|
|
assert.equal(host({}, {
|
|
window: { location: { protocol: 'chrome-extension:' } },
|
|
chrome: { runtime: {} }
|
|
}).web_extension_host_js(), 1);
|
|
assert.equal(host({ __inbeStorageSyncing: true }).browser_storage_busy(), 1);
|
|
assert.equal(host({ __inbeStorageSyncPending: true }).browser_storage_busy(), 1);
|
|
assert.equal(host().browser_storage_busy(), 0);
|
|
console.log('web host effects passed');
|