Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peerconnection api tests #277

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions webrtc/featuredetection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// 2012-01-27
// The code below has been stolen from Microsoft's submission tests to the Page Visibility
// specification. Thanks!


// This function returns the value of an API feature if it is defined with one of
// the known ventor prefixes.
//
// Parameters:
// parent: the object containing the API feature
// feature: the name of the API feature, this should be a string value
// isAttribute: set this to true to indicate that this is a constant attribute
// as opposed to a variable
function BrowserHasFeature(parent, feature, isAttribute)
{
if (parent[feature] !== undefined)
{
//feature is defined without a vendor prefix, no further checks necessary
return parent[feature];
}

// the feature is not defined without a vendor prefix, so find the vendor prefix, if any,
// that it is defined with
var prefix = GetVendorPrefix(parent, feature, isAttribute);

// if prefix is not undefined, then the feature has been found to exist with this prefix
if (prefix !== undefined)
{
var prefixedFeatureName = AppendPrefix(prefix, feature, isAttribute);
return parent[prefixedFeatureName];
}

//The feature does not exist.
//Callers should check for !==undefined as the feature itself could return
//a Bool which would fail a typical if(feature) check
return undefined;
}

// returns the name of the feature in the said browser
function FeatureNameInBrowser(parent, feature, isAttribute)
{
if (parent[feature] !== undefined)
{
//feature is defined without a vendor prefix, no further checks necessary
return feature;
}

// the feature is not defined without a vendor prefix, so find the vendor prefix, if any,
// that it is defined with
var prefix = GetVendorPrefix(parent, feature, isAttribute);

// if prefix is not undefined, then the feature has been found to exist with this prefix
if (prefix !== undefined)
{
var prefixedFeatureName = AppendPrefix(prefix, feature, isAttribute);
return prefixedFeatureName;
}

//The feature does not exist.
//Callers should check for !==undefined as the feature itself could return
//a Bool which would fail a typical if(feature) check
return undefined;
}


// This function returns the vendor prefix found if a certain feature is defined with it.
// It takes the same parameters at BrowserHasFeature().
function GetVendorPrefix(parent, feature, isAttribute)
{
//Known vendor prefixes
var VendorPrefixes = ["moz", "ms", "o", "webkit"];
for (vendor in VendorPrefixes)
{
//Build up the new feature name with the vendor prefix
var prefixedFeatureName = AppendPrefix(VendorPrefixes[vendor], feature, isAttribute);
if (parent[prefixedFeatureName] !== undefined)
{
//Vendor prefix version exists, return a pointer to the feature
return VendorPrefixes[vendor];
}
}

// if no version of the feature with a vendor prefix has been found, return undefined
return undefined;
}

// This will properly capitalize the feature name and then return the feature name preceded
// with the provided vendor prefix. If the prefix given is undefined, this function will
// return the feature name given as is. The output of this function should not be used
// as an indicator of whether or not a feature exists as it will return the same thing if
// the inputted feature is undefined or is defined without a vendor prefix. It takes the
// same parameters at BrowserHasFeature().
function AppendPrefix(prefix, feature, isAttribute)
{
if (prefix !== undefined)
{
if (isAttribute)
{
// if a certain feature is an attribute, then it follows a different naming standard
// where it must be completely capitalized and have words split with an underscore
return prefix.toUpperCase() + "_" + feature.toUpperCase();
}
else
{
//Vendor prefixing should follow the standard convention: vendorprefixFeature
//Note that the feature is capitalized after the vendor prefix
//Therefore if the feature is window.feature, the vendor prefix version is:
//window.[vp]Feature where vp is the vendor prefix:
//window.msFeature, window.webkitFeature, window.mozFeature, window.oFeature
var newFeature = feature[0].toUpperCase() + feature.substr(1, feature.length);

//Build up the new feature name with the vendor prefix
return prefix + newFeature;
}
}
else
{
return feature;
}
}
22 changes: 22 additions & 0 deletions webrtc/peer-to-peer-connections/api-present.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<title>RTCPeerconnection: test that RTCPeerConnection is present (with or without vendor prefix)</title>
<meta name='assert' content='Check that the RTCPeerConnection() method is present.'/>
<meta name='flags' content='vendor-prefix, dom'/>
<link rel='stylesheet' href='/resources/testharness.css' media='all'/>
</head>
<body>
<h1>Description</h1>
<p>This test checks for the presence of the <code>RTCPeerConnection</code> method, taking vendor prefixes into account.</p>
<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=../featuredetection.js></script>
<script>
test(function () {
assert_true(undefined !== BrowserHasFeature(window, "RTCPeerConnection"), "RTCPeerconnection exists");
}, "RTCPeerConnection() is present on window");
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions webrtc/peer-to-peer-connections/prefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var api = BrowserHasFeature(window, "RTCPeerConnection");
if (!window.RTCPeerConnection && undefined !== api) {
window.RTCPeerConnection = api;
}
33 changes: 33 additions & 0 deletions webrtc/peer-to-peer-connections/rtcpeerconnection-event.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!doctype html>
<html>
<head>
<title>On a peer connection</title>
<link rel='stylesheet' href='/resources/testharness.css' media='all'/>
</head>
<body>
<h1>Description</h1>
<p>This test checks that a new peer connection triggers the events as expected.</p>

<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=../featuredetection.js></script>
<script src=prefix.js></script>
<script>
var t = async_test("Tests that a new peer triggers events as expected.", {timeout: 20000});
t.step(function () {
var peer, connection, config;

peer = new window.RTCPeerConnection({"iceServers": [{"url": "stun:stun.l.google.com:19302"}]});
peer.onicecandidate = onIceCandidate;

function onIceCandidate(event) {
t.step(function () {
assert_own_property(event, "candidate", "a new candidate is created");
t.done();
});
}
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!doctype html>
<html>
<head>
<title>Mandatory constraint in RTCPeerConnection</title>
<link rel='stylesheet' href='/resources/testharness.css' media='all'/>
</head>
<body>
<h1>Description</h1>
<p>This test checks that setting a trivial mandatory constraint (iceServers) in RTCPeerConnection is required</p>

<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=../featuredetection.js></script>
<script src=prefix.js></script>
<script>
var t = async_test("", {timeout: 10000});
t.step(function () {
var peer1, peer2;

function anotherTry() {
t.step(function() {
try{
peer2 = new window.RTCPeerConnection();
} catch(e){
if(peer2 == undefined) {
t.done();
}
assert_unreached("peer can be created without STUN server");
t.done();
}
}, "ICE connection required");
}

peer1 = new window.RTCPeerConnection({"iceServers": [{"url": "stun:stun.l.google.com:19302"}]});
if(peer1.hasOwnProperty("iceConnectionState")) {
anotherTry();
}
});
</script>
</body>
</html>