5 <script src=
"../resources/js-test.js"></script>
6 <script src=
"resources/compatibility.js"></script>
7 <script src=
"resources/audio-testing.js"></script>
11 <div id=
"description"></div>
12 <div id=
"console"></div>
15 description("Basic tests for MediaStreamAudioSourceNode API.");
20 testFailed('Stream generation failed.');
24 function getUserMedia(dictionary
, callback
) {
26 navigator
.webkitGetUserMedia(dictionary
, callback
, error
);
28 testFailed('webkitGetUserMedia threw exception :' + e
);
33 function gotStream(stream
) {
35 testPassed('{audio:true} generated stream');
36 shouldBe('s.getAudioTracks().length', '1');
37 shouldBe('s.getVideoTracks().length', '0');
39 context
= new AudioContext();
41 // Create an AudioNode from the stream.
42 var mediaStreamSource
= context
.createMediaStreamSource(stream
);
44 // Check number of inputs and outputs.
45 if (mediaStreamSource
.numberOfInputs
== 0)
46 testPassed("Source AudioNode has no inputs.");
48 testFailed("Source AudioNode should not have inputs.");
50 if (mediaStreamSource
.numberOfOutputs
== 1)
51 testPassed("Source AudioNode has one output.");
53 testFailed("Source AudioNode should have one output.");
55 // Try calling connect() method with illegal values.
58 mediaStreamSource
.connect(0, 0, 0);
59 testFailed("connect() exception should be thrown for illegal destination AudioNode.");
61 testPassed("connect() exception thrown for illegal destination AudioNode.");
65 mediaStreamSource
.connect(context
.destination
, 5, 0);
66 testFailed("connect() exception should be thrown for illegal output index.");
68 testPassed("connect() exception thrown for illegal output index.");
72 mediaStreamSource
.connect(context
.destination
, 0, 5);
73 testFailed("connect() exception should be thrown for illegal input index.");
75 testPassed("connect() exception thrown for illegal input index.");
78 // Try calling connect() with proper values.
80 mediaStreamSource
.connect(context
.destination
, 0, 0);
81 testPassed("mediaStreamSource.connect(context.destination) succeeded.");
83 testFailed("mediaStreamSource.connect(context.destination) failed.");
89 getUserMedia({audio
:true}, gotStream
);
90 window
.jsTestIsAsync
= true;
91 window
.successfullyParsed
= true;