Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 | |
| 4 <head> | |
| 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> | |
| 9 | |
| 10 <body> | |
| 11 <script> | |
| 12 description('Test disconnect() method on AudioNode destination.'); | |
| 13 window.jsTestIsAsync = true; | |
| 14 | |
| 15 var audit = Audit.createTaskRunner(); | |
| 16 | |
| 17 // Task 1: test disconnect() method. | |
| 18 audit.defineTask('disconnect()', function (done) { | |
| 19 | |
| 20 // Create fan-out connections from a source node to multiple gain nodes. | |
| 21 // Then test if disconnecting all the connections works. | |
|
Raymond Toy
2015/02/12 19:45:52
This still doesn't explain the test to me. I had t
hongchan
2015/02/13 01:16:56
Thanks. Done.
| |
| 22 var context = new OfflineAudioContext(1, 128, 44100); | |
| 23 var source = context.createBufferSource(); | |
| 24 var buffer1ch = createTestingBuffer(context, 1, 128); | |
| 25 var gain1 = context.createGain(); | |
| 26 var gain2 = context.createGain(); | |
| 27 var gain3 = context.createGain(); | |
| 28 | |
| 29 source.buffer = buffer1ch; | |
| 30 | |
| 31 source.connect(gain1); | |
| 32 source.connect(gain2); | |
| 33 source.connect(gain3); | |
| 34 gain1.connect(context.destination); | |
| 35 gain2.connect(context.destination); | |
| 36 gain3.connect(context.destination); | |
| 37 source.start(); | |
| 38 | |
| 39 // This disconnects everything. | |
| 40 source.disconnect(); | |
| 41 | |
| 42 context.startRendering().then(function (buffer) { | |
| 43 var channelData = buffer.getChannelData(0); | |
| 44 | |
| 45 // With everything disconnected, the result should be zero. | |
| 46 Should.haveValueInChannel(0, channelData); | |
| 47 | |
| 48 }).then(done); | |
| 49 }); | |
| 50 | |
| 51 // Task 2: test disconnect(output) method. | |
| 52 audit.defineTask('disconnect(output)', function (done) { | |
| 53 | |
| 54 // Create multiple connections from each output of a ChannelSplitter | |
| 55 // to a gain node. Then test if disconnecting a single output of splitter | |
| 56 // works correctly. | |
|
Raymond Toy
2015/02/12 19:45:52
"works correctly" is too vague. Say "is actually
hongchan
2015/02/13 01:16:56
Done.
| |
| 57 var context = new OfflineAudioContext(1, 128, 44100); | |
| 58 var source = context.createBufferSource(); | |
| 59 var buffer3ch = createTestingBuffer(context, 3, 128); | |
|
Raymond Toy
2015/02/12 19:45:53
Can createTestingBuffer be renamed to createTestin
hongchan
2015/02/13 01:16:56
Done.
| |
| 60 var splitter = context.createChannelSplitter(3); | |
| 61 var sum = context.createGain(); | |
| 62 | |
| 63 source.buffer = buffer3ch; | |
| 64 | |
| 65 source.connect(splitter); | |
| 66 splitter.connect(sum, 0); | |
| 67 splitter.connect(sum, 1); | |
| 68 splitter.connect(sum, 2); | |
| 69 sum.connect(context.destination); | |
| 70 source.start(); | |
| 71 | |
| 72 // This disconnects the second output. | |
| 73 splitter.disconnect(1); | |
| 74 | |
| 75 // There is no output #3. Exception should be thrown. | |
| 76 Should.throwWithType('IndexSizeError', function () { | |
| 77 splitter.disconnect(3); | |
| 78 }); | |
| 79 | |
| 80 // Disconnecting the output already disconnected should not throw. | |
| 81 Should.notThrow(function () { | |
| 82 splitter.disconnect(1); | |
| 83 }); | |
|
Raymond Toy
2015/02/12 19:45:52
Can these exception tests be put in a separate tes
hongchan
2015/02/13 01:16:56
Moving all exception checks to dom-exception.html.
| |
| 84 | |
| 85 context.startRendering().then(function (buffer) { | |
|
Raymond Toy
2015/02/12 19:45:53
I don't know what the actual style should be, but
hongchan
2015/02/13 01:16:56
Hmm. I am following the style from various JS proj
| |
| 86 var channelData = buffer.getChannelData(0); | |
| 87 | |
| 88 // The rendered channel should contain 4. (= 1 + 0 + 3) | |
| 89 Should.haveValueInChannel(4, channelData); | |
| 90 | |
| 91 }).then(done); | |
| 92 }); | |
| 93 | |
| 94 // Task 3: test disconnect(AudioNode) method. | |
| 95 audit.defineTask('disconnect(AudioNode)', function (done) { | |
| 96 | |
| 97 // Connect a source to multiple gain nodes. Then test if disconnecting a | |
| 98 // single destination selectively works correctly. | |
| 99 var context = new OfflineAudioContext(1, 128, 44100); | |
| 100 var source = context.createBufferSource(); | |
| 101 var buffer1ch = createTestingBuffer(context, 1, 128); | |
| 102 var gain1 = context.createGain(); | |
| 103 var gain2 = context.createGain(); | |
| 104 var gain3 = context.createGain(); | |
| 105 var orphan = context.createGain(); | |
| 106 | |
| 107 source.buffer = buffer1ch; | |
| 108 | |
| 109 source.connect(gain1); | |
| 110 source.connect(gain2); | |
| 111 source.connect(gain3); | |
| 112 gain1.connect(context.destination); | |
| 113 gain2.connect(context.destination); | |
| 114 gain3.connect(context.destination); | |
| 115 source.start(); | |
| 116 | |
| 117 source.disconnect(gain2); | |
| 118 | |
| 119 // gain2 is already disconnected. Exception should be thrown. | |
| 120 Should.throwWithType('InvalidAccessError', function () { | |
| 121 gain1.disconnect(gain2); | |
| 122 }); | |
| 123 | |
| 124 // gain1 and orphan are not connected. Exception should not be thrown. | |
| 125 Should.throwWithType('InvalidAccessError', function () { | |
| 126 gain1.disconnect(orphan); | |
| 127 }); | |
|
Raymond Toy
2015/02/12 19:45:53
As above, can these exception tests be moved somew
hongchan
2015/02/13 01:16:57
Done.
| |
| 128 | |
| 129 context.startRendering().then(function (buffer) { | |
| 130 var channelData = buffer.getChannelData(0); | |
| 131 | |
| 132 // The |sum| gain node should produce value 2. (1 + 0 + 1 = 2) | |
| 133 Should.haveValueInChannel(2, channelData); | |
| 134 | |
| 135 }).then(done); | |
| 136 }); | |
| 137 | |
| 138 // Task 4: test disconnect(AudioNode, output) method. | |
| 139 audit.defineTask('disconnect(AudioNode, output)', function (done) { | |
| 140 | |
| 141 // Connect a 2-channel buffer [1, 2] to a ChannelSplitter, then connect | |
|
Raymond Toy
2015/02/12 19:45:53
What does the notation [1, 2] mean?
hongchan
2015/02/13 01:16:56
They are constant values for each channel. I thoug
| |
| 142 // the splitter to 2 gain nodes as shown below: | |
| 143 // (1) splitter#0 => gain1 | |
| 144 // (2) splitter#0 => gain2 | |
| 145 // (3) splitter#1 => gain2 | |
| 146 // Then disconnect (2) and verify if the selective disconnection on a | |
| 147 // specified output of the destination node works correctly. | |
| 148 var context = new OfflineAudioContext(1, 128, 44100); | |
| 149 var source = context.createBufferSource(); | |
| 150 var buffer2ch = createTestingBuffer(context, 2, 128); | |
| 151 var splitter = context.createChannelSplitter(2); | |
| 152 var gain1 = context.createGain(); | |
| 153 var gain2 = context.createGain(); | |
| 154 var orphan = context.createGain(); | |
| 155 | |
| 156 source.buffer = buffer2ch; | |
| 157 | |
| 158 source.connect(splitter); | |
| 159 splitter.connect(gain1, 0); // gain1 gets [1] | |
| 160 splitter.connect(gain2, 0); // gain2 gets [1 + 2] | |
|
Raymond Toy
2015/02/12 19:45:53
What does gain gets [1] and [1 + 2] mean?
hongchan
2015/02/13 01:16:57
The incoming signal into gain1 is [1] and gain2 is
| |
| 161 splitter.connect(gain2, 1); | |
| 162 gain1.connect(context.destination); | |
| 163 gain2.connect(context.destination); | |
| 164 source.start(); | |
| 165 | |
| 166 splitter.disconnect(gain2, 0); // Now gain2 gets [2] | |
| 167 | |
| 168 // There is no output #2 in the splitter. An exception should be thrown. | |
| 169 Should.throwWithType('IndexSizeError', function () { | |
| 170 splitter.disconnect(gain2, 2); | |
| 171 }); | |
| 172 | |
| 173 // No valid connection to |orphan|. An exception should be thrown. | |
| 174 Should.throwWithType('InvalidAccessError', function () { | |
| 175 splitter.disconnect(orphan, 0); | |
| 176 }); | |
|
Raymond Toy
2015/02/12 19:45:52
Again, move these tests somewhere else.
hongchan
2015/02/13 01:16:56
Done.
hongchan
2015/02/13 01:16:56
Done.
| |
| 177 | |
| 178 context.startRendering().then(function (buffer) { | |
| 179 var channelData0 = buffer.getChannelData(0); | |
| 180 | |
| 181 // The sum of gain1 and gain2 should produce value 3. (= 1 + 2) | |
| 182 Should.haveValueInChannel(3, channelData0); | |
| 183 | |
| 184 }).then(done); | |
| 185 }); | |
| 186 | |
| 187 // Task 5: test disconnect(AudioNode, output, input) method. | |
| 188 audit.defineTask('disconnect(AudioNode, output, input)', function (done) { | |
| 189 | |
| 190 // Create a 3-channel buffer [1, 2, 3] and then pass it through a splitter | |
| 191 // and a merger. Each input/output of the splitter and the merger is | |
| 192 // connected in a sequential order as shown below. | |
| 193 // (1) splitter#0 => merger#0 | |
| 194 // (2) splitter#1 => merger#1 | |
| 195 // (3) splitter#2 => merger#2 | |
| 196 // Then disconnect (3) and verify if each channel contains [1] and [2] | |
| 197 // respectively. | |
| 198 var context = new OfflineAudioContext(3, 128, 44100); | |
| 199 var source = context.createBufferSource(); | |
| 200 var buffer3ch = createTestingBuffer(context, 3, 128); | |
| 201 var splitter = context.createChannelSplitter(3); | |
| 202 var merger = context.createChannelMerger(3); | |
| 203 var orphan = context.createGain(); | |
| 204 | |
| 205 context.destination.channelCount = 3; | |
| 206 context.destination.channelCountMode = 'explicit'; | |
|
Raymond Toy
2015/02/12 19:45:52
Are these actually necessary? The offline context
hongchan
2015/02/13 01:16:56
Removing.
| |
| 207 source.buffer = buffer3ch; | |
| 208 | |
| 209 source.connect(splitter); | |
| 210 splitter.connect(merger, 0, 0); | |
| 211 splitter.connect(merger, 1, 1); | |
| 212 splitter.connect(merger, 2, 2); | |
| 213 merger.connect(context.destination); | |
| 214 source.start(); | |
| 215 | |
| 216 splitter.disconnect(merger, 2, 2); | |
| 217 | |
| 218 // Orphan doesn't have a connection. An exception should be thrown. | |
| 219 Should.throwWithType('InvalidAccessError', function () { | |
| 220 splitter.disconnect(orphan, 0, 0); | |
| 221 }); | |
| 222 | |
| 223 // The output index is out of bound. An exception should be thrown. | |
| 224 Should.throwWithType('IndexSizeError', function () { | |
| 225 splitter.disconnect(merger, 3, 0); | |
| 226 }); | |
| 227 | |
| 228 context.startRendering().then(function (buffer) { | |
| 229 var channelData0 = buffer.getChannelData(0); | |
| 230 var channelData1 = buffer.getChannelData(1); | |
| 231 | |
| 232 // Each channel should have [1] and [2] respectively. | |
| 233 Should.haveValueInChannel(1, channelData0); | |
| 234 Should.haveValueInChannel(2, channelData1); | |
|
Raymond Toy
2015/02/12 19:45:52
What about channel 2? It should be zero, right?
hongchan
2015/02/13 01:16:56
Done.
| |
| 235 | |
| 236 }).then(done); | |
| 237 }); | |
| 238 | |
| 239 audit.defineTask('finish', function (done) { | |
| 240 finishJSTest(); | |
| 241 done(); | |
| 242 }); | |
| 243 | |
| 244 audit.runTasks( | |
| 245 'disconnect()', | |
| 246 'disconnect(output)', | |
| 247 'disconnect(AudioNode)', | |
| 248 'disconnect(AudioNode, output)', | |
| 249 'disconnect(AudioNode, output, input)', | |
| 250 'finish' | |
| 251 ); | |
| 252 | |
| 253 successfullyParsed = true; | |
| 254 </script> | |
| 255 </body> | |
| 256 | |
| 257 </html> | |
| OLD | NEW |