blob: c2d9ff2d6ce15288f24ef7c155e6289bcee1d196 [file] [log] [blame]
Harald Alvestrand168935a2015-05-13 08:23:141<!doctype html>
2<!--
Harald Alvestrand698efbc2015-05-18 08:53:053This test uses data only, and thus does not require fake media devices.
Harald Alvestrand168935a2015-05-13 08:23:144-->
5
6<html>
7<head>
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Harald Alvestrand698efbc2015-05-18 08:53:059 <title>RTCPeerConnection Data-Only Connection Test with Promises</title>
Harald Alvestrand168935a2015-05-13 08:23:1410</head>
11<body>
12 <div id="log"></div>
13 <h2>iceConnectionState info</h2>
14 <div id="stateinfo">
15 </div>
16
17 <!-- These files are in place when executing on W3C. -->
18 <script src="/resources/testharness.js"></script>
19 <script src="/resources/testharnessreport.js"></script>
20 <script src="/common/vendor-prefix.js"
21 data-prefixed-objects=
22 '[{"ancestors":["window"], "name":"RTCPeerConnection"},
23 {"ancestors":["window"], "name":"RTCSessionDescription"},
24 {"ancestors":["window"], "name":"RTCIceCandidate"}]'
25 >
26 </script>
27 <script type="text/javascript">
Harald Alvestrandba63db82015-05-19 08:33:4028 var test = async_test('Can set up a basic WebRTC call with only data using promises.');
Harald Alvestrand168935a2015-05-13 08:23:1429
30 var gFirstConnection = null;
31 var gSecondConnection = null;
32
Harald Alvestrand168935a2015-05-13 08:23:1433 var onIceCandidateToFirst = test.step_func(function(event) {
34 // If event.candidate is null = no more candidates.
35 if (event.candidate) {
36 var candidate = new RTCIceCandidate(event.candidate);
37 gSecondConnection.addIceCandidate(candidate);
38 }
39 });
40
41 var onIceCandidateToSecond = test.step_func(function(event) {
42 if (event.candidate) {
43 var candidate = new RTCIceCandidate(event.candidate);
44 gFirstConnection.addIceCandidate(candidate);
45 }
46 });
47
48 var onRemoteStream = test.step_func(function(event) {
49 assert_unreached('WebRTC received a stream when there was none');
50 });
51
52 var onIceConnectionStateChange = test.step_func(function(event) {
53 assert_equals(event.type, 'iceconnectionstatechange');
54 var stateinfo = document.getElementById('stateinfo');
55 stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState
56 + '<br>Second: ' + gSecondConnection.iceConnectionState;
57 // Note: All these combinations are legal states indicating that the
58 // call has connected. All browsers should end up in completed/completed,
59 // but as of this moment, we've chosen to terminate the test early.
60 // TODO: Revise test to ensure completed/completed is reached.
61 if (gFirstConnection.iceConnectionState == 'connected' &&
62 gSecondConnection.iceConnectionState == 'connected') {
63 test.done()
64 }
65 if (gFirstConnection.iceConnectionState == 'connected' &&
66 gSecondConnection.iceConnectionState == 'completed') {
67 test.done()
68 }
69 if (gFirstConnection.iceConnectionState == 'completed' &&
70 gSecondConnection.iceConnectionState == 'connected') {
71 test.done()
72 }
73 if (gFirstConnection.iceConnectionState == 'completed' &&
74 gSecondConnection.iceConnectionState == 'completed') {
75 test.done()
76 }
77 });
78
Harald Alvestrand168935a2015-05-13 08:23:1479 // This function starts the test.
80 test.step(function() {
81 gFirstConnection = new RTCPeerConnection(null);
82 gFirstConnection.onicecandidate = onIceCandidateToFirst;
83 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange;
84
85 gSecondConnection = new RTCPeerConnection(null);
86 gSecondConnection.onicecandidate = onIceCandidateToSecond;
87 gSecondConnection.onaddstream = onRemoteStream;
88 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange;
89
Harald Alvestrand698efbc2015-05-18 08:53:0590 // The createDataChannel is necessary and sufficient to make
91 // sure the ICE connection be attempted.
92 gFirstConnection.createDataChannel('channel');
Harald Alvestrand4ec420d2015-05-18 14:31:5293
Harald Alvestrand1a596652015-05-19 08:45:3294 var atStep = 'Create offer';
Harald Alvestrand698efbc2015-05-18 08:53:0595
96 gFirstConnection.createOffer()
97 .then(function(offer) {
Harald Alvestrand1a596652015-05-19 08:45:3298 atStep = 'Handle offer';
99 return Promise.all([gFirstConnection.setLocalDescription(offer),
100 gSecondConnection.setRemoteDescription(offer)])
Harald Alvestrand698efbc2015-05-18 08:53:05101 })
102 .then(function() {
Harald Alvestrand1a596652015-05-19 08:45:32103 atStep = 'Create answer';
Harald Alvestrand698efbc2015-05-18 08:53:05104 return gSecondConnection.createAnswer()
105 })
106 .then(function(answer) {
Harald Alvestrand1a596652015-05-19 08:45:32107 atStep = 'Handle answer';
108 return Promise.all([gSecondConnection.setLocalDescription(answer),
109 gFirstConnection.setRemoteDescription(answer)])
Harald Alvestrand698efbc2015-05-18 08:53:05110 })
111 .then(function() {
112 atStep = 'negotiation completed';
113 })
114 .catch(test.step_func(function(e) {
Harald Alvestrandba63db82015-05-19 08:33:40115 assert_unreached('Error ' + e.name + ': ' + e.message +
Harald Alvestrand698efbc2015-05-18 08:53:05116 ' happened at step ' + atStep);
117 }));
Harald Alvestrand168935a2015-05-13 08:23:14118 });
119</script>
120
121</body>
122</html>