| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 | 3 |
| 4 <head> | 4 <head> |
| 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/audio-testing.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 renderQuantum = 128; | 14 var renderQuantum = 128; |
| 15 | 15 |
| 16 var sampleRate = 44100; | 16 var sampleRate = 44100; |
| 17 var renderDuration = 0.5; | 17 var renderDuration = 0.5; |
| 18 var disconnectTime = 0.5 * renderDuration; | 18 var disconnectTime = 0.5 * renderDuration; |
| 19 | 19 |
| 20 var audit = Audit.createTaskRunner(); | 20 var audit = Audit.createTaskRunner(); |
| 21 | 21 |
| 22 // Calculate the index for disconnection. | 22 // Calculate the index for disconnection. |
| 23 function getDisconnectIndex(disconnectTime) { | 23 function getDisconnectIndex(disconnectTime) { |
| 24 var disconnectIndex = disconnectTime * sampleRate; | 24 var disconnectIndex = disconnectTime * sampleRate; |
| 25 return disconnectIndex -= (disconnectIndex) % renderQuantum; | 25 return disconnectIndex -= (disconnectIndex) % renderQuantum; |
| 26 } | 26 } |
| 27 | 27 |
| 28 // Get the index of value change. | 28 // Get the index of value change. |
| 29 function getValueChangeIndex(array, targetValue) { | 29 function getValueChangeIndex(array, targetValue) { |
| 30 return array.findIndex(function (element, index) { | 30 return array.findIndex(function (element, index) { |
| 31 if (element === targetValue) | 31 if (element === targetValue) |
| 32 return true; | 32 return true; |
| 33 }); | 33 }); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Task 1: test disconnect(AudioParam) method. | 36 // Task 1: test disconnect(AudioParam) method. |
| 37 audit.defineTask('disconnect(AudioParam)', function (done) { | 37 audit.define('disconnect(AudioParam)', (task, should) => { |
| 38 | 38 |
| 39 // Creates a buffer source with value [1] and then connect it to two gain | 39 // Creates a buffer source with value [1] and then connect it to two gain |
| 40 // nodes in series. The output of the buffer source is lowered by half | 40 // nodes in series. The output of the buffer source is lowered by half |
| 41 // (* 0.5) and then connected to two |.gain| AudioParams in each gain node
. | 41 // (* 0.5) and then connected to two |.gain| AudioParams in each gain node
. |
| 42 // | 42 // |
| 43 // (1) bufferSource => gain1 => gain2 | 43 // (1) bufferSource => gain1 => gain2 |
| 44 // (2) bufferSource => half => gain1.gain | 44 // (2) bufferSource => half => gain1.gain |
| 45 // (3) half => gain2.gain | 45 // (3) half => gain2.gain |
| 46 // | 46 // |
| 47 // This graph should produce the output of 2.25 (= 1 * 1.5 * 1.5). After | 47 // This graph should produce the output of 2.25 (= 1 * 1.5 * 1.5). After |
| (...skipping 27 matching lines...) Expand all Loading... |
| 75 half.disconnect(gain2.gain); | 75 half.disconnect(gain2.gain); |
| 76 context.resume(); | 76 context.resume(); |
| 77 }); | 77 }); |
| 78 | 78 |
| 79 context.startRendering().then(function (buffer) { | 79 context.startRendering().then(function (buffer) { |
| 80 var channelData = buffer.getChannelData(0); | 80 var channelData = buffer.getChannelData(0); |
| 81 var disconnectIndex = getDisconnectIndex(disconnectTime); | 81 var disconnectIndex = getDisconnectIndex(disconnectTime); |
| 82 var valueChangeIndex = getValueChangeIndex(channelData, 1.5); | 82 var valueChangeIndex = getValueChangeIndex(channelData, 1.5); |
| 83 | 83 |
| 84 // Expected values are: 1 * 1.5 * 1.5 -> 1 * 1.5 = [2.25, 1.5] | 84 // Expected values are: 1 * 1.5 * 1.5 -> 1 * 1.5 = [2.25, 1.5] |
| 85 Should('Channel #0', channelData).containValues([2.25, 1.5]); | 85 should(channelData, 'Channel #0').containValues([2.25, 1.5]); |
| 86 Should('The index of value change', valueChangeIndex) | 86 should(valueChangeIndex, 'The index of value change') |
| 87 .beEqualTo(disconnectIndex); | 87 .beEqualTo(disconnectIndex); |
| 88 | 88 |
| 89 }).then(done); | 89 }).then(() => task.done()); |
| 90 }); | 90 }); |
| 91 | 91 |
| 92 // Task 2: test disconnect(AudioParam, output) method. | 92 // Task 2: test disconnect(AudioParam, output) method. |
| 93 audit.defineTask('disconnect(AudioParam, output)', function (done) { | 93 audit.define('disconnect(AudioParam, output)', (task, should) => { |
| 94 | 94 |
| 95 // Create a 2-channel buffer source with [1, 2] in each channel and | 95 // Create a 2-channel buffer source with [1, 2] in each channel and |
| 96 // make a serial connection through gain1 and gain 2. The make the buffer | 96 // make a serial connection through gain1 and gain 2. The make the buffer |
| 97 // source half with a gain node and connect it to a 2-output splitter. | 97 // source half with a gain node and connect it to a 2-output splitter. |
| 98 // Connect each output to 2 gain AudioParams respectively. | 98 // Connect each output to 2 gain AudioParams respectively. |
| 99 // | 99 // |
| 100 // (1) bufferSource => gain1 => gain2 | 100 // (1) bufferSource => gain1 => gain2 |
| 101 // (2) bufferSource => half => splitter(2) | 101 // (2) bufferSource => half => splitter(2) |
| 102 // (3) splitter#0 => gain1.gain | 102 // (3) splitter#0 => gain1.gain |
| 103 // (4) splitter#1 => gain2.gain | 103 // (4) splitter#1 => gain2.gain |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 context.startRendering().then(function (buffer) { | 143 context.startRendering().then(function (buffer) { |
| 144 var channelData0 = buffer.getChannelData(0); | 144 var channelData0 = buffer.getChannelData(0); |
| 145 var channelData1 = buffer.getChannelData(1); | 145 var channelData1 = buffer.getChannelData(1); |
| 146 | 146 |
| 147 var disconnectIndex = getDisconnectIndex(disconnectTime); | 147 var disconnectIndex = getDisconnectIndex(disconnectTime); |
| 148 var valueChangeIndexCh0 = getValueChangeIndex(channelData0, 1.5); | 148 var valueChangeIndexCh0 = getValueChangeIndex(channelData0, 1.5); |
| 149 var valueChangeIndexCh1 = getValueChangeIndex(channelData1, 3); | 149 var valueChangeIndexCh1 = getValueChangeIndex(channelData1, 3); |
| 150 | 150 |
| 151 // Expected values are: 1 * 1.5 * 2 -> 1 * 1.5 = [3, 1.5] | 151 // Expected values are: 1 * 1.5 * 2 -> 1 * 1.5 = [3, 1.5] |
| 152 Should('Channel #0', channelData0).containValues([3, 1.5]); | 152 should(channelData0, 'Channel #0').containValues([3, 1.5]); |
| 153 Should('The index of value change in channel #0', valueChangeIndexCh0) | 153 should(valueChangeIndexCh0, 'The index of value change in channel #0') |
| 154 .beEqualTo(disconnectIndex); | 154 .beEqualTo(disconnectIndex); |
| 155 | 155 |
| 156 // Expected values are: 2 * 1.5 * 2 -> 2 * 1.5 = [6, 3] | 156 // Expected values are: 2 * 1.5 * 2 -> 2 * 1.5 = [6, 3] |
| 157 Should('Channel #1', channelData1).containValues([6, 3]); | 157 should(channelData1, 'Channel #1').containValues([6, 3]); |
| 158 Should('The index of value change in channel #1', valueChangeIndexCh1) | 158 should(valueChangeIndexCh1, 'The index of value change in channel #1') |
| 159 .beEqualTo(disconnectIndex); | 159 .beEqualTo(disconnectIndex); |
| 160 | 160 |
| 161 }).then(done); | 161 }).then(() => task.done()); |
| 162 }); | 162 }); |
| 163 | 163 |
| 164 // Task 3: exception checks. | 164 // Task 3: exception checks. |
| 165 audit.defineTask('exceptions', function (done) { | 165 audit.define('exceptions', (task, should) => { |
| 166 var context = new AudioContext(); | 166 var context = new AudioContext(); |
| 167 var gain1 = context.createGain(); | 167 var gain1 = context.createGain(); |
| 168 var splitter = context.createChannelSplitter(2); | 168 var splitter = context.createChannelSplitter(2); |
| 169 var gain2 = context.createGain(); | 169 var gain2 = context.createGain(); |
| 170 var gain3 = context.createGain(); | 170 var gain3 = context.createGain(); |
| 171 | 171 |
| 172 // Connect a splitter to gain nodes and merger so we can test the possible | 172 // Connect a splitter to gain nodes and merger so we can test the possible |
| 173 // ways of disconnecting the nodes to verify that appropriate exceptions | 173 // ways of disconnecting the nodes to verify that appropriate exceptions |
| 174 // are thrown. | 174 // are thrown. |
| 175 gain1.connect(splitter); | 175 gain1.connect(splitter); |
| 176 splitter.connect(gain2.gain, 0); | 176 splitter.connect(gain2.gain, 0); |
| 177 splitter.connect(gain3.gain, 1); | 177 splitter.connect(gain3.gain, 1); |
| 178 gain2.connect(gain3); | 178 gain2.connect(gain3); |
| 179 gain3.connect(context.destination); | 179 gain3.connect(context.destination); |
| 180 | 180 |
| 181 // gain1 is not connected to gain3.gain. Exception should be thrown. | 181 // gain1 is not connected to gain3.gain. Exception should be thrown. |
| 182 Should('gain1.disconnect(gain3.gain)', function () { | 182 should(function () { |
| 183 gain1.disconnect(gain3.gain); | 183 gain1.disconnect(gain3.gain); |
| 184 }).throw('InvalidAccessError'); | 184 }, 'gain1.disconnect(gain3.gain)').throw('InvalidAccessError'); |
| 185 | 185 |
| 186 // When the output index is good but the destination is invalid. | 186 // When the output index is good but the destination is invalid. |
| 187 Should('splitter.disconnect(gain1.gain, 1)', function () { | 187 should(function () { |
| 188 splitter.disconnect(gain1.gain, 1); | 188 splitter.disconnect(gain1.gain, 1); |
| 189 }).throw('InvalidAccessError'); | 189 }, 'splitter.disconnect(gain1.gain, 1)').throw('InvalidAccessError'); |
| 190 | 190 |
| 191 // When both arguments are wrong, throw IndexSizeError first. | 191 // When both arguments are wrong, throw IndexSizeError first. |
| 192 Should('splitter.disconnect(gain1.gain, 2)', function () { | 192 should(function () { |
| 193 splitter.disconnect(gain1.gain, 2); | 193 splitter.disconnect(gain1.gain, 2); |
| 194 }).throw('IndexSizeError'); | 194 }, 'splitter.disconnect(gain1.gain, 2)').throw('IndexSizeError'); |
| 195 | 195 |
| 196 done(); | 196 task.done(); |
| 197 }); | 197 }); |
| 198 | 198 |
| 199 audit.defineTask('finish', function (done) { | 199 audit.run(); |
| 200 done(); | |
| 201 }); | |
| 202 | |
| 203 audit.runTasks( | |
| 204 'disconnect(AudioParam)', | |
| 205 'disconnect(AudioParam, output)', | |
| 206 'exceptions', | |
| 207 'finish' | |
| 208 ); | |
| 209 | |
| 210 successfullyParsed = true; | |
| 211 </script> | 200 </script> |
| 212 </body> | 201 </body> |
| 213 | 202 |
| 214 </html> | 203 </html> |
| OLD | NEW |