Update selection handle position in Ref-Internet browser
[framework/web/webkit-efl.git] / LayoutTests / webaudio / audiobuffersource-loop-comprehensive.html
1 <!DOCTYPE html>
2
3 <html>
4 <head>
5 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
6 <script src="resources/audio-testing.js"></script>
7 <script src="resources/audiobuffersource-testing.js"></script>
8 <script src="../fast/js/resources/js-test-pre.js"></script>
9 </head>
10
11 <body>
12
13 <div id="description"></div>
14 <div id="console"></div>
15
16 <script>
17 description("Tests AudioBufferSourceNode looping with a variety of loop points.");
18
19 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,...
20
21 var tests = [
22
23 { description: "loop whole buffer by default with loopStart == loopEnd == 0",
24   loopStartFrame: 0, loopEndFrame: 0, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
25
26 { description: "loop whole buffer explicitly",
27   loopStartFrame: 0, loopEndFrame: 8, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
28
29 { description: "loop from middle to end of buffer",
30   loopStartFrame: 4, loopEndFrame: 8, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,4,5,6,7,4,5,6,7] },
31
32 { description: "loop from start to middle of buffer",
33   loopStartFrame: 0, loopEndFrame: 4, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3] },
34
35 { description: "loop internally from 4 -> 6",
36   loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,4,5,4,5,4,5,4,5,4,5] },
37
38 { description: "loop internally from 3 -> 7",
39   loopStartFrame: 3, loopEndFrame: 7, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,3,4,5,6,3,4,5,6,3] },
40
41 { description: "loop internally from 4 -> 6 with playbackRate of 0.5",
42   loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 0.5, expected: [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 4, 4.5, 5, 5.5] },
43
44 { description: "loop internally from 4 -> 6 with playbackRate of 1.5",
45   loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 1.5, expected: [0, 1.5, 3, 4.5, 4, 5.5, 5, 4.5, 4, 5.5, 5, 4.5, 4, 5.5, 5, 4.5] },
46
47 { description: "illegal playbackRate of 47 greater than loop length",
48   loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 47, expected: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] },
49
50 // Try illegal loop-points - they should be ignored and we'll loop the whole buffer.
51
52 { description: "illegal loop: loopStartFrame > loopEndFrame",
53   loopStartFrame: 7, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
54
55 { description: "illegal loop: loopStartFrame == loopEndFrame",
56   loopStartFrame: 3, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
57
58 { description: "illegal loop: loopStartFrame < 0",
59   loopStartFrame: -45, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
60
61 { description: "illegal loop: loopEndFrame > bufferLength",
62   loopStartFrame: 0, loopEndFrame: 30000, renderFrames: 16, playbackRate: 1, expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] },
63
64 ];
65
66 var sampleRate = 44100;
67 var buffer;
68 var bufferFrameLength = 8;
69 var testSpacingFrames = 32;
70 var testSpacingSeconds = testSpacingFrames / sampleRate;
71 var totalRenderLengthFrames = tests.length * testSpacingFrames;
72
73 function runLoopTest(context, testNumber, test) {
74     var source = context.createBufferSource();
75
76     source.buffer = buffer;
77     source.playbackRate.value = test.playbackRate;
78     source.loop = true;
79     source.loopStart = test.loopStartFrame / context.sampleRate;
80     source.loopEnd = test.loopEndFrame / context.sampleRate;
81
82     source.connect(context.destination);
83
84     // Render each test one after the other, spaced apart by testSpacingSeconds.
85     var startTime = testNumber * testSpacingSeconds;
86     var duration = test.renderFrames / context.sampleRate;
87     source.start(startTime);
88     source.stop(startTime + duration);
89 }
90
91 function runTest() {
92     if (window.testRunner) {
93         testRunner.dumpAsText();
94         testRunner.waitUntilDone();
95     }
96
97     window.jsTestIsAsync = true;
98
99     // Create offline audio context.
100     var context = new webkitOfflineAudioContext(1, totalRenderLengthFrames, sampleRate);
101     buffer = createTestBuffer(context, bufferFrameLength);
102
103     for (var i = 0; i < tests.length; ++i)
104         runLoopTest(context, i, tests[i]);
105
106     context.oncomplete = checkAllTests;
107     context.startRendering();
108 }
109
110 runTest();
111 successfullyParsed = true;
112
113 </script>
114
115 <script src="../fast/js/resources/js-test-post.js"></script>
116 </body>
117 </html>