summaryrefslogtreecommitdiffstats
path: root/dom/worklet/tests/test_promise.html
blob: 8ea71af9a6313032b03b2caefc495e347961fe72 (plain)
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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for promise in worklet</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="application/javascript" src="common.js"></script>
</head>
<body>

<script type="application/javascript">

function configureTest() {
  return SpecialPowers.pushPrefEnv(
    {"set": [["dom.audioworklet.enabled", true],
             ["dom.worklet.enabled", true]]});
}

function runTestInIframe() {
  if (!SpecialPowers.Cu.getJSTestingFunctions().wasmIsSupported()) {
    SimpleTest.finish();
    return;
  }

  ok(window.isSecureContext, "Test should run in secure context");
  var audioContext = new AudioContext();
  ok(audioContext.audioWorklet instanceof AudioWorklet,
     "AudioContext.audioWorklet should be an instance of AudioWorklet");
  audioContext.audioWorklet.addModule("worklet_promise.js")
  .then(() => {
    const node = new AudioWorkletNode(audioContext, 'promise');
    node.port.onmessage = e => {
      ok(e.data instanceof WebAssembly.Module, "The WasmModule has been compiled into the worklet.");
      SimpleTest.finish();
    }

    const wasmTextToBinary = SpecialPowers.unwrap(SpecialPowers.Cu.getJSTestingFunctions().wasmTextToBinary);
    /*
      js -e '
        t = wasmTextToBinary(`
          (module
            (func $foo (result i32) (i32.const 42))
            (export "foo" (func $foo))
          )
        `);
        print(t)
      '
    */
    // eslint-disable-next-line
    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]);

    node.port.postMessage(fooModuleCode);
  });
}
</script>
</body>
</html>