| 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 | |
| 14 function getUserMedia(dictionary, callback) { | |
| 15 try { | |
| 16 navigator.webkitGetUserMedia(dictionary, callback, error); | |
| 17 } catch (e) { | |
| 18 testFailed('webkitGetUserMedia threw exception :' + e); | |
| 19 finishJSTest(); | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 function error() { | |
| 24 testFailed('Stream generation failed.'); | |
| 25 finishJSTest(); | |
| 26 } | |
| 27 | |
| 28 function verifyStats(status) | |
| 29 { | |
| 30 // Status must be a global variable to be used in test statements. | |
| 31 status_g = status; | |
| 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. | |
| 38 fudgeForXP = 20; | |
| 39 res = result[0]; | |
| 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]'); | |
| 50 } | |
| 51 | |
| 52 function statsHandler1(status) | |
| 53 { | |
| 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)'); | |
| 59 } | |
| 60 | |
| 61 function gotStream(s) { | |
| 62 testPassed('Got a stream.'); | |
| 63 stream = s; | |
| 64 | |
| 65 pc.addStream(stream); | |
| 66 shouldNotThrow('pc.getStats(statsHandler2)'); | |
| 67 } | |
| 68 | |
| 69 function statsHandler2(status) | |
| 70 { | |
| 71 testPassed("statsHandler2 was called"); | |
| 72 verifyStats(status); | |
| 73 shouldNotThrow('pc.close()'); | |
| 74 shouldNotThrow('pc.getStats(statsHandler3)'); | |
| 75 } | |
| 76 | |
| 77 function statsHandler3(status) | |
| 78 { | |
| 79 testPassed("statsHandler3 was called"); | |
| 80 verifyStats(status); | |
| 81 finishJSTest(); | |
| 82 } | |
| 83 | |
| 84 var startTime = new Date().getTime(); | |
| 85 shouldNotThrow('pc = new webkitRTCPeerConnection(null)'); | |
| 86 shouldNotThrow('pc.getStats(statsHandler1)'); | |
| 87 | |
| 88 window.jsTestIsAsync = true; | |
| 89 window.successfullyParsed = true; | |
| 90 </script> | |
| 91 </body> | |
| 92 </html> | |
| OLD | NEW |