| 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 | })); | 
| Soares Chen | adb6176 | 2017-08-31 07:51:38 | [diff] [blame^] | 60 | }, 'setRemoteDescription with invalid type and invalid SDP should reject with TypeError'); | 
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 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 | })); | 
| Soares Chen | adb6176 | 2017-08-31 07:51:38 | [diff] [blame^] | 71 | }, 'setRemoteDescription() with invalid SDP and stable state should reject with InvalidStateError'); | 
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 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 |  | 
| Soares Chen | adb6176 | 2017-08-31 07:51:38 | [diff] [blame^] | 82 | return pc2.createOffer({ offerToReceiveAudio: true }) | 
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 83 | .then(offer1 => | 
|  | 84 | pc.setRemoteDescription(offer1) | 
|  | 85 | .then(() => pc.createAnswer()) | 
|  | 86 | .then(answer => pc.setLocalDescription(answer)) | 
| Soares Chen | adb6176 | 2017-08-31 07:51:38 | [diff] [blame^] | 87 | .then(() => pc2.createOffer({ offerToReceiveVideo: true })) | 
|  | 88 | .then(offer2 => { | 
|  | 89 | return pc.setRemoteDescription(offer2) | 
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 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); | 
| Soares Chen | adb6176 | 2017-08-31 07:51:38 | [diff] [blame^] | 96 | }); | 
|  | 97 | })); | 
| Soares Chen | fda8782 | 2017-06-05 14:00:30 | [diff] [blame] | 98 | }, 'Calling setRemoteDescription() again after one round of remote-offer/local-answer should succeed'); | 
|  | 99 |  | 
|  | 100 | promise_test(t => { | 
|  | 101 | const pc = new RTCPeerConnection(); | 
|  | 102 |  | 
|  | 103 | test_state_change_event(t, pc, | 
|  | 104 | ['have-local-offer', 'stable', 'have-remote-offer']); | 
|  | 105 |  | 
|  | 106 | return pc.createOffer({ offerToReceiveAudio: true }) | 
|  | 107 | .then(offer => | 
|  | 108 | pc.setLocalDescription(offer) | 
|  | 109 | .then(() => generateAnswer(offer))) | 
|  | 110 | .then(answer => | 
|  | 111 | pc.setRemoteDescription(answer) | 
|  | 112 | .then(() => generateOffer({ data: true })) | 
|  | 113 | .then(offer => | 
|  | 114 | pc.setRemoteDescription(offer) | 
|  | 115 | .then(() => { | 
|  | 116 | assert_equals(pc.signalingState, 'have-remote-offer'); | 
|  | 117 | assert_session_desc_equals(pc.remoteDescription, offer); | 
|  | 118 | assert_session_desc_equals(pc.currentRemoteDescription, answer); | 
|  | 119 | assert_session_desc_equals(pc.pendingRemoteDescription, offer); | 
|  | 120 | }))); | 
|  | 121 | }, 'Switching role from offerer to answerer after going back to stable state should succeed'); | 
|  | 122 |  | 
|  | 123 | /* | 
| Soares Chen | a01b1e5 | 2017-07-07 09:52:03 | [diff] [blame] | 124 | TODO | 
|  | 125 | 4.3.2. setRemoteDescription | 
|  | 126 | - If an a=identity attribute is present in the session description, the browser | 
|  | 127 | validates the identity assertion. | 
|  | 128 | */ | 
| Soares Chen | 0f17643 | 2017-05-04 04:40:47 | [diff] [blame] | 129 |  | 
| Philipp Hancke | b7014f7 | 2017-02-27 13:24:20 | [diff] [blame] | 130 | </script> |