| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 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: |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 14 | // assert_session_desc_similar |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 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 | |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 64 | t.add_cleanup(() => pc.close()); |
| 65 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 66 | return pc.createOffer() |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 67 | .then(offer => |
| Boris Zbarsky | b7f2dd3 | 2020-02-04 21:26:48 | [diff] [blame] | 68 | promise_rejects_dom(t, 'InvalidStateError', |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 69 | pc.setLocalDescription({ type: 'pranswer', sdp: offer.sdp }))); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 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(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 82 | t.add_cleanup(() => pc.close()); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 83 | |
| 84 | const states = []; |
| 85 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 86 | |
| Youenn Fablet | 7b16358 | 2018-11-04 07:30:59 | [diff] [blame] | 87 | return generateVideoReceiveOnlyOffer(pc) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 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 | |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 98 | assert_session_desc_similar(pc.remoteDescription, offer); |
| 99 | assert_session_desc_similar(pc.pendingRemoteDescription, offer); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 100 | assert_equals(pc.currentRemoteDescription, null); |
| 101 | |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 102 | assert_session_desc_similar(pc.localDescription, pranswer); |
| 103 | assert_session_desc_similar(pc.pendingLocalDescription, pranswer); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 104 | assert_equals(pc.currentLocalDescription, null); |
| 105 | |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 106 | |
| 107 | assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 108 | }); |
| 109 | })); |
| 110 | }, 'setLocalDescription(pranswer) should succeed'); |
| 111 | |
| 112 | promise_test(t => { |
| 113 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 114 | t.add_cleanup(() => pc.close()); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 115 | |
| 116 | const states = []; |
| 117 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 118 | |
| Youenn Fablet | 7b16358 | 2018-11-04 07:30:59 | [diff] [blame] | 119 | return generateVideoReceiveOnlyOffer(pc) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 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) |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 127 | .then(() => pc.setLocalDescription(pranswer)) |
| 128 | .then(() => { |
| 129 | assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']); |
| 130 | }); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 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(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 136 | t.add_cleanup(() => pc.close()); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 137 | |
| 138 | const states = []; |
| 139 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 140 | |
| Youenn Fablet | 7b16358 | 2018-11-04 07:30:59 | [diff] [blame] | 141 | return generateVideoReceiveOnlyOffer(pc) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 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'); |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 152 | assert_session_desc_similar(pc.localDescription, answer); |
| 153 | assert_session_desc_similar(pc.remoteDescription, offer); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 154 | |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 155 | assert_session_desc_similar(pc.currentLocalDescription, answer); |
| 156 | assert_session_desc_similar(pc.currentRemoteDescription, offer); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 157 | |
| 158 | assert_equals(pc.pendingLocalDescription, null); |
| 159 | assert_equals(pc.pendingRemoteDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 160 | |
| 161 | assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer', 'stable']); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 162 | }); |
| 163 | })); |
| 164 | }, 'setLocalDescription(answer) from have-local-pranswer state should succeed'); |
| 165 | |
| 166 | </script> |