Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / webaudio / audionode-connect-order.html
1 <!DOCTYPE html>
2
3 <html>
4 <head>
5 <script src="../resources/js-test.js"></script>
6 <script src="resources/audio-testing.js"></script>
7 </head>
8
9 <body>
10
11 <div id="description"></div>
12 <div id="console"></div>
13
14 <script>
15 description("This tests that we don't trigger an assertion failure due to AudioNode connection order.");
16
17 var sampleRate = 44100.0;
18 var renderLengthSeconds = 0.125;
19 var delayTimeSeconds = 0.1;
20
21 function createSinWaveBuffer(context, lengthInSeconds, frequency) {
22     var audioBuffer = context.createBuffer(1, lengthInSeconds * sampleRate, sampleRate);
23
24     var n = audioBuffer.length;
25     var data = audioBuffer.getChannelData(0);
26
27     for (var i = 0; i < n; ++i) {
28         data[i] = Math.sin(frequency * 2 * Math.PI * i / sampleRate);
29     }
30
31     return audioBuffer;
32 }
33
34 function runTest() {
35     if (window.testRunner) {
36         testRunner.dumpAsText();
37         testRunner.waitUntilDone();
38     }
39     
40     window.jsTestIsAsync = true;
41         
42     // Create offline audio context.
43     var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
44     var toneBuffer = createSinWaveBuffer(context, renderLengthSeconds, 880);
45     
46     var bufferSource = context.createBufferSource();
47     bufferSource.buffer = toneBuffer;
48     bufferSource.connect(context.destination);
49
50     var delay = context.createDelay();
51     delay.delayTime.value = delayTimeSeconds;
52
53     // We connect delay node to gain node before anything is connected to delay node itself.
54     // We do this because we try to trigger the ASSERT which might be fired due to AudioNode connection order,
55     // especially when gain node and delay node is involved e.g. https://bugs.webkit.org/show_bug.cgi?id=76685.
56
57     var gain = context.createGain();
58     gain.connect(context.destination);
59     delay.connect(gain);
60
61     bufferSource.start(0);
62
63     context.oncomplete = finishJSTest;
64     context.startRendering();
65 }
66
67 runTest();
68
69 </script>
70
71 </body>
72 </html>