adam.bergkvist@ericsson.com | 0717784 | 2016-10-06 17:27:23 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | |
| 3 | <html> |
| 4 | <head> |
| 5 | <script src="../../resources/js-test-pre.js"></script> |
| 6 | </head> |
| 7 | <body> |
| 8 | <script> |
| 9 | description("Test RTCPeerConnection 'iceconnectionstatechange' event"); |
| 10 | |
commit-queue@webkit.org | 37ca965 | 2017-01-27 04:54:09 +0000 | [diff] [blame] | 11 | if (window.internals) |
| 12 | internals.useMockRTCPeerConnectionFactory("ICEConnectionState"); |
| 13 | |
adam.bergkvist@ericsson.com | 0717784 | 2016-10-06 17:27:23 +0000 | [diff] [blame] | 14 | let expectedState; |
| 15 | let expectedStates = [ |
| 16 | "checking", |
| 17 | "connected", |
| 18 | "completed", |
| 19 | "failed", |
| 20 | "disconnected", |
| 21 | "new" |
| 22 | ]; |
| 23 | |
| 24 | if (window.testRunner) |
| 25 | testRunner.setUserMediaPermission(true); |
| 26 | else { |
| 27 | debug("This test can not be run without the testRunner"); |
| 28 | finishJSTest(); |
| 29 | } |
| 30 | |
commit-queue@webkit.org | 131c376 | 2016-10-28 18:09:41 +0000 | [diff] [blame] | 31 | const pc = new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]}); |
adam.bergkvist@ericsson.com | 0717784 | 2016-10-06 17:27:23 +0000 | [diff] [blame] | 32 | |
| 33 | pc.oniceconnectionstatechange = function () { |
| 34 | testPassed("Got icetransportstatechange event"); |
| 35 | |
| 36 | expectedState = expectedStates.shift(); |
| 37 | debug(`expectedState is "${expectedState}"`); |
| 38 | shouldBe("pc.iceConnectionState", "expectedState"); |
| 39 | debug(""); |
| 40 | |
| 41 | if (pc.iceConnectionState === "new") |
| 42 | finishJSTest(); |
| 43 | }; |
| 44 | |
| 45 | navigator.mediaDevices.getUserMedia({ "video": true }).then(function (stream) { |
| 46 | const stream2 = stream.clone(); |
| 47 | const stream3 = stream.clone(); |
| 48 | |
| 49 | pc.addTrack(stream.getTracks()[0], stream); |
| 50 | pc.addTrack(stream2.getTracks()[0], stream2); |
| 51 | pc.addTrack(stream3.getTracks()[0], stream3); |
| 52 | |
| 53 | return pc.createOffer(); |
| 54 | }) |
| 55 | .then(function (offer) { |
| 56 | return pc.setLocalDescription(offer); |
| 57 | }) |
| 58 | .then(function () { |
| 59 | testPassed("Local description set"); |
| 60 | shouldBe("pc.getTransceivers().length", "3"); |
| 61 | shouldBe("pc.iceConnectionState", "'new'"); |
| 62 | |
| 63 | window.internals.emulateRTCPeerConnectionPlatformEvent(pc, "step-ice-transport-states"); |
| 64 | testPassed("End of test promise chain"); |
| 65 | debug(""); |
| 66 | }) |
| 67 | .catch(function (error) { |
| 68 | testFailed("Error in promise chain: " + error); |
| 69 | finishJSTest(); |
| 70 | }); |
| 71 | |
| 72 | window.jsTestIsAsync = true; |
| 73 | window.successfullyParsed = true; |
| 74 | |
| 75 | </script> |
| 76 | <script src="../../resources/js-test-post.js"></script> |
| 77 | </body> |
| 78 | </html> |