Bug 1475004 - Enable ESLint for dom/presentation - automatic fixes. r=mccr8

This is based on the same rules as for the majority of the rest of mozilla-central.

MozReview-Commit-ID: 2O1jH8cNXIj

--HG--
extra : rebase_source : b6788a231f70521398ef8783bebce99384a344d9
This commit is contained in:
Mark Banner 2018-07-03 16:19:05 +01:00
parent f1b93a05ce
commit a0026662dd
53 changed files with 1856 additions and 1868 deletions

View file

@ -9,7 +9,7 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
// Bug 1228209 - plan to remove this eventually
function log(aMsg) {
//dump("-*- PresentationDataChannelSessionTransport.js : " + aMsg + "\n");
// dump("-*- PresentationDataChannelSessionTransport.js : " + aMsg + "\n");
}
const PRESENTATIONTRANSPORT_CID = Components.ID("{dd2bbf2f-3399-4389-8f5f-d382afb8b2d6}");
@ -50,7 +50,7 @@ PresentationTransportBuilder.prototype = {
Ci.nsIPresentationDataChannelSessionTransportBuilder,
Ci.nsITimerCallback]),
buildDataChannelTransport: function(aRole, aWindow, aListener) {
buildDataChannelTransport(aRole, aWindow, aListener) {
if (!aRole || !aWindow || !aListener) {
log("buildDataChannelTransport with illegal parameters");
throw Cr.NS_ERROR_ILLEGAL_VALUE;
@ -85,7 +85,7 @@ PresentationTransportBuilder.prototype = {
.then(() => this._listener
.sendOffer(new PresentationDataChannelDescription(this._peerConnection.localDescription)))
.catch(e => this._reportError(e));
}
};
switch (this._role) {
case Ci.nsIPresentationService.ROLE_CONTROLLER:
@ -99,7 +99,7 @@ PresentationTransportBuilder.prototype = {
// Ensure the binaryType of dataChannel is blob.
this._dataChannel.binaryType = "blob";
this._setDataChannel();
}
};
break;
default:
throw Cr.NS_ERROR_ILLEGAL_VALUE;
@ -114,18 +114,18 @@ PresentationTransportBuilder.prototype = {
this._timer.initWithCallback(this, timeout, this._timer.TYPE_ONE_SHOT);
},
notify: function() {
notify() {
if (!this._sessionTransport) {
this._cleanup(Cr.NS_ERROR_NET_TIMEOUT);
}
},
_reportError: function(aError) {
_reportError(aError) {
log("report Error " + aError.name + ":" + aError.message);
this._cleanup(Cr.NS_ERROR_FAILURE);
},
_setDataChannel: function() {
_setDataChannel() {
this._dataChannel.onopen = () => {
log("data channel is open, notify the listener, role " + this._role);
@ -146,10 +146,10 @@ PresentationTransportBuilder.prototype = {
this._dataChannel.onerror = aError => {
log("data channel onerror " + aError.name + ":" + aError.message);
this._cleanup(Cr.NS_ERROR_FAILURE);
}
};
},
_cleanup: function(aReason) {
_cleanup(aReason) {
if (aReason != Cr.NS_OK) {
this._listener.onError(aReason);
}
@ -177,7 +177,7 @@ PresentationTransportBuilder.prototype = {
},
// nsIPresentationControlChannelListener
onOffer: function(aOffer) {
onOffer(aOffer) {
if (this._role !== Ci.nsIPresentationService.ROLE_RECEIVER ||
this._sessionTransport) {
log("onOffer status error");
@ -196,11 +196,11 @@ PresentationTransportBuilder.prototype = {
.then(() => {
this._isControlChannelNeeded = false;
this._listener
.sendAnswer(new PresentationDataChannelDescription(this._peerConnection.localDescription))
.sendAnswer(new PresentationDataChannelDescription(this._peerConnection.localDescription));
}).catch(e => this._reportError(e));
},
onAnswer: function(aAnswer) {
onAnswer(aAnswer) {
if (this._role !== Ci.nsIPresentationService.ROLE_CONTROLLER ||
this._sessionTransport) {
log("onAnswer status error");
@ -216,7 +216,7 @@ PresentationTransportBuilder.prototype = {
this._isControlChannelNeeded = false;
},
onIceCandidate: function(aCandidate) {
onIceCandidate(aCandidate) {
log("onIceCandidate: " + aCandidate + " with role " + this._role);
if (!this._window || !this._peerConnection) {
log("ignoring ICE candidate after connection");
@ -226,7 +226,7 @@ PresentationTransportBuilder.prototype = {
this._peerConnection.addIceCandidate(candidate).catch(e => this._reportError(e));
},
notifyDisconnected: function(aReason) {
notifyDisconnected(aReason) {
log("notifyDisconnected reason: " + aReason);
if (aReason != Cr.NS_OK) {
@ -247,7 +247,7 @@ PresentationTransport.prototype = {
contractID: PRESENTATIONTRANSPORT_CONTRACTID,
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationSessionTransport]),
init: function(aPeerConnection, aDataChannel, aWindow) {
init(aPeerConnection, aDataChannel, aWindow) {
log("initWithDataChannel");
this._enableDataNotification = false;
this._dataChannel = aDataChannel;
@ -264,7 +264,7 @@ PresentationTransport.prototype = {
this._callback.notifyTransportClosed(this._closeReason);
}
this._cleanup();
}
};
this._dataChannel.onmessage = aEvent => {
log("data channel onmessage " + aEvent.data);
@ -283,7 +283,7 @@ PresentationTransport.prototype = {
this._callback.notifyTransportClosed(Cr.NS_ERROR_FAILURE);
}
this._cleanup();
}
};
},
// nsIPresentationTransport
@ -299,12 +299,12 @@ PresentationTransport.prototype = {
this._callback = aCallback;
},
send: function(aData) {
send(aData) {
log("send " + aData);
this._dataChannel.send(aData);
},
sendBinaryMsg: function(aData) {
sendBinaryMsg(aData) {
log("sendBinaryMsg");
let array = new Uint8Array(aData.length);
@ -315,13 +315,13 @@ PresentationTransport.prototype = {
this._dataChannel.send(array);
},
sendBlob: function(aBlob) {
sendBlob(aBlob) {
log("sendBlob");
this._dataChannel.send(aBlob);
},
enableDataNotification: function() {
enableDataNotification() {
log("enableDataNotification");
if (this._enableDataNotification) {
return;
@ -337,13 +337,13 @@ PresentationTransport.prototype = {
this._messageQueue = [];
},
close: function(aReason) {
close(aReason) {
this._closeReason = aReason;
this._dataChannel.close();
},
_cleanup: function() {
_cleanup() {
this._dataChannel = null;
if (this._peerConnection) {
@ -355,7 +355,7 @@ PresentationTransport.prototype = {
this._window = null;
},
_doNotifyData: function(aData) {
_doNotifyData(aData) {
if (!this._callback) {
throw Cr.NS_ERROR_NOT_AVAILABLE;
}

View file

@ -16,7 +16,7 @@ PresentationNetworkHelper.prototype = {
classID: NETWORKHELPER_CID,
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationNetworkHelper]),
getWifiIPAddress: function(aListener) {
getWifiIPAddress(aListener) {
EventDispatcher.instance.sendRequestForResult({type: "Wifi:GetIPAddress"})
.then(result => aListener.onGetWifiIPAddress(result),
err => aListener.onError(err));

View file

@ -22,7 +22,7 @@ function log(str) {
function descriptionToString(aDescription) {
let json = {};
json.type = aDescription.type;
switch(aDescription.type) {
switch (aDescription.type) {
case Ci.nsIPresentationChannelDescription.TYPE_TCP:
let addresses = aDescription.tcpAddress.QueryInterface(Ci.nsIArray);
json.tcpAddress = [];

View file

@ -96,8 +96,8 @@ ControllerStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.LAUNCH,
presentationId: presentationId,
url: url,
presentationId,
url,
});
}
},
@ -106,7 +106,7 @@ ControllerStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.TERMINATE,
presentationId: presentationId,
presentationId,
});
}
},
@ -115,7 +115,7 @@ ControllerStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.TERMINATE_ACK,
presentationId: presentationId,
presentationId,
});
}
},
@ -124,8 +124,8 @@ ControllerStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.RECONNECT,
presentationId: presentationId,
url: url,
presentationId,
url,
});
}
},
@ -134,7 +134,7 @@ ControllerStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.OFFER,
offer: offer,
offer,
});
}
},
@ -148,7 +148,7 @@ ControllerStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.ICE_CANDIDATE,
candidate: candidate,
candidate,
});
}
},
@ -176,7 +176,7 @@ ControllerStateMachine.prototype = {
} else {
this._sendCommand({
type: CommandType.DISCONNECT,
reason: reason
reason
});
this.state = State.CLOSING;
this._closeReason = reason;
@ -203,7 +203,7 @@ ControllerStateMachine.prototype = {
},
_notifyDeviceConnected: function _notifyDeviceConnected() {
//XXX trigger following command
// XXX trigger following command
this._channel.notifyDeviceConnected();
},

View file

@ -50,9 +50,9 @@ PresentationControlService.prototype = {
*/
_controlChannels: [],
startServer: function(aEncrypted, aPort) {
startServer(aEncrypted, aPort) {
if (this._isServiceInit()) {
DEBUG && log("PresentationControlService - server socket has been initialized"); // jshint ignore:line
DEBUG && log("PresentationControlService - server socket has been initialized"); // jshint ignore:line
throw Cr.NS_ERROR_FAILURE;
}
@ -67,8 +67,8 @@ PresentationControlService.prototype = {
let localCertService = Cc["@mozilla.org/security/local-cert-service;1"]
.getService(Ci.nsILocalCertService);
localCertService.getOrCreateCert(kLocalCertName, {
handleCert: function(aCert, aRv) {
DEBUG && log("PresentationControlService - handleCert"); // jshint ignore:line
handleCert(aCert, aRv) {
DEBUG && log("PresentationControlService - handleCert"); // jshint ignore:line
if (aRv) {
self._notifyServerStopped(aRv);
} else {
@ -87,7 +87,7 @@ PresentationControlService.prototype = {
}
},
_serverSocketInit: function(aPort, aCert) {
_serverSocketInit(aPort, aCert) {
if (!this._serverSocket) {
DEBUG && log("PresentationControlService - create server socket fail."); // jshint ignore:line
throw Cr.NS_ERROR_FAILURE;
@ -121,7 +121,7 @@ PresentationControlService.prototype = {
this._notifyServerReady();
},
_notifyServerReady: function() {
_notifyServerReady() {
Services.tm.dispatchToMainThread(() => {
if (this._listener) {
this._listener.onServerReady(this._port, this.certFingerprint);
@ -129,7 +129,7 @@ PresentationControlService.prototype = {
});
},
_notifyServerStopped: function(aRv) {
_notifyServerStopped(aRv) {
Services.tm.dispatchToMainThread(() => {
if (this._listener) {
this._listener.onServerStopped(aRv);
@ -137,7 +137,7 @@ PresentationControlService.prototype = {
});
},
isCompatibleServer: function(aVersion) {
isCompatibleServer(aVersion) {
// No compatibility issue for the first version of control protocol
return this.version === aVersion;
},
@ -174,11 +174,11 @@ PresentationControlService.prototype = {
return this._listener;
},
_isServiceInit: function() {
_isServiceInit() {
return this._serverSocket !== null;
},
connect: function(aDeviceInfo) {
connect(aDeviceInfo) {
if (!this.id) {
DEBUG && log("PresentationControlService - Id has not initialized; connect fails"); // jshint ignore:line
return null;
@ -192,7 +192,7 @@ PresentationControlService.prototype = {
"sender");
},
_attemptConnect: function(aDeviceInfo) {
_attemptConnect(aDeviceInfo) {
let sts = Cc["@mozilla.org/network/socket-transport-service;1"]
.getService(Ci.nsISocketTransportService);
@ -222,14 +222,14 @@ PresentationControlService.prototype = {
// Shorten the connection failure procedure.
socketTransport.setTimeout(Ci.nsISocketTransport.TIMEOUT_CONNECT, 2);
} catch (e) {
DEBUG && log("PresentationControlService - createTransport throws: " + e); // jshint ignore:line
DEBUG && log("PresentationControlService - createTransport throws: " + e); // jshint ignore:line
// Pop the exception to |TCPDevice.establishControlChannel|
throw Cr.NS_ERROR_FAILURE;
}
return socketTransport;
},
responseSession: function(aDeviceInfo, aSocketTransport) {
responseSession(aDeviceInfo, aSocketTransport) {
if (!this._isServiceInit()) {
DEBUG && log("PresentationControlService - should never receive remote " +
"session request before server socket initialization"); // jshint ignore:line
@ -244,7 +244,7 @@ PresentationControlService.prototype = {
},
// Triggered by TCPControlChannel
onSessionRequest: function(aDeviceInfo, aUrl, aPresentationId, aControlChannel) {
onSessionRequest(aDeviceInfo, aUrl, aPresentationId, aControlChannel) {
DEBUG && log("PresentationControlService - onSessionRequest: " +
aDeviceInfo.address + ":" + aDeviceInfo.port); // jshint ignore:line
if (!this.listener) {
@ -259,7 +259,7 @@ PresentationControlService.prototype = {
this.releaseControlChannel(aControlChannel);
},
onSessionTerminate: function(aDeviceInfo, aPresentationId, aControlChannel, aIsFromReceiver) {
onSessionTerminate(aDeviceInfo, aPresentationId, aControlChannel, aIsFromReceiver) {
DEBUG && log("TCPPresentationServer - onSessionTerminate: " +
aDeviceInfo.address + ":" + aDeviceInfo.port); // jshint ignore:line
if (!this.listener) {
@ -274,7 +274,7 @@ PresentationControlService.prototype = {
this.releaseControlChannel(aControlChannel);
},
onSessionReconnect: function(aDeviceInfo, aUrl, aPresentationId, aControlChannel) {
onSessionReconnect(aDeviceInfo, aUrl, aPresentationId, aControlChannel) {
DEBUG && log("TCPPresentationServer - onSessionReconnect: " +
aDeviceInfo.address + ":" + aDeviceInfo.port); // jshint ignore:line
if (!this.listener) {
@ -290,18 +290,18 @@ PresentationControlService.prototype = {
},
// nsIServerSocketListener (Triggered by nsIServerSocket.init)
onSocketAccepted: function(aServerSocket, aClientSocket) {
onSocketAccepted(aServerSocket, aClientSocket) {
DEBUG && log("PresentationControlService - onSocketAccepted: " +
aClientSocket.host + ":" + aClientSocket.port); // jshint ignore:line
let deviceInfo = new TCPDeviceInfo(aClientSocket.host, aClientSocket.port);
this.holdControlChannel(this.responseSession(deviceInfo, aClientSocket));
},
holdControlChannel: function(aControlChannel) {
holdControlChannel(aControlChannel) {
this._controlChannels.push(aControlChannel);
},
releaseControlChannel: function(aControlChannel) {
releaseControlChannel(aControlChannel) {
let index = this._controlChannels.indexOf(aControlChannel);
if (index !== -1) {
delete this._controlChannels[index];
@ -309,11 +309,11 @@ PresentationControlService.prototype = {
},
// nsIServerSocketListener (Triggered by nsIServerSocket.init)
onStopListening: function(aServerSocket, aStatus) {
onStopListening(aServerSocket, aStatus) {
DEBUG && log("PresentationControlService - onStopListening: " + aStatus); // jshint ignore:line
},
close: function() {
close() {
DEBUG && log("PresentationControlService - close"); // jshint ignore:line
if (this._isServiceInit()) {
DEBUG && log("PresentationControlService - close server socket"); // jshint ignore:line
@ -328,7 +328,7 @@ PresentationControlService.prototype = {
},
// nsIObserver
observe: function(aSubject, aTopic, aData) {
observe(aSubject, aTopic, aData) {
DEBUG && log("PresentationControlService - observe: " + aTopic); // jshint ignore:line
switch (aTopic) {
case "network:offline-status-changed": {
@ -342,7 +342,7 @@ PresentationControlService.prototype = {
}
},
_restartServer: function() {
_restartServer() {
DEBUG && log("PresentationControlService - restart service"); // jshint ignore:line
// restart server socket
@ -358,9 +358,9 @@ PresentationControlService.prototype = {
},
classID: Components.ID("{f4079b8b-ede5-4b90-a112-5b415a931deb}"),
QueryInterface : ChromeUtils.generateQI([Ci.nsIServerSocketListener,
Ci.nsIPresentationControlService,
Ci.nsIObserver]),
QueryInterface: ChromeUtils.generateQI([Ci.nsIServerSocketListener,
Ci.nsIPresentationControlService,
Ci.nsIObserver]),
};
function ChannelDescription(aInit) {
@ -414,7 +414,7 @@ ChannelDescription.prototype = {
function discriptionAsJson(aDescription) {
let json = {};
json.type = aDescription.type;
switch(aDescription.type) {
switch (aDescription.type) {
case Ci.nsIPresentationChannelDescription.TYPE_TCP:
let addresses = aDescription.tcpAddress.QueryInterface(Ci.nsIArray);
json.tcpAddress = [];
@ -488,23 +488,23 @@ TCPControlChannel.prototype = {
_pendingCloseReason: null,
_pendingReconnect: false,
sendOffer: function(aOffer) {
sendOffer(aOffer) {
this._stateMachine.sendOffer(discriptionAsJson(aOffer));
},
sendAnswer: function(aAnswer) {
sendAnswer(aAnswer) {
this._stateMachine.sendAnswer(discriptionAsJson(aAnswer));
},
sendIceCandidate: function(aCandidate) {
sendIceCandidate(aCandidate) {
this._stateMachine.updateIceCandidate(aCandidate);
},
launch: function(aPresentationId, aUrl) {
launch(aPresentationId, aUrl) {
this._stateMachine.launch(aPresentationId, aUrl);
},
terminate: function(aPresentationId) {
terminate(aPresentationId) {
if (!this._terminatingId) {
this._terminatingId = aPresentationId;
this._stateMachine.terminate(aPresentationId);
@ -525,7 +525,7 @@ TCPControlChannel.prototype = {
}
},
_flushOutgoing: function() {
_flushOutgoing() {
if (!this._outgoingEnabled || this._outgoingMsgs.length === 0) {
return;
}
@ -534,7 +534,7 @@ TCPControlChannel.prototype = {
},
// may throw an exception
_send: function(aMsg) {
_send(aMsg) {
DEBUG && log("TCPControlChannel - Send: " + JSON.stringify(aMsg, null, 2)); // jshint ignore:line
/**
@ -547,13 +547,13 @@ TCPControlChannel.prototype = {
let message = JSON.stringify(aMsg).replace(["\n"], "") + "\n";
try {
this._output.write(message, message.length);
} catch(e) {
} catch (e) {
DEBUG && log("TCPControlChannel - Failed to send message: " + e.name); // jshint ignore:line
throw e;
}
},
_setSecurityObserver: function(observer) {
_setSecurityObserver(observer) {
if (this._transport && this._transport.securityInfo) {
DEBUG && log("TCPControlChannel - setSecurityObserver: " + observer); // jshint ignore:line
let connectionInfo = this._transport.securityInfo
@ -563,7 +563,7 @@ TCPControlChannel.prototype = {
},
// nsITLSServerSecurityObserver
onHandshakeDone: function(socket, clientStatus) {
onHandshakeDone(socket, clientStatus) {
log("TCPControlChannel - onHandshakeDone: TLS version: " + clientStatus.tlsVersionUsed.toString(16));
this._setSecurityObserver(null);
@ -573,7 +573,7 @@ TCPControlChannel.prototype = {
},
// nsIAsyncOutputStream
onOutputStreamReady: function() {
onOutputStreamReady() {
DEBUG && log("TCPControlChannel - onOutputStreamReady"); // jshint ignore:line
if (this._outgoingMsgs.length === 0) {
return;
@ -596,7 +596,7 @@ TCPControlChannel.prototype = {
// nsIAsyncInputStream (Triggered by nsIInputStream.asyncWait)
// Only used for detecting connection refused
onInputStreamReady: function(aStream) {
onInputStreamReady(aStream) {
DEBUG && log("TCPControlChannel - onInputStreamReady"); // jshint ignore:line
try {
aStream.available();
@ -608,7 +608,7 @@ TCPControlChannel.prototype = {
},
// nsITransportEventSink (Triggered by nsISocketTransport.setEventSink)
onTransportStatus: function(aTransport, aStatus) {
onTransportStatus(aTransport, aStatus) {
DEBUG && log("TCPControlChannel - onTransportStatus: " + aStatus.toString(16) +
" with role: " + this._direction); // jshint ignore:line
if (aStatus === Ci.nsISocketTransport.STATUS_CONNECTED_TO) {
@ -618,21 +618,21 @@ TCPControlChannel.prototype = {
},
// nsIRequestObserver (Triggered by nsIInputStreamPump.asyncRead)
onStartRequest: function() {
onStartRequest() {
DEBUG && log("TCPControlChannel - onStartRequest with role: " +
this._direction); // jshint ignore:line
this._incomingEnabled = true;
},
// nsIRequestObserver (Triggered by nsIInputStreamPump.asyncRead)
onStopRequest: function(aRequest, aContext, aStatus) {
onStopRequest(aRequest, aContext, aStatus) {
DEBUG && log("TCPControlChannel - onStopRequest: " + aStatus +
" with role: " + this._direction); // jshint ignore:line
this._stateMachine.onChannelClosed(aStatus, true);
},
// nsIStreamListener (Triggered by nsIInputStreamPump.asyncRead)
onDataAvailable: function(aRequest, aContext, aInputStream) {
onDataAvailable(aRequest, aContext, aInputStream) {
let data = NetUtil.readInputStreamToString(aInputStream,
aInputStream.available());
DEBUG && log("TCPControlChannel - onDataAvailable: " + data); // jshint ignore:line
@ -652,7 +652,7 @@ TCPControlChannel.prototype = {
}
},
_createInputStreamPump: function() {
_createInputStreamPump() {
if (this._pump) {
return;
}
@ -667,7 +667,7 @@ TCPControlChannel.prototype = {
},
// Handle command from remote side
_handleMessage: function(aMsg) {
_handleMessage(aMsg) {
DEBUG && log("TCPControlChannel - handleMessage from " +
JSON.stringify(this._deviceInfo) + ": " + JSON.stringify(aMsg)); // jshint ignore:line
this._stateMachine.onCommand(aMsg);
@ -724,7 +724,7 @@ TCPControlChannel.prototype = {
* These functions are designed to handle the interaction with listener
* appropriately. |_FUNC| is to handle |this._listener.FUNC|.
*/
_onOffer: function(aOffer) {
_onOffer(aOffer) {
if (!this._incomingEnabled) {
return;
}
@ -737,7 +737,7 @@ TCPControlChannel.prototype = {
this._listener.onOffer(new ChannelDescription(aOffer));
},
_onAnswer: function(aAnswer) {
_onAnswer(aAnswer) {
if (!this._incomingEnabled) {
return;
}
@ -750,7 +750,7 @@ TCPControlChannel.prototype = {
this._listener.onAnswer(new ChannelDescription(aAnswer));
},
_notifyConnected: function() {
_notifyConnected() {
this._pendingClose = false;
this._pendingCloseReason = Cr.NS_OK;
@ -764,7 +764,7 @@ TCPControlChannel.prototype = {
this._listener.notifyConnected();
},
_notifyDisconnected: function(aReason) {
_notifyDisconnected(aReason) {
this._pendingOpen = false;
this._pendingOffer = null;
this._pendingAnswer = null;
@ -785,7 +785,7 @@ TCPControlChannel.prototype = {
this._listener.notifyDisconnected(aReason);
},
_notifyReconnected: function() {
_notifyReconnected() {
if (!this._listener) {
this._pendingReconnect = true;
return;
@ -796,20 +796,20 @@ TCPControlChannel.prototype = {
this._listener.notifyReconnected();
},
_closeOutgoing: function() {
_closeOutgoing() {
if (this._outgoingEnabled) {
this._output.close();
this._outgoingEnabled = false;
}
},
_closeIncoming: function() {
_closeIncoming() {
if (this._incomingEnabled) {
this._pump = null;
this._input.close();
this._incomingEnabled = false;
}
},
_closeTransport: function() {
_closeTransport() {
if (this._disconnectTimer) {
clearTimeout(this._disconnectTimer);
delete this._disconnectTimer;
@ -829,7 +829,7 @@ TCPControlChannel.prototype = {
this._presentationService.releaseControlChannel(this);
},
disconnect: function(aReason) {
disconnect(aReason) {
DEBUG && log("TCPControlChannel - disconnect with reason: " + aReason); // jshint ignore:line
// Pending disconnect during termination procedure.
@ -855,7 +855,7 @@ TCPControlChannel.prototype = {
}
},
reconnect: function(aPresentationId, aUrl) {
reconnect(aPresentationId, aUrl) {
DEBUG && log("TCPControlChannel - reconnect with role: " +
this._direction); // jshint ignore:line
if (this._direction != "sender") {
@ -866,12 +866,12 @@ TCPControlChannel.prototype = {
},
// callback from state machine
sendCommand: function(command) {
sendCommand(command) {
this._outgoingMsgs.push(command);
this._flushOutgoing();
},
notifyDeviceConnected: function(deviceId) {
notifyDeviceConnected(deviceId) {
switch (this._direction) {
case "receiver":
this._deviceInfo.id = deviceId;
@ -880,12 +880,12 @@ TCPControlChannel.prototype = {
this._notifyConnected();
},
notifyDisconnected: function(reason) {
notifyDisconnected(reason) {
this._closeTransport();
this._notifyDisconnected(reason);
},
notifyLaunch: function(presentationId, url) {
notifyLaunch(presentationId, url) {
switch (this._direction) {
case "receiver":
this._presentationService.onSessionRequest(this._deviceInfo,
@ -896,7 +896,7 @@ TCPControlChannel.prototype = {
}
},
notifyTerminate: function(presentationId) {
notifyTerminate(presentationId) {
if (!this._terminatingId) {
this._terminatingId = presentationId;
this._presentationService.onSessionTerminate(this._deviceInfo,
@ -925,7 +925,7 @@ TCPControlChannel.prototype = {
}
},
notifyReconnect: function(presentationId, url) {
notifyReconnect(presentationId, url) {
switch (this._direction) {
case "receiver":
this._presentationService.onSessionReconnect(this._deviceInfo,
@ -939,15 +939,15 @@ TCPControlChannel.prototype = {
}
},
notifyOffer: function(offer) {
notifyOffer(offer) {
this._onOffer(offer);
},
notifyAnswer: function(answer) {
notifyAnswer(answer) {
this._onAnswer(answer);
},
notifyIceCandidate: function(candidate) {
notifyIceCandidate(candidate) {
this._listener.onIceCandidate(candidate);
},

View file

@ -113,7 +113,7 @@ ReceiverStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.TERMINATE,
presentationId: presentationId,
presentationId,
});
}
},
@ -122,7 +122,7 @@ ReceiverStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.TERMINATE_ACK,
presentationId: presentationId,
presentationId,
});
}
},
@ -140,7 +140,7 @@ ReceiverStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.ANSWER,
answer: answer,
answer,
});
}
},
@ -149,7 +149,7 @@ ReceiverStateMachine.prototype = {
if (this.state === State.CONNECTED) {
this._sendCommand({
type: CommandType.ICE_CANDIDATE,
candidate: candidate,
candidate,
});
}
},
@ -173,7 +173,7 @@ ReceiverStateMachine.prototype = {
} else {
this._sendCommand({
type: CommandType.DISCONNECT,
reason: reason
reason
});
this.state = State.CLOSING;
this._closeReason = reason;

View file

@ -1,28 +1,28 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
"use strict";
const { XPCOMUtils } = ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm');
const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const manager = Cc['@mozilla.org/presentation-device/manager;1']
const manager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
var testProvider = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceProvider]),
forceDiscovery: function() {
sendAsyncMessage('force-discovery');
forceDiscovery() {
sendAsyncMessage("force-discovery");
},
listener: null,
};
var testDevice = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevice]),
establishControlChannel: function() {
establishControlChannel() {
return null;
},
disconnect: function() {},
isRequestedUrlSupported: function(requestedUrl) {
disconnect() {},
isRequestedUrlSupported(requestedUrl) {
return true;
},
id: null,
@ -33,56 +33,56 @@ var testDevice = {
var testDevice1 = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevice]),
id: 'dummyid',
name: 'dummyName',
type: 'dummyType',
establishControlChannel: function(url, presentationId) {
id: "dummyid",
name: "dummyName",
type: "dummyType",
establishControlChannel(url, presentationId) {
return null;
},
disconnect: function() {},
isRequestedUrlSupported: function(requestedUrl) {
disconnect() {},
isRequestedUrlSupported(requestedUrl) {
return true;
},
};
var testDevice2 = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevice]),
id: 'dummyid',
name: 'dummyName',
type: 'dummyType',
establishControlChannel: function(url, presentationId) {
id: "dummyid",
name: "dummyName",
type: "dummyType",
establishControlChannel(url, presentationId) {
return null;
},
disconnect: function() {},
isRequestedUrlSupported: function(requestedUrl) {
disconnect() {},
isRequestedUrlSupported(requestedUrl) {
return true;
},
};
var mockedDeviceWithoutSupportedURL = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevice]),
id: 'dummyid',
name: 'dummyName',
type: 'dummyType',
establishControlChannel: function(url, presentationId) {
id: "dummyid",
name: "dummyName",
type: "dummyType",
establishControlChannel(url, presentationId) {
return null;
},
disconnect: function() {},
isRequestedUrlSupported: function(requestedUrl) {
disconnect() {},
isRequestedUrlSupported(requestedUrl) {
return false;
},
};
var mockedDeviceSupportHttpsURL = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevice]),
id: 'dummyid',
name: 'dummyName',
type: 'dummyType',
establishControlChannel: function(url, presentationId) {
id: "dummyid",
name: "dummyName",
type: "dummyType",
establishControlChannel(url, presentationId) {
return null;
},
disconnect: function() {},
isRequestedUrlSupported: function(requestedUrl) {
disconnect() {},
isRequestedUrlSupported(requestedUrl) {
if (requestedUrl.includes("https://")) {
return true;
}
@ -90,57 +90,57 @@ var mockedDeviceSupportHttpsURL = {
},
};
addMessageListener('setup', function() {
addMessageListener("setup", function() {
manager.addDeviceProvider(testProvider);
sendAsyncMessage('setup-complete');
sendAsyncMessage("setup-complete");
});
addMessageListener('trigger-device-add', function(device) {
addMessageListener("trigger-device-add", function(device) {
testDevice.id = device.id;
testDevice.name = device.name;
testDevice.type = device.type;
manager.addDevice(testDevice);
});
addMessageListener('trigger-add-unsupport-url-device', function() {
addMessageListener("trigger-add-unsupport-url-device", function() {
manager.addDevice(mockedDeviceWithoutSupportedURL);
});
addMessageListener('trigger-add-multiple-devices', function() {
addMessageListener("trigger-add-multiple-devices", function() {
manager.addDevice(testDevice1);
manager.addDevice(testDevice2);
});
addMessageListener('trigger-add-https-devices', function() {
addMessageListener("trigger-add-https-devices", function() {
manager.addDevice(mockedDeviceSupportHttpsURL);
});
addMessageListener('trigger-device-update', function(device) {
addMessageListener("trigger-device-update", function(device) {
testDevice.id = device.id;
testDevice.name = device.name;
testDevice.type = device.type;
manager.updateDevice(testDevice);
});
addMessageListener('trigger-device-remove', function() {
addMessageListener("trigger-device-remove", function() {
manager.removeDevice(testDevice);
});
addMessageListener('trigger-remove-unsupported-device', function() {
addMessageListener("trigger-remove-unsupported-device", function() {
manager.removeDevice(mockedDeviceWithoutSupportedURL);
});
addMessageListener('trigger-remove-multiple-devices', function() {
addMessageListener("trigger-remove-multiple-devices", function() {
manager.removeDevice(testDevice1);
manager.removeDevice(testDevice2);
});
addMessageListener('trigger-remove-https-devices', function() {
addMessageListener("trigger-remove-https-devices", function() {
manager.removeDevice(mockedDeviceSupportHttpsURL);
});
addMessageListener('teardown', function() {
addMessageListener("teardown", function() {
manager.removeDeviceProvider(testProvider);
});

View file

@ -1,13 +1,13 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
"use strict";
const Cm = Components.manager;
ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm');
ChromeUtils.import('resource://gre/modules/Services.jsm');
ChromeUtils.import('resource://gre/modules/Timer.jsm');
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/Timer.jsm");
const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator);
@ -30,11 +30,11 @@ function registerMockedFactory(contractId, mockedClassId, mockedFactory) {
registrar.registerFactory(mockedClassId, "", contractId, mockedFactory);
}
return { contractId: contractId,
mockedClassId: mockedClassId,
mockedFactory: mockedFactory,
originalClassId: originalClassId,
originalFactory: originalFactory };
return { contractId,
mockedClassId,
mockedFactory,
originalClassId,
originalFactory };
}
function registerOriginalFactory(contractId, mockedClassId, mockedFactory, originalClassId, originalFactory) {
@ -45,7 +45,7 @@ function registerOriginalFactory(contractId, mockedClassId, mockedFactory, origi
}
}
var sessionId = 'test-session-id-' + uuidGenerator.generateUUID().toString();
var sessionId = "test-session-id-" + uuidGenerator.generateUUID().toString();
const address = Cc["@mozilla.org/supports-cstring;1"]
.createInstance(Ci.nsISupportsCString);
@ -68,7 +68,7 @@ const mockedChannelDescription = {
const mockedServerSocket = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIServerSocket,
Ci.nsIFactory]),
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
@ -80,20 +80,20 @@ const mockedServerSocket = {
set listener(listener) {
this._listener = listener;
},
init: function(port, loopbackOnly, backLog) {
init(port, loopbackOnly, backLog) {
if (port != -1) {
this._port = port;
} else {
this._port = 5678;
}
},
asyncListen: function(listener) {
asyncListen(listener) {
this._listener = listener;
},
close: function() {
close() {
this._listener.onStopListening(this, Cr.NS_BINDING_ABORTED);
},
simulateOnSocketAccepted: function(serverSocket, socketTransport) {
simulateOnSocketAccepted(serverSocket, socketTransport) {
this._listener.onSocketAccepted(serverSocket, socketTransport);
}
};
@ -110,17 +110,17 @@ const mockedControlChannel = {
get listener() {
return this._listener;
},
sendOffer: function(offer) {
sendAsyncMessage('offer-sent', this._isValidSDP(offer));
sendOffer(offer) {
sendAsyncMessage("offer-sent", this._isValidSDP(offer));
},
sendAnswer: function(answer) {
sendAsyncMessage('answer-sent', this._isValidSDP(answer));
sendAnswer(answer) {
sendAsyncMessage("answer-sent", this._isValidSDP(answer));
if (answer.type == Ci.nsIPresentationChannelDescription.TYPE_TCP) {
this._listener.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportReady();
}
},
_isValidSDP: function(aSDP) {
_isValidSDP(aSDP) {
var isValid = false;
if (aSDP.type == Ci.nsIPresentationChannelDescription.TYPE_TCP) {
try {
@ -141,52 +141,52 @@ const mockedControlChannel = {
}
return isValid;
},
launch: function(presentationId, url) {
launch(presentationId, url) {
sessionId = presentationId;
},
terminate: function(presentationId) {
sendAsyncMessage('sender-terminate', presentationId);
terminate(presentationId) {
sendAsyncMessage("sender-terminate", presentationId);
},
reconnect: function(presentationId, url) {
sendAsyncMessage('start-reconnect', url);
reconnect(presentationId, url) {
sendAsyncMessage("start-reconnect", url);
},
notifyReconnected: function() {
notifyReconnected() {
this._listener
.QueryInterface(Ci.nsIPresentationControlChannelListener)
.notifyReconnected();
},
disconnect: function(reason) {
sendAsyncMessage('control-channel-closed', reason);
disconnect(reason) {
sendAsyncMessage("control-channel-closed", reason);
this._listener.QueryInterface(Ci.nsIPresentationControlChannelListener).notifyDisconnected(reason);
},
simulateReceiverReady: function() {
simulateReceiverReady() {
this._listener.QueryInterface(Ci.nsIPresentationControlChannelListener).notifyReceiverReady();
},
simulateOnOffer: function() {
sendAsyncMessage('offer-received');
simulateOnOffer() {
sendAsyncMessage("offer-received");
this._listener.QueryInterface(Ci.nsIPresentationControlChannelListener).onOffer(mockedChannelDescription);
},
simulateOnAnswer: function() {
sendAsyncMessage('answer-received');
simulateOnAnswer() {
sendAsyncMessage("answer-received");
this._listener.QueryInterface(Ci.nsIPresentationControlChannelListener).onAnswer(mockedChannelDescription);
},
simulateNotifyConnected: function() {
sendAsyncMessage('control-channel-opened');
simulateNotifyConnected() {
sendAsyncMessage("control-channel-opened");
this._listener.QueryInterface(Ci.nsIPresentationControlChannelListener).notifyConnected();
},
};
const mockedDevice = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevice]),
id: 'id',
name: 'name',
type: 'type',
establishControlChannel: function(url, presentationId) {
sendAsyncMessage('control-channel-established');
id: "id",
name: "name",
type: "type",
establishControlChannel(url, presentationId) {
sendAsyncMessage("control-channel-established");
return mockedControlChannel;
},
disconnect: function() {},
isRequestedUrlSupported: function(requestedUrl) {
disconnect() {},
isRequestedUrlSupported(requestedUrl) {
return true;
},
};
@ -194,7 +194,7 @@ const mockedDevice = {
const mockedDevicePrompt = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevicePrompt,
Ci.nsIFactory]),
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
@ -206,14 +206,14 @@ const mockedDevicePrompt = {
get request() {
return this._request;
},
promptDeviceSelection: function(request) {
promptDeviceSelection(request) {
this._request = request;
sendAsyncMessage('device-prompt');
sendAsyncMessage("device-prompt");
},
simulateSelect: function() {
simulateSelect() {
this._request.select(mockedDevice);
},
simulateCancel: function(result) {
simulateCancel(result) {
this._request.cancel(result);
}
};
@ -225,7 +225,7 @@ const mockedSessionTransport = {
Ci.nsIPresentationDataChannelSessionTransportBuilder,
Ci.nsIPresentationControlChannelListener,
Ci.nsIFactory]),
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
@ -240,18 +240,18 @@ const mockedSessionTransport = {
get selfAddress() {
return this._selfAddress;
},
buildTCPSenderTransport: function(transport, listener) {
buildTCPSenderTransport(transport, listener) {
this._listener = listener;
this._role = Ci.nsIPresentationService.ROLE_CONTROLLER;
this._listener.onSessionTransport(this);
this._listener = null;
sendAsyncMessage('data-transport-initialized');
sendAsyncMessage("data-transport-initialized");
setTimeout(()=>{
setTimeout(() => {
this.simulateTransportReady();
}, 0);
},
buildTCPReceiverTransport: function(description, listener) {
buildTCPReceiverTransport(description, listener) {
this._listener = listener;
this._role = Ci.nsIPresentationService.ROLE_RECEIVER;
@ -263,53 +263,53 @@ const mockedSessionTransport = {
port: description.QueryInterface(Ci.nsIPresentationChannelDescription).tcpPort,
};
setTimeout(()=>{
setTimeout(() => {
this._listener.onSessionTransport(this);
this._listener = null;
}, 0);
},
// in-process case
buildDataChannelTransport: function(role, window, listener) {
buildDataChannelTransport(role, window, listener) {
this._listener = listener;
this._role = role;
var hasNavigator = window ? (typeof window.navigator != "undefined") : false;
sendAsyncMessage('check-navigator', hasNavigator);
sendAsyncMessage("check-navigator", hasNavigator);
setTimeout(()=>{
setTimeout(() => {
this._listener.onSessionTransport(this);
this._listener = null;
this.simulateTransportReady();
}, 0);
},
enableDataNotification: function() {
sendAsyncMessage('data-transport-notification-enabled');
enableDataNotification() {
sendAsyncMessage("data-transport-notification-enabled");
},
send: function(data) {
sendAsyncMessage('message-sent', data);
send(data) {
sendAsyncMessage("message-sent", data);
},
close: function(reason) {
close(reason) {
// Don't send a message after tearDown, to avoid a leak.
if (this._callback) {
sendAsyncMessage('data-transport-closed', reason);
sendAsyncMessage("data-transport-closed", reason);
this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportClosed(reason);
}
},
simulateTransportReady: function() {
simulateTransportReady() {
this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportReady();
},
simulateIncomingMessage: function(message) {
simulateIncomingMessage(message) {
this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyData(message, false);
},
onOffer: function(aOffer) {
onOffer(aOffer) {
},
onAnswer: function(aAnswer) {
onAnswer(aAnswer) {
}
};
const mockedNetworkInfo = {
QueryInterface: ChromeUtils.generateQI([Ci.nsINetworkInfo]),
getAddresses: function(ips, prefixLengths) {
getAddresses(ips, prefixLengths) {
ips.value = ["127.0.0.1"];
prefixLengths.value = [0];
return 1;
@ -319,7 +319,7 @@ const mockedNetworkInfo = {
const mockedNetworkManager = {
QueryInterface: ChromeUtils.generateQI([Ci.nsINetworkManager,
Ci.nsIFactory]),
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
@ -335,14 +335,14 @@ var requestPromise = null;
const mockedRequestUIGlue = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationRequestUIGlue,
Ci.nsIFactory]),
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
return this.QueryInterface(aIID);
},
sendRequest: function(aUrl, aSessionId) {
sendAsyncMessage('receiver-launching', aSessionId);
sendRequest(aUrl, aSessionId) {
sendAsyncMessage("receiver-launching", aSessionId);
return requestPromise;
},
};
@ -376,7 +376,7 @@ function tearDown() {
mockedDevicePrompt.request = null;
mockedSessionTransport.callback = null;
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener).removeDevice(mockedDevice);
@ -387,79 +387,79 @@ function tearDown() {
data.originalFactory);
}
sendAsyncMessage('teardown-complete');
sendAsyncMessage("teardown-complete");
}
addMessageListener('trigger-device-add', function() {
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
addMessageListener("trigger-device-add", function() {
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener).addDevice(mockedDevice);
});
addMessageListener('trigger-device-prompt-select', function() {
addMessageListener("trigger-device-prompt-select", function() {
mockedDevicePrompt.simulateSelect();
});
addMessageListener('trigger-device-prompt-cancel', function(result) {
addMessageListener("trigger-device-prompt-cancel", function(result) {
mockedDevicePrompt.simulateCancel(result);
});
addMessageListener('trigger-incoming-session-request', function(url) {
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
addMessageListener("trigger-incoming-session-request", function(url) {
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
.onSessionRequest(mockedDevice, url, sessionId, mockedControlChannel);
});
addMessageListener('trigger-incoming-terminate-request', function() {
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
addMessageListener("trigger-incoming-terminate-request", function() {
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
.onTerminateRequest(mockedDevice, sessionId, mockedControlChannel, true);
});
addMessageListener('trigger-reconnected-acked', function(url) {
addMessageListener("trigger-reconnected-acked", function(url) {
mockedControlChannel.notifyReconnected();
});
addMessageListener('trigger-incoming-offer', function() {
addMessageListener("trigger-incoming-offer", function() {
mockedControlChannel.simulateOnOffer();
});
addMessageListener('trigger-incoming-answer', function() {
addMessageListener("trigger-incoming-answer", function() {
mockedControlChannel.simulateOnAnswer();
});
addMessageListener('trigger-incoming-transport', function() {
addMessageListener("trigger-incoming-transport", function() {
mockedServerSocket.simulateOnSocketAccepted(mockedServerSocket, mockedSocketTransport);
});
addMessageListener('trigger-control-channel-open', function(reason) {
addMessageListener("trigger-control-channel-open", function(reason) {
mockedControlChannel.simulateNotifyConnected();
});
addMessageListener('trigger-control-channel-close', function(reason) {
addMessageListener("trigger-control-channel-close", function(reason) {
mockedControlChannel.disconnect(reason);
});
addMessageListener('trigger-data-transport-close', function(reason) {
addMessageListener("trigger-data-transport-close", function(reason) {
mockedSessionTransport.close(reason);
});
addMessageListener('trigger-incoming-message', function(message) {
addMessageListener("trigger-incoming-message", function(message) {
mockedSessionTransport.simulateIncomingMessage(message);
});
addMessageListener('teardown', function() {
addMessageListener("teardown", function() {
tearDown();
});
var controlChannelListener;
addMessageListener('save-control-channel-listener', function() {
addMessageListener("save-control-channel-listener", function() {
controlChannelListener = mockedControlChannel.listener;
});
addMessageListener('restore-control-channel-listener', function(message) {
addMessageListener("restore-control-channel-listener", function(message) {
mockedControlChannel.listener = controlChannelListener;
controlChannelListener = null;
});
@ -470,4 +470,4 @@ obs.addObserver(function observer(aSubject, aTopic, aData) {
obs.removeObserver(observer, aTopic);
requestPromise = aSubject;
}, 'setup-request-promise');
}, "setup-request-promise");

View file

@ -3,12 +3,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';
"use strict";
const Cm = Components.manager;
ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm');
ChromeUtils.import('resource://gre/modules/Services.jsm');
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator);
@ -27,42 +27,42 @@ const mockControlChannelOfSender = {
set listener(listener) {
// PresentationControllingInfo::SetControlChannel
if (listener) {
debug('set listener for mockControlChannelOfSender without null');
debug("set listener for mockControlChannelOfSender without null");
} else {
debug('set listener for mockControlChannelOfSender with null');
debug("set listener for mockControlChannelOfSender with null");
}
this._listener = listener;
},
get listener() {
return this._listener;
},
notifyConnected: function() {
notifyConnected() {
// send offer after notifyConnected immediately
this._listener
.QueryInterface(Ci.nsIPresentationControlChannelListener)
.notifyConnected();
},
notifyReconnected: function() {
notifyReconnected() {
// send offer after notifyOpened immediately
this._listener
.QueryInterface(Ci.nsIPresentationControlChannelListener)
.notifyReconnected();
},
sendOffer: function(offer) {
sendOffer(offer) {
Services.tm.dispatchToMainThread(() => {
mockControlChannelOfReceiver.onOffer(offer);
});
},
onAnswer: function(answer) {
onAnswer(answer) {
this._listener
.QueryInterface(Ci.nsIPresentationControlChannelListener)
.onAnswer(answer);
},
launch: function(presentationId, url) {
launch(presentationId, url) {
sessionId = presentationId;
sendAsyncMessage('sender-launch', url);
sendAsyncMessage("sender-launch", url);
},
disconnect: function(reason) {
disconnect(reason) {
if (!this._listener) {
return;
}
@ -71,16 +71,16 @@ const mockControlChannelOfSender = {
.notifyDisconnected(reason);
mockControlChannelOfReceiver.disconnect();
},
terminate: function(presentationId) {
sendAsyncMessage('sender-terminate');
terminate(presentationId) {
sendAsyncMessage("sender-terminate");
},
reconnect: function(presentationId, url) {
sendAsyncMessage('start-reconnect', url);
reconnect(presentationId, url) {
sendAsyncMessage("start-reconnect", url);
},
sendIceCandidate: function(candidate) {
sendIceCandidate(candidate) {
mockControlChannelOfReceiver.notifyIceCandidate(candidate);
},
notifyIceCandidate: function(candidate) {
notifyIceCandidate(candidate) {
if (!this._listener) {
return;
}
@ -97,9 +97,9 @@ const mockControlChannelOfReceiver = {
set listener(listener) {
// PresentationPresentingInfo::SetControlChannel
if (listener) {
debug('set listener for mockControlChannelOfReceiver without null');
debug("set listener for mockControlChannelOfReceiver without null");
} else {
debug('set listener for mockControlChannelOfReceiver with null');
debug("set listener for mockControlChannelOfReceiver with null");
}
this._listener = listener;
@ -111,7 +111,7 @@ const mockControlChannelOfReceiver = {
get listener() {
return this._listener;
},
notifyConnected: function() {
notifyConnected() {
// do nothing
if (!this._listener) {
this._pendingOpened = true;
@ -121,17 +121,17 @@ const mockControlChannelOfReceiver = {
.QueryInterface(Ci.nsIPresentationControlChannelListener)
.notifyConnected();
},
onOffer: function(offer) {
onOffer(offer) {
this._listener
.QueryInterface(Ci.nsIPresentationControlChannelListener)
.onOffer(offer);
},
sendAnswer: function(answer) {
sendAnswer(answer) {
Services.tm.dispatchToMainThread(() => {
mockControlChannelOfSender.onAnswer(answer);
});
},
disconnect: function(reason) {
disconnect(reason) {
if (!this._listener) {
return;
}
@ -139,14 +139,14 @@ const mockControlChannelOfReceiver = {
this._listener
.QueryInterface(Ci.nsIPresentationControlChannelListener)
.notifyDisconnected(reason);
sendAsyncMessage('control-channel-receiver-closed', reason);
sendAsyncMessage("control-channel-receiver-closed", reason);
},
terminate: function(presentaionId) {
terminate(presentaionId) {
},
sendIceCandidate: function(candidate) {
sendIceCandidate(candidate) {
mockControlChannelOfReceiver.notifyIceCandidate(candidate);
},
notifyIceCandidate: function(candidate) {
notifyIceCandidate(candidate) {
if (!this._listener) {
return;
}
@ -159,20 +159,20 @@ const mockControlChannelOfReceiver = {
const mockDevice = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevice]),
id: 'id',
name: 'name',
type: 'type',
establishControlChannel: function(url, presentationId) {
id: "id",
name: "name",
type: "type",
establishControlChannel(url, presentationId) {
if (triggerControlChannelError) {
throw Cr.NS_ERROR_FAILURE;
}
sendAsyncMessage('control-channel-established');
sendAsyncMessage("control-channel-established");
return mockControlChannelOfSender;
},
disconnect: function() {
sendAsyncMessage('device-disconnected');
disconnect() {
sendAsyncMessage("device-disconnected");
},
isRequestedUrlSupported: function(requestedUrl) {
isRequestedUrlSupported(requestedUrl) {
return true;
},
};
@ -180,7 +180,7 @@ const mockDevice = {
const mockDevicePrompt = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevicePrompt,
Ci.nsIFactory]),
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
@ -192,14 +192,14 @@ const mockDevicePrompt = {
get request() {
return this._request;
},
promptDeviceSelection: function(request) {
promptDeviceSelection(request) {
this._request = request;
sendAsyncMessage('device-prompt');
sendAsyncMessage("device-prompt");
},
simulateSelect: function() {
simulateSelect() {
this._request.select(mockDevice);
},
simulateCancel: function() {
simulateCancel() {
this._request.cancel();
}
};
@ -208,18 +208,18 @@ const mockRequestUIGlue = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationRequestUIGlue,
Ci.nsIFactory]),
set promise(aPromise) {
this._promise = aPromise
this._promise = aPromise;
},
get promise() {
return this._promise;
},
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
return this.QueryInterface(aIID);
},
sendRequest: function(aUrl, aSessionId) {
sendRequest(aUrl, aSessionId) {
return this.promise;
},
};
@ -244,11 +244,11 @@ function initMockAndListener() {
registrar.registerFactory(mockClassId, "", contractId, mockFactory);
}
return { contractId: contractId,
mockClassId: mockClassId,
mockFactory: mockFactory,
originalClassId: originalClassId,
originalFactory: originalFactory };
return { contractId,
mockClassId,
mockFactory,
originalClassId,
originalFactory };
}
// Register mock factories.
const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
@ -260,22 +260,22 @@ function initMockAndListener() {
uuidGenerator.generateUUID(),
mockRequestUIGlue));
addMessageListener('trigger-device-add', function() {
debug('Got message: trigger-device-add');
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
addMessageListener("trigger-device-add", function() {
debug("Got message: trigger-device-add");
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
.addDevice(mockDevice);
});
addMessageListener('trigger-device-prompt-select', function() {
debug('Got message: trigger-device-prompt-select');
addMessageListener("trigger-device-prompt-select", function() {
debug("Got message: trigger-device-prompt-select");
mockDevicePrompt.simulateSelect();
});
addMessageListener('trigger-on-session-request', function(url) {
debug('Got message: trigger-on-session-request');
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
addMessageListener("trigger-on-session-request", function(url) {
debug("Got message: trigger-on-session-request");
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
.onSessionRequest(mockDevice,
@ -284,9 +284,9 @@ function initMockAndListener() {
mockControlChannelOfReceiver);
});
addMessageListener('trigger-on-terminate-request', function() {
debug('Got message: trigger-on-terminate-request');
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
addMessageListener("trigger-on-terminate-request", function() {
debug("Got message: trigger-on-terminate-request");
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
.onTerminateRequest(mockDevice,
@ -295,21 +295,21 @@ function initMockAndListener() {
false);
});
addMessageListener('trigger-control-channel-open', function(reason) {
debug('Got message: trigger-control-channel-open');
addMessageListener("trigger-control-channel-open", function(reason) {
debug("Got message: trigger-control-channel-open");
mockControlChannelOfSender.notifyConnected();
mockControlChannelOfReceiver.notifyConnected();
});
addMessageListener('trigger-control-channel-error', function(reason) {
debug('Got message: trigger-control-channel-open');
addMessageListener("trigger-control-channel-error", function(reason) {
debug("Got message: trigger-control-channel-open");
triggerControlChannelError = true;
});
addMessageListener('trigger-reconnected-acked', function(url) {
debug('Got message: trigger-reconnected-acked');
addMessageListener("trigger-reconnected-acked", function(url) {
debug("Got message: trigger-reconnected-acked");
mockControlChannelOfSender.notifyReconnected();
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
.onReconnectRequest(mockDevice,
@ -319,20 +319,20 @@ function initMockAndListener() {
});
// Used to call sendAsyncMessage in chrome script from receiver.
addMessageListener('forward-command', function(command_data) {
addMessageListener("forward-command", function(command_data) {
let command = JSON.parse(command_data);
sendAsyncMessage(command.name, command.data);
});
addMessageListener('teardown', teardown);
addMessageListener("teardown", teardown);
var obs = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
obs.addObserver(function setupRequestPromiseHandler(aSubject, aTopic, aData) {
debug('Got observer: setup-request-promise');
debug("Got observer: setup-request-promise");
obs.removeObserver(setupRequestPromiseHandler, aTopic);
mockRequestUIGlue.promise = aSubject;
sendAsyncMessage('promise-setup-ready');
}, 'setup-request-promise');
sendAsyncMessage("promise-setup-ready");
}, "setup-request-promise");
}
function teardown() {
@ -350,7 +350,7 @@ function teardown() {
mockControlChannelOfReceiver.listener = null;
mockDevicePrompt.request = null;
var deviceManager = Cc['@mozilla.org/presentation-device/manager;1']
var deviceManager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
deviceManager.QueryInterface(Ci.nsIPresentationDeviceListener)
.removeDevice(mockDevice);
@ -360,7 +360,7 @@ function teardown() {
data.mockFactory, data.originalClassId,
data.originalFactory);
}
sendAsyncMessage('teardown-complete');
sendAsyncMessage("teardown-complete");
}
initMockAndListener();

View file

@ -12,10 +12,10 @@ function loadPrivilegedScriptTest() {
*/
function sendMessage(type, data) {
if (typeof port == "undefined") {
sendAsyncMessage(type, {'data': data});
sendAsyncMessage(type, {"data": data});
} else {
port.postMessage({'type': type,
'data': data
port.postMessage({"type": type,
"data": data
});
}
}
@ -26,7 +26,7 @@ function loadPrivilegedScriptTest() {
* are exposed to this script.
*/
port.onmessage = (e) => {
var type = e.data['type'];
var type = e.data.type;
if (!handlers.hasOwnProperty(type)) {
return;
}
@ -55,7 +55,7 @@ function loadPrivilegedScriptTest() {
const Cm = Components.manager;
const mockedChannelDescription = {
QueryInterface : function (iid) {
QueryInterface(iid) {
const interfaces = [Ci.nsIPresentationChannelDescription];
if (!interfaces.some(v => iid.equals(v))) {
@ -83,7 +83,7 @@ function loadPrivilegedScriptTest() {
}
const mockedSessionTransport = {
QueryInterface : function (iid) {
QueryInterface(iid) {
const interfaces = [Ci.nsIPresentationSessionTransport,
Ci.nsIPresentationDataChannelSessionTransportBuilder,
Ci.nsIFactory];
@ -93,7 +93,7 @@ function loadPrivilegedScriptTest() {
}
return this;
},
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
@ -106,45 +106,45 @@ function loadPrivilegedScriptTest() {
return this._callback;
},
/* OOP case */
buildDataChannelTransport: function(role, window, listener) {
buildDataChannelTransport(role, window, listener) {
dump("PresentationSessionFrameScript: build data channel transport\n");
this._listener = listener;
this._role = role;
var hasNavigator = window ? (typeof window.navigator != "undefined") : false;
sendMessage('check-navigator', hasNavigator);
sendMessage("check-navigator", hasNavigator);
if (this._role == Ci.nsIPresentationService.ROLE_CONTROLLER) {
this._listener.sendOffer(mockedChannelDescription);
}
},
enableDataNotification: function() {
sendMessage('data-transport-notification-enabled');
enableDataNotification() {
sendMessage("data-transport-notification-enabled");
},
send: function(data) {
sendMessage('message-sent', data);
send(data) {
sendMessage("message-sent", data);
},
close: function(reason) {
sendMessage('data-transport-closed', reason);
close(reason) {
sendMessage("data-transport-closed", reason);
this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportClosed(reason);
this._callback = null;
},
simulateTransportReady: function() {
simulateTransportReady() {
this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyTransportReady();
},
simulateIncomingMessage: function(message) {
simulateIncomingMessage(message) {
this._callback.QueryInterface(Ci.nsIPresentationSessionTransportCallback).notifyData(message, false);
},
onOffer: function(aOffer) {
onOffer(aOffer) {
this._listener.sendAnswer(mockedChannelDescription);
this._onSessionTransport();
},
onAnswer: function(aAnswer) {
onAnswer(aAnswer) {
this._onSessionTransport();
},
_onSessionTransport: function() {
setTimeout(()=>{
_onSessionTransport() {
setTimeout(() => {
this._listener.onSessionTransport(this);
this.simulateTransportReady();
this._listener = null;
@ -184,11 +184,11 @@ function loadPrivilegedScriptTest() {
registrar.registerFactory(mockedClassId, "", contractId, mockedFactory);
}
return { contractId: contractId,
mockedClassId: mockedClassId,
mockedFactory: mockedFactory,
originalClassId: originalClassId,
originalFactory: originalFactory };
return { contractId,
mockedClassId,
mockedFactory,
originalClassId,
originalFactory };
}
function registerOriginalFactory(contractId, mockedClassId, mockedFactory, originalClassId, originalFactory) {
@ -207,23 +207,23 @@ function loadPrivilegedScriptTest() {
uuidGenerator.generateUUID(),
mockedSessionTransport));
addMessageListener('trigger-incoming-message', function(event) {
addMessageListener("trigger-incoming-message", function(event) {
mockedSessionTransport.simulateIncomingMessage(event.data.data);
});
addMessageListener('teardown', ()=>tearDown());
addMessageListener("teardown", () => tearDown());
}
// Exposed to the caller of |loadPrivilegedScript|
var contentScript = {
handlers: {},
addMessageListener: function(message, handler) {
addMessageListener(message, handler) {
if (this.handlers.hasOwnProperty(message)) {
this.handlers[message].push(handler);
} else {
this.handlers[message] = [handler];
}
},
removeMessageListener: function(message, handler) {
removeMessageListener(message, handler) {
if (!handler || !this.handlers.hasOwnProperty(message)) {
return;
}
@ -232,12 +232,12 @@ var contentScript = {
this.handlers[message].splice(index, 1);
}
},
sendAsyncMessage: function(message, data) {
port.postMessage({'type': message,
'data': data
sendAsyncMessage(message, data) {
port.postMessage({"type": message,
"data": data
});
}
}
};
if (!SpecialPowers.isMainProcess()) {
var port;
@ -248,11 +248,11 @@ if (!SpecialPowers.isMainProcess()) {
}
port.onmessage = (e) => {
var type = e.data['type'];
var type = e.data.type;
if (!contentScript.handlers.hasOwnProperty(type)) {
return;
}
var args = [e.data['data']];
var args = [e.data.data];
contentScript.handlers[type].forEach(handler => handler.apply(null, args));
};
}

View file

@ -13,26 +13,26 @@
function is(a, b, msg) {
if (a === b) {
alert('OK ' + msg);
alert("OK " + msg);
} else {
alert('KO ' + msg + ' | reason: ' + a + ' != ' + b);
alert("KO " + msg + " | reason: " + a + " != " + b);
}
}
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function info(msg) {
alert('INFO ' + msg);
alert("INFO " + msg);
}
function command(name, data) {
alert('COMMAND ' + JSON.stringify({name: name, data: data}));
alert("COMMAND " + JSON.stringify({name, data}));
}
function finish() {
alert('DONE');
alert("DONE");
}
var connection;
@ -51,7 +51,7 @@ function is_same_buffer(recv_data, expect_data) {
for (let i = 0; i < recv_dataview.length; i++) {
if (recv_dataview[i] != expected_dataview[i]) {
info('discover byte differenct at ' + i);
info("discover byte differenct at " + i);
return false;
}
}
@ -60,7 +60,7 @@ function is_same_buffer(recv_data, expect_data) {
function testConnectionAvailable() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionAvailable ---');
info("Receiver: --- testConnectionAvailable ---");
ok(navigator.presentation, "Receiver: navigator.presentation should be available.");
ok(navigator.presentation.receiver, "Receiver: navigator.presentation.receiver should be available.");
is(navigator.presentation.defaultRequest, null, "Receiver: navigator.presentation.defaultRequest should be null.");
@ -83,10 +83,10 @@ function testConnectionAvailable() {
function testConnectionReady() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionReady ---');
info("Receiver: --- testConnectionReady ---");
connection.onconnect = function() {
connection.onconnect = null;
ok(false, "Should not get |onconnect| event.")
ok(false, "Should not get |onconnect| event.");
aReject();
};
if (connection.state === "connected") {
@ -99,27 +99,27 @@ function testConnectionReady() {
function testIncomingMessage() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testIncomingMessage ---');
connection.addEventListener('message', function(evt) {
info("Receiver: --- testIncomingMessage ---");
connection.addEventListener("message", function(evt) {
let msg = evt.data;
is(msg, 'msg-sender-to-receiver', 'Receiver: Receiver should receive message from sender.');
command('forward-command', JSON.stringify({ name: 'message-from-sender-received' }));
is(msg, "msg-sender-to-receiver", "Receiver: Receiver should receive message from sender.");
command("forward-command", JSON.stringify({ name: "message-from-sender-received" }));
aResolve();
}, {once: true});
command('forward-command', JSON.stringify({ name: 'trigger-message-from-sender' }));
command("forward-command", JSON.stringify({ name: "trigger-message-from-sender" }));
});
}
function testSendMessage() {
return new Promise(function(aResolve, aReject) {
window.addEventListener('hashchange', function hashchangeHandler(evt) {
window.addEventListener("hashchange", function hashchangeHandler(evt) {
var message = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
if (message.type === 'trigger-message-from-receiver') {
info('Receiver: --- testSendMessage ---');
connection.send('msg-receiver-to-sender');
if (message.type === "trigger-message-from-receiver") {
info("Receiver: --- testSendMessage ---");
connection.send("msg-receiver-to-sender");
}
if (message.type === 'message-from-receiver-received') {
window.removeEventListener('hashchange', hashchangeHandler);
if (message.type === "message-from-receiver-received") {
window.removeEventListener("hashchange", hashchangeHandler);
aResolve();
}
});
@ -128,11 +128,11 @@ function testSendMessage() {
function testIncomingBlobMessage() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testIncomingBlobMessage ---');
connection.send('testIncomingBlobMessage');
connection.addEventListener('message', function(evt) {
let recvData= String.fromCharCode.apply(null, new Uint8Array(evt.data));
is(recvData, "Hello World", 'expected same string data');
info("Receiver: --- testIncomingBlobMessage ---");
connection.send("testIncomingBlobMessage");
connection.addEventListener("message", function(evt) {
let recvData = String.fromCharCode.apply(null, new Uint8Array(evt.data));
is(recvData, "Hello World", "expected same string data");
aResolve();
}, {once: true});
});
@ -140,29 +140,29 @@ function testIncomingBlobMessage() {
function testConnectionClosed() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionClosed ---');
info("Receiver: --- testConnectionClosed ---");
connection.onclose = function() {
connection.onclose = null;
is(connection.state, "closed", "Receiver: Connection should be closed.");
command('forward-command', JSON.stringify({ name: 'receiver-closed' }));
command("forward-command", JSON.stringify({ name: "receiver-closed" }));
aResolve();
};
command('forward-command', JSON.stringify({ name: 'ready-to-close' }));
command("forward-command", JSON.stringify({ name: "ready-to-close" }));
});
}
function testReconnectConnection() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testReconnectConnection ---');
window.addEventListener('hashchange', function hashchangeHandler(evt) {
info("Receiver: --- testReconnectConnection ---");
window.addEventListener("hashchange", function hashchangeHandler(evt) {
var message = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
if (message.type === 'prepare-for-reconnect') {
command('forward-command', JSON.stringify({ name: 'ready-to-reconnect' }));
if (message.type === "prepare-for-reconnect") {
command("forward-command", JSON.stringify({ name: "ready-to-reconnect" }));
}
});
connection.onconnect = function() {
connection.onconnect = null;
ok(true, "The connection is reconnected.")
ok(true, "The connection is reconnected.");
aResolve();
};
});
@ -170,10 +170,10 @@ function testReconnectConnection() {
function testIncomingArrayBuffer() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testIncomingArrayBuffer ---');
info("Receiver: --- testIncomingArrayBuffer ---");
connection.binaryType = "blob";
connection.send('testIncomingArrayBuffer');
connection.addEventListener('message', function(evt) {
connection.send("testIncomingArrayBuffer");
connection.addEventListener("message", function(evt) {
var fileReader = new FileReader();
fileReader.onload = function() {
ok(is_same_buffer(DATA_ARRAY_BUFFER, this.result), "expected same buffer data");
@ -186,10 +186,10 @@ function testIncomingArrayBuffer() {
function testIncomingArrayBufferView() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testIncomingArrayBufferView ---');
info("Receiver: --- testIncomingArrayBufferView ---");
connection.binaryType = "arraybuffer";
connection.send('testIncomingArrayBufferView');
connection.addEventListener('message', function(evt) {
connection.send("testIncomingArrayBufferView");
connection.addEventListener("message", function(evt) {
ok(is_same_buffer(evt.data, TYPED_DATA_ARRAY), "expected same buffer data");
aResolve();
}, {once: true});

View file

@ -13,33 +13,33 @@
function is(a, b, msg) {
if (a === b) {
alert('OK ' + msg);
alert("OK " + msg);
} else {
alert('KO ' + msg + ' | reason: ' + a + ' != ' + b);
alert("KO " + msg + " | reason: " + a + " != " + b);
}
}
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function info(msg) {
alert('INFO ' + msg);
alert("INFO " + msg);
}
function command(name, data) {
alert('COMMAND ' + JSON.stringify({name: name, data: data}));
alert("COMMAND " + JSON.stringify({name, data}));
}
function finish() {
alert('DONE');
alert("DONE");
}
var connection;
function testConnectionAvailable() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionAvailable ---');
info("Receiver: --- testConnectionAvailable ---");
ok(navigator.presentation, "Receiver: navigator.presentation should be available.");
ok(navigator.presentation.receiver, "Receiver: navigator.presentation.receiver should be available.");
@ -61,10 +61,10 @@ function testConnectionAvailable() {
function testConnectionReady() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionReady ---');
info("Receiver: --- testConnectionReady ---");
connection.onconnect = function() {
connection.onconnect = null;
ok(false, "Should not get |onconnect| event.")
ok(false, "Should not get |onconnect| event.");
aReject();
};
if (connection.state === "connected") {
@ -77,8 +77,8 @@ function testConnectionReady() {
function testConnectionWentaway() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionWentaway ---\n');
command('forward-command', JSON.stringify({ name: 'ready-to-remove-receiverFrame' }));
info("Receiver: --- testConnectionWentaway ---\n");
command("forward-command", JSON.stringify({ name: "ready-to-remove-receiverFrame" }));
});
}

View file

@ -6,5 +6,5 @@ function testReceiver() {
}
testReceiver();
window.addEventListener('hashchange', testReceiver);
window.addEventListener("hashchange", testReceiver);
</script>

View file

@ -11,19 +11,19 @@
"use strict";
function is(a, b, msg) {
alert((a === b ? 'OK ' : 'KO ') + msg);
alert((a === b ? "OK " : "KO ") + msg);
}
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function info(msg) {
alert('INFO ' + msg);
alert("INFO " + msg);
}
function finish() {
alert('DONE');
alert("DONE");
}
function testConnectionAvailable() {

View file

@ -11,7 +11,7 @@
"use strict";
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function testConnectionAvailable() {

View file

@ -11,23 +11,23 @@
"use strict";
function is(a, b, msg) {
alert((a === b ? 'OK ' : 'KO ') + msg);
alert((a === b ? "OK " : "KO ") + msg);
}
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function info(msg) {
alert('INFO ' + msg);
alert("INFO " + msg);
}
function command(msg) {
alert('COMMAND ' + JSON.stringify(msg));
alert("COMMAND " + JSON.stringify(msg));
}
function finish() {
alert('DONE');
alert("DONE");
}
var connection;
@ -51,7 +51,7 @@ function testConnectionAvailable() {
aReject();
}
);
command({ name: 'trigger-incoming-offer' });
command({ name: "trigger-incoming-offer" });
});
}
@ -64,8 +64,8 @@ function testDefaultRequestIsUndefined() {
function testConnectionAvailableSameOriginInnerIframe() {
return new Promise(function(aResolve, aReject) {
var iframe = document.createElement('iframe');
iframe.setAttribute('src', './file_presentation_receiver_inner_iframe.html');
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "./file_presentation_receiver_inner_iframe.html");
document.body.appendChild(iframe);
aResolve();
@ -74,8 +74,8 @@ function testConnectionAvailableSameOriginInnerIframe() {
function testConnectionUnavailableDiffOriginInnerIframe() {
return new Promise(function(aResolve, aReject) {
var iframe = document.createElement('iframe');
iframe.setAttribute('src', 'http://example.com/tests/dom/presentation/tests/mochitest/file_presentation_non_receiver_inner_iframe.html');
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "http://example.com/tests/dom/presentation/tests/mochitest/file_presentation_non_receiver_inner_iframe.html");
document.body.appendChild(iframe);
aResolve();
@ -103,12 +103,12 @@ function testIncomingMessage() {
return new Promise(function(aResolve, aReject) {
const incomingMessage = "test incoming message";
connection.addEventListener('message', function(aEvent) {
connection.addEventListener("message", function(aEvent) {
is(aEvent.data, incomingMessage, "An incoming message should be received.");
aResolve();
}, {once: true});
command({ name: 'trigger-incoming-message',
command({ name: "trigger-incoming-message",
data: incomingMessage });
});
}

View file

@ -11,23 +11,23 @@
"use strict";
function is(a, b, msg) {
alert((a === b ? 'OK ' : 'KO ') + msg);
alert((a === b ? "OK " : "KO ") + msg);
}
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function info(msg) {
alert('INFO ' + msg);
alert("INFO " + msg);
}
function command(msg) {
alert('COMMAND ' + JSON.stringify(msg));
alert("COMMAND " + JSON.stringify(msg));
}
function finish() {
alert('DONE');
alert("DONE");
}
function testConnectionAvailable() {
@ -44,7 +44,7 @@ function testOpenWindow() {
try {
window.open("http://example.com");
ok(false, "receiver page should not be able to open a new window.");
} catch(e) {
} catch (e) {
ok(true, "receiver page should not be able to open a new window.");
aResolve();
}

View file

@ -12,26 +12,26 @@
function is(a, b, msg) {
if (a === b) {
alert('OK ' + msg);
alert("OK " + msg);
} else {
alert('KO ' + msg + ' | reason: ' + a + ' != ' + b);
alert("KO " + msg + " | reason: " + a + " != " + b);
}
}
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function info(msg) {
alert('INFO ' + msg);
alert("INFO " + msg);
}
function command(name, data) {
alert('COMMAND ' + JSON.stringify({name: name, data: data}));
alert("COMMAND " + JSON.stringify({name, data}));
}
function finish() {
alert('DONE');
alert("DONE");
}
function testConnectionAvailable() {
@ -44,13 +44,13 @@ function testConnectionAvailable() {
function testUnexpectedControlChannelClose() {
// Trigger the control channel to be closed with error code.
command({ name: 'trigger-control-channel-close', data: 0x80004004 /* NS_ERROR_ABORT */ });
command({ name: "trigger-control-channel-close", data: 0x80004004 /* NS_ERROR_ABORT */ });
return new Promise(function(aResolve, aReject) {
return Promise.race([
navigator.presentation.receiver.connectionList.then(
(aList) => {
ok(false, "Should not get a connection list.")
ok(false, "Should not get a connection list.");
aReject();
},
(aError) => {

View file

@ -11,7 +11,7 @@
"use strict";
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function testConnectionAvailable() {

View file

@ -81,14 +81,13 @@ function testCloseConnection() {
window.addEventListener("message", function onMessage(evt) {
if (evt.data === "startConnection") {
testStartRequest().then(
function () {
function() {
command({ name: "connection-connected", id: connection.id });
}
);
}
else if (evt.data === "closeConnection") {
} else if (evt.data === "closeConnection") {
testCloseConnection().then(
function () {
function() {
command({ name: "connection-closed", id: connection.id });
}
);

View file

@ -9,50 +9,50 @@
<div id='content'></div>
<script type='application/javascript'>
'use strict';
"use strict";
function is(a, b, msg) {
if (a === b) {
alert('OK ' + msg);
alert("OK " + msg);
} else {
alert('KO ' + msg + ' | reason: ' + a + ' != ' + b);
alert("KO " + msg + " | reason: " + a + " != " + b);
}
}
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function info(msg) {
alert('INFO ' + msg);
alert("INFO " + msg);
}
function command(name, data) {
alert('COMMAND ' + JSON.stringify({name: name, data: data}));
alert("COMMAND " + JSON.stringify({name, data}));
}
function finish() {
alert('DONE');
alert("DONE");
}
var connection;
function testConnectionAvailable() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionAvailable ---');
ok(navigator.presentation, 'Receiver: navigator.presentation should be available.');
ok(navigator.presentation.receiver, 'Receiver: navigator.presentation.receiver should be available.');
info("Receiver: --- testConnectionAvailable ---");
ok(navigator.presentation, "Receiver: navigator.presentation should be available.");
ok(navigator.presentation.receiver, "Receiver: navigator.presentation.receiver should be available.");
navigator.presentation.receiver.connectionList
.then((aList) => {
is(aList.connections.length, 1, 'Should get one conncetion.');
is(aList.connections.length, 1, "Should get one conncetion.");
connection = aList.connections[0];
ok(connection.id, 'Connection ID should be set: ' + connection.id);
is(connection.state, 'connected', 'Connection state at receiver side should be connected.');
ok(connection.id, "Connection ID should be set: " + connection.id);
is(connection.state, "connected", "Connection state at receiver side should be connected.");
aResolve();
})
.catch((aError) => {
ok(false, 'Receiver: Error occurred when getting the connection: ' + aError);
ok(false, "Receiver: Error occurred when getting the connection: " + aError);
finish();
aReject();
});
@ -61,15 +61,15 @@ function testConnectionAvailable() {
function testConnectionReady() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionReady ---');
info("Receiver: --- testConnectionReady ---");
connection.onconnect = function() {
connection.onconnect = null;
ok(false, 'Should not get |onconnect| event.')
ok(false, "Should not get |onconnect| event.");
aReject();
};
if (connection.state === 'connected') {
if (connection.state === "connected") {
connection.onconnect = null;
is(connection.state, 'connected', 'Receiver: Connection state should become connected.');
is(connection.state, "connected", "Receiver: Connection state should become connected.");
aResolve();
}
});
@ -77,24 +77,24 @@ function testConnectionReady() {
function testConnectionTerminate() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionTerminate ---');
info("Receiver: --- testConnectionTerminate ---");
connection.onterminate = function() {
connection.onterminate = null;
// Using window.alert at this stage will cause window.close() fail.
// Only trigger it if verdict fail.
if (connection.state !== 'terminated') {
is(connection.state, 'terminated', 'Receiver: Connection should be terminated.');
if (connection.state !== "terminated") {
is(connection.state, "terminated", "Receiver: Connection should be terminated.");
}
aResolve();
};
command('forward-command', JSON.stringify({ name: 'ready-to-terminate' }));
command("forward-command", JSON.stringify({ name: "ready-to-terminate" }));
});
}
function runTests() {
testConnectionAvailable()
.then(testConnectionReady)
.then(testConnectionTerminate)
.then(testConnectionTerminate);
}
runTests();

View file

@ -9,50 +9,50 @@
<div id='content'></div>
<script type='application/javascript'>
'use strict';
"use strict";
function is(a, b, msg) {
if (a === b) {
alert('OK ' + msg);
alert("OK " + msg);
} else {
alert('KO ' + msg + ' | reason: ' + a + ' != ' + b);
alert("KO " + msg + " | reason: " + a + " != " + b);
}
}
function ok(a, msg) {
alert((a ? 'OK ' : 'KO ') + msg);
alert((a ? "OK " : "KO ") + msg);
}
function info(msg) {
alert('INFO ' + msg);
alert("INFO " + msg);
}
function command(name, data) {
alert('COMMAND ' + JSON.stringify({name: name, data: data}));
alert("COMMAND " + JSON.stringify({name, data}));
}
function finish() {
alert('DONE');
alert("DONE");
}
var connection;
function testConnectionAvailable() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionAvailable ---');
ok(navigator.presentation, 'Receiver: navigator.presentation should be available.');
ok(navigator.presentation.receiver, 'Receiver: navigator.presentation.receiver should be available.');
info("Receiver: --- testConnectionAvailable ---");
ok(navigator.presentation, "Receiver: navigator.presentation should be available.");
ok(navigator.presentation.receiver, "Receiver: navigator.presentation.receiver should be available.");
navigator.presentation.receiver.connectionList
.then((aList) => {
is(aList.connections.length, 1, 'Should get one connection.');
is(aList.connections.length, 1, "Should get one connection.");
connection = aList.connections[0];
ok(connection.id, 'Connection ID should be set: ' + connection.id);
is(connection.state, 'connected', 'Connection state at receiver side should be connected.');
ok(connection.id, "Connection ID should be set: " + connection.id);
is(connection.state, "connected", "Connection state at receiver side should be connected.");
aResolve();
})
.catch((aError) => {
ok(false, 'Receiver: Error occurred when getting the connection: ' + aError);
ok(false, "Receiver: Error occurred when getting the connection: " + aError);
finish();
aReject();
});
@ -61,15 +61,15 @@ function testConnectionAvailable() {
function testConnectionReady() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionReady ---');
info("Receiver: --- testConnectionReady ---");
connection.onconnect = function() {
connection.onconnect = null;
ok(false, 'Should not get |onconnect| event.')
ok(false, "Should not get |onconnect| event.");
aReject();
};
if (connection.state === 'connected') {
if (connection.state === "connected") {
connection.onconnect = null;
is(connection.state, 'connected', 'Receiver: Connection state should become connected.');
is(connection.state, "connected", "Receiver: Connection state should become connected.");
aResolve();
}
});
@ -77,34 +77,34 @@ function testConnectionReady() {
function testConnectionTerminate() {
return new Promise(function(aResolve, aReject) {
info('Receiver: --- testConnectionTerminate ---');
info("Receiver: --- testConnectionTerminate ---");
connection.onterminate = function() {
connection.onterminate = null;
// Using window.alert at this stage will cause window.close() fail.
// Only trigger it if verdict fail.
if (connection.state !== 'terminated') {
is(connection.state, 'terminated', 'Receiver: Connection should be terminated.');
if (connection.state !== "terminated") {
is(connection.state, "terminated", "Receiver: Connection should be terminated.");
}
aResolve();
};
window.addEventListener('hashchange', function hashchangeHandler(evt) {
window.addEventListener("hashchange", function hashchangeHandler(evt) {
var message = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
if (message.type === 'ready-to-terminate') {
info('Receiver: --- ready-to-terminate ---');
if (message.type === "ready-to-terminate") {
info("Receiver: --- ready-to-terminate ---");
connection.terminate();
}
});
command('forward-command', JSON.stringify({ name: 'prepare-for-terminate' }));
command("forward-command", JSON.stringify({ name: "prepare-for-terminate" }));
});
}
function runTests() {
testConnectionAvailable()
.then(testConnectionReady)
.then(testConnectionTerminate)
.then(testConnectionTerminate);
}
runTests();

View file

@ -1,42 +1,42 @@
'use strict';
"use strict";
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout('Test for guarantee not firing async event');
SimpleTest.requestFlakyTimeout("Test for guarantee not firing async event");
function debug(str) {
// info(str);
}
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript1UA.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_1ua_wentaway.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript1UA.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_1ua_wentaway.html");
var request;
var connection;
var receiverIframe;
function setup() {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
debug('Got message: device-prompt');
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
debug("Got message: device-prompt");
gScript.removeMessageListener("device-prompt", devicePromptHandler);
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established',
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established",
controlChannelEstablishedHandler);
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('sender-launch', function senderLaunchHandler(url) {
debug('Got message: sender-launch');
gScript.removeMessageListener('sender-launch', senderLaunchHandler);
is(url, receiverUrl, 'Receiver: should receive the same url');
receiverIframe = document.createElement('iframe');
gScript.addMessageListener("sender-launch", function senderLaunchHandler(url) {
debug("Got message: sender-launch");
gScript.removeMessageListener("sender-launch", senderLaunchHandler);
is(url, receiverUrl, "Receiver: should receive the same url");
receiverIframe = document.createElement("iframe");
receiverIframe.setAttribute("mozbrowser", "true");
receiverIframe.setAttribute("mozpresentation", receiverUrl);
var oop = !location.pathname.includes('_inproc');
var oop = !location.pathname.includes("_inproc");
receiverIframe.setAttribute("remote", oop);
receiverIframe.setAttribute('src', receiverUrl);
receiverIframe.setAttribute("src", receiverUrl);
receiverIframe.addEventListener("mozbrowserloadend", function() {
info("Receiver loaded.");
}, {once: true});
@ -67,14 +67,14 @@ function setup() {
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
});
gScript.addMessageListener('promise-setup-ready', function promiseSetupReadyHandler() {
debug('Got message: promise-setup-ready');
gScript.removeMessageListener('promise-setup-ready',
gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
debug("Got message: promise-setup-ready");
gScript.removeMessageListener("promise-setup-ready",
promiseSetupReadyHandler);
gScript.sendAsyncMessage('trigger-on-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-on-session-request", receiverUrl);
});
return Promise.resolve();
@ -82,7 +82,7 @@ function setup() {
function testCreateRequest() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testCreateRequest ---');
info("Sender: --- testCreateRequest ---");
request = new PresentationRequest(receiverUrl);
request.getAvailability().then((aAvailability) => {
is(aAvailability.value, false, "Sender: should have no available device after setup");
@ -90,9 +90,9 @@ function testCreateRequest() {
aAvailability.onchange = null;
ok(aAvailability.value, "Sender: Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
}).catch((aError) => {
ok(false, "Sender: Error occurred when getting availability: " + aError);
teardown();
@ -123,32 +123,32 @@ function testStartConnection() {
function testConnectionWentaway() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testConnectionWentaway ---');
info("Sender: --- testConnectionWentaway ---");
connection.onclose = function() {
connection.onclose = null;
is(connection.state, "closed", "Sender: Connection should be closed.");
receiverIframe.addEventListener('mozbrowserclose', function closeHandler() {
ok(false, 'wentaway should not trigger receiver close');
receiverIframe.addEventListener("mozbrowserclose", function closeHandler() {
ok(false, "wentaway should not trigger receiver close");
aResolve();
});
setTimeout(aResolve, 3000);
};
gScript.addMessageListener('ready-to-remove-receiverFrame', function onReadyToRemove() {
gScript.removeMessageListener('ready-to-remove-receiverFrame', onReadyToRemove);
gScript.addMessageListener("ready-to-remove-receiverFrame", function onReadyToRemove() {
gScript.removeMessageListener("ready-to-remove-receiverFrame", onReadyToRemove);
receiverIframe.src = "http://example.com";
});
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
debug('Got message: teardown-complete');
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
debug("Got message: teardown-complete");
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -159,10 +159,10 @@ function runTests() {
}
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], () => {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.receiver.enabled", true],
["dom.presentation.test.enabled", true],

View file

@ -3,14 +3,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
'use strict';
"use strict";
function debug(str) {
// info(str);
}
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript1UA.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_1ua_receiver.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript1UA.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_1ua_receiver.html");
var request;
var connection;
var receiverIframe;
@ -27,33 +27,33 @@ function postMessageToIframe(aType) {
function setup() {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
debug('Got message: device-prompt');
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
debug("Got message: device-prompt");
gScript.removeMessageListener("device-prompt", devicePromptHandler);
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established',
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established",
controlChannelEstablishedHandler);
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('sender-launch', function senderLaunchHandler(url) {
debug('Got message: sender-launch');
gScript.removeMessageListener('sender-launch', senderLaunchHandler);
is(url, receiverUrl, 'Receiver: should receive the same url');
receiverIframe = document.createElement('iframe');
receiverIframe.setAttribute('src', receiverUrl);
gScript.addMessageListener("sender-launch", function senderLaunchHandler(url) {
debug("Got message: sender-launch");
gScript.removeMessageListener("sender-launch", senderLaunchHandler);
is(url, receiverUrl, "Receiver: should receive the same url");
receiverIframe = document.createElement("iframe");
receiverIframe.setAttribute("src", receiverUrl);
receiverIframe.setAttribute("mozbrowser", "true");
receiverIframe.setAttribute("mozpresentation", receiverUrl);
var oop = !location.pathname.includes('_inproc');
var oop = !location.pathname.includes("_inproc");
receiverIframe.setAttribute("remote", oop);
// This event is triggered when the iframe calls "alert".
receiverIframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(evt) {
var message = evt.detail.message;
debug('Got iframe message: ' + message);
debug("Got iframe message: " + message);
if (/^OK /.exec(message)) {
ok(true, message.replace(/^OK /, ""));
} else if (/^KO /.exec(message)) {
@ -76,13 +76,13 @@ function setup() {
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
});
gScript.addMessageListener('promise-setup-ready', function promiseSetupReadyHandler() {
debug('Got message: promise-setup-ready');
gScript.removeMessageListener('promise-setup-ready', promiseSetupReadyHandler);
gScript.sendAsyncMessage('trigger-on-session-request', receiverUrl);
gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
debug("Got message: promise-setup-ready");
gScript.removeMessageListener("promise-setup-ready", promiseSetupReadyHandler);
gScript.sendAsyncMessage("trigger-on-session-request", receiverUrl);
});
return Promise.resolve();
@ -90,7 +90,7 @@ function setup() {
function testCreateRequest() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testCreateRequest ---');
info("Sender: --- testCreateRequest ---");
request = new PresentationRequest("file_presentation_1ua_receiver.html");
request.getAvailability().then((aAvailability) => {
is(aAvailability.value, false, "Sender: should have no available device after setup");
@ -98,9 +98,9 @@ function testCreateRequest() {
aAvailability.onchange = null;
ok(aAvailability.value, "Sender: Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
}).catch((aError) => {
ok(false, "Sender: Error occurred when getting availability: " + aError);
teardown();
@ -140,17 +140,17 @@ function testStartConnection() {
function testSendMessage() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testSendMessage ---');
gScript.addMessageListener('trigger-message-from-sender', function triggerMessageFromSenderHandler() {
debug('Got message: trigger-message-from-sender');
gScript.removeMessageListener('trigger-message-from-sender', triggerMessageFromSenderHandler);
info('Send message to receiver');
connection.send('msg-sender-to-receiver');
info("Sender: --- testSendMessage ---");
gScript.addMessageListener("trigger-message-from-sender", function triggerMessageFromSenderHandler() {
debug("Got message: trigger-message-from-sender");
gScript.removeMessageListener("trigger-message-from-sender", triggerMessageFromSenderHandler);
info("Send message to receiver");
connection.send("msg-sender-to-receiver");
});
gScript.addMessageListener('message-from-sender-received', function messageFromSenderReceivedHandler() {
debug('Got message: message-from-sender-received');
gScript.removeMessageListener('message-from-sender-received', messageFromSenderReceivedHandler);
gScript.addMessageListener("message-from-sender-received", function messageFromSenderReceivedHandler() {
debug("Got message: message-from-sender-received");
gScript.removeMessageListener("message-from-sender-received", messageFromSenderReceivedHandler);
aResolve();
});
});
@ -158,24 +158,24 @@ function testSendMessage() {
function testIncomingMessage() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testIncomingMessage ---');
connection.addEventListener('message', function(evt) {
info("Sender: --- testIncomingMessage ---");
connection.addEventListener("message", function(evt) {
let msg = evt.data;
is(msg, "msg-receiver-to-sender", "Sender: Sender should receive message from Receiver");
postMessageToIframe('message-from-receiver-received');
postMessageToIframe("message-from-receiver-received");
aResolve();
}, {once: true});
postMessageToIframe('trigger-message-from-receiver');
postMessageToIframe("trigger-message-from-receiver");
});
}
function testSendBlobMessage() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testSendBlobMessage ---');
connection.addEventListener('message', function(evt) {
info("Sender: --- testSendBlobMessage ---");
connection.addEventListener("message", function(evt) {
let msg = evt.data;
is(msg, "testIncomingBlobMessage", "Sender: Sender should receive message from Receiver");
let blob = new Blob(["Hello World"], {type : 'text/plain'});
let blob = new Blob(["Hello World"], {type: "text/plain"});
connection.send(blob);
aResolve();
}, {once: true});
@ -184,8 +184,8 @@ function testSendBlobMessage() {
function testSendArrayBuffer() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testSendArrayBuffer ---');
connection.addEventListener('message', function(evt) {
info("Sender: --- testSendArrayBuffer ---");
connection.addEventListener("message", function(evt) {
let msg = evt.data;
is(msg, "testIncomingArrayBuffer", "Sender: Sender should receive message from Receiver");
connection.send(DATA_ARRAY_BUFFER);
@ -196,8 +196,8 @@ function testSendArrayBuffer() {
function testSendArrayBufferView() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testSendArrayBufferView ---');
connection.addEventListener('message', function(evt) {
info("Sender: --- testSendArrayBufferView ---");
connection.addEventListener("message", function(evt) {
let msg = evt.data;
is(msg, "testIncomingArrayBufferView", "Sender: Sender should receive message from Receiver");
connection.send(TYPED_DATA_ARRAY);
@ -207,19 +207,18 @@ function testSendArrayBufferView() {
}
function testCloseConnection() {
info('Sender: --- testCloseConnection ---');
info("Sender: --- testCloseConnection ---");
// Test terminate immediate after close.
function controlChannelEstablishedHandler()
{
gScript.removeMessageListener('control-channel-established',
function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established",
controlChannelEstablishedHandler);
ok(false, "terminate after close should do nothing");
}
gScript.addMessageListener('ready-to-close', function onReadyToClose() {
gScript.removeMessageListener('ready-to-close', onReadyToClose);
gScript.addMessageListener("ready-to-close", function onReadyToClose() {
gScript.removeMessageListener("ready-to-close", onReadyToClose);
connection.close();
gScript.addMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", controlChannelEstablishedHandler);
connection.terminate();
});
@ -227,34 +226,34 @@ function testCloseConnection() {
new Promise(function(aResolve, aReject) {
connection.onclose = function() {
connection.onclose = null;
is(connection.state, 'closed', 'Sender: Connection should be closed.');
gScript.removeMessageListener('control-channel-established',
is(connection.state, "closed", "Sender: Connection should be closed.");
gScript.removeMessageListener("control-channel-established",
controlChannelEstablishedHandler);
aResolve();
};
}),
new Promise(function(aResolve, aReject) {
let timeout = setTimeout(function() {
gScript.removeMessageListener('device-disconnected',
gScript.removeMessageListener("device-disconnected",
deviceDisconnectedHandler);
ok(true, "terminate after close should not trigger device.disconnect");
aResolve();
}, 3000);
function deviceDisconnectedHandler() {
gScript.removeMessageListener('device-disconnected',
gScript.removeMessageListener("device-disconnected",
deviceDisconnectedHandler);
ok(false, "terminate after close should not trigger device.disconnect");
clearTimeout(timeout);
aResolve();
}
gScript.addMessageListener('device-disconnected', deviceDisconnectedHandler);
gScript.addMessageListener("device-disconnected", deviceDisconnectedHandler);
}),
new Promise(function(aResolve, aReject) {
gScript.addMessageListener('receiver-closed', function onReceiverClosed() {
gScript.removeMessageListener('receiver-closed', onReceiverClosed);
gScript.removeMessageListener('control-channel-established',
gScript.addMessageListener("receiver-closed", function onReceiverClosed() {
gScript.removeMessageListener("receiver-closed", onReceiverClosed);
gScript.removeMessageListener("control-channel-established",
controlChannelEstablishedHandler);
aResolve();
});
@ -263,19 +262,19 @@ function testCloseConnection() {
}
function testTerminateAfterClose() {
info('Sender: --- testTerminateAfterClose ---');
info("Sender: --- testTerminateAfterClose ---");
return Promise.race([
new Promise(function(aResolve, aReject) {
connection.onterminate = function() {
connection.onterminate = null;
ok(false, 'terminate after close should do nothing');
ok(false, "terminate after close should do nothing");
aResolve();
};
connection.terminate();
}),
new Promise(function(aResolve, aReject) {
setTimeout(function() {
is(connection.state, 'closed', 'Sender: Connection should be closed.');
is(connection.state, "closed", "Sender: Connection should be closed.");
aResolve();
}, 3000);
}),
@ -284,21 +283,21 @@ function testTerminateAfterClose() {
function testReconnect() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testReconnect ---');
gScript.addMessageListener('control-channel-established', function controlChannelEstablished() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablished);
info("Sender: --- testReconnect ---");
gScript.addMessageListener("control-channel-established", function controlChannelEstablished() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablished);
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('start-reconnect', function startReconnectHandler(url) {
debug('Got message: start-reconnect');
gScript.removeMessageListener('start-reconnect', startReconnectHandler);
is(url, receiverUrl, "URLs should be the same.")
gScript.sendAsyncMessage('trigger-reconnected-acked', url);
gScript.addMessageListener("start-reconnect", function startReconnectHandler(url) {
debug("Got message: start-reconnect");
gScript.removeMessageListener("start-reconnect", startReconnectHandler);
is(url, receiverUrl, "URLs should be the same.");
gScript.sendAsyncMessage("trigger-reconnected-acked", url);
});
gScript.addMessageListener('ready-to-reconnect', function onReadyToReconnect() {
gScript.removeMessageListener('ready-to-reconnect', onReadyToReconnect);
gScript.addMessageListener("ready-to-reconnect", function onReadyToReconnect() {
gScript.removeMessageListener("ready-to-reconnect", onReadyToReconnect);
request.reconnect(presentationId).then((aConnection) => {
connection = aConnection;
ok(connection, "Sender: Connection should be available.");
@ -316,19 +315,19 @@ function testReconnect() {
});
});
postMessageToIframe('prepare-for-reconnect');
postMessageToIframe("prepare-for-reconnect");
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
debug('Got message: teardown-complete');
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
debug("Got message: teardown-complete");
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -347,12 +346,12 @@ function runTests() {
}
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout('Test for guarantee not firing async event');
SimpleTest.requestFlakyTimeout("Test for guarantee not firing async event");
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], () => {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
/* Mocked TCP session transport builder in the test */
["dom.presentation.session_transport.data_channel.enable", true],
["dom.presentation.controller.enabled", true],

View file

@ -14,7 +14,7 @@
// This test loads in an iframe, to ensure that the navigator instance is
// loaded with the correct value of the preference.
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout('Test for guarantee not firing async event');
SimpleTest.requestFlakyTimeout("Test for guarantee not firing async event");
SpecialPowers.pushPermissions([
{type: "presentation-device-manage", allow: false, context: document},
], function() {

View file

@ -19,21 +19,21 @@ let SpecialPowers = window.parent.SpecialPowers;
"use strict";
var testDevice = {
id: 'id',
name: 'name',
type: 'type',
id: "id",
name: "name",
type: "type",
};
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationDeviceInfoChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationDeviceInfoChromeScript.js"));
var request;
var availability;
function testSetup() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('setup-complete', function() {
gScript.addMessageListener("setup-complete", function() {
aResolve();
});
gScript.sendAsyncMessage('setup');
gScript.sendAsyncMessage("setup");
});
}
@ -45,9 +45,9 @@ function testInitialUnavailable() {
aAvailability.onchange = function() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
}
};
availability = aAvailability;
gScript.sendAsyncMessage('trigger-device-add', testDevice);
gScript.sendAsyncMessage("trigger-device-add", testDevice);
}).catch(function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
teardown();
@ -81,8 +81,8 @@ function testOnChangeEvent() {
availability.onchange = null;
is(availability.value, false, "Should have no available device after device removed");
aResolve();
}
gScript.sendAsyncMessage('trigger-device-remove');
};
gScript.sendAsyncMessage("trigger-device-remove");
});
}
@ -112,15 +112,15 @@ function testUnsupportedDeviceAvailability() {
availability.onchange = null;
ok(false, "Should not get onchange event.");
teardown();
}
};
});
gScript.sendAsyncMessage('trigger-add-unsupport-url-device');
gScript.sendAsyncMessage("trigger-add-unsupport-url-device");
}),
new Promise(function(aResolve, aReject) {
setTimeout(function() {
ok(true, "Should not get onchange event.");
availability.onchange = null;
gScript.sendAsyncMessage('trigger-remove-unsupported-device');
gScript.sendAsyncMessage("trigger-remove-unsupported-device");
aResolve();
}, 3000);
}),
@ -152,11 +152,11 @@ function testMultipleAvailabilityURLs() {
});
}),
new Promise(function(aResolve) {
gScript.sendAsyncMessage('trigger-add-multiple-devices');
gScript.sendAsyncMessage("trigger-add-multiple-devices");
aResolve();
}),
]).then(new Promise(function(aResolve) {
gScript.sendAsyncMessage('trigger-remove-multiple-devices');
gScript.sendAsyncMessage("trigger-remove-multiple-devices");
aResolve();
}));
}
@ -194,11 +194,11 @@ function testPartialSupportedDeviceAvailability() {
}),
]),
new Promise(function(aResolve) {
gScript.sendAsyncMessage('trigger-add-https-devices');
gScript.sendAsyncMessage("trigger-add-https-devices");
aResolve();
}),
]).then(new Promise(function(aResolve) {
gScript.sendAsyncMessage('trigger-remove-https-devices');
gScript.sendAsyncMessage("trigger-remove-https-devices");
aResolve();
}));
}
@ -206,7 +206,7 @@ function testPartialSupportedDeviceAvailability() {
function teardown() {
request = null;
availability = null;
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
gScript.destroy();
SimpleTest.finish();
}

View file

@ -43,7 +43,7 @@ var gReject;
const clientCallback = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationSessionTransportCallback]),
notifyTransportReady: function () {
notifyTransportReady() {
info("Client transport ready.");
isClientReady = true;
@ -51,7 +51,7 @@ const clientCallback = {
gResolve();
}
},
notifyTransportClosed: function (aReason) {
notifyTransportClosed(aReason) {
info("Client transport is closed.");
isClientClosed = true;
@ -59,7 +59,7 @@ const clientCallback = {
gResolve();
}
},
notifyData: function(aData) {
notifyData(aData) {
is(aData, serverMessage, "Client transport receives data.");
gResolve();
},
@ -67,7 +67,7 @@ const clientCallback = {
const serverCallback = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationSessionTransportCallback]),
notifyTransportReady: function () {
notifyTransportReady() {
info("Server transport ready.");
isServerReady = true;
@ -75,7 +75,7 @@ const serverCallback = {
gResolve();
}
},
notifyTransportClosed: function (aReason) {
notifyTransportClosed(aReason) {
info("Server transport is closed.");
isServerClosed = true;
@ -83,34 +83,34 @@ const serverCallback = {
gResolve();
}
},
notifyData: function(aData) {
notifyData(aData) {
is(aData, clientMessage, "Server transport receives data.");
gResolve()
gResolve();
},
};
const clientListener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationSessionTransportBuilderListener]),
onSessionTransport: function(aTransport) {
onSessionTransport(aTransport) {
info("Client Transport is built.");
clientTransport = aTransport;
clientTransport.callback = clientCallback;
},
onError: function(aError) {
onError(aError) {
ok(false, "client's builder reports error " + aError);
},
sendOffer: function(aOffer) {
setTimeout(()=>this._remoteBuilder.onOffer(aOffer), 0);
sendOffer(aOffer) {
setTimeout(() => this._remoteBuilder.onOffer(aOffer), 0);
},
sendAnswer: function(aAnswer) {
setTimeout(()=>this._remoteBuilder.onAnswer(aAnswer), 0);
sendAnswer(aAnswer) {
setTimeout(() => this._remoteBuilder.onAnswer(aAnswer), 0);
},
sendIceCandidate: function(aCandidate) {
setTimeout(()=>this._remoteBuilder.onIceCandidate(aCandidate), 0);
sendIceCandidate(aCandidate) {
setTimeout(() => this._remoteBuilder.onIceCandidate(aCandidate), 0);
},
disconnect: function(aReason) {
setTimeout(()=>this._localBuilder.notifyDisconnected(aReason), 0);
setTimeout(()=>this._remoteBuilder.notifyDisconnected(aReason), 0);
disconnect(aReason) {
setTimeout(() => this._localBuilder.notifyDisconnected(aReason), 0);
setTimeout(() => this._remoteBuilder.notifyDisconnected(aReason), 0);
},
set remoteBuilder(aRemoteBuilder) {
this._remoteBuilder = aRemoteBuilder;
@ -118,31 +118,31 @@ const clientListener = {
set localBuilder(aLocalBuilder) {
this._localBuilder = aLocalBuilder;
},
}
};
const serverListener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationSessionTransportBuilderListener]),
onSessionTransport: function(aTransport) {
onSessionTransport(aTransport) {
info("Server Transport is built.");
serverTransport = aTransport;
serverTransport.callback = serverCallback;
serverTransport.enableDataNotification();
},
onError: function(aError) {
onError(aError) {
ok(false, "server's builder reports error " + aError);
},
sendOffer: function(aOffer) {
setTimeout(()=>this._remoteBuilder.onOffer(aOffer), 0);
sendOffer(aOffer) {
setTimeout(() => this._remoteBuilder.onOffer(aOffer), 0);
},
sendAnswer: function(aAnswer) {
setTimeout(()=>this._remoteBuilder.onAnswer(aAnswer), 0);
sendAnswer(aAnswer) {
setTimeout(() => this._remoteBuilder.onAnswer(aAnswer), 0);
},
sendIceCandidate: function(aCandidate) {
setTimeout(()=>this._remoteBuilder.onIceCandidate(aCandidate), 0);
sendIceCandidate(aCandidate) {
setTimeout(() => this._remoteBuilder.onIceCandidate(aCandidate), 0);
},
disconnect: function(aReason) {
setTimeout(()=>this._localBuilder.notifyDisconnected(aReason), 0);
setTimeout(()=>this._remoteBuilder.notifyDisconnected(aReason), 0);
disconnect(aReason) {
setTimeout(() => this._localBuilder.notifyDisconnected(aReason), 0);
setTimeout(() => this._remoteBuilder.notifyDisconnected(aReason), 0);
},
set remoteBuilder(aRemoteBuilder) {
this._remoteBuilder = aRemoteBuilder;
@ -150,7 +150,7 @@ const serverListener = {
set localBuilder(aLocalBuilder) {
this._localBuilder = aLocalBuilder;
},
}
};
function testBuilder() {
return new Promise(function(aResolve, aReject) {
@ -196,7 +196,7 @@ function testServerSendMessage() {
gReject = aReject;
serverTransport.send(serverMessage);
setTimeout(()=>clientTransport.enableDataNotification(), 0);
setTimeout(() => clientTransport.enableDataNotification(), 0);
});
}

View file

@ -15,20 +15,20 @@
<pre id="test"></pre>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_receiver.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver.html");
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
function setup() {
return new Promise(function(aResolve, aReject) {
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
var iframe = document.createElement('iframe');
iframe.setAttribute('src', receiverUrl);
var iframe = document.createElement("iframe");
iframe.setAttribute("src", receiverUrl);
iframe.setAttribute("mozbrowser", "true");
iframe.setAttribute("mozpresentation", receiverUrl);
@ -56,35 +56,35 @@ function setup() {
aResolve(iframe);
});
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
gScript.addMessageListener('offer-received', function offerReceivedHandler() {
gScript.removeMessageListener('offer-received', offerReceivedHandler);
gScript.addMessageListener("offer-received", function offerReceivedHandler() {
gScript.removeMessageListener("offer-received", offerReceivedHandler);
info("An offer is received.");
});
gScript.addMessageListener('answer-sent', function answerSentHandler(aIsValid) {
gScript.removeMessageListener('answer-sent', answerSentHandler);
gScript.addMessageListener("answer-sent", function answerSentHandler(aIsValid) {
gScript.removeMessageListener("answer-sent", answerSentHandler);
ok(aIsValid, "A valid answer is sent.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
});
gScript.addMessageListener('check-navigator', function checknavigatorHandler(aSuccess) {
gScript.removeMessageListener('check-navigator', checknavigatorHandler);
gScript.addMessageListener("check-navigator", function checknavigatorHandler(aSuccess) {
gScript.removeMessageListener("check-navigator", checknavigatorHandler);
ok(aSuccess, "buildDataChannel get correct window object");
});
gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
is(aReason, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
});
@ -94,8 +94,8 @@ function setup() {
function testIncomingSessionRequest() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
info("Trying to launch receiver page.");
ok(navigator.presentation, "navigator.presentation should be available in in-process pages.");
@ -103,18 +103,18 @@ function testIncomingSessionRequest() {
aResolve();
});
gScript.sendAsyncMessage('trigger-incoming-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-incoming-session-request", receiverUrl);
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -124,10 +124,10 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", false],
["dom.presentation.receiver.enabled", true],
["dom.presentation.session_transport.data_channel.enable", true],

View file

@ -16,11 +16,11 @@
<pre id="test"></pre>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_receiver.html');
var nonReceiverUrl = SimpleTest.getTestFileURL('file_presentation_non_receiver.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver.html");
var nonReceiverUrl = SimpleTest.getTestFileURL("file_presentation_non_receiver.html");
var isReceiverFinished = false;
var isNonReceiverFinished = false;
@ -31,17 +31,17 @@ var receiverIframe;
function setup() {
return new Promise(function(aResolve, aReject) {
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
// Create a receiver OOP iframe.
receiverIframe = document.createElement('iframe');
receiverIframe.setAttribute('remote', 'true');
receiverIframe.setAttribute('mozbrowser', 'true');
receiverIframe.setAttribute('mozpresentation', receiverUrl);
receiverIframe.setAttribute('src', receiverUrl);
receiverIframe = document.createElement("iframe");
receiverIframe.setAttribute("remote", "true");
receiverIframe.setAttribute("mozbrowser", "true");
receiverIframe.setAttribute("mozpresentation", receiverUrl);
receiverIframe.setAttribute("src", receiverUrl);
// This event is triggered when the iframe calls "alert".
receiverIframe.addEventListener('mozbrowsershowmodalprompt', function receiverListener(aEvent) {
receiverIframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(aEvent) {
var message = aEvent.detail.message;
if (/^OK /.exec(message)) {
ok(true, "Message from iframe: " + message);
@ -50,16 +50,16 @@ function setup() {
} else if (/^INFO /.exec(message)) {
info("Message from iframe: " + message);
} else if (/^COMMAND /.exec(message)) {
var command = JSON.parse(message.replace(/^COMMAND /, ''));
var command = JSON.parse(message.replace(/^COMMAND /, ""));
if (command.name == "trigger-incoming-message") {
var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
mm.sendAsyncMessage('trigger-incoming-message', {"data": command.data});
mm.sendAsyncMessage("trigger-incoming-message", {"data": command.data});
} else {
gScript.sendAsyncMessage(command.name, command.data);
}
} else if (/^DONE$/.exec(message)) {
ok(true, "Messaging from iframe complete.");
receiverIframe.removeEventListener('mozbrowsershowmodalprompt', receiverListener);
receiverIframe.removeEventListener("mozbrowsershowmodalprompt", receiverListener);
isReceiverFinished = true;
@ -78,16 +78,16 @@ function setup() {
aResolve(receiverIframe);
});
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
// Create a non-receiver OOP iframe.
var nonReceiverIframe = document.createElement('iframe');
nonReceiverIframe.setAttribute('remote', 'true');
nonReceiverIframe.setAttribute('mozbrowser', 'true');
nonReceiverIframe.setAttribute('src', nonReceiverUrl);
var nonReceiverIframe = document.createElement("iframe");
nonReceiverIframe.setAttribute("remote", "true");
nonReceiverIframe.setAttribute("mozbrowser", "true");
nonReceiverIframe.setAttribute("src", nonReceiverUrl);
// This event is triggered when the iframe calls "alert".
nonReceiverIframe.addEventListener('mozbrowsershowmodalprompt', function nonReceiverListener(aEvent) {
nonReceiverIframe.addEventListener("mozbrowsershowmodalprompt", function nonReceiverListener(aEvent) {
var message = aEvent.detail.message;
if (/^OK /.exec(message)) {
ok(true, "Message from iframe: " + message);
@ -96,11 +96,11 @@ function setup() {
} else if (/^INFO /.exec(message)) {
info("Message from iframe: " + message);
} else if (/^COMMAND /.exec(message)) {
var command = JSON.parse(message.replace(/^COMMAND /, ''));
var command = JSON.parse(message.replace(/^COMMAND /, ""));
gScript.sendAsyncMessage(command.name, command.data);
} else if (/^DONE$/.exec(message)) {
ok(true, "Messaging from iframe complete.");
nonReceiverIframe.removeEventListener('mozbrowsershowmodalprompt', nonReceiverListener);
nonReceiverIframe.removeEventListener("mozbrowsershowmodalprompt", nonReceiverListener);
isNonReceiverFinished = true;
@ -112,34 +112,34 @@ function setup() {
document.body.appendChild(nonReceiverIframe);
gScript.addMessageListener('offer-received', function offerReceivedHandler() {
gScript.removeMessageListener('offer-received', offerReceivedHandler);
gScript.addMessageListener("offer-received", function offerReceivedHandler() {
gScript.removeMessageListener("offer-received", offerReceivedHandler);
info("An offer is received.");
});
gScript.addMessageListener('answer-sent', function answerSentHandler(aIsValid) {
gScript.removeMessageListener('answer-sent', answerSentHandler);
gScript.addMessageListener("answer-sent", function answerSentHandler(aIsValid) {
gScript.removeMessageListener("answer-sent", answerSentHandler);
ok(aIsValid, "A valid answer is sent.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
});
var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
mm.addMessageListener('check-navigator', function checknavigatorHandler(aSuccess) {
mm.removeMessageListener('check-navigator', checknavigatorHandler);
mm.addMessageListener("check-navigator", function checknavigatorHandler(aSuccess) {
mm.removeMessageListener("check-navigator", checknavigatorHandler);
ok(SpecialPowers.wrap(aSuccess).data.data, "buildDataChannel get correct window object");
});
mm.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
mm.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
mm.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
mm.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
mm.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
mm.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
mm.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
mm.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
is(SpecialPowers.wrap(aReason).data.data, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
});
@ -149,14 +149,14 @@ function setup() {
function testIncomingSessionRequest() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
info("Trying to launch receiver page.");
aResolve();
});
gScript.sendAsyncMessage('trigger-incoming-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-incoming-session-request", receiverUrl);
});
}
@ -164,18 +164,18 @@ var mmTeardownComplete = false;
var gScriptTeardownComplete = false;
function teardown() {
var mm = SpecialPowers.getBrowserFrameMessageManager(receiverIframe);
mm.addMessageListener('teardown-complete', function teardownCompleteHandler() {
mm.removeMessageListener('teardown-complete', teardownCompleteHandler);
mm.addMessageListener("teardown-complete", function teardownCompleteHandler() {
mm.removeMessageListener("teardown-complete", teardownCompleteHandler);
mmTeardownComplete = true;
if (gScriptTeardownComplete) {
SimpleTest.finish();
}
});
mm.sendAsyncMessage('teardown');
mm.sendAsyncMessage("teardown");
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
gScriptTeardownComplete = true;
if (mmTeardownComplete) {
@ -183,7 +183,7 @@ function teardown() {
}
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -193,10 +193,10 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: 'browser', allow: true, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", false],
["dom.presentation.receiver.enabled", true],
["dom.presentation.session_transport.data_channel.enable", true],

View file

@ -13,9 +13,9 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1148307">Test for B2G Presentation API at sender side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var frameScript = SpecialPowers.isMainProcess() ? gScript : contentScript;
var request;
var connection;
@ -31,9 +31,9 @@ function testSetup() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
},
function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
@ -46,51 +46,51 @@ function testSetup() {
function testStartConnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
});
frameScript.addMessageListener('check-navigator', function checknavigatorHandler(aSuccess) {
frameScript.removeMessageListener('check-navigator', checknavigatorHandler);
frameScript.addMessageListener("check-navigator", function checknavigatorHandler(aSuccess) {
frameScript.removeMessageListener("check-navigator", checknavigatorHandler);
ok(aSuccess, "buildDataChannel get correct window object");
});
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.removeMessageListener('answer-received', answerReceivedHandler);
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
gScript.removeMessageListener("answer-received", answerReceivedHandler);
info("An answer is received.");
});
frameScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
frameScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
frameScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
frameScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
});
frameScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
frameScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
frameScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
frameScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
@ -134,8 +134,8 @@ function testSend() {
return new Promise(function(aResolve, aReject) {
const outgoingMessage = "test outgoing message";
frameScript.addMessageListener('message-sent', function messageSentHandler(aMessage) {
frameScript.removeMessageListener('message-sent', messageSentHandler);
frameScript.addMessageListener("message-sent", function messageSentHandler(aMessage) {
frameScript.removeMessageListener("message-sent", messageSentHandler);
is(aMessage, outgoingMessage, "The message is sent out.");
aResolve();
});
@ -148,19 +148,19 @@ function testIncomingMessage() {
return new Promise(function(aResolve, aReject) {
const incomingMessage = "test incoming message";
connection.addEventListener('message', function(aEvent) {
connection.addEventListener("message", function(aEvent) {
is(aEvent.data, incomingMessage, "An incoming message should be received.");
aResolve();
}, {once: true});
frameScript.sendAsyncMessage('trigger-incoming-message', incomingMessage);
frameScript.sendAsyncMessage("trigger-incoming-message", incomingMessage);
});
}
function testCloseConnection() {
return new Promise(function(aResolve, aReject) {
frameScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
frameScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
frameScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
frameScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
});
@ -176,31 +176,31 @@ function testCloseConnection() {
function testReconnect() {
return new Promise(function(aResolve, aReject) {
info('--- testReconnect ---');
gScript.addMessageListener('control-channel-established', function controlChannelEstablished() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablished);
info("--- testReconnect ---");
gScript.addMessageListener("control-channel-established", function controlChannelEstablished() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablished);
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('start-reconnect', function startReconnectHandler(url) {
gScript.removeMessageListener('start-reconnect', startReconnectHandler);
is(url, "http://example.com/", "URLs should be the same.")
gScript.sendAsyncMessage('trigger-reconnected-acked', url);
gScript.addMessageListener("start-reconnect", function startReconnectHandler(url) {
gScript.removeMessageListener("start-reconnect", startReconnectHandler);
is(url, "http://example.com/", "URLs should be the same.");
gScript.sendAsyncMessage("trigger-reconnected-acked", url);
});
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.removeMessageListener('answer-received', answerReceivedHandler);
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
gScript.removeMessageListener("answer-received", answerReceivedHandler);
info("An answer is received.");
});
frameScript.addMessageListener('check-navigator', function checknavigatorHandler(aSuccess) {
frameScript.removeMessageListener('check-navigator', checknavigatorHandler);
frameScript.addMessageListener("check-navigator", function checknavigatorHandler(aSuccess) {
frameScript.removeMessageListener("check-navigator", checknavigatorHandler);
ok(aSuccess, "buildDataChannel get correct window object");
});
@ -227,14 +227,14 @@ function testReconnect() {
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
info('teardown-complete');
info("teardown-complete");
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function testConstructRequestError() {
@ -252,8 +252,7 @@ function testConstructRequestError() {
new Promise(function(aResolve, aReject) {
try {
request = new PresentationRequest([]);
}
catch(e) {
} catch (e) {
is(e.name, "NotSupportedError", "Expect to get NotSupportedError.");
aResolve();
}
@ -277,9 +276,9 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.session_transport.data_channel.enable", true]]},
runTests);

View file

@ -4,8 +4,8 @@
<script>
/* global SimpleTest SpecialPowers */
const gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript1UA.js'));
const kReceiverFile = 'file_presentation_fingerprinting_resistance_receiver.html';
const gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript1UA.js"));
const kReceiverFile = "file_presentation_fingerprinting_resistance_receiver.html";
const kReceiverUrl = SimpleTest.getTestFileURL(kReceiverFile);
let runTests = async () => {
@ -21,60 +21,60 @@ let runTests = async () => {
let setup = async () => {
await SpecialPowers.pushPrefEnv({
set: [
['dom.presentation.enabled', true],
['dom.presentation.controller.enabled', true],
['dom.presentation.receiver.enabled', true],
['dom.presentation.test.enabled', true],
['dom.presentation.test.stage', 0],
['dom.mozBrowserFramesEnabled', true],
['network.disable.ipc.security', true]
["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.receiver.enabled", true],
["dom.presentation.test.enabled", true],
["dom.presentation.test.stage", 0],
["dom.mozBrowserFramesEnabled", true],
["network.disable.ipc.security", true]
]
});
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('promise-setup-ready', function promiseSetupReadyHandler() {
gScript.removeMessageListener('promise-setup-ready', promiseSetupReadyHandler);
gScript.sendAsyncMessage('trigger-on-session-request', kReceiverUrl);
gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
gScript.removeMessageListener("promise-setup-ready", promiseSetupReadyHandler);
gScript.sendAsyncMessage("trigger-on-session-request", kReceiverUrl);
});
};
let createRequest = () => new Promise((resolve, reject) => {
let request = new PresentationRequest(kReceiverFile);
request.getAvailability().then((availability) => {
SimpleTest.ok(availability, 'PresentationRequest.getAvailability');
SimpleTest.ok(availability, "PresentationRequest.getAvailability");
availability.onchange = () => {
availability.onchange = null;
resolve(request);
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
}).catch((error) => {
SimpleTest.ok(false, 'PresentationRequest.getAvailability: ' + error);
SimpleTest.ok(false, "PresentationRequest.getAvailability: " + error);
teardown();
reject(error);
});
});
let testRequestAndReceiver = (request) => new Promise((resolve, reject) => {
gScript.addMessageListener('sender-launch', function senderLaunchHandler(url) {
gScript.addMessageListener("sender-launch", function senderLaunchHandler(url) {
// SimpleTest.is(url, kReceiverUrl, 'sender-launch');
gScript.removeMessageListener('sender-launch', senderLaunchHandler);
gScript.removeMessageListener("sender-launch", senderLaunchHandler);
let iframe = document.createElement('iframe');
iframe.setAttribute('src', kReceiverUrl);
iframe.setAttribute('mozbrowser', 'true');
iframe.setAttribute('mozpresentation', kReceiverUrl);
iframe.setAttribute('remote', 'false');
iframe.addEventListener('mozbrowsershowmodalprompt', (event) => {
SimpleTest.is(event.detail.message, 'true', 'navigator.presentation.receiver');
let iframe = document.createElement("iframe");
iframe.setAttribute("src", kReceiverUrl);
iframe.setAttribute("mozbrowser", "true");
iframe.setAttribute("mozpresentation", kReceiverUrl);
iframe.setAttribute("remote", "false");
iframe.addEventListener("mozbrowsershowmodalprompt", (event) => {
SimpleTest.is(event.detail.message, "true", "navigator.presentation.receiver");
resolve(iframe);
}, {once: true});
@ -84,21 +84,21 @@ let testRequestAndReceiver = (request) => new Promise((resolve, reject) => {
});
let obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"].getService(SpecialPowers.Ci.nsIObserverService);
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
});
request.start().then((connection) => {
SimpleTest.ok(connection, 'PresentationRequest.start');
SimpleTest.ok(connection, "PresentationRequest.start");
}).catch((error) => {
SimpleTest.ok(false, 'PresentationRequest.start: ' + error);
SimpleTest.ok(false, "PresentationRequest.start: " + error);
teardown();
reject(error);
});
});
let enableResistFingerprinting = () => {
const kPref = 'privacy.resistFingerprinting';
SimpleTest.info(kPref + ' = true');
const kPref = "privacy.resistFingerprinting";
SimpleTest.info(kPref + " = true");
return SpecialPowers.pushPrefEnv({
set: [
[kPref, true]
@ -108,38 +108,38 @@ let enableResistFingerprinting = () => {
let testRequestResistFingerprinting = (request) => {
return request.getAvailability()
.then(() => SimpleTest.ok(false, 'PresentationRequest.getAvailability'))
.catch((error) => SimpleTest.is(error.name, 'SecurityError', 'PresentationRequest.getAvailability'))
.then(() => SimpleTest.ok(false, "PresentationRequest.getAvailability"))
.catch((error) => SimpleTest.is(error.name, "SecurityError", "PresentationRequest.getAvailability"))
.then(() => request.start())
.then(() => SimpleTest.ok(false, 'PresentationRequest.start'))
.catch((error) => SimpleTest.is(error.name, 'SecurityError', 'PresentationRequest.start'))
.then(() => SimpleTest.ok(false, "PresentationRequest.start"))
.catch((error) => SimpleTest.is(error.name, "SecurityError", "PresentationRequest.start"))
.then(() => request.reconnect(kReceiverUrl))
.then(() => SimpleTest.ok(false, 'PresentationRequest.reconnect'))
.catch((error) => SimpleTest.is(error.name, 'SecurityError', 'PresentationRequest.reconnect'));
.then(() => SimpleTest.ok(false, "PresentationRequest.reconnect"))
.catch((error) => SimpleTest.is(error.name, "SecurityError", "PresentationRequest.reconnect"));
};
let testReceiverResistFingerprinting = (iframe) => new Promise((resolve) => {
iframe.addEventListener('mozbrowsershowmodalprompt', (event) => {
SimpleTest.is(event.detail.message, 'false', 'navigator.presentation.receiver');
iframe.addEventListener("mozbrowsershowmodalprompt", (event) => {
SimpleTest.is(event.detail.message, "false", "navigator.presentation.receiver");
resolve();
}, {once: true});
iframe.setAttribute('src', kReceiverUrl + '#privacy.resistFingerprinting');
iframe.setAttribute("src", kReceiverUrl + "#privacy.resistFingerprinting");
});
let teardown = () => {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
};
SimpleTest.waitForExplicitFinish();
document.addEventListener('DOMContentLoaded', () => {
document.addEventListener("DOMContentLoaded", () => {
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: 'browser', allow: true, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], runTests);
});
</script>

View file

@ -42,7 +42,7 @@ function setup() {
startTest();
}
} else if (/^DONE$/.exec(message)) {
window.removeEventListener('message', listener);
window.removeEventListener("message", listener);
SimpleTest.finish();
}
}, false);

View file

@ -13,7 +13,7 @@ function setup() {
var iframe = document.createElement("iframe");
iframe.setAttribute("mozbrowser", "true");
iframe.setAttribute("mozpresentation", receiverUrl);
var oop = !location.pathname.includes('_inproc');
var oop = !location.pathname.includes("_inproc");
iframe.setAttribute("remote", oop);
iframe.setAttribute("src", receiverUrl);

View file

@ -14,10 +14,10 @@
<iframe id="iframe" src="file_presentation_reconnect.html"></iframe>
<script type="application/javascript">
'use strict';
"use strict";
var iframe = document.getElementById("iframe");
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var frameScript = SpecialPowers.isMainProcess() ? gScript : contentScript;
var request;
var connection;
@ -39,7 +39,7 @@ function testSetup() {
commandHandler[command.name](command);
}
} else if (/^DONE$/.exec(message)) {
window.removeEventListener('message', listener);
window.removeEventListener("message", listener);
SimpleTest.finish();
}
}, false);
@ -53,9 +53,9 @@ function testSetup() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
},
function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
@ -68,42 +68,42 @@ function testSetup() {
function testStartConnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler(aReason) {
info("The control channel is opened.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
info("The control channel is closed. " + aReason);
});
frameScript.addMessageListener('check-navigator', function checknavigatorHandler(aSuccess) {
frameScript.addMessageListener("check-navigator", function checknavigatorHandler(aSuccess) {
ok(aSuccess, "buildDataChannel get correct window object");
});
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
info("An answer is received.");
});
frameScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
frameScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
info("Data transport channel is initialized.");
});
frameScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
frameScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
info("Data notification is enabled for data transport channel.");
});
@ -145,8 +145,8 @@ function testStartConnection() {
function testCloseConnection() {
return new Promise(function(aResolve, aReject) {
frameScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
frameScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
frameScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
frameScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
});
@ -162,7 +162,7 @@ function testCloseConnection() {
function testReconnectAConnectedConnection() {
return new Promise(function(aResolve, aReject) {
info('--- testReconnectAConnectedConnection ---');
info("--- testReconnectAConnectedConnection ---");
ok(connection.state, "connected", "Make sure the state is connected.");
request.reconnect(connection.id).then(
@ -185,7 +185,7 @@ function testReconnectAConnectedConnection() {
function testReconnectInvalidID() {
return new Promise(function(aResolve, aReject) {
info('--- testReconnectInvalidID ---');
info("--- testReconnectInvalidID ---");
request.reconnect("dummyID").then(
function(aConnection) {
@ -203,7 +203,7 @@ function testReconnectInvalidID() {
function testReconnectInvalidURL() {
return new Promise(function(aResolve, aReject) {
info('--- testReconnectInvalidURL ---');
info("--- testReconnectInvalidURL ---");
var request1 = new PresentationRequest("http://invalidURL");
request1.reconnect(connection.id).then(
@ -221,14 +221,14 @@ function testReconnectInvalidURL() {
}
function testReconnectIframeConnectedConnection() {
info('--- testReconnectIframeConnectedConnection ---');
gScript.sendAsyncMessage('save-control-channel-listener');
info("--- testReconnectIframeConnectedConnection ---");
gScript.sendAsyncMessage("save-control-channel-listener");
return Promise.all([
new Promise(function(aResolve, aReject) {
commandHandler["connection-connected"] = function(command) {
gScript.addMessageListener('start-reconnect', function startReconnectHandler(url) {
gScript.removeMessageListener('start-reconnect', startReconnectHandler);
gScript.sendAsyncMessage('trigger-reconnected-acked', url);
gScript.addMessageListener("start-reconnect", function startReconnectHandler(url) {
gScript.removeMessageListener("start-reconnect", startReconnectHandler);
gScript.sendAsyncMessage("trigger-reconnected-acked", url);
});
var request1 = new PresentationRequest("http://example1.com");
@ -237,7 +237,7 @@ function testReconnectIframeConnectedConnection() {
is(aConnection.state, "connecting", "The state should be connecting.");
aConnection.onclose = function() {
delete commandHandler["connection-connected"];
gScript.sendAsyncMessage('restore-control-channel-listener');
gScript.sendAsyncMessage("restore-control-channel-listener");
aResolve();
};
aConnection.close();
@ -262,12 +262,12 @@ function testReconnectIframeConnectedConnection() {
function testReconnectIframeClosedConnection() {
return new Promise(function(aResolve, aReject) {
info('--- testReconnectIframeClosedConnection ---');
gScript.sendAsyncMessage('save-control-channel-listener');
info("--- testReconnectIframeClosedConnection ---");
gScript.sendAsyncMessage("save-control-channel-listener");
commandHandler["connection-closed"] = function(command) {
gScript.addMessageListener('start-reconnect', function startReconnectHandler(url) {
gScript.removeMessageListener('start-reconnect', startReconnectHandler);
gScript.sendAsyncMessage('trigger-reconnected-acked', url);
gScript.addMessageListener("start-reconnect", function startReconnectHandler(url) {
gScript.removeMessageListener("start-reconnect", startReconnectHandler);
gScript.sendAsyncMessage("trigger-reconnected-acked", url);
});
var request1 = new PresentationRequest("http://example1.com");
@ -283,7 +283,7 @@ function testReconnectIframeClosedConnection() {
aResolve();
};
aConnection.close();
gScript.sendAsyncMessage('restore-control-channel-listener');
gScript.sendAsyncMessage("restore-control-channel-listener");
};
},
function(aError) {
@ -299,11 +299,11 @@ function testReconnectIframeClosedConnection() {
function testReconnect() {
return new Promise(function(aResolve, aReject) {
info('--- testReconnect ---');
gScript.addMessageListener('start-reconnect', function startReconnectHandler(url) {
gScript.removeMessageListener('start-reconnect', startReconnectHandler);
info("--- testReconnect ---");
gScript.addMessageListener("start-reconnect", function startReconnectHandler(url) {
gScript.removeMessageListener("start-reconnect", startReconnectHandler);
is(url, "http://example.com/", "URLs should be the same.");
gScript.sendAsyncMessage('trigger-reconnected-acked', url);
gScript.sendAsyncMessage("trigger-reconnected-acked", url);
});
request.reconnect(connection.id).then(
@ -318,12 +318,12 @@ function testReconnect() {
is(aConnection.state, "connected", "Connection should be connected.");
const incomingMessage = "test incoming message";
aConnection.addEventListener('message', function(aEvent) {
aConnection.addEventListener("message", function(aEvent) {
is(aEvent.data, incomingMessage, "An incoming message should be received.");
aResolve();
}, {once: true});
frameScript.sendAsyncMessage('trigger-incoming-message', incomingMessage);
frameScript.sendAsyncMessage("trigger-incoming-message", incomingMessage);
};
},
function(aError) {
@ -336,14 +336,14 @@ function testReconnect() {
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
info('teardown-complete');
info("teardown-complete");
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -364,9 +364,9 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.receiver.enabled", true],
["dom.presentation.session_transport.data_channel.enable", true]]},

View file

@ -35,7 +35,7 @@ function setup() {
startTest();
}
} else if (/^DONE$/.exec(message)) {
window.removeEventListener('message', listener);
window.removeEventListener("message", listener);
SimpleTest.finish();
}
}, false);

View file

@ -12,9 +12,9 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1276378">Test onTerminateRequest at sender side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var request;
var connection;
@ -29,9 +29,9 @@ function testSetup() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
},
function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
@ -44,47 +44,47 @@ function testSetup() {
function testStartConnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
});
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.sendAsyncMessage("trigger-incoming-transport");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.removeMessageListener('answer-received', answerReceivedHandler);
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
gScript.removeMessageListener("answer-received", answerReceivedHandler);
info("An answer is received.");
});
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
@ -126,18 +126,18 @@ function testStartConnection() {
function testOnTerminateRequest() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
});
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
});
@ -147,19 +147,19 @@ function testOnTerminateRequest() {
aResolve();
};
gScript.sendAsyncMessage('trigger-incoming-terminate-request');
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-incoming-terminate-request");
gScript.sendAsyncMessage("trigger-control-channel-open");
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -173,9 +173,9 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.receiver.enabled", false],
["dom.presentation.session_transport.data_channel.enable", false]]},

View file

@ -12,9 +12,9 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1239242">Test startWithDevice for B2G Presentation API at sender side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var request;
var connection;
@ -29,9 +29,9 @@ function testSetup() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
},
function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
@ -44,48 +44,48 @@ function testSetup() {
function testStartConnectionWithDevice() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
ok(false, "Device prompt should not be triggered.");
teardown();
aReject();
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
});
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.sendAsyncMessage("trigger-incoming-transport");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.removeMessageListener('answer-received', answerReceivedHandler);
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
gScript.removeMessageListener("answer-received", answerReceivedHandler);
info("An answer is received.");
});
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
@ -100,7 +100,7 @@ function testStartConnectionWithDevice() {
}
};
request.startWithDevice('id').then(
request.startWithDevice("id").then(
function(aConnection) {
connection = aConnection;
ok(connection, "Connection should be available.");
@ -127,14 +127,14 @@ function testStartConnectionWithDevice() {
function testStartConnectionWithDeviceNotFoundError() {
return new Promise(function(aResolve, aReject) {
request.startWithDevice('').then(
request.startWithDevice("").then(
function(aConnection) {
ok(false, "Should not establish connection to an unknown device");
teardown();
aReject();
},
function(aError) {
is(aError.name, 'NotFoundError', "Expect NotFoundError occurred when establishing a connection");
is(aError.name, "NotFoundError", "Expect NotFoundError occurred when establishing a connection");
aResolve();
}
);
@ -142,13 +142,13 @@ function testStartConnectionWithDeviceNotFoundError() {
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -161,7 +161,7 @@ function runTests() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.session_transport.data_channel.enable", false],
["dom.presentation.controller.enabled", true],
["dom.presentation.test.enabled", true],

View file

@ -15,25 +15,25 @@
<pre id="test"></pre>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_receiver.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver.html");
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
function setup() {
return new Promise(function(aResolve, aReject) {
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
var iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', 'true');
iframe.setAttribute('mozpresentation', receiverUrl);
iframe.setAttribute('src', receiverUrl);
var iframe = document.createElement("iframe");
iframe.setAttribute("mozbrowser", "true");
iframe.setAttribute("mozpresentation", receiverUrl);
iframe.setAttribute("src", receiverUrl);
// This event is triggered when the iframe calls "postMessage".
iframe.addEventListener('mozbrowsershowmodalprompt', function listener(aEvent) {
iframe.addEventListener("mozbrowsershowmodalprompt", function listener(aEvent) {
var message = aEvent.detail.message;
if (/^OK /.exec(message)) {
ok(true, "Message from iframe: " + message);
@ -42,11 +42,11 @@ function setup() {
} else if (/^INFO /.exec(message)) {
info("Message from iframe: " + message);
} else if (/^COMMAND /.exec(message)) {
var command = JSON.parse(message.replace(/^COMMAND /, ''));
var command = JSON.parse(message.replace(/^COMMAND /, ""));
gScript.sendAsyncMessage(command.name, command.data);
} else if (/^DONE$/.exec(message)) {
ok(true, "Messaging from iframe complete.");
iframe.removeEventListener('mozbrowsershowmodalprompt', listener);
iframe.removeEventListener("mozbrowsershowmodalprompt", listener);
teardown();
}
@ -57,30 +57,30 @@ function setup() {
aResolve(iframe);
});
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
gScript.addMessageListener('offer-received', function offerReceivedHandler() {
gScript.removeMessageListener('offer-received', offerReceivedHandler);
gScript.addMessageListener("offer-received", function offerReceivedHandler() {
gScript.removeMessageListener("offer-received", offerReceivedHandler);
info("An offer is received.");
});
gScript.addMessageListener('answer-sent', function answerSentHandler(aIsValid) {
gScript.removeMessageListener('answer-sent', answerSentHandler);
gScript.addMessageListener("answer-sent", function answerSentHandler(aIsValid) {
gScript.removeMessageListener("answer-sent", answerSentHandler);
ok(aIsValid, "A valid answer is sent.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
});
gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
is(aReason, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
});
@ -90,8 +90,8 @@ function setup() {
function testIncomingSessionRequest() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
info("Trying to launch receiver page.");
ok(navigator.presentation, "navigator.presentation should be available in in-process pages.");
@ -99,18 +99,18 @@ function testIncomingSessionRequest() {
aResolve();
});
gScript.sendAsyncMessage('trigger-incoming-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-incoming-session-request", receiverUrl);
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -120,10 +120,10 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: 'browser', allow: true, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", false],
["dom.presentation.receiver.enabled", true],
["dom.mozBrowserFramesEnabled", true],

View file

@ -12,20 +12,20 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for connection establishing errors of B2G Presentation API at receiver side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_receiver_establish_connection_error.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver_establish_connection_error.html");
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
function setup() {
return new Promise(function(aResolve, aReject) {
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
var iframe = document.createElement('iframe');
iframe.setAttribute('src', receiverUrl);
var iframe = document.createElement("iframe");
iframe.setAttribute("src", receiverUrl);
iframe.setAttribute("mozbrowser", "true");
iframe.setAttribute("mozpresentation", receiverUrl);
@ -53,10 +53,10 @@ function setup() {
aResolve(iframe);
});
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
is(aReason, 0x80004004 /* NS_ERROR_ABORT */, "The control channel is closed abnormally.");
});
@ -66,25 +66,25 @@ function setup() {
function testIncomingSessionRequest() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
info("Trying to launch receiver page.");
aResolve();
});
gScript.sendAsyncMessage('trigger-incoming-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-incoming-session-request", receiverUrl);
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -94,10 +94,10 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.receiver.enabled", true],
["dom.presentation.session_transport.data_channel.enable", false],
["dom.mozBrowserFramesEnabled", true],

View file

@ -12,21 +12,21 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for connection establishing timeout of B2G Presentation API at receiver side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
function setup() {
return new Promise(function(aResolve, aReject) {
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
var promise = new Promise(function(aResolve, aReject) {
// In order to trigger timeout, do not resolve the promise.
});
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
aResolve();
});
@ -34,29 +34,29 @@ function setup() {
function testIncomingSessionRequestReceiverLaunchTimeout() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
info("Trying to launch receiver page.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
is(aReason, 0x80530017 /* NS_ERROR_DOM_TIMEOUT_ERR */, "The control channel is closed due to timeout.");
aResolve();
});
gScript.sendAsyncMessage('trigger-incoming-session-request', 'http://example.com');
gScript.sendAsyncMessage("trigger-incoming-session-request", "http://example.com");
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -67,9 +67,9 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.receiver.enabled", true],
["dom.presentation.session_transport.data_channel.enable", false],
["presentation.receiver.loading.timeout", 10]]},

View file

@ -1,22 +1,22 @@
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_unknown_content_type.test');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_unknown_content_type.test");
var obs = SpecialPowers.Cc['@mozilla.org/observer-service;1']
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
var receiverIframe;
function setup() {
return new Promise(function(aResolve, aReject) {
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
receiverIframe = document.createElement('iframe');
receiverIframe.setAttribute('mozbrowser', 'true');
receiverIframe.setAttribute('mozpresentation', receiverUrl);
receiverIframe.setAttribute('src', receiverUrl);
var oop = !location.pathname.includes('_inproc');
receiverIframe = document.createElement("iframe");
receiverIframe.setAttribute("mozbrowser", "true");
receiverIframe.setAttribute("mozpresentation", receiverUrl);
receiverIframe.setAttribute("src", receiverUrl);
var oop = !location.pathname.includes("_inproc");
receiverIframe.setAttribute("remote", oop);
var promise = new Promise(function(aResolve, aReject) {
@ -24,7 +24,7 @@ function setup() {
aResolve(receiverIframe);
});
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
aResolve();
});
@ -33,37 +33,37 @@ function setup() {
function testIncomingSessionRequestReceiverLaunchUnknownContentType() {
let promise = Promise.all([
new Promise(function(aResolve, aReject) {
gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
info('Trying to launch receiver page.');
gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
info("Trying to launch receiver page.");
receiverIframe.addEventListener('mozbrowserclose', function() {
ok(true, 'observe receiver window closed');
receiverIframe.addEventListener("mozbrowserclose", function() {
ok(true, "observe receiver window closed");
aResolve();
});
});
}),
new Promise(function(aResolve, aReject) {
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
is(aReason, 0x80530020 /* NS_ERROR_DOM_OPERATION_ERR */, 'The control channel is closed due to load failure.');
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
is(aReason, 0x80530020 /* NS_ERROR_DOM_OPERATION_ERR */, "The control channel is closed due to load failure.");
aResolve();
});
})
]);
gScript.sendAsyncMessage('trigger-incoming-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-incoming-session-request", receiverUrl);
return promise;
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -74,15 +74,15 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: 'browser', allow: true, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [['dom.presentation.enabled', true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.receiver.enabled", true],
['dom.presentation.session_transport.data_channel.enable', false],
['dom.mozBrowserFramesEnabled', true],
["dom.presentation.session_transport.data_channel.enable", false],
["dom.mozBrowserFramesEnabled", true],
["network.disable.ipc.security", true],
['dom.ipc.tabs.disabled', false]]},
["dom.ipc.tabs.disabled", false]]},
runTests);
});

View file

@ -15,11 +15,11 @@
<pre id="test"></pre>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_receiver.html');
var nonReceiverUrl = SimpleTest.getTestFileURL('file_presentation_non_receiver.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_receiver.html");
var nonReceiverUrl = SimpleTest.getTestFileURL("file_presentation_non_receiver.html");
var isReceiverFinished = false;
var isNonReceiverFinished = false;
@ -29,17 +29,17 @@ var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
function setup() {
return new Promise(function(aResolve, aReject) {
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
// Create a receiver OOP iframe.
var receiverIframe = document.createElement('iframe');
receiverIframe.setAttribute('remote', 'true');
receiverIframe.setAttribute('mozbrowser', 'true');
receiverIframe.setAttribute('mozpresentation', receiverUrl);
receiverIframe.setAttribute('src', receiverUrl);
var receiverIframe = document.createElement("iframe");
receiverIframe.setAttribute("remote", "true");
receiverIframe.setAttribute("mozbrowser", "true");
receiverIframe.setAttribute("mozpresentation", receiverUrl);
receiverIframe.setAttribute("src", receiverUrl);
// This event is triggered when the iframe calls "alert".
receiverIframe.addEventListener('mozbrowsershowmodalprompt', function receiverListener(aEvent) {
receiverIframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(aEvent) {
var message = aEvent.detail.message;
if (/^OK /.exec(message)) {
ok(true, "Message from iframe: " + message);
@ -48,11 +48,11 @@ function setup() {
} else if (/^INFO /.exec(message)) {
info("Message from iframe: " + message);
} else if (/^COMMAND /.exec(message)) {
var command = JSON.parse(message.replace(/^COMMAND /, ''));
var command = JSON.parse(message.replace(/^COMMAND /, ""));
gScript.sendAsyncMessage(command.name, command.data);
} else if (/^DONE$/.exec(message)) {
ok(true, "Messaging from iframe complete.");
receiverIframe.removeEventListener('mozbrowsershowmodalprompt', receiverListener);
receiverIframe.removeEventListener("mozbrowsershowmodalprompt", receiverListener);
isReceiverFinished = true;
@ -67,16 +67,16 @@ function setup() {
aResolve(receiverIframe);
});
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
// Create a non-receiver OOP iframe.
var nonReceiverIframe = document.createElement('iframe');
nonReceiverIframe.setAttribute('remote', 'true');
nonReceiverIframe.setAttribute('mozbrowser', 'true');
nonReceiverIframe.setAttribute('src', nonReceiverUrl);
var nonReceiverIframe = document.createElement("iframe");
nonReceiverIframe.setAttribute("remote", "true");
nonReceiverIframe.setAttribute("mozbrowser", "true");
nonReceiverIframe.setAttribute("src", nonReceiverUrl);
// This event is triggered when the iframe calls "alert".
nonReceiverIframe.addEventListener('mozbrowsershowmodalprompt', function nonReceiverListener(aEvent) {
nonReceiverIframe.addEventListener("mozbrowsershowmodalprompt", function nonReceiverListener(aEvent) {
var message = aEvent.detail.message;
if (/^OK /.exec(message)) {
ok(true, "Message from iframe: " + message);
@ -85,11 +85,11 @@ function setup() {
} else if (/^INFO /.exec(message)) {
info("Message from iframe: " + message);
} else if (/^COMMAND /.exec(message)) {
var command = JSON.parse(message.replace(/^COMMAND /, ''));
var command = JSON.parse(message.replace(/^COMMAND /, ""));
gScript.sendAsyncMessage(command.name, command.data);
} else if (/^DONE$/.exec(message)) {
ok(true, "Messaging from iframe complete.");
nonReceiverIframe.removeEventListener('mozbrowsershowmodalprompt', nonReceiverListener);
nonReceiverIframe.removeEventListener("mozbrowsershowmodalprompt", nonReceiverListener);
isNonReceiverFinished = true;
@ -101,28 +101,28 @@ function setup() {
document.body.appendChild(nonReceiverIframe);
gScript.addMessageListener('offer-received', function offerReceivedHandler() {
gScript.removeMessageListener('offer-received', offerReceivedHandler);
gScript.addMessageListener("offer-received", function offerReceivedHandler() {
gScript.removeMessageListener("offer-received", offerReceivedHandler);
info("An offer is received.");
});
gScript.addMessageListener('answer-sent', function answerSentHandler(aIsValid) {
gScript.removeMessageListener('answer-sent', answerSentHandler);
gScript.addMessageListener("answer-sent", function answerSentHandler(aIsValid) {
gScript.removeMessageListener("answer-sent", answerSentHandler);
ok(aIsValid, "A valid answer is sent.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed normally.");
});
gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
is(aReason, SpecialPowers.Cr.NS_OK, "The data transport should be closed normally.");
});
@ -132,25 +132,25 @@ function setup() {
function testIncomingSessionRequest() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
gScript.addMessageListener("receiver-launching", function launchReceiverHandler(aSessionId) {
gScript.removeMessageListener("receiver-launching", launchReceiverHandler);
info("Trying to launch receiver page.");
aResolve();
});
gScript.sendAsyncMessage('trigger-incoming-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-incoming-session-request", receiverUrl);
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -160,10 +160,10 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: 'browser', allow: true, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", false],
["dom.presentation.receiver.enabled", true],
["dom.presentation.session_transport.data_channel.enable", false],

View file

@ -12,9 +12,9 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for B2G Presentation API at sender side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var request;
var connection;
@ -29,8 +29,8 @@ function testSetup() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
aResolve();
}
gScript.sendAsyncMessage('trigger-device-add');
};
gScript.sendAsyncMessage("trigger-device-add");
},
function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
@ -44,47 +44,47 @@ function testSetup() {
function testStartConnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
});
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.sendAsyncMessage("trigger-incoming-transport");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.removeMessageListener('answer-received', answerReceivedHandler);
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
gScript.removeMessageListener("answer-received", answerReceivedHandler);
info("An answer is received.");
});
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
@ -128,8 +128,8 @@ function testSend() {
return new Promise(function(aResolve, aReject) {
const outgoingMessage = "test outgoing message";
gScript.addMessageListener('message-sent', function messageSentHandler(aMessage) {
gScript.removeMessageListener('message-sent', messageSentHandler);
gScript.addMessageListener("message-sent", function messageSentHandler(aMessage) {
gScript.removeMessageListener("message-sent", messageSentHandler);
is(aMessage, outgoingMessage, "The message is sent out.");
aResolve();
});
@ -142,19 +142,19 @@ function testIncomingMessage() {
return new Promise(function(aResolve, aReject) {
const incomingMessage = "test incoming message";
connection.addEventListener('message', function(aEvent) {
connection.addEventListener("message", function(aEvent) {
is(aEvent.data, incomingMessage, "An incoming message should be received.");
aResolve();
}, {once: true});
gScript.sendAsyncMessage('trigger-incoming-message', incomingMessage);
gScript.sendAsyncMessage("trigger-incoming-message", incomingMessage);
});
}
function testCloseConnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
});
@ -170,36 +170,36 @@ function testCloseConnection() {
function testReconnect() {
return new Promise(function(aResolve, aReject) {
info('--- testReconnect ---');
gScript.addMessageListener('control-channel-established', function controlChannelEstablished() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablished);
info("--- testReconnect ---");
gScript.addMessageListener("control-channel-established", function controlChannelEstablished() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablished);
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('start-reconnect', function startReconnectHandler(url) {
gScript.removeMessageListener('start-reconnect', startReconnectHandler);
is(url, "https://example.com/", "URLs should be the same.")
gScript.sendAsyncMessage('trigger-reconnected-acked', url);
gScript.addMessageListener("start-reconnect", function startReconnectHandler(url) {
gScript.removeMessageListener("start-reconnect", startReconnectHandler);
is(url, "https://example.com/", "URLs should be the same.");
gScript.sendAsyncMessage("trigger-reconnected-acked", url);
});
gScript.addMessageListener('offer-sent', function offerSentHandler() {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.addMessageListener("offer-sent", function offerSentHandler() {
gScript.removeMessageListener("offer-sent", offerSentHandler);
gScript.sendAsyncMessage("trigger-incoming-transport");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.removeMessageListener('answer-received', answerReceivedHandler);
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
gScript.removeMessageListener("answer-received", answerReceivedHandler);
info("An answer is received.");
});
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
@ -226,13 +226,13 @@ function testReconnect() {
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -249,7 +249,7 @@ function runTests() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.session_transport.data_channel.enable", false]]},
runTests);

View file

@ -12,9 +12,9 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test default request for B2G Presentation API at sender side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var connection;
function testSetup() {
@ -28,9 +28,9 @@ function testSetup() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
},
function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
@ -43,43 +43,43 @@ function testSetup() {
function testStartConnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
});
gScript.addMessageListener('offer-sent', function offerSentHandler() {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler() {
gScript.removeMessageListener("offer-sent", offerSentHandler);
info("An offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.sendAsyncMessage("trigger-incoming-transport");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.removeMessageListener('answer-received', answerReceivedHandler);
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
gScript.removeMessageListener("answer-received", answerReceivedHandler);
info("An answer is received.");
});
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
is(navigator.presentation.receiver, undefined, "Sender shouldn't get a presentation receiver instance.");
@ -104,8 +104,8 @@ function testStartConnection() {
function testCloseConnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
});
@ -120,13 +120,13 @@ function testCloseConnection() {
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -140,7 +140,7 @@ function runTests() {
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.receiver.enabled", false],
["dom.presentation.session_transport.data_channel.enable", false]]},

View file

@ -12,9 +12,9 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for disconnection of B2G Presentation API at sender side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var request;
var connection;
@ -29,9 +29,9 @@ function testSetup() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
},
function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
@ -44,47 +44,47 @@ function testSetup() {
function testStartConnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler(aReason) {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
});
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
});
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-answer');
gScript.sendAsyncMessage("trigger-incoming-answer");
});
gScript.addMessageListener('answer-received', function answerReceivedHandler() {
gScript.removeMessageListener('answer-received', answerReceivedHandler);
gScript.addMessageListener("answer-received", function answerReceivedHandler() {
gScript.removeMessageListener("answer-received", answerReceivedHandler);
info("An answer is received.");
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.sendAsyncMessage("trigger-incoming-transport");
});
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
});
gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
gScript.addMessageListener("data-transport-notification-enabled", function dataTransportNotificationEnabledHandler() {
gScript.removeMessageListener("data-transport-notification-enabled", dataTransportNotificationEnabledHandler);
info("Data notification is enabled for data transport channel.");
});
@ -111,8 +111,8 @@ function testStartConnection() {
function testDisconnection() {
return new Promise(function(aResolve, aReject) {
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
});
@ -122,18 +122,18 @@ function testDisconnection() {
aResolve();
};
gScript.sendAsyncMessage('trigger-data-transport-close', SpecialPowers.Cr.NS_ERROR_FAILURE);
gScript.sendAsyncMessage("trigger-data-transport-close", SpecialPowers.Cr.NS_ERROR_FAILURE);
});
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -147,9 +147,9 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.session_transport.data_channel.enable", false]]},
runTests);

View file

@ -12,9 +12,9 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for connection establishing errors of B2G Presentation API at sender side</a>
<script type="application/javascript">
'use strict';
"use strict";
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript.js"));
var request;
function setup() {
@ -28,9 +28,9 @@ function setup() {
aAvailability.onchange = null;
ok(aAvailability.value, "Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
},
function(aError) {
ok(false, "Error occurred when getting availability: " + aError);
@ -42,13 +42,13 @@ function setup() {
}
function testStartConnectionCancelPrompt() {
info('--- testStartConnectionCancelPrompt ---');
info("--- testStartConnectionCancelPrompt ---");
return Promise.all([
new Promise((resolve) => {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-cancel', SpecialPowers.Cr.NS_ERROR_DOM_NOT_ALLOWED_ERR);
gScript.sendAsyncMessage("trigger-device-prompt-cancel", SpecialPowers.Cr.NS_ERROR_DOM_NOT_ALLOWED_ERR);
resolve();
});
}),
@ -64,13 +64,13 @@ function testStartConnectionCancelPrompt() {
}
function testStartConnectionNoDevice() {
info('--- testStartConnectionNoDevice ---');
info("--- testStartConnectionNoDevice ---");
return Promise.all([
new Promise((resolve) => {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-cancel', SpecialPowers.Cr.NS_ERROR_DOM_NOT_FOUND_ERR);
gScript.sendAsyncMessage("trigger-device-prompt-cancel", SpecialPowers.Cr.NS_ERROR_DOM_NOT_FOUND_ERR);
resolve();
});
}),
@ -86,38 +86,38 @@ function testStartConnectionNoDevice() {
}
function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit() {
info('--- testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit ---');
info("--- testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit ---");
return Promise.all([
new Promise((resolve) => {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler() {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
is(aReason, SpecialPowers.Cr.NS_ERROR_FAILURE, "The control channel is closed with NS_ERROR_FAILURE");
resolve();
@ -125,10 +125,10 @@ function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit
}),
new Promise((resolve) => {
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_ERROR_FAILURE);
gScript.sendAsyncMessage("trigger-control-channel-close", SpecialPowers.Cr.NS_ERROR_FAILURE);
resolve();
});
}),
@ -154,38 +154,38 @@ function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportInit
}
function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit() {
info('--- testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit ---');
info("--- testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportInit ---");
return Promise.all([
new Promise((resolve) => {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler() {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed with NS_OK");
resolve();
@ -193,10 +193,10 @@ function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTrans
}),
new Promise((resolve) => {
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_OK);
gScript.sendAsyncMessage("trigger-control-channel-close", SpecialPowers.Cr.NS_OK);
resolve();
});
}),
@ -222,64 +222,64 @@ function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTrans
}
function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady() {
info('--- testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady ---');
info("--- testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportReady ---");
return Promise.all([
new Promise((resolve) => {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler() {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
is(aReason, SpecialPowers.Cr.NS_ERROR_ABORT, "The control channel is closed with NS_ERROR_ABORT");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.sendAsyncMessage("trigger-incoming-transport");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_ERROR_ABORT);
gScript.sendAsyncMessage("trigger-control-channel-close", SpecialPowers.Cr.NS_ERROR_ABORT);
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
resolve();
});
@ -306,38 +306,38 @@ function testStartConnectionUnexpectedControlChannelCloseBeforeDataTransportRead
}
function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady() {
info('--- testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady -- ');
info("--- testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTransportReady -- ");
return Promise.all([
new Promise((resolve) => {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler() {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
is(aReason, SpecialPowers.Cr.NS_OK, "The control channel is closed with NS_OK");
resolve();
@ -345,26 +345,26 @@ function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTrans
}),
new Promise((resolve) => {
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.sendAsyncMessage("trigger-incoming-transport");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_OK);
gScript.sendAsyncMessage("trigger-control-channel-close", SpecialPowers.Cr.NS_OK);
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
resolve();
});
@ -391,65 +391,65 @@ function testStartConnectionUnexpectedControlChannelCloseNoReasonBeforeDataTrans
}
function testStartConnectionUnexpectedDataTransportClose() {
info('--- testStartConnectionUnexpectedDataTransportClose ---');
info("--- testStartConnectionUnexpectedDataTransportClose ---");
return Promise.all([
new Promise((resolve) => {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
gScript.removeMessageListener("device-prompt", devicePromptHandler);
info("Device prompt is triggered.");
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.sendAsyncMessage("trigger-device-prompt-select");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established", controlChannelEstablishedHandler);
info("A control channel is established.");
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler() {
gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
gScript.addMessageListener("control-channel-opened", function controlChannelOpenedHandler() {
gScript.removeMessageListener("control-channel-opened", controlChannelOpenedHandler);
info("The control channel is opened.");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
gScript.addMessageListener("control-channel-closed", function controlChannelClosedHandler(aReason) {
gScript.removeMessageListener("control-channel-closed", controlChannelClosedHandler);
info("The control channel is closed. " + aReason);
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
gScript.removeMessageListener('offer-sent', offerSentHandler);
gScript.addMessageListener("offer-sent", function offerSentHandler(aIsValid) {
gScript.removeMessageListener("offer-sent", offerSentHandler);
ok(aIsValid, "A valid offer is sent out.");
info("recv offer-sent.");
gScript.sendAsyncMessage('trigger-incoming-transport');
gScript.sendAsyncMessage("trigger-incoming-transport");
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
gScript.addMessageListener("data-transport-initialized", function dataTransportInitializedHandler() {
gScript.removeMessageListener("data-transport-initialized", dataTransportInitializedHandler);
info("Data transport channel is initialized.");
gScript.sendAsyncMessage('trigger-data-transport-close', SpecialPowers.Cr.NS_ERROR_UNEXPECTED);
gScript.sendAsyncMessage("trigger-data-transport-close", SpecialPowers.Cr.NS_ERROR_UNEXPECTED);
resolve();
});
}),
new Promise((resolve) => {
gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
gScript.addMessageListener("data-transport-closed", function dataTransportClosedHandler(aReason) {
gScript.removeMessageListener("data-transport-closed", dataTransportClosedHandler);
info("The data transport is closed. " + aReason);
resolve();
});
@ -476,13 +476,13 @@ function testStartConnectionUnexpectedDataTransportClose() {
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -501,9 +501,9 @@ function runTests() {
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: "presentation-device-manage", allow: false, context: document},
], function() {
SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.session_transport.data_channel.enable", false]]},
runTests);

View file

@ -1,61 +1,61 @@
'use strict';
"use strict";
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout('Test for guarantee not firing async event');
SimpleTest.requestFlakyTimeout("Test for guarantee not firing async event");
function debug(str) {
// info(str);
}
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript1UA.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_terminate.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript1UA.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_terminate.html");
var request;
var connection;
var receiverIframe;
function setup() {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
debug('Got message: device-prompt');
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
debug("Got message: device-prompt");
gScript.removeMessageListener("device-prompt", devicePromptHandler);
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established',
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established",
controlChannelEstablishedHandler);
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('sender-launch', function senderLaunchHandler(url) {
debug('Got message: sender-launch');
gScript.removeMessageListener('sender-launch', senderLaunchHandler);
is(url, receiverUrl, 'Receiver: should receive the same url');
receiverIframe = document.createElement('iframe');
receiverIframe.setAttribute('mozbrowser', 'true');
receiverIframe.setAttribute('mozpresentation', receiverUrl);
var oop = !location.pathname.includes('_inproc');
receiverIframe.setAttribute('remote', oop);
gScript.addMessageListener("sender-launch", function senderLaunchHandler(url) {
debug("Got message: sender-launch");
gScript.removeMessageListener("sender-launch", senderLaunchHandler);
is(url, receiverUrl, "Receiver: should receive the same url");
receiverIframe = document.createElement("iframe");
receiverIframe.setAttribute("mozbrowser", "true");
receiverIframe.setAttribute("mozpresentation", receiverUrl);
var oop = !location.pathname.includes("_inproc");
receiverIframe.setAttribute("remote", oop);
receiverIframe.setAttribute('src', receiverUrl);
receiverIframe.addEventListener('mozbrowserloadend', function() {
info('Receiver loaded.');
receiverIframe.setAttribute("src", receiverUrl);
receiverIframe.addEventListener("mozbrowserloadend", function() {
info("Receiver loaded.");
}, {once: true});
// This event is triggered when the iframe calls 'alert'.
receiverIframe.addEventListener('mozbrowsershowmodalprompt', function receiverListener(evt) {
receiverIframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(evt) {
var message = evt.detail.message;
if (/^OK /.exec(message)) {
ok(true, message.replace(/^OK /, ''));
ok(true, message.replace(/^OK /, ""));
} else if (/^KO /.exec(message)) {
ok(false, message.replace(/^KO /, ''));
ok(false, message.replace(/^KO /, ""));
} else if (/^INFO /.exec(message)) {
info(message.replace(/^INFO /, ''));
info(message.replace(/^INFO /, ""));
} else if (/^COMMAND /.exec(message)) {
var command = JSON.parse(message.replace(/^COMMAND /, ''));
var command = JSON.parse(message.replace(/^COMMAND /, ""));
gScript.sendAsyncMessage(command.name, command.data);
} else if (/^DONE$/.exec(message)) {
ok(true, 'Messaging from iframe complete.');
receiverIframe.removeEventListener('mozbrowsershowmodalprompt',
ok(true, "Messaging from iframe complete.");
receiverIframe.removeEventListener("mozbrowsershowmodalprompt",
receiverListener);
}
});
@ -65,16 +65,16 @@ function setup() {
aResolve(receiverIframe);
});
var obs = SpecialPowers.Cc['@mozilla.org/observer-service;1']
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
});
gScript.addMessageListener('promise-setup-ready', function promiseSetupReadyHandler() {
debug('Got message: promise-setup-ready');
gScript.removeMessageListener('promise-setup-ready',
gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
debug("Got message: promise-setup-ready");
gScript.removeMessageListener("promise-setup-ready",
promiseSetupReadyHandler);
gScript.sendAsyncMessage('trigger-on-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-on-session-request", receiverUrl);
});
return Promise.resolve();
@ -82,19 +82,19 @@ function setup() {
function testCreateRequest() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testCreateRequest ---');
info("Sender: --- testCreateRequest ---");
request = new PresentationRequest(receiverUrl);
request.getAvailability().then((aAvailability) => {
is(aAvailability.value, false, "Sender: should have no available device after setup");
aAvailability.onchange = function() {
aAvailability.onchange = null;
ok(aAvailability.value, 'Sender: Device should be available.');
ok(aAvailability.value, "Sender: Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
}).catch((aError) => {
ok(false, 'Sender: Error occurred when getting availability: ' + aError);
ok(false, "Sender: Error occurred when getting availability: " + aError);
teardown();
aReject();
});
@ -105,24 +105,24 @@ function testStartConnection() {
return new Promise(function(aResolve, aReject) {
request.start().then((aConnection) => {
connection = aConnection;
ok(connection, 'Sender: Connection should be available.');
ok(connection.id, 'Sender: Connection ID should be set.');
is(connection.state, 'connecting', 'Sender: The initial state should be connecting.');
ok(connection, "Sender: Connection should be available.");
ok(connection.id, "Sender: Connection ID should be set.");
is(connection.state, "connecting", "Sender: The initial state should be connecting.");
connection.onconnect = function() {
connection.onconnect = null;
is(connection.state, 'connected', 'Connection should be connected.');
is(connection.state, "connected", "Connection should be connected.");
aResolve();
};
info('Sender: test terminate at connecting state');
info("Sender: test terminate at connecting state");
connection.onterminate = function() {
connection.onterminate = null;
ok(false, 'Should not be able to terminate at connecting state');
ok(false, "Should not be able to terminate at connecting state");
aReject();
}
};
connection.terminate();
}).catch((aError) => {
ok(false, 'Sender: Error occurred when establishing a connection: ' + aError);
ok(false, "Sender: Error occurred when establishing a connection: " + aError);
teardown();
aReject();
});
@ -131,45 +131,45 @@ function testStartConnection() {
function testConnectionTerminate() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testConnectionTerminate---');
info("Sender: --- testConnectionTerminate---");
connection.onterminate = function() {
connection.onterminate = null;
is(connection.state, 'terminated', 'Sender: Connection should be terminated.');
is(connection.state, "terminated", "Sender: Connection should be terminated.");
};
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established',
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established",
controlChannelEstablishedHandler);
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('sender-terminate', function senderTerminateHandler() {
gScript.removeMessageListener('sender-terminate',
gScript.addMessageListener("sender-terminate", function senderTerminateHandler() {
gScript.removeMessageListener("sender-terminate",
senderTerminateHandler);
Promise.all([
new Promise((resolve) => {
gScript.addMessageListener('device-disconnected', function deviceDisconnectedHandler() {
gScript.removeMessageListener('device-disconnected', deviceDisconnectedHandler);
ok(true, 'observe device disconnect');
gScript.addMessageListener("device-disconnected", function deviceDisconnectedHandler() {
gScript.removeMessageListener("device-disconnected", deviceDisconnectedHandler);
ok(true, "observe device disconnect");
resolve();
});
}),
new Promise((resolve) => {
receiverIframe.addEventListener('mozbrowserclose', function() {
ok(true, 'observe receiver page closing');
receiverIframe.addEventListener("mozbrowserclose", function() {
ok(true, "observe receiver page closing");
resolve();
});
}),
]).then(aResolve);
gScript.sendAsyncMessage('trigger-on-terminate-request');
gScript.sendAsyncMessage("trigger-on-terminate-request");
});
gScript.addMessageListener('ready-to-terminate', function onReadyToTerminate() {
gScript.removeMessageListener('ready-to-terminate', onReadyToTerminate);
gScript.addMessageListener("ready-to-terminate", function onReadyToTerminate() {
gScript.removeMessageListener("ready-to-terminate", onReadyToTerminate);
connection.terminate();
// test unexpected close right after terminate
connection.onclose = function() {
ok(false, 'close after terminate should do nothing');
ok(false, "close after terminate should do nothing");
};
connection.close();
});
@ -179,10 +179,10 @@ function testConnectionTerminate() {
function testSendAfterTerminate() {
return new Promise(function(aResolve, aReject) {
try {
connection.send('something');
ok(false, 'PresentationConnection.send should be failed');
connection.send("something");
ok(false, "PresentationConnection.send should be failed");
} catch (e) {
is(e.name, 'InvalidStateError', 'Must throw InvalidStateError');
is(e.name, "InvalidStateError", "Must throw InvalidStateError");
}
aResolve();
});
@ -193,14 +193,14 @@ function testCloseAfterTerminate() {
new Promise(function(aResolve, aReject) {
connection.onclose = function() {
connection.onclose = null;
ok(false, 'close at terminated state should do nothing');
ok(false, "close at terminated state should do nothing");
aResolve();
};
connection.close();
}),
new Promise(function(aResolve, aReject) {
setTimeout(function() {
is(connection.state, 'terminated', 'Sender: Connection should be terminated.');
is(connection.state, "terminated", "Sender: Connection should be terminated.");
aResolve();
}, 3000);
}),
@ -208,13 +208,13 @@ function testCloseAfterTerminate() {
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
debug('Got message: teardown-complete');
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
debug("Got message: teardown-complete");
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -227,16 +227,16 @@ function runTests() {
}
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: 'browser', allow: true, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], () => {
SpecialPowers.pushPrefEnv({ 'set': [['dom.presentation.enabled', true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.receiver.enabled", true],
['dom.presentation.test.enabled', true],
['dom.mozBrowserFramesEnabled', true],
["dom.presentation.test.enabled", true],
["dom.mozBrowserFramesEnabled", true],
["network.disable.ipc.security", true],
['dom.ipc.tabs.disabled', false],
['dom.presentation.test.stage', 0]]},
["dom.ipc.tabs.disabled", false],
["dom.presentation.test.stage", 0]]},
runTests);
});

View file

@ -1,14 +1,14 @@
'use strict';
"use strict";
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout('Test for guarantee not firing async event');
SimpleTest.requestFlakyTimeout("Test for guarantee not firing async event");
function debug(str) {
// info(str);
}
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript1UA.js'));
var receiverUrl = SimpleTest.getTestFileURL('file_presentation_terminate_establish_connection_error.html');
var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("PresentationSessionChromeScript1UA.js"));
var receiverUrl = SimpleTest.getTestFileURL("file_presentation_terminate_establish_connection_error.html");
var request;
var connection;
var receiverIframe;
@ -19,48 +19,48 @@ function postMessageToIframe(aType) {
}
function setup() {
gScript.addMessageListener('device-prompt', function devicePromptHandler() {
debug('Got message: device-prompt');
gScript.removeMessageListener('device-prompt', devicePromptHandler);
gScript.sendAsyncMessage('trigger-device-prompt-select');
gScript.addMessageListener("device-prompt", function devicePromptHandler() {
debug("Got message: device-prompt");
gScript.removeMessageListener("device-prompt", devicePromptHandler);
gScript.sendAsyncMessage("trigger-device-prompt-select");
});
gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
gScript.removeMessageListener('control-channel-established',
gScript.addMessageListener("control-channel-established", function controlChannelEstablishedHandler() {
gScript.removeMessageListener("control-channel-established",
controlChannelEstablishedHandler);
gScript.sendAsyncMessage('trigger-control-channel-open');
gScript.sendAsyncMessage("trigger-control-channel-open");
});
gScript.addMessageListener('sender-launch', function senderLaunchHandler(url) {
debug('Got message: sender-launch');
gScript.removeMessageListener('sender-launch', senderLaunchHandler);
is(url, receiverUrl, 'Receiver: should receive the same url');
receiverIframe = document.createElement('iframe');
receiverIframe.setAttribute('mozbrowser', 'true');
receiverIframe.setAttribute('mozpresentation', receiverUrl);
var oop = !location.pathname.includes('_inproc');
receiverIframe.setAttribute('remote', oop);
gScript.addMessageListener("sender-launch", function senderLaunchHandler(url) {
debug("Got message: sender-launch");
gScript.removeMessageListener("sender-launch", senderLaunchHandler);
is(url, receiverUrl, "Receiver: should receive the same url");
receiverIframe = document.createElement("iframe");
receiverIframe.setAttribute("mozbrowser", "true");
receiverIframe.setAttribute("mozpresentation", receiverUrl);
var oop = !location.pathname.includes("_inproc");
receiverIframe.setAttribute("remote", oop);
receiverIframe.setAttribute('src', receiverUrl);
receiverIframe.addEventListener('mozbrowserloadend', function() {
info('Receiver loaded.');
receiverIframe.setAttribute("src", receiverUrl);
receiverIframe.addEventListener("mozbrowserloadend", function() {
info("Receiver loaded.");
}, {once: true});
// This event is triggered when the iframe calls 'alert'.
receiverIframe.addEventListener('mozbrowsershowmodalprompt', function receiverListener(evt) {
receiverIframe.addEventListener("mozbrowsershowmodalprompt", function receiverListener(evt) {
var message = evt.detail.message;
if (/^OK /.exec(message)) {
ok(true, message.replace(/^OK /, ''));
ok(true, message.replace(/^OK /, ""));
} else if (/^KO /.exec(message)) {
ok(false, message.replace(/^KO /, ''));
ok(false, message.replace(/^KO /, ""));
} else if (/^INFO /.exec(message)) {
info(message.replace(/^INFO /, ''));
info(message.replace(/^INFO /, ""));
} else if (/^COMMAND /.exec(message)) {
var command = JSON.parse(message.replace(/^COMMAND /, ''));
var command = JSON.parse(message.replace(/^COMMAND /, ""));
gScript.sendAsyncMessage(command.name, command.data);
} else if (/^DONE$/.exec(message)) {
ok(true, 'Messaging from iframe complete.');
receiverIframe.removeEventListener('mozbrowsershowmodalprompt',
ok(true, "Messaging from iframe complete.");
receiverIframe.removeEventListener("mozbrowsershowmodalprompt",
receiverListener);
}
});
@ -70,16 +70,16 @@ function setup() {
aResolve(receiverIframe);
});
var obs = SpecialPowers.Cc['@mozilla.org/observer-service;1']
var obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
obs.notifyObservers(promise, 'setup-request-promise');
obs.notifyObservers(promise, "setup-request-promise");
});
gScript.addMessageListener('promise-setup-ready', function promiseSetupReadyHandler() {
debug('Got message: promise-setup-ready');
gScript.removeMessageListener('promise-setup-ready',
gScript.addMessageListener("promise-setup-ready", function promiseSetupReadyHandler() {
debug("Got message: promise-setup-ready");
gScript.removeMessageListener("promise-setup-ready",
promiseSetupReadyHandler);
gScript.sendAsyncMessage('trigger-on-session-request', receiverUrl);
gScript.sendAsyncMessage("trigger-on-session-request", receiverUrl);
});
return Promise.resolve();
@ -87,19 +87,19 @@ function setup() {
function testCreateRequest() {
return new Promise(function(aResolve, aReject) {
info('Sender: --- testCreateRequest ---');
info("Sender: --- testCreateRequest ---");
request = new PresentationRequest(receiverUrl);
request.getAvailability().then((aAvailability) => {
is(aAvailability.value, false, "Sender: should have no available device after setup");
aAvailability.onchange = function() {
aAvailability.onchange = null;
ok(aAvailability.value, 'Sender: Device should be available.');
ok(aAvailability.value, "Sender: Device should be available.");
aResolve();
}
};
gScript.sendAsyncMessage('trigger-device-add');
gScript.sendAsyncMessage("trigger-device-add");
}).catch((aError) => {
ok(false, 'Sender: Error occurred when getting availability: ' + aError);
ok(false, "Sender: Error occurred when getting availability: " + aError);
teardown();
aReject();
});
@ -110,16 +110,16 @@ function testStartConnection() {
return new Promise(function(aResolve, aReject) {
request.start().then((aConnection) => {
connection = aConnection;
ok(connection, 'Sender: Connection should be available.');
ok(connection.id, 'Sender: Connection ID should be set.');
is(connection.state, 'connecting', 'Sender: The initial state should be connecting.');
ok(connection, "Sender: Connection should be available.");
ok(connection.id, "Sender: Connection ID should be set.");
is(connection.state, "connecting", "Sender: The initial state should be connecting.");
connection.onconnect = function() {
connection.onconnect = null;
is(connection.state, 'connected', 'Connection should be connected.');
is(connection.state, "connected", "Connection should be connected.");
aResolve();
};
}).catch((aError) => {
ok(false, 'Sender: Error occurred when establishing a connection: ' + aError);
ok(false, "Sender: Error occurred when establishing a connection: " + aError);
teardown();
aReject();
});
@ -127,50 +127,50 @@ function testStartConnection() {
}
function testConnectionTerminate() {
info('Sender: --- testConnectionTerminate---');
info("Sender: --- testConnectionTerminate---");
let promise = Promise.all([
new Promise(function(aResolve, aReject) {
connection.onclose = function() {
connection.onclose = null;
is(connection.state, 'closed', 'Sender: Connection should be closed.');
is(connection.state, "closed", "Sender: Connection should be closed.");
aResolve();
};
}),
new Promise(function(aResolve, aReject) {
function deviceDisconnectedHandler() {
gScript.removeMessageListener('device-disconnected', deviceDisconnectedHandler);
ok(true, 'should not receive device disconnect');
gScript.removeMessageListener("device-disconnected", deviceDisconnectedHandler);
ok(true, "should not receive device disconnect");
aResolve();
}
gScript.addMessageListener('device-disconnected', deviceDisconnectedHandler);
gScript.addMessageListener("device-disconnected", deviceDisconnectedHandler);
}),
new Promise(function(aResolve, aReject) {
receiverIframe.addEventListener('mozbrowserclose', function() {
ok(true, 'observe receiver page closing');
receiverIframe.addEventListener("mozbrowserclose", function() {
ok(true, "observe receiver page closing");
aResolve();
});
})
]);
gScript.addMessageListener('prepare-for-terminate', function prepareForTerminateHandler() {
debug('Got message: prepare-for-terminate');
gScript.removeMessageListener('prepare-for-terminate', prepareForTerminateHandler);
gScript.sendAsyncMessage('trigger-control-channel-error');
postMessageToIframe('ready-to-terminate');
gScript.addMessageListener("prepare-for-terminate", function prepareForTerminateHandler() {
debug("Got message: prepare-for-terminate");
gScript.removeMessageListener("prepare-for-terminate", prepareForTerminateHandler);
gScript.sendAsyncMessage("trigger-control-channel-error");
postMessageToIframe("ready-to-terminate");
});
return promise;
}
function teardown() {
gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
debug('Got message: teardown-complete');
gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
gScript.addMessageListener("teardown-complete", function teardownCompleteHandler() {
debug("Got message: teardown-complete");
gScript.removeMessageListener("teardown-complete", teardownCompleteHandler);
gScript.destroy();
SimpleTest.finish();
});
gScript.sendAsyncMessage('teardown');
gScript.sendAsyncMessage("teardown");
}
function runTests() {
@ -181,16 +181,16 @@ function runTests() {
}
SpecialPowers.pushPermissions([
{type: 'presentation-device-manage', allow: false, context: document},
{type: 'browser', allow: true, context: document},
{type: "presentation-device-manage", allow: false, context: document},
{type: "browser", allow: true, context: document},
], () => {
SpecialPowers.pushPrefEnv({ 'set': [['dom.presentation.enabled', true],
SpecialPowers.pushPrefEnv({ "set": [["dom.presentation.enabled", true],
["dom.presentation.controller.enabled", true],
["dom.presentation.receiver.enabled", true],
['dom.presentation.test.enabled', true],
['dom.mozBrowserFramesEnabled', true],
["dom.presentation.test.enabled", true],
["dom.mozBrowserFramesEnabled", true],
["network.disable.ipc.security", true],
['dom.ipc.tabs.disabled', false],
['dom.presentation.test.stage', 0]]},
["dom.ipc.tabs.disabled", false],
["dom.presentation.test.stage", 0]]},
runTests);
});

View file

@ -19,7 +19,7 @@ const SERVER_CONTRACT_ID = "@mozilla.org/presentation/control-service;1";
const PREF_DISCOVERY = "dom.presentation.discovery.enabled";
const PREF_DISCOVERABLE = "dom.presentation.discoverable";
const PREF_DEVICENAME= "dom.presentation.device.name";
const PREF_DEVICENAME = "dom.presentation.device.name";
const LATEST_VERSION = 1;
const SERVICE_TYPE = "_presentation-ctrl._tcp";
@ -36,7 +36,7 @@ function sleep(aMs) {
.createInstance(Ci.nsITimer);
timer.initWithCallback({
notify: function () {
notify() {
resolve();
},
}, aMs, timer.TYPE_ONE_SHOT);
@ -48,11 +48,11 @@ function MockFactory(aClass) {
this._cls = aClass;
}
MockFactory.prototype = {
createInstance: function(aOuter, aIID) {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
switch(typeof(this._cls)) {
switch (typeof(this._cls)) {
case "function":
return new this._cls().QueryInterface(aIID);
case "object":
@ -61,7 +61,7 @@ MockFactory.prototype = {
return null;
}
},
lockFactory: function(aLock) {
lockFactory(aLock) {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIFactory])
@ -82,7 +82,7 @@ function ContractHook(aContractID, aClass) {
ContractHook.prototype = {
hookedMap: new Map(), // remember only the most original factory.
init: function() {
init() {
this.reset();
let oldContract = this.unregister();
@ -95,9 +95,9 @@ ContractHook.prototype = {
registerCleanupFunction(() => { this.cleanup.apply(this); });
},
reset: function() {},
reset() {},
cleanup: function() {
cleanup() {
this.reset();
this.unregister();
@ -111,7 +111,7 @@ ContractHook.prototype = {
}
},
unregister: function() {
unregister() {
var classID, factory;
try {
@ -126,7 +126,7 @@ ContractHook.prototype = {
registrar.unregisterFactory(classID, factory);
}
return { classID: classID, factory: factory };
return { classID, factory };
}
};
@ -198,12 +198,12 @@ TestPresentationDeviceListener.prototype = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) { this.devices[device.id] = device; },
removeDevice: function(device) { delete this.devices[device.id]; },
updateDevice: function(device) { this.devices[device.id] = device; },
onSessionRequest: function(device, url, presentationId, controlChannel) {},
addDevice(device) { this.devices[device.id] = device; },
removeDevice(device) { delete this.devices[device.id]; },
updateDevice(device) { this.devices[device.id] = device; },
onSessionRequest(device, url, presentationId, controlChannel) {},
count: function() {
count() {
var size = 0, key;
for (key in this.devices) {
if (this.devices.hasOwnProperty(key)) {
@ -233,8 +233,8 @@ function registerService() {
let mockObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {},
registerService: function(serviceInfo, listener) {
startDiscovery(serviceType, listener) {},
registerService(serviceInfo, listener) {
deferred.resolve();
this.serviceRegistered++;
return {
@ -244,7 +244,7 @@ function registerService() {
}
};
},
resolveService: function(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {},
serviceRegistered: 0,
serviceUnregistered: 0
};
@ -258,9 +258,9 @@ function registerService() {
provider.listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {},
removeDevice: function(device) {},
updateDevice: function(device) {},
addDevice(device) {},
removeDevice(device) {},
updateDevice(device) {},
};
deferred.promise.then(function() {
@ -283,12 +283,12 @@ function noRegisterService() {
let mockObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {},
registerService: function(serviceInfo, listener) {
startDiscovery(serviceType, listener) {},
registerService(serviceInfo, listener) {
deferred.resolve();
Assert.ok(false, "should not register service if not discoverable");
},
resolveService: function(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {},
};
let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
@ -298,9 +298,9 @@ function noRegisterService() {
provider.listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {},
removeDevice: function(device) {},
updateDevice: function(device) {},
addDevice(device) {},
removeDevice(device) {},
updateDevice(device) {},
};
let race = Promise.race([
@ -322,8 +322,8 @@ function registerServiceDynamically() {
let mockObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {},
registerService: function(serviceInfo, listener) {
startDiscovery(serviceType, listener) {},
registerService(serviceInfo, listener) {
deferred.resolve();
this.serviceRegistered++;
return {
@ -333,7 +333,7 @@ function registerServiceDynamically() {
}
};
},
resolveService: function(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {},
serviceRegistered: 0,
serviceUnregistered: 0
};
@ -347,9 +347,9 @@ function registerServiceDynamically() {
provider.listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {},
removeDevice: function(device) {},
updateDevice: function(device) {},
addDevice(device) {},
removeDevice(device) {},
updateDevice(device) {},
};
Assert.equal(mockObj.serviceRegistered, 0);
@ -385,7 +385,7 @@ function addDevice() {
SERVICE_TYPE);
let mockObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
listener.onServiceFound(createDevice("",
0,
@ -393,11 +393,11 @@ function addDevice() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {
Assert.equal(serviceInfo.serviceName, mockDevice.serviceName);
Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
listener.onServiceResolved(createDevice(mockDevice.host,
@ -435,7 +435,7 @@ function filterDevice() {
SERVICE_TYPE);
let mockObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
listener.onServiceFound(createDevice("",
0,
@ -443,11 +443,11 @@ function filterDevice() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {
Assert.equal(serviceInfo.serviceName, mockDevice.serviceName);
Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
listener.onServiceResolved(createDevice(mockDevice.host,
@ -462,7 +462,7 @@ function filterDevice() {
let listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {
addDevice(device) {
let tests = [
{ requestedUrl: "app://fling-player.gaiamobile.org/index.html", supported: true },
{ requestedUrl: "app://notification-receiver.gaiamobile.org/index.html", supported: true },
@ -481,9 +481,9 @@ function filterDevice() {
provider = null;
run_next_test();
},
updateDevice: function() {},
removeDevice: function() {},
onSessionRequest: function() {},
updateDevice() {},
removeDevice() {},
onSessionRequest() {},
};
provider.listener = listener;
@ -505,7 +505,7 @@ function handleSessionRequest() {
SERVICE_TYPE);
let mockSDObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
listener.onServiceFound(createDevice("",
0,
@ -513,11 +513,11 @@ function handleSessionRequest() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {
listener.onServiceResolved(createDevice(mockDevice.host,
mockDevice.port,
mockDevice.serviceName,
@ -527,9 +527,9 @@ function handleSessionRequest() {
let mockServerObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlService]),
connect: function(deviceInfo) {
connect(deviceInfo) {
this.request = {
deviceInfo: deviceInfo,
deviceInfo,
};
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlChannel]),
@ -537,7 +537,7 @@ function handleSessionRequest() {
},
id: "",
version: LATEST_VERSION,
isCompatibleServer: function(version) {
isCompatibleServer(version) {
return this.version === version;
}
};
@ -548,7 +548,7 @@ function handleSessionRequest() {
let listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {
addDevice(device) {
this.device = device;
},
};
@ -577,7 +577,7 @@ function handleOnSessionRequest() {
SERVICE_TYPE);
let mockSDObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
listener.onServiceFound(createDevice("",
0,
@ -585,11 +585,11 @@ function handleOnSessionRequest() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {
listener.onServiceResolved(createDevice(mockDevice.host,
mockDevice.port,
mockDevice.serviceName,
@ -599,10 +599,10 @@ function handleOnSessionRequest() {
let mockServerObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlService]),
startServer: function() {},
sessionRequest: function() {},
close: function() {},
id: '',
startServer() {},
sessionRequest() {},
close() {},
id: "",
version: LATEST_VERSION,
port: 0,
listener: null,
@ -614,15 +614,15 @@ function handleOnSessionRequest() {
let listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {},
removeDevice: function(device) {},
updateDevice: function(device) {},
onSessionRequest: function(device, url, presentationId, controlChannel) {
addDevice(device) {},
removeDevice(device) {},
updateDevice(device) {},
onSessionRequest(device, url, presentationId, controlChannel) {
Assert.ok(true, "receive onSessionRequest event");
this.request = {
deviceId: device.id,
url: url,
presentationId: presentationId,
url,
presentationId,
};
}
};
@ -659,17 +659,17 @@ function handleOnSessionRequestFromUnknownDevice() {
let mockSDObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {}
startDiscovery(serviceType, listener) {},
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {}
};
let mockServerObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlService]),
startServer: function() {},
sessionRequest: function() {},
close: function() {},
id: '',
startServer() {},
sessionRequest() {},
close() {},
id: "",
version: LATEST_VERSION,
port: 0,
listener: null,
@ -681,21 +681,21 @@ function handleOnSessionRequestFromUnknownDevice() {
let listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {
addDevice(device) {
Assert.ok(false, "shouldn't create any new device");
},
removeDevice: function(device) {
removeDevice(device) {
Assert.ok(false, "shouldn't remote any device");
},
updateDevice: function(device) {
updateDevice(device) {
Assert.ok(false, "shouldn't update any device");
},
onSessionRequest: function(device, url, presentationId, controlChannel) {
onSessionRequest(device, url, presentationId, controlChannel) {
Assert.ok(true, "receive onSessionRequest event");
this.request = {
deviceId: device.id,
url: url,
presentationId: presentationId,
url,
presentationId,
};
}
};
@ -732,11 +732,11 @@ function noAddDevice() {
let mockDevice = createDevice("device.local", 12345, "service.name", SERVICE_TYPE);
let mockObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
Assert.ok(false, "shouldn't perform any device discovery");
},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {
}
};
let contractHook = new ContractHook(SD_CONTRACT_ID, mockObj);
@ -745,9 +745,9 @@ function noAddDevice() {
let listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {},
removeDevice: function(device) {},
updateDevice: function(device) {},
addDevice(device) {},
removeDevice(device) {},
updateDevice(device) {},
};
provider.listener = listener;
provider.forceDiscovery();
@ -769,7 +769,7 @@ function ignoreIncompatibleDevice() {
let mockSDObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
listener.onServiceFound(createDevice("",
0,
@ -777,10 +777,10 @@ function ignoreIncompatibleDevice() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
registerService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {
deferred.resolve();
listener.onServiceRegistered(createDevice("",
54321,
@ -788,10 +788,10 @@ function ignoreIncompatibleDevice() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
resolveService: function(serviceInfo, listener) {
resolveService(serviceInfo, listener) {
Assert.equal(serviceInfo.serviceName, mockDevice.serviceName);
Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
listener.onServiceResolved(createDevice(mockDevice.host,
@ -803,20 +803,20 @@ function ignoreIncompatibleDevice() {
let mockServerObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlService]),
startServer: function() {
startServer() {
Services.tm.dispatchToMainThread(() => {
this.listener.onServerReady(this.port, this.certFingerprint);
});
},
sessionRequest: function() {},
close: function() {},
id: '',
sessionRequest() {},
close() {},
id: "",
version: LATEST_VERSION,
isCompatibleServer: function(version) {
isCompatibleServer(version) {
return false;
},
port: 54321,
certFingerprint: 'mock-cert-fingerprint',
certFingerprint: "mock-cert-fingerprint",
listener: null,
};
@ -854,7 +854,7 @@ function ignoreSelfDevice() {
let deferred = Promise.defer();
let mockSDObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
listener.onServiceFound(createDevice("",
0,
@ -862,10 +862,10 @@ function ignoreSelfDevice() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
registerService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {
deferred.resolve();
listener.onServiceRegistered(createDevice("",
0,
@ -873,10 +873,10 @@ function ignoreSelfDevice() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
resolveService: function(serviceInfo, listener) {
resolveService(serviceInfo, listener) {
Assert.equal(serviceInfo.serviceName, mockDevice.serviceName);
Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
listener.onServiceResolved(createDevice(mockDevice.host,
@ -888,20 +888,20 @@ function ignoreSelfDevice() {
let mockServerObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlService]),
startServer: function() {
startServer() {
Services.tm.dispatchToMainThread(() => {
this.listener.onServerReady(this.port, this.certFingerprint);
});
},
sessionRequest: function() {},
close: function() {},
id: '',
sessionRequest() {},
close() {},
id: "",
version: LATEST_VERSION,
isCompatibleServer: function(version) {
isCompatibleServer(version) {
return this.version === version;
},
port: 54321,
certFingerprint: 'mock-cert-fingerprint',
certFingerprint: "mock-cert-fingerprint",
listener: null,
};
@ -935,7 +935,7 @@ function addDeviceDynamically() {
SERVICE_TYPE);
let mockObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
listener.onServiceFound(createDevice("",
0,
@ -943,11 +943,11 @@ function addDeviceDynamically() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {
Assert.equal(serviceInfo.serviceName, mockDevice.serviceName);
Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
listener.onServiceResolved(createDevice(mockDevice.host,
@ -992,7 +992,7 @@ function updateDevice() {
discovered: false,
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
if (!this.discovered) {
@ -1004,13 +1004,13 @@ function updateDevice() {
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {
cancel() {
listener.onDiscoveryStopped(serviceType);
}
};
},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {
Assert.equal(serviceInfo.serviceType, SERVICE_TYPE);
if (serviceInfo.serviceName == "N1") {
listener.onServiceResolved(mockDevice1);
@ -1028,14 +1028,14 @@ function updateDevice() {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {
addDevice(device) {
Assert.ok(!this.isDeviceAdded);
Assert.equal(device.id, mockDevice1.host);
Assert.equal(device.name, mockDevice1.serviceName);
this.isDeviceAdded = true;
},
removeDevice: function(device) { Assert.ok(false); },
updateDevice: function(device) {
removeDevice(device) { Assert.ok(false); },
updateDevice(device) {
Assert.ok(!this.isDeviceUpdated);
Assert.equal(device.id, mockDevice2.host);
Assert.equal(device.name, mockDevice2.serviceName);
@ -1079,7 +1079,7 @@ function diffDiscovery() {
discovered: false,
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
if (!this.discovered) {
@ -1093,13 +1093,13 @@ function diffDiscovery() {
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {
cancel() {
listener.onDiscoveryStopped(serviceType);
}
};
},
registerService: function(serviceInfo, listener) {},
resolveService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {},
resolveService(serviceInfo, listener) {
Assert.equal(serviceInfo.serviceType, SERVICE_TYPE);
if (serviceInfo.serviceName == "N1") {
listener.onServiceResolved(mockDevice1);
@ -1121,9 +1121,9 @@ function diffDiscovery() {
// Start discovery
provider.listener = listener; // discover: N1, N2
Assert.equal(listener.count(), 2);
Assert.equal(listener.devices['A.local'].name, mockDevice1.serviceName);
Assert.equal(listener.devices['B.local'].name, mockDevice2.serviceName);
Assert.ok(!listener.devices['C.local']);
Assert.equal(listener.devices["A.local"].name, mockDevice1.serviceName);
Assert.equal(listener.devices["B.local"].name, mockDevice2.serviceName);
Assert.ok(!listener.devices["C.local"]);
// temporarily disable to stop discovery and re-enable
Services.prefs.setBoolPref(PREF_DISCOVERY, false);
@ -1131,9 +1131,9 @@ function diffDiscovery() {
provider.forceDiscovery(); // discover: N1, N3, going to remove: N2
Assert.equal(listener.count(), 3);
Assert.equal(listener.devices['A.local'].name, mockDevice1.serviceName);
Assert.equal(listener.devices['B.local'].name, mockDevice2.serviceName);
Assert.equal(listener.devices['C.local'].name, mockDevice3.serviceName);
Assert.equal(listener.devices["A.local"].name, mockDevice1.serviceName);
Assert.equal(listener.devices["B.local"].name, mockDevice2.serviceName);
Assert.equal(listener.devices["C.local"].name, mockDevice3.serviceName);
// temporarily disable to stop discovery and re-enable
Services.prefs.setBoolPref(PREF_DISCOVERY, false);
@ -1141,9 +1141,9 @@ function diffDiscovery() {
provider.forceDiscovery(); // discover: N1, N3, remove: N2
Assert.equal(listener.count(), 2);
Assert.equal(listener.devices['A.local'].name, mockDevice1.serviceName);
Assert.ok(!listener.devices['B.local']);
Assert.equal(listener.devices['C.local'].name, mockDevice3.serviceName);
Assert.equal(listener.devices["A.local"].name, mockDevice1.serviceName);
Assert.ok(!listener.devices["B.local"]);
Assert.equal(listener.devices["C.local"].name, mockDevice3.serviceName);
provider.listener = null;
@ -1161,7 +1161,7 @@ function serverClosed() {
let mockObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {
startDiscovery(serviceType, listener) {
listener.onDiscoveryStarted(serviceType);
listener.onServiceFound(createDevice("",
0,
@ -1169,10 +1169,10 @@ function serverClosed() {
mockDevice.serviceType));
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
cancel: function() {}
cancel() {}
};
},
registerService: function(serviceInfo, listener) {
registerService(serviceInfo, listener) {
this.serviceRegistered++;
return {
QueryInterface: ChromeUtils.generateQI([Ci.nsICancelable]),
@ -1181,7 +1181,7 @@ function serverClosed() {
}
};
},
resolveService: function(serviceInfo, listener) {
resolveService(serviceInfo, listener) {
Assert.equal(serviceInfo.serviceName, mockDevice.serviceName);
Assert.equal(serviceInfo.serviceType, mockDevice.serviceType);
listener.onServiceResolved(createDevice(mockDevice.host,
@ -1202,9 +1202,9 @@ function serverClosed() {
let listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) { this.devices.push(device); },
removeDevice: function(device) {},
updateDevice: function(device) {},
addDevice(device) { this.devices.push(device); },
removeDevice(device) {},
updateDevice(device) {},
devices: []
};
Assert.equal(listener.devices.length, 0);
@ -1216,7 +1216,7 @@ function serverClosed() {
let serverListener = provider.QueryInterface(Ci.nsIPresentationControlServerListener);
let randomPort = 9527;
serverListener.onServerReady(randomPort, '');
serverListener.onServerReady(randomPort, "");
Assert.equal(mockObj.serviceRegistered, 2);
Assert.equal(mockObj.serviceUnregistered, 1);
@ -1239,18 +1239,18 @@ function serverRetry() {
let mockSDObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIDNSServiceDiscovery]),
startDiscovery: function(serviceType, listener) {},
registerService: function(serviceInfo, listener) {
startDiscovery(serviceType, listener) {},
registerService(serviceInfo, listener) {
Assert.ok(isRetrying, "register service after retrying startServer");
provider.listener = null;
run_next_test();
},
resolveService: function(serviceInfo, listener) {}
resolveService(serviceInfo, listener) {}
};
let mockServerObj = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlService]),
startServer: function(encrypted, port) {
startServer(encrypted, port) {
if (!isRetrying) {
isRetrying = true;
Services.tm.dispatchToMainThread(() => {
@ -1263,12 +1263,12 @@ function serverRetry() {
});
}
},
sessionRequest: function() {},
close: function() {},
id: '',
sessionRequest() {},
close() {},
id: "",
version: LATEST_VERSION,
port: 0,
certFingerprint: 'mock-cert-fingerprint',
certFingerprint: "mock-cert-fingerprint",
listener: null,
};
@ -1278,10 +1278,10 @@ function serverRetry() {
let listener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceListener,
Ci.nsISupportsWeakReference]),
addDevice: function(device) {},
removeDevice: function(device) {},
updateDevice: function(device) {},
onSessionRequest: function(device, url, presentationId, controlChannel) {}
addDevice(device) {},
removeDevice(device) {},
updateDevice(device) {},
onSessionRequest(device, url, presentationId, controlChannel) {}
};
provider.listener = listener;

View file

@ -2,12 +2,12 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
"use strict";
ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm');
ChromeUtils.import('resource://gre/modules/Services.jsm');
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
const manager = Cc['@mozilla.org/presentation-device/manager;1']
const manager = Cc["@mozilla.org/presentation-device/manager;1"]
.getService(Ci.nsIPresentationDeviceManager);
function TestPresentationDevice() {}
@ -17,12 +17,12 @@ function TestPresentationControlChannel() {}
TestPresentationControlChannel.prototype = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlChannel]),
sendOffer: function(offer) {},
sendAnswer: function(answer) {},
disconnect: function() {},
launch: function() {},
terminate: function() {},
reconnect: function() {},
sendOffer(offer) {},
sendAnswer(answer) {},
disconnect() {},
launch() {},
terminate() {},
reconnect() {},
set listener(listener) {},
get listener() {},
};
@ -30,7 +30,7 @@ TestPresentationControlChannel.prototype = {
var testProvider = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDeviceProvider]),
forceDiscovery: function() {
forceDiscovery() {
},
set listener(listener) {
},
@ -38,26 +38,26 @@ var testProvider = {
},
};
const forbiddenRequestedUrl = 'http://example.com';
const forbiddenRequestedUrl = "http://example.com";
var testDevice = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationDevice]),
id: 'id',
name: 'name',
type: 'type',
establishControlChannel: function(url, presentationId) {
id: "id",
name: "name",
type: "type",
establishControlChannel(url, presentationId) {
return null;
},
disconnect: function() {},
isRequestedUrlSupported: function(requestedUrl) {
disconnect() {},
isRequestedUrlSupported(requestedUrl) {
return forbiddenRequestedUrl !== requestedUrl;
},
};
function addProvider() {
Object.defineProperty(testProvider, 'listener', {
Object.defineProperty(testProvider, "listener", {
configurable: true,
set: function(listener) {
Assert.strictEqual(listener, manager, 'listener setter is invoked by PresentationDeviceManager');
set(listener) {
Assert.strictEqual(listener, manager, "listener setter is invoked by PresentationDeviceManager");
delete testProvider.listener;
run_next_test();
},
@ -68,7 +68,7 @@ function addProvider() {
function forceDiscovery() {
testProvider.forceDiscovery = function() {
testProvider.forceDiscovery = function() {};
Assert.ok(true, 'forceDiscovery is invoked by PresentationDeviceManager');
Assert.ok(true, "forceDiscovery is invoked by PresentationDeviceManager");
run_next_test();
};
manager.forceDiscovery();
@ -79,23 +79,23 @@ function addDevice() {
Services.obs.removeObserver(observer, topic);
let updatedDevice = subject.QueryInterface(Ci.nsIPresentationDevice);
Assert.equal(updatedDevice.id, testDevice.id, 'expected device id');
Assert.equal(updatedDevice.name, testDevice.name, 'expected device name');
Assert.equal(updatedDevice.type, testDevice.type, 'expected device type');
Assert.equal(data, 'add', 'expected update type');
Assert.equal(updatedDevice.id, testDevice.id, "expected device id");
Assert.equal(updatedDevice.name, testDevice.name, "expected device name");
Assert.equal(updatedDevice.type, testDevice.type, "expected device type");
Assert.equal(data, "add", "expected update type");
Assert.ok(manager.deviceAvailable, 'device is available');
Assert.ok(manager.deviceAvailable, "device is available");
let devices = manager.getAvailableDevices();
Assert.equal(devices.length, 1, 'expect 1 available device');
Assert.equal(devices.length, 1, "expect 1 available device");
let device = devices.queryElementAt(0, Ci.nsIPresentationDevice);
Assert.equal(device.id, testDevice.id, 'expected device id');
Assert.equal(device.name, testDevice.name, 'expected device name');
Assert.equal(device.type, testDevice.type, 'expected device type');
Assert.equal(device.id, testDevice.id, "expected device id");
Assert.equal(device.name, testDevice.name, "expected device name");
Assert.equal(device.type, testDevice.type, "expected device type");
run_next_test();
}, 'presentation-device-change');
}, "presentation-device-change");
manager.QueryInterface(Ci.nsIPresentationDeviceListener).addDevice(testDevice);
}
@ -104,59 +104,59 @@ function updateDevice() {
Services.obs.removeObserver(observer, topic);
let updatedDevice = subject.QueryInterface(Ci.nsIPresentationDevice);
Assert.equal(updatedDevice.id, testDevice.id, 'expected device id');
Assert.equal(updatedDevice.name, testDevice.name, 'expected device name');
Assert.equal(updatedDevice.type, testDevice.type, 'expected device type');
Assert.equal(data, 'update', 'expected update type');
Assert.equal(updatedDevice.id, testDevice.id, "expected device id");
Assert.equal(updatedDevice.name, testDevice.name, "expected device name");
Assert.equal(updatedDevice.type, testDevice.type, "expected device type");
Assert.equal(data, "update", "expected update type");
Assert.ok(manager.deviceAvailable, 'device is available');
Assert.ok(manager.deviceAvailable, "device is available");
let devices = manager.getAvailableDevices();
Assert.equal(devices.length, 1, 'expect 1 available device');
Assert.equal(devices.length, 1, "expect 1 available device");
let device = devices.queryElementAt(0, Ci.nsIPresentationDevice);
Assert.equal(device.id, testDevice.id, 'expected device id');
Assert.equal(device.name, testDevice.name, 'expected name after device update');
Assert.equal(device.type, testDevice.type, 'expected device type');
Assert.equal(device.id, testDevice.id, "expected device id");
Assert.equal(device.name, testDevice.name, "expected name after device update");
Assert.equal(device.type, testDevice.type, "expected device type");
run_next_test();
}, 'presentation-device-change');
testDevice.name = 'updated-name';
}, "presentation-device-change");
testDevice.name = "updated-name";
manager.QueryInterface(Ci.nsIPresentationDeviceListener).updateDevice(testDevice);
}
function filterDevice() {
let presentationUrls = Cc['@mozilla.org/array;1'].createInstance(Ci.nsIMutableArray);
let url = Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString);
let presentationUrls = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
let url = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
url.data = forbiddenRequestedUrl;
presentationUrls.appendElement(url);
let devices = manager.getAvailableDevices(presentationUrls);
Assert.equal(devices.length, 0, 'expect 0 available device for example.com');
Assert.equal(devices.length, 0, "expect 0 available device for example.com");
run_next_test();
}
function sessionRequest() {
let testUrl = 'http://www.example.org/';
let testPresentationId = 'test-presentation-id';
let testUrl = "http://www.example.org/";
let testPresentationId = "test-presentation-id";
let testControlChannel = new TestPresentationControlChannel();
Services.obs.addObserver(function observer(subject, topic, data) {
Services.obs.removeObserver(observer, topic);
let request = subject.QueryInterface(Ci.nsIPresentationSessionRequest);
Assert.equal(request.device.id, testDevice.id, 'expected device');
Assert.equal(request.url, testUrl, 'expected requesting URL');
Assert.equal(request.presentationId, testPresentationId, 'expected presentation Id');
Assert.equal(request.device.id, testDevice.id, "expected device");
Assert.equal(request.url, testUrl, "expected requesting URL");
Assert.equal(request.presentationId, testPresentationId, "expected presentation Id");
run_next_test();
}, 'presentation-session-request');
}, "presentation-session-request");
manager.QueryInterface(Ci.nsIPresentationDeviceListener)
.onSessionRequest(testDevice, testUrl, testPresentationId, testControlChannel);
}
function terminateRequest() {
let testUrl = 'http://www.example.org/';
let testPresentationId = 'test-presentation-id';
let testUrl = "http://www.example.org/";
let testPresentationId = "test-presentation-id";
let testControlChannel = new TestPresentationControlChannel();
let testIsFromReceiver = true;
Services.obs.addObserver(function observer(subject, topic, data) {
@ -164,32 +164,32 @@ function terminateRequest() {
let request = subject.QueryInterface(Ci.nsIPresentationTerminateRequest);
Assert.equal(request.device.id, testDevice.id, 'expected device');
Assert.equal(request.presentationId, testPresentationId, 'expected presentation Id');
Assert.equal(request.isFromReceiver, testIsFromReceiver, 'expected isFromReceiver');
Assert.equal(request.device.id, testDevice.id, "expected device");
Assert.equal(request.presentationId, testPresentationId, "expected presentation Id");
Assert.equal(request.isFromReceiver, testIsFromReceiver, "expected isFromReceiver");
run_next_test();
}, 'presentation-terminate-request');
}, "presentation-terminate-request");
manager.QueryInterface(Ci.nsIPresentationDeviceListener)
.onTerminateRequest(testDevice, testPresentationId,
testControlChannel, testIsFromReceiver);
}
function reconnectRequest() {
let testUrl = 'http://www.example.org/';
let testPresentationId = 'test-presentation-id';
let testUrl = "http://www.example.org/";
let testPresentationId = "test-presentation-id";
let testControlChannel = new TestPresentationControlChannel();
Services.obs.addObserver(function observer(subject, topic, data) {
Services.obs.removeObserver(observer, topic);
let request = subject.QueryInterface(Ci.nsIPresentationSessionRequest);
Assert.equal(request.device.id, testDevice.id, 'expected device');
Assert.equal(request.url, testUrl, 'expected requesting URL');
Assert.equal(request.presentationId, testPresentationId, 'expected presentation Id');
Assert.equal(request.device.id, testDevice.id, "expected device");
Assert.equal(request.url, testUrl, "expected requesting URL");
Assert.equal(request.presentationId, testPresentationId, "expected presentation Id");
run_next_test();
}, 'presentation-reconnect-request');
}, "presentation-reconnect-request");
manager.QueryInterface(Ci.nsIPresentationDeviceListener)
.onReconnectRequest(testDevice, testUrl, testPresentationId, testControlChannel);
}
@ -199,26 +199,26 @@ function removeDevice() {
Services.obs.removeObserver(observer, topic);
let updatedDevice = subject.QueryInterface(Ci.nsIPresentationDevice);
Assert.equal(updatedDevice.id, testDevice.id, 'expected device id');
Assert.equal(updatedDevice.name, testDevice.name, 'expected device name');
Assert.equal(updatedDevice.type, testDevice.type, 'expected device type');
Assert.equal(data, 'remove', 'expected update type');
Assert.equal(updatedDevice.id, testDevice.id, "expected device id");
Assert.equal(updatedDevice.name, testDevice.name, "expected device name");
Assert.equal(updatedDevice.type, testDevice.type, "expected device type");
Assert.equal(data, "remove", "expected update type");
Assert.ok(!manager.deviceAvailable, 'device is not available');
Assert.ok(!manager.deviceAvailable, "device is not available");
let devices = manager.getAvailableDevices();
Assert.equal(devices.length, 0, 'expect 0 available device');
Assert.equal(devices.length, 0, "expect 0 available device");
run_next_test();
}, 'presentation-device-change');
}, "presentation-device-change");
manager.QueryInterface(Ci.nsIPresentationDeviceListener).removeDevice(testDevice);
}
function removeProvider() {
Object.defineProperty(testProvider, 'listener', {
Object.defineProperty(testProvider, "listener", {
configurable: true,
set: function(listener) {
Assert.strictEqual(listener, null, 'unsetListener is invoked by PresentationDeviceManager');
set(listener) {
Assert.strictEqual(listener, null, "unsetListener is invoked by PresentationDeviceManager");
delete testProvider.listener;
run_next_test();
},
@ -236,7 +236,3 @@ add_test(terminateRequest);
add_test(reconnectRequest);
add_test(removeDevice);
add_test(removeProvider);
function run_test() {
run_next_test();
}

View file

@ -2,15 +2,15 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
"use strict";
const CC = Components.Constructor;
const ServerSocket = CC("@mozilla.org/network/server-socket;1",
"nsIServerSocket",
"init");
ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm');
ChromeUtils.import('resource://gre/modules/Services.jsm');
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
var testServer = null;
var clientTransport = null;
@ -41,7 +41,7 @@ var isServerClosed = false;
const clientCallback = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationSessionTransportCallback]),
notifyTransportReady: function () {
notifyTransportReady() {
Assert.ok(true, "Client transport ready.");
isClientReady = true;
@ -49,7 +49,7 @@ const clientCallback = {
run_next_test();
}
},
notifyTransportClosed: function (aReason) {
notifyTransportClosed(aReason) {
Assert.ok(true, "Client transport is closed.");
isClientClosed = true;
@ -57,7 +57,7 @@ const clientCallback = {
run_next_test();
}
},
notifyData: function(aData) {
notifyData(aData) {
Assert.equal(aData, serverMessage, "Client transport receives data.");
run_next_test();
},
@ -65,7 +65,7 @@ const clientCallback = {
const serverCallback = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationSessionTransportCallback]),
notifyTransportReady: function () {
notifyTransportReady() {
Assert.ok(true, "Server transport ready.");
isServerReady = true;
@ -73,7 +73,7 @@ const serverCallback = {
run_next_test();
}
},
notifyTransportClosed: function (aReason) {
notifyTransportClosed(aReason) {
Assert.ok(true, "Server transport is closed.");
isServerClosed = true;
@ -81,7 +81,7 @@ const serverCallback = {
run_next_test();
}
},
notifyData: function(aData) {
notifyData(aData) {
Assert.equal(aData, clientMessage, "Server transport receives data.");
run_next_test();
},
@ -98,7 +98,7 @@ const clientListener = {
run_next_test();
}
}
}
};
const serverListener = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationSessionTransportBuilderListener]),
@ -112,24 +112,24 @@ const serverListener = {
run_next_test();
}
}
}
};
function TestServer() {
this.serverSocket = ServerSocket(-1, true, -1);
this.serverSocket.asyncListen(this)
this.serverSocket.asyncListen(this);
}
TestServer.prototype = {
onSocketAccepted: function(aSocket, aTransport) {
onSocketAccepted(aSocket, aTransport) {
print("Test server gets a client connection.");
serverBuilder = Cc["@mozilla.org/presentation/presentationtcpsessiontransport;1"]
.createInstance(Ci.nsIPresentationTCPSessionTransportBuilder);
serverBuilder.buildTCPSenderTransport(aTransport, serverListener);
},
onStopListening: function(aSocket) {
onStopListening(aSocket) {
print("Test server stops listening.");
},
close: function() {
close() {
if (this.serverSocket) {
this.serverSocket.close();
this.serverSocket = null;

View file

@ -4,18 +4,18 @@
/* jshint esnext:true, globalstrict:true, moz:true, undef:true, unused:true */
/* globals Components,Assert,run_next_test,add_test,do_execute_soon */
'use strict';
"use strict";
/* globals ControllerStateMachine */
ChromeUtils.import('resource://gre/modules/presentation/ControllerStateMachine.jsm');
ChromeUtils.import("resource://gre/modules/presentation/ControllerStateMachine.jsm");
/* globals ReceiverStateMachine */
ChromeUtils.import('resource://gre/modules/presentation/ReceiverStateMachine.jsm');
ChromeUtils.import("resource://gre/modules/presentation/ReceiverStateMachine.jsm");
/* globals State */
ChromeUtils.import('resource://gre/modules/presentation/StateMachineHelper.jsm');
ChromeUtils.import("resource://gre/modules/presentation/StateMachineHelper.jsm");
const testControllerId = 'test-controller-id';
const testPresentationId = 'test-presentation-id';
const testUrl = 'http://example.org';
const testControllerId = "test-controller-id";
const testPresentationId = "test-presentation-id";
const testUrl = "http://example.org";
let mockControllerChannel = {};
let mockReceiverChannel = {};
@ -36,40 +36,40 @@ mockReceiverChannel.sendCommand = function(command) {
};
function connect() {
Assert.equal(controllerState.state, State.INIT, 'controller in init state');
Assert.equal(receiverState.state, State.INIT, 'receiver in init state');
Assert.equal(controllerState.state, State.INIT, "controller in init state");
Assert.equal(receiverState.state, State.INIT, "receiver in init state");
// step 1: underlying connection is ready
controllerState.onChannelReady();
Assert.equal(controllerState.state, State.CONNECTING, 'controller in connecting state');
Assert.equal(controllerState.state, State.CONNECTING, "controller in connecting state");
receiverState.onChannelReady();
Assert.equal(receiverState.state, State.CONNECTING, 'receiver in connecting state');
Assert.equal(receiverState.state, State.CONNECTING, "receiver in connecting state");
// step 2: receiver reply to connect command
mockReceiverChannel.notifyDeviceConnected = function(deviceId) {
Assert.equal(deviceId, testControllerId, 'receiver connect to mock controller');
Assert.equal(receiverState.state, State.CONNECTED, 'receiver in connected state');
Assert.equal(deviceId, testControllerId, "receiver connect to mock controller");
Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
// step 3: controller receive connect-ack command
mockControllerChannel.notifyDeviceConnected = function() {
Assert.equal(controllerState.state, State.CONNECTED, 'controller in connected state');
Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
run_next_test();
};
};
}
function launch() {
Assert.equal(controllerState.state, State.CONNECTED, 'controller in connected state');
Assert.equal(receiverState.state, State.CONNECTED, 'receiver in connected state');
Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
controllerState.launch(testPresentationId, testUrl);
mockReceiverChannel.notifyLaunch = function(presentationId, url) {
Assert.equal(receiverState.state, State.CONNECTED, 'receiver in connected state');
Assert.equal(presentationId, testPresentationId, 'expected presentationId received');
Assert.equal(url, testUrl, 'expected url received');
Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
Assert.equal(presentationId, testPresentationId, "expected presentationId received");
Assert.equal(url, testUrl, "expected url received");
mockControllerChannel.notifyLaunch = function(presentationId) {
Assert.equal(controllerState.state, State.CONNECTED, 'controller in connected state');
Assert.equal(presentationId, testPresentationId, 'expected presentationId received from ack');
Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
Assert.equal(presentationId, testPresentationId, "expected presentationId received from ack");
run_next_test();
};
@ -77,17 +77,17 @@ function launch() {
}
function terminateByController() {
Assert.equal(controllerState.state, State.CONNECTED, 'controller in connected state');
Assert.equal(receiverState.state, State.CONNECTED, 'receiver in connected state');
Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
controllerState.terminate(testPresentationId);
mockReceiverChannel.notifyTerminate = function(presentationId) {
Assert.equal(receiverState.state, State.CONNECTED, 'receiver in connected state');
Assert.equal(presentationId, testPresentationId, 'expected presentationId received');
Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
Assert.equal(presentationId, testPresentationId, "expected presentationId received");
mockControllerChannel.notifyTerminate = function(presentationId) {
Assert.equal(controllerState.state, State.CONNECTED, 'controller in connected state');
Assert.equal(presentationId, testPresentationId, 'expected presentationId received from ack');
Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
Assert.equal(presentationId, testPresentationId, "expected presentationId received from ack");
run_next_test();
};
@ -97,17 +97,17 @@ function terminateByController() {
}
function terminateByReceiver() {
Assert.equal(controllerState.state, State.CONNECTED, 'controller in connected state');
Assert.equal(receiverState.state, State.CONNECTED, 'receiver in connected state');
Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
receiverState.terminate(testPresentationId);
mockControllerChannel.notifyTerminate = function(presentationId) {
Assert.equal(controllerState.state, State.CONNECTED, 'controller in connected state');
Assert.equal(presentationId, testPresentationId, 'expected presentationId received');
Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
Assert.equal(presentationId, testPresentationId, "expected presentationId received");
mockReceiverChannel.notifyTerminate = function(presentationId) {
Assert.equal(receiverState.state, State.CONNECTED, 'receiver in connected state');
Assert.equal(presentationId, testPresentationId, 'expected presentationId received from ack');
Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
Assert.equal(presentationId, testPresentationId, "expected presentationId received from ack");
run_next_test();
};
@ -116,27 +116,27 @@ function terminateByReceiver() {
}
function exchangeSDP() {
Assert.equal(controllerState.state, State.CONNECTED, 'controller in connected state');
Assert.equal(receiverState.state, State.CONNECTED, 'receiver in connected state');
Assert.equal(controllerState.state, State.CONNECTED, "controller in connected state");
Assert.equal(receiverState.state, State.CONNECTED, "receiver in connected state");
const testOffer = 'test-offer';
const testAnswer = 'test-answer';
const testIceCandidate = 'test-ice-candidate';
const testOffer = "test-offer";
const testAnswer = "test-answer";
const testIceCandidate = "test-ice-candidate";
controllerState.sendOffer(testOffer);
mockReceiverChannel.notifyOffer = function(offer) {
Assert.equal(offer, testOffer, 'expected offer received');
Assert.equal(offer, testOffer, "expected offer received");
receiverState.sendAnswer(testAnswer);
mockControllerChannel.notifyAnswer = function(answer) {
Assert.equal(answer, testAnswer, 'expected answer received');
Assert.equal(answer, testAnswer, "expected answer received");
controllerState.updateIceCandidate(testIceCandidate);
mockReceiverChannel.notifyIceCandidate = function(candidate) {
Assert.equal(candidate, testIceCandidate, 'expected ice candidate received in receiver');
Assert.equal(candidate, testIceCandidate, "expected ice candidate received in receiver");
receiverState.updateIceCandidate(testIceCandidate);
mockControllerChannel.notifyIceCandidate = function(candidate) {
Assert.equal(candidate, testIceCandidate, 'expected ice candidate received in controller');
Assert.equal(candidate, testIceCandidate, "expected ice candidate received in controller");
run_next_test();
};
@ -148,18 +148,18 @@ function exchangeSDP() {
function disconnect() {
// step 1: controller send disconnect command
controllerState.onChannelClosed(Cr.NS_OK, false);
Assert.equal(controllerState.state, State.CLOSING, 'controller in closing state');
Assert.equal(controllerState.state, State.CLOSING, "controller in closing state");
mockReceiverChannel.notifyDisconnected = function(reason) {
Assert.equal(reason, Cr.NS_OK, 'receive close reason');
Assert.equal(receiverState.state, State.CLOSED, 'receiver in closed state');
Assert.equal(reason, Cr.NS_OK, "receive close reason");
Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
receiverState.onChannelClosed(Cr.NS_OK, true);
Assert.equal(receiverState.state, State.CLOSED, 'receiver in closed state');
Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
mockControllerChannel.notifyDisconnected = function(reason) {
Assert.equal(reason, Cr.NS_OK, 'receive close reason');
Assert.equal(controllerState.state, State.CLOSED, 'controller in closed state');
Assert.equal(reason, Cr.NS_OK, "receive close reason");
Assert.equal(controllerState.state, State.CLOSED, "controller in closed state");
run_next_test();
};
@ -174,18 +174,18 @@ function receiverDisconnect() {
// step 1: controller send disconnect command
receiverState.onChannelClosed(Cr.NS_OK, false);
Assert.equal(receiverState.state, State.CLOSING, 'receiver in closing state');
Assert.equal(receiverState.state, State.CLOSING, "receiver in closing state");
mockControllerChannel.notifyDisconnected = function(reason) {
Assert.equal(reason, Cr.NS_OK, 'receive close reason');
Assert.equal(controllerState.state, State.CLOSED, 'controller in closed state');
Assert.equal(reason, Cr.NS_OK, "receive close reason");
Assert.equal(controllerState.state, State.CLOSED, "controller in closed state");
controllerState.onChannelClosed(Cr.NS_OK, true);
Assert.equal(controllerState.state, State.CLOSED, 'controller in closed state');
Assert.equal(controllerState.state, State.CLOSED, "controller in closed state");
mockReceiverChannel.notifyDisconnected = function(reason) {
Assert.equal(reason, Cr.NS_OK, 'receive close reason');
Assert.equal(receiverState.state, State.CLOSED, 'receiver in closed state');
Assert.equal(reason, Cr.NS_OK, "receive close reason");
Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
run_next_test();
};
@ -201,18 +201,18 @@ function abnormalDisconnect() {
const testErrorReason = Cr.NS_ERROR_FAILURE;
// step 1: controller send disconnect command
controllerState.onChannelClosed(testErrorReason, false);
Assert.equal(controllerState.state, State.CLOSING, 'controller in closing state');
Assert.equal(controllerState.state, State.CLOSING, "controller in closing state");
mockReceiverChannel.notifyDisconnected = function(reason) {
Assert.equal(reason, testErrorReason, 'receive abnormal close reason');
Assert.equal(receiverState.state, State.CLOSED, 'receiver in closed state');
Assert.equal(reason, testErrorReason, "receive abnormal close reason");
Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
receiverState.onChannelClosed(Cr.NS_OK, true);
Assert.equal(receiverState.state, State.CLOSED, 'receiver in closed state');
Assert.equal(receiverState.state, State.CLOSED, "receiver in closed state");
mockControllerChannel.notifyDisconnected = function(reason) {
Assert.equal(reason, testErrorReason, 'receive abnormal close reason');
Assert.equal(controllerState.state, State.CLOSED, 'controller in closed state');
Assert.equal(reason, testErrorReason, "receive abnormal close reason");
Assert.equal(controllerState.state, State.CLOSED, "controller in closed state");
run_next_test();
};
@ -228,7 +228,3 @@ add_test(exchangeSDP);
add_test(disconnect);
add_test(receiverDisconnect);
add_test(abnormalDisconnect);
function run_test() { // jshint ignore:line
run_next_test();
}

View file

@ -2,10 +2,10 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
"use strict";
ChromeUtils.import('resource://gre/modules/XPCOMUtils.jsm');
ChromeUtils.import('resource://gre/modules/Services.jsm');
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
var pcs;
@ -14,7 +14,7 @@ function makeJointSuccess(names) {
let funcs = {}, successCount = 0;
names.forEach(function(name) {
funcs[name] = function() {
info('got expected: ' + name);
info("got expected: " + name);
if (++successCount === names.length)
run_next_test();
};
@ -37,7 +37,7 @@ function TestDescription(aType, aTcpAddress, aTcpPort) {
TestDescription.prototype = {
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationChannelDescription]),
}
};
const CONTROLLER_CONTROL_CHANNEL_PORT = 36777;
const PRESENTER_CONTROL_CHANNEL_PORT = 36888;
@ -46,19 +46,19 @@ var CLOSE_CONTROL_CHANNEL_REASON = Cr.NS_OK;
var candidate;
// presenter's presentation channel description
const OFFER_ADDRESS = '192.168.123.123';
const OFFER_ADDRESS = "192.168.123.123";
const OFFER_PORT = 123;
// controller's presentation channel description
const ANSWER_ADDRESS = '192.168.321.321';
const ANSWER_ADDRESS = "192.168.321.321";
const ANSWER_PORT = 321;
function loopOfferAnser() {
pcs = Cc["@mozilla.org/presentation/control-service;1"]
.createInstance(Ci.nsIPresentationControlService);
pcs.id = 'controllerID';
pcs.id = "controllerID";
pcs.listener = {
onServerReady: function() {
onServerReady() {
testPresentationServer();
}
};
@ -69,45 +69,45 @@ function loopOfferAnser() {
function testPresentationServer() {
let yayFuncs = makeJointSuccess(['controllerControlChannelClose',
'presenterControlChannelClose',
'controllerControlChannelReconnect',
'presenterControlChannelReconnect']);
let yayFuncs = makeJointSuccess(["controllerControlChannelClose",
"presenterControlChannelClose",
"controllerControlChannelReconnect",
"presenterControlChannelReconnect"]);
let presenterControlChannel;
pcs.listener = {
onSessionRequest: function(deviceInfo, url, presentationId, controlChannel) {
onSessionRequest(deviceInfo, url, presentationId, controlChannel) {
presenterControlChannel = controlChannel;
Assert.equal(deviceInfo.id, pcs.id, 'expected device id');
Assert.equal(deviceInfo.address, '127.0.0.1', 'expected device address');
Assert.equal(url, 'http://example.com', 'expected url');
Assert.equal(presentationId, 'testPresentationId', 'expected presentation id');
Assert.equal(deviceInfo.id, pcs.id, "expected device id");
Assert.equal(deviceInfo.address, "127.0.0.1", "expected device address");
Assert.equal(url, "http://example.com", "expected url");
Assert.equal(presentationId, "testPresentationId", "expected presentation id");
presenterControlChannel.listener = {
status: 'created',
onOffer: function(aOffer) {
Assert.equal(this.status, 'opened', '1. presenterControlChannel: get offer, send answer');
this.status = 'onOffer';
status: "created",
onOffer(aOffer) {
Assert.equal(this.status, "opened", "1. presenterControlChannel: get offer, send answer");
this.status = "onOffer";
let offer = aOffer.QueryInterface(Ci.nsIPresentationChannelDescription);
Assert.strictEqual(offer.tcpAddress.queryElementAt(0,Ci.nsISupportsCString).data,
Assert.strictEqual(offer.tcpAddress.queryElementAt(0, Ci.nsISupportsCString).data,
OFFER_ADDRESS,
'expected offer address array');
Assert.equal(offer.tcpPort, OFFER_PORT, 'expected offer port');
"expected offer address array");
Assert.equal(offer.tcpPort, OFFER_PORT, "expected offer port");
try {
let tcpType = Ci.nsIPresentationChannelDescription.TYPE_TCP;
let answer = new TestDescription(tcpType, [ANSWER_ADDRESS], ANSWER_PORT);
presenterControlChannel.sendAnswer(answer);
} catch (e) {
Assert.ok(false, 'sending answer fails' + e);
Assert.ok(false, "sending answer fails" + e);
}
},
onAnswer: function(aAnswer) {
Assert.ok(false, 'get answer');
onAnswer(aAnswer) {
Assert.ok(false, "get answer");
},
onIceCandidate: function(aCandidate) {
Assert.ok(true, '3. presenterControlChannel: get ice candidate, close channel');
onIceCandidate(aCandidate) {
Assert.ok(true, "3. presenterControlChannel: get ice candidate, close channel");
let recvCandidate = JSON.parse(aCandidate);
for (let key in recvCandidate) {
if (typeof(recvCandidate[key]) !== "function") {
@ -116,22 +116,22 @@ function testPresentationServer() {
}
presenterControlChannel.disconnect(CLOSE_CONTROL_CHANNEL_REASON);
},
notifyConnected: function() {
Assert.equal(this.status, 'created', '0. presenterControlChannel: opened');
this.status = 'opened';
notifyConnected() {
Assert.equal(this.status, "created", "0. presenterControlChannel: opened");
this.status = "opened";
},
notifyDisconnected: function(aReason) {
Assert.equal(this.status, 'onOffer', '4. presenterControlChannel: closed');
Assert.equal(aReason, CLOSE_CONTROL_CHANNEL_REASON, 'presenterControlChannel notify closed');
this.status = 'closed';
notifyDisconnected(aReason) {
Assert.equal(this.status, "onOffer", "4. presenterControlChannel: closed");
Assert.equal(aReason, CLOSE_CONTROL_CHANNEL_REASON, "presenterControlChannel notify closed");
this.status = "closed";
yayFuncs.controllerControlChannelClose();
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlChannelListener]),
};
},
onReconnectRequest: function(deviceInfo, url, presentationId, controlChannel) {
Assert.equal(url, 'http://example.com', 'expected url');
Assert.equal(presentationId, 'testPresentationId', 'expected presentation id');
onReconnectRequest(deviceInfo, url, presentationId, controlChannel) {
Assert.equal(url, "http://example.com", "expected url");
Assert.equal(presentationId, "testPresentationId", "expected presentation id");
yayFuncs.presenterControlChannelReconnect();
},
@ -139,8 +139,8 @@ function testPresentationServer() {
};
let presenterDeviceInfo = {
id: 'presentatorID',
address: '127.0.0.1',
id: "presentatorID",
address: "127.0.0.1",
port: PRESENTER_CONTROL_CHANNEL_PORT,
certFingerprint: pcs.certFingerprint,
QueryInterface: ChromeUtils.generateQI([Ci.nsITCPDeviceInfo]),
@ -149,18 +149,18 @@ function testPresentationServer() {
let controllerControlChannel = pcs.connect(presenterDeviceInfo);
controllerControlChannel.listener = {
status: 'created',
onOffer: function(offer) {
Assert.ok(false, 'get offer');
status: "created",
onOffer(offer) {
Assert.ok(false, "get offer");
},
onAnswer: function(aAnswer) {
Assert.equal(this.status, 'opened', '2. controllerControlChannel: get answer, send ICE candidate');
onAnswer(aAnswer) {
Assert.equal(this.status, "opened", "2. controllerControlChannel: get answer, send ICE candidate");
let answer = aAnswer.QueryInterface(Ci.nsIPresentationChannelDescription);
Assert.strictEqual(answer.tcpAddress.queryElementAt(0,Ci.nsISupportsCString).data,
Assert.strictEqual(answer.tcpAddress.queryElementAt(0, Ci.nsISupportsCString).data,
ANSWER_ADDRESS,
'expected answer address array');
Assert.equal(answer.tcpPort, ANSWER_PORT, 'expected answer port');
"expected answer address array");
Assert.equal(answer.tcpPort, ANSWER_PORT, "expected answer port");
candidate = {
candidate: "1 1 UDP 1 127.0.0.1 34567 type host",
sdpMid: "helloworld",
@ -168,32 +168,32 @@ function testPresentationServer() {
};
controllerControlChannel.sendIceCandidate(JSON.stringify(candidate));
},
onIceCandidate: function(aCandidate) {
Assert.ok(false, 'get ICE candidate');
onIceCandidate(aCandidate) {
Assert.ok(false, "get ICE candidate");
},
notifyConnected: function() {
Assert.equal(this.status, 'created', '0. controllerControlChannel: opened, send offer');
controllerControlChannel.launch('testPresentationId', 'http://example.com');
this.status = 'opened';
notifyConnected() {
Assert.equal(this.status, "created", "0. controllerControlChannel: opened, send offer");
controllerControlChannel.launch("testPresentationId", "http://example.com");
this.status = "opened";
try {
let tcpType = Ci.nsIPresentationChannelDescription.TYPE_TCP;
let offer = new TestDescription(tcpType, [OFFER_ADDRESS], OFFER_PORT)
let offer = new TestDescription(tcpType, [OFFER_ADDRESS], OFFER_PORT);
controllerControlChannel.sendOffer(offer);
} catch (e) {
Assert.ok(false, 'sending offer fails:' + e);
Assert.ok(false, "sending offer fails:" + e);
}
},
notifyDisconnected: function(aReason) {
this.status = 'closed';
Assert.equal(aReason, CLOSE_CONTROL_CHANNEL_REASON, '4. controllerControlChannel notify closed');
notifyDisconnected(aReason) {
this.status = "closed";
Assert.equal(aReason, CLOSE_CONTROL_CHANNEL_REASON, "4. controllerControlChannel notify closed");
yayFuncs.presenterControlChannelClose();
let reconnectControllerControlChannel = pcs.connect(presenterDeviceInfo);
reconnectControllerControlChannel.listener = {
notifyConnected: function() {
reconnectControllerControlChannel.reconnect('testPresentationId', 'http://example.com');
notifyConnected() {
reconnectControllerControlChannel.reconnect("testPresentationId", "http://example.com");
},
notifyReconnected: function() {
notifyReconnected() {
yayFuncs.controllerControlChannelReconnect();
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlChannelListener]),
@ -204,43 +204,43 @@ function testPresentationServer() {
}
function terminateRequest() {
let yayFuncs = makeJointSuccess(['controllerControlChannelConnected',
'controllerControlChannelDisconnected',
'presenterControlChannelDisconnected',
'terminatedByController',
'terminatedByReceiver']);
let yayFuncs = makeJointSuccess(["controllerControlChannelConnected",
"controllerControlChannelDisconnected",
"presenterControlChannelDisconnected",
"terminatedByController",
"terminatedByReceiver"]);
let controllerControlChannel;
let terminatePhase = 'controller';
let terminatePhase = "controller";
pcs.listener = {
onTerminateRequest: function(deviceInfo, presentationId, controlChannel, isFromReceiver) {
Assert.equal(deviceInfo.address, '127.0.0.1', 'expected device address');
Assert.equal(presentationId, 'testPresentationId', 'expected presentation id');
onTerminateRequest(deviceInfo, presentationId, controlChannel, isFromReceiver) {
Assert.equal(deviceInfo.address, "127.0.0.1", "expected device address");
Assert.equal(presentationId, "testPresentationId", "expected presentation id");
controlChannel.terminate(presentationId); // Reply terminate ack.
if (terminatePhase === 'controller') {
if (terminatePhase === "controller") {
controllerControlChannel = controlChannel;
Assert.equal(deviceInfo.id, pcs.id, 'expected controller device id');
Assert.equal(isFromReceiver, false, 'expected request from controller');
Assert.equal(deviceInfo.id, pcs.id, "expected controller device id");
Assert.equal(isFromReceiver, false, "expected request from controller");
yayFuncs.terminatedByController();
controllerControlChannel.listener = {
notifyConnected: function() {
Assert.ok(true, 'control channel notify connected');
notifyConnected() {
Assert.ok(true, "control channel notify connected");
yayFuncs.controllerControlChannelConnected();
terminatePhase = 'receiver';
controllerControlChannel.terminate('testPresentationId');
terminatePhase = "receiver";
controllerControlChannel.terminate("testPresentationId");
},
notifyDisconnected: function(aReason) {
Assert.equal(aReason, CLOSE_CONTROL_CHANNEL_REASON, 'controllerControlChannel notify disconncted');
notifyDisconnected(aReason) {
Assert.equal(aReason, CLOSE_CONTROL_CHANNEL_REASON, "controllerControlChannel notify disconncted");
yayFuncs.controllerControlChannelDisconnected();
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlChannelListener]),
};
} else {
Assert.equal(deviceInfo.id, presenterDeviceInfo.id, 'expected presenter device id');
Assert.equal(isFromReceiver, true, 'expected request from receiver');
Assert.equal(deviceInfo.id, presenterDeviceInfo.id, "expected presenter device id");
Assert.equal(isFromReceiver, true, "expected request from receiver");
yayFuncs.terminatedByReceiver();
presenterControlChannel.disconnect(CLOSE_CONTROL_CHANNEL_REASON);
}
@ -249,8 +249,8 @@ function terminateRequest() {
};
let presenterDeviceInfo = {
id: 'presentatorID',
address: '127.0.0.1',
id: "presentatorID",
address: "127.0.0.1",
port: PRESENTER_CONTROL_CHANNEL_PORT,
certFingerprint: pcs.certFingerprint,
QueryInterface: ChromeUtils.generateQI([Ci.nsITCPDeviceInfo]),
@ -259,11 +259,11 @@ function terminateRequest() {
let presenterControlChannel = pcs.connect(presenterDeviceInfo);
presenterControlChannel.listener = {
notifyConnected: function() {
presenterControlChannel.terminate('testPresentationId');
notifyConnected() {
presenterControlChannel.terminate("testPresentationId");
},
notifyDisconnected: function(aReason) {
Assert.equal(aReason, CLOSE_CONTROL_CHANNEL_REASON, '4. presenterControlChannel notify disconnected');
notifyDisconnected(aReason) {
Assert.equal(aReason, CLOSE_CONTROL_CHANNEL_REASON, "4. presenterControlChannel notify disconnected");
yayFuncs.presenterControlChannelDisconnected();
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlChannelListener]),
@ -271,28 +271,28 @@ function terminateRequest() {
}
function terminateRequestAbnormal() {
let yayFuncs = makeJointSuccess(['controllerControlChannelConnected',
'controllerControlChannelDisconnected',
'presenterControlChannelDisconnected']);
let yayFuncs = makeJointSuccess(["controllerControlChannelConnected",
"controllerControlChannelDisconnected",
"presenterControlChannelDisconnected"]);
let controllerControlChannel;
pcs.listener = {
onTerminateRequest: function(deviceInfo, presentationId, controlChannel, isFromReceiver) {
Assert.equal(deviceInfo.id, pcs.id, 'expected controller device id');
Assert.equal(deviceInfo.address, '127.0.0.1', 'expected device address');
Assert.equal(presentationId, 'testPresentationId', 'expected presentation id');
Assert.equal(isFromReceiver, false, 'expected request from controller');
controlChannel.terminate('unmatched-presentationId'); // Reply abnormal terminate ack.
onTerminateRequest(deviceInfo, presentationId, controlChannel, isFromReceiver) {
Assert.equal(deviceInfo.id, pcs.id, "expected controller device id");
Assert.equal(deviceInfo.address, "127.0.0.1", "expected device address");
Assert.equal(presentationId, "testPresentationId", "expected presentation id");
Assert.equal(isFromReceiver, false, "expected request from controller");
controlChannel.terminate("unmatched-presentationId"); // Reply abnormal terminate ack.
controllerControlChannel = controlChannel;
controllerControlChannel.listener = {
notifyConnected: function() {
Assert.ok(true, 'control channel notify connected');
notifyConnected() {
Assert.ok(true, "control channel notify connected");
yayFuncs.controllerControlChannelConnected();
},
notifyDisconnected: function(aReason) {
Assert.equal(aReason, Cr.NS_ERROR_FAILURE, 'controllerControlChannel notify disconncted with error');
notifyDisconnected(aReason) {
Assert.equal(aReason, Cr.NS_ERROR_FAILURE, "controllerControlChannel notify disconncted with error");
yayFuncs.controllerControlChannelDisconnected();
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlChannelListener]),
@ -302,8 +302,8 @@ function terminateRequestAbnormal() {
};
let presenterDeviceInfo = {
id: 'presentatorID',
address: '127.0.0.1',
id: "presentatorID",
address: "127.0.0.1",
port: PRESENTER_CONTROL_CHANNEL_PORT,
certFingerprint: pcs.certFingerprint,
QueryInterface: ChromeUtils.generateQI([Ci.nsITCPDeviceInfo]),
@ -312,11 +312,11 @@ function terminateRequestAbnormal() {
let presenterControlChannel = pcs.connect(presenterDeviceInfo);
presenterControlChannel.listener = {
notifyConnected: function() {
presenterControlChannel.terminate('testPresentationId');
notifyConnected() {
presenterControlChannel.terminate("testPresentationId");
},
notifyDisconnected: function(aReason) {
Assert.equal(aReason, Cr.NS_ERROR_FAILURE, '4. presenterControlChannel notify disconnected with error');
notifyDisconnected(aReason) {
Assert.equal(aReason, Cr.NS_ERROR_FAILURE, "4. presenterControlChannel notify disconnected with error");
yayFuncs.presenterControlChannelDisconnected();
},
QueryInterface: ChromeUtils.generateQI([Ci.nsIPresentationControlChannelListener]),
@ -325,8 +325,8 @@ function terminateRequestAbnormal() {
function setOffline() {
pcs.listener = {
onServerReady: function(aPort, aCertFingerprint) {
Assert.notEqual(aPort, 0, 'TCPPresentationServer port changed and the port should be valid');
onServerReady(aPort, aCertFingerprint) {
Assert.notEqual(aPort, 0, "TCPPresentationServer port changed and the port should be valid");
pcs.close();
run_next_test();
},
@ -340,7 +340,7 @@ function setOffline() {
function oneMoreLoop() {
try {
pcs.listener = {
onServerReady: function() {
onServerReady() {
testPresentationServer();
}
};
@ -348,17 +348,16 @@ function oneMoreLoop() {
// Second run with TLS disabled.
pcs.startServer(false, PRESENTER_CONTROL_CHANNEL_PORT);
} catch (e) {
Assert.ok(false, 'TCP presentation init fail:' + e);
Assert.ok(false, "TCP presentation init fail:" + e);
run_next_test();
}
}
function shutdown()
{
function shutdown() {
pcs.listener = {
onServerReady: function(aPort, aCertFingerprint) {
Assert.ok(false, 'TCPPresentationServer port changed');
onServerReady(aPort, aCertFingerprint) {
Assert.ok(false, "TCPPresentationServer port changed");
},
};
pcs.close();