Bug 1164811 - Let TCP presentation server can be inited again in |listener.onClose|. r=fabrice

This commit is contained in:
Junior Hsu 2015-05-14 03:37:00 -04:00
Родитель cb7ae71daf
Коммит 0ea8611993
2 изменённых файлов: 46 добавлений и 15 удалений

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

@ -235,17 +235,21 @@ TCPPresentationServer.prototype = {
onStopListening: function(aServerSocket, aStatus) {
DEBUG && log("TCPPresentationServer - onStopListening: " + aStatus);
// manually closed
if (aStatus === Cr.NS_BINDING_ABORTED) {
if (this._serverSocket) {
DEBUG && log("TCPPresentationServer - should be non-manually closed");
this.close();
} else if (aStatus === Cr.NS_BINDING_ABORTED) {
DEBUG && log("TCPPresentationServer - should be manually closed");
aStatus = Cr.NS_OK;
}
this._listener && this._listener.onClose(aStatus);
this._serverSocket = null;
},
close: function() {
DEBUG && log("TCPPresentationServer - close signalling channel");
DEBUG && log("TCPPresentationServer - close");
if (this._serverSocket) {
DEBUG && log("TCPPresentationServer - close server socket");
this._serverSocket.close();
this._serverSocket = null;
}

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

@ -41,8 +41,7 @@ TestDescription.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationChannelDescription]),
}
function loopOfferAnser()
{
function loopOfferAnser() {
const CONTROLLER_CONTROL_CHANNEL_PORT = 36777;
const PRESENTER_CONTROL_CHANNEL_PORT = 36888;
@ -59,8 +58,6 @@ function loopOfferAnser()
let controllerDevice, controllerControlChannel;
let presenterDevice, presenterControlChannel;
Services.prefs.setBoolPref("dom.presentation.tcp_server.debug", true);
tps = Cc["@mozilla.org/presentation-device/tcp-presentation-server;1"]
.createInstance(Ci.nsITCPPresentationServer);
tps.init(null, PRESENTER_CONTROL_CHANNEL_PORT);
@ -171,20 +168,50 @@ function loopOfferAnser()
};
}
function shutdown()
{
function shutdownAndOneMoreLoop() {
const PRESENTER_CONTROL_CHANNEL_PORT = 36888;
let isFirstClose = true;
let expectedReason;
tps.listener = {
onClose: function(aReason) {
Assert.equal(aReason, Cr.NS_OK, 'TCPPresentationServer close success');
Services.prefs.clearUserPref("dom.presentation.tcp_server.debug");
run_next_test();
expectedReason = isFirstClose ? Cr.NS_ERROR_ABORT // non-manually closed
: Cr.NS_OK; // manually closed
Assert.equal(aReason, expectedReason, 'TCPPresentationServer close as expected');
if (isFirstClose){
isFirstClose = false;
try {
tps.init('controllerID', PRESENTER_CONTROL_CHANNEL_PORT);
tps.close();
} catch (e) {
Assert.ok(false, 'TCP presentation init fail:' + e);
run_next_test();
}
} else {
run_next_test();
}
},
}
tps.close();
// A fake event to pretend the server socket is closed non-manually
tps.QueryInterface(Ci.nsIServerSocketListener)
.onStopListening(null, Cr.NS_ERROR_ABORT);
}
function setPref() {
Services.prefs.setBoolPref("dom.presentation.tcp_server.debug", true);
run_next_test();
}
function clearPref() {
Services.prefs.clearUserPref("dom.presentation.tcp_server.debug");
run_next_test();
}
add_test(setPref);
add_test(loopOfferAnser);
add_test(shutdown);
add_test(shutdownAndOneMoreLoop);
add_test(clearPref);
function run_test() {
run_next_test();