1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
8 description("Tests that an RTCPeerConnection can signal that remote streams are added and removed.");
11 var local_stream
= null;
14 testFailed('Stream generation failed.');
18 function getUserMedia(dictionary
, callback
) {
20 navigator
.webkitGetUserMedia(dictionary
, callback
, error
);
22 testFailed('webkitGetUserMedia threw exception :' + e
);
27 function requestSucceeded2()
29 testPassed('requestSucceeded was called.');
30 shouldBeEqualToNumber('pc.getRemoteStreams().length', 0);
34 function requestSucceeded1()
36 testPassed('requestSucceeded was called.');
37 shouldBeEqualToNumber('pc.getRemoteStreams().length', 1);
39 sessionDescription
= new RTCSessionDescription({type
:"offer", sdp
:"remote"});
40 shouldNotThrow('pc.setRemoteDescription(sessionDescription, requestSucceeded2, requestFailedUnexpectedly);');
43 function requestFailedUnexpectedly()
45 testFailed('requestFailed was called.');
49 function gotStream(stream
) {
50 local_stream
= stream
;
51 pc
.addStream(local_stream
);
53 sessionDescription
= new RTCSessionDescription({type
:"answer", sdp
:"remote"});
54 shouldNotThrow('pc.setRemoteDescription(sessionDescription, requestSucceeded1, requestFailedUnexpectedly);');
57 function onAddStream(event
) {
58 testPassed('remote stream was added');
59 shouldBeEqualToNumber('event.stream.getVideoTracks().length', 1);
60 shouldBeEqualToNumber('event.stream.getAudioTracks().length', 1);
61 shouldBeTrue('event.stream.active')
62 pc
.removeStream(local_stream
);
65 function onRemoveStream(event
) {
66 testPassed('remote stream was removed');
67 shouldBeEqualToNumber('event.stream.getVideoTracks().length', 0);
68 shouldBeEqualToNumber('event.stream.getAudioTracks().length', 0);
69 shouldBeFalse('event.stream.active')
72 pc
= new webkitRTCPeerConnection(null, null);
73 pc
.onaddstream
= onAddStream
;
74 pc
.onremovestream
= onRemoveStream
;
75 getUserMedia({audio
:true, video
:true}, gotStream
);
78 window
.jsTestIsAsync
= true;
79 window
.successfullyParsed
= true;