test_audioWorklet_options.html (2552B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for AudioWorklet + Options + 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 <script type="application/javascript"> 11 12 function configureTest() { 13 return SpecialPowers.pushPrefEnv( 14 {"set": [ 15 ["dom.postMessage.sharedArrayBuffer.bypassCOOP_COEP.insecure.enabled", true], 16 ["browser.tabs.remote.useCrossOriginOpenerPolicy", true], 17 ["browser.tabs.remote.useCrossOriginEmbedderPolicy", true], 18 ["javascript.options.shared_memory", true], 19 ]}); 20 } 21 22 function create_wasmModule() { 23 return new Promise(resolve => { 24 info("Checking if we can play with WebAssembly..."); 25 26 if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) { 27 resolve(null); 28 return; 29 } 30 31 ok(WebAssembly, "WebAssembly object should exist"); 32 ok(WebAssembly.compile, "WebAssembly.compile function should exist"); 33 34 // eslint-disable-next-line no-unused-vars 35 const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary); 36 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_options.js") 63 .then(() => create_wasmModule()) 64 .then(wasmModule => { 65 const node = new AudioWorkletNode(audioContext, 'options', { processorOptions: { 66 wasmModule, sab: new SharedArrayBuffer(1024), 67 }}); 68 node.port.onmessage = e => { 69 ok(e.data.wasmModule instanceof WebAssembly.Module, "WasmModule received"); 70 ok(e.data.sab instanceof SharedArrayBuffer, "SAB received"); 71 SimpleTest.finish(); 72 } 73 74 node.connect(audioContext.destination); 75 }); 76 } 77 78 </script> 79 </body> 80 </html>