| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 | 2 |
| 3 <html> | 3 <html> |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 8 </head> | 9 </head> |
| 9 | 10 |
| 10 <body> | 11 <body> |
| 11 <div id="description"></div> | 12 <div id="description"></div> |
| 12 <div id="console"></div> | 13 <div id="console"></div> |
| 13 | 14 |
| 14 <script> | 15 <script> |
| 15 description("Basic tests for AudioNode API."); | 16 let audit = Audit.createTaskRunner(); |
| 16 | 17 |
| 17 var context = 0; | 18 let context = 0; |
| 18 var context2 = 0; | 19 let context2 = 0; |
| 19 var context3 = 0; | 20 let context3 = 0; |
| 20 | 21 |
| 21 function runTest() { | 22 audit.define('test', function(task, should) { |
| 22 if (window.testRunner) { | 23 task.describe('Basic tests for AudioNode API.'); |
| 23 testRunner.dumpAsText(); | |
| 24 testRunner.waitUntilDone(); | |
| 25 } | |
| 26 | |
| 27 window.jsTestIsAsync = true; | |
| 28 | 24 |
| 29 context = new AudioContext(); | 25 context = new AudioContext(); |
| 30 window.audioNode = context.createBufferSource(); | 26 window.audioNode = context.createBufferSource(); |
| 31 | 27 |
| 32 // Check input and output numbers of AudioSourceNode. | 28 // Check input and output numbers of AudioSourceNode. |
| 33 if (audioNode.numberOfInputs === 0) | 29 should(audioNode.numberOfInputs, 'AudioBufferSource.numberOfInputs') |
| 34 testPassed("Source AudioNode has no inputs."); | 30 .beEqualTo(0); |
| 35 else | 31 should(audioNode.numberOfOutputs, 'AudioBufferSource.numberOfOutputs') |
| 36 testFailed("Source AudioNode should not have inputs."); | 32 .beEqualTo(1); |
| 37 | |
| 38 if (audioNode.numberOfOutputs === 1) | |
| 39 testPassed("Source AudioNode has one output."); | |
| 40 else | |
| 41 testFailed("Source AudioNode should have one output."); | |
| 42 | 33 |
| 43 // Check input and output numbers of AudioDestinationNode | 34 // Check input and output numbers of AudioDestinationNode |
| 44 if (context.destination.numberOfInputs === 1) | 35 should( |
| 45 testPassed("Destination AudioNode has one input."); | 36 context.destination.numberOfInputs, |
| 46 else | 37 'AudioContext.destination.numberOfInputs') |
| 47 testFailed("Destination AudioNode should have one input."); | 38 .beEqualTo(1); |
| 39 should( |
| 40 context.destination.numberOfOutputs, |
| 41 'AudioContext.destination.numberOfOutputs') |
| 42 .beEqualTo(0); |
| 48 | 43 |
| 49 if (context.destination.numberOfOutputs === 0) | 44 // Try calling connect() method with illegal values. |
| 50 testPassed("Destination AudioNode has no outputs."); | 45 should(() => audioNode.connect(0, 0, 0), 'audioNode.connect(0, 0, 0)') |
| 51 else | 46 .throw('TypeError'); |
| 52 testFailed("Destination AudioNode should have no outputs."); | 47 should(() => audioNode.connect(null, 0, 0), 'audioNode.connect(null, 0, 0)') |
| 48 .throw('TypeError'); |
| 49 should( |
| 50 () => audioNode.connect(context.destination, 5, 0), |
| 51 'audioNode.connect(context.destination, 5, 0)') |
| 52 .throw('IndexSizeError'); |
| 53 should( |
| 54 () => audioNode.connect(context.destination, 0, 5), |
| 55 'audioNode.connect(context.destination, 0, 5)') |
| 56 .throw('IndexSizeError'); |
| 53 | 57 |
| 54 // Try calling connect() method with illegal values. | 58 should( |
| 55 shouldThrow('audioNode.connect(0, 0, 0)'); | 59 () => audioNode.connect(context.destination, 0, 0), |
| 56 shouldThrow('audioNode.connect(null, 0, 0)'); | 60 'audioNode.connect(context.destination, 0, 0)') |
| 57 shouldThrow('audioNode.connect(context.destination, 5, 0)'); | 61 .notThrow(); |
| 58 shouldThrow('audioNode.connect(context.destination, 0, 5)'); | |
| 59 | |
| 60 shouldNotThrow('audioNode.connect(context.destination, 0, 0)'); | |
| 61 | |
| 62 // Create a new context and try to connect the other context's node to this
one. | |
| 63 try { | |
| 64 context2 = new AudioContext(); | |
| 65 window.audioNode.connect(context2.destination); | |
| 66 testFailed("exception should be thrown when connecting to other context'
s node."); | |
| 67 } catch(e) { | |
| 68 testPassed("exception thrown when connecting to other context's node."); | |
| 69 } | |
| 70 | 62 |
| 71 // 3-arg AudioContext doesn't create an offline context anymore. | 63 // Create a new context and try to connect the other context's node to this |
| 72 shouldNotThrow("context3 = new AudioContext(1, 44100, 44100)"); | 64 // one. |
| 73 if (context3 instanceof OfflineAudioContext) | 65 context2 = new AudioContext(); |
| 74 testFailed("context3 should not be an OfflineAudioContext"); | 66 should( |
| 75 else | 67 () => window.audioNode.connect(context2.destination), |
| 76 testPassed("context3 is not an OfflineAudioContext"); | 68 'Connecting a node to a different context') |
| 69 .throw('InvalidAccessError'); |
| 77 | 70 |
| 78 // Ensure it is an EventTarget | 71 should( |
| 79 try { | 72 () => context3 = new AudioContext(1, 44100, 44100), |
| 80 audioNode.addEventListener('testEvent', function(){ | 73 'context3 = new AudioContext(1, 44100, 44100)') |
| 81 testPassed("AudioNode is an EventTarget"); | 74 .notThrow(); |
| 82 }); | 75 should( |
| 83 audioNode.dispatchEvent(new Event('testEvent')); | 76 context3 instanceof OfflineAudioContext, |
| 84 } catch(e) { | 77 'context3 instanceof OfflineAudioContext') |
| 85 testFailed("exception shouldn't be thrown when testing whether audio nod
e is an event target"); | 78 .beFalse(); |
| 86 } | |
| 87 | 79 |
| 88 finishJSTest(); | 80 // Ensure it is an EventTarget |
| 89 } | 81 should(audioNode instanceof EventTarget, 'AudioNode is an EventTarget') |
| 82 .beTrue(); |
| 90 | 83 |
| 91 runTest(); | 84 task.done(); |
| 85 }); |
| 86 |
| 87 audit.run(); |
| 92 | 88 |
| 93 </script> | 89 </script> |
| 94 | 90 |
| 95 </body> | 91 </body> |
| 96 </html> | 92 </html> |
| OLD | NEW |