Workplace Widget 5.10.23
This commit is contained in:
50
hmi-frontend/tests/cheerpj-window-runtime.mjs
Normal file
50
hmi-frontend/tests/cheerpj-window-runtime.mjs
Normal file
@@ -0,0 +1,50 @@
|
||||
/** Standalone Workplace launch and CheerpJ runtime allowlist regression checks. */
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const read = rel => fs.readFileSync(new URL(rel, import.meta.url), 'utf8');
|
||||
const html = read('../public/cheerpj-runner.html');
|
||||
const js = read('../public/cheerpj-runner.js').replace(/^import jaasNativeHandlers from '\.\/cheerpj\/natives\/jaas\.js';\n/, 'const jaasNativeHandlers=mockJaasNativeHandlers;\n');
|
||||
const widget = read('../src/widgets/CheerpJWidget.vue');
|
||||
const css = read('../src/style.css');
|
||||
assert.match(html, /requested === '4\.3' \? '4\.3' : '5\.0'/,
|
||||
'Only the fixed 4.3/5.0 versions may be selected');
|
||||
assert.match(html, /cjrtnc\.leaningtech\.com/);
|
||||
assert.match(html, /body\.cheerpj-standalone #state/);
|
||||
assert.match(widget, /standalone=workplace&runtime=/);
|
||||
assert.match(widget, /Fensterdiagnose/);
|
||||
assert.match(widget, /windowMode:windowMode\.value/);
|
||||
assert.match(html, /id="window-diagnostics"/);
|
||||
assert.match(widget, /rel="noopener noreferrer"/);
|
||||
assert.match(widget, /CheerpJ Laufzeitversion/);
|
||||
assert.match(widget, /workplace\.value \? '5\.0' : '4\.3'/, 'Do not change the runtime of ordinary widgets');
|
||||
assert.match(widget, /:src="frameSrc"/);
|
||||
assert.match(css, /cheerpj-open-window/);
|
||||
|
||||
async function runStandalone(query) {
|
||||
const local = 'https://mes.internal:8181';
|
||||
const classNames = [];
|
||||
const fetched = [];
|
||||
const status = {textContent:'',className:''};
|
||||
const context = {
|
||||
URL, Error, Promise, setInterval, clearInterval, mockJaasNativeHandlers:{},
|
||||
location:{href:local+'/backend/hmi/cheerpj-runner.html'+query,origin:local},
|
||||
document:{getElementById:id=>status,body:{classList:{add:n=>classNames.push(n)}}},
|
||||
fetch:async url=>{fetched.push(url);return {ok:false,status:503,url}},
|
||||
window:{addEventListener:()=>{}}
|
||||
};
|
||||
context.window.parent = context.window;
|
||||
vm.runInNewContext(js,context);
|
||||
await new Promise(resolve=>setTimeout(resolve,5));
|
||||
return {fetched,classNames,status};
|
||||
}
|
||||
const launched = await runStandalone('?standalone=workplace&runtime=5.0&jnlpUrl=https://evil.example/payload.jnlp');
|
||||
assert.deepEqual(launched.fetched, [
|
||||
'https://mes.internal:8181/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp'
|
||||
]);
|
||||
assert.ok(launched.classNames.includes('cheerpj-standalone'));
|
||||
assert.match(launched.status.textContent,/HTTP 503/);
|
||||
const idle=await runStandalone('?standalone=unknown');
|
||||
assert.deepEqual(idle.fetched,[]);
|
||||
console.log('CheerpJ standalone window, fixed JNLP endpoint, and 4.3/5.0 runtime option tests passed.');
|
||||
Reference in New Issue
Block a user