tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_audioWorklet_WASM.html (2632B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for AudioWorklet + WASM</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      7  <script type="application/javascript" src="common.js"></script>
      8 </head>
      9 <body>
     10 
     11 <script type="application/javascript">
     12 
     13 function configureTest() {
     14  return SpecialPowers.pushPrefEnv(
     15    {"set": [
     16             ["dom.postMessage.sharedArrayBuffer.bypassCOOP_COEP.insecure.enabled", true],
     17             ["browser.tabs.remote.useCrossOriginOpenerPolicy", true],
     18             ["browser.tabs.remote.useCrossOriginEmbedderPolicy", true],
     19             ["javascript.options.shared_memory", true],
     20    ]});
     21 }
     22 
     23 function create_wasmModule() {
     24  return new Promise(resolve => {
     25    info("Checking if we can play with WebAssembly...");
     26 
     27    if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) {
     28      resolve(null);
     29      return;
     30    }
     31 
     32    ok(WebAssembly, "WebAssembly object should exist");
     33    ok(WebAssembly.compile, "WebAssembly.compile function should exist");
     34 
     35    // eslint-disable-next-line no-unused-vars
     36    const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary);
     37    /*
     38      js -e '
     39        t = wasmTextToBinary(`
     40          (module
     41            (func $foo (result i32) (i32.const 42))
     42            (export "foo" (func $foo))
     43          )
     44        `);
     45        print(t)
     46      '
     47    */
     48    const fooModuleCode = new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,127,3,2,1,0,7,7,1,3,102,111,111,0,0,10,6,1,4,0,65,42,11,0,13,4,110,97,109,101,1,6,1,0,3,102,111,111]);
     49 
     50    WebAssembly.compile(fooModuleCode).then(m => {
     51      ok(m instanceof WebAssembly.Module, "The WasmModule has been compiled.");
     52      resolve(m);
     53    }, () => {
     54      ok(false, "The compilation of the wasmModule failed.");
     55      resolve(null);
     56    });
     57  });
     58 }
     59 
     60 function runTestInIframe() {
     61  let audioContext = new AudioContext();
     62  audioContext.audioWorklet.addModule("worklet_audioWorklet_WASM.js")
     63  .then(() => create_wasmModule())
     64  .then(wasmModule => {
     65    const node = new AudioWorkletNode(audioContext, 'wasm');
     66    let msgId = 0;
     67    node.port.onmessage = e => {
     68      if (msgId++ == 0) {
     69        ok(e.data.wasmModule instanceof WebAssembly.Module, "WasmModule received");
     70      } else {
     71        ok(e.data.sab instanceof SharedArrayBuffer, "SAB received");
     72        SimpleTest.finish();
     73      }
     74    }
     75 
     76    node.port.postMessage({wasmModule});
     77    node.port.postMessage({sab: new SharedArrayBuffer(1024)});
     78    node.connect(audioContext.destination);
     79  });
     80 }
     81 </script>
     82 
     83 </body>
     84 </html>