| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <meta charset=utf-8> |
| 3 | <title>RTCPeerConnection.prototype.setLocalDescription rollback</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 | // assert_session_desc_equals |
| 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.2.2. If description is set as a local description, then run one of the |
| 54 | following steps: |
| 55 | - If description is of type "rollback", then this is a rollback. Set |
| 56 | connection.pendingLocalDescription to null and signaling state to stable. |
| 57 | */ |
| 58 | promise_test(t=> { |
| 59 | const pc = new RTCPeerConnection(); |
| 60 | |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame^] | 61 | const states = []; |
| 62 | pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState)); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 63 | |
| 64 | return pc.createOffer() |
| 65 | .then(offer => pc.setLocalDescription(offer)) |
| 66 | .then(() => { |
| 67 | assert_equals(pc.signalingState, 'have-local-offer'); |
| 68 | assert_not_equals(pc.localDescription, null); |
| 69 | assert_not_equals(pc.pendingLocalDescription, null); |
| 70 | assert_equals(pc.currentLocalDescription, null); |
| 71 | |
| 72 | return pc.setLocalDescription({ type: 'rollback' }); |
| 73 | }) |
| 74 | .then(() => { |
| 75 | assert_equals(pc.signalingState, 'stable'); |
| 76 | assert_equals(pc.localDescription, null); |
| 77 | assert_equals(pc.pendingLocalDescription, null); |
| 78 | assert_equals(pc.currentLocalDescription, null); |
| Philipp Hancke | eb37a99 | 2018-05-30 15:55:02 | [diff] [blame^] | 79 | |
| 80 | assert_array_equals(states, ['have-local-offer', 'stable']); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 81 | }); |
| 82 | }, 'setLocalDescription(rollback) from have-local-offer state should reset back to stable state'); |
| 83 | |
| Soares Chen | c94ef3e | 2017-07-14 05:20:20 | [diff] [blame] | 84 | /* |
| 85 | 4.3.1.6. Set the RTCSessionSessionDescription |
| 86 | 2.3. If the description's type is invalid for the current signaling state of |
| 87 | connection, then reject p with a newly created InvalidStateError and abort |
| 88 | these steps. Note that this implies that once the answerer has performed |
| 89 | setLocalDescription with his answer, this cannot be rolled back. |
| 90 | |
| 91 | [jsep] |
| 92 | 4.1.8.2. Rollback |
| 93 | - Rollback can only be used to cancel proposed changes; |
| 94 | there is no support for rolling back from a stable state to a |
| 95 | previous stable state |
| 96 | */ |
| 97 | promise_test(t => { |
| 98 | const pc = new RTCPeerConnection(); |
| 99 | return promise_rejects(t, 'InvalidStateError', |
| 100 | pc.setLocalDescription({ type: 'rollback' })); |
| 101 | }, `setLocalDescription(rollback) from stable state should reject with InvalidStateError`); |
| 102 | |
| 103 | promise_test(t => { |
| 104 | const pc = new RTCPeerConnection(); |
| Rick Waldron | 5445fa3 | 2017-08-30 21:53:59 | [diff] [blame] | 105 | return pc.createOffer({ offerToReceiveAudio: true }) |
| Soares Chen | c94ef3e | 2017-07-14 05:20:20 | [diff] [blame] | 106 | .then(offer => |
| 107 | pc.setRemoteDescription(offer) |
| 108 | .then(() => pc.createAnswer())) |
| 109 | .then(answer => pc.setLocalDescription(answer)) |
| 110 | .then(() => { |
| 111 | return promise_rejects(t, 'InvalidStateError', |
| 112 | pc.setLocalDescription({ type: 'rollback' })); |
| 113 | }); |
| 114 | }, `setLocalDescription(rollback) after setting answer description should reject with InvalidStateError`); |
| 115 | |
| 116 | promise_test(t => { |
| 117 | const pc = new RTCPeerConnection(); |
| 118 | return pc.createOffer() |
| 119 | .then(offer => pc.setLocalDescription(offer)) |
| 120 | .then(() => pc.setLocalDescription({ |
| 121 | type: 'rollback', |
| 122 | sdp: '!<Invalid SDP Content>;' |
| 123 | })); |
| 124 | }, `setLocalDescription(rollback) should ignore invalid sdp content and succeed`); |
| Soares Chen | 5dbbd5f | 2017-07-10 09:56:09 | [diff] [blame] | 125 | </script> |