Bug 951892 - Adding ICE Connection state checks to PeerConnection Mochitests r=abr

This commit is contained in:
Nils Ohlmeier [:drno] 2013-12-20 14:00:00 -06:00
parent e0fcc8ecec
commit beb013fc2a
2 changed files with 124 additions and 1 deletions

View File

@ -976,8 +976,20 @@ function PeerConnectionWrapper(label, configuration) {
var self = this;
// This enables tests to validate that the next ice state is the one they expect to happen
this.next_ice_state = ""; // in most cases, the next state will be "checking", but in some tests "closed"
// This allows test to register their own callbacks for ICE connection state changes
this.ice_connection_callbacks = [ ];
this._pc.oniceconnectionstatechange = function() {
ok(self._pc.iceConnectionState != undefined, "iceConnectionState should not be undefined");
info(self + ": oniceconnectionstatechange fired, new state is: " + self._pc.iceConnectionState);
if (Object.keys(self.ice_connection_callbacks).length >= 1) {
var it = Iterator(self.ice_connection_callbacks);
var name = "";
var callback = "";
for ([name, callback] in it) {
callback();
}
}
if (self.next_ice_state != "") {
is(self._pc.iceConnectionState, self.next_ice_state, "iceConnectionState changed to '" +
self.next_ice_state + "'");
@ -1081,13 +1093,21 @@ PeerConnectionWrapper.prototype = {
},
/**
* Returns the remote signaling state.
* Returns the signaling state.
*
* @returns {object} The local description
*/
get signalingState() {
return this._pc.signalingState;
},
/**
* Returns the ICE connection state.
*
* @returns {object} The local description
*/
get iceConnectionState() {
return this._pc.iceConnectionState;
},
/**
* Callback when we get media from either side. Also an appropriate
@ -1316,6 +1336,63 @@ PeerConnectionWrapper.prototype = {
}) ;
},
/**
* Returns if the ICE the connection state is "connected".
*
* @returns {boolean} True is the connection state is "connected", otherwise false.
*/
isIceConnected : function PCW_isIceConnected() {
info("iceConnectionState: " + this.iceConnectionState);
return this.iceConnectionState === "connected";
},
/**
* Returns if the ICE the connection state is "checking".
*
* @returns {boolean} True is the connection state is "checking", otherwise false.
*/
isIceChecking : function PCW_isIceChecking() {
return this.iceConnectionState === "checking";
},
/**
* Returns if the ICE the connection state is "new".
*
* @returns {boolean} True is the connection state is "new", otherwise false.
*/
isIceNew : function PCW_isIceNew() {
return this.iceConnectionState === "new";
},
/**
* Registers a callback for the ICE connection state change and
* reports success (=connected) or failure via the callbacks.
* States "new" and "checking" are ignored.
*
* @param {function} onSuccess
* Callback if ICE connection status is "connected".
* @param {function} onFailure
* Callback if ICE connection reaches a different state than
* "new", "checking" or "connected".
*/
waitForIceConnected : function PCW_waitForIceConnected(onSuccess, onFailure) {
var self = this;
var mySuccess = onSuccess;
var myFailure = onFailure;
function iceConnectedChanged () {
if (self.isIceConnected()) {
delete self.ice_connection_callbacks["waitForIceConnected"];
mySuccess();
} else if (! (self.isIceChecking() || self.isIceNew())) {
delete self.ice_connection_callbacks["waitForIceConnected"];
myFailure();
}
};
self.ice_connection_callbacks["waitForIceConnected"] = (function() {iceConnectedChanged()});
},
/**
* Checks that we are getting the media streams we expect.
*

View File

@ -136,6 +136,52 @@ var commandsPeerConnection = [
});
}
],
[
'PC_LOCAL_WAIT_FOR_ICE_CONNECTED',
function (test) {
var myTest = test;
var myPc = myTest.pcLocal;
function onIceConnectedSuccess () {
ok(true, "pc_local: ICE switched to connected state");
myTest.next();
};
function onIceConnectedFailed () {
ok(false, "pc_local: ICE failed to switch to connected");
myTest.next();
};
if (myPc.isIceConnected()) {
ok(true, "pc_local: ICE is in connected state");
myTest.next();
} else {
myPc.waitForIceConnected(onIceConnectedSuccess, onIceConnectedFailed);
}
}
],
[
'PC_REMOTE_WAIT_FOR_ICE_CONNECTED',
function (test) {
var myTest = test;
var myPc = myTest.pcRemote;
function onIceConnectedSuccess () {
ok(true, "pc_remote: ICE switched to connected state");
myTest.next();
};
function onIceConnectedFailed () {
ok(false, "pc_remote: ICE failed to switch to connected");
myTest.next();
};
if (myPc.isIceConnected()) {
ok(true, "pc_remote: ICE is in connected state");
myTest.next();
} else {
myPc.waitForIceConnected(onIceConnectedSuccess, onIceConnectedFailed);
}
}
],
[
'PC_LOCAL_CHECK_MEDIA_STREAMS',
function (test) {