RTCPeerConnection-setRemoteDescription-answer.html (4255B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>RTCPeerConnection.prototype.setRemoteDescription - answer</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="RTCPeerConnection-helper.js"></script> 7 <script> 8 'use strict'; 9 10 // Test is based on the following editor draft: 11 // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html 12 13 // The following helper functions are called from RTCPeerConnection-helper.js: 14 // generateAnswer() 15 // assert_session_desc_similar() 16 17 /* 18 4.3.2. Interface Definition 19 [Constructor(optional RTCConfiguration configuration)] 20 interface RTCPeerConnection : EventTarget { 21 Promise<void> setRemoteDescription( 22 RTCSessionDescriptionInit description); 23 24 readonly attribute RTCSessionDescription? remoteDescription; 25 readonly attribute RTCSessionDescription? currentRemoteDescription; 26 readonly attribute RTCSessionDescription? pendingRemoteDescription; 27 ... 28 }; 29 30 4.6.2. RTCSessionDescription Class 31 dictionary RTCSessionDescriptionInit { 32 required RTCSdpType type; 33 DOMString sdp = ""; 34 }; 35 36 4.6.1. RTCSdpType 37 enum RTCSdpType { 38 "offer", 39 "pranswer", 40 "answer", 41 "rollback" 42 }; 43 */ 44 45 /* 46 4.3.1.6. Set the RTCSessionSessionDescription 47 2.2.3. Otherwise, if description is set as a remote description, then run one of 48 the following steps: 49 - If description is of type "answer", then this completes an offer answer 50 negotiation. 51 52 Set connection's currentRemoteDescription to description and 53 currentLocalDescription to the value of pendingLocalDescription. 54 55 Set both pendingRemoteDescription and pendingLocalDescription to null. 56 57 Finally setconnection's signaling state to stable. 58 */ 59 promise_test(t => { 60 const pc = new RTCPeerConnection(); 61 t.add_cleanup(() => pc.close()); 62 63 const states = []; 64 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); 65 66 return generateVideoReceiveOnlyOffer(pc) 67 .then(offer => 68 pc.setLocalDescription(offer) 69 .then(() => generateAnswer(offer)) 70 .then(answer => 71 pc.setRemoteDescription(answer) 72 .then(() => { 73 assert_equals(pc.signalingState, 'stable'); 74 75 assert_session_desc_similar(pc.localDescription, offer); 76 assert_session_desc_similar(pc.remoteDescription, answer); 77 78 assert_session_desc_similar(pc.currentLocalDescription, offer); 79 assert_session_desc_similar(pc.currentRemoteDescription, answer); 80 81 assert_equals(pc.pendingLocalDescription, null); 82 assert_equals(pc.pendingRemoteDescription, null); 83 84 assert_array_equals(states, ['have-local-offer', 'stable']); 85 }))); 86 }, 'setRemoteDescription() with valid state and answer should succeed'); 87 88 /* 89 4.3.1.6. Set the RTCSessionSessionDescription 90 2.1.3. If the description's type is invalid for the current signaling state of 91 connection, then reject p with a newly created InvalidStateError and abort 92 these steps. 93 94 [JSEP] 95 5.6. If the type is "answer", the PeerConnection state MUST be either 96 "have-local-offer" or "have-remote-pranswer". 97 */ 98 promise_test(t => { 99 const pc = new RTCPeerConnection(); 100 101 t.add_cleanup(() => pc.close()); 102 103 return pc.createOffer() 104 .then(offer => 105 promise_rejects_dom(t, 'InvalidStateError', 106 pc.setRemoteDescription({ type: 'answer', sdp: offer.sdp }))); 107 }, 'Calling setRemoteDescription(answer) from stable state should reject with InvalidStateError'); 108 109 promise_test(t => { 110 const pc = new RTCPeerConnection(); 111 112 t.add_cleanup(() => pc.close()); 113 114 return pc.createOffer() 115 .then(offer => 116 pc.setRemoteDescription(offer) 117 .then(() => generateAnswer(offer))) 118 .then(answer => 119 promise_rejects_dom(t, 'InvalidStateError', 120 pc.setRemoteDescription(answer))); 121 }, 'Calling setRemoteDescription(answer) from have-remote-offer state should reject with InvalidStateError'); 122 123 </script>