blob: 0147b3185cce20c7345fe640dd6e466209d0e3ca [file] [log] [blame]
Soares Chen5dbbd5f2017-07-10 09:56:091<!doctype html>
2<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.setLocalDescription rollback</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.2.2. If description is set as a local description, then run one of the
54 following steps:
55 - If description is of type "rollback", then this is a rollback. Set
56 connection.pendingLocalDescription to null and signaling state to stable.
57 */
58 promise_test(t=> {
59 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:5360 t.add_cleanup(() => pc.close());
Soares Chen5dbbd5f2017-07-10 09:56:0961
Philipp Hanckeeb37a992018-05-30 15:55:0262 const states = [];
63 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chen5dbbd5f2017-07-10 09:56:0964
65 return pc.createOffer()
66 .then(offer => pc.setLocalDescription(offer))
67 .then(() => {
68 assert_equals(pc.signalingState, 'have-local-offer');
69 assert_not_equals(pc.localDescription, null);
70 assert_not_equals(pc.pendingLocalDescription, null);
71 assert_equals(pc.currentLocalDescription, null);
72
73 return pc.setLocalDescription({ type: 'rollback' });
74 })
75 .then(() => {
76 assert_equals(pc.signalingState, 'stable');
77 assert_equals(pc.localDescription, null);
78 assert_equals(pc.pendingLocalDescription, null);
79 assert_equals(pc.currentLocalDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:0280
81 assert_array_equals(states, ['have-local-offer', 'stable']);
Soares Chen5dbbd5f2017-07-10 09:56:0982 });
83 }, 'setLocalDescription(rollback) from have-local-offer state should reset back to stable state');
84
Soares Chenc94ef3e2017-07-14 05:20:2085 /*
86 4.3.1.6. Set the RTCSessionSessionDescription
87 2.3. If the description's type is invalid for the current signaling state of
88 connection, then reject p with a newly created InvalidStateError and abort
89 these steps. Note that this implies that once the answerer has performed
90 setLocalDescription with his answer, this cannot be rolled back.
91
92 [jsep]
93 4.1.8.2. Rollback
94 - Rollback can only be used to cancel proposed changes;
95 there is no support for rolling back from a stable state to a
96 previous stable state
97 */
98 promise_test(t => {
99 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53100 t.add_cleanup(() => pc.close());
Soares Chenc94ef3e2017-07-14 05:20:20101 return promise_rejects(t, 'InvalidStateError',
102 pc.setLocalDescription({ type: 'rollback' }));
103 }, `setLocalDescription(rollback) from stable state should reject with InvalidStateError`);
104
105 promise_test(t => {
106 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53107 t.add_cleanup(() => pc.close());
Rick Waldron5445fa32017-08-30 21:53:59108 return pc.createOffer({ offerToReceiveAudio: true })
Soares Chenc94ef3e2017-07-14 05:20:20109 .then(offer =>
110 pc.setRemoteDescription(offer)
111 .then(() => pc.createAnswer()))
112 .then(answer => pc.setLocalDescription(answer))
113 .then(() => {
114 return promise_rejects(t, 'InvalidStateError',
115 pc.setLocalDescription({ type: 'rollback' }));
116 });
117 }, `setLocalDescription(rollback) after setting answer description should reject with InvalidStateError`);
118
119 promise_test(t => {
120 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53121 t.add_cleanup(() => pc.close());
Soares Chenc94ef3e2017-07-14 05:20:20122 return pc.createOffer()
123 .then(offer => pc.setLocalDescription(offer))
124 .then(() => pc.setLocalDescription({
125 type: 'rollback',
126 sdp: '!<Invalid SDP Content>;'
127 }));
128 }, `setLocalDescription(rollback) should ignore invalid sdp content and succeed`);
Soares Chen5dbbd5f2017-07-10 09:56:09129</script>