OLD | NEW |
1 <!doctype html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
| 4 <title> |
| 5 offlineaudiocontext-suspend-resume-basic.html |
| 6 </title> |
4 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
5 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
6 <script src="../resources/audit-util.js"></script> | 9 <script src="../resources/audit-util.js"></script> |
7 <script src="../resources/audit.js"></script> | 10 <script src="../resources/audit.js"></script> |
8 </head> | 11 </head> |
| 12 <body> |
| 13 <script id="layout-test-code"> |
| 14 let sampleRate = 44100; |
| 15 let renderDuration = 1; |
| 16 let renderQuantum = 128; |
9 | 17 |
10 <body> | 18 let audit = Audit.createTaskRunner(); |
11 <script> | |
12 var sampleRate = 44100; | |
13 var renderDuration = 1; | |
14 var renderQuantum = 128; | |
15 | |
16 var audit = Audit.createTaskRunner(); | |
17 | 19 |
18 // Task: Calling suspend with no argument, negative time or the time | 20 // Task: Calling suspend with no argument, negative time or the time |
19 // beyond the maximum render duration reject the promise. | 21 // beyond the maximum render duration reject the promise. |
20 audit.define('suspend-invalid-argument', (task, should) => { | 22 audit.define('suspend-invalid-argument', (task, should) => { |
21 var context = | 23 let context = |
22 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); | 24 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
23 | 25 |
24 should(context.suspend(), 'context.suspend()').beRejected(); | 26 should(context.suspend(), 'context.suspend()').beRejected(); |
25 should(context.suspend(-1.0), 'context.suspend(-1.0)').beRejected(); | 27 should(context.suspend(-1.0), 'context.suspend(-1.0)').beRejected(); |
26 should(context.suspend(2.0), 'context.suspend(2.0)').beRejected(); | 28 should(context.suspend(2.0), 'context.suspend(2.0)').beRejected(); |
27 | 29 |
28 context.startRendering().then(() => task.done()); | 30 context.startRendering().then(() => task.done()); |
29 }); | 31 }); |
30 | 32 |
31 // Task: Scheduling a suspend in the past should be rejected. | 33 // Task: Scheduling a suspend in the past should be rejected. |
32 audit.define('suspend-in-the-past', (task, should) => { | 34 audit.define('suspend-in-the-past', (task, should) => { |
33 var context = | 35 let context = |
34 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); | 36 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
35 | 37 |
36 context.suspend(0.5).then(function() { | 38 context.suspend(0.5).then(function() { |
37 should( | 39 should( |
38 context.suspend(context.currentTime - 0.1), | 40 context.suspend(context.currentTime - 0.1), |
39 'Scheduling a suspend in the past') | 41 'Scheduling a suspend in the past') |
40 .beRejected(); | 42 .beRejected(); |
41 | 43 |
42 should(context | 44 should(context |
43 .suspend( | 45 .suspend( |
44 context.currentTime + 0.1, | 46 context.currentTime + 0.1, |
45 'Scheduling a suspend in the future') | 47 'Scheduling a suspend in the future') |
46 .then(function() { | 48 .then(function() { |
47 context.resume(); | 49 context.resume(); |
48 })) | 50 })) |
49 .beResolved(); | 51 .beResolved(); |
50 | 52 |
51 context.resume(); | 53 context.resume(); |
52 }); | 54 }); |
53 | 55 |
54 context.startRendering().then(() => task.done()); | 56 context.startRendering().then(() => task.done()); |
55 }); | 57 }); |
56 | 58 |
57 // Task: suspending after rendering is finished must be rejected with the | 59 // Task: suspending after rendering is finished must be rejected with the |
58 // properly clamped frame/time information. | 60 // properly clamped frame/time information. |
59 audit.define('suspend-after-render-completion', (task, should) => { | 61 audit.define('suspend-after-render-completion', (task, should) => { |
60 var context = | 62 let context = |
61 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); | 63 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
62 context.startRendering() | 64 context.startRendering() |
63 .then(function() { | 65 .then(function() { |
64 should( | 66 should( |
65 context.suspend(renderDuration), | 67 context.suspend(renderDuration), |
66 'Scheduling a suspend after the render completion') | 68 'Scheduling a suspend after the render completion') |
67 .beRejected(); | 69 .beRejected(); |
68 }) | 70 }) |
69 .then(() => task.done()); | 71 .then(() => task.done()); |
70 }); | 72 }); |
71 | 73 |
72 // Task: Calling multiple suspends at the same rendering quantum should | 74 // Task: Calling multiple suspends at the same rendering quantum should |
73 // reject the promise. | 75 // reject the promise. |
74 audit.define('identical-suspend-time', (task, should) => { | 76 audit.define('identical-suspend-time', (task, should) => { |
75 var context = | 77 let context = |
76 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); | 78 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
77 | 79 |
78 // |suspendTime1| and |suspendTime2| are identical when quantized to | 80 // |suspendTime1| and |suspendTime2| are identical when quantized to |
79 // the render quantum size. | 81 // the render quantum size. |
80 var suspendTime1 = renderQuantum / sampleRate; | 82 let suspendTime1 = renderQuantum / sampleRate; |
81 var suspendTime2 = 1.5 * renderQuantum / sampleRate; | 83 let suspendTime2 = 1.5 * renderQuantum / sampleRate; |
82 | 84 |
83 should( | 85 should( |
84 () => context.suspend(suspendTime1).then(() => context.resume()), | 86 () => context.suspend(suspendTime1).then(() => context.resume()), |
85 'Scheduling a suspend at frame ' + suspendTime1 * sampleRate) | 87 'Scheduling a suspend at frame ' + suspendTime1 * sampleRate) |
86 .notThrow(); | 88 .notThrow(); |
87 | 89 |
88 should( | 90 should( |
89 context.suspend(suspendTime2), | 91 context.suspend(suspendTime2), |
90 'Scheduling another suspend at the same rendering quantum') | 92 'Scheduling another suspend at the same rendering quantum') |
91 .beRejected(); | 93 .beRejected(); |
92 | 94 |
93 context.startRendering().then(() => task.done()); | 95 context.startRendering().then(() => task.done()); |
94 }); | 96 }); |
95 | 97 |
96 // Task: Resuming a running context should be resolved. | 98 // Task: Resuming a running context should be resolved. |
97 audit.define('resume-before-suspend', (task, should) => { | 99 audit.define('resume-before-suspend', (task, should) => { |
98 | 100 |
99 // Make the render length 5 times longer to minimize the flakiness. | 101 // Make the render length 5 times longer to minimize the flakiness. |
100 var longRenderDuration = renderDuration * 5; | 102 let longRenderDuration = renderDuration * 5; |
101 var context = new OfflineAudioContext( | 103 let context = new OfflineAudioContext( |
102 1, sampleRate * longRenderDuration, sampleRate); | 104 1, sampleRate * longRenderDuration, sampleRate); |
103 | 105 |
104 // Create dummy audio graph to slow the rendering. | 106 // Create dummy audio graph to slow the rendering. |
105 var osc = context.createOscillator(); | 107 let osc = context.createOscillator(); |
106 var lpf = context.createBiquadFilter(); | 108 let lpf = context.createBiquadFilter(); |
107 osc.type = 'sawtooth'; | 109 osc.type = 'sawtooth'; |
108 osc.frequency.setValueAtTime(0.1, 0.0); | 110 osc.frequency.setValueAtTime(0.1, 0.0); |
109 osc.frequency.linearRampToValueAtTime(1000, longRenderDuration * 0.5); | 111 osc.frequency.linearRampToValueAtTime(1000, longRenderDuration * 0.5); |
110 osc.frequency.linearRampToValueAtTime(0.1, longRenderDuration); | 112 osc.frequency.linearRampToValueAtTime(0.1, longRenderDuration); |
111 lpf.frequency.setValueAtTime(0.1, 0.0); | 113 lpf.frequency.setValueAtTime(0.1, 0.0); |
112 lpf.frequency.linearRampToValueAtTime(1000, longRenderDuration * 0.5); | 114 lpf.frequency.linearRampToValueAtTime(1000, longRenderDuration * 0.5); |
113 lpf.frequency.linearRampToValueAtTime(0.1, longRenderDuration); | 115 lpf.frequency.linearRampToValueAtTime(0.1, longRenderDuration); |
114 osc.connect(lpf); | 116 osc.connect(lpf); |
115 lpf.connect(context.destination); | 117 lpf.connect(context.destination); |
116 osc.start(); | 118 osc.start(); |
(...skipping 11 matching lines...) Expand all Loading... |
128 context.startRendering(); | 130 context.startRendering(); |
129 | 131 |
130 // Then call resume() immediately after the rendering starts. Resuming | 132 // Then call resume() immediately after the rendering starts. Resuming |
131 // a context that is already running should be resolved. | 133 // a context that is already running should be resolved. |
132 should(context.resume(), 'Resuming a running context').beResolved(); | 134 should(context.resume(), 'Resuming a running context').beResolved(); |
133 }); | 135 }); |
134 | 136 |
135 // Task: Calling resume on a context that is not started should reject the | 137 // Task: Calling resume on a context that is not started should reject the |
136 // promise. | 138 // promise. |
137 audit.define('resume-without-suspend', (task, should) => { | 139 audit.define('resume-without-suspend', (task, should) => { |
138 var context = | 140 let context = |
139 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); | 141 new OfflineAudioContext(1, sampleRate * renderDuration, sampleRate); |
140 | 142 |
141 should(context.resume(), 'Resuming a context without starting it') | 143 should(context.resume(), 'Resuming a context without starting it') |
142 .beRejected() | 144 .beRejected() |
143 .then(() => task.done()); | 145 .then(() => task.done()); |
144 }); | 146 }); |
145 | 147 |
146 audit.run(); | 148 audit.run(); |
147 </script> | 149 </script> |
148 | |
149 </body> | 150 </body> |
150 </html> | 151 </html> |
OLD | NEW |