Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/audioparam-setValueCurve-exceptions.html

Issue 2581463002: Refactor WebAudio test directory (Closed)
Patch Set: Use correct path for wav result files Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <html>
3 <head>
4 <title>Test Exceptions from setValueCurveAtTime</title>
5 <script src="../resources/js-test.js"></script>
6 <script src="resources/compatibility.js"></script>
7 <script src="resources/audit-util.js"></script>
8 <script src="resources/audio-testing.js"></script>
9 </head>
10
11 <body>
12 <script>
13 description("Test Exceptions from setValueCurveAtTime");
14 window.jsTestIsAsync = true;
15
16 var sampleRate = 48000;
17 // Some short duration because we don't need to run the test for very long .
18 var testDurationSec = 0.125;
19 var testDurationFrames = testDurationSec * sampleRate;
20
21 var audit = Audit.createTaskRunner();
22
23 audit.defineTask("setValueCurve", function(done) {
24 var success = true;
25 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
26 var g = context.createGain();
27 var curve = new Float32Array(2);
28
29 // Start time and duration for setValueCurveAtTime
30 var curveStartTime = 0.1 * testDurationSec;
31 var duration = 0.1 * testDurationSec;
32
33 // Some time that is known to during the setValueCurveTime interval.
34 var automationTime = curveStartTime + duration / 2;
35
36 success = Should("setValueCurveAtTime(curve, " + curveStartTime + ", " + duration + ")", function() {
37 g.gain.setValueCurveAtTime(curve, curveStartTime, duration);
38 }).notThrow() && success;
39
40 success = Should("setValueAtTime(1, " + automationTime + ")", function() {
41 g.gain.setValueAtTime(1, automationTime);
42 }).throw("NotSupportedError") && success;
43
44 success = Should("linearRampToValueAtTime(1, " + automationTime + ")", f unction() {
45 g.gain.linearRampToValueAtTime(1, automationTime);
46 }).throw("NotSupportedError") && success;
47
48 success = Should("exponentialRampToValueAtTime(1, " + automationTime + " )", function() {
49 g.gain.exponentialRampToValueAtTime(1, automationTime);
50 }).throw("NotSupportedError") && success;
51
52 success = Should("setTargetAtTime(1, " + automationTime + ", 1)", functi on() {
53 g.gain.setTargetAtTime(1, automationTime, 1);
54 }).throw("NotSupportedError") && success;
55
56 success = Should("setValueAtTime(1, " + (curveStartTime + 1.1 * duration ) + ")", function() {
57 g.gain.setValueAtTime(1, curveStartTime + 1.1 * duration);
58 }).notThrow() && success;
59
60 var prefix = "Automation functions overlapping an existing setValueCurve AtTime";
61 if (success)
62 testPassed(prefix + " correctly signaled errors.\n");
63 else
64 testFailed(prefix + " failed to signal errors.\n");
65
66 done();
67 });
68
69 audit.defineTask("automations", function (done) {
70 var success = true;
71 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
72 var g = context.createGain();
73
74 var curve = new Float32Array(2);
75 // Start time and duration for setValueCurveAtTime
76 var startTime = 0;
77 var timeInterval = testDurationSec / 10;
78
79 startTime += timeInterval;
80 success = Should("linearRampToValueAtTime(1, " + startTime + ")", functi on () {
81 g.gain.linearRampToValueAtTime(1, startTime);
82 }).notThrow() && success;
83
84 startTime += timeInterval;
85 success = Should("exponentialRampToValueAtTime(1, " + startTime + ")", f unction () {
86 g.gain.exponentialRampToValueAtTime(1, startTime);
87 }).notThrow() && success;
88
89 startTime += timeInterval;
90 success = Should("setTargetAtTime(1, " + startTime + ", 0.1)", function () {
91 g.gain.setTargetAtTime(1, startTime, 0.1);
92 }).notThrow() && success;
93
94 startTime += timeInterval;
95 success = Should("setValueCurveAtTime(curve, " + startTime + ", 0.1)", f unction () {
96 g.gain.setValueCurveAtTime(curve, startTime, 0.1);
97 }).notThrow() && success;
98
99 // Now try to setValueCurve that overlaps each of the above automations
100 startTime = timeInterval / 2;
101
102 for (var k = 0; k < 4; ++k) {
103 var time = startTime + timeInterval * k;
104 success = Should("setValueCurveAtTime(curve, " + time + ", 0.01)", fun ction () {
105 g.gain.setValueCurveAtTime(curve, time, 0.01);
106 }).throw("NotSupportedError") && success;
107 }
108
109 // Elements of setValueCurve should be finite.
110 success = Should("setValueCurveAtTime([NaN, NaN], " + time + ", 0.01)", function () {
111 g.gain.setValueCurveAtTime(Float32Array.from([NaN, NaN]), time, 0.01);
112 }).throw("TypeError") && success;
113
114 success = Should("setValueCurveAtTime([1, Infinity], " + time + ", 0.01) ", function () {
115 g.gain.setValueCurveAtTime(Float32Array.from([1, Infinity]), time, 0.0 1);
116 }).throw("TypeError") && success;
117
118 var d = context.createDelay();
119 // Check that we get warnings for out-of-range values and also throw for
120 // non-finite values.
121 success = Should("delayTime.setValueCurveAtTime([1, 5], " + time + ", 0. 01)", function() {
122 d.delayTime.setValueCurveAtTime(Float32Array.from([1, 5]), time, 0.01) ;
123 }).notThrow() && success;
124
125 success = Should("delayTime.setValueCurveAtTime([1, 5, Infinity], " + ti me + ", 0.01)",
126 function() {
127 d.delayTime.setValueCurveAtTime(Float32Array.from([1, 5, Infinity]), time, 0.01);
128 }).throw("TypeError") && success;
129
130 // One last test that prints out lots of digits for the time.
131 var time = Math.PI / 100;
132 success = Should("setValueCurveAtTime(curve, " + time + ", 0.01)", funct ion () {
133 g.gain.setValueCurveAtTime(curve, time, 0.01);
134 }).throw("NotSupportedError") && success;
135
136 var prefix = "setValueCurve overlapping existing automation functions";
137 if (success)
138 testPassed(prefix + " correctly signaled errors.\n");
139 else
140 testFailed(prefix + " failed to signal errors.\n");
141
142 done();
143 });
144
145 audit.defineTask("catch-exception", function (done) {
146 // Verify that the curve isn't inserted into the time line even if we ca tch the exception.
147 var success = true;
148 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
149 var gain = context.createGain();
150 var source = context.createBufferSource();
151 var buffer = context.createBuffer(1, 1, context.sampleRate);
152 buffer.getChannelData(0)[0] = 1;
153 source.buffer = buffer;
154 source.loop = true;
155
156 source.connect(gain);
157 gain.connect(context.destination);
158
159 gain.gain.setValueAtTime(1, 0);
160 try {
161 // The value curve has an invalid element. This automation shouldn't b e inserted into the
162 // timeline at all.
163 gain.gain.setValueCurveAtTime(Float32Array.from([0, NaN]), 128 / conte xt.sampleRate, .5);
164 } catch (e) {
165 };
166 source.start();
167
168 context.startRendering().then(function (resultBuffer) {
169 // Since the setValueCurve wasn't inserted, the output should be exact ly 1 for the entire
170 // duration.
171 var success = Should("Handled setValueCurve exception so output", resu ltBuffer.getChannelData(0))
172 .beConstantValueOf(1);
173
174 if (success)
175 testPassed("setValueCurveAtTime correctly not inserted into timeline .\n");
176 else
177 testFailed("setValueCurveAtTime incorrectly still inserted into time line.\n");
178 }).then(done);
179 });
180
181 audit.defineTask("start-end", function (done) {
182 var success = true;
183 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
184 var g = context.createGain();
185 var curve = new Float32Array(2);
186
187 // Verify that a setValueCurve can start at the end of an automation.
188 var time = 0;
189 var timeInterval = testDurationSec / 50;
190 success = Should("setValueAtTime(1, " + time + ")", function () {
191 g.gain.setValueAtTime(1, time);
192 }).notThrow();
193
194 time += timeInterval;
195 success = Should("linearRampToValueAtTime(0, " + time + ")", function () {
196 g.gain.linearRampToValueAtTime(0, time);
197 }).notThrow() && success;
198
199 // setValueCurve starts at the end of the linear ramp. This should be fi ne.
200 success = Should("setValueCurveAtTime(..., " + time + ", " + timeInterva l + ")", function () {
201 g.gain.setValueCurveAtTime(curve, time, timeInterval);
202 }).notThrow() && success;
203
204 // exponentialRamp ending one interval past the setValueCurve should be fine.
205 time += 2*timeInterval;
206 success = Should("exponentialRampToValueAtTime(1, " + time + ")", functi on () {
207 g.gain.exponentialRampToValueAtTime(1, time);
208 }).notThrow() && success;
209
210 // setValueCurve starts at the end of the exponential ramp. This should be fine.
211 success = Should("setValueCurveAtTime(..., " + time + ", " + timeInterva l + ")", function () {
212 g.gain.setValueCurveAtTime(curve, time, timeInterval);
213 }).notThrow() && success;
214
215 // setValueCurve at the end of the setValueCurve should be fine.
216 time += timeInterval;
217 success = Should("setValueCurveAtTime(..., " + time + ", " + timeInterva l + ")", function () {
218 g.gain.setValueCurveAtTime(curve, time, timeInterval);
219 }).notThrow() && success;
220
221 // setValueAtTime at the end of setValueCurve should be fine.
222 time += timeInterval;
223 success = Should("setValueAtTime(0, " + time + ")", function () {
224 g.gain.setValueAtTime(0, time);
225 }).notThrow() && success;
226
227 // setValueCurve at the end of setValueAtTime should be fine.
228 success = Should("setValueCurveAtTime(..., " + time + ", " + timeInterva l + ")", function () {
229 g.gain.setValueCurveAtTime(curve, time, timeInterval);
230 }).notThrow() && success;
231
232 // setTarget starting at the end of setValueCurve should be fine.
233 time += timeInterval;
234 success = Should("setTargetAtTime(1, " + time + ", 1)", function () {
235 g.gain.setTargetAtTime(1, time, 1);
236 }).notThrow() && success;
237
238 var prefix = "setValueCurve with adjoining automation functions";
239 if (success)
240 testPassed(prefix + " allowed as expected.\n");
241 else
242 testFailed(prefix + " unexpectedly signaled errors.\n");
243
244 done();
245 });
246
247 audit.defineTask("curve lengths", function (done) {
248 var success = true;
249 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
250 var g = context.createGain();
251 var time = 0;
252
253 // Check for invalid curve lengths
254 success = Should("setValueCurveAtTime([], " + time + ", 0.01)", function () {
255 g.gain.setValueCurveAtTime(Float32Array.from([]), time, 0.01);
256 }).throw("InvalidStateError") && success;
257
258 success = Should("setValueCurveAtTime([1], " + time + ", 0.01)", functio n () {
259 g.gain.setValueCurveAtTime(Float32Array.from([1]), time, 0.01);
260 }).throw("InvalidStateError") && success;
261
262 success = Should("setValueCurveAtTime([1,2], " + time + ", 0.01)", funct ion () {
263 g.gain.setValueCurveAtTime(Float32Array.from([1,2]), time, 0.01);
264 }).notThrow() && success;
265
266 if (success)
267 testPassed("Exceptions for curve length correctly handled.\n");
268 else
269 testFailed("Exceptions for curve length not correctly handled.\n");
270
271 done();
272 });
273
274 audit.defineTask("finish", function (done) {
275 finishJSTest();
276 done();
277 });
278
279 audit.runTasks();
280 successfullyParsed = true;
281 </script>
282 </body>
283 </html>
284
285
286
287
288
289
290
291
292
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698