blob: d1073c85f5b77bc35bdf291d34f58cde7b20aafb [file] [log] [blame]
Soares Chen5dbbd5f2017-07-10 09:56:091<!doctype html>
2<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.setRemoteDescription pranswer</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
15 // generateAnswer
16 // assert_session_desc_equals
Soares Chen5dbbd5f2017-07-10 09:56:0917
18 /*
19 4.3.2. Interface Definition
20 [Constructor(optional RTCConfiguration configuration)]
21 interface RTCPeerConnection : EventTarget {
22 Promise<void> setLocalDescription(
23 RTCSessionDescriptionInit description);
24
25 readonly attribute RTCSessionDescription? localDescription;
26 readonly attribute RTCSessionDescription? currentLocalDescription;
27 readonly attribute RTCSessionDescription? pendingLocalDescription;
28
29 Promise<void> setRemoteDescription(
30 RTCSessionDescriptionInit description);
31
32 readonly attribute RTCSessionDescription? remoteDescription;
33 readonly attribute RTCSessionDescription? currentRemoteDescription;
34 readonly attribute RTCSessionDescription? pendingRemoteDescription;
35 ...
36 };
37
38 4.6.2. RTCSessionDescription Class
39 dictionary RTCSessionDescriptionInit {
40 required RTCSdpType type;
41 DOMString sdp = "";
42 };
43
44 4.6.1. RTCSdpType
45 enum RTCSdpType {
46 "offer",
47 "pranswer",
48 "answer",
49 "rollback"
50 };
51 */
52
53 /*
54 4.3.1.6. Set the RTCSessionSessionDescription
55 2.1.3. If the description's type is invalid for the current signaling state of
56 connection, then reject p with a newly created InvalidStateError and abort
57 these steps.
58
59 [JSEP]
60 5.6. If the type is "pranswer" or "answer", the PeerConnection state MUST be either
61 "have-local-offer" or "have-remote-pranswer".
62 */
63 promise_test(t => {
64 const pc = new RTCPeerConnection();
65
Philipp Hancke1622a022018-06-11 10:00:5366 t.add_cleanup(() => pc.close());
67
Rick Waldron5445fa32017-08-30 21:53:5968 return pc.createOffer()
Soares Chen5dbbd5f2017-07-10 09:56:0969 .then(offer =>
70 promise_rejects(t, 'InvalidStateError',
71 pc.setRemoteDescription({ type: 'pranswer', sdp: offer.sdp })));
72 }, 'setRemoteDescription(pranswer) from stable state should reject with InvalidStateError');
73
74 /*
75 4.3.1.6. Set the RTCSessionSessionDescription
76 2.2.3. Otherwise, if description is set as a remote description, then run one
77 of the following steps:
78 - If description is of type "pranswer", then set
79 connection.pendingRemoteDescription to description and signaling state
80 to have-remote-pranswer.
81 */
82 promise_test(t => {
83 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:5384 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:0285
86 const states = [];
87 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:0988
89 return pc.createOffer({ offerToReceiveVideo: true })
90 .then(offer =>
91 pc.setLocalDescription(offer)
92 .then(() => generateAnswer(offer))
93 .then(answer => {
94 const pranswer = { type: 'pranswer', sdp: answer.sdp };
95
96 return pc.setRemoteDescription(pranswer)
97 .then(() => {
98 assert_equals(pc.signalingState, 'have-remote-pranswer');
99
100 assert_session_desc_equals(pc.localDescription, offer);
101 assert_session_desc_equals(pc.pendingLocalDescription, offer);
102 assert_equals(pc.currentLocalDescription, null);
103
104 assert_session_desc_equals(pc.remoteDescription, pranswer);
105 assert_session_desc_equals(pc.pendingRemoteDescription, pranswer);
106 assert_equals(pc.currentRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:02107
108 assert_array_equals(states, ['have-local-offer', 'have-remote-pranswer']);
Soares Chen5dbbd5f2017-07-10 09:56:09109 });
110 }));
111 }, 'setRemoteDescription(pranswer) from have-local-offer state should succeed');
112
113 promise_test(t => {
114 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53115 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:02116
117 const states = [];
118 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:09119
120 return pc.createOffer({ offerToReceiveVideo: true })
121 .then(offer =>
122 pc.setLocalDescription(offer)
123 .then(() => generateAnswer(offer))
124 .then(answer => {
125 const pranswer = { type: 'pranswer', sdp: answer.sdp };
126
127 return pc.setRemoteDescription(pranswer)
Philipp Hanckeeb37a992018-05-30 15:55:02128 .then(() => pc.setRemoteDescription(pranswer))
129 .then(() => {
130 assert_array_equals(states, ['have-local-offer', 'have-remote-pranswer']);
131 });
Soares Chen5dbbd5f2017-07-10 09:56:09132 }));
133 }, 'setRemoteDescription(pranswer) multiple times should succeed');
134
135 promise_test(t => {
136 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53137 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:02138
139 const states = [];
140 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:09141
142 return pc.createOffer({ offerToReceiveVideo: true })
143 .then(offer =>
144 pc.setLocalDescription(offer)
145 .then(() => generateAnswer(offer))
146 .then(answer => {
147 const pranswer = { type: 'pranswer', sdp: answer.sdp };
148
149 return pc.setRemoteDescription(pranswer)
150 .then(() => pc.setRemoteDescription(answer))
151 .then(() => {
152 assert_equals(pc.signalingState, 'stable');
153
154 assert_session_desc_equals(pc.localDescription, offer);
155 assert_session_desc_equals(pc.currentLocalDescription, offer);
156 assert_equals(pc.pendingLocalDescription, null);
157
158 assert_session_desc_equals(pc.remoteDescription, answer);
159 assert_session_desc_equals(pc.currentRemoteDescription, answer);
160 assert_equals(pc.pendingRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:02161
162 assert_array_equals(states, ['have-local-offer', 'have-remote-pranswer', 'stable']);
Soares Chen5dbbd5f2017-07-10 09:56:09163 });
164 }));
165 }, 'setRemoteDescription(answer) from have-remote-pranswer state should succeed');
166
167</script>