adam.bergkvist@ericsson.com | d63713d | 2016-06-14 16:41:18 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | |
| 3 | <html> |
| 4 | <head> |
| 5 | <script src="../../resources/js-test-pre.js"></script> |
| 6 | <script src="resources/promise-utils.js"></script> |
| 7 | </head> |
| 8 | <body> |
| 9 | <script> |
| 10 | let stream; |
| 11 | let track; |
| 12 | |
| 13 | let sdpMLineIndex = 0; |
| 14 | let badSdpMLineIndex; |
| 15 | let sdpMid = null; |
| 16 | let badSdpMid; |
| 17 | const validCandidate = "candidate:1 1 UDP 2013266431 172.17.0.1 44474 typ host"; |
| 18 | |
| 19 | description("Test behavior of RTCPeerConnection.addIceCandidate"); |
| 20 | |
| 21 | if (window.testRunner) |
| 22 | testRunner.setUserMediaPermission(true); |
| 23 | else { |
| 24 | debug("This test can not be run without the testRunner"); |
| 25 | finishJSTest(); |
| 26 | } |
| 27 | |
commit-queue@webkit.org | 131c376 | 2016-10-28 18:09:41 +0000 | [diff] [blame] | 28 | const pc = new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]}); |
| 29 | const remotePc = new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]}); |
adam.bergkvist@ericsson.com | d63713d | 2016-06-14 16:41:18 +0000 | [diff] [blame] | 30 | |
| 31 | debug("<br>*** A remote description is needed before a candidate can be added"); |
| 32 | shouldBe("pc.remoteDescription", "null"); |
| 33 | promiseShouldReject("pc.addIceCandidate(new RTCIceCandidate({candidate: 'foo', sdpMid: 0}))").then(function () { |
| 34 | return navigator.mediaDevices.getUserMedia({ "audio": true, "video": true }); |
| 35 | }) |
| 36 | .then(function (s) { |
| 37 | stream = s; |
| 38 | track = stream.getTracks()[0]; |
| 39 | |
| 40 | remotePc.addTrack(track, stream); |
| 41 | return remotePc.createOffer(); |
| 42 | }) |
| 43 | .then(function (remoteOffer) { |
| 44 | return pc.setRemoteDescription(remoteOffer); |
| 45 | }) |
| 46 | .then(function () { |
| 47 | testPassed("Remote description set"); |
| 48 | |
| 49 | debug("<br>*** Define sdpMid, badSdpMid, sdpMLineIndex and badSdpMLineIndex for testing"); |
| 50 | badSdpMLineIndex = sdpMLineIndex + pc.getTransceivers().length + 10; |
| 51 | shouldNotBe("sdpMLineIndex", "badSdpMLineIndex"); |
| 52 | |
commit-queue@webkit.org | b6cf2c6 | 2017-03-28 21:17:12 +0000 | [diff] [blame] | 53 | sdpMid = pc.getTransceivers()[0] ? pc.getTransceivers()[0].mid : null; |
adam.bergkvist@ericsson.com | d63713d | 2016-06-14 16:41:18 +0000 | [diff] [blame] | 54 | shouldNotBe("sdpMid", "null"); |
| 55 | badSdpMid = sdpMid + "_foo"; |
| 56 | shouldNotBe("sdpMid", "badSdpMid"); |
| 57 | |
commit-queue@webkit.org | 3a5954d | 2017-03-29 04:09:14 +0000 | [diff] [blame] | 58 | sdpMid = 1; |
| 59 | |
adam.bergkvist@ericsson.com | d63713d | 2016-06-14 16:41:18 +0000 | [diff] [blame] | 60 | return promiseShouldReject("pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: badSdpMid}))"); |
| 61 | }) |
| 62 | .then(function () { |
| 63 | return promiseShouldReject("pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMLineIndex: badSdpMLineIndex}))"); |
| 64 | }) |
| 65 | .then(function () { |
| 66 | debug("*** A (bad) sdpMid takes precedesce over valid sdpMLineIndex"); |
| 67 | return promiseShouldReject("pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: badSdpMid, sdpMLineIndex: sdpMLineIndex}))"); |
| 68 | }) |
| 69 | .then(function () { |
| 70 | debug("*** Test bad candidate content with valid sdpMid"); |
| 71 | return promiseShouldReject("pc.addIceCandidate(new RTCIceCandidate({candidate: 'bad content', sdpMid: sdpMid}))"); |
| 72 | }) |
| 73 | .then(function () { |
| 74 | debug("*** Test bad candidate content with valid sdpMLineIndex"); |
| 75 | return promiseShouldReject("pc.addIceCandidate(new RTCIceCandidate({candidate: 'bad content', sdpMLineIndex: sdpMLineIndex}))"); |
| 76 | }) |
| 77 | .then(function () { |
commit-queue@webkit.org | 3a5954d | 2017-03-29 04:09:14 +0000 | [diff] [blame] | 78 | debug("*** Test valid candidate with no mid and mlineindex"); |
| 79 | return promiseShouldReject("pc.addIceCandidate({candidate: validCandidate})"); |
| 80 | }) |
| 81 | .then(function () { |
adam.bergkvist@ericsson.com | d63713d | 2016-06-14 16:41:18 +0000 | [diff] [blame] | 82 | debug("<br>*** Test some OK input"); |
commit-queue@webkit.org | 5530d95 | 2017-01-31 17:52:33 +0000 | [diff] [blame] | 83 | // Testing passing a RTCIceCandidateInit |
| 84 | return promiseShouldResolve("pc.addIceCandidate({candidate: validCandidate, sdpMid: sdpMid})"); |
adam.bergkvist@ericsson.com | d63713d | 2016-06-14 16:41:18 +0000 | [diff] [blame] | 85 | }) |
| 86 | .then(function () { |
commit-queue@webkit.org | 3a5954d | 2017-03-29 04:09:14 +0000 | [diff] [blame] | 87 | return promiseShouldResolve("pc.addIceCandidate({candidate: validCandidate, sdpMLineIndex: sdpMLineIndex})"); |
| 88 | }) |
| 89 | .then(function () { |
| 90 | return promiseShouldResolve("pc.addIceCandidate(undefined)"); |
| 91 | }) |
| 92 | .then(function () { |
| 93 | return promiseShouldResolve("pc.addIceCandidate(null)"); |
| 94 | }) |
| 95 | .then(function () { |
commit-queue@webkit.org | 5530d95 | 2017-01-31 17:52:33 +0000 | [diff] [blame] | 96 | // Testing passing a RTCIceCandidate |
adam.bergkvist@ericsson.com | d63713d | 2016-06-14 16:41:18 +0000 | [diff] [blame] | 97 | return promiseShouldResolve("pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMLineIndex: sdpMLineIndex}))"); |
| 98 | }) |
| 99 | .then(function () { |
| 100 | debug("*** A valid sdpMid takes precedesce over a bad sdpMLineIndex"); |
| 101 | return promiseShouldResolve("pc.addIceCandidate(new RTCIceCandidate({candidate: validCandidate, sdpMid: sdpMid, sdpMLineIndex: badSdpMLineIndex}))"); |
| 102 | }) |
| 103 | .then(function () { |
| 104 | testPassed("End of test promise chain"); |
| 105 | finishJSTest(); |
| 106 | }) |
| 107 | .catch(function (error) { |
| 108 | testFailed("Error in promise chain: " + error); |
| 109 | finishJSTest(); |
| 110 | }); |
| 111 | |
| 112 | window.jsTestIsAsync = true; |
| 113 | window.successfullyParsed = true; |
| 114 | |
| 115 | </script> |
| 116 | <script src="../../resources/js-test-post.js"></script> |
| 117 | </body> |
| 118 | </html> |