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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-cancel-and-hold.html

Issue 2727663003: Move task.describe to audit.define arg (Closed)
Patch Set: Fix up expected results Created 3 years, 9 months 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
1 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../resources/testharness.js"></script> 4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script> 5 <script src="../../resources/testharnessreport.js"></script>
6 <script src="../resources/audit-util.js"></script> 6 <script src="../resources/audit-util.js"></script>
7 <script src="../resources/audit.js"></script> 7 <script src="../resources/audit.js"></script>
8 <title>Test CancelValuesAndHoldAtTime</title> 8 <title>Test CancelValuesAndHoldAtTime</title>
9 </head> 9 </head>
10 10
11 <body> 11 <body>
12 <script> 12 <script>
13 let sampleRate = 48000; 13 let sampleRate = 48000;
14 let renderDuration = 0.5; 14 let renderDuration = 0.5;
15 15
16 let audit = Audit.createTaskRunner(); 16 let audit = Audit.createTaskRunner();
17 17
18 // The first few tasks test the cancellation of each relevant automation 18 // The first few tasks test the cancellation of each relevant automation
19 // function. For the test, a simple linear ramp from 0 to 1 is used to 19 // function. For the test, a simple linear ramp from 0 to 1 is used to
20 // start things off. Then the automation to be tested is scheduled and 20 // start things off. Then the automation to be tested is scheduled and
21 // cancelled. 21 // cancelled.
22 22
23 audit.define("linear", function (task, should) { 23 audit.define(
24 task.describe("Cancel linearRampToValueAtTime"); 24 {label: 'linear', description: 'Cancel linearRampToValueAtTime'},
25 cancelTest(should, linearRampTest("linearRampToValueAtTime"), { 25 function(task, should) {
26 valueThreshold: 8.3998e-5, 26 cancelTest(should, linearRampTest('linearRampToValueAtTime'), {
27 curveThreshold: 0 27 valueThreshold: 8.3998e-5,
28 }).then(task.done.bind(task)); 28 curveThreshold: 0
29 }); 29 }).then(task.done.bind(task));
30 30 });
31 audit.define("exponential", function (task, should) { 31
32 task.describe("Cancel exponentialRampAtTime"); 32 audit.define(
33 // Cancel an exponential ramp. The thresholds are experimentally 33 {label: 'exponential', description: 'Cancel exponentialRampAtTime'},
34 // determined. 34 function(task, should) {
35 cancelTest(should, function (g, v0, t0, cancelTime) { 35 // Cancel an exponential ramp. The thresholds are experimentally
36 // Initialize values to 0. 36 // determined.
37 g[0].gain.setValueAtTime(0, 0); 37 cancelTest(should, function(g, v0, t0, cancelTime) {
38 g[1].gain.setValueAtTime(0, 0); 38 // Initialize values to 0.
39 // Schedule a short linear ramp to start things off. 39 g[0].gain.setValueAtTime(0, 0);
40 g[0].gain.linearRampToValueAtTime(v0, t0); 40 g[1].gain.setValueAtTime(0, 0);
41 g[1].gain.linearRampToValueAtTime(v0, t0); 41 // Schedule a short linear ramp to start things off.
42 42 g[0].gain.linearRampToValueAtTime(v0, t0);
43 // After the linear ramp, schedule an exponential ramp to the end. 43 g[1].gain.linearRampToValueAtTime(v0, t0);
44 // (This is the event that will be be cancelled.) 44
45 let v1 = 0.001; 45 // After the linear ramp, schedule an exponential ramp to the end.
46 let t1 = renderDuration; 46 // (This is the event that will be be cancelled.)
47 47 let v1 = 0.001;
48 g[0].gain.exponentialRampToValueAtTime(v1, t1); 48 let t1 = renderDuration;
49 g[1].gain.exponentialRampToValueAtTime(v1, t1); 49
50 50 g[0].gain.exponentialRampToValueAtTime(v1, t1);
51 expectedConstant = Math.fround(v0 * Math.pow(v1 / v0, ( 51 g[1].gain.exponentialRampToValueAtTime(v1, t1);
52 cancelTime - 52
53 t0) / (t1 - t0))); 53 expectedConstant = Math.fround(
54 return { 54 v0 * Math.pow(v1 / v0, (cancelTime - t0) / (t1 - t0)));
55 expectedConstant: expectedConstant, 55 return {
56 autoMessage: "exponentialRampToValue(" + v1 + ", " + t1 + ")", 56 expectedConstant: expectedConstant,
57 summary: "exponentialRampToValueAtTime", 57 autoMessage: 'exponentialRampToValue(' + v1 + ', ' + t1 + ')',
58 }; 58 summary: 'exponentialRampToValueAtTime',
59 }, { 59 };
60 valueThreshold: 1.8664e-6, 60 }, {
61 curveThreshold: 5.9605e-8 61 valueThreshold: 1.8664e-6,
62 }).then(task.done.bind(task)); 62 curveThreshold: 5.9605e-8
63 }); 63 }).then(task.done.bind(task));
64 64 });
65 audit.define("setTarget", function (task, should) { 65
66 task.describe("Cancel setTargetAtTime"); 66 audit.define(
67 // Cancel a setTarget event. 67 {label: 'setTarget', description: 'Cancel setTargetAtTime'},
68 cancelTest(should, function (g, v0, t0, cancelTime) { 68 function(task, should) {
69 // Initialize values to 0. 69 // Cancel a setTarget event.
70 g[0].gain.setValueAtTime(0, 0); 70 cancelTest(should, function(g, v0, t0, cancelTime) {
71 g[1].gain.setValueAtTime(0, 0); 71 // Initialize values to 0.
72 // Schedule a short linear ramp to start things off. 72 g[0].gain.setValueAtTime(0, 0);
73 g[0].gain.linearRampToValueAtTime(v0, t0); 73 g[1].gain.setValueAtTime(0, 0);
74 g[1].gain.linearRampToValueAtTime(v0, t0); 74 // Schedule a short linear ramp to start things off.
75 75 g[0].gain.linearRampToValueAtTime(v0, t0);
76 // At the end of the linear ramp, schedule a setTarget. (This is the 76 g[1].gain.linearRampToValueAtTime(v0, t0);
77 // event that will be cancelled.) 77
78 let v1 = 0; 78 // At the end of the linear ramp, schedule a setTarget. (This is
79 let t1 = t0; 79 // the event that will be cancelled.)
80 let timeConstant = 0.05; 80 let v1 = 0;
81 81 let t1 = t0;
82 g[0].gain.setTargetAtTime(v1, t1, timeConstant); 82 let timeConstant = 0.05;
83 g[1].gain.setTargetAtTime(v1, t1, timeConstant); 83
84 84 g[0].gain.setTargetAtTime(v1, t1, timeConstant);
85 expectedConstant = Math.fround(v1 + (v0 - v1) * Math.exp(-( 85 g[1].gain.setTargetAtTime(v1, t1, timeConstant);
86 cancelTime - t0) / timeConstant)); 86
87 return { 87 expectedConstant = Math.fround(
88 expectedConstant: expectedConstant, 88 v1 + (v0 - v1) * Math.exp(-(cancelTime - t0) / timeConstant));
89 autoMessage: "setTargetAtTime(" + v1 + ", " + t1 + ", " + 89 return {
90 timeConstant + ")", 90 expectedConstant: expectedConstant,
91 summary: "setTargetAtTime", 91 autoMessage: 'setTargetAtTime(' + v1 + ', ' + t1 + ', ' +
92 }; 92 timeConstant + ')',
93 }, { 93 summary: 'setTargetAtTime',
94 valueThreshold: 4.5267e-7, //1.1317e-7, 94 };
95 curveThreshold: 0 95 }, {
96 }).then(task.done.bind(task)); 96 valueThreshold: 4.5267e-7, // 1.1317e-7,
97 }); 97 curveThreshold: 0
98 98 }).then(task.done.bind(task));
99 audit.define("setValueCurve", function (task, should) { 99 });
100 task.describe("Cancel setValueCurveAtTime"); 100
101 // Cancel a setValueCurve event. 101 audit.define(
102 cancelTest(should, function (g, v0, t0, cancelTime) { 102 {label: 'setValueCurve', description: 'Cancel setValueCurveAtTime'},
103 // Initialize values to 0. 103 function(task, should) {
104 g[0].gain.setValueAtTime(0, 0); 104 // Cancel a setValueCurve event.
105 g[1].gain.setValueAtTime(0, 0); 105 cancelTest(should, function(g, v0, t0, cancelTime) {
106 // Schedule a short linear ramp to start things off. 106 // Initialize values to 0.
107 g[0].gain.linearRampToValueAtTime(v0, t0); 107 g[0].gain.setValueAtTime(0, 0);
108 g[1].gain.linearRampToValueAtTime(v0, t0); 108 g[1].gain.setValueAtTime(0, 0);
109 109 // Schedule a short linear ramp to start things off.
110 // After the linear ramp, schedule a setValuesCurve. (This is the 110 g[0].gain.linearRampToValueAtTime(v0, t0);
111 // event that will be cancelled.) 111 g[1].gain.linearRampToValueAtTime(v0, t0);
112 let v1 = 0; 112
113 let duration = renderDuration - t0; 113 // After the linear ramp, schedule a setValuesCurve. (This is the
114 114 // event that will be cancelled.)
115 // For simplicity, a 2-point curve so we get a linear interpolated res ult. 115 let v1 = 0;
116 let curve = Float32Array.from([v0, 0]); 116 let duration = renderDuration - t0;
117 117
118 g[0].gain.setValueCurveAtTime(curve, t0, duration); 118 // For simplicity, a 2-point curve so we get a linear interpolated
119 g[1].gain.setValueCurveAtTime(curve, t0, duration); 119 // result.
120 120 let curve = Float32Array.from([v0, 0]);
121 let index = Math.floor((curve.length - 1) / duration * ( 121
122 cancelTime - t0)); 122 g[0].gain.setValueCurveAtTime(curve, t0, duration);
123 123 g[1].gain.setValueCurveAtTime(curve, t0, duration);
124 let curvePointsPerFrame = (curve.length - 1) / duration / 124
125 sampleRate; 125 let index =
126 let virtualIndex = (cancelTime - t0) * sampleRate * 126 Math.floor((curve.length - 1) / duration * (cancelTime - t0));
127 curvePointsPerFrame; 127
128 128 let curvePointsPerFrame =
129 let delta = virtualIndex - index; 129 (curve.length - 1) / duration / sampleRate;
130 expectedConstant = curve[0] + (curve[1] - curve[0]) * delta; 130 let virtualIndex =
131 return { 131 (cancelTime - t0) * sampleRate * curvePointsPerFrame;
132 expectedConstant: expectedConstant, 132
133 autoMessage: "setValueCurveAtTime([" + curve + "], " + t0 + 133 let delta = virtualIndex - index;
134 ", " + duration + 134 expectedConstant = curve[0] + (curve[1] - curve[0]) * delta;
135 ")", 135 return {
136 summary: "setValueCurveAtTime", 136 expectedConstant: expectedConstant,
137 }; 137 autoMessage: 'setValueCurveAtTime([' + curve + '], ' + t0 +
138 }, { 138 ', ' + duration + ')',
139 valueThreshold: 9.5368e-9, 139 summary: 'setValueCurveAtTime',
140 curveThreshold: 0 140 };
141 }).then(task.done.bind(task)); 141 }, {
142 }); 142 valueThreshold: 9.5368e-9,
143 143 curveThreshold: 0
144 audit.define("setValueCurve after end", function (task, should) { 144 }).then(task.done.bind(task));
145 task.describe("Cancel setValueCurveAtTime after the end"); 145 });
146 cancelTest(should, function (g, v0, t0, cancelTime) { 146
147 // Initialize values to 0. 147 audit.define(
148 g[0].gain.setValueAtTime(0, 0); 148 {
149 g[1].gain.setValueAtTime(0, 0); 149 label: 'setValueCurve after end',
150 // Schedule a short linear ramp to start things off. 150 description: 'Cancel setValueCurveAtTime after the end'
151 g[0].gain.linearRampToValueAtTime(v0, t0); 151 },
152 g[1].gain.linearRampToValueAtTime(v0, t0); 152 function(task, should) {
153 153 cancelTest(should, function(g, v0, t0, cancelTime) {
154 // After the linear ramp, schedule a setValuesCurve. (This is the 154 // Initialize values to 0.
155 // event that will be cancelled.) Make sure the curve ends before the 155 g[0].gain.setValueAtTime(0, 0);
156 // cancellation time. 156 g[1].gain.setValueAtTime(0, 0);
157 let v1 = 0; 157 // Schedule a short linear ramp to start things off.
158 let duration = cancelTime - t0 - 0.125; 158 g[0].gain.linearRampToValueAtTime(v0, t0);
159 159 g[1].gain.linearRampToValueAtTime(v0, t0);
160 // For simplicity, a 2-point curve so we get a linear interpolated 160
161 // result. 161 // After the linear ramp, schedule a setValuesCurve. (This is the
162 let curve = Float32Array.from([v0, 0]); 162 // event that will be cancelled.) Make sure the curve ends before
163 163 // the cancellation time.
164 g[0].gain.setValueCurveAtTime(curve, t0, duration); 164 let v1 = 0;
165 g[1].gain.setValueCurveAtTime(curve, t0, duration); 165 let duration = cancelTime - t0 - 0.125;
166 166
167 expectedConstant = curve[1]; 167 // For simplicity, a 2-point curve so we get a linear interpolated
168 return { 168 // result.
169 expectedConstant: expectedConstant, 169 let curve = Float32Array.from([v0, 0]);
170 autoMessage: "setValueCurveAtTime([" + curve + "], " + t0 + 170
171 ", " + duration + 171 g[0].gain.setValueCurveAtTime(curve, t0, duration);
172 ")", 172 g[1].gain.setValueCurveAtTime(curve, t0, duration);
173 summary: "setValueCurveAtTime", 173
174 }; 174 expectedConstant = curve[1];
175 }, { 175 return {
176 valueThreshold: 0, 176 expectedConstant: expectedConstant,
177 curveThreshold: 0 177 autoMessage: 'setValueCurveAtTime([' + curve + '], ' + t0 +
178 }).then(task.done.bind(task)); 178 ', ' + duration + ')',
179 }); 179 summary: 'setValueCurveAtTime',
180 };
181 }, {
182 valueThreshold: 0,
183 curveThreshold: 0
184 }).then(task.done.bind(task));
185 });
180 186
181 // Special case where we schedule a setTarget and there is no earlier 187 // Special case where we schedule a setTarget and there is no earlier
182 // automation event. This tests that we pick up the starting point 188 // automation event. This tests that we pick up the starting point
183 // correctly from the last setting of the AudioParam value attribute. 189 // correctly from the last setting of the AudioParam value attribute.
184 190
185 191
186 audit.define("initial setTarget", function (task, should) { 192 audit.define(
187 task.describe("Cancel with initial setTargetAtTime"); 193 {
188 cancelTest(should, function (g, v0, t0, cancelTime) { 194 label: 'initial setTarget',
189 let v1 = 0; 195 description: 'Cancel with initial setTargetAtTime'
190 let timeConstant = 0.1; 196 },
191 g[0].gain.value = 1; 197 function(task, should) {
192 g[0].gain.setTargetAtTime(v1, t0, timeConstant); 198 cancelTest(should, function(g, v0, t0, cancelTime) {
193 g[1].gain.value = 1; 199 let v1 = 0;
194 g[1].gain.setTargetAtTime(v1, t0, timeConstant); 200 let timeConstant = 0.1;
195 201 g[0].gain.value = 1;
196 let expectedConstant = Math.fround(v1 + (v0 - v1) * Math.exp(- 202 g[0].gain.setTargetAtTime(v1, t0, timeConstant);
197 (cancelTime - t0) / 203 g[1].gain.value = 1;
198 timeConstant)); 204 g[1].gain.setTargetAtTime(v1, t0, timeConstant);
199 205
200 return { 206 let expectedConstant = Math.fround(
201 expectedConstant: expectedConstant, 207 v1 + (v0 - v1) * Math.exp(-(cancelTime - t0) / timeConstant));
202 autoMessage: "setTargetAtTime(" + v1 + ", " + t0 + ", " + 208
203 timeConstant + ")", 209 return {
204 summary: "Initial setTargetAtTime", 210 expectedConstant: expectedConstant,
205 }; 211 autoMessage: 'setTargetAtTime(' + v1 + ', ' + t0 + ', ' +
206 }, { 212 timeConstant + ')',
207 valueThreshold: 1.2320e-6, 213 summary: 'Initial setTargetAtTime',
208 curveThreshold: 0 214 };
209 }).then(task.done.bind(task)); 215 }, {
210 }); 216 valueThreshold: 1.2320e-6,
217 curveThreshold: 0
218 }).then(task.done.bind(task));
219 });
211 220
212 // Test automations scheduled after the call to cancelAndHoldAtTime. 221 // Test automations scheduled after the call to cancelAndHoldAtTime.
213 // Very similar to the above tests, but we also schedule an event after 222 // Very similar to the above tests, but we also schedule an event after
214 // cancelAndHoldAtTime and verify that curve after cancellation has 223 // cancelAndHoldAtTime and verify that curve after cancellation has
215 // the correct values. 224 // the correct values.
216 225
217 audit.define("post cancel: Linear", function (task, should) { 226 audit.define(
218 // Run the cancel test using a linearRamp as the event to be cancelled. 227 {
219 // Then schedule another linear ramp after the cancellation. 228 label: 'post cancel: Linear',
220 task.describe("LinearRamp after cancelling"); 229 description: 'LinearRamp after cancelling'
221 cancelTest(should, linearRampTest( 230 },
222 "Post cancellation linearRampToValueAtTime"), { 231 function(task, should) {
223 valueThreshold: 8.3998e-5, 232 // Run the cancel test using a linearRamp as the event to be
224 curveThreshold: 0 233 // cancelled. Then schedule another linear ramp after the
225 }, function (g, cancelTime, expectedConstant) { 234 // cancellation.
226 // Schedule the linear ramp on g[0], and do the same for g[2], using t he starting point 235 cancelTest(
227 // given by expectedConstant. 236 should,
228 let v2 = 2; 237 linearRampTest('Post cancellation linearRampToValueAtTime'),
229 let t2 = cancelTime + 0.125; 238 {valueThreshold: 8.3998e-5, curveThreshold: 0},
230 g[0].gain.linearRampToValueAtTime(v2, t2); 239 function(g, cancelTime, expectedConstant) {
231 g[2].gain.setValueAtTime(expectedConstant, cancelTime); 240 // Schedule the linear ramp on g[0], and do the same for g[2],
232 g[2].gain.linearRampToValueAtTime(v2, t2); 241 // using the starting point given by expectedConstant.
233 return { 242 let v2 = 2;
234 constantEndTime: cancelTime, 243 let t2 = cancelTime + 0.125;
235 message: "Post linearRamp(" + v2 + ", " + t2 + ")" 244 g[0].gain.linearRampToValueAtTime(v2, t2);
236 }; 245 g[2].gain.setValueAtTime(expectedConstant, cancelTime);
237 }).then(task.done.bind(task)); 246 g[2].gain.linearRampToValueAtTime(v2, t2);
238 }); 247 return {
239 248 constantEndTime: cancelTime,
240 audit.define("post cancel: Exponential", function (task, should) { 249 message: 'Post linearRamp(' + v2 + ', ' + t2 + ')'
241 task.describe("ExponentialRamp after cancelling"); 250 };
242 // Run the cancel test using a linearRamp as the event to be cancelled. 251 })
243 // Then schedule an exponential ramp after the cancellation. 252 .then(task.done.bind(task));
244 cancelTest(should, linearRampTest( 253 });
245 "Post cancel exponentialRampToValueAtTime"), { 254
246 valueThreshold: 8.3998e-5, 255 audit.define(
247 curveThreshold: 0 256 {
248 }, function (g, cancelTime, expectedConstant) { 257 label: 'post cancel: Exponential',
249 // Schedule the exponential ramp on g[0], and do the same for g[2], 258 description: 'ExponentialRamp after cancelling'
250 // using the starting point given by expectedConstant. 259 },
251 let v2 = 2; 260 function(task, should) {
252 let t2 = cancelTime + 0.125; 261 // Run the cancel test using a linearRamp as the event to be
253 g[0].gain.exponentialRampToValueAtTime(v2, t2); 262 // cancelled. Then schedule an exponential ramp after the
254 g[2].gain.setValueAtTime(expectedConstant, cancelTime); 263 // cancellation.
255 g[2].gain.exponentialRampToValueAtTime(v2, t2); 264 cancelTest(
256 return { 265 should,
257 constantEndTime: cancelTime, 266 linearRampTest('Post cancel exponentialRampToValueAtTime'),
258 message: "Post exponentialRamp(" + v2 + ", " + t2 + ")" 267 {valueThreshold: 8.3998e-5, curveThreshold: 0},
259 }; 268 function(g, cancelTime, expectedConstant) {
260 }).then(task.done.bind(task)); 269 // Schedule the exponential ramp on g[0], and do the same for
261 }); 270 // g[2], using the starting point given by expectedConstant.
262 271 let v2 = 2;
263 audit.define("post cancel: ValueCurve", function (task, should) { 272 let t2 = cancelTime + 0.125;
273 g[0].gain.exponentialRampToValueAtTime(v2, t2);
274 g[2].gain.setValueAtTime(expectedConstant, cancelTime);
275 g[2].gain.exponentialRampToValueAtTime(v2, t2);
276 return {
277 constantEndTime: cancelTime,
278 message: 'Post exponentialRamp(' + v2 + ', ' + t2 + ')'
279 };
280 })
281 .then(task.done.bind(task));
282 });
283
284 audit.define('post cancel: ValueCurve', function(task, should) {
264 // Run the cancel test using a linearRamp as the event to be cancelled. 285 // Run the cancel test using a linearRamp as the event to be cancelled.
265 // Then schedule a setValueCurve after the cancellation. 286 // Then schedule a setValueCurve after the cancellation.
266 cancelTest(should, linearRampTest("Post cancel setValueCurveAtTime"), { 287 cancelTest(
267 valueThreshold: 8.3998e-5, 288 should, linearRampTest('Post cancel setValueCurveAtTime'),
268 curveThreshold: 0 289 {valueThreshold: 8.3998e-5, curveThreshold: 0},
269 }, function (g, cancelTime, expectedConstant) { 290 function(g, cancelTime, expectedConstant) {
270 // Schedule the exponential ramp on g[0], and do the same for g[2], 291 // Schedule the exponential ramp on g[0], and do the same for
271 // using the starting point given by expectedConstant. 292 // g[2], using the starting point given by expectedConstant.
272 let t2 = cancelTime + 0.125; 293 let t2 = cancelTime + 0.125;
273 let duration = 0.125; 294 let duration = 0.125;
274 let curve = Float32Array.from([.125, 2]); 295 let curve = Float32Array.from([.125, 2]);
275 g[0].gain.setValueCurveAtTime(curve, t2, duration); 296 g[0].gain.setValueCurveAtTime(curve, t2, duration);
276 g[2].gain.setValueAtTime(expectedConstant, cancelTime); 297 g[2].gain.setValueAtTime(expectedConstant, cancelTime);
277 g[2].gain.setValueCurveAtTime(curve, t2, duration); 298 g[2].gain.setValueCurveAtTime(curve, t2, duration);
278 return { 299 return {
279 constantEndTime: cancelTime, 300 constantEndTime: cancelTime,
280 message: "Post setValueCurve([" + curve + "], " + t2 + ", " + 301 message: 'Post setValueCurve([' + curve + '], ' + t2 + ', ' +
281 duration + ")", 302 duration + ')',
282 errorThreshold: 8.3998e-5 303 errorThreshold: 8.3998e-5
283 }; 304 };
284 }).then(task.done.bind(task)); 305 })
306 .then(task.done.bind(task));
285 }); 307 });
286 308
287 audit.define("post cancel: setTarget", function (task, should) { 309 audit.define('post cancel: setTarget', function(task, should) {
288 // Run the cancel test using a linearRamp as the event to be cancelled. 310 // Run the cancel test using a linearRamp as the event to be cancelled.
289 // Then schedule a setTarget after the cancellation. 311 // Then schedule a setTarget after the cancellation.
290 cancelTest(should, linearRampTest("Post cancel setTargetAtTime"), { 312 cancelTest(
291 valueThreshold: 8.3998e-5, 313 should, linearRampTest('Post cancel setTargetAtTime'),
292 curveThreshold: 0 314 {valueThreshold: 8.3998e-5, curveThreshold: 0},
293 }, function (g, cancelTime, expectedConstant) { 315 function(g, cancelTime, expectedConstant) {
294 // Schedule the exponential ramp on g[0], and do the same for g[2], 316 // Schedule the exponential ramp on g[0], and do the same for
295 // using the starting point given by expectedConstant. 317 // g[2], using the starting point given by expectedConstant.
296 let v2 = 0.125; 318 let v2 = 0.125;
297 let t2 = cancelTime + 0.125; 319 let t2 = cancelTime + 0.125;
298 let timeConstant = 0.1; 320 let timeConstant = 0.1;
299 g[0].gain.setTargetAtTime(v2, t2, timeConstant); 321 g[0].gain.setTargetAtTime(v2, t2, timeConstant);
300 g[2].gain.setValueAtTime(expectedConstant, cancelTime); 322 g[2].gain.setValueAtTime(expectedConstant, cancelTime);
301 g[2].gain.setTargetAtTime(v2, t2, timeConstant); 323 g[2].gain.setTargetAtTime(v2, t2, timeConstant);
302 return { 324 return {
303 constantEndTime: cancelTime + 0.125, 325 constantEndTime: cancelTime + 0.125,
304 message: "Post setTargetAtTime(" + v2 + ", " + t2 + ", " + 326 message: 'Post setTargetAtTime(' + v2 + ', ' + t2 + ', ' +
305 timeConstant + ")", 327 timeConstant + ')',
306 errorThreshold: 8.4037e-5 328 errorThreshold: 8.4037e-5
307 }; 329 };
308 }).then(task.done.bind(task)); 330 })
331 .then(task.done.bind(task));
309 }); 332 });
310 333
311 audit.define("post cancel: setValue", function (task, should) { 334 audit.define('post cancel: setValue', function(task, should) {
312 // Run the cancel test using a linearRamp as the event to be cancelled. 335 // Run the cancel test using a linearRamp as the event to be cancelled.
313 // Then schedule a setTarget after the cancellation. 336 // Then schedule a setTarget after the cancellation.
314 cancelTest(should, linearRampTest("Post cancel setValueAtTime"), { 337 cancelTest(
315 valueThreshold: 8.3998e-5, 338 should, linearRampTest('Post cancel setValueAtTime'),
316 curveThreshold: 0 339 {valueThreshold: 8.3998e-5, curveThreshold: 0},
317 }, function (g, cancelTime, expectedConstant) { 340 function(g, cancelTime, expectedConstant) {
318 // Schedule the exponential ramp on g[0], and do the same for g[2], 341 // Schedule the exponential ramp on g[0], and do the same for
319 // using the starting point given by expectedConstant. 342 // g[2], using the starting point given by expectedConstant.
320 let v2 = 0.125; 343 let v2 = 0.125;
321 let t2 = cancelTime + 0.125; 344 let t2 = cancelTime + 0.125;
322 g[0].gain.setValueAtTime(v2, t2); 345 g[0].gain.setValueAtTime(v2, t2);
323 g[2].gain.setValueAtTime(expectedConstant, cancelTime); 346 g[2].gain.setValueAtTime(expectedConstant, cancelTime);
324 g[2].gain.setValueAtTime(v2, t2); 347 g[2].gain.setValueAtTime(v2, t2);
325 return { 348 return {
326 constantEndTime: cancelTime + 0.125, 349 constantEndTime: cancelTime + 0.125,
327 message: "Post setValueAtTime(" + v2 + ", " + t2 + ")" 350 message: 'Post setValueAtTime(' + v2 + ', ' + t2 + ')'
328 }; 351 };
329 }).then(task.done.bind(task)); 352 })
353 .then(task.done.bind(task));
330 }); 354 });
331 355
332 audit.run(); 356 audit.run();
333 357
334 // Common function for doing a linearRamp test. This just does a linear 358 // Common function for doing a linearRamp test. This just does a linear
335 // ramp from 0 to v0 at from time 0 to t0. Then another linear ramp is 359 // ramp from 0 to v0 at from time 0 to t0. Then another linear ramp is
336 // scheduled from v0 to 0 from time t0 to t1. This is the ramp that is to 360 // scheduled from v0 to 0 from time t0 to t1. This is the ramp that is to
337 // be cancelled. 361 // be cancelled.
338 function linearRampTest(message) { 362 function linearRampTest(message) {
339 return function (g, v0, t0, cancelTime) { 363 return function(g, v0, t0, cancelTime) {
340 g[0].gain.setValueAtTime(0, 0); 364 g[0].gain.setValueAtTime(0, 0);
341 g[1].gain.setValueAtTime(0, 0); 365 g[1].gain.setValueAtTime(0, 0);
342 g[0].gain.linearRampToValueAtTime(v0, t0); 366 g[0].gain.linearRampToValueAtTime(v0, t0);
343 g[1].gain.linearRampToValueAtTime(v0, t0); 367 g[1].gain.linearRampToValueAtTime(v0, t0);
344 368
345 let v1 = 0; 369 let v1 = 0;
346 let t1 = renderDuration; 370 let t1 = renderDuration;
347 g[0].gain.linearRampToValueAtTime(v1, t1); 371 g[0].gain.linearRampToValueAtTime(v1, t1);
348 g[1].gain.linearRampToValueAtTime(v1, t1); 372 g[1].gain.linearRampToValueAtTime(v1, t1);
349 373
350 expectedConstant = Math.fround(v0 + (v1 - v0) * (cancelTime - t0) / 374 expectedConstant =
351 (t1 - t0)); 375 Math.fround(v0 + (v1 - v0) * (cancelTime - t0) / (t1 - t0));
352 376
353 return { 377 return {
354 expectedConstant: expectedConstant, 378 expectedConstant: expectedConstant,
355 autoMessage: "linearRampToValue(" + v1 + ", " + t1 + ")", 379 autoMessage: 'linearRampToValue(' + v1 + ', ' + t1 + ')',
356 summary: message, 380 summary: message,
357 }; 381 };
358 } 382 }
359 } 383 }
360 384
361 // Run the cancellation test. A set of automations is created and 385 // Run the cancellation test. A set of automations is created and
362 // canceled. 386 // canceled.
363 // 387 //
364 // |testFunction| is a function that generates the automation to be 388 // |testFunction| is a function that generates the automation to be
365 // tested. It is given an array of 3 gain nodes, the value and time of an 389 // tested. It is given an array of 3 gain nodes, the value and time of an
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 should(actual.slice(constantEndFrame), postResult.message) 531 should(actual.slice(constantEndFrame), postResult.message)
508 .beCloseToArray(c2.slice(constantEndFrame), { 532 .beCloseToArray(c2.slice(constantEndFrame), {
509 absoluteThreshold: postResult.errorThreshold || 0 533 absoluteThreshold: postResult.errorThreshold || 0
510 }); 534 });
511 } 535 }
512 }); 536 });
513 } 537 }
514 </script> 538 </script>
515 </body> 539 </body>
516 </html> 540 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698