no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / worklet / tests / test_audioWorklet_WASM.html
blob01804651184d4b067f57d7f2ea862c9755f1c4de
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>
11 <script type="application/javascript">
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 ]});
23 function create_wasmModule() {
24 return new Promise(resolve => {
25 info("Checking if we can play with WebAssembly...");
27 if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) {
28 resolve(null);
29 return;
32 ok(WebAssembly, "WebAssembly object should exist");
33 ok(WebAssembly.compile, "WebAssembly.compile function should exist");
35 const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary);
37 js -e '
38 t = wasmTextToBinary(`
39 (module
40 (func $foo (result i32) (i32.const 42))
41 (export "foo" (func $foo))
43 `);
44 print(t)
47 // eslint-disable-next-line
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]);
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 });
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();
76 node.port.postMessage({wasmModule});
77 node.port.postMessage({sab: new SharedArrayBuffer(1024)});
78 node.connect(audioContext.destination);
79 });
81 </script>
83 </body>
84 </html>