blob: 01845f09b16ce1ff03747f039dee5de89b19a5ae [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:
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:0914 // assert_session_desc_similar
Soares Chen5dbbd5f2017-07-10 09:56:0915
16 /*
17 4.3.2. Interface Definition
18 [Constructor(optional RTCConfiguration configuration)]
19 interface RTCPeerConnection : EventTarget {
20 Promise<void> setLocalDescription(
21 RTCSessionDescriptionInit description);
22
23 readonly attribute RTCSessionDescription? localDescription;
24 readonly attribute RTCSessionDescription? currentLocalDescription;
25 readonly attribute RTCSessionDescription? pendingLocalDescription;
26
27 Promise<void> setRemoteDescription(
28 RTCSessionDescriptionInit description);
29
30 readonly attribute RTCSessionDescription? remoteDescription;
31 readonly attribute RTCSessionDescription? currentRemoteDescription;
32 readonly attribute RTCSessionDescription? pendingRemoteDescription;
33 ...
34 };
35
36 4.6.2. RTCSessionDescription Class
37 dictionary RTCSessionDescriptionInit {
38 required RTCSdpType type;
39 DOMString sdp = "";
40 };
41
42 4.6.1. RTCSdpType
43 enum RTCSdpType {
44 "offer",
45 "pranswer",
46 "answer",
47 "rollback"
48 };
49 */
50
51 /*
52 4.3.1.6. Set the RTCSessionSessionDescription
53 2.3. If the description's type is invalid for the current signaling state of
54 connection, then reject p with a newly created InvalidStateError and abort
55 these steps.
56
57 [jsep]
58 5.5. If the type is "pranswer" or "answer", the PeerConnection
59 state MUST be either "have-remote-offer" or "have-local-pranswer".
60 */
61 promise_test(t => {
62 const pc = new RTCPeerConnection();
63
Philipp Hancke1622a022018-06-11 10:00:5364 t.add_cleanup(() => pc.close());
65
Rick Waldron5445fa32017-08-30 21:53:5966 return pc.createOffer()
Soares Chen5dbbd5f2017-07-10 09:56:0967 .then(offer =>
Boris Zbarskyb7f2dd32020-02-04 21:26:4868 promise_rejects_dom(t, 'InvalidStateError',
Soares Chen5dbbd5f2017-07-10 09:56:0969 pc.setLocalDescription({ type: 'pranswer', sdp: offer.sdp })));
Soares Chen5dbbd5f2017-07-10 09:56:0970 }, 'setLocalDescription(pranswer) from stable state should reject with InvalidStateError');
71
72 /*
73 4.3.1.6 Set the RTCSessionSessionDescription
74 2.2.2. If description is set as a local description, then run one of the
75 following steps:
76 - If description is of type "pranswer", then set
77 connection.pendingLocalDescription to description and signaling state to
78 have-local-pranswer.
79 */
80 promise_test(t => {
81 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:5382 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:0283
84 const states = [];
85 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:0986
Youenn Fablet7b163582018-11-04 07:30:5987 return generateVideoReceiveOnlyOffer(pc)
Soares Chen5dbbd5f2017-07-10 09:56:0988 .then(offer =>
89 pc.setRemoteDescription(offer)
90 .then(() => pc.createAnswer())
91 .then(answer => {
92 const pranswer = { type: 'pranswer', sdp: answer.sdp };
93
94 return pc.setLocalDescription(pranswer)
95 .then(() => {
96 assert_equals(pc.signalingState, 'have-local-pranswer');
97
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:0998 assert_session_desc_similar(pc.remoteDescription, offer);
99 assert_session_desc_similar(pc.pendingRemoteDescription, offer);
Soares Chen5dbbd5f2017-07-10 09:56:09100 assert_equals(pc.currentRemoteDescription, null);
101
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:09102 assert_session_desc_similar(pc.localDescription, pranswer);
103 assert_session_desc_similar(pc.pendingLocalDescription, pranswer);
Soares Chen5dbbd5f2017-07-10 09:56:09104 assert_equals(pc.currentLocalDescription, null);
105
Philipp Hanckeeb37a992018-05-30 15:55:02106
107 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']);
Soares Chen5dbbd5f2017-07-10 09:56:09108 });
109 }));
110 }, 'setLocalDescription(pranswer) should succeed');
111
112 promise_test(t => {
113 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53114 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:02115
116 const states = [];
117 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:09118
Youenn Fablet7b163582018-11-04 07:30:59119 return generateVideoReceiveOnlyOffer(pc)
Soares Chen5dbbd5f2017-07-10 09:56:09120 .then(offer =>
121 pc.setRemoteDescription(offer)
122 .then(() => pc.createAnswer())
123 .then(answer => {
124 const pranswer = { type: 'pranswer', sdp: answer.sdp };
125
126 return pc.setLocalDescription(pranswer)
Philipp Hanckeeb37a992018-05-30 15:55:02127 .then(() => pc.setLocalDescription(pranswer))
128 .then(() => {
129 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']);
130 });
Soares Chen5dbbd5f2017-07-10 09:56:09131 }));
132 }, 'setLocalDescription(pranswer) can be applied multiple times while still in have-local-pranswer');
133
134 promise_test(t => {
135 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53136 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:02137
138 const states = [];
139 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:09140
Youenn Fablet7b163582018-11-04 07:30:59141 return generateVideoReceiveOnlyOffer(pc)
Soares Chen5dbbd5f2017-07-10 09:56:09142 .then(offer =>
143 pc.setRemoteDescription(offer)
144 .then(() => pc.createAnswer())
145 .then(answer => {
146 const pranswer = { type: 'pranswer', sdp: answer.sdp };
147
148 return pc.setLocalDescription(pranswer)
149 .then(() => pc.setLocalDescription(answer))
150 .then(() => {
151 assert_equals(pc.signalingState, 'stable');
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:09152 assert_session_desc_similar(pc.localDescription, answer);
153 assert_session_desc_similar(pc.remoteDescription, offer);
Soares Chen5dbbd5f2017-07-10 09:56:09154
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:09155 assert_session_desc_similar(pc.currentLocalDescription, answer);
156 assert_session_desc_similar(pc.currentRemoteDescription, offer);
Soares Chen5dbbd5f2017-07-10 09:56:09157
158 assert_equals(pc.pendingLocalDescription, null);
159 assert_equals(pc.pendingRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:02160
161 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer', 'stable']);
Soares Chen5dbbd5f2017-07-10 09:56:09162 });
163 }));
164 }, 'setLocalDescription(answer) from have-local-pranswer state should succeed');
165
166</script>