blob: 134f3d1b9ce0ba886cd0b675db8aadd110141094 [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
Rick Waldron5445fa32017-08-30 21:53:5966 return pc.createOffer()
Soares Chen5dbbd5f2017-07-10 09:56:0967 .then(offer =>
68 promise_rejects(t, 'InvalidStateError',
69 pc.setLocalDescription({ type: 'pranswer', sdp: offer.sdp })));
70
71 }, 'setLocalDescription(pranswer) from stable state should reject with InvalidStateError');
72
73 /*
74 4.3.1.6 Set the RTCSessionSessionDescription
75 2.2.2. If description is set as a local description, then run one of the
76 following steps:
77 - If description is of type "pranswer", then set
78 connection.pendingLocalDescription to description and signaling state to
79 have-local-pranswer.
80 */
81 promise_test(t => {
82 const pc = new RTCPeerConnection();
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
Rick Waldron5445fa32017-08-30 21:53:5987 return pc.createOffer({ offerToReceiveVideo: true })
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
98 assert_session_desc_equals(pc.remoteDescription, offer);
99 assert_session_desc_equals(pc.pendingRemoteDescription, offer);
100 assert_equals(pc.currentRemoteDescription, null);
101
102 assert_session_desc_equals(pc.localDescription, pranswer);
103 assert_session_desc_equals(pc.pendingLocalDescription, pranswer);
104 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 Hanckeeb37a992018-05-30 15:55:02115
116 const states = [];
117 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:09118
Rick Waldron5445fa32017-08-30 21:53:59119 return pc.createOffer({ offerToReceiveVideo: true })
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 Hanckeeb37a992018-05-30 15:55:02136
137 const states = [];
138 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:09139
Rick Waldron5445fa32017-08-30 21:53:59140 return pc.createOffer({ offerToReceiveVideo: true })
Soares Chen5dbbd5f2017-07-10 09:56:09141 .then(offer =>
142 pc.setRemoteDescription(offer)
143 .then(() => pc.createAnswer())
144 .then(answer => {
145 const pranswer = { type: 'pranswer', sdp: answer.sdp };
146
147 return pc.setLocalDescription(pranswer)
148 .then(() => pc.setLocalDescription(answer))
149 .then(() => {
150 assert_equals(pc.signalingState, 'stable');
151 assert_session_desc_equals(pc.localDescription, answer);
152 assert_session_desc_equals(pc.remoteDescription, offer);
153
154 assert_session_desc_equals(pc.currentLocalDescription, answer);
155 assert_session_desc_equals(pc.currentRemoteDescription, offer);
156
157 assert_equals(pc.pendingLocalDescription, null);
158 assert_equals(pc.pendingRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:02159
160 assert_array_equals(states, ['have-remote-offer', 'have-local-pranswer', 'stable']);
Soares Chen5dbbd5f2017-07-10 09:56:09161 });
162 }));
163 }, 'setLocalDescription(answer) from have-local-pranswer state should succeed');
164
165</script>