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.
55 shouldThrow('audioNode.connect(0, 0, 0)');
56 shouldThrow('audioNode.connect(null, 0, 0)');
57 shouldThrow('audioNode.connect(context.destination, 5, 0)');
58 shouldThrow('audioNode.connect(context.destination, 0, 5)');
60 shouldNotThrow('audioNode.connect(context.destination, 0, 0)');
62 // Create a new context and try to connect the other context's node to this one.
64 context2
= new AudioContext();
65 window
.audioNode
.connect(context2
.destination
);
66 testFailed("exception should be thrown when connecting to other context's node.");
68 testPassed("exception thrown when connecting to other context's node.");
71 // 3-arg AudioContext doesn't create an offline context anymore.
72 shouldNotThrow("context3 = new AudioContext(1, 44100, 44100)");
73 if (context3
instanceof OfflineAudioContext
)
74 testFailed("context3 should not be an OfflineAudioContext");
76 testPassed("context3 is not an OfflineAudioContext");
78 // Ensure it is an EventTarget
80 audioNode
.addEventListener('testEvent', function(){
81 testPassed("AudioNode is an EventTarget");
83 audioNode
.dispatchEvent(new Event('testEvent'));
85 testFailed("exception shouldn't be thrown when testing whether audio node is an event target");