OLD | NEW |
---|---|
(Empty) | |
1 <!doctype html> | |
2 <html> | |
3 <head> | |
4 <script src="../resources/js-test.js"></script> | |
5 <script src="resources/compatibility.js"></script> | |
6 <script src="resources/audio-testing.js"></script> | |
7 </head> | |
8 | |
9 <body> | |
10 <script> | |
11 description('Test promise resolution of OfflineAudioContext.resume() and O fflineAudioContext.suspend().'); | |
12 window.jsTestIsAsync = true; | |
13 | |
14 var context; | |
15 | |
16 // The sample rate is multiple of the rendering quantum, so suspension | |
17 // times fall in to the render quantum boundary. | |
18 var renderQuantum = 128; | |
19 | |
20 var sampleRate = renderQuantum * 100; | |
21 var renderDuration = 2; | |
22 var scheduledSuspendTime = 0; | |
23 | |
24 // With the sample rate setting above, this ensures suspension time fall | |
25 // in to the render quantum boundary. | |
26 var suspendInterval = 0.25; | |
27 | |
28 context = new OfflineAudioContext(1, sampleRate * renderDuration, sampleRa te); | |
29 | |
30 function onSuspended() { | |
31 Should('context.currentTime', context.currentTime) | |
32 .beEqualTo(scheduledSuspendTime); | |
33 | |
34 scheduledSuspendTime = context.currentTime + suspendInterval; | |
35 | |
36 // When |scheduledSuspendTime >= renderDuration|, suspending the context | |
37 // will reject the promise. | |
38 if (scheduledSuspendTime < renderDuration) { | |
39 context.suspend(scheduledSuspendTime).then(onSuspended); | |
40 } else { | |
41 Should('context.suspend(scheduledSuspendTime)', | |
42 context.suspend(scheduledSuspendTime)).beRejected(); | |
43 } | |
44 | |
45 context.resume(); | |
46 } | |
47 | |
48 // Initiate the suspension loop. | |
49 context.suspend(scheduledSuspendTime).then(onSuspended); | |
50 context.startRendering().then(function () { | |
51 Should('context.state', context.state).beEqualTo('closed'); | |
52 finishJSTest(); | |
53 }); | |
Raymond Toy
2015/07/15 20:59:13
Would it be nicer to write startRendering() like t
hongchan
2015/07/15 23:24:22
Done.
| |
54 | |
55 successfullyParsed = true; | |
56 </script> | |
57 | |
58 </body> | |
59 </html> | |
OLD | NEW |