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

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

Issue 2892803002: Fix layout tests to prevent errors from layout-test-tidy (Closed)
Patch Set: Created 3 years, 7 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 <title>Test Exceptions from setValueCurveAtTime</title> 4 <title>Test Exceptions from setValueCurveAtTime</title>
5 <script src="../../resources/testharness.js"></script> 5 <script src="../../resources/testharness.js"></script>
6 <script src="../../resources/testharnessreport.js"></script> 6 <script src="../../resources/testharnessreport.js"></script>
7 <script src="../resources/audit-util.js"></script> 7 <script src="../resources/audit-util.js"></script>
8 <script src="../resources/audit.js"></script> 8 <script src="../resources/audit.js"></script>
9 </head> 9 </head>
10 10
11 <body> 11 <body>
12 <script> 12 <script>
13 13
14 var sampleRate = 48000; 14 let sampleRate = 48000;
15 // Some short duration because we don't need to run the test for very long . 15 // Some short duration because we don't need to run the test for very long .
16 var testDurationSec = 0.125; 16 let testDurationSec = 0.125;
17 var testDurationFrames = testDurationSec * sampleRate; 17 let testDurationFrames = testDurationSec * sampleRate;
18 18
19 var audit = Audit.createTaskRunner(); 19 let audit = Audit.createTaskRunner();
20 20
21 audit.define("setValueCurve", (task, should) => { 21 audit.define("setValueCurve", (task, should) => {
22 var success = true; 22 let success = true;
23 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ; 23 let context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
24 var g = context.createGain(); 24 let g = context.createGain();
25 var curve = new Float32Array(2); 25 let curve = new Float32Array(2);
26 26
27 // Start time and duration for setValueCurveAtTime 27 // Start time and duration for setValueCurveAtTime
28 var curveStartTime = 0.1 * testDurationSec; 28 let curveStartTime = 0.1 * testDurationSec;
29 var duration = 0.1 * testDurationSec; 29 let duration = 0.1 * testDurationSec;
30 30
31 // Some time that is known to during the setValueCurveTime interval. 31 // Some time that is known to during the setValueCurveTime interval.
32 var automationTime = curveStartTime + duration / 2; 32 let automationTime = curveStartTime + duration / 2;
33 33
34 should(() => { 34 should(() => {
35 g.gain.setValueCurveAtTime(curve, curveStartTime, duration); 35 g.gain.setValueCurveAtTime(curve, curveStartTime, duration);
36 }, 36 },
37 "setValueCurveAtTime(curve, " + curveStartTime + ", " + duration + 37 "setValueCurveAtTime(curve, " + curveStartTime + ", " + duration +
38 ")") 38 ")")
39 .notThrow(); 39 .notThrow();
40 40
41 should(function() { 41 should(function() {
42 g.gain.setValueAtTime(1, automationTime); 42 g.gain.setValueAtTime(1, automationTime);
(...skipping 17 matching lines...) Expand all
60 60
61 should(function() { 61 should(function() {
62 g.gain.setValueAtTime(1, curveStartTime + 1.1 * duration); 62 g.gain.setValueAtTime(1, curveStartTime + 1.1 * duration);
63 }, "setValueAtTime(1, " + (curveStartTime + 1.1 * duration) + ")") 63 }, "setValueAtTime(1, " + (curveStartTime + 1.1 * duration) + ")")
64 .notThrow(); 64 .notThrow();
65 65
66 task.done(); 66 task.done();
67 }); 67 });
68 68
69 audit.define("automations", (task, should) => { 69 audit.define("automations", (task, should) => {
70 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ; 70 let context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
71 var g = context.createGain(); 71 let g = context.createGain();
72 72
73 var curve = new Float32Array(2); 73 let curve = new Float32Array(2);
74 // Start time and duration for setValueCurveAtTime 74 // Start time and duration for setValueCurveAtTime
75 var startTime = 0; 75 let startTime = 0;
76 var timeInterval = testDurationSec / 10; 76 let timeInterval = testDurationSec / 10;
77 let time;
Raymond Toy 2017/05/19 13:53:38 This declaration of time is the actual fix, right?
hongchan 2017/05/19 16:15:29 See line 192. You actually create a |time| variabl
77 78
78 startTime += timeInterval; 79 startTime += timeInterval;
79 should(() => { 80 should(() => {
80 g.gain.linearRampToValueAtTime(1, startTime); 81 g.gain.linearRampToValueAtTime(1, startTime);
81 }, "linearRampToValueAtTime(1, " + startTime + ")").notThrow(); 82 }, "linearRampToValueAtTime(1, " + startTime + ")").notThrow();
82 83
83 startTime += timeInterval; 84 startTime += timeInterval;
84 should(() => { 85 should(() => {
85 g.gain.exponentialRampToValueAtTime(1, startTime); 86 g.gain.exponentialRampToValueAtTime(1, startTime);
86 }, "exponentialRampToValueAtTime(1, " + startTime + ")").notThrow(); 87 }, "exponentialRampToValueAtTime(1, " + startTime + ")").notThrow();
87 88
88 startTime += timeInterval; 89 startTime += timeInterval;
89 should(() => { 90 should(() => {
90 g.gain.setTargetAtTime(1, startTime, 0.1); 91 g.gain.setTargetAtTime(1, startTime, 0.1);
91 }, "setTargetAtTime(1, " + startTime + ", 0.1)").notThrow(); 92 }, "setTargetAtTime(1, " + startTime + ", 0.1)").notThrow();
92 93
93 startTime += timeInterval; 94 startTime += timeInterval;
94 should(() => { 95 should(() => {
95 g.gain.setValueCurveAtTime(curve, startTime, 0.1); 96 g.gain.setValueCurveAtTime(curve, startTime, 0.1);
96 }, "setValueCurveAtTime(curve, " + startTime + ", 0.1)").notThrow(); 97 }, "setValueCurveAtTime(curve, " + startTime + ", 0.1)").notThrow();
97 98
98 // Now try to setValueCurve that overlaps each of the above automations 99 // Now try to setValueCurve that overlaps each of the above automations
99 startTime = timeInterval / 2; 100 startTime = timeInterval / 2;
100 101
101 for (var k = 0; k < 4; ++k) { 102 for (let k = 0; k < 4; ++k) {
102 var time = startTime + timeInterval * k; 103 time = startTime + timeInterval * k;
103 should(() => { 104 should(() => {
104 g.gain.setValueCurveAtTime(curve, time, 0.01); 105 g.gain.setValueCurveAtTime(curve, time, 0.01);
105 }, 106 },
106 "setValueCurveAtTime(curve, " + time + ", 0.01)") 107 "setValueCurveAtTime(curve, " + time + ", 0.01)")
107 .throw("NotSupportedError"); 108 .throw("NotSupportedError");
108 } 109 }
109 110
110 // Elements of setValueCurve should be finite. 111 // Elements of setValueCurve should be finite.
111 should(() => { 112 should(() => {
112 g.gain.setValueCurveAtTime(Float32Array.from([NaN, NaN]), time, 113 g.gain.setValueCurveAtTime(Float32Array.from([NaN, NaN]), time,
113 0.01); 114 0.01);
114 }, 115 },
115 "setValueCurveAtTime([NaN, NaN], " + time + ", 0.01)") 116 "setValueCurveAtTime([NaN, NaN], " + time + ", 0.01)")
116 .throw("TypeError"); 117 .throw("TypeError");
117 118
118 should(() => { 119 should(() => {
119 g.gain.setValueCurveAtTime(Float32Array.from([1, Infinity]), time, 120 g.gain.setValueCurveAtTime(Float32Array.from([1, Infinity]), time,
120 0.01); 121 0.01);
121 }, 122 },
122 "setValueCurveAtTime([1, Infinity], " + time + ", 0.01)") 123 "setValueCurveAtTime([1, Infinity], " + time + ", 0.01)")
123 .throw("TypeError"); 124 .throw("TypeError");
124 125
125 var d = context.createDelay(); 126 let d = context.createDelay();
126 // Check that we get warnings for out-of-range values and also throw for 127 // Check that we get warnings for out-of-range values and also throw for
127 // non-finite values. 128 // non-finite values.
128 should(() => { 129 should(() => {
129 d.delayTime.setValueCurveAtTime(Float32Array.from([1, 5]), time, 130 d.delayTime.setValueCurveAtTime(Float32Array.from([1, 5]), time,
130 0.01); 131 0.01);
131 }, 132 },
132 "delayTime.setValueCurveAtTime([1, 5], " + time + ", 0.01)") 133 "delayTime.setValueCurveAtTime([1, 5], " + time + ", 0.01)")
133 .notThrow(); 134 .notThrow();
134 135
135 should(() => { 136 should(() => {
136 d.delayTime.setValueCurveAtTime(Float32Array.from([1, 5, Infinity] ), 137 d.delayTime.setValueCurveAtTime(Float32Array.from([1, 5, Infinity] ),
137 time, 0.01); 138 time, 0.01);
138 }, 139 },
139 "delayTime.setValueCurveAtTime([1, 5, Infinity], " + time + 140 "delayTime.setValueCurveAtTime([1, 5, Infinity], " + time +
140 ", 0.01)") 141 ", 0.01)")
141 .throw("TypeError"); 142 .throw("TypeError");
142 143
143 // One last test that prints out lots of digits for the time. 144 // One last test that prints out lots of digits for the time.
144 var time = Math.PI / 100; 145 time = Math.PI / 100;
145 should(() => { 146 should(() => {
146 g.gain.setValueCurveAtTime(curve, time, 0.01); 147 g.gain.setValueCurveAtTime(curve, time, 0.01);
147 }, "setValueCurveAtTime(curve, " + time + ", 0.01)").throw("NotSupported Error"); 148 }, "setValueCurveAtTime(curve, " + time + ", 0.01)").throw("NotSupported Error");
148 149
149 task.done(); 150 task.done();
150 }); 151 });
151 152
152 audit.define("catch-exception", (task, should) => { 153 audit.define("catch-exception", (task, should) => {
153 // Verify that the curve isn't inserted into the time line even if we ca tch the exception. 154 // Verify that the curve isn't inserted into the time line even if we ca tch the exception.
154 var success = true; 155 let success = true;
155 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ; 156 let context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
156 var gain = context.createGain(); 157 let gain = context.createGain();
157 var source = context.createBufferSource(); 158 let source = context.createBufferSource();
158 var buffer = context.createBuffer(1, 1, context.sampleRate); 159 let buffer = context.createBuffer(1, 1, context.sampleRate);
159 buffer.getChannelData(0)[0] = 1; 160 buffer.getChannelData(0)[0] = 1;
160 source.buffer = buffer; 161 source.buffer = buffer;
161 source.loop = true; 162 source.loop = true;
162 163
163 source.connect(gain); 164 source.connect(gain);
164 gain.connect(context.destination); 165 gain.connect(context.destination);
165 166
166 gain.gain.setValueAtTime(1, 0); 167 gain.gain.setValueAtTime(1, 0);
167 try { 168 try {
168 // The value curve has an invalid element. This automation shouldn't b e inserted into the 169 // The value curve has an invalid element. This automation shouldn't b e inserted into the
169 // timeline at all. 170 // timeline at all.
170 gain.gain.setValueCurveAtTime(Float32Array.from([0, NaN]), 128 / conte xt.sampleRate, .5); 171 gain.gain.setValueCurveAtTime(Float32Array.from([0, NaN]), 128 / conte xt.sampleRate, .5);
171 } catch (e) { 172 } catch (e) {
172 }; 173 };
173 source.start(); 174 source.start();
174 175
175 context.startRendering().then(function (resultBuffer) { 176 context.startRendering().then(function (resultBuffer) {
176 // Since the setValueCurve wasn't inserted, the output should be exact ly 1 for the entire 177 // Since the setValueCurve wasn't inserted, the output should be exact ly 1 for the entire
177 // duration. 178 // duration.
178 should(resultBuffer.getChannelData(0), 179 should(resultBuffer.getChannelData(0),
179 "Handled setValueCurve exception so output") 180 "Handled setValueCurve exception so output")
180 .beConstantValueOf(1); 181 .beConstantValueOf(1);
181 182
182 }).then(() => task.done()); 183 }).then(() => task.done());
183 }); 184 });
184 185
185 audit.define("start-end", (task, should) => { 186 audit.define("start-end", (task, should) => {
186 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ; 187 let context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
187 var g = context.createGain(); 188 let g = context.createGain();
188 var curve = new Float32Array(2); 189 let curve = new Float32Array(2);
189 190
190 // Verify that a setValueCurve can start at the end of an automation. 191 // Verify that a setValueCurve can start at the end of an automation.
191 var time = 0; 192 let time = 0;
192 var timeInterval = testDurationSec / 50; 193 let timeInterval = testDurationSec / 50;
193 should(() => { 194 should(() => {
194 g.gain.setValueAtTime(1, time); 195 g.gain.setValueAtTime(1, time);
195 }, "setValueAtTime(1, " + time + ")").notThrow(); 196 }, "setValueAtTime(1, " + time + ")").notThrow();
196 197
197 time += timeInterval; 198 time += timeInterval;
198 should(() => { 199 should(() => {
199 g.gain.linearRampToValueAtTime(0, time); 200 g.gain.linearRampToValueAtTime(0, time);
200 }, "linearRampToValueAtTime(0, " + time + ")").notThrow(); 201 }, "linearRampToValueAtTime(0, " + time + ")").notThrow();
201 202
202 // setValueCurve starts at the end of the linear ramp. This should be fi ne. 203 // setValueCurve starts at the end of the linear ramp. This should be fi ne.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 // setTarget starting at the end of setValueCurve should be fine. 244 // setTarget starting at the end of setValueCurve should be fine.
244 time += timeInterval; 245 time += timeInterval;
245 should(() => { 246 should(() => {
246 g.gain.setTargetAtTime(1, time, 1); 247 g.gain.setTargetAtTime(1, time, 1);
247 }, "setTargetAtTime(1, " + time + ", 1)").notThrow(); 248 }, "setTargetAtTime(1, " + time + ", 1)").notThrow();
248 249
249 task.done(); 250 task.done();
250 }); 251 });
251 252
252 audit.define("curve lengths", (task, should) => { 253 audit.define("curve lengths", (task, should) => {
253 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ; 254 let context = new OfflineAudioContext(1, testDurationFrames, sampleRate) ;
254 var g = context.createGain(); 255 let g = context.createGain();
255 var time = 0; 256 let time = 0;
256 257
257 // Check for invalid curve lengths 258 // Check for invalid curve lengths
258 should(() => { 259 should(() => {
259 g.gain.setValueCurveAtTime(Float32Array.from([]), time, 0.01); 260 g.gain.setValueCurveAtTime(Float32Array.from([]), time, 0.01);
260 }, 261 },
261 "setValueCurveAtTime([], " + time + ", 0.01)") 262 "setValueCurveAtTime([], " + time + ", 0.01)")
262 .throw("InvalidStateError"); 263 .throw("InvalidStateError");
263 264
264 should(() => { 265 should(() => {
265 g.gain.setValueCurveAtTime(Float32Array.from([1]), time, 0.01); 266 g.gain.setValueCurveAtTime(Float32Array.from([1]), time, 0.01);
(...skipping 14 matching lines...) Expand all
280 </html> 281 </html>
281 282
282 283
283 284
284 285
285 286
286 287
287 288
288 289
289 290
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698