Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / audioparam-setValueCurve-exceptions.html
blob4ab2a2db4d682fd962c1d45cee163c665fade0ce
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/audio-testing.js"></script>
8 </head>
10 <body>
11 <script>
12 description("Test Exceptions from setValueCurveAtTime");
13 window.jsTestIsAsync = true;
15 var sampleRate = 48000;
16 // Some short duration because we don't need to run the test for very long.
17 var testDurationSec = 0.125;
18 var testDurationFrames = testDurationSec * sampleRate;
20 var audit = Audit.createTaskRunner();
22 audit.defineTask("setValueCurve", function(done) {
23 var success = true;
24 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate);
25 var g = context.createGain();
26 var curve = new Float32Array(2);
28 // Start time and duration for setValueCurveAtTime
29 var curveStartTime = 0.1 * testDurationSec;
30 var duration = 0.1 * testDurationSec;
32 // Some time that is known to during the setValueCurveTime interval.
33 var automationTime = curveStartTime + duration / 2;
35 success = success && Should("setValueCurveAtTime(curve, " + curveStartTime + ", " + duration + ")", function() {
36 g.gain.setValueCurveAtTime(curve, curveStartTime, duration);
37 }).notThrow();
39 success = success && Should("setValueAtTime(1, " + automationTime + ")", function() {
40 g.gain.setValueAtTime(1, automationTime);
41 }).throw("NotSupportedError");
43 success = success && Should("linearRampToValueAtTime(1, " + automationTime + ")", function() {
44 g.gain.linearRampToValueAtTime(1, automationTime);
45 }).throw("NotSupportedError");
47 success = success && Should("exponentialRampToValueAtTime(1, " + automationTime + ")", function() {
48 g.gain.exponentialRampToValueAtTime(1, automationTime);
49 }).throw("NotSupportedError");
51 success = success && Should("setTargetAtTime(1, " + automationTime + ", 1)", function() {
52 g.gain.setTargetAtTime(1, automationTime, 1);
53 }).throw("NotSupportedError");
55 success = success && Should("setValueAtTime(1, " + (curveStartTime + 1.1 * duration) + ")", function() {
56 g.gain.setValueAtTime(1, curveStartTime + 1.1 * duration);
57 }).notThrow();
59 var prefix = "Automation functions overlapping an existing setValueCurveAtTime";
60 if (success)
61 testPassed(prefix + " correctly signaled errors.\n");
62 else
63 testFailed(prefix + " failed to signal errors.\n");
65 done();
66 });
68 audit.defineTask("automations", function (done) {
69 var success = true;
70 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate);
71 var g = context.createGain();
73 var curve = new Float32Array(2);
74 // Start time and duration for setValueCurveAtTime
75 var startTime = 0
76 var timeInterval = testDurationSec / 10;
78 startTime += timeInterval;
79 success = success && Should("linearRampToValueAtTime(1, " + startTime + ")", function () {
80 g.gain.linearRampToValueAtTime(1, startTime);
81 }).notThrow();
83 startTime += timeInterval;
84 success = success && Should("exponentialRampToValueAtTime(1, " + startTime + ")", function () {
85 g.gain.exponentialRampToValueAtTime(1, startTime);
86 }).notThrow();
88 startTime += timeInterval;
89 success = success && Should("setTargetAtTime(1, " + startTime + ", 0.1)", function () {
90 g.gain.setTargetAtTime(1, startTime, 0.1);
91 }).notThrow();
93 startTime += timeInterval;
94 success = success && Should("setValueCurveAtTime(curve, " + startTime + ", 0.1)", function () {
95 g.gain.setValueCurveAtTime(curve, startTime, 0.1);
96 }).notThrow();
98 // Now try to setValueCurve that overlaps each of the above automations
99 startTime = timeInterval / 2;
101 for (var k = 0; k < 4; ++k) {
102 success = success && Should("setValueCurveAtTime(curve, " + startTime + ", 0.01)", function () {
103 g.gain.setValueCurveAtTime(curve, startTime, 0.01);
104 }).throw("NotSupportedError");
105 startTime += timeInterval;
108 var prefix = "setValueCurve overlapping existing automation functions";
109 if (success)
110 testPassed(prefix + " correctly signaled errors.\n");
111 else
112 testFailed(prefix + " failed to signal errors.\n");
114 done();
117 audit.defineTask("start-end", function (done) {
118 var success = true;
119 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate);
120 var g = context.createGain();
121 var curve = new Float32Array(2);
123 // Verify that a setValueCurve can start at the end of an automation.
124 var time = 0;
125 var timeInterval = testDurationSec / 50;
126 success = Should("setValueAtTime(1, " + time + ")", function () {
127 g.gain.setValueAtTime(1, time);
128 }).notThrow();
130 time += timeInterval;
131 success = Should("linearRampToValueAtTime(0, " + time + ")", function () {
132 g.gain.linearRampToValueAtTime(0, time);
133 }).notThrow() && success;
135 // setValueCurve starts at the end of the linear ramp. This should be fine.
136 success = Should("setValueCurveAtTime(..., " + time + ", " + timeInterval + ")", function () {
137 g.gain.setValueCurveAtTime(curve, time, timeInterval);
138 }).notThrow() && success;
140 // exponentialRamp ending one interval past the setValueCurve should be fine.
141 time += 2*timeInterval;
142 success = Should("exponentialRampToValueAtTime(1, " + time + ")", function () {
143 g.gain.exponentialRampToValueAtTime(1, time);
144 }).notThrow() && success;
146 // setValueCurve starts at the end of the exponential ramp. This should be fine.
147 success = Should("setValueCurveAtTime(..., " + time + ", " + timeInterval + ")", function () {
148 g.gain.setValueCurveAtTime(curve, time, timeInterval);
149 }).notThrow() && success;
151 // setValueCurve at the end of the setValueCurve should be fine.
152 time += timeInterval;
153 success = Should("setValueCurveAtTime(..., " + time + ", " + timeInterval + ")", function () {
154 g.gain.setValueCurveAtTime(curve, time, timeInterval);
155 }).notThrow() && success;
157 // setValueAtTime at the end of setValueCurve should be fine.
158 time += timeInterval;
159 success = Should("setValueAtTime(0, " + time + ")", function () {
160 g.gain.setValueAtTime(0, time);
161 }).notThrow() && success;
163 // setValueCurve at the end of setValueAtTime should be fine.
164 success = Should("setValueCurveAtTime(..., " + time + ", " + timeInterval + ")", function () {
165 g.gain.setValueCurveAtTime(curve, time, timeInterval);
166 }).notThrow() && success;
168 // setTarget starting at the end of setValueCurve should be fine.
169 time += timeInterval;
170 success = Should("setTargetAtTime(1, " + time + ", 1)", function () {
171 g.gain.setTargetAtTime(1, time, 1);
172 }).notThrow() && success;
174 var prefix = "setValueCurve with adjoining automation functions";
175 if (success)
176 testPassed(prefix + " allowed as expected.\n");
177 else
178 testFailed(prefix + " unexpectedly signaled errors.\n");
180 done();
183 audit.defineTask("finish", function (done) {
184 finishJSTest();
185 done();
188 audit.runTasks();
189 successfullyParsed = true;
190 </script>
191 </body>
192 </html>