OLD | NEW |
| (Empty) |
1 function runLateStartTest(audit, context, node) { | |
2 | |
3 // Set up a dummy signal path to keep the audio context running and spend | |
4 // processing time before calling start(0). | |
5 var osc = context.createOscillator(); | |
6 var silent = context.createGain(); | |
7 | |
8 osc.connect(silent); | |
9 silent.connect(context.destination); | |
10 silent.gain.setValueAtTime(0.0, 0); | |
11 osc.start(); | |
12 | |
13 node.connect(context.destination); | |
14 | |
15 // Task: define |onstatechange| and start rendering. | |
16 audit.defineTask('test-late-start', function (done) { | |
17 | |
18 // Trigger playback at 0 second. The assumptions are: | |
19 // | |
20 // 1) The specified timing of start() call is already passed in terms of | |
21 // the context time. So the argument |0| will be clamped to the current | |
22 // context time. | |
23 // 2) The |onstatechange| event will be fired later than the 0 second | |
24 // context time. | |
25 // | |
26 // See issue: crbug.com/462167 | |
27 context.onstatechange = function () { | |
28 if (context.state === 'running') { | |
29 node.start(0); | |
30 } | |
31 }; | |
32 | |
33 // Start rendering and verify result: this verifies if 1) the rendered | |
34 // buffer contains at least one non-zero value and 2) the non-zero value is | |
35 // found later than the first output sample. | |
36 context.startRendering().then(function (buffer) { | |
37 | |
38 var nonZeroValueIndex = -1; | |
39 var channelData = buffer.getChannelData(0); | |
40 for (var i = 0; i < channelData.length; i++) { | |
41 if (channelData[i] !== 0) { | |
42 nonZeroValueIndex = i; | |
43 break; | |
44 } | |
45 } | |
46 | |
47 if (nonZeroValueIndex === -1) { | |
48 testFailed('The rendered buffer was all zeros.'); | |
49 } else if (nonZeroValueIndex === 0) { | |
50 testFailed('The first sample was non-zero value. It should be zero.'); | |
51 } else { | |
52 testPassed('The rendered buffer contains non-zero values after the first
sample.'); | |
53 } | |
54 | |
55 done(); | |
56 }); | |
57 }); | |
58 | |
59 audit.defineTask('finish-test', function (done) { | |
60 done(); | |
61 finishJSTest(); | |
62 }); | |
63 | |
64 audit.runTasks( | |
65 'test-late-start', | |
66 'finish-test' | |
67 ); | |
68 | |
69 } | |
OLD | NEW |