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