Add a test for the fixes on this branch.
[sqlite.git] / ext / wasm / tester1-worker.html
blobe768c3d6c3cfeb0bbb4ef2bc9fea9ad9d69f87d7
1 <!doctype html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
7 <link rel="stylesheet" href="../common/emscripten.css"/>
8 <link rel="stylesheet" href="../common/testing.css"/>
9 <title>sqlite3 tester #1: Worker thread</title>
10 <style></style>
11 </head>
12 <body>
13 <h1 id='color-target'>sqlite3 tester #1: Worker thread</h1>
14 <div>Variants:
15 <a href='tester1.html' target='tester1.html'>conventional UI thread</a>,
16 <a href='tester1-worker.html' target='tester1-worker.html'>conventional worker</a>,
17 <a href='tester1-esm.html' target='tester1-esm.html'>ESM in UI thread</a>,
18 <a href='tester1-worker.html?esm' target='tester1-worker.html?esm'>ESM worker</a>
19 </div>
20 <div class='input-wrapper'>
21 <input type='checkbox' id='cb-log-reverse'>
22 <label for='cb-log-reverse'>Reverse log order?</label>
23 </div>
24 <div id='test-output'></div>
25 <script>(function(){
26 const logTarget = document.querySelector('#test-output');
27 const logHtml = function(cssClass,...args){
28 const ln = document.createElement('div');
29 if(cssClass){
30 for(const c of (Array.isArray(cssClass) ? cssClass : [cssClass])){
31 ln.classList.add(c);
34 ln.append(document.createTextNode(args.join(' ')));
35 logTarget.append(ln);
37 const cbReverse = document.querySelector('#cb-log-reverse');
38 const cbReverseIt = ()=>{
39 logTarget.classList[cbReverse.checked ? 'add' : 'remove']('reverse');
41 cbReverse.addEventListener('change',cbReverseIt,true);
42 cbReverseIt();
43 const urlParams = new URL(self.location.href).searchParams;
44 const workerArgs = [];
45 if(urlParams.has('esm')){
46 logHtml('warning',"Attempting to run an ES6 Worker Module, "+
47 "which is not supported by all browsers! "+
48 "e.g. Firefox (as of 2023-05) cannot do this.");
49 workerArgs.push("tester1.mjs",{type:"module"});
50 document.querySelectorAll('title,#color-target').forEach((e)=>{
51 e.innerText = "sqlite3 tester #1: ES6 Worker Module";
52 });
53 }else{
54 workerArgs.push("tester1.js?sqlite3.dir=jswasm");
56 const w = new Worker(...workerArgs);
57 w.onmessage = function({data}){
58 switch(data.type){
59 case 'log':
60 logHtml(data.payload.cssClass, ...data.payload.args);
61 break;
62 case 'error':
63 logHtml('error', ...data.payload.args);
64 break;
65 case 'test-result':{
66 document.querySelector('#color-target').classList.add(
67 data.payload.pass ? 'tests-pass' : 'tests-fail'
69 const e = document.querySelector('title');
70 e.innerText = (
71 data.payload.pass ? 'PASS' : 'FAIL'
72 ) + ': ' + e.innerText;
73 break;
75 default:
76 logHtml('error',"Unhandled message:",data.type);
79 })();</script>
80 </body>
81 </html>