OLD | NEW |
| (Empty) |
1 | |
2 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
3 <html> | |
4 <head> | |
5 <script src="../../resources/js-test.js"></script> | |
6 </head> | |
7 <body> | |
8 <script> | |
9 description("Tests the RTCPeerConnection stats interface."); | |
10 | |
11 var pc = null; | |
12 var result; | |
13 var timestamp; | |
14 var local; | |
15 | |
16 function getUserMedia(dictionary, callback) { | |
17 try { | |
18 navigator.webkitGetUserMedia(dictionary, callback, error); | |
19 } catch (e) { | |
20 testFailed('webkitGetUserMedia threw exception :' + e); | |
21 finishJSTest(); | |
22 } | |
23 } | |
24 | |
25 function error() { | |
26 testFailed('Stream generation failed.'); | |
27 finishJSTest(); | |
28 } | |
29 | |
30 function verifyStats(status) | |
31 { | |
32 // Status must be a global variable to be used in test statements. | |
33 status_g = status; | |
34 result = status.result(); | |
35 shouldBeGreaterThanOrEqual('result.length', '2'); | |
36 // The "local" interface is deprecated. Keep test until interface deleted. | |
37 local = result[0].local; | |
38 timestamp = local.timestamp; | |
39 // Windows XP sometimes gives time that appears to go backwards. | |
40 // This hack will make the tests non-flaky if it never goes backwards | |
41 // by more than 20 milliseconds. | |
42 // Up to 10 milliseconds has been observed on XP, 2 milliseconds on Win7. | |
43 fudgeForXP = 20; | |
44 timediff = timestamp - startTime + fudgeForXP; | |
45 shouldBeGreaterThanOrEqual('timediff', '0'); | |
46 shouldBeGreaterThanOrEqual('local.names().length', '1'); | |
47 shouldBeGreaterThanOrEqual('local.names().indexOf("type")', '0'); | |
48 shouldBe('local.stat("type")', '"audio"'); | |
49 // Newer interface. | |
50 res = result[0]; | |
51 timediff = timestamp - startTime + fudgeForXP; | |
52 shouldBeGreaterThanOrEqual('timediff', '0'); | |
53 shouldBeNonNull('res.id'); | |
54 shouldBeNonNull('res.type'); | |
55 shouldBeGreaterThanOrEqual('res.names().length', '1'); | |
56 shouldBeGreaterThanOrEqual('res.names().indexOf("type")', '0'); | |
57 shouldBe('res.stat("type")', '"audio"'); | |
58 // Named getter: Can access results by their ID values. | |
59 shouldBeNonNull('status_g.namedItem(res.id)'); | |
60 shouldBeNonNull('status_g[res.id]'); | |
61 } | |
62 | |
63 function statsHandler1(status) | |
64 { | |
65 testPassed("statsHandler1 was called"); | |
66 shouldBeNonNull('status'); | |
67 result = status.result(); | |
68 shouldBe('result.length', '0'); | |
69 shouldNotThrow('getUserMedia({audio:true, video:true}, gotStream)'); | |
70 } | |
71 | |
72 function gotStream(s) { | |
73 testPassed('Got a stream.'); | |
74 stream = s; | |
75 | |
76 pc.addStream(stream); | |
77 shouldNotThrow('pc.getStats(statsHandler2)'); | |
78 } | |
79 | |
80 function statsHandler2(status) | |
81 { | |
82 testPassed("statsHandler2 was called"); | |
83 verifyStats(status); | |
84 shouldNotThrow('pc.close()'); | |
85 shouldNotThrow('pc.getStats(statsHandler3)'); | |
86 } | |
87 | |
88 function statsHandler3(status) | |
89 { | |
90 testPassed("statsHandler3 was called"); | |
91 verifyStats(status); | |
92 finishJSTest(); | |
93 } | |
94 | |
95 var startTime = new Date().getTime(); | |
96 shouldNotThrow('pc = new webkitRTCPeerConnection(null)'); | |
97 shouldNotThrow('pc.getStats(statsHandler1)'); | |
98 | |
99 window.jsTestIsAsync = true; | |
100 window.successfullyParsed = true; | |
101 </script> | |
102 </body> | |
103 </html> | |
OLD | NEW |