blob: e6d8d062701a795a289ad011fa4cfae143a342e9 [file] [log] [blame]
Philipp Hanckebdc02672017-03-03 13:11:101<!doctype html>
Soares Chen300db382017-06-19 20:46:422<meta charset=utf-8>
3<title>RTCPeerConnection.prototype.iceGatheringState</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';
Philipp Hanckebdc02672017-03-03 13:11:109
Soares Chen300db382017-06-19 20:46:4210 // 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 Chen300db382017-06-19 20:46:4214 // doSignalingHandshake
Youenn Fablet27e0acb2018-11-13 19:00:2015 // exchangeIceCandidates
16 // generateAudioReceiveOnlyOffer
Soares Chen300db382017-06-19 20:46:4217
18 /*
19 4.3.2. Interface Definition
20 interface RTCPeerConnection : EventTarget {
21 ...
22 readonly attribute RTCIceGatheringState iceGatheringState;
23 attribute EventHandler onicegatheringstatechange;
24 };
25
26 4.4.2. RTCIceGatheringState Enum
27 enum RTCIceGatheringState {
28 "new",
29 "gathering",
30 "complete"
31 };
32
33 5.6. RTCIceTransport Interface
34 interface RTCIceTransport {
35 readonly attribute RTCIceGathererState gatheringState;
36 ...
37 };
38
39 enum RTCIceGathererState {
40 "new",
41 "gathering",
42 "complete"
43 };
44 */
45
46 /*
47 4.4.2. RTCIceGatheringState Enum
48 new
49 Any of the RTCIceTransport s are in the new gathering state and
50 none of the transports are in the gathering state, or there are
51 no transports.
52 */
53 test(t => {
54 const pc = new RTCPeerConnection();
55 assert_equals(pc.iceGatheringState, 'new');
56 }, 'Initial iceGatheringState should be new');
57
58 async_test(t => {
59 const pc = new RTCPeerConnection();
60
Philipp Hancke1622a022018-06-11 10:00:5361 t.add_cleanup(() => pc.close());
62
Soares Chen300db382017-06-19 20:46:4263 const onIceGatheringStateChange = t.step_func(() => {
64 const { iceGatheringState } = pc;
65
66 if(iceGatheringState === 'complete') {
67 t.done();
Philipp Hanckebdc02672017-03-03 13:11:1068 }
69 });
Philipp Hanckebdc02672017-03-03 13:11:1070
Soares Chen300db382017-06-19 20:46:4271 assert_equals(pc.onicegatheringstatechange, null,
72 'Expect connection to have icegatheringstatechange event');
73
74 pc.addEventListener('icegatheringstatechange', onIceGatheringStateChange);
75
Youenn Fablet27e0acb2018-11-13 19:00:2076 generateAudioReceiveOnlyOffer(pc)
Soares Chen300db382017-06-19 20:46:4277 .then(offer => pc.setLocalDescription(offer))
78 .then(err => t.step_func(err =>
79 assert_unreached(`Unhandled rejection ${err.name}: ${err.message}`)));
Soares Chen300db382017-06-19 20:46:4280 }, 'iceGatheringState should eventually become complete after setLocalDescription');
81
82 /*
83 4.4.2. RTCIceGatheringState Enum
84 gathering
85 Any of the RTCIceTransport s are in the gathering state.
86
87 complete
88 At least one RTCIceTransport exists, and all RTCIceTransports are
89 in the completed gathering state.
90
91 5.6. RTCIceGathererState
92 gathering
93 The RTCIceTransport is in the process of gathering candidates.
94
95 complete
96 The RTCIceTransport has completed gathering and the end-of-candidates
97 indication for this transport has been sent. It will not gather candidates
98 again until an ICE restart causes it to restart.
99 */
100 async_test(t => {
101 const pc1 = new RTCPeerConnection();
Philipp Hancke1622a022018-06-11 10:00:53102 t.add_cleanup(() => pc1.close());
Soares Chen300db382017-06-19 20:46:42103 const pc2 = new RTCPeerConnection();
104
Philipp Hancke1622a022018-06-11 10:00:53105 t.add_cleanup(() => pc2.close());
106
Soares Chen300db382017-06-19 20:46:42107 const onIceGatheringStateChange = t.step_func(() => {
108 const { iceGatheringState } = pc2;
109
110 if(iceGatheringState === 'gathering') {
111 const iceTransport = pc2.sctp.transport.transport;
112
113 assert_equals(iceTransport.gatheringState, 'gathering',
114 'Expect ICE transport to be in checking gatheringState when iceGatheringState is checking');
115
116 } else if(iceGatheringState === 'complete') {
117 const iceTransport = pc2.sctp.transport.transport;
118
119 assert_equals(iceTransport.gatheringState, 'complete',
120 'Expect ICE transport to be in complete gatheringState when iceGatheringState is complete');
121
122 t.done();
123 }
124 });
125
126 pc1.createDataChannel('test');
127
128 assert_equals(pc2.onicegatheringstatechange, null,
129 'Expect connection to have icegatheringstatechange event');
130
131 // Spec bug w3c/webrtc-pc#1382
132 // Because sctp is only defined when answer is set, we listen
133 // to pc2 so that we can be confident that sctp is defined
134 // when icegatheringstatechange event is fired.
135 pc2.addEventListener('icegatheringstatechange', onIceGatheringStateChange);
136
137 exchangeIceCandidates(pc1, pc2);
138 doSignalingHandshake(pc1, pc2);
Soares Chen300db382017-06-19 20:46:42139 }, 'connection with one data channel should eventually have connected connection state');
140
141 /*
142 TODO
143 5.6. RTCIceTransport Interface
144 new
145 The RTCIceTransport was just created, and has not started gathering
146 candidates yet.
147 */
148</script>