blob: 8b9a27554973531e8528406a52d38b7c55932f3c [file] [log] [blame]
commit-queue@webkit.org89165762016-10-27 06:33:21 +00001<!doctype html>
cdumez@apple.com88d4e142017-10-13 02:04:33 +00002<!--
commit-queue@webkit.org89165762016-10-27 06:33:21 +00003This test uses data only, and thus does not require fake media devices.
cdumez@apple.com88d4e142017-10-13 02:04:33 +00004-->
commit-queue@webkit.org89165762016-10-27 06:33:21 +00005
6<html>
7<head>
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
9 <title>RTCPeerConnection Data-Only Connection Test with Promises</title>
10</head>
11<body>
12 <div id="log"></div>
13 <h2>iceConnectionState info</h2>
14 <div id="stateinfo">
15 </div>
16
cdumez@apple.com88d4e142017-10-13 02:04:33 +000017 <!-- These files are in place when executing on W3C. -->
commit-queue@webkit.org89165762016-10-27 06:33:21 +000018 <script src="/resources/testharness.js"></script>
19 <script src="/resources/testharnessreport.js"></script>
20 <script type="text/javascript">
21 var test = async_test('Can set up a basic WebRTC call with only data using promises.');
22
23 var gFirstConnection = null;
24 var gSecondConnection = null;
25
26 var onIceCandidateToFirst = test.step_func(function(event) {
27 // If event.candidate is null = no more candidates.
28 if (event.candidate) {
29 gSecondConnection.addIceCandidate(event.candidate);
30 }
31 });
32
33 var onIceCandidateToSecond = test.step_func(function(event) {
34 if (event.candidate) {
35 gFirstConnection.addIceCandidate(event.candidate);
36 }
37 });
38
commit-queue@webkit.org89165762016-10-27 06:33:21 +000039 var onIceConnectionStateChange = test.step_func(function(event) {
40 assert_equals(event.type, 'iceconnectionstatechange');
41 var stateinfo = document.getElementById('stateinfo');
42 stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState
43 + '<br>Second: ' + gSecondConnection.iceConnectionState;
44 // Note: All these combinations are legal states indicating that the
45 // call has connected. All browsers should end up in completed/completed,
46 // but as of this moment, we've chosen to terminate the test early.
47 // TODO: Revise test to ensure completed/completed is reached.
48 if (gFirstConnection.iceConnectionState == 'connected' &&
49 gSecondConnection.iceConnectionState == 'connected') {
50 test.done()
51 }
52 if (gFirstConnection.iceConnectionState == 'connected' &&
53 gSecondConnection.iceConnectionState == 'completed') {
54 test.done()
55 }
56 if (gFirstConnection.iceConnectionState == 'completed' &&
57 gSecondConnection.iceConnectionState == 'connected') {
58 test.done()
59 }
60 if (gFirstConnection.iceConnectionState == 'completed' &&
61 gSecondConnection.iceConnectionState == 'completed') {
62 test.done()
63 }
64 });
65
66 // This function starts the test.
67 test.step(function() {
68 gFirstConnection = new RTCPeerConnection(null);
cdumez@apple.comcd405bc2020-07-09 23:04:17 +000069 test.add_cleanup(() => gFirstConnection.close());
commit-queue@webkit.org89165762016-10-27 06:33:21 +000070 gFirstConnection.onicecandidate = onIceCandidateToFirst;
71 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange;
72
73 gSecondConnection = new RTCPeerConnection(null);
cdumez@apple.comcd405bc2020-07-09 23:04:17 +000074 test.add_cleanup(() => gSecondConnection.close());
commit-queue@webkit.org89165762016-10-27 06:33:21 +000075 gSecondConnection.onicecandidate = onIceCandidateToSecond;
commit-queue@webkit.org89165762016-10-27 06:33:21 +000076 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange;
77
78 // The createDataChannel is necessary and sufficient to make
79 // sure the ICE connection be attempted.
80 gFirstConnection.createDataChannel('channel');
81
82 var atStep = 'Create offer';
83
84 gFirstConnection.createOffer()
85 .then(function(offer) {
86 atStep = 'Set local description at first';
87 return gFirstConnection.setLocalDescription(offer);
88 })
89 .then(function() {
90 atStep = 'Set remote description at second';
91 return gSecondConnection.setRemoteDescription(
92 gFirstConnection.localDescription);
93 })
94 .then(function() {
95 atStep = 'Create answer';
96 return gSecondConnection.createAnswer();
97 })
98 .then(function(answer) {
99 atStep = 'Set local description at second';
100 return gSecondConnection.setLocalDescription(answer);
101 })
102 .then(function() {
103 atStep = 'Set remote description at first';
104 return gFirstConnection.setRemoteDescription(
105 gSecondConnection.localDescription);
106 })
107 .then(function() {
108 atStep = 'Negotiation completed';
109 })
110 .catch(test.step_func(function(e) {
111 assert_unreached('Error ' + e.name + ': ' + e.message +
112 ' happened at step ' + atStep);
113 }));
114 });
115</script>
116
117</body>
118</html>