blob: ceb6ab258ccbaaebb39b63742a48a379db35bc46 [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>
Harald Alvestrand168935a2015-05-13 08:23:1420 <script type="text/javascript">
Harald Alvestrandba63db82015-05-19 08:33:4021 var test = async_test('Can set up a basic WebRTC call with only data using promises.');
Harald Alvestrand168935a2015-05-13 08:23:1422
23 var gFirstConnection = null;
24 var gSecondConnection = null;
25
Harald Alvestrand168935a2015-05-13 08:23:1426 var onIceCandidateToFirst = test.step_func(function(event) {
27 // If event.candidate is null = no more candidates.
28 if (event.candidate) {
Dominique Hazael-Massieuxa0a52482015-06-15 09:36:5429 gSecondConnection.addIceCandidate(event.candidate);
Harald Alvestrand168935a2015-05-13 08:23:1430 }
31 });
32
33 var onIceCandidateToSecond = test.step_func(function(event) {
34 if (event.candidate) {
Dominique Hazael-Massieuxa0a52482015-06-15 09:36:5435 gFirstConnection.addIceCandidate(event.candidate);
Harald Alvestrand168935a2015-05-13 08:23:1436 }
37 });
38
Harald Alvestrand168935a2015-05-13 08:23:1439 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
Harald Alvestrand168935a2015-05-13 08:23:1466 // This function starts the test.
67 test.step(function() {
68 gFirstConnection = new RTCPeerConnection(null);
69 gFirstConnection.onicecandidate = onIceCandidateToFirst;
70 gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange;
71
72 gSecondConnection = new RTCPeerConnection(null);
73 gSecondConnection.onicecandidate = onIceCandidateToSecond;
Harald Alvestrand168935a2015-05-13 08:23:1474 gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange;
75
Harald Alvestrand698efbc2015-05-18 08:53:0576 // The createDataChannel is necessary and sufficient to make
77 // sure the ICE connection be attempted.
78 gFirstConnection.createDataChannel('channel');
Harald Alvestrand4ec420d2015-05-18 14:31:5279
Harald Alvestrand1a596652015-05-19 08:45:3280 var atStep = 'Create offer';
Harald Alvestrand698efbc2015-05-18 08:53:0581
82 gFirstConnection.createOffer()
83 .then(function(offer) {
Harald Alvestrandf7a85392015-05-20 08:05:1584 atStep = 'Set local description at first';
85 return gFirstConnection.setLocalDescription(offer);
86 })
87 .then(function() {
88 atStep = 'Set remote description at second';
89 return gSecondConnection.setRemoteDescription(
90 gFirstConnection.localDescription);
Harald Alvestrand698efbc2015-05-18 08:53:0591 })
92 .then(function() {
Harald Alvestrand1a596652015-05-19 08:45:3293 atStep = 'Create answer';
Dominique Hazael-Massieux71948762015-06-15 09:01:1194 return gSecondConnection.createAnswer();
Harald Alvestrand698efbc2015-05-18 08:53:0595 })
96 .then(function(answer) {
Harald Alvestrandf7a85392015-05-20 08:05:1597 atStep = 'Set local description at second';
98 return gSecondConnection.setLocalDescription(answer);
Harald Alvestrand698efbc2015-05-18 08:53:0599 })
100 .then(function() {
Harald Alvestrandf7a85392015-05-20 08:05:15101 atStep = 'Set remote description at first';
102 return gFirstConnection.setRemoteDescription(
103 gSecondConnection.localDescription);
104 })
105 .then(function() {
106 atStep = 'Negotiation completed';
Harald Alvestrand698efbc2015-05-18 08:53:05107 })
108 .catch(test.step_func(function(e) {
Harald Alvestrandba63db82015-05-19 08:33:40109 assert_unreached('Error ' + e.name + ': ' + e.message +
Harald Alvestrand698efbc2015-05-18 08:53:05110 ' happened at step ' + atStep);
111 }));
Harald Alvestrand168935a2015-05-13 08:23:14112 });
113</script>
114
115</body>
116</html>