blob: cc5bd1e0807b71e0e96c368fe18ab6bd0c6d142d [file] [log] [blame]
Soares Chen363f1252017-07-10 09:22:151<!doctype html>
2<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.setRemoteDescription - answer</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:
Soares Chen363f1252017-07-10 09:22:1514 // generateAnswer()
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:0915 // assert_session_desc_similar()
Soares Chen363f1252017-07-10 09:22:1516
17 /*
18 4.3.2. Interface Definition
19 [Constructor(optional RTCConfiguration configuration)]
20 interface RTCPeerConnection : EventTarget {
21 Promise<void> setRemoteDescription(
22 RTCSessionDescriptionInit description);
23
24 readonly attribute RTCSessionDescription? remoteDescription;
25 readonly attribute RTCSessionDescription? currentRemoteDescription;
26 readonly attribute RTCSessionDescription? pendingRemoteDescription;
27 ...
28 };
29
30 4.6.2. RTCSessionDescription Class
31 dictionary RTCSessionDescriptionInit {
32 required RTCSdpType type;
33 DOMString sdp = "";
34 };
35
36 4.6.1. RTCSdpType
37 enum RTCSdpType {
38 "offer",
39 "pranswer",
40 "answer",
41 "rollback"
42 };
43 */
44
45 /*
46 4.3.1.6. Set the RTCSessionSessionDescription
47 2.2.3. Otherwise, if description is set as a remote description, then run one of
48 the following steps:
49 - If description is of type "answer", then this completes an offer answer
50 negotiation.
51
52 Set connection's currentRemoteDescription to description and
53 currentLocalDescription to the value of pendingLocalDescription.
54
55 Set both pendingRemoteDescription and pendingLocalDescription to null.
56
57 Finally setconnection's signaling state to stable.
58 */
59 promise_test(t => {
60 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:5361 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:0262
63 const states = [];
64 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen363f1252017-07-10 09:22:1565
Youenn Fablet7b163582018-11-04 07:30:5966 return generateVideoReceiveOnlyOffer(pc)
Soares Chen363f1252017-07-10 09:22:1567 .then(offer =>
68 pc.setLocalDescription(offer)
69 .then(() => generateAnswer(offer))
70 .then(answer =>
71 pc.setRemoteDescription(answer)
72 .then(() => {
73 assert_equals(pc.signalingState, 'stable');
74
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:0975 assert_session_desc_similar(pc.localDescription, offer);
76 assert_session_desc_similar(pc.remoteDescription, answer);
Soares Chen363f1252017-07-10 09:22:1577
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:0978 assert_session_desc_similar(pc.currentLocalDescription, offer);
79 assert_session_desc_similar(pc.currentRemoteDescription, answer);
Soares Chen363f1252017-07-10 09:22:1580
81 assert_equals(pc.pendingLocalDescription, null);
82 assert_equals(pc.pendingRemoteDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:0283
84 assert_array_equals(states, ['have-local-offer', 'stable']);
Soares Chen363f1252017-07-10 09:22:1585 })));
86 }, 'setRemoteDescription() with valid state and answer should succeed');
87
88 /*
89 4.3.1.6. Set the RTCSessionSessionDescription
90 2.1.3. If the description's type is invalid for the current signaling state of
91 connection, then reject p with a newly created InvalidStateError and abort
92 these steps.
93
94 [JSEP]
95 5.6. If the type is "answer", the PeerConnection state MUST be either
96 "have-local-offer" or "have-remote-pranswer".
97 */
98 promise_test(t => {
99 const pc = new RTCPeerConnection();
100
Philipp Hancke1622a022018-06-11 10:00:53101 t.add_cleanup(() => pc.close());
102
Rick Waldron5445fa32017-08-30 21:53:59103 return pc.createOffer()
Soares Chen363f1252017-07-10 09:22:15104 .then(offer =>
105 promise_rejects(t, 'InvalidStateError',
106 pc.setRemoteDescription({ type: 'answer', sdp: offer.sdp })));
107 }, 'Calling setRemoteDescription(answer) from stable state should reject with InvalidStateError');
108
109 promise_test(t => {
110 const pc = new RTCPeerConnection();
111
Philipp Hancke1622a022018-06-11 10:00:53112 t.add_cleanup(() => pc.close());
113
Rick Waldron5445fa32017-08-30 21:53:59114 return pc.createOffer()
Soares Chen363f1252017-07-10 09:22:15115 .then(offer =>
116 pc.setRemoteDescription(offer)
117 .then(() => generateAnswer(offer)))
118 .then(answer =>
119 promise_rejects(t, 'InvalidStateError',
120 pc.setRemoteDescription(answer)));
Soares Chen363f1252017-07-10 09:22:15121 }, 'Calling setRemoteDescription(answer) from have-remote-offer state should reject with InvalidStateError');
122
123</script>