RTCPeerConnection-createOffer.html (5069B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>RTCPeerConnection.prototype.createOffer</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/20170515/webrtc.html 12 13 // The following helper functions are called from RTCPeerConnection-helper.js: 14 // countAudioLine() 15 // countVideoLine() 16 // assert_session_desc_similar() 17 18 /* 19 * 4.3.2. createOffer() 20 */ 21 22 /* 23 * Final steps to create an offer 24 * 4. Let offer be a newly created RTCSessionDescriptionInit dictionary 25 * with its type member initialized to the string "offer" and its sdp member 26 * initialized to sdpString. 27 */ 28 promise_test(async t => { 29 const pc = new RTCPeerConnection() 30 t.add_cleanup(() => pc.close()); 31 32 const offer = await pc.createOffer() 33 assert_equals(typeof offer, 'object', 34 'Expect offer to be plain object (dictionary RTCSessionDescriptionInit)'); 35 36 assert_false(offer instanceof RTCSessionDescription, 37 'Expect offer to not be instance of RTCSessionDescription') 38 }, 'createOffer() returns RTCSessionDescriptionInit'); 39 40 promise_test(t => { 41 const pc = new RTCPeerConnection(); 42 t.add_cleanup(() => pc.close()); 43 44 const states = []; 45 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); 46 47 return generateVideoReceiveOnlyOffer(pc) 48 .then(offer => 49 pc.setLocalDescription(offer) 50 .then(() => { 51 assert_equals(pc.signalingState, 'have-local-offer'); 52 assert_session_desc_similar(pc.localDescription, offer); 53 assert_equals(pc.pendingLocalDescription, pc.localDescription); 54 assert_equals(pc.currentLocalDescription, null); 55 56 assert_array_equals(states, ['have-local-offer']); 57 })); 58 }, 'createOffer() and then setLocalDescription() should succeed'); 59 60 promise_test(t => { 61 const pc = new RTCPeerConnection(); 62 t.add_cleanup(() => pc.close()); 63 pc.close(); 64 65 return promise_rejects_dom(t, 'InvalidStateError', 66 pc.createOffer()); 67 }, 'createOffer() after connection is closed should reject with InvalidStateError'); 68 69 /* 70 * Final steps to create an offer 71 * 2. If connection was modified in such a way that additional inspection of the 72 * system state is necessary, then in parallel begin the steps to create an 73 * offer again, given p, and abort these steps. 74 * 75 * This test might hit step 2 of final steps to create an offer. But the media stream 76 * is likely added already by the time steps to create an offer is executed, because 77 * that is enqueued as an operation. 78 * Either way it verifies that the media stream is included in the offer even though 79 * the stream is added after synchronous call to createOffer. 80 */ 81 promise_test(t => { 82 const pc = new RTCPeerConnection(); 83 t.add_cleanup(() => pc.close()); 84 const promise = pc.createOffer(); 85 86 pc.addTransceiver('audio'); 87 return promise.then(offer => { 88 assert_equals(countAudioLine(offer.sdp), 1, 89 'Expect m=audio line to be found in offer SDP') 90 }); 91 }, 'When media stream is added when createOffer() is running in parallel, the result offer should contain the new media stream'); 92 93 /* 94 If connection's signaling state is neither "stable" nor "have-local-offer", return a promise rejected with a newly created InvalidStateError. 95 */ 96 promise_test(t => { 97 const pc = new RTCPeerConnection(); 98 t.add_cleanup(() => pc.close()); 99 100 const states = []; 101 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); 102 103 return generateVideoReceiveOnlyOffer(pc) 104 .then(offer => 105 pc.setRemoteDescription(offer) 106 .then(() => { 107 assert_equals(pc.signalingState, 'have-remote-offer'); 108 return promise_rejects_dom(t, 'InvalidStateError', 109 pc.createOffer()); 110 }) 111 ) 112 }, 'createOffer() should fail when signaling state is not stable or have-local-offer'); 113 /* 114 * TODO 115 * 4.3.2 createOffer 116 * 3. If connection is configured with an identity provider, and an identity 117 * assertion has not yet been generated using said identity provider, then 118 * begin the identity assertion request process if it has not already begun. 119 * Steps to create an offer 120 * 1. If the need for an identity assertion was identified when createOffer was 121 * invoked, wait for the identity assertion request process to complete. 122 * 123 * Non-Testable 124 * 4.3.2 createOffer 125 * Steps to create an offer 126 * 4. Inspect the system state to determine the currently available resources as 127 * necessary for generating the offer, as described in [JSEP] (section 4.1.6.). 128 * 5. If this inspection failed for any reason, reject p with a newly created 129 * OperationError and abort these steps. 130 */ 131 </script>