chromium/third_party/blink/web_tests/fast/peerconnection/RTCPeerConnection.html

<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
description("Tests the RTCPeerConnection constructor.");

shouldBe("webkitRTCPeerConnection", "RTCPeerConnection");

shouldNotThrow("new RTCPeerConnection(null);");
shouldNotThrow("new RTCPeerConnection(undefined);");
shouldNotThrow("new RTCPeerConnection({});");
shouldNotThrow("new RTCPeerConnection();");
shouldThrow("new RTCPeerConnection('');");

shouldNotThrow("new RTCPeerConnection({iceServers:[]});");
shouldNotThrow("new RTCPeerConnection({iceServers:[{url:'stun:foo.com'}]});");
shouldNotThrow("new RTCPeerConnection({iceServers:[{url:'turn:foo.com', username:'x', credential:'x'}]});");
shouldNotThrow("new RTCPeerConnection({iceServers:[{url:'turn:foo.com', username:'x', credential:'x'},{url:'stun:bar.com'}]});");
shouldNotThrow("new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]});");
shouldNotThrow("new RTCPeerConnection({iceServers:[{urls:['stun:foo.com', 'turn:foo.com'], username:'x', credential:'x'}]});");
shouldThrow("new RTCPeerConnection({iceServers:[{urls:['stun:foo.com', 'turn:foo.com']}]});");

shouldNotThrow("new RTCPeerConnection({fooServers:[]});");
shouldThrow("new RTCPeerConnection({iceServers:true});");
shouldThrow("new RTCPeerConnection({iceServers:[1, 2, 3]});");
shouldThrow("new RTCPeerConnection({iceServers:[{}]});");
shouldThrow("new RTCPeerConnection({iceServers:[{url:'foo'}]});");
shouldThrow("new RTCPeerConnection({iceServers:[{urls:'unsupported:scheme'}]});");
shouldThrow("new RTCPeerConnection({iceServers:[{urls:[1, 'turn:foo.com']}]});");

shouldNotThrow("new RTCPeerConnection({iceServers:[], iceTransportPolicy:'relay'});");
shouldNotThrow("new RTCPeerConnection({iceServers:[], iceTransportPolicy:'all'});");
shouldThrow("new RTCPeerConnection({iceServers:[], iceTransportPolicy:'none'});");
shouldThrow("new RTCPeerConnection({iceServers:[], iceTransportPolicy:'foo'});");

// TODO(foolip): |iceTransports| is not in the spec.
shouldNotThrow("new RTCPeerConnection({iceServers:[], iceTransports:'relay'});");
shouldNotThrow("new RTCPeerConnection({iceServers:[], iceTransports:'all'});");
shouldThrow("new RTCPeerConnection({iceServers:[], iceTransports:'none'});");
shouldThrow("new RTCPeerConnection({iceServers:[], iceTransports:'foo'});");

shouldNotThrow("new RTCPeerConnection({iceServers:[], bundlePolicy:'balanced'});");
shouldNotThrow("new RTCPeerConnection({iceServers:[], bundlePolicy:'max-bundle'});");
shouldNotThrow("new RTCPeerConnection({iceServers:[], bundlePolicy:'max-compat'});");
shouldThrow("new RTCPeerConnection({iceServers:[], bundlePolicy:'foo'});");

shouldNotThrow("new RTCPeerConnection({iceServers:[], rtcpMuxPolicy:'negotiate'});");
shouldNotThrow("new RTCPeerConnection({iceServers:[], rtcpMuxPolicy:'require'});");
shouldThrow("new RTCPeerConnection({iceServers:[], rtcpMuxPolicy:'foo'});");

shouldNotThrow("new RTCPeerConnection({iceCandidatePoolSize:0});");
shouldNotThrow("new RTCPeerConnection({iceCandidatePoolSize:1});");
shouldNotThrow("new RTCPeerConnection({iceCandidatePoolSize:255});");
shouldThrow("new RTCPeerConnection({iceCandidatePoolSize:-1});");
shouldThrow("new RTCPeerConnection({iceCandidatePoolSize:99999999});");
shouldThrow("new RTCPeerConnection({iceCandidatePoolSize:256});");
shouldThrow("new RTCPeerConnection({iceCandidatePoolSize:'foo'});");

// Invalid constraints don't throw, including unshipped feature googIPv6.
shouldNotThrow("new RTCPeerConnection(null, {mandatory:{googIPv6:true}});");
shouldNotThrow("new RTCPeerConnection(null, {mandatory:{googIPv6:false}});");
shouldNotThrow("new RTCPeerConnection(null, {mandatory:{googInvalid:true}});");
shouldNotThrow("new RTCPeerConnection(null, {mandatory:{googInvalid:false}});");
shouldNotThrow("new RTCPeerConnection(null, {optional:[{googIPv6:true}]});");
shouldNotThrow("new RTCPeerConnection(null, {optional:[{googIPv6:false}]});");
shouldNotThrow("new RTCPeerConnection(null, {optional:[{googInvalid:true}]});");
shouldNotThrow("new RTCPeerConnection(null, {optional:[{googInvalid:false}]});");
shouldNotThrow("new RTCPeerConnection(null, {mandatory:{googIPv6:123}});");
shouldNotThrow("new RTCPeerConnection(null, {optional:[{googIPv6:123}]});");

// Construct with certificates.
shouldThrow("new RTCPeerConnection({iceServers:[], certificates:null});");
shouldNotThrow("new RTCPeerConnection({iceServers:[], certificates:undefined});");
shouldNotThrow("new RTCPeerConnection({iceServers:[], certificates:[]});");
shouldThrow("new RTCPeerConnection({iceServers:[], certificates:[null]});");
shouldThrow("new RTCPeerConnection({iceServers:[], certificates:[1337]});");
// Global certificate variables so that the "should..." methods can evaluate them.
var certRSA = null;
var certECDSA = null;
var certExpired = null;

function testCertificates1RSA()
{
    RTCPeerConnection.generateCertificate({ name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" })
        .then(function(certificate) {
                  certRSA = certificate;
                  shouldNotThrow('new RTCPeerConnection({iceServers:[], certificates:[certRSA]}, null);');
                  testCertificates2ECDSA();
              },
              function() {
                  testFailed('Generating RSA 2048');
                  testCertificates2ECDSA();
              });
}
function testCertificates2ECDSA()
{
    RTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-256" })
        .then(function(certificate) {
                  certECDSA = certificate;
                  shouldNotThrow('new RTCPeerConnection({iceServers:[], certificates:[certECDSA]}, null);');
                  testCertificates3Expired();
              },
              function() {
                  testFailed('Generating ECDSA P-256');
                  testCertificates3Expired();
              });
}
function testCertificates3Expired()
{
    RTCPeerConnection.generateCertificate({ name: "ECDSA", namedCurve: "P-256", expires:0 })
        .then(function(certificate) {
                  certExpired = certificate;
                  shouldBeTrue('certExpired.expires <= new Date().getTime()');
                  shouldThrow('new RTCPeerConnection({iceServers:[], certificates:[certExpired]}, null);');
                  finishJSTest();
              },
              function() {
                  testFailed('Generating ECDSA P-256');
                  finishJSTest();
              });
}
// Sequentially test construction with RSA and ECDSA certificates.
// testCertificates3Expired's callback methods mark the end of the async tests.
testCertificates1RSA();

window.jsTestIsAsync = true;
window.successfullyParsed = true;
</script>
</body>
</html>