commit-queue@webkit.org | 8916576 | 2016-10-27 06:33:21 +0000 | [diff] [blame] | 1 | <!doctype html> |
cdumez@apple.com | 88d4e14 | 2017-10-13 02:04:33 +0000 | [diff] [blame] | 2 | <!-- |
commit-queue@webkit.org | 8916576 | 2016-10-27 06:33:21 +0000 | [diff] [blame] | 3 | This test uses data only, and thus does not require fake media devices. |
cdumez@apple.com | 88d4e14 | 2017-10-13 02:04:33 +0000 | [diff] [blame] | 4 | --> |
commit-queue@webkit.org | 8916576 | 2016-10-27 06:33:21 +0000 | [diff] [blame] | 5 | |
| 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.com | 88d4e14 | 2017-10-13 02:04:33 +0000 | [diff] [blame] | 17 | <!-- These files are in place when executing on W3C. --> |
commit-queue@webkit.org | 8916576 | 2016-10-27 06:33:21 +0000 | [diff] [blame] | 18 | <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.org | 8916576 | 2016-10-27 06:33:21 +0000 | [diff] [blame] | 39 | 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.com | cd405bc | 2020-07-09 23:04:17 +0000 | [diff] [blame] | 69 | test.add_cleanup(() => gFirstConnection.close()); |
commit-queue@webkit.org | 8916576 | 2016-10-27 06:33:21 +0000 | [diff] [blame] | 70 | gFirstConnection.onicecandidate = onIceCandidateToFirst; |
| 71 | gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange; |
| 72 | |
| 73 | gSecondConnection = new RTCPeerConnection(null); |
cdumez@apple.com | cd405bc | 2020-07-09 23:04:17 +0000 | [diff] [blame] | 74 | test.add_cleanup(() => gSecondConnection.close()); |
commit-queue@webkit.org | 8916576 | 2016-10-27 06:33:21 +0000 | [diff] [blame] | 75 | gSecondConnection.onicecandidate = onIceCandidateToSecond; |
commit-queue@webkit.org | 8916576 | 2016-10-27 06:33:21 +0000 | [diff] [blame] | 76 | 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> |