blob: 8b173c441b0cf976ce1c7506a3ff96bb50d5ede9 [file] [log] [blame]
Soares Chen5dbbd5f2017-07-10 09:56:091<!doctype html>
2<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.setLocalDescription 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.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.5. If the type is "pranswer" or "answer", the PeerConnection
61 state MUST be either "have-remote-offer" or "have-local-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.setLocalDescription({ type: 'pranswer', sdp: offer.sdp })));
Soares Chen5dbbd5f2017-07-10 09:56:0972 }, 'setLocalDescription(pranswer) from stable state should reject with InvalidStateError');
73
74 /*
75 4.3.1.6 Set the RTCSessionSessionDescription
76 2.2.2. If description is set as a local description, then run one of the
77 following steps:
78 - If description is of type "pranswer", then set
79 connection.pendingLocalDescription to description and signaling state to
80 have-local-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
Rick Waldron5445fa32017-08-30 21:53:5989 return pc.createOffer({ offerToReceiveVideo: true })
Soares Chen5dbbd5f2017-07-10 09:56:0990 .then(offer =>
91 pc.setRemoteDescription(offer)
92 .then(() => pc.createAnswer())
93 .then(answer => {
94 const pranswer = { type: 'pranswer', sdp: answer.sdp };
95
96 return pc.setLocalDescription(pranswer)
97 .then(() => {
98 assert_equals(pc.signalingState, 'have-local-pranswer');
99
100 assert_session_desc_equals(pc.remoteDescription, offer);
101 assert_session_desc_equals(pc.pendingRemoteDescription, offer);
102 assert_equals(pc.currentRemoteDescription, null);
103
104 assert_session_desc_equals(pc.localDescription, pranswer);
105 assert_session_desc_equals(pc.pendingLocalDescription, pranswer);
106 assert_equals(pc.currentLocalDescription, null);
107
108 assert_equals(pc.pendingRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:02109
110 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']);
Soares Chen5dbbd5f2017-07-10 09:56:09111 });
112 }));
113 }, 'setLocalDescription(pranswer) should succeed');
114
115 promise_test(t => {
116 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53117 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:02118
119 const states = [];
120 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:09121
Rick Waldron5445fa32017-08-30 21:53:59122 return pc.createOffer({ offerToReceiveVideo: true })
Soares Chen5dbbd5f2017-07-10 09:56:09123 .then(offer =>
124 pc.setRemoteDescription(offer)
125 .then(() => pc.createAnswer())
126 .then(answer => {
127 const pranswer = { type: 'pranswer', sdp: answer.sdp };
128
129 return pc.setLocalDescription(pranswer)
Philipp Hanckeeb37a992018-05-30 15:55:02130 .then(() => pc.setLocalDescription(pranswer))
131 .then(() => {
132 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']);
133 });
Soares Chen5dbbd5f2017-07-10 09:56:09134 }));
135 }, 'setLocalDescription(pranswer) can be applied multiple times while still in have-local-pranswer');
136
137 promise_test(t => {
138 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53139 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:02140
141 const states = [];
142 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:09143
Rick Waldron5445fa32017-08-30 21:53:59144 return pc.createOffer({ offerToReceiveVideo: true })
Soares Chen5dbbd5f2017-07-10 09:56:09145 .then(offer =>
146 pc.setRemoteDescription(offer)
147 .then(() => pc.createAnswer())
148 .then(answer => {
149 const pranswer = { type: 'pranswer', sdp: answer.sdp };
150
151 return pc.setLocalDescription(pranswer)
152 .then(() => pc.setLocalDescription(answer))
153 .then(() => {
154 assert_equals(pc.signalingState, 'stable');
155 assert_session_desc_equals(pc.localDescription, answer);
156 assert_session_desc_equals(pc.remoteDescription, offer);
157
158 assert_session_desc_equals(pc.currentLocalDescription, answer);
159 assert_session_desc_equals(pc.currentRemoteDescription, offer);
160
161 assert_equals(pc.pendingLocalDescription, null);
162 assert_equals(pc.pendingRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:02163
164 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer', 'stable']);
Soares Chen5dbbd5f2017-07-10 09:56:09165 });
166 }));
167 }, 'setLocalDescription(answer) from have-local-pranswer state should succeed');
168
169</script>