Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / resources / late-start-testing.js
blob96f709b1285e757504e96ddeddc592f981fa00bf
1 function runLateStartTest(audit, context, node) {
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();
8 osc.connect(silent);
9 silent.connect(context.destination);
10 silent.gain.setValueAtTime(0.0, 0);
11 osc.start();
13 node.connect(context.destination);
15 // Task: define |onstatechange| and start rendering.
16 audit.defineTask('test-late-start', function (done) {
18 // Trigger playback at 0 second. The assumptions are:
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.
26 // See issue: crbug.com/462167
27 context.onstatechange = function () {
28 if (context.state === 'running') {
29 node.start(0);
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) {
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;
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.');
55 done();
56 });
57 });
59 audit.defineTask('finish-test', function (done) {
60 done();
61 finishJSTest();
62 });
64 audit.runTasks(
65 'test-late-start',
66 'finish-test'