summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioworklet-interface/audioworklet-addmodule-resolution.https.html
blob: dc324b22d6539d5383ed53f68ab911f6e96fd0dd (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
58
59
60
61
<!DOCTYPE html>
<html>
  <head>
    <title>
      Test the invocation order of AudioWorklet.addModule() and BaseAudioContext
    </title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/webaudio/resources/audit.js"></script>
  </head>
  <body>
    <script id="layout-test-code">
      let audit = Audit.createTaskRunner();

      setup(() => {
        let sampleRate = 48000;
        let realtimeContext = new AudioContext();
        let offlineContext = new OfflineAudioContext(1, sampleRate, sampleRate);

        let filePath = 'processors/dummy-processor.js';

        // Test if the browser does not crash upon addModule() call after the
        // realtime context construction.
        audit.define(
            {label: 'module-loading-after-realtime-context-creation'},
            (task, should) => {
              let dummyWorkletNode =
                  new AudioWorkletNode(realtimeContext, 'dummy');
              dummyWorkletNode.connect(realtimeContext.destination);
              should(dummyWorkletNode instanceof AudioWorkletNode,
                     '"dummyWorkletNode" is an instance of AudioWorkletNode ' +
                     'from realtime context')
                  .beTrue();
              task.done();
            });

        // Test if the browser does not crash upon addModule() call after the
        // offline context construction.
        audit.define(
            {label: 'module-loading-after-offline-context-creation'},
            (task, should) => {
              let dummyWorkletNode =
                  new AudioWorkletNode(offlineContext, 'dummy');
              dummyWorkletNode.connect(offlineContext.destination);
              should(dummyWorkletNode instanceof AudioWorkletNode,
                     '"dummyWorkletNode" is an instance of AudioWorkletNode ' +
                     'from offline context')
                  .beTrue();
              task.done();
            });

        Promise.all([
            realtimeContext.audioWorklet.addModule(filePath),
            offlineContext.audioWorklet.addModule(filePath)
          ]).then(() => {
            audit.run();
          });
      });
    </script>
  </body>
</html>