| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="../resources/audit-util.js"></script> | 6 <script src="../resources/audit-util.js"></script> |
| 6 <script src="../resources/audio-testing.js"></script> | 7 <script src="../resources/audit.js"></script> |
| 7 <title>OfflineAudioContext.startRendering Promise with oncomplete</title> | 8 <title>OfflineAudioContext.startRendering Promise with oncomplete</title> |
| 8 </head> | 9 </head> |
| 9 | 10 |
| 10 <body> | 11 <body> |
| 11 <script> | 12 <script> |
| 12 description("Test OfflineAudioContext.startRendering Promise with oncomple
te"); | 13 let audit = Audit.createTaskRunner(); |
| 13 | 14 |
| 14 var context; | 15 var context; |
| 15 var promise; | 16 var promise; |
| 16 var renderedData; | 17 var renderedData; |
| 17 var promiseData; | 18 var promiseData; |
| 18 | 19 |
| 19 var sampleRate = 48000; | 20 var sampleRate = 48000; |
| 20 var renderSeconds = 1; | 21 var renderSeconds = 1; |
| 21 var renderFrames = sampleRate * renderSeconds; | 22 var renderFrames = sampleRate * renderSeconds; |
| 22 var contextChannels = 2; | 23 var contextChannels = 2; |
| 23 | 24 |
| 24 function compareData() { | 25 function compareData(should) { |
| 25 // The spec implies that the same buffer is returned by both oncomplete
and the promise. | 26 // The spec implies that the same buffer is returned by both oncomplete
and the promise. |
| 26 // Check that they are identical. | 27 // Check that they are identical. |
| 27 if (renderedData === promiseData) { | 28 |
| 28 testPassed("AudioBuffer returned by oncomplete and promise are identic
al"); | 29 should(renderedData === promiseData, |
| 29 } else { | 30 "AudioBuffer returned by oncomplete and promise are identical") |
| 30 testFailed("AudioBuffer returned by oncomplete and promise are NOT ide
ntical"); | 31 .beTrue(); |
| 31 } | |
| 32 finishJSTest(); | |
| 33 } | 32 } |
| 34 | 33 |
| 35 function checkResult (event) { | 34 function checkResult (task, should, event) { |
| 36 renderedData = event.renderedBuffer; | 35 renderedData = event.renderedBuffer; |
| 37 promise.then(function (result) { | 36 promise.then(function (result) { |
| 38 promiseData = result; | 37 promiseData = result; |
| 39 compareData(); | 38 compareData(should); |
| 39 task.done(); |
| 40 }); | 40 }); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Create an offline context and verify that both the oncomplete and promi
se are returned with | 43 // Create an offline context and verify that both the oncomplete and |
| 44 // the same stuff. | 44 // promise are returned with the same stuff. |
| 45 function runTest() { | 45 audit.define("test", (task, should) => { |
| 46 window.jsTestIsAsync = true; | 46 task.describe( |
| 47 | 47 "OfflineAudioContext.startRendering Promise with oncomplete"); |
| 48 context = new OfflineAudioContext(contextChannels, renderFrames, sampleR
ate); | 48 context = new OfflineAudioContext(contextChannels, renderFrames, |
| 49 sampleRate); |
| 49 | 50 |
| 50 var buffer = context.createBuffer(contextChannels, renderFrames, sampleR
ate); | 51 var buffer = context.createBuffer(contextChannels, renderFrames, |
| 52 sampleRate); |
| 51 for (var k = 0; k < renderFrames; ++k) { | 53 for (var k = 0; k < renderFrames; ++k) { |
| 52 buffer.getChannelData(0)[k] = 1; | 54 buffer.getChannelData(0)[k] = 1; |
| 53 buffer.getChannelData(1)[k] = 2; | 55 buffer.getChannelData(1)[k] = 2; |
| 54 } | 56 } |
| 55 | 57 |
| 56 var source = context.createBufferSource(); | 58 var source = context.createBufferSource(); |
| 57 source.buffer = buffer; | 59 source.buffer = buffer; |
| 58 source.connect(context.destination); | 60 source.connect(context.destination); |
| 59 source.start(); | 61 source.start(); |
| 60 | 62 |
| 61 context.oncomplete = checkResult; | 63 context.oncomplete = (event) => { |
| 64 checkResult(task, should, event); |
| 65 }; |
| 62 | 66 |
| 63 promise = context.startRendering(); | 67 promise = context.startRendering(); |
| 64 | |
| 65 } | |
| 66 | 68 |
| 67 runTest(); | 69 }); |
| 68 successfullyParsed = true; | 70 |
| 71 audit.run(); |
| 69 </script> | 72 </script> |
| 70 | 73 |
| 71 </body> | 74 </body> |
| 72 </html> | 75 </html> |
| OLD | NEW |