bug 965656 - properly close() PC's when no longer used. r=jesup

This commit is contained in:
Nils Ohlmeier [:drno] 2014-04-02 13:56:00 +02:00
Родитель adcc7d481e
Коммит 64ef568ebe
5 изменённых файлов: 105 добавлений и 5 удалений

Просмотреть файл

@ -53,6 +53,7 @@ skip-if = toolkit=='gonk' # b2g(Bug 960442, video support for WebRTC is disabled
skip-if = toolkit=='gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g) b2g-debug(Bug 960442, video support for WebRTC is disabled on b2g)
[test_peerConnection_bug834153.html]
[test_peerConnection_bug835370.html]
[test_peerConnection_close.html]
[test_peerConnection_errorCallbacks.html]
[test_peerConnection_offerRequiresReceiveAudio.html]
skip-if = toolkit=='gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g) b2g-debug(Bug 960442, video support for WebRTC is disabled on b2g)

Просмотреть файл

@ -568,7 +568,7 @@ function PCT_setLocalDescription(peer, desc, onSuccess) {
}
peer.onsignalingstatechange = function () {
info(peer + ": 'onsignalingstatechange' event registered for async check");
info(peer + ": 'onsignalingstatechange' event registered, signalingState: " + peer.signalingState);
eventFired = true;
check_next_test();
@ -629,7 +629,7 @@ function PCT_setRemoteDescription(peer, desc, onSuccess) {
}
peer.onsignalingstatechange = function () {
info(peer + ": 'onsignalingstatechange' event registered for async check");
info(peer + ": 'onsignalingstatechange' event registered, signalingState: " + peer.signalingState);
eventFired = true;
check_next_test();

Просмотреть файл

@ -15,12 +15,17 @@
makePC = function (config, expect_success) {
var exception = null;
var pc = null;
try {
var pc = new mozRTCPeerConnection(config);
pc = new mozRTCPeerConnection(config);
} catch (e) {
exception = e;
}
if (pc !== null) {
pc.close();
}
pc = null
if (expect_success) {
ok(!exception, "mozRTCPeerConnection(" +
@ -34,12 +39,19 @@
// This is a test of the iceServers parsing code + readable errors
runTest(function () {
var pc, pcs;
var pcs = null;
var exception = null;
var config;
try { pcs = new mozRTCPeerConnection(); } catch (e) { exception = e; }
try {
pcs = new mozRTCPeerConnection();
} catch (e) {
exception = e;
}
ok(!exception, "mozRTCPeerConnection() succeeds");
if (pcs !== null) {
pcs.close();
}
pcs = null;
exception = null;
@ -69,6 +81,9 @@
ok(e.message.indexOf("http") > 0,
"mozRTCPeerConnection() constructor has readable exceptions");
}
if (pcs !== null) {
pcs.close();
}
pcs = null;
SimpleTest.finish();

Просмотреть файл

@ -15,6 +15,8 @@
function croak(msg) {
ok(0, msg);
pc1.close();
pc2.close();
SimpleTest.finish();
}
@ -30,6 +32,8 @@
pc2.setRemoteDescription(d, function (x) {}, function (x) {});
pc2.createAnswer(function (d) {
is(d.type,"answer","CreateAnswer created an answer");
pc1.close();
pc2.close();
SimpleTest.finish();
}, function (err) {
croak("createAnswer failed: " + err);

Просмотреть файл

@ -0,0 +1,80 @@
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="head.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
bug: "834153",
title: "Basic RTCPeerConnection.close() tests"
});
runTest(function () {
var pc = new mozRTCPeerConnection();
// everything should be in initial state
is(pc.signalingState, "stable", "Initial signalingState is 'stable'");
is(pc.iceConnectionState, "new", "Initial iceConnectionState is 'new'");
is(pc.iceGatheringState, "new", "Initial iceGatheringState is 'new'");
setTimeout(function() {
var exception = null;
var signalstatechanged = false;
// we did not send or receive and offer or answer
is(pc.signalingState, "stable", "Middle signalingState is 'stable'");
// we have not established a connection
is(pc.iceConnectionState, "new", "Middle iceConnectionState is 'new'");
// apparently there is no callback for iceGatheringState
// we could only run a poll loop, so for now we just hope... it is complete
is(pc.iceGatheringState, "complete", "Final iceGatheringState is 'complete'");
pc.onsignalingstatechange = function() {
signalstatechanged = true;
info(self + ": onsignalingstatechange fired, new state is: " + pc.signalingState);
};
try {
pc.close();
} catch (e) {
exception = e;
}
is(pc.signalingState, "closed", "Final signalingState is 'closed'");
is(pc.iceConnectionState, "closed", "Final iceConnectionState is 'closed'");
is(pc.iceGatheringState, "complete", "Final iceGatheringState is 'complete'");
is(exception, null, "closing the connection raises no exception");
exception = null;
// wait some time if we receive the signalstate callback
setTimeout(function() {
todo(signalstatechanged, "Closing the connection should create a callback");
pc.onsignalingstatechange = null;
try {
pc.close();
} catch (e) {
exception = e;
}
todo(!exception, "A second close() should not raise an exception");
is(pc.signalingState, "closed", "Final signalingState stays at 'closed'");
is(pc.iceConnectionState, "closed", "Final iceConnectionState stays at 'closed'");
is(pc.iceGatheringState, "complete", "Final iceGatheringState stays at 'complete'");
// destroy the PC object to be safe
pc = null;
SimpleTest.finish();
}, 1000);
}, 1000);
});
</script>
</pre>
</body>
</html>