4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"resources/compatibility.js"></script>
6 <script src=
"resources/audio-testing.js"></script>
7 <title>OfflineAudioContext.startRendering Promise with oncomplete
</title>
12 description("Test OfflineAudioContext.startRendering Promise with oncomplete");
19 var sampleRate
= 48000;
20 var renderSeconds
= 1;
21 var renderFrames
= sampleRate
* renderSeconds
;
22 var contextChannels
= 2;
24 function compareData() {
25 // The spec implies that the same buffer is returned by both oncomplete and the promise.
26 // Check that they are identical.
27 if (renderedData
=== promiseData
) {
28 testPassed("AudioBuffer returned by oncomplete and promise are identical");
30 testFailed("AudioBuffer returned by oncomplete and promise are NOT identical");
35 function checkResult (event
) {
36 renderedData
= event
.renderedBuffer
;
37 promise
.then(function (result
) {
43 // Create an offline context and verify that both the oncomplete and promise are returned with
46 window
.jsTestIsAsync
= true;
48 context
= new OfflineAudioContext(contextChannels
, renderFrames
, sampleRate
);
50 var buffer
= context
.createBuffer(contextChannels
, renderFrames
, sampleRate
);
51 for (var k
= 0; k
< renderFrames
; ++k
) {
52 buffer
.getChannelData(0)[k
] = 1;
53 buffer
.getChannelData(1)[k
] = 2;
56 var source
= context
.createBufferSource();
57 source
.buffer
= buffer
;
58 source
.connect(context
.destination
);
61 context
.oncomplete
= checkResult
;
63 promise
= context
.startRendering();
68 successfullyParsed
= true;