blob: e4296aef139f19d08229c9450f61c30706147d24 [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
106 assert_equals(pc.pendingRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:02107
108 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']);
Soares Chen5dbbd5f2017-07-10 09:56:09109 });
110 }));
111 }, 'setLocalDescription(pranswer) 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
Youenn Fablet7b163582018-11-04 07:30:59120 return generateVideoReceiveOnlyOffer(pc)
Soares Chen5dbbd5f2017-07-10 09:56:09121 .then(offer =>
122 pc.setRemoteDescription(offer)
123 .then(() => pc.createAnswer())
124 .then(answer => {
125 const pranswer = { type: 'pranswer', sdp: answer.sdp };
126
127 return pc.setLocalDescription(pranswer)
Philipp Hanckeeb37a992018-05-30 15:55:02128 .then(() => pc.setLocalDescription(pranswer))
129 .then(() => {
130 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer']);
131 });
Soares Chen5dbbd5f2017-07-10 09:56:09132 }));
133 }, 'setLocalDescription(pranswer) can be applied multiple times while still in have-local-pranswer');
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
Youenn Fablet7b163582018-11-04 07:30:59142 return generateVideoReceiveOnlyOffer(pc)
Soares Chen5dbbd5f2017-07-10 09:56:09143 .then(offer =>
144 pc.setRemoteDescription(offer)
145 .then(() => pc.createAnswer())
146 .then(answer => {
147 const pranswer = { type: 'pranswer', sdp: answer.sdp };
148
149 return pc.setLocalDescription(pranswer)
150 .then(() => pc.setLocalDescription(answer))
151 .then(() => {
152 assert_equals(pc.signalingState, 'stable');
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:09153 assert_session_desc_similar(pc.localDescription, answer);
154 assert_session_desc_similar(pc.remoteDescription, offer);
Soares Chen5dbbd5f2017-07-10 09:56:09155
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:09156 assert_session_desc_similar(pc.currentLocalDescription, answer);
157 assert_session_desc_similar(pc.currentRemoteDescription, offer);
Soares Chen5dbbd5f2017-07-10 09:56:09158
159 assert_equals(pc.pendingLocalDescription, null);
160 assert_equals(pc.pendingRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:02161
162 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer', 'stable']);
Soares Chen5dbbd5f2017-07-10 09:56:09163 });
164 }));
165 }, 'setLocalDescription(answer) from have-local-pranswer state should succeed');
166
167</script>