| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <meta charset=utf-8> |
| 3 | <title>RTCPeerConnection.prototype.setRemoteDescription - offer</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: |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 14 | // assert_session_desc_equals() |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 15 | |
| 16 | /* |
| 17 | 4.3.2. Interface Definition |
| 18 | [Constructor(optional RTCConfiguration configuration)] |
| 19 | interface RTCPeerConnection : EventTarget { |
| 20 | Promise<void> setRemoteDescription( |
| 21 | RTCSessionDescriptionInit description); |
| 22 | |
| 23 | readonly attribute RTCSessionDescription? remoteDescription; |
| 24 | readonly attribute RTCSessionDescription? currentRemoteDescription; |
| 25 | readonly attribute RTCSessionDescription? pendingRemoteDescription; |
| 26 | ... |
| 27 | }; |
| 28 | |
| 29 | 4.6.2. RTCSessionDescription Class |
| 30 | dictionary RTCSessionDescriptionInit { |
| 31 | required RTCSdpType type; |
| 32 | DOMString sdp = ""; |
| 33 | }; |
| 34 | |
| 35 | 4.6.1. RTCSdpType |
| 36 | enum RTCSdpType { |
| 37 | "offer", |
| 38 | "pranswer", |
| 39 | "answer", |
| 40 | "rollback" |
| 41 | }; |
| 42 | */ |
| 43 | |
| 44 | /* |
| 45 | 4.3.1.6. Set the RTCSessionSessionDescription |
| 46 | 2.2.3. Otherwise, if description is set as a remote description, then run one of |
| 47 | the following steps: |
| 48 | - If description is of type "offer", set connection.pendingRemoteDescription |
| 49 | attribute to description and signaling state to have-remote-offer. |
| 50 | */ |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 51 | |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 52 | promise_test(t => { |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 53 | const pc1 = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 54 | t.add_cleanup(() => pc1.close()); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 55 | pc1.createDataChannel('datachannel'); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 56 | |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 57 | const pc2 = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 58 | t.add_cleanup(() => pc2.close()); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 59 | |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 60 | const states = []; |
| 61 | pc2.addEventListener('signalingstatechange', () => states.push(pc2.signalingState)); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 62 | |
| 63 | return pc1.createOffer() |
| 64 | .then(offer => { |
| 65 | return pc2.setRemoteDescription(offer) |
| Nils Ohlmeier | 4b1563d | 2017-08-31 03:45:53 | [diff] [blame] | 66 | .then(() => { |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 67 | assert_equals(pc2.signalingState, 'have-remote-offer'); |
| 68 | assert_session_desc_equals(pc2.remoteDescription, offer); |
| 69 | assert_session_desc_equals(pc2.pendingRemoteDescription, offer); |
| 70 | assert_equals(pc2.currentRemoteDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 71 | |
| Henrik Boström | 6c78554 | 2018-06-11 13:36:22 | [diff] [blame] | 72 | assert_array_equals(states, ['have-remote-offer']); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 73 | }); |
| 74 | }); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 75 | }, 'setRemoteDescription with valid offer should succeed'); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 76 | |
| 77 | promise_test(t => { |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 78 | const pc1 = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 79 | t.add_cleanup(() => pc1.close()); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 80 | pc1.createDataChannel('datachannel'); |
| 81 | |
| 82 | const pc2 = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 83 | t.add_cleanup(() => pc2.close()); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 84 | |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 85 | const states = []; |
| 86 | pc2.addEventListener('signalingstatechange', () => states.push(pc2.signalingState)); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 87 | |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 88 | return pc1.createOffer() |
| 89 | .then(offer => { |
| 90 | return pc2.setRemoteDescription(offer) |
| 91 | .then(() => pc2.setRemoteDescription(offer)) |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 92 | .then(() => { |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 93 | assert_equals(pc2.signalingState, 'have-remote-offer'); |
| 94 | assert_session_desc_equals(pc2.remoteDescription, offer); |
| 95 | assert_session_desc_equals(pc2.pendingRemoteDescription, offer); |
| 96 | assert_equals(pc2.currentRemoteDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 97 | |
| 98 | assert_array_equals(states, ['have-remote-offer']); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 99 | }); |
| 100 | }); |
| 101 | }, 'setRemoteDescription multiple times should succeed'); |
| 102 | |
| 103 | promise_test(t => { |
| 104 | const pc1 = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 105 | t.add_cleanup(() => pc1.close()); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 106 | pc1.createDataChannel('datachannel'); |
| 107 | |
| 108 | const pc2 = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 109 | t.add_cleanup(() => pc2.close()); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 110 | |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 111 | const states = []; |
| 112 | pc2.addEventListener('signalingstatechange', () => states.push(pc2.signalingState)); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 113 | |
| 114 | return pc1.createOffer() |
| 115 | .then(offer1 => { |
| 116 | return pc1.setLocalDescription(offer1) |
| 117 | .then(()=> { |
| 118 | return pc1.createOffer({ offerToReceiveAudio: true }) |
| 119 | .then(offer2 => { |
| 120 | assert_session_desc_not_equals(offer1, offer2); |
| 121 | |
| 122 | return pc2.setRemoteDescription(offer1) |
| 123 | .then(() => pc2.setRemoteDescription(offer2)) |
| 124 | .then(() => { |
| 125 | assert_equals(pc2.signalingState, 'have-remote-offer'); |
| 126 | assert_session_desc_equals(pc2.remoteDescription, offer2); |
| 127 | assert_session_desc_equals(pc2.pendingRemoteDescription, offer2); |
| 128 | assert_equals(pc2.currentRemoteDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 129 | |
| 130 | assert_array_equals(states, ['have-remote-offer']); |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 131 | }); |
| 132 | }); |
| 133 | }); |
| 134 | }); |
| 135 | }, 'setRemoteDescription multiple times with different offer should succeed'); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | 4.3.1.6. Set the RTCSessionSessionDescription |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 139 | 2.1.4. If the content of description is not valid SDP syntax, then reject p with |
| 140 | an RTCError (with errorDetail set to "sdp-syntax-error" and the |
| 141 | sdpLineNumber attribute set to the line number in the SDP where the syntax |
| 142 | error was detected) and abort these steps. |
| 143 | */ |
| 144 | promise_test(t => { |
| 145 | const pc = new RTCPeerConnection(); |
| 146 | |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 147 | t.add_cleanup(() => pc.close()); |
| 148 | |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 149 | return pc.setRemoteDescription({ |
| 150 | type: 'offer', |
| 151 | sdp: 'Invalid SDP' |
| 152 | }) |
| 153 | .then(() => { |
| 154 | assert_unreached('Expect promise to be rejected'); |
| 155 | }, err => { |
| 156 | assert_equals(err.errorDetail, 'sdp-syntax-error', |
| 157 | 'Expect error detail field to set to sdp-syntax-error'); |
| 158 | |
| 159 | assert_true(err instanceof RTCError, |
| 160 | 'Expect err to be instance of RTCError'); |
| 161 | }); |
| 162 | }, 'setRemoteDescription(offer) with invalid SDP should reject with RTCError'); |
| 163 | |
| 164 | /* |
| 165 | 4.3.1.6. Set the RTCSessionSessionDescription |
| 166 | 2.1.3. If the description's type is invalid for the current signaling state of |
| 167 | connection, then reject p with a newly created InvalidStateError and abort |
| 168 | these steps. |
| 169 | |
| 170 | [JSEP] |
| 171 | 5.6. If the type is "offer", the PeerConnection state MUST be either "stable" or |
| 172 | "have-remote-offer". |
| 173 | */ |
| 174 | promise_test(t => { |
| 175 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 176 | t.add_cleanup(() => pc.close()); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 177 | return pc.createOffer() |
| Zhi Huang | 7a384ee | 2017-10-26 19:09:48 | [diff] [blame] | 178 | .then(offer => { |
| 179 | return pc.setLocalDescription(offer) |
| 180 | .then(() => { |
| 181 | return promise_rejects(t, 'InvalidStateError', |
| 182 | pc.setRemoteDescription(offer)); |
| 183 | }); |
| 184 | }); |
| 185 | }, 'setRemoteDescription(offer) from have-local-offer state should reject with InvalidStateError'); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 186 | |
| 187 | </script> |