RTCPeerConnection-setLocalDescription-parameterless.https.html (6312B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title></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 const kSmallTimeoutMs = 100; 11 12 promise_test(async t => { 13 const offerer = new RTCPeerConnection(); 14 t.add_cleanup(() => offerer.close()); 15 16 const signalingStateChangeEvent 17 = new EventWatcher(t, offerer, 'signalingstatechange') 18 .wait_for('signalingstatechange'); 19 await offerer.setLocalDescription(); 20 await signalingStateChangeEvent; 21 assert_equals(offerer.signalingState, 'have-local-offer'); 22 }, "Parameterless SLD() in 'stable' goes to 'have-local-offer'"); 23 24 promise_test(async t => { 25 const offerer = new RTCPeerConnection(); 26 t.add_cleanup(() => offerer.close()); 27 28 await offerer.setLocalDescription(); 29 assert_not_equals(offerer.pendingLocalDescription, null); 30 assert_equals(offerer.pendingLocalDescription, offerer.pendingLocalDescription); 31 }, "Parameterless SLD() in 'stable' sets pendingLocalDescription"); 32 33 promise_test(async t => { 34 const offerer = new RTCPeerConnection(); 35 t.add_cleanup(() => offerer.close()); 36 37 const transceiver = offerer.addTransceiver('audio'); 38 assert_equals(transceiver.mid, null); 39 await offerer.setLocalDescription(); 40 assert_not_equals(transceiver.mid, null); 41 }, "Parameterless SLD() in 'stable' assigns transceiver.mid"); 42 43 promise_test(async t => { 44 const offerer = new RTCPeerConnection(); 45 t.add_cleanup(() => offerer.close()); 46 const answerer = new RTCPeerConnection(); 47 t.add_cleanup(() => answerer.close()); 48 49 await answerer.setRemoteDescription(await offerer.createOffer()); 50 const signalingStateChangeEvent 51 = new EventWatcher(t, answerer, 'signalingstatechange') 52 .wait_for('signalingstatechange'); 53 await answerer.setLocalDescription(); 54 await signalingStateChangeEvent; 55 assert_equals(answerer.signalingState, 'stable'); 56 }, "Parameterless SLD() in 'have-remote-offer' goes to 'stable'"); 57 58 promise_test(async t => { 59 const offerer = new RTCPeerConnection(); 60 t.add_cleanup(() => offerer.close()); 61 const answerer = new RTCPeerConnection(); 62 t.add_cleanup(() => answerer.close()); 63 64 await answerer.setRemoteDescription(await offerer.createOffer()); 65 await answerer.setLocalDescription(); 66 assert_not_equals(answerer.currentLocalDescription, null); 67 assert_equals(answerer.currentLocalDescription, answerer.currentLocalDescription); 68 }, "Parameterless SLD() in 'have-remote-offer' sets currentLocalDescription"); 69 70 promise_test(async t => { 71 const offerer = new RTCPeerConnection(); 72 t.add_cleanup(() => offerer.close()); 73 const answerer = new RTCPeerConnection(); 74 t.add_cleanup(() => answerer.close()); 75 76 offerer.addTransceiver('audio'); 77 const onTransceiverPromise = new Promise(resolve => 78 answerer.ontrack = e => resolve(e.transceiver)); 79 await answerer.setRemoteDescription(await offerer.createOffer()); 80 const transceiver = await onTransceiverPromise; 81 await answerer.setLocalDescription(); 82 assert_equals(transceiver.currentDirection, 'recvonly'); 83 }, "Parameterless SLD() in 'have-remote-offer' sets " + 84 "transceiver.currentDirection"); 85 86 promise_test(async t => { 87 const offerer = new RTCPeerConnection(); 88 t.add_cleanup(() => offerer.close()); 89 90 const offer = await offerer.createOffer(); 91 await offerer.setLocalDescription(); 92 // assert_true() is used rather than assert_equals() so that if the assertion 93 // fails, the -expected.txt file is not different on each run. 94 assert_true(offerer.pendingLocalDescription.sdp == offer.sdp, 95 "offerer.pendingLocalDescription.sdp == offer.sdp"); 96 }, "Parameterless SLD() uses [[LastCreatedOffer]] if it is still valid"); 97 98 promise_test(async t => { 99 const offerer = new RTCPeerConnection(); 100 t.add_cleanup(() => offerer.close()); 101 const answerer = new RTCPeerConnection(); 102 t.add_cleanup(() => answerer.close()); 103 104 await answerer.setRemoteDescription(await offerer.createOffer()); 105 const answer = await answerer.createAnswer(); 106 await answerer.setLocalDescription(); 107 // assert_true() is used rather than assert_equals() so that if the assertion 108 // fails, the -expected.txt file is not different on each run. 109 assert_true(answerer.currentLocalDescription.sdp == answer.sdp, 110 "answerer.currentLocalDescription.sdp == answer.sdp"); 111 }, "Parameterless SLD() uses [[LastCreatedAnswer]] if it is still valid"); 112 113 promise_test(async t => { 114 const offerer = new RTCPeerConnection(); 115 offerer.close(); 116 try { 117 await offerer.setLocalDescription(); 118 assert_not_reached(); 119 } catch (e) { 120 assert_equals(e.name, "InvalidStateError"); 121 } 122 }, "Parameterless SLD() rejects with InvalidStateError if already closed"); 123 124 promise_test(async t => { 125 const offerer = new RTCPeerConnection(); 126 t.add_cleanup(() => offerer.close()); 127 128 const p = Promise.race([ 129 offerer.setLocalDescription(), 130 new Promise(r => t.step_timeout(() => r("timeout"), kSmallTimeoutMs)) 131 ]); 132 offerer.close(); 133 assert_equals(await p, "timeout"); 134 }, "Parameterless SLD() never settles if closed while pending"); 135 136 promise_test(async t => { 137 const offerer = new RTCPeerConnection(); 138 t.add_cleanup(() => offerer.close()); 139 const answerer = new RTCPeerConnection(); 140 t.add_cleanup(() => answerer.close()); 141 142 // Implicitly create an offer. 143 await offerer.setLocalDescription(); 144 await answerer.setRemoteDescription(offerer.pendingLocalDescription); 145 // Implicitly create an answer. 146 await answerer.setLocalDescription(); 147 await offerer.setRemoteDescription(answerer.currentLocalDescription); 148 }, "Parameterless SLD() in a full O/A exchange succeeds"); 149 150 promise_test(async t => { 151 const answerer = new RTCPeerConnection(); 152 try { 153 await answerer.setRemoteDescription(); 154 assert_not_reached(); 155 } catch (e) { 156 assert_equals(e.name, "TypeError"); 157 } 158 }, "Parameterless SRD() rejects with TypeError."); 159 160 promise_test(async t => { 161 const offerer = new RTCPeerConnection(); 162 const {sdp} = await offerer.createOffer(); 163 new RTCSessionDescription({type: "offer", sdp}); 164 try { 165 new RTCSessionDescription({sdp}); 166 assert_not_reached(); 167 } catch (e) { 168 assert_equals(e.name, "TypeError"); 169 } 170 }, "RTCSessionDescription constructed without type throws TypeError"); 171 172 </script>