| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <meta charset=utf-8> |
| 3 | <title>RTCPeerConnection.prototype.setRemoteDescription - answer</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 | // generateAnswer() |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 15 | // assert_session_desc_similar() |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | 4.3.2. Interface Definition |
| 19 | [Constructor(optional RTCConfiguration configuration)] |
| 20 | interface RTCPeerConnection : EventTarget { |
| 21 | Promise<void> setRemoteDescription( |
| 22 | RTCSessionDescriptionInit description); |
| 23 | |
| 24 | readonly attribute RTCSessionDescription? remoteDescription; |
| 25 | readonly attribute RTCSessionDescription? currentRemoteDescription; |
| 26 | readonly attribute RTCSessionDescription? pendingRemoteDescription; |
| 27 | ... |
| 28 | }; |
| 29 | |
| 30 | 4.6.2. RTCSessionDescription Class |
| 31 | dictionary RTCSessionDescriptionInit { |
| 32 | required RTCSdpType type; |
| 33 | DOMString sdp = ""; |
| 34 | }; |
| 35 | |
| 36 | 4.6.1. RTCSdpType |
| 37 | enum RTCSdpType { |
| 38 | "offer", |
| 39 | "pranswer", |
| 40 | "answer", |
| 41 | "rollback" |
| 42 | }; |
| 43 | */ |
| 44 | |
| 45 | /* |
| 46 | 4.3.1.6. Set the RTCSessionSessionDescription |
| 47 | 2.2.3. Otherwise, if description is set as a remote description, then run one of |
| 48 | the following steps: |
| 49 | - If description is of type "answer", then this completes an offer answer |
| 50 | negotiation. |
| 51 | |
| 52 | Set connection's currentRemoteDescription to description and |
| 53 | currentLocalDescription to the value of pendingLocalDescription. |
| 54 | |
| 55 | Set both pendingRemoteDescription and pendingLocalDescription to null. |
| 56 | |
| 57 | Finally setconnection's signaling state to stable. |
| 58 | */ |
| 59 | promise_test(t => { |
| 60 | const pc = new RTCPeerConnection(); |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 61 | t.add_cleanup(() => pc.close()); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 62 | |
| 63 | const states = []; |
| 64 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 65 | |
| Youenn Fablet | 7b16358 | 2018-11-04 07:30:59 | [diff] [blame] | 66 | return generateVideoReceiveOnlyOffer(pc) |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 67 | .then(offer => |
| 68 | pc.setLocalDescription(offer) |
| 69 | .then(() => generateAnswer(offer)) |
| 70 | .then(answer => |
| 71 | pc.setRemoteDescription(answer) |
| 72 | .then(() => { |
| 73 | assert_equals(pc.signalingState, 'stable'); |
| 74 | |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 75 | assert_session_desc_similar(pc.localDescription, offer); |
| 76 | assert_session_desc_similar(pc.remoteDescription, answer); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 77 | |
| Jan-Ivar Bruaroey | 6d3fda5 | 2018-07-04 13:49:09 | [diff] [blame] | 78 | assert_session_desc_similar(pc.currentLocalDescription, offer); |
| 79 | assert_session_desc_similar(pc.currentRemoteDescription, answer); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 80 | |
| 81 | assert_equals(pc.pendingLocalDescription, null); |
| 82 | assert_equals(pc.pendingRemoteDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame] | 83 | |
| 84 | assert_array_equals(states, ['have-local-offer', 'stable']); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 85 | }))); |
| 86 | }, 'setRemoteDescription() with valid state and answer should succeed'); |
| 87 | |
| 88 | /* |
| 89 | 4.3.1.6. Set the RTCSessionSessionDescription |
| 90 | 2.1.3. If the description's type is invalid for the current signaling state of |
| 91 | connection, then reject p with a newly created InvalidStateError and abort |
| 92 | these steps. |
| 93 | |
| 94 | [JSEP] |
| 95 | 5.6. If the type is "answer", the PeerConnection state MUST be either |
| 96 | "have-local-offer" or "have-remote-pranswer". |
| 97 | */ |
| 98 | promise_test(t => { |
| 99 | const pc = new RTCPeerConnection(); |
| 100 | |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 101 | t.add_cleanup(() => pc.close()); |
| 102 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 103 | return pc.createOffer() |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 104 | .then(offer => |
| 105 | promise_rejects(t, 'InvalidStateError', |
| 106 | pc.setRemoteDescription({ type: 'answer', sdp: offer.sdp }))); |
| 107 | }, 'Calling setRemoteDescription(answer) from stable state should reject with InvalidStateError'); |
| 108 | |
| 109 | promise_test(t => { |
| 110 | const pc = new RTCPeerConnection(); |
| 111 | |
| Philipp Hancke | 1622a02 | 2018-06-11 10:00:53 | [diff] [blame] | 112 | t.add_cleanup(() => pc.close()); |
| 113 | |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 114 | return pc.createOffer() |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 115 | .then(offer => |
| 116 | pc.setRemoteDescription(offer) |
| 117 | .then(() => generateAnswer(offer))) |
| 118 | .then(answer => |
| 119 | promise_rejects(t, 'InvalidStateError', |
| 120 | pc.setRemoteDescription(answer))); |
| Soares Chen | 363f125 | 2017-07-10 09:22:15 | [diff] [blame] | 121 | }, 'Calling setRemoteDescription(answer) from have-remote-offer state should reject with InvalidStateError'); |
| 122 | |
| 123 | </script> |