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