| Philipp Hancke | b7014f7 | 2017-02-27 13:24:20 | [diff] [blame] | 1 | <!doctype html> |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 2 | <meta charset=utf-8> |
| 3 | <title>RTCPeerConnection.prototype.setRemoteDescription</title> |
| 4 | <script src="/resources/testharness.js"></script> |
| 5 | <script src="/resources/testharnessreport.js"></script> |
| 6 | <script src="RTCPeerConnection-helper.js"></script> |
| 7 | <script> |
| Soares Chen | 0f17643 | 2017-05-04 04:40:47 | [diff] [blame] | 8 | 'use strict'; |
| 9 | |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 10 | // Test is based on the following editor draft: |
| Soares Chen | a01b1e5 | 2017-07-07 09:52:03 | [diff] [blame] | 11 | // https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 12 | |
| Rick Waldron | 1c5c05d | 2017-06-07 17:54:42 | [diff] [blame] | 13 | // The following helper functions are called from RTCPeerConnection-helper.js: |
| 14 | // generateOffer() |
| 15 | // generateAnswer() |
| 16 | // assert_session_desc_not_equals() |
| 17 | // assert_session_desc_equals() |
| 18 | // test_state_change_event() |
| Rick Waldron | 1c5c05d | 2017-06-07 17:54:42 | [diff] [blame] | 19 | |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 20 | /* |
| Soares Chen | a01b1e5 | 2017-07-07 09:52:03 | [diff] [blame] | 21 | 4.3.2. Interface Definition |
| 22 | [Constructor(optional RTCConfiguration configuration)] |
| 23 | interface RTCPeerConnection : EventTarget { |
| 24 | Promise<void> setRemoteDescription( |
| 25 | RTCSessionDescriptionInit description); |
| 26 | |
| 27 | readonly attribute RTCSessionDescription? remoteDescription; |
| 28 | readonly attribute RTCSessionDescription? currentRemoteDescription; |
| 29 | readonly attribute RTCSessionDescription? pendingRemoteDescription; |
| 30 | ... |
| 31 | }; |
| 32 | |
| 33 | 4.6.2. RTCSessionDescription Class |
| 34 | dictionary RTCSessionDescriptionInit { |
| 35 | required RTCSdpType type; |
| 36 | DOMString sdp = ""; |
| 37 | }; |
| 38 | |
| 39 | 4.6.1. RTCSdpType |
| 40 | enum RTCSdpType { |
| 41 | "offer", |
| 42 | "pranswer", |
| 43 | "answer", |
| 44 | "rollback" |
| 45 | }; |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 46 | */ |
| 47 | |
| Soares Chen | a01b1e5 | 2017-07-07 09:52:03 | [diff] [blame] | 48 | /* |
| Soares Chen | a01b1e5 | 2017-07-07 09:52:03 | [diff] [blame] | 49 | 4.6.1. enum RTCSdpType |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 50 | */ |
| 51 | promise_test(t => { |
| 52 | const pc = new RTCPeerConnection(); |
| 53 | |
| 54 | // SDP is validated after WebIDL validation |
| 55 | return promise_rejects(t, new TypeError(), |
| 56 | pc.setRemoteDescription({ |
| 57 | type: 'bogus', |
| 58 | sdp: 'bogus' |
| 59 | })); |
| 60 | }, 'setRemoteDescription with invalid type and invalid SDP should reject with TypeError') |
| 61 | |
| 62 | promise_test(t => { |
| 63 | const pc = new RTCPeerConnection(); |
| 64 | |
| 65 | // SDP is validated after validating type |
| 66 | return promise_rejects(t, 'InvalidStateError', |
| 67 | pc.setRemoteDescription({ |
| 68 | type: 'answer', |
| 69 | sdp: 'invalid' |
| 70 | })); |
| 71 | }, 'setRemoteDescription() with invalid SDP and stable state should reject with InvalidStateError') |
| 72 | |
| Soares Chen | a01b1e5 | 2017-07-07 09:52:03 | [diff] [blame] | 73 | /* Operations after returning to stable state */ |
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 74 | |
| 75 | promise_test(t => { |
| 76 | const pc = new RTCPeerConnection(); |
| 77 | const pc2 = new RTCPeerConnection(); |
| 78 | |
| 79 | test_state_change_event(t, pc, |
| 80 | ['have-remote-offer', 'stable', 'have-remote-offer']); |
| 81 | |
| 82 | return generateOffer({ audio: true }) |
| 83 | .then(offer1 => |
| 84 | pc.setRemoteDescription(offer1) |
| 85 | .then(() => pc.createAnswer()) |
| 86 | .then(answer => pc.setLocalDescription(answer)) |
| 87 | .then(() => generateOffer({ data: true })) |
| 88 | .then(offer2 => |
| 89 | pc.setRemoteDescription(offer2) |
| 90 | .then(() => { |
| 91 | assert_equals(pc.signalingState, 'have-remote-offer'); |
| 92 | assert_session_desc_not_equals(offer1, offer2); |
| 93 | assert_session_desc_equals(pc.remoteDescription, offer2); |
| 94 | assert_session_desc_equals(pc.currentRemoteDescription, offer1); |
| 95 | assert_session_desc_equals(pc.pendingRemoteDescription, offer2); |
| 96 | }))); |
| 97 | }, 'Calling setRemoteDescription() again after one round of remote-offer/local-answer should succeed'); |
| 98 | |
| 99 | promise_test(t => { |
| 100 | const pc = new RTCPeerConnection(); |
| 101 | |
| 102 | test_state_change_event(t, pc, |
| 103 | ['have-local-offer', 'stable', 'have-remote-offer']); |
| 104 | |
| 105 | return pc.createOffer({ offerToReceiveAudio: true }) |
| 106 | .then(offer => |
| 107 | pc.setLocalDescription(offer) |
| 108 | .then(() => generateAnswer(offer))) |
| 109 | .then(answer => |
| 110 | pc.setRemoteDescription(answer) |
| 111 | .then(() => generateOffer({ data: true })) |
| 112 | .then(offer => |
| 113 | pc.setRemoteDescription(offer) |
| 114 | .then(() => { |
| 115 | assert_equals(pc.signalingState, 'have-remote-offer'); |
| 116 | assert_session_desc_equals(pc.remoteDescription, offer); |
| 117 | assert_session_desc_equals(pc.currentRemoteDescription, answer); |
| 118 | assert_session_desc_equals(pc.pendingRemoteDescription, offer); |
| 119 | }))); |
| 120 | }, 'Switching role from offerer to answerer after going back to stable state should succeed'); |
| 121 | |
| 122 | /* |
| Soares Chen | a01b1e5 | 2017-07-07 09:52:03 | [diff] [blame] | 123 | TODO |
| 124 | 4.3.2. setRemoteDescription |
| 125 | - If an a=identity attribute is present in the session description, the browser |
| 126 | validates the identity assertion. |
| 127 | */ |
| Soares Chen | 0f17643 | 2017-05-04 04:40:47 | [diff] [blame] | 128 | |
| Philipp Hancke | b7014f7 | 2017-02-27 13:24:20 | [diff] [blame] | 129 | </script> |