gecko-dev/dom/media/tests/mochitest/test_peerConnection_bug825703.html
Rithesh Shenthar b5aacea0d3 Bug 1167922 - Handle broken entries in media.peerconnection.default_iceservers more gracefully. r=jib
--HG--
extra : rebase_source : 272b59a709de1a65e5b35475e4075492b5ecd310
2015-06-23 16:52:50 -07:00

95 lines
2.9 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "825703",
title: "RTCConfiguration valid/invalid permutations"
});
var makePC = (config, expected_error) => {
var exception;
try {
new mozRTCPeerConnection(config).close();
} catch (e) {
exception = e;
}
is((exception? exception.name : "success"), expected_error || "success",
"mozRTCPeerConnection(" + JSON.stringify(config) + ")");
};
// This is a test of the iceServers parsing code + readable errors
runNetworkTest(() => {
var exception = null;
try {
new mozRTCPeerConnection().close();
} catch (e) {
exception = e;
}
ok(!exception, "mozRTCPeerConnection() succeeds");
exception = null;
makePC();
makePC(1, "TypeError");
makePC({});
makePC({ iceServers: [] });
makePC({ iceServers: [{ urls:"" }] }, "SyntaxError");
makePC({ iceServers: [
{ urls:"stun:127.0.0.1" },
{ urls:"stun:localhost", foo:"" },
{ urls: ["stun:127.0.0.1", "stun:localhost"] },
{ urls:"stuns:localhost", foo:"" },
{ urls:"turn:[::1]:3478", username:"p", credential:"p" },
{ urls:"turn:localhost:3478?transport=udp", username:"p", credential:"p" },
{ urls: ["turn:[::1]:3478", "turn:localhost"], username:"p", credential:"p" },
{ urls:"turns:localhost:3478?transport=udp", username:"p", credential:"p" },
{ url:"stun:localhost", foo:"" },
{ url:"turn:localhost", username:"p", credential:"p" }
]});
makePC({ iceServers: [{ urls: ["stun:127.0.0.1", ""] }] }, "SyntaxError");
makePC({ iceServers: [{ urls:"turns:localhost:3478", username:"p" }] }, "InvalidAccessError");
makePC({ iceServers: [{ url:"turns:localhost:3478", credential:"p" }] }, "InvalidAccessError");
makePC({ iceServers: [{ urls:"http:0.0.0.0" }] }, "SyntaxError");
try {
new mozRTCPeerConnection({ iceServers: [{ url:"http:0.0.0.0" }] }).close();
} catch (e) {
ok(e.message.indexOf("http") > 0,
"mozRTCPeerConnection() constructor has readable exceptions");
}
// Below tests are setting the about:config User preferences for default
// ice servers and checking the outputs when mozRTCPeerConnection() is
// invoked. See Bug 1167922 for more information.
// Note - We use promises here since the SpecialPowers API will be
// performed asynchronously.
var push = prefs => new Promise(resolve =>
SpecialPowers.pushPrefEnv(prefs, resolve));
push({ set: [['media.peerconnection.default_iceservers', ""]] })
.then(() => makePC())
.then(() => push({ set: [['media.peerconnection.default_iceservers', "k"]] }))
.then(() => makePC())
.then(() => push({ set: [['media.peerconnection.default_iceservers', "[{\"urls\": [\"stun:stun.services.mozilla.com\"]}]"]] }))
.then(() => makePC())
.then(networkTestFinished);
});
</script>
</pre>
</body>
</html>