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('Basic test for OfflineAudioContext.suspend() and OfflineAudio Context.resume().'); | |
12 window.jsTestIsAsync = true; | |
13 | |
14 var sampleRate = 44100; | |
15 var renderDuration = 1; | |
16 var renderQuantum = 128; | |
17 | |
18 var audit = Audit.createTaskRunner(); | |
19 | |
20 // Task: Calling suspend with no argument or negative time should | |
21 // reject the promise. | |
22 audit.defineTask('suspend-invalid-argument', function (done) { | |
23 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate); | |
24 | |
25 Should('context.suspend()', context.suspend()).beRejected(); | |
26 Should('context.suspend(-1.0)', context.suspend(-1.0)).beRejected().then (done); | |
27 }); | |
28 | |
29 // Task: Scheduling a suspend in the past should be rejected. | |
30 audit.defineTask('suspend-in-the-past', function (done) { | |
31 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate); | |
32 | |
33 context.suspend(0.5).then(function () { | |
Raymond Toy
2015/07/15 20:59:13
Should there be a test that this suspend actually
hongchan
2015/07/15 23:24:22
Isn't that considered as 'duplicate' time entry te
| |
34 Should('Scheduling a suspend in the past', | |
35 context.suspend(context.currentTime - 0.1)).beRejected(); | |
36 context.resume(); | |
37 }); | |
38 | |
39 context.startRendering().then(done); | |
40 }); | |
41 | |
42 // Task: Calling multiple suspends at the same rendering quantum should | |
43 // reject the promise. | |
44 audit.defineTask('identical-suspend-time', function (done) { | |
45 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate); | |
46 | |
47 // |suspendTime1| and |suspendTime2| are identical when quantized to | |
48 // the render quantum size. | |
49 var suspendTime1 = renderQuantum / sampleRate; | |
50 var suspendTime2 = (renderQuantum + renderQuantum * 0.5) / sampleRate; | |
51 | |
52 context.suspend(suspendTime1); | |
53 | |
54 Should('Calling multiple suspends at the same rendering quantum', | |
55 context.suspend(suspendTime2)).beRejected().then(done); | |
56 }); | |
57 | |
58 // Task: Resuming the context before the actual suspension happens. | |
59 audit.defineTask('resume-before-suspend', function (done) { | |
60 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate); | |
61 | |
62 // A suspend is scheduled at the half. | |
63 context.suspend(renderDuration * 0.5).then(done); | |
64 | |
65 // We have to start rendering to get the time running. | |
66 context.startRendering(); | |
67 | |
68 // Then call resume() immediately after the rendering starts. This | |
69 // resume() will be performed before the actual suspension happens. | |
70 Should('Resuming before suspend', context.resume()).beRejected(); | |
Raymond Toy
2015/07/15 20:59:13
Isn't there a race here? What if GC happens betwe
hongchan
2015/07/15 23:24:22
Would chaining all these into a sequence of promis
| |
71 }); | |
72 | |
73 // Task: Calling resume on non-suspended context should reject the promise . | |
74 audit.defineTask('resume-without-suspend', function (done) { | |
75 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate); | |
76 | |
77 Should('Calling resume on non-suspended context', context.resume()) | |
78 .beRejected().then(done); | |
79 }); | |
80 | |
81 audit.defineTask('finish', function (done) { | |
82 finishJSTest(); | |
83 done(); | |
84 }); | |
85 | |
86 audit.runTasks( | |
87 'suspend-invalid-argument', | |
88 'suspend-in-the-past', | |
89 'identical-suspend-time', | |
90 'resume-before-suspend', | |
91 'resume-without-suspend', | |
92 'finish' | |
93 ); | |
94 | |
95 successfullyParsed = true; | |
96 </script> | |
97 | |
98 </body> | |
99 </html> | |
OLD | NEW |