blob: 35058639ae3486efc9ce19879972cc879ba50630 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("Tests the RTCPeerConnection stats interface.");
var pc = null;
var result;
var timestamp;
var local;
function getUserMedia(dictionary, callback) {
try {
navigator.webkitGetUserMedia(dictionary, callback, error);
} catch (e) {
testFailed('webkitGetUserMedia threw exception :' + e);
finishJSTest();
}
}
function error() {
testFailed('Stream generation failed.');
finishJSTest();
}
function statsHandler1(status)
{
testPassed("statsHandler1 was called");
shouldBeNonNull('status');
result = status.result();
shouldBe('result.length', '0');
shouldNotThrow('getUserMedia({audio:true, video:true}, gotStream)');
}
function gotStream(s) {
testPassed('Got a stream.');
stream = s;
pc.addStream(stream);
shouldNotThrow('pc.getStats(statsHandler2)');
}
function statsHandler2(status)
{
testPassed("statsHandler2 was called");
// Status must be a global variable to be used in test statements.
status_g = status;
result = status.result();
shouldBeGreaterThanOrEqual('result.length', '2');
// The "local" interface is deprecated. Keep test until interface deleted.
local = result[0].local;
timestamp = local.timestamp;
shouldBeGreaterThanOrEqual('timestamp', 'startTime');
shouldBeGreaterThanOrEqual('local.names().length', '1');
shouldBeGreaterThanOrEqual('local.names().indexOf("type")', '0');
shouldBe('local.stat("type")', '"audio"');
// Newer interface.
res = result[0];
shouldBeGreaterThanOrEqual('res.timestamp', 'startTime');
shouldBeNonNull('res.id');
shouldBeNonNull('res.type');
shouldBeGreaterThanOrEqual('res.names().length', '1');
shouldBeGreaterThanOrEqual('res.names().indexOf("type")', '0');
shouldBe('res.stat("type")', '"audio"');
// Named getter: Can access results by their ID values.
shouldBeNonNull('status_g.namedItem(res.id)');
shouldBeNonNull('status_g[res.id]');
finishJSTest();
}
var startTime = new Date().getTime();
shouldNotThrow('pc = new webkitRTCPeerConnection(null)');
shouldNotThrow('pc.getStats(statsHandler1)');
window.jsTestIsAsync = true;
window.successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>