| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 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 | |
| Rick Waldron | 1c5c05d | 2017-06-07 17:54:42 | [diff] [blame] | 13 | // The following helper functions are called from RTCPeerConnection-helper.js: |
| Rick Waldron | 1c5c05d | 2017-06-07 17:54:42 | [diff] [blame] | 14 | // countAudioLine() |
| 15 | // countVideoLine() |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 16 | // assert_session_desc_similar() |
| Rick Waldron | 1c5c05d | 2017-06-07 17:54:42 | [diff] [blame] | 17 | |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 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(t => { |
| 29 | const pc = new RTCPeerConnection() |
| 30 | |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 31 | t.add_cleanup(() => pc.close()); |
| 32 | |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 33 | return pc.createOffer() |
| 34 | .then(offer => { |
| 35 | assert_equals(typeof offer, 'object', |
| 36 | 'Expect offer to be plain object dictionary RTCSessionDescriptionInit'); |
| 37 | |
| 38 | assert_false(offer instanceof RTCSessionDescription, |
| 39 | 'Expect offer to not be instance of RTCSessionDescription') |
| 40 | }); |
| 41 | }, 'createOffer() with no argument from newly created RTCPeerConnection should succeed'); |
| 42 | |
| 43 | promise_test(t => { |
| 44 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 45 | t.add_cleanup(() => pc.close()); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 46 | |
| 47 | const states = []; |
| 48 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 49 | |
| Youenn Fablet | 20676f8 | 2018-11-04 04:18:09 | [diff] [blame] | 50 | return generateVideoReceiveOnlyOffer(pc) |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 51 | .then(offer => |
| Dominique Hazael-Massieux | 841671e | 2020-01-15 08:57:12 | [diff] [blame] | 52 | pc.setLocalDescription(offer) |
| Nils Ohlmeier | 6cb9707 | 2017-08-31 00:38:29 | [diff] [blame] | 53 | .then(() => { |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 54 | assert_equals(pc.signalingState, 'have-local-offer'); |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 55 | assert_session_desc_similar(pc.localDescription, offer); |
| 56 | assert_session_desc_similar(pc.pendingLocalDescription, offer); |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 57 | assert_equals(pc.currentLocalDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 58 | |
| 59 | assert_array_equals(states, ['have-local-offer']); |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 60 | })); |
| 61 | }, 'createOffer() and then setLocalDescription() should succeed'); |
| 62 | |
| 63 | promise_test(t => { |
| 64 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 65 | t.add_cleanup(() => pc.close()); |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 66 | pc.close(); |
| 67 | |
| Boris Zbarsky | b7f2dd3 | 2020-02-04 21:26:48 | [diff] [blame] | 68 | return promise_rejects_dom(t, 'InvalidStateError', |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 69 | pc.createOffer()); |
| 70 | }, 'createOffer() after connection is closed should reject with InvalidStateError'); |
| 71 | |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 72 | /* |
| 73 | * Final steps to create an offer |
| 74 | * 2. If connection was modified in such a way that additional inspection of the |
| 75 | * system state is necessary, then in parallel begin the steps to create an |
| 76 | * offer again, given p, and abort these steps. |
| 77 | * |
| 78 | * This test might hit step 2 of final steps to create an offer. But the media stream |
| 79 | * is likely added already by the time steps to create an offer is executed, because |
| 80 | * that is enqueued as an operation. |
| 81 | * Either way it verifies that the media stream is included in the offer even though |
| 82 | * the stream is added after synchronous call to createOffer. |
| 83 | */ |
| 84 | promise_test(t => { |
| 85 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 86 | t.add_cleanup(() => pc.close()); |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 87 | const promise = pc.createOffer(); |
| 88 | |
| 89 | pc.addTransceiver('audio'); |
| 90 | return promise.then(offer => { |
| 91 | assert_equals(countAudioLine(offer.sdp), 1, |
| 92 | 'Expect m=audio line to be found in offer SDP') |
| 93 | }); |
| 94 | }, 'When media stream is added when createOffer() is running in parallel, the result offer should contain the new media stream'); |
| 95 | |
| 96 | /* |
| Dominique Hazael-Massieux | 841671e | 2020-01-15 08:57:12 | [diff] [blame] | 97 | If connection's signaling state is neither "stable" nor "have-local-offer", return a promise rejected with a newly created InvalidStateError. |
| 98 | */ |
| 99 | promise_test(t => { |
| 100 | const pc = new RTCPeerConnection(); |
| 101 | t.add_cleanup(() => pc.close()); |
| 102 | |
| 103 | const states = []; |
| 104 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| 105 | |
| 106 | return generateVideoReceiveOnlyOffer(pc) |
| 107 | .then(offer => |
| 108 | pc.setRemoteDescription(offer) |
| 109 | .then(() => { |
| 110 | assert_equals(pc.signalingState, 'have-remote-offer'); |
| Boris Zbarsky | b7f2dd3 | 2020-02-04 21:26:48 | [diff] [blame] | 111 | return promise_rejects_dom(t, 'InvalidStateError', |
| Dominique Hazael-Massieux | 841671e | 2020-01-15 08:57:12 | [diff] [blame] | 112 | pc.createOffer()); |
| 113 | }) |
| 114 | ) |
| 115 | }, 'createOffer() should fail when signaling state is not stable or have-local-offer'); |
| 116 | /* |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 117 | * TODO |
| 118 | * 4.3.2 createOffer |
| 119 | * 3. If connection is configured with an identity provider, and an identity |
| 120 | * assertion has not yet been generated using said identity provider, then |
| 121 | * begin the identity assertion request process if it has not already begun. |
| 122 | * Steps to create an offer |
| 123 | * 1. If the need for an identity assertion was identified when createOffer was |
| 124 | * invoked, wait for the identity assertion request process to complete. |
| 125 | * |
| 126 | * Non-Testable |
| 127 | * 4.3.2 createOffer |
| 128 | * Steps to create an offer |
| 129 | * 4. Inspect the system state to determine the currently available resources as |
| 130 | * necessary for generating the offer, as described in [JSEP] (section 4.1.6.). |
| 131 | * 5. If this inspection failed for any reason, reject p with a newly created |
| 132 | * OperationError and abort these steps. |
| 133 | */ |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 134 | </script> |