| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Tests RTCPeerConnection in stable state."); |
| |
| var pc = null; |
| |
| // Let's ensure built-ins are shielded from user scripts |
| var thenPromise = Promise.prototype.then; |
| Promise.prototype.then = function() { |
| console.log("Promise.prototype.then is called internally"); |
| return thenPromise.apply(this, arguments); |
| } |
| |
| function requestSucceeded2() |
| { |
| testPassed('setRemoteDescription succeeded.'); |
| check("", "", "offer", "remote", '"have-remote-offer"'); |
| finishJSTest(); |
| } |
| |
| function requestSucceeded1() |
| { |
| testPassed('setLocalDescription succeeded.'); |
| check("offer", "local", "", "", '"have-local-offer"') |
| pc = new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]}); |
| check("", "", "", "", '"stable"'); |
| sessionDescription = new RTCSessionDescription({type:"offer", sdp:"remote"}); |
| shouldNotThrow('pc.setRemoteDescription(sessionDescription, requestSucceeded2, finishIfFailed);'); |
| } |
| |
| function requestFailed4(reason) |
| { |
| errorReason = reason; |
| testPassed('setRemoteDescription failed.'); |
| shouldBe('errorReason.name', '"InvalidSessionDescriptionError"'); |
| check("", "", "", "", '"stable"'); |
| sessionDescription = new RTCSessionDescription({type:"offer", sdp:"local"}); |
| shouldNotThrow('pc.setLocalDescription(sessionDescription, requestSucceeded1, finishIfFailed);'); |
| } |
| |
| function requestFailed3(reason) |
| { |
| errorReason = reason; |
| testPassed('setRemoteDescription failed.'); |
| shouldBe('errorReason.name', '"InvalidSessionDescriptionError"'); |
| check("", "", "", "", '"stable"'); |
| sessionDescription = new RTCSessionDescription({type:"answer", sdp:"remote"}); |
| shouldNotThrow('pc.setRemoteDescription(sessionDescription, finishIfSucceeded, requestFailed4);'); |
| } |
| |
| function requestFailed2(reason) |
| { |
| errorReason = reason; |
| testPassed('setLocalDescription failed.'); |
| shouldBe('errorReason.name', '"InvalidSessionDescriptionError"'); |
| check("", "", "", "", '"stable"'); |
| sessionDescription = new RTCSessionDescription({type:"pranswer", sdp:"remote"}); |
| shouldNotThrow('pc.setRemoteDescription(sessionDescription, finishIfSucceeded, requestFailed3);'); |
| } |
| |
| function requestFailed1(reason) |
| { |
| errorReason = reason; |
| testPassed('setLocalDescription failed.'); |
| shouldBe('errorReason.name', '"InvalidSessionDescriptionError"'); |
| check("", "", "", "", '"stable"'); |
| sessionDescription = new RTCSessionDescription({type:"pranswer", sdp:"local"}); |
| shouldNotThrow('pc.setLocalDescription(sessionDescription, finishIfSucceeded, requestFailed2);'); |
| } |
| |
| function finishIfSucceeded() |
| { |
| testFailed('setRemoteDescription succeeded.'); |
| finishJSTest(); |
| } |
| |
| function finishIfFailed() |
| { |
| testFailed('setRemoteDescription failed.'); |
| finishJSTest(); |
| } |
| |
| function check(localType, localSdp, remoteType, remoteSdp, signalingState) |
| { |
| if (localType !== "" && localSdp !== "") { |
| shouldBeEqualToString('pc.localDescription.type', localType); |
| shouldBeEqualToString('pc.localDescription.sdp', localSdp); |
| } else { |
| shouldThrow('pc.localDescription'); |
| } |
| if (remoteType !== "" && remoteSdp !== "") { |
| shouldBeEqualToString('pc.remoteDescription.type', remoteType); |
| shouldBeEqualToString('pc.remoteDescription.sdp', remoteSdp); |
| } else { |
| shouldThrow('pc.remoteDescription'); |
| } |
| shouldBe('pc.signalingState', signalingState); |
| } |
| |
| pc = new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]}); |
| shouldBe('pc.signalingState', '"stable"'); |
| var sessionDescription = new RTCSessionDescription({type:"answer", sdp:"local"}); |
| shouldNotThrow('pc.setLocalDescription(sessionDescription, finishIfSucceeded, requestFailed1);'); |
| |
| window.jsTestIsAsync = true; |
| window.successfullyParsed = true; |
| </script> |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |