Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: LayoutTests/fast/mediastream/RTCPeerConnection-stats.html

Issue 329093002: Allow PeerConnection to be garbage collected after close(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Data channel now has a weak ptr to the peer connection that created it. Stops itself if creator goe… Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 2 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
3 <html> 3 <html>
4 <head> 4 <head>
5 <script src="../../resources/js-test.js"></script> 5 <script src="../../resources/js-test.js"></script>
6 </head> 6 </head>
7 <body> 7 <body>
8 <script> 8 <script>
9 description("Tests the RTCPeerConnection stats interface."); 9 description("Tests the RTCPeerConnection stats interface.");
10 10
11 var pc = null; 11 var pc = null;
12 var result; 12 var result;
13 var timestamp; 13 var timestamp;
14 var local; 14 var local;
15 15
16 function getUserMedia(dictionary, callback) { 16 function getUserMedia(dictionary, callback) {
17 try { 17 try {
18 navigator.webkitGetUserMedia(dictionary, callback, error); 18 navigator.webkitGetUserMedia(dictionary, callback, error);
19 } catch (e) { 19 } catch (e) {
20 testFailed('webkitGetUserMedia threw exception :' + e); 20 testFailed('webkitGetUserMedia threw exception :' + e);
21 finishJSTest(); 21 finishJSTest();
22 } 22 }
23 } 23 }
24 24
25 function error() { 25 function error() {
26 testFailed('Stream generation failed.'); 26 testFailed('Stream generation failed.');
27 finishJSTest(); 27 finishJSTest();
28 } 28 }
29 29
30 function statsHandler1(status) 30 function verifyStats(status)
31 { 31 {
32 testPassed("statsHandler1 was called");
33 shouldBeNonNull('status');
34 result = status.result();
35 shouldBe('result.length', '0');
36 shouldNotThrow('getUserMedia({audio:true, video:true}, gotStream)');
37 }
38
39 function gotStream(s) {
40 testPassed('Got a stream.');
41 stream = s;
42
43 pc.addStream(stream);
44 shouldNotThrow('pc.getStats(statsHandler2)');
45 }
46
47 function statsHandler2(status)
48 {
49 testPassed("statsHandler2 was called");
50 // Status must be a global variable to be used in test statements. 32 // Status must be a global variable to be used in test statements.
51 status_g = status; 33 status_g = status;
52 result = status.result(); 34 result = status.result();
53 shouldBeGreaterThanOrEqual('result.length', '2'); 35 shouldBeGreaterThanOrEqual('result.length', '2');
54 // The "local" interface is deprecated. Keep test until interface deleted. 36 // The "local" interface is deprecated. Keep test until interface deleted.
55 local = result[0].local; 37 local = result[0].local;
56 timestamp = local.timestamp; 38 timestamp = local.timestamp;
57 // Windows XP sometimes gives time that appears to go backwards. 39 // Windows XP sometimes gives time that appears to go backwards.
58 // This hack will make the tests non-flaky if it never goes backwards 40 // This hack will make the tests non-flaky if it never goes backwards
59 // by more than 20 milliseconds. 41 // by more than 20 milliseconds.
60 // Up to 10 milliseconds has been observed on XP, 2 milliseconds on Win7. 42 // Up to 10 milliseconds has been observed on XP, 2 milliseconds on Win7.
61 fudgeForXP = 20; 43 fudgeForXP = 20;
62 timediff = timestamp - startTime + fudgeForXP; 44 timediff = timestamp - startTime + fudgeForXP;
63 shouldBeGreaterThanOrEqual('timediff', '0'); 45 shouldBeGreaterThanOrEqual('timediff', '0');
64 shouldBeGreaterThanOrEqual('local.names().length', '1'); 46 shouldBeGreaterThanOrEqual('local.names().length', '1');
65 shouldBeGreaterThanOrEqual('local.names().indexOf("type")', '0'); 47 shouldBeGreaterThanOrEqual('local.names().indexOf("type")', '0');
66 shouldBe('local.stat("type")', '"audio"'); 48 shouldBe('local.stat("type")', '"audio"');
67 // Newer interface. 49 // Newer interface.
68 res = result[0]; 50 res = result[0];
69 timediff = timestamp - startTime + fudgeForXP; 51 timediff = timestamp - startTime + fudgeForXP;
70 shouldBeGreaterThanOrEqual('timediff', '0'); 52 shouldBeGreaterThanOrEqual('timediff', '0');
71 shouldBeNonNull('res.id'); 53 shouldBeNonNull('res.id');
72 shouldBeNonNull('res.type'); 54 shouldBeNonNull('res.type');
73 shouldBeGreaterThanOrEqual('res.names().length', '1'); 55 shouldBeGreaterThanOrEqual('res.names().length', '1');
74 shouldBeGreaterThanOrEqual('res.names().indexOf("type")', '0'); 56 shouldBeGreaterThanOrEqual('res.names().indexOf("type")', '0');
75 shouldBe('res.stat("type")', '"audio"'); 57 shouldBe('res.stat("type")', '"audio"');
76 // Named getter: Can access results by their ID values. 58 // Named getter: Can access results by their ID values.
77 shouldBeNonNull('status_g.namedItem(res.id)'); 59 shouldBeNonNull('status_g.namedItem(res.id)');
78 shouldBeNonNull('status_g[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);
79 finishJSTest(); 92 finishJSTest();
80 } 93 }
81 94
82 var startTime = new Date().getTime(); 95 var startTime = new Date().getTime();
83 shouldNotThrow('pc = new webkitRTCPeerConnection(null)'); 96 shouldNotThrow('pc = new webkitRTCPeerConnection(null)');
84 shouldNotThrow('pc.getStats(statsHandler1)'); 97 shouldNotThrow('pc.getStats(statsHandler1)');
85 98
86 window.jsTestIsAsync = true; 99 window.jsTestIsAsync = true;
87 window.successfullyParsed = true; 100 window.successfullyParsed = true;
88 </script> 101 </script>
89 </body> 102 </body>
90 </html> 103 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698