| 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: |
| 14 | // generateOffer |
| 15 | // generateAnswer |
| 16 | // assert_session_desc_equals |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | 4.3.2. Interface Definition |
| 20 | [Constructor(optional RTCConfiguration configuration)] |
| 21 | interface RTCPeerConnection : EventTarget { |
| 22 | Promise<void> setLocalDescription( |
| 23 | RTCSessionDescriptionInit description); |
| 24 | |
| 25 | readonly attribute RTCSessionDescription? localDescription; |
| 26 | readonly attribute RTCSessionDescription? currentLocalDescription; |
| 27 | readonly attribute RTCSessionDescription? pendingLocalDescription; |
| 28 | |
| 29 | Promise<void> setRemoteDescription( |
| 30 | RTCSessionDescriptionInit description); |
| 31 | |
| 32 | readonly attribute RTCSessionDescription? remoteDescription; |
| 33 | readonly attribute RTCSessionDescription? currentRemoteDescription; |
| 34 | readonly attribute RTCSessionDescription? pendingRemoteDescription; |
| 35 | ... |
| 36 | }; |
| 37 | |
| 38 | 4.6.2. RTCSessionDescription Class |
| 39 | dictionary RTCSessionDescriptionInit { |
| 40 | required RTCSdpType type; |
| 41 | DOMString sdp = ""; |
| 42 | }; |
| 43 | |
| 44 | 4.6.1. RTCSdpType |
| 45 | enum RTCSdpType { |
| 46 | "offer", |
| 47 | "pranswer", |
| 48 | "answer", |
| 49 | "rollback" |
| 50 | }; |
| 51 | */ |
| 52 | |
| 53 | /* |
| 54 | 4.3.1.6. Set the RTCSessionSessionDescription |
| 55 | 2.3. If the description's type is invalid for the current signaling state of |
| 56 | connection, then reject p with a newly created InvalidStateError and abort |
| 57 | these steps. |
| 58 | |
| 59 | [jsep] |
| 60 | 5.5. If the type is "pranswer" or "answer", the PeerConnection |
| 61 | state MUST be either "have-remote-offer" or "have-local-pranswer". |
| 62 | */ |
| 63 | promise_test(t => { |
| 64 | const pc = new RTCPeerConnection(); |
| 65 | |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame^] | 66 | t.add_cleanup(() => pc.close()); |
| 67 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 68 | return pc.createOffer() |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 69 | .then(offer => |
| 70 | promise_rejects(t, 'InvalidStateError', |
| 71 | pc.setLocalDescription({ type: 'pranswer', sdp: offer.sdp }))); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 72 | }, 'setLocalDescription(pranswer) from stable state should reject with InvalidStateError'); |
| 73 | |
| 74 | /* |
| 75 | 4.3.1.6 Set the RTCSessionSessionDescription |
| 76 | 2.2.2. If description is set as a local description, then run one of the |
| 77 | following steps: |
| 78 | - If description is of type "pranswer", then set |
| 79 | connection.pendingLocalDescription to description and signaling state to |
| 80 | have-local-pranswer. |
| 81 | */ |
| 82 | promise_test(t => { |
| 83 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame^] | 84 | t.add_cleanup(() => pc.close()); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 85 | |
| 86 | const states = []; |
| 87 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 88 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 89 | return pc.createOffer({ offerToReceiveVideo: true }) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 90 | .then(offer => |
| 91 | pc.setRemoteDescription(offer) |
| 92 | .then(() => pc.createAnswer()) |
| 93 | .then(answer => { |
| 94 | const pranswer = { type: 'pranswer', sdp: answer.sdp }; |
| 95 | |
| 96 | return pc.setLocalDescription(pranswer) |
| 97 | .then(() => { |
| 98 | assert_equals(pc.signalingState, 'have-local-pranswer'); |
| 99 | |
| 100 | assert_session_desc_equals(pc.remoteDescription, offer); |
| 101 | assert_session_desc_equals(pc.pendingRemoteDescription, offer); |
| 102 | assert_equals(pc.currentRemoteDescription, null); |
| 103 | |
| 104 | assert_session_desc_equals(pc.localDescription, pranswer); |
| 105 | assert_session_desc_equals(pc.pendingLocalDescription, pranswer); |
| 106 | assert_equals(pc.currentLocalDescription, null); |
| 107 | |
| 108 | assert_equals(pc.pendingRemoteDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 109 | |
| 110 | assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 111 | }); |
| 112 | })); |
| 113 | }, 'setLocalDescription(pranswer) should succeed'); |
| 114 | |
| 115 | promise_test(t => { |
| 116 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame^] | 117 | t.add_cleanup(() => pc.close()); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 118 | |
| 119 | const states = []; |
| 120 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 121 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 122 | return pc.createOffer({ offerToReceiveVideo: true }) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 123 | .then(offer => |
| 124 | pc.setRemoteDescription(offer) |
| 125 | .then(() => pc.createAnswer()) |
| 126 | .then(answer => { |
| 127 | const pranswer = { type: 'pranswer', sdp: answer.sdp }; |
| 128 | |
| 129 | return pc.setLocalDescription(pranswer) |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 130 | .then(() => pc.setLocalDescription(pranswer)) |
| 131 | .then(() => { |
| 132 | assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']); |
| 133 | }); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 134 | })); |
| 135 | }, 'setLocalDescription(pranswer) can be applied multiple times while still in have-local-pranswer'); |
| 136 | |
| 137 | promise_test(t => { |
| 138 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame^] | 139 | t.add_cleanup(() => pc.close()); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 140 | |
| 141 | const states = []; |
| 142 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 143 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 144 | return pc.createOffer({ offerToReceiveVideo: true }) |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 145 | .then(offer => |
| 146 | pc.setRemoteDescription(offer) |
| 147 | .then(() => pc.createAnswer()) |
| 148 | .then(answer => { |
| 149 | const pranswer = { type: 'pranswer', sdp: answer.sdp }; |
| 150 | |
| 151 | return pc.setLocalDescription(pranswer) |
| 152 | .then(() => pc.setLocalDescription(answer)) |
| 153 | .then(() => { |
| 154 | assert_equals(pc.signalingState, 'stable'); |
| 155 | assert_session_desc_equals(pc.localDescription, answer); |
| 156 | assert_session_desc_equals(pc.remoteDescription, offer); |
| 157 | |
| 158 | assert_session_desc_equals(pc.currentLocalDescription, answer); |
| 159 | assert_session_desc_equals(pc.currentRemoteDescription, offer); |
| 160 | |
| 161 | assert_equals(pc.pendingLocalDescription, null); |
| 162 | assert_equals(pc.pendingRemoteDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 163 | |
| 164 | assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer', 'stable']); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 165 | }); |
| 166 | })); |
| 167 | }, 'setLocalDescription(answer) from have-local-pranswer state should succeed'); |
| 168 | |
| 169 | </script> |