5 <script src="../resources/js-test.js"></script>
6 <script src="resources/compatibility.js"></script>
7 <script type="text/javascript" src="resources/audio-testing.js"></script>
11 <div id="description"></div>
12 <div id="console"></div>
15 description("Basic tests for AudioNode API.");
22 if (window.testRunner) {
23 testRunner.dumpAsText();
24 testRunner.waitUntilDone();
27 window.jsTestIsAsync = true;
29 context = new AudioContext();
30 window.audioNode = context.createBufferSource();
32 // Check input and output numbers of AudioSourceNode.
33 if (audioNode.numberOfInputs === 0)
34 testPassed("Source AudioNode has no inputs.");
36 testFailed("Source AudioNode should not have inputs.");
38 if (audioNode.numberOfOutputs === 1)
39 testPassed("Source AudioNode has one output.");
41 testFailed("Source AudioNode should have one output.");
43 // Check input and output numbers of AudioDestinationNode
44 if (context.destination.numberOfInputs === 1)
45 testPassed("Destination AudioNode has one input.");
47 testFailed("Destination AudioNode should have one input.");
49 if (context.destination.numberOfOutputs === 0)
50 testPassed("Destination AudioNode has no outputs.");
52 testFailed("Destination AudioNode should have no outputs.");
54 // Try calling connect() method with illegal values.
57 audioNode.connect(0, 0, 0);
58 testFailed("connect() exception should be thrown for illegal destination AudioNode.");
60 testPassed("connect() exception thrown for illegal destination AudioNode.");
64 audioNode.connect(context.destination, 5, 0);
65 testFailed("connect() exception should be thrown for illegal output index.");
67 testPassed("connect() exception thrown for illegal output index.");
71 audioNode.connect(context.destination, 0, 5);
72 testFailed("connect() exception should be thrown for illegal input index.");
74 testPassed("connect() exception thrown for illegal input index.");
77 // Try calling connect() with proper values.
79 audioNode.connect(context.destination, 0, 0);
80 testPassed("audioNode.connect(context.destination) succeeded.");
82 testFailed("audioNode.connect(context.destination) failed.");
85 // Create a new context and try to connect the other context's node to this one.
87 context2 = new AudioContext();
88 window.audioNode.connect(context2.destination);
89 testFailed("exception should be thrown when connecting to other context's node.");
91 testPassed("exception thrown when connecting to other context's node.");
94 // 3-arg AudioContext doesn't create an offline context anymore.
95 shouldNotThrow("context3 = new AudioContext(1, 44100, 44100)");
96 if (context3 instanceof OfflineAudioContext)
97 testFailed("context3 should not be an OfflineAudioContext");
99 testPassed("context3 is not an OfflineAudioContext");
101 // Ensure it is an EventTarget
103 audioNode.addEventListener('testEvent', function(){
104 testPassed("AudioNode is an EventTarget");
106 audioNode.dispatchEvent(new Event('testEvent'));
108 testFailed("exception shouldn't be thrown when testing whether audio node is an event target");