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