1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
.vtk_test_suite {
padding-right: 0;
margin-left: auto;
margin-right: auto;
display: block;
}
body {
background-color: black;
}
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.vtk_test_suite {
border: 0px none;
background-color: black;
}
</style>
</head>
<body>
<canvas class="vtk_test_suite" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
<script>
var wasmStdOutErr = Array();
var exitCodeSent = false;
function closeWindow() {
try {
window.close();
}
catch (err) {
console.error(`Failed to close window ${err}`);
}
}
function postExitCode(code) {
return new Promise((resolve) => {
try {
const req = new XMLHttpRequest;
req.open("POST", "exit");
req.send(code);
req.onload = (e) => {
if (req.readyState === req.DONE && req.status === 200) {
if (req.responseText !== 'undefined') {
resolve(req.responseText);
}
}
};
} catch (err) {
reject(err);
}
})
};
function flushConsoleMessages() {
return new Promise((resolve, reject) => {
try {
if (!wasmStdOutErr.length) {
// Nothing was printed by C++ test, this is fine.
resolve();
} else {
const req = new XMLHttpRequest;
const encoder = new TextEncoder();
let view = encoder.encode(wasmStdOutErr.join("\n"));
wasmStdOutErr.length = 0;
req.open("POST", "console_output");
req.send(view);
req.onload = (e) => {
if (req.readyState === req.DONE && req.status === 200) {
resolve();
}
};
}
}
catch (err) {
reject(err)
}
});
};
function finalize(code) {
if (exitCodeSent) {
return;
}
exitCodeSent = true;
flushConsoleMessages()
.then(() => {
postExitCode(code)
.then((responseText) => {
if (responseText.includes("close-window")) {
closeWindow();
} else {
console.log("Leaving window open.");
}
}).catch((err) => {
console.error(`postExitCode failed. ${err}`);
closeWindow();
})
})
.catch((err) => {
console.error(`flushConsoleMessages failed. ${err}`);
closeWindow();
});
};
/**
* Lock canvas size for VTK rendering unit tests. These settings make the canvas ignore
* resize events from the parent HTML element.
*/
function lockCanvasSize(wasmRuntime) {
try {
if (typeof wasmRuntime._setDefaultExpandVTKCanvasToContainer !== 'undefined') {
wasmRuntime._setDefaultExpandVTKCanvasToContainer(false);
}
if (typeof wasmRuntime._setDefaultInstallHTMLResizeObserver !== 'undefined') {
wasmRuntime._setDefaultInstallHTMLResizeObserver(false);
}
} catch (_e) { }
}
window.onunhandledrejection = (event) => {
let message = `Uncaught rejection from ${event.promise}: ${event.reason}`;
console.error(message);
wasmStdOutErr.push(message);
finalize(1);
return true;
};
window.onerror = (message, source, lineno, colno, error) => {
if (error !== null) {
console.error(error);
wasmStdOutErr.push(`${error.message} at ${source}:${lineno}#${colno}`)
}
else {
console.error(`${message} at ${source}:${lineno}#${colno}`);
wasmStdOutErr.push(`${message} at ${source}:${lineno}#${colno}`)
}
finalize(1);
return true;
};
var vtkWasmRuntime = null;
var Module = {
arguments: [],
print: (() => {
return (...args) => {
const text = args.join(" ");
if (text.length > 0) {
wasmStdOutErr.push(text);
console.log(text);
}
};
})(),
printErr: (() => {
return (...args) => {
const text = args.join(" ");
if (text.length > 0) {
wasmStdOutErr.push(text);
console.error(text);
// Some VTK tests write to stderr when they should infact write to stdout.
// This block only posts exit code when the message has the word "Error" in all it's case avatars.
if (text.includes('ERROR') || text.includes("Error") || text.includes("error")) {
// catch some more of those "ERROR" messages to give some context before finalizing.
setTimeout(finalize, 2000, 1);
}
}
};
})(),
canvas: (() => {
let canvasElement = document.getElementById("canvas");
canvasElement.addEventListener("click", _e => canvasElement.focus());
canvasElement.addEventListener("webglcontextlost", (e) => { alert("WebGL context lost. You will need to reload the page."); e.preventDefault(); }, false);
return canvasElement;
})(),
preRun: (runtime) => {
// cache the VTK wasm runtime instance.
vtkWasmRuntime = runtime;
},
onRuntimeInitialized: () => {
if (vtkWasmRuntime !== null) {
lockCanvasSize(vtkWasmRuntime);
}
},
onExit: finalize,
arguments: [{{ test_args }}]
};
</script>
{% if js_type == "module" %}
<script type="module">
import initModule from "./{{ js_filename }}";
initModule(Module);
</script>
{% else %}
<script async src="{{ js_filename }}"></script>
{% endif %}
</body>
</html>
|