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/audit-util.js"></script> | |
7 <script src="resources/audio-testing.js"></script> | |
8 </head> | |
9 | |
10 <body> | |
11 <script> | |
12 description('Basic test for OfflineAudioContext.suspend() and OfflineAudio
Context.resume().'); | |
13 window.jsTestIsAsync = true; | |
14 | |
15 var sampleRate = 44100; | |
16 var renderDuration = 1; | |
17 var renderQuantum = 128; | |
18 | |
19 var audit = Audit.createTaskRunner(); | |
20 | |
21 // Task: Calling suspend with no argument, negative time or the time | |
22 // beyond the maximum render duration reject the promise. | |
23 audit.defineTask('suspend-invalid-argument', function (done) { | |
24 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa
mpleRate); | |
25 | |
26 Should('context.suspend()', context.suspend()).beRejected(); | |
27 Should('context.suspend(-1.0)', context.suspend(-1.0)).beRejected(); | |
28 Should('context.suspend(2.0)', context.suspend(2.0)).beRejected(); | |
29 | |
30 context.startRendering().then(done); | |
31 }); | |
32 | |
33 // Task: Scheduling a suspend in the past should be rejected. | |
34 audit.defineTask('suspend-in-the-past', function (done) { | |
35 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa
mpleRate); | |
36 | |
37 context.suspend(0.5).then(function () { | |
38 | |
39 Should('Scheduling a suspend in the past', | |
40 context.suspend(context.currentTime - 0.1)).beRejected(); | |
41 | |
42 Should('Scheduling a suspend in the future', | |
43 context.suspend(context.currentTime + 0.1).then(function () { | |
44 context.resume(); | |
45 })).beResolved(); | |
46 | |
47 context.resume(); | |
48 }); | |
49 | |
50 context.startRendering().then(done); | |
51 }); | |
52 | |
53 // Task: Calling multiple suspends at the same rendering quantum should | |
54 // reject the promise. | |
55 audit.defineTask('identical-suspend-time', function (done) { | |
56 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa
mpleRate); | |
57 | |
58 // |suspendTime1| and |suspendTime2| are identical when quantized to | |
59 // the render quantum size. | |
60 var suspendTime1 = renderQuantum / sampleRate; | |
61 var suspendTime2 = 1.5 * renderQuantum / sampleRate; | |
62 | |
63 context.suspend(suspendTime1).then(function () { | |
64 context.resume(); | |
65 }); | |
66 | |
67 // Printing out the pass message to be more informative here. | |
68 testPassed('Scheduling a suspend at frame ' + suspendTime1 * sampleRate
+ ' was successful.'); | |
69 | |
70 Should('Scheduling another suspend at the same rendering quantum', | |
71 context.suspend(suspendTime2)).beRejected(); | |
72 | |
73 context.startRendering().then(done); | |
74 }); | |
75 | |
76 // Task: Resuming a running context should be resolved. | |
77 audit.defineTask('resume-before-suspend', function (done) { | |
78 | |
79 // Make the render length 5 times longer to minimize the flakiness. | |
80 var longRenderDuration = renderDuration * 5; | |
81 var context = new OfflineAudioContext(1, sampleRate * longRenderDuration
, sampleRate); | |
82 | |
83 // Create dummy audio graph to slow the rendering. | |
84 var osc = context.createOscillator(); | |
85 var lpf = context.createBiquadFilter(); | |
86 osc.type = 'sawtooth'; | |
87 osc.frequency.setValueAtTime(0.1, 0.0); | |
88 osc.frequency.linearRampToValueAtTime(1000, longRenderDuration * 0.5); | |
89 osc.frequency.linearRampToValueAtTime(0.1, longRenderDuration); | |
90 lpf.frequency.setValueAtTime(0.1, 0.0); | |
91 lpf.frequency.linearRampToValueAtTime(1000, longRenderDuration * 0.5); | |
92 lpf.frequency.linearRampToValueAtTime(0.1, longRenderDuration); | |
93 osc.connect(lpf); | |
94 lpf.connect(context.destination); | |
95 osc.start(); | |
96 | |
97 // A suspend is scheduled at the 90% of the render duration. | |
98 context.suspend(longRenderDuration * 0.9).then(done); | |
99 | |
100 testPassed('Scheduling a suspend at ' + longRenderDuration * 0.9 + ' sec
onds.'); | |
101 | |
102 // We have to start rendering to get the time running. | |
103 context.startRendering(); | |
104 | |
105 // Then call resume() immediately after the rendering starts. Resuming | |
106 // a context that is already running should be resolved. | |
107 Should('Resuming a running context', context.resume()) | |
108 .beResolved(); | |
109 }); | |
110 | |
111 // Task: Calling resume on a context that is not started should reject the
promise. | |
112 audit.defineTask('resume-without-suspend', function (done) { | |
113 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa
mpleRate); | |
114 | |
115 Should('Resuming a context without starting it', context.resume()) | |
116 .beRejected().then(done); | |
117 }); | |
118 | |
119 audit.defineTask('finish', function (done) { | |
120 finishJSTest(); | |
121 done(); | |
122 }); | |
123 | |
124 audit.runTasks( | |
125 'suspend-invalid-argument', | |
126 'suspend-in-the-past', | |
127 'identical-suspend-time', | |
128 'resume-before-suspend', | |
129 'resume-without-suspend', | |
130 'finish' | |
131 ); | |
132 | |
133 successfullyParsed = true; | |
134 </script> | |
135 | |
136 </body> | |
137 </html> | |
OLD | NEW |