2 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
5 <script src=
"../../resources/js-test.js"></script>
9 description("Tests the RTCPeerConnection stats interface.");
14 function getUserMedia(dictionary
, callback
) {
16 navigator
.webkitGetUserMedia(dictionary
, callback
, error
);
18 testFailed('webkitGetUserMedia threw exception :' + e
);
24 testFailed('Stream generation failed.');
28 function verifyStats(status
)
30 // Status must be a global variable to be used in test statements.
32 result
= status
.result();
33 shouldBeGreaterThanOrEqual('result.length', '2');
34 // Windows XP sometimes gives time that appears to go backwards.
35 // This hack will make the tests non-flaky if it never goes backwards
36 // by more than 20 milliseconds.
37 // Up to 10 milliseconds has been observed on XP, 2 milliseconds on Win7.
40 timediff
= res
.timestamp
- startTime
+ fudgeForXP
;
41 shouldBeGreaterThanOrEqual('timediff', '0');
42 shouldBeNonNull('res.id');
43 shouldBeNonNull('res.type');
44 shouldBeGreaterThanOrEqual('res.names().length', '1');
45 shouldBeGreaterThanOrEqual('res.names().indexOf("type")', '0');
46 shouldBe('res.stat("type")', '"audio"');
47 // Named getter: Can access results by their ID values.
48 shouldBeNonNull('status_g.namedItem(res.id)');
49 shouldBeNonNull('status_g[res.id]');
52 function statsHandler1(status
)
54 testPassed("statsHandler1 was called");
55 shouldBeNonNull('status');
56 result
= status
.result();
57 shouldBe('result.length', '0');
58 shouldNotThrow('getUserMedia({audio:true, video:true}, gotStream)');
61 function gotStream(s
) {
62 testPassed('Got a stream.');
66 shouldNotThrow('pc.getStats(statsHandler2)');
69 function statsHandler2(status
)
71 testPassed("statsHandler2 was called");
73 shouldNotThrow('pc.close()');
74 shouldNotThrow('pc.getStats(statsHandler3)');
77 function statsHandler3(status
)
79 testPassed("statsHandler3 was called");
84 var startTime
= new Date().getTime();
85 shouldNotThrow('pc = new webkitRTCPeerConnection(null)');
86 shouldNotThrow('pc.getStats(statsHandler1)');
88 window
.jsTestIsAsync
= true;
89 window
.successfullyParsed
= true;