RTCPeerConnection-setRemoteDescription-pranswer.html (6022B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>RTCPeerConnection.prototype.setRemoteDescription pranswer</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> setLocalDescription( 22 RTCSessionDescriptionInit description); 23 24 readonly attribute RTCSessionDescription? localDescription; 25 readonly attribute RTCSessionDescription? currentLocalDescription; 26 readonly attribute RTCSessionDescription? pendingLocalDescription; 27 28 Promise<void> setRemoteDescription( 29 RTCSessionDescriptionInit description); 30 31 readonly attribute RTCSessionDescription? remoteDescription; 32 readonly attribute RTCSessionDescription? currentRemoteDescription; 33 readonly attribute RTCSessionDescription? pendingRemoteDescription; 34 ... 35 }; 36 37 4.6.2. RTCSessionDescription Class 38 dictionary RTCSessionDescriptionInit { 39 required RTCSdpType type; 40 DOMString sdp = ""; 41 }; 42 43 4.6.1. RTCSdpType 44 enum RTCSdpType { 45 "offer", 46 "pranswer", 47 "answer", 48 "rollback" 49 }; 50 */ 51 52 /* 53 4.3.1.6. Set the RTCSessionSessionDescription 54 2.1.3. If the description's type is invalid for the current signaling state of 55 connection, then reject p with a newly created InvalidStateError and abort 56 these steps. 57 58 [JSEP] 59 5.6. If the type is "pranswer" or "answer", the PeerConnection state MUST be either 60 "have-local-offer" or "have-remote-pranswer". 61 */ 62 promise_test(t => { 63 const pc = new RTCPeerConnection(); 64 65 t.add_cleanup(() => pc.close()); 66 67 return pc.createOffer() 68 .then(offer => 69 promise_rejects_dom(t, 'InvalidStateError', 70 pc.setRemoteDescription({ type: 'pranswer', sdp: offer.sdp }))); 71 }, 'setRemoteDescription(pranswer) from stable state should reject with InvalidStateError'); 72 73 /* 74 4.3.1.6. Set the RTCSessionSessionDescription 75 2.2.3. Otherwise, if description is set as a remote description, then run one 76 of the following steps: 77 - If description is of type "pranswer", then set 78 connection.pendingRemoteDescription to description and signaling state 79 to have-remote-pranswer. 80 */ 81 promise_test(t => { 82 const pc = new RTCPeerConnection(); 83 t.add_cleanup(() => pc.close()); 84 85 const states = []; 86 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); 87 88 return generateVideoReceiveOnlyOffer(pc) 89 .then(offer => 90 pc.setLocalDescription(offer) 91 .then(() => generateAnswer(offer)) 92 .then(answer => { 93 const pranswer = { type: 'pranswer', sdp: answer.sdp }; 94 95 return pc.setRemoteDescription(pranswer) 96 .then(() => { 97 assert_equals(pc.signalingState, 'have-remote-pranswer'); 98 99 assert_session_desc_similar(pc.localDescription, offer); 100 assert_session_desc_similar(pc.pendingLocalDescription, offer); 101 assert_equals(pc.currentLocalDescription, null); 102 103 assert_session_desc_similar(pc.remoteDescription, pranswer); 104 assert_session_desc_similar(pc.pendingRemoteDescription, pranswer); 105 assert_equals(pc.currentRemoteDescription, null); 106 107 assert_array_equals(states, ['have-local-offer', 'have-remote-pranswer']); 108 }); 109 })); 110 }, 'setRemoteDescription(pranswer) from have-local-offer state should succeed'); 111 112 promise_test(t => { 113 const pc = new RTCPeerConnection(); 114 t.add_cleanup(() => pc.close()); 115 116 const states = []; 117 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); 118 119 return generateVideoReceiveOnlyOffer(pc) 120 .then(offer => 121 pc.setLocalDescription(offer) 122 .then(() => generateAnswer(offer)) 123 .then(answer => { 124 const pranswer = { type: 'pranswer', sdp: answer.sdp }; 125 126 return pc.setRemoteDescription(pranswer) 127 .then(() => pc.setRemoteDescription(pranswer)) 128 .then(() => { 129 assert_array_equals(states, ['have-local-offer', 'have-remote-pranswer']); 130 }); 131 })); 132 }, 'setRemoteDescription(pranswer) multiple times should succeed'); 133 134 promise_test(t => { 135 const pc = new RTCPeerConnection(); 136 t.add_cleanup(() => pc.close()); 137 138 const states = []; 139 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); 140 141 return generateVideoReceiveOnlyOffer(pc) 142 .then(offer => 143 pc.setLocalDescription(offer) 144 .then(() => generateAnswer(offer)) 145 .then(answer => { 146 const pranswer = { type: 'pranswer', sdp: answer.sdp }; 147 148 return pc.setRemoteDescription(pranswer) 149 .then(() => pc.setRemoteDescription(answer)) 150 .then(() => { 151 assert_equals(pc.signalingState, 'stable'); 152 153 assert_session_desc_similar(pc.localDescription, offer); 154 assert_session_desc_similar(pc.currentLocalDescription, offer); 155 assert_equals(pc.pendingLocalDescription, null); 156 157 assert_session_desc_similar(pc.remoteDescription, answer); 158 assert_session_desc_similar(pc.currentRemoteDescription, answer); 159 assert_equals(pc.pendingRemoteDescription, null); 160 161 assert_array_equals(states, ['have-local-offer', 'have-remote-pranswer', 'stable']); 162 }); 163 })); 164 }, 'setRemoteDescription(answer) from have-remote-pranswer state should succeed'); 165 166 </script>