blob: 704fa3c6467e377447b140fbcd7b27cb1d9d20dc [file] [log] [blame]
Soares Chenfda87822017-06-05 14:00:301<!doctype html>
2<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.createOffer</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/20170515/webrtc.html
12
Rick Waldron1c5c05d2017-06-07 17:54:4213 // The following helper functions are called from RTCPeerConnection-helper.js:
Rick Waldron1c5c05d2017-06-07 17:54:4214 // countAudioLine()
15 // countVideoLine()
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:0916 // assert_session_desc_similar()
Rick Waldron1c5c05d2017-06-07 17:54:4217
Soares Chenfda87822017-06-05 14:00:3018 /*
19 * 4.3.2. createOffer()
20 */
21
22 /*
23 * Final steps to create an offer
24 * 4. Let offer be a newly created RTCSessionDescriptionInit dictionary
25 * with its type member initialized to the string "offer" and its sdp member
26 * initialized to sdpString.
27 */
28 promise_test(t => {
29 const pc = new RTCPeerConnection()
30
Philipp Hancke1622a022018-06-11 10:00:5331 t.add_cleanup(() => pc.close());
32
Soares Chenfda87822017-06-05 14:00:3033 return pc.createOffer()
34 .then(offer => {
35 assert_equals(typeof offer, 'object',
36 'Expect offer to be plain object dictionary RTCSessionDescriptionInit');
37
38 assert_false(offer instanceof RTCSessionDescription,
39 'Expect offer to not be instance of RTCSessionDescription')
40 });
41 }, 'createOffer() with no argument from newly created RTCPeerConnection should succeed');
42
43 promise_test(t => {
44 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:5345 t.add_cleanup(() => pc.close());
Philipp Hanckeeb37a992018-05-30 15:55:0246
47 const states = [];
48 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
Soares Chenfda87822017-06-05 14:00:3049
Youenn Fablet20676f82018-11-04 04:18:0950 return generateVideoReceiveOnlyOffer(pc)
Soares Chenfda87822017-06-05 14:00:3051 .then(offer =>
Dominique Hazael-Massieux841671e2020-01-15 08:57:1252 pc.setLocalDescription(offer)
Nils Ohlmeier6cb97072017-08-31 00:38:2953 .then(() => {
Soares Chenfda87822017-06-05 14:00:3054 assert_equals(pc.signalingState, 'have-local-offer');
Jan-Ivar Bruaroey6d3fda52018-07-04 13:49:0955 assert_session_desc_similar(pc.localDescription, offer);
56 assert_session_desc_similar(pc.pendingLocalDescription, offer);
Soares Chenfda87822017-06-05 14:00:3057 assert_equals(pc.currentLocalDescription, null);
Philipp Hanckeeb37a992018-05-30 15:55:0258
59 assert_array_equals(states, ['have-local-offer']);
Soares Chenfda87822017-06-05 14:00:3060 }));
61 }, 'createOffer() and then setLocalDescription() should succeed');
62
63 promise_test(t => {
64 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:5365 t.add_cleanup(() => pc.close());
Soares Chenfda87822017-06-05 14:00:3066 pc.close();
67
Boris Zbarskyb7f2dd32020-02-04 21:26:4868 return promise_rejects_dom(t, 'InvalidStateError',
Soares Chenfda87822017-06-05 14:00:3069 pc.createOffer());
70 }, 'createOffer() after connection is closed should reject with InvalidStateError');
71
Soares Chenfda87822017-06-05 14:00:3072 /*
73 * Final steps to create an offer
74 * 2. If connection was modified in such a way that additional inspection of the
75 * system state is necessary, then in parallel begin the steps to create an
76 * offer again, given p, and abort these steps.
77 *
78 * This test might hit step 2 of final steps to create an offer. But the media stream
79 * is likely added already by the time steps to create an offer is executed, because
80 * that is enqueued as an operation.
81 * Either way it verifies that the media stream is included in the offer even though
82 * the stream is added after synchronous call to createOffer.
83 */
84 promise_test(t => {
85 const pc = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:5386 t.add_cleanup(() => pc.close());
Soares Chenfda87822017-06-05 14:00:3087 const promise = pc.createOffer();
88
89 pc.addTransceiver('audio');
90 return promise.then(offer => {
91 assert_equals(countAudioLine(offer.sdp), 1,
92 'Expect m=audio line to be found in offer SDP')
93 });
94 }, 'When media stream is added when createOffer() is running in parallel, the result offer should contain the new media stream');
95
96 /*
Dominique Hazael-Massieux841671e2020-01-15 08:57:1297 If connection's signaling state is neither "stable" nor "have-local-offer", return a promise rejected with a newly created InvalidStateError.
98 */
99 promise_test(t => {
100 const pc = new RTCPeerConnection();
101 t.add_cleanup(() => pc.close());
102
103 const states = [];
104 pc.addEventListener('signalingstatechange', () => states.push(pc.signalingState));
105
106 return generateVideoReceiveOnlyOffer(pc)
107 .then(offer =>
108 pc.setRemoteDescription(offer)
109 .then(() => {
110 assert_equals(pc.signalingState, 'have-remote-offer');
Boris Zbarskyb7f2dd32020-02-04 21:26:48111 return promise_rejects_dom(t, 'InvalidStateError',
Dominique Hazael-Massieux841671e2020-01-15 08:57:12112 pc.createOffer());
113 })
114 )
115 }, 'createOffer() should fail when signaling state is not stable or have-local-offer');
116 /*
Soares Chenfda87822017-06-05 14:00:30117 * TODO
118 * 4.3.2 createOffer
119 * 3. If connection is configured with an identity provider, and an identity
120 * assertion has not yet been generated using said identity provider, then
121 * begin the identity assertion request process if it has not already begun.
122 * Steps to create an offer
123 * 1. If the need for an identity assertion was identified when createOffer was
124 * invoked, wait for the identity assertion request process to complete.
125 *
126 * Non-Testable
127 * 4.3.2 createOffer
128 * Steps to create an offer
129 * 4. Inspect the system state to determine the currently available resources as
130 * necessary for generating the offer, as described in [JSEP] (section 4.1.6.).
131 * 5. If this inspection failed for any reason, reject p with a newly created
132 * OperationError and abort these steps.
133 */
Soares Chenfda87822017-06-05 14:00:30134</script>