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 </head> | 8 </head> |
8 | 9 |
9 <body> | 10 <body> |
10 <script> | 11 <script> |
11 description('Test promise resolution of OfflineAudioContext.resume() and O fflineAudioContext.suspend().'); | 12 var audit = Audit.createTaskRunner(); |
12 window.jsTestIsAsync = true; | |
13 | |
14 var context; | 13 var context; |
15 | 14 |
16 // The sample rate is multiple of the rendering quantum, so suspension | 15 // The sample rate is multiple of the rendering quantum, so suspension |
17 // times fall in to the render quantum boundary. | 16 // times fall in to the render quantum boundary. |
18 var renderQuantum = 128; | 17 var renderQuantum = 128; |
19 | 18 |
20 var sampleRate = renderQuantum * 100; | 19 var sampleRate = renderQuantum * 100; |
21 var renderDuration = 2; | 20 var renderDuration = 2; |
22 var scheduledSuspendTime = 0; | 21 var scheduledSuspendTime = 0; |
23 | 22 |
24 // With the sample rate setting above, this ensures suspension time fall | 23 // With the sample rate setting above, this ensures suspension time fall |
25 // in to the render quantum boundary. | 24 // in to the render quantum boundary. |
26 var suspendInterval = 0.25; | 25 var suspendInterval = 0.25; |
27 | 26 |
28 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa te); | 27 function onSuspended(should) { |
29 | 28 if (context.state === 'suspended' && context.currentTime === |
30 function onSuspended() { | 29 scheduledSuspendTime) { |
hongchan
2017/02/07 18:38:43
I find this line break is weird. This should be:
Raymond Toy
2017/02/07 19:11:10
js-(un)beautify. I'll reindent this with clang-fo
| |
31 if (context.state === 'suspended' && context.currentTime === scheduledSu spendTime) { | 30 should(context.state === 'suspended' && context.currentTime === |
32 | 31 scheduledSuspendTime, |
hongchan
2017/02/07 18:38:43
Ditto.
| |
33 testPassed('suspend promise resolved: context is suspended at ' + | 32 'Context suspended at ' + scheduledSuspendTime + ' second(s)') |
34 scheduledSuspendTime + ' second(s).'); | 33 .beTrue(); |
35 | 34 |
36 scheduledSuspendTime = context.currentTime + suspendInterval; | 35 scheduledSuspendTime = context.currentTime + suspendInterval; |
37 | 36 |
38 // Scheduling a suspend before the render duration should pass. | 37 // Scheduling a suspend before the render duration should pass. |
39 if (scheduledSuspendTime < renderDuration) { | 38 if (scheduledSuspendTime < renderDuration) { |
40 context.suspend(scheduledSuspendTime).then(onSuspended); | 39 should(() => context.suspend(scheduledSuspendTime).then(() => |
41 testPassed('A new suspend has been scheduled at ' + | 40 onSuspended(should)), |
42 scheduledSuspendTime + ' second(s).'); | 41 'Scheduling a new suspend at ' + |
42 scheduledSuspendTime + ' second(s)') | |
43 .notThrow(); | |
43 } | 44 } |
44 | 45 |
45 // Scheduling a suspend exactly at the render duration should be | 46 // Scheduling a suspend exactly at the render duration should be |
46 // rejected. | 47 // rejected. |
47 if (scheduledSuspendTime === renderDuration) { | 48 if (scheduledSuspendTime === renderDuration) { |
48 Should('Scheduling at ' + renderDuration + ' seconds', | 49 should(context.suspend(scheduledSuspendTime), |
49 context.suspend(scheduledSuspendTime)).beRejected(); | 50 'Scheduling at ' + renderDuration + ' seconds' |
51 ).beRejected(); | |
50 } | 52 } |
51 | 53 |
52 context.resume(); | 54 context.resume(); |
53 } | 55 } |
54 } | 56 } |
55 | 57 |
56 // Schedule the first suspension. | 58 audit.define('test', (task, should) => { |
57 context.suspend(scheduledSuspendTime).then(onSuspended); | 59 task.describe('Promise resolution of resume() and suspend()'); |
58 testPassed('A new suspend has been scheduled at ' + scheduledSuspendTime + ' second(s).'); | 60 context = new OfflineAudioContext(1, sampleRate * renderDuration, |
61 sampleRate); | |
59 | 62 |
60 context.startRendering().then(function () { | 63 // Schedule the first suspension. |
61 Should('Promise context.state', context.state).beEqualTo('closed'); | 64 should(() => context.suspend(scheduledSuspendTime) |
62 }).then(finishJSTest); | 65 .then(() => |
66 onSuspended(should)), | |
67 'Scheduling a new suspend at ' + scheduledSuspendTime + | |
68 ' second(s)') | |
69 .notThrow(); | |
63 | 70 |
64 successfullyParsed = true; | 71 context.startRendering().then(function () { |
72 should(context.state, 'Promise context.state') | |
73 .beEqualTo('closed'); | |
74 }).then(() => task.done()); | |
75 }); | |
76 | |
77 audit.run(); | |
65 </script> | 78 </script> |
66 | 79 |
67 </body> | 80 </body> |
68 </html> | 81 </html> |
OLD | NEW |