Chromium Code Reviews| 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 | 12 |
| 14 var sampleRate = 44100; | 13 var sampleRate = 44100; |
| 15 var renderDuration = 1; | 14 var renderDuration = 1; |
| 16 var renderQuantum = 128; | 15 var renderQuantum = 128; |
| 17 | 16 |
| 18 var audit = Audit.createTaskRunner(); | 17 var audit = Audit.createTaskRunner(); |
| 19 | 18 |
| 20 // Task: Calling suspend with no argument, negative time or the time | 19 // Task: Calling suspend with no argument, negative time or the time |
| 21 // beyond the maximum render duration reject the promise. | 20 // beyond the maximum render duration reject the promise. |
| 22 audit.defineTask('suspend-invalid-argument', function (done) { | 21 audit.defineTask('suspend-invalid-argument', function (done) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 // Task: Calling multiple suspends at the same rendering quantum should | 62 // Task: Calling multiple suspends at the same rendering quantum should |
| 64 // reject the promise. | 63 // reject the promise. |
| 65 audit.defineTask('identical-suspend-time', function (done) { | 64 audit.defineTask('identical-suspend-time', function (done) { |
| 66 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate); | 65 var context = new OfflineAudioContext(1, sampleRate * renderDuration, sa mpleRate); |
| 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(function() { |
| 76 | 75 context.resume(); |
| 77 // Printing out the pass message to be more informative here. | 76 })) |
|
hongchan
2017/02/07 18:26:15
Perhaps:
() => {
context.suspend(suspendTime1)
Raymond Toy
2017/02/14 16:27:57
Done. And reindented using clang-format.
| |
| 78 testPassed('Scheduling a suspend at frame ' + suspendTime1 * sampleRate + ' was successful.'); | 77 .notThrow(); |
| 79 | 78 |
| 80 Should('Scheduling another suspend at the same rendering quantum', | 79 Should('Scheduling another suspend at the same rendering quantum', |
| 81 context.suspend(suspendTime2)).beRejected(); | 80 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.defineTask('finish', function (done) { |
| 130 finishJSTest(); | |
| 131 done(); | 133 done(); |
| 132 }); | 134 }); |
|
hongchan
2017/02/07 18:26:15
This task can be removed.
Raymond Toy
2017/02/14 16:27:57
Done.
| |
| 133 | 135 |
| 134 audit.runTasks( | 136 audit.runTasks( |
| 135 'suspend-invalid-argument', | 137 'suspend-invalid-argument', |
| 136 'suspend-in-the-past', | 138 'suspend-in-the-past', |
| 137 'suspend-after-render-completion', | 139 'suspend-after-render-completion', |
| 138 'identical-suspend-time', | 140 'identical-suspend-time', |
| 139 'resume-before-suspend', | 141 'resume-before-suspend', |
| 140 'resume-without-suspend', | 142 'resume-without-suspend', |
| 141 'finish' | 143 'finish' |
| 142 ); | 144 ); |
| 143 | 145 |
| 144 successfullyParsed = true; | 146 successfullyParsed = true; |
| 145 </script> | 147 </script> |
| 146 | 148 |
| 147 </body> | 149 </body> |
| 148 </html> | 150 </html> |
| OLD | NEW |