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 event handler callback from OfflineAudioContext.resume() and OfflineAudioContext.suspend().'); | |
12 window.jsTestIsAsync = true; | |
13 | |
14 var context; | |
15 var renderQuantum = 128; | |
16 | |
17 // The sample rate is multiple of the rendering quantum, so suspension | |
18 // times in the test fall in to the render quantum boundary. Although | |
19 // this is not necessary, it is easier to understand the test. | |
20 var sampleRate = renderQuantum * 100; | |
21 | |
22 var renderDuration = 2; | |
23 var scheduledSuspendTime = 0; | |
24 | |
25 // With the sample rate setting above, this ensures suspension time fall | |
26 // in to the render quantum boundary. | |
27 var suspendInterval = 0.25; | |
28 | |
29 function runTest() { | |
30 context = new OfflineAudioContext(1, sampleRate * renderDuration, sample Rate); | |
31 | |
32 context.onstatechange = function () { | |
33 if (context.state === 'suspended') { | |
34 Should('context.currentTime', context.currentTime) | |
35 .beEqualTo(scheduledSuspendTime); | |
36 | |
37 scheduledSuspendTime = context.currentTime + suspendInterval; | |
38 | |
39 // Schedule the next suspension only when |scheduledSuspendTime| is | |
40 // less than |renderDuration|. Although suspend() will catch | |
41 // the out-of-bound error, but it will reject the promise and | |
Raymond Toy
2015/07/15 20:59:13
"but it" -> "it"
hongchan
2015/07/15 23:24:22
Done.
| |
42 // this test is for the event handler, not the promise. | |
43 if (scheduledSuspendTime < renderDuration) | |
44 context.suspend(scheduledSuspendTime); | |
45 | |
46 context.resume(); | |
47 } | |
48 }; | |
49 | |
50 // This test is for verifying all the event handlers on OAC and that is | |
51 // why 'oncomplete' is used here. | |
52 context.oncomplete = function () { | |
53 Should('context.state', context.state).beEqualTo('closed'); | |
54 finishJSTest(); | |
55 }; | |
56 | |
57 // Initiate the suspension loop. | |
58 context.suspend(scheduledSuspendTime); | |
59 context.startRendering(); | |
60 } | |
61 | |
62 runTest(); | |
63 successfullyParsed = true; | |
64 </script> | |
65 | |
66 </body> | |
67 </html> | |
OLD | NEW |