1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 description("Tests webkitMediaStream.");
17 var idArray
= new Array();
19 function checkIdAttribute(id
) {
22 for (var i
= 0; i
< id
.length
; i
++) {
23 charCode
= id
.charCodeAt(i
);
25 || (charCode
>= 0x23 && charCode
<= 0x27)
26 || (charCode
>= 0x2A && charCode
<= 0x2B)
27 || (charCode
>= 0x2D && charCode
<= 0x2E)
28 || (charCode
>= 0x30 && charCode
<= 0x39)
29 || (charCode
>= 0x41 && charCode
<= 0x5A)
30 || (charCode
>= 0x5E && charCode
<= 0x7E))
34 for (var i
= 0; i
< idArray
.length
; i
++) {
35 if (id
=== idArray
[i
])
44 testFailed('Stream generation failed.');
48 function getUserMedia(dictionary
, callback
) {
50 navigator
.webkitGetUserMedia(dictionary
, callback
, error
);
52 testFailed('webkitGetUserMedia threw exception :' + e
);
57 function gotStream(s
) {
59 testPassed('Got local stream.');
60 shouldBe('localStream.getAudioTracks().length', '1');
61 shouldBe('localStream.getVideoTracks().length', '1');
63 shouldBeTrue("typeof webkitMediaStream === 'function'");
64 shouldBeTrue('checkIdAttribute(localStream.id)');
65 testConstructor(localStream
);
68 function testConstructor(s
) {
70 shouldThrow('new webkitMediaStream(document)');
71 shouldThrow('new webkitMediaStream([document])');
72 shouldThrow('new webkitMediaStream([stream.getAudioTracks()[0], document])');
73 shouldThrow('new webkitMediaStream([null])');
74 shouldThrow('new webkitMediaStream([undefined])');
75 shouldThrow('new webkitMediaStream(null)');
76 shouldThrow('new webkitMediaStream(undefined)');
78 verifyStream(new webkitMediaStream(), 0, 0);
79 verifyStream(new webkitMediaStream([]), 0, 0);
81 verifyStream(new webkitMediaStream(s
), s
.getAudioTracks().length
, s
.getVideoTracks().length
);
83 verifyStream(new webkitMediaStream([s
.getAudioTracks()[0]]), 1, 0);
84 verifyStream(new webkitMediaStream([s
.getVideoTracks()[0]]), 0, 1);
85 verifyStream(new webkitMediaStream([s
.getAudioTracks()[0], s
.getVideoTracks()[0]]), 1, 1);
86 verifyStream(new webkitMediaStream([s
.getVideoTracks()[0], s
.getAudioTracks()[0], s
.getVideoTracks()[0]]), 1, 1);
88 s
.oninactive = function () {
89 verifyStream(new webkitMediaStream([s
.getAudioTracks()[0]]), 0, 0);
90 verifyStream(new webkitMediaStream([s
.getVideoTracks()[0]]), 0, 0);
91 verifyStream(new webkitMediaStream([s
.getAudioTracks()[0], s
.getVideoTracks()[0]]), 0, 0);
92 verifyStream(new webkitMediaStream(s
), 0, 0);
100 function verifyStream(s
, numAudioTracks
, numVideoTracks
) {
102 nAudio
= numAudioTracks
;
103 nVideo
= numVideoTracks
;
105 testPassed('Stream constructed');
106 shouldBeNonNull(newStream
);
107 shouldBeDefined(newStream
);
108 shouldBe("newStream.constructor.name", "'MediaStream'");
109 shouldBe('newStream.getAudioTracks().length', 'nAudio');
110 shouldBe('newStream.getVideoTracks().length', 'nVideo');
112 if (!nAudio
&& !nVideo
)
113 shouldBe('newStream.active', 'false');
115 shouldBe('newStream.active', 'true');
117 shouldBeTrue('checkIdAttribute(newStream.id)');
120 getUserMedia({video
:true, audio
:true}, gotStream
);
122 window
.jsTestIsAsync
= true;
123 window
.successfullyParsed
= true;