Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!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"
});
// ^^^ Don't insert data above this line without adjusting line number below!
var lineNumberAndFunction = {
// <--- 16 is the line this must be.
line: 17, func: () => new RTCPeerConnection().onaddstream = () => {}
};
var makePC = (config, expected_error) => {
var exception;
try {
new RTCPeerConnection(config).close();
} catch (e) {
exception = e;
}
is((exception? exception.name : "success"), expected_error || "success",
"RTCPeerConnection(" + JSON.stringify(config) + ") " + exception?.message);
};
// The order of properties in objects is not guaranteed in JavaScript, so this
// transform produces json-comparable dictionaries. The resulting copy is only
// meant to be used in comparisons (e.g. array-ness is not preserved).
var toComparable = o =>
(typeof o != 'object' || !o)? o : Object.keys(o).sort().reduce((co, key) => {
co[key] = toComparable(o[key]);
return co;
}, {});
// This is a test of the iceServers parsing code + readable errors
runNetworkTest(async () => {
let exception = null;
try {
new RTCPeerConnection().close();
} catch (e) {
exception = e;
}
ok(!exception, "RTCPeerConnection() succeeds");
exception = null;
// Some overlap still with WPT RTCConfiguration-iceServers.html
makePC({ iceServers: [
{ urls:"stun:127.0.0.1" },
{ urls:"stun:localhost", foo:"" },
{ urls: ["stun:127.0.0.1", "stun:localhost"] },
]});
makePC({ iceServers: [
{ urls:"turn:[::1]:3478", username:"p", credential:"p" },
{ urls:"turn:[::1]:3478", username:"", credential:"" },
{ urls:"turns:[::1]:3478", username:"", credential:"" },
]});
makePC({ iceServers: [
{ 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" },
]});
makePC({ iceServers: [{ urls:"http:0.0.0.0" }] }, "SyntaxError");
try {
new RTCPeerConnection({ iceServers: [{ urls:"http:0.0.0.0" }] }).close();
} catch (e) {
ok(e.message.indexOf("http") > 0,
"RTCPeerConnection() constructor has readable exceptions");
}
const push = prefs => SpecialPowers.pushPrefEnv(prefs);
// Remaining tests trigger warnings
await push({ set: [['media.peerconnection.treat_warnings_as_errors', false]] });
makePC({ iceServers: [
{ urls:"stuns:localhost", foo:"" },
{ url:"stun:localhost", foo:"" },
{ url:"turn:localhost", username:"p", credential:"p" }
]});
// Test getConfiguration
const config = {
bundlePolicy: "max-bundle",
iceTransportPolicy: "relay",
peerIdentity: null,
certificates: [],
iceServers: [
{ urls: ["stun:127.0.0.1", "stun:localhost"], credentialType:"password" },
{ urls: ["turn:[::1]:3478"], username:"p", credential:"p", credentialType:"password" },
],
};
// Make sure sdpSemantics is not exposed in getConfiguration
const configWithExtraProps = Object.assign({},
config,
{sdpSemantics: "plan-b"});
ok("sdpSemantics" in configWithExtraProps, "sdpSemantics control");
const pc = new RTCPeerConnection(configWithExtraProps);
is(JSON.stringify(toComparable(pc.getConfiguration())),
JSON.stringify(toComparable(config)), "getConfiguration");
pc.close();
// This set of tests are setting the about:config User preferences for default
// ice servers and checking the outputs when RTCPeerConnection() is
// invoked. See Bug 1167922 for more information.
await push({ set: [['media.peerconnection.default_iceservers', ""]] });
makePC();
await push({ set: [['media.peerconnection.default_iceservers', "k"]] });
makePC();
await push({ set: [['media.peerconnection.default_iceservers',
"[{\"urls\": [\"stun:stun.services.mozilla.com\"]}]"]]});
makePC();
// This set of tests check that warnings work. See Bug 1254839 for more.
const warning = await new Promise(resolve => {
SpecialPowers.registerConsoleListener(msg => {
if (msg.message.includes("onaddstream")) {
SpecialPowers.postConsoleSentinel();
resolve(msg.message);
}
});
lineNumberAndFunction.func();
});
is(warning.split('"')[1],
"WebRTC: onaddstream is deprecated! Use peerConnection.ontrack instead.",
"warning logged");
const remainder = warning.split('"').slice(2).join('"');
info(remainder);
ok(remainder.includes('file: "' + window.location + '"'),
"warning has this file");
ok(remainder.includes('line: ' + lineNumberAndFunction.line),
"warning has correct line number");
});
</script>
</pre>
</body>
</html>