summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/audioparam-large-endtime.html
blob: d8f38eeba0857a352badbdbeef3eca8bf9a6f087 (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
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
  <head>
    <title>
      AudioParam with Huge End Time
    </title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/webaudio/resources/audit-util.js"></script>
    <script src="/webaudio/resources/audit.js"></script>
  </head>
  <body>
    <script id="layout-test-code">
      let sampleRate = 48000;
      // Render for some small (but fairly arbitrary) time.
      let renderDuration = 0.125;
      // Any huge time value that won't fit in a size_t (2^64 on a 64-bit
      // machine).
      let largeTime = 1e300;

      let audit = Audit.createTaskRunner();

      // See crbug.com/582701.  Create an audioparam with a huge end time and
      // verify that to automation is run.  We don't care about the actual
      // results, just that it runs.

      // Test linear ramp with huge end time
      audit.define('linearRamp', (task, should) => {
        let graph = createGraph();
        graph.gain.gain.linearRampToValueAtTime(0.1, largeTime);

        graph.source.start();
        graph.context.startRendering()
            .then(function(buffer) {
              should(true, 'linearRampToValue(0.1, ' + largeTime + ')')
                  .message('successfully rendered', 'unsuccessfully rendered');
            })
            .then(() => task.done());
      });

      // Test exponential ramp with huge end time
      audit.define('exponentialRamp', (task, should) => {
        let graph = createGraph();
        graph.gain.gain.exponentialRampToValueAtTime(.1, largeTime);

        graph.source.start();
        graph.context.startRendering()
            .then(function(buffer) {
              should(true, 'exponentialRampToValue(0.1, ' + largeTime + ')')
                  .message('successfully rendered', 'unsuccessfully rendered');
            })
            .then(() => task.done());
      });

      audit.run();

      // Create the graph and return the context, the source, and the gain node.
      function createGraph() {
        let context =
            new OfflineAudioContext(1, renderDuration * sampleRate, sampleRate);
        let src = context.createBufferSource();
        src.buffer = createConstantBuffer(context, 1, 1);
        src.loop = true;
        let gain = context.createGain();
        src.connect(gain);
        gain.connect(context.destination);
        gain.gain.setValueAtTime(1, 0.1 / sampleRate);

        return {context: context, gain: gain, source: src};
      }
    </script>
  </body>
</html>