| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Exceptions from setValueCurveAtTime</title> | 4 <title>Test Exceptions from setValueCurveAtTime</title> |
| 5 <script src="../resources/js-test.js"></script> | 5 <script src="../resources/js-test.js"></script> |
| 6 <script src="resources/compatibility.js"></script> | 6 <script src="resources/compatibility.js"></script> |
| 7 <script src="resources/audio-testing.js"></script> | 7 <script src="resources/audio-testing.js"></script> |
| 8 </head> | 8 </head> |
| 9 | 9 |
| 10 <body> | 10 <body> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Now try to setValueCurve that overlaps each of the above automations | 98 // Now try to setValueCurve that overlaps each of the above automations |
| 99 startTime = timeInterval / 2; | 99 startTime = timeInterval / 2; |
| 100 | 100 |
| 101 for (var k = 0; k < 4; ++k) { | 101 for (var k = 0; k < 4; ++k) { |
| 102 var time = startTime + timeInterval * k; | 102 var time = startTime + timeInterval * k; |
| 103 success = Should("setValueCurveAtTime(curve, " + time + ", 0.01)", fun
ction () { | 103 success = Should("setValueCurveAtTime(curve, " + time + ", 0.01)", fun
ction () { |
| 104 g.gain.setValueCurveAtTime(curve, time, 0.01); | 104 g.gain.setValueCurveAtTime(curve, time, 0.01); |
| 105 }).throw("NotSupportedError") && success; | 105 }).throw("NotSupportedError") && success; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Elements of setValueCurve should be finite. |
| 109 success = Should("setValueCurveAtTime([NaN, NaN], " + time + ", 0.01)",
function () { |
| 110 g.gain.setValueCurveAtTime(Float32Array.from([NaN, NaN]), time, 0.01); |
| 111 }).throw("TypeError") && success; |
| 112 |
| 113 success = Should("setValueCurveAtTime([1, Infinity], " + time + ", 0.01)
", function () { |
| 114 g.gain.setValueCurveAtTime(Float32Array.from([1, Infinity]), time, 0.0
1); |
| 115 }).throw("TypeError") && success; |
| 116 |
| 108 // One last test that prints out lots of digits for the time. | 117 // One last test that prints out lots of digits for the time. |
| 109 var time = Math.PI / 100; | 118 var time = Math.PI / 100; |
| 110 success = Should("setValueCurveAtTime(curve, " + time + ", 0.01)", funct
ion () { | 119 success = Should("setValueCurveAtTime(curve, " + time + ", 0.01)", funct
ion () { |
| 111 g.gain.setValueCurveAtTime(curve, time, 0.01); | 120 g.gain.setValueCurveAtTime(curve, time, 0.01); |
| 112 }).throw("NotSupportedError") && success; | 121 }).throw("NotSupportedError") && success; |
| 113 | 122 |
| 114 var prefix = "setValueCurve overlapping existing automation functions"; | 123 var prefix = "setValueCurve overlapping existing automation functions"; |
| 115 if (success) | 124 if (success) |
| 116 testPassed(prefix + " correctly signaled errors.\n"); | 125 testPassed(prefix + " correctly signaled errors.\n"); |
| 117 else | 126 else |
| 118 testFailed(prefix + " failed to signal errors.\n"); | 127 testFailed(prefix + " failed to signal errors.\n"); |
| 119 | 128 |
| 120 done(); | 129 done(); |
| 121 }); | 130 }); |
| 122 | 131 |
| 132 audit.defineTask("catch-exception", function (done) { |
| 133 // Verify that the curve isn't inserted into the time line even if we ca
tch the exception. |
| 134 var success = true; |
| 135 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate)
; |
| 136 var gain = context.createGain(); |
| 137 var source = context.createBufferSource(); |
| 138 var buffer = context.createBuffer(1, 1, context.sampleRate); |
| 139 buffer.getChannelData(0)[0] = 1; |
| 140 source.buffer = buffer; |
| 141 source.loop = true; |
| 142 |
| 143 source.connect(gain); |
| 144 gain.connect(context.destination); |
| 145 |
| 146 gain.gain.setValueAtTime(1, 0); |
| 147 try { |
| 148 // The value curve has an invalid element. This automation shouldn't b
e inserted into the |
| 149 // timeline at all. |
| 150 gain.gain.setValueCurveAtTime(Float32Array.from([0, NaN]), 128 / conte
xt.sampleRate, .5); |
| 151 } catch (e) { |
| 152 }; |
| 153 source.start(); |
| 154 |
| 155 context.startRendering().then(function (resultBuffer) { |
| 156 // Since the setValueCurve wasn't inserted, the output should be exact
ly 1 for the entire |
| 157 // duration. |
| 158 var success = Should("Handled setValueCurve exception so output", resu
ltBuffer.getChannelData(0)) |
| 159 .beConstantValueOf(1); |
| 160 |
| 161 if (success) |
| 162 testPassed("setValueCurveAtTime correctly not inserted into timeline
.\n"); |
| 163 else |
| 164 testFailed("setValueCurveAtTime incorrectly still inserted into time
line.\n"); |
| 165 }).then(done); |
| 166 }); |
| 167 |
| 123 audit.defineTask("start-end", function (done) { | 168 audit.defineTask("start-end", function (done) { |
| 124 var success = true; | 169 var success = true; |
| 125 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate)
; | 170 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate)
; |
| 126 var g = context.createGain(); | 171 var g = context.createGain(); |
| 127 var curve = new Float32Array(2); | 172 var curve = new Float32Array(2); |
| 128 | 173 |
| 129 // Verify that a setValueCurve can start at the end of an automation. | 174 // Verify that a setValueCurve can start at the end of an automation. |
| 130 var time = 0; | 175 var time = 0; |
| 131 var timeInterval = testDurationSec / 50; | 176 var timeInterval = testDurationSec / 50; |
| 132 success = Should("setValueAtTime(1, " + time + ")", function () { | 177 success = Should("setValueAtTime(1, " + time + ")", function () { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 </html> | 243 </html> |
| 199 | 244 |
| 200 | 245 |
| 201 | 246 |
| 202 | 247 |
| 203 | 248 |
| 204 | 249 |
| 205 | 250 |
| 206 | 251 |
| 207 | 252 |
| OLD | NEW |