blob: 7dbcb3a8a8cbfef0f353e442bf9170ebc820946f [file] [log] [blame]
Soares Chen363f1252017-07-10 09:22:151<!doctype html>
2<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.setRemoteDescription - offer</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()
Soares Chen363f1252017-07-10 09:22:1515 // assert_session_desc_equals()
16 // test_state_change_event()
Soares Chen363f1252017-07-10 09:22:1517
18 /*
19 4.3.2. Interface Definition
20 [Constructor(optional RTCConfiguration configuration)]
21 interface RTCPeerConnection : EventTarget {
22 Promise<void> setRemoteDescription(
23 RTCSessionDescriptionInit description);
24
25 readonly attribute RTCSessionDescription? remoteDescription;
26 readonly attribute RTCSessionDescription? currentRemoteDescription;
27 readonly attribute RTCSessionDescription? pendingRemoteDescription;
28 ...
29 };
30
31 4.6.2. RTCSessionDescription Class
32 dictionary RTCSessionDescriptionInit {
33 required RTCSdpType type;
34 DOMString sdp = "";
35 };
36
37 4.6.1. RTCSdpType
38 enum RTCSdpType {
39 "offer",
40 "pranswer",
41 "answer",
42 "rollback"
43 };
44 */
45
46 /*
47 4.3.1.6. Set the RTCSessionSessionDescription
48 2.2.3. Otherwise, if description is set as a remote description, then run one of
49 the following steps:
50 - If description is of type "offer", set connection.pendingRemoteDescription
51 attribute to description and signaling state to have-remote-offer.
52 */
53 promise_test(t => {
54 const pc = new RTCPeerConnection();
55
56 test_state_change_event(t, pc, ['have-remote-offer']);
57
58 return generateOffer({ data: true })
59 .then(offer =>
60 pc.setRemoteDescription(offer)
Nils Ohlmeier4b1563d2017-08-31 03:45:5361 .then(() => {
Soares Chen363f1252017-07-10 09:22:1562 assert_equals(pc.signalingState, 'have-remote-offer');
63 assert_session_desc_equals(pc.remoteDescription, offer);
64 assert_session_desc_equals(pc.pendingRemoteDescription, offer);
65 assert_equals(pc.currentRemoteDescription, null);
66 }));
67 }, 'setRemoteDescription with valid offer should succeed');
68
69 promise_test(t => {
70 const pc = new RTCPeerConnection();
71
72 // have-remote-offer event should only fire once
73 test_state_change_event(t, pc, ['have-remote-offer']);
74
75 return Promise.all([
76 generateOffer({ audio: true }),
77 generateOffer({ data: true })
78 ]).then(([offer1, offer2]) =>
79 pc.setRemoteDescription(offer1)
80 .then(() => pc.setRemoteDescription(offer2))
81 .then(() => {
82 assert_equals(pc.signalingState, 'have-remote-offer');
83 assert_session_desc_equals(pc.remoteDescription, offer2);
84 assert_session_desc_equals(pc.pendingRemoteDescription, offer2);
85 assert_equals(pc.currentRemoteDescription, null);
86 }));
87 }, 'Setting remote description multiple times with different offer should succeed');
88
89 /*
90 4.3.1.6. Set the RTCSessionSessionDescription
Soares Chen363f1252017-07-10 09:22:1591 2.1.4. If the content of description is not valid SDP syntax, then reject p with
92 an RTCError (with errorDetail set to "sdp-syntax-error" and the
93 sdpLineNumber attribute set to the line number in the SDP where the syntax
94 error was detected) and abort these steps.
95 */
96 promise_test(t => {
97 const pc = new RTCPeerConnection();
98
99 return pc.setRemoteDescription({
100 type: 'offer',
101 sdp: 'Invalid SDP'
102 })
103 .then(() => {
104 assert_unreached('Expect promise to be rejected');
105 }, err => {
106 assert_equals(err.errorDetail, 'sdp-syntax-error',
107 'Expect error detail field to set to sdp-syntax-error');
108
109 assert_true(err instanceof RTCError,
110 'Expect err to be instance of RTCError');
111 });
112 }, 'setRemoteDescription(offer) with invalid SDP should reject with RTCError');
113
114 /*
115 4.3.1.6. Set the RTCSessionSessionDescription
116 2.1.3. If the description's type is invalid for the current signaling state of
117 connection, then reject p with a newly created InvalidStateError and abort
118 these steps.
119
120 [JSEP]
121 5.6. If the type is "offer", the PeerConnection state MUST be either "stable" or
122 "have-remote-offer".
123 */
124 promise_test(t => {
125 const pc = new RTCPeerConnection();
126
127 return pc.createOffer()
128 .then(offer => pc.setLocalDescription(offer))
129 .then(() => generateOffer())
Nils Ohlmeier4b1563d2017-08-31 03:45:53130 .then(offer2 =>
Soares Chen363f1252017-07-10 09:22:15131 promise_rejects(t, 'InvalidStateError',
Nils Ohlmeier4b1563d2017-08-31 03:45:53132 pc.setRemoteDescription(offer2)));
Soares Chen363f1252017-07-10 09:22:15133 }, 'Calling setRemoteDescription(offer) from have-local-offer state should reject with InvalidStateError');
134
135</script>