Backed out 2 changesets (bug 1227539) for Win 7 M(bc4) and likely Win XP opt M(bc6) failures. r=backout

Backed out changeset 48d56e89c482 (bug 1227539)
Backed out changeset 0fbd239d0c37 (bug 1227539)
This commit is contained in:
Sebastian Hengst 2015-12-16 23:33:08 +01:00
parent 5c2f270233
commit 8007ffbe98
19 changed files with 109 additions and 287 deletions

View File

@ -718,7 +718,7 @@ var LoopRoomsInternal = {
eventEmitter.emit("open", roomToken);
return MozLoopService.openChatWindow(windowData, () => {
MozLoopService.openChatWindow(windowData, () => {
eventEmitter.emit("close");
});
},

View File

@ -123,7 +123,7 @@ const updateSocialProvidersCache = function() {
};
var gAppVersionInfo = null;
var gBrowserSharingListeners = new Set();
var gBrowserSharingListenerCount = 0;
var gBrowserSharingWindows = new Set();
var gPageListeners = null;
var gOriginalPageListeners = null;
@ -141,12 +141,10 @@ const kMessageHandlers = {
/**
* Start browser sharing, which basically means to start listening for tab
* switches and passing the new window ID to the sender whenever that happens.
*
*
* @param {Object} message Message meant for the handler function, containing
* the following parameters in its `data` property:
* [
* {Number} windowId The window ID of the chat window
* ]
* [ ]
* @param {Function} reply Callback function, invoked with the result of this
* message handler. The result will be sent back to
* the senders' channel.
@ -171,13 +169,10 @@ const kMessageHandlers = {
return;
}
let [windowId] = message.data;
win.LoopUI.startBrowserSharing();
gBrowserSharingWindows.add(Cu.getWeakReference(win));
gBrowserSharingListeners.add(windowId);
reply();
++gBrowserSharingListenerCount;
},
/**
@ -238,14 +233,13 @@ const kMessageHandlers = {
* message handler. The result will be sent back to
* the senders' channel.
*/
ComposeEmail: function(message, reply) {
ComposeEmail: function(message) {
let [subject, body, recipient] = message.data;
recipient = recipient || "";
let mailtoURL = "mailto:" + encodeURIComponent(recipient) +
"?subject=" + encodeURIComponent(subject) +
"&body=" + encodeURIComponent(body);
extProtocolSvc.loadURI(CommonUtils.makeURI(mailtoURL));
reply();
},
/**
@ -369,7 +363,6 @@ const kMessageHandlers = {
TWO_WAY_MEDIA_CONN_LENGTH: TWO_WAY_MEDIA_CONN_LENGTH
});
},
/**
* Returns the app version information for use during feedback.
*
@ -693,46 +686,9 @@ const kMessageHandlers = {
/**
* Hangup and close all chat windows that are open.
*
* @param {Object} message Message meant for the handler function, containing
* the following parameters in its `data` property:
* [ ]
* @param {Function} reply Callback function, invoked with the result of this
* message handler. The result will be sent back to
* the senders' channel.
*/
HangupAllChatWindows: function(message, reply) {
HangupAllChatWindows: function() {
MozLoopService.hangupAllChatWindows();
reply();
},
/**
* Hangup a specific chay window or room, by leaving a room, resetting the
* screensharing state and removing any active browser switch listeners.
*
* @param {Object} message Message meant for the handler function, containing
* the following parameters in its `data` property:
* [
* {String} roomToken The token of the room to leave
* {Number} windowId The window ID of the chat window
* ]
* @param {Function} reply Callback function, invoked with the result of this
* message handler. The result will be sent back to
* the senders' channel.
*/
HangupNow: function(message, reply) {
let [roomToken, sessionToken, windowId] = message.data;
if (!windowId) {
windowId = sessionToken;
}
LoopRooms.leave(roomToken);
MozLoopService.setScreenShareState(windowId, false);
LoopAPI.sendMessageToHandler({
name: "RemoveBrowserSharingListener",
data: [windowId]
});
reply();
},
/**
@ -859,7 +815,6 @@ const kMessageHandlers = {
let win = Services.wm.getMostRecentWindow("navigator:browser");
let url = message.data[0] ? message.data[0] : "about:home";
win.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no,non-remote", url);
reply();
},
/**
@ -882,27 +837,14 @@ const kMessageHandlers = {
/**
* Removes a listener that was previously added.
*
* @param {Object} message Message meant for the handler function, containing
* the following parameters in its `data` property:
* [
* {Number} windowId The window ID of the chat
* ]
* @param {Function} reply Callback function, invoked with the result of this
* message handler. The result will be sent back to
* the senders' channel.
*/
RemoveBrowserSharingListener: function(message, reply) {
if (!gBrowserSharingListeners.size) {
reply();
RemoveBrowserSharingListener: function() {
if (!gBrowserSharingListenerCount) {
return;
}
let [windowId] = message.data;
gBrowserSharingListeners.delete(windowId);
if (gBrowserSharingListeners.size > 0) {
if (--gBrowserSharingListenerCount > 0) {
// There are still clients listening in, so keep on listening...
reply();
return;
}
@ -915,7 +857,6 @@ const kMessageHandlers = {
}
gBrowserSharingWindows.clear();
reply();
},
"Rooms:*": function(action, message, reply) {
@ -1001,10 +942,9 @@ const kMessageHandlers = {
* message handler. The result will be sent back to
* the senders' channel.
*/
SetScreenShareState: function(message, reply) {
SetScreenShareState: function(message) {
let [windowId, active] = message.data;
MozLoopService.setScreenShareState(windowId, active);
reply();
},
/**
@ -1374,46 +1314,6 @@ this.LoopAPI = Object.freeze({
destroy: function() {
LoopAPIInternal.destroy();
},
/**
* Gateway for chrome scripts to send a message to a message handler, when
* using the RemotePageManager module is not an option.
*
* @param {Object} message Message meant for the handler function, containing
* the following properties:
* - {String} name Name of handler to send this
* message to. See `kMessageHandlers`
* for the available names.
* - {String} [action] Optional action name of the
* function to call on a sub-API.
* - {Array} data List of arguments that the
* handler can use.
* @param {Function} [reply] Callback function, invoked with the result of this
* message handler. Optional.
*/
sendMessageToHandler: function(message, reply) {
reply = reply || function() {};
let handlerName = message.name;
let handler = kMessageHandlers[handlerName];
if (gStubbedMessageHandlers && gStubbedMessageHandlers[handlerName]) {
handler = gStubbedMessageHandlers[handlerName];
}
if (!handler) {
let msg = "Ouch, no message handler available for '" + handlerName + "'";
MozLoopService.log.error(msg);
reply(cloneableError(msg));
return;
}
if (!message.data) {
message.data = [];
}
if (handlerName.endsWith("*")) {
handler(message.action, message, reply);
} else {
handler(message, reply);
}
},
// The following functions are only used in unit tests.
inspect: function() {
return [Object.create(LoopAPIInternal), Object.create(kMessageHandlers),

View File

@ -953,10 +953,7 @@ var MozLoopServiceInternal = {
// NOTE: if you add something here, please also consider if something
// needs to be done on the content side as well (e.g.
// activeRoomStore#windowUnload).
LoopAPI.sendMessageToHandler({
name: "HangupNow",
data: [conversationWindowData.roomToken, windowId]
});
LoopRooms.leave(conversationWindowData.roomToken);
}
}
}
@ -1207,7 +1204,7 @@ var gServiceInitialized = false;
*/
this.MozLoopService = {
_DNSService: gDNSService,
_activeScreenShares: new Set(),
_activeScreenShares: [],
get channelIDs() {
// Channel ids that will be registered with the PushServer for notifications
@ -1925,10 +1922,11 @@ this.MozLoopService = {
*/
setScreenShareState: function(windowId, active) {
if (active) {
this._activeScreenShares.add(windowId);
this._activeScreenShares.push(windowId);
} else {
if (this._activeScreenShares.has(windowId)) {
this._activeScreenShares.delete(windowId);
var index = this._activeScreenShares.indexOf(windowId);
if (index != -1) {
this._activeScreenShares.splice(index, 1);
}
}
@ -1939,6 +1937,6 @@ this.MozLoopService = {
* Returns true if screen sharing is active in at least one window.
*/
get screenShareActive() {
return this._activeScreenShares.size > 0;
return this._activeScreenShares.length > 0;
}
};

View File

@ -819,7 +819,7 @@ loop.panel = (function(_, mozL10n) {
loop.request("GetSelectedTabMetadata").then(function(metadata) {
// Bail out when the component is not mounted (anymore).
// This occurs during test runs. See bug 1174611 for more info.
if (!this.isMounted() || !metadata) {
if (!this.isMounted()) {
return;
}

View File

@ -819,7 +819,7 @@ loop.panel = (function(_, mozL10n) {
loop.request("GetSelectedTabMetadata").then(function(metadata) {
// Bail out when the component is not mounted (anymore).
// This occurs during test runs. See bug 1174611 for more info.
if (!this.isMounted() || !metadata) {
if (!this.isMounted()) {
return;
}

View File

@ -979,7 +979,7 @@ loop.store.ActiveRoomStore = (function() {
endScreenShare: function() {
if (this._browserSharingListener) {
// Remove the browser sharing listener as we don't need it now.
loop.request("RemoveBrowserSharingListener", this.getStoreState().windowId);
loop.request("RemoveBrowserSharingListener");
loop.unsubscribe("BrowserSwitch", this._browserSharingListener);
this._browserSharingListener = null;
}
@ -1117,8 +1117,13 @@ loop.store.ActiveRoomStore = (function() {
loop.standaloneMedia.multiplexGum.reset();
}
var requests = [
["SetScreenShareState", this.getStoreState().windowId, false]
];
if (this._browserSharingListener) {
// Remove the browser sharing listener as we don't need it now.
requests.push(["RemoveBrowserSharingListener"]);
loop.unsubscribe("BrowserSwitch", this._browserSharingListener);
this._browserSharingListener = null;
}
@ -1140,15 +1145,17 @@ loop.store.ActiveRoomStore = (function() {
delete this._timeout;
}
// If we're not going to close the window, we can hangup the call ourselves.
// NOTE: when the window _is_ closed, hanging up the call is performed by
// MozLoopService, because we can't get a message across to LoopAPI
// in time whilst a window is closing.
if ((nextState === ROOM_STATES.FAILED || !this._isDesktop) && !failedJoinRequest) {
loop.request("HangupNow", this._storeState.roomToken,
this._storeState.sessionToken, this._storeState.windowId);
if (!failedJoinRequest &&
(this._storeState.roomState === ROOM_STATES.JOINING ||
this._storeState.roomState === ROOM_STATES.JOINED ||
this._storeState.roomState === ROOM_STATES.SESSION_CONNECTED ||
this._storeState.roomState === ROOM_STATES.HAS_PARTICIPANTS)) {
requests.push(["Rooms:Leave", this._storeState.roomToken,
this._storeState.sessionToken]);
}
loop.requestMulti.apply(null, requests);
this.setStoreState({ roomState: nextState });
},

View File

@ -393,9 +393,6 @@ loop.shared.mixins = (function() {
console.error(error);
return;
}
if (!blob) {
return;
}
var url = URL.createObjectURL(blob);
this.audio = new Audio(url);
@ -414,7 +411,7 @@ loop.shared.mixins = (function() {
if (this._isLoopDesktop()) {
loop.request("GetAudioBlob", name).then(function(result) {
if (result && result.isError) {
if (result.isError) {
callback(result);
return;
}

View File

@ -255,13 +255,6 @@ loop.StandaloneMozLoop = (function(mozL10n) {
};
var kMessageHandlers = {
AddConversationContext: function() {},
HangupNow: function(data, reply) {
var roomToken = data[0];
var sessionToken = data[1];
StandaloneLoopRooms.leave(roomToken, sessionToken, reply);
},
"Rooms:*": function(action, data, reply) {
var funcName = action.split(":").pop();
funcName = funcName.charAt(0).toLowerCase() + funcName.substr(1);

View File

@ -8,6 +8,7 @@
"use strict";
const BASE_URL = Services.prefs.getCharPref("loop.server");
const { LoopAPI } = Cu.import("chrome://loop/content/modules/MozLoopAPI.jsm", {});
function* checkFxA401() {
let err = MozLoopService.errors.get("login");

View File

@ -2,6 +2,7 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { LoopAPI } = Cu.import("chrome://loop/content/modules/MozLoopAPI.jsm", {});
var [, gHandlers] = LoopAPI.inspect();
add_task(function* test_mozLoop_appVersionInfo() {

View File

@ -18,17 +18,22 @@ add_task(function* test_mozLoop_nochat() {
});
add_task(function* test_mozLoop_openchat() {
let windowId = LoopRooms.open("fake1234");
Assert.ok(isAnyLoopChatOpen(), "chat window should have been opened");
let windowData = {
roomToken: "fake1234",
type: "room"
};
let chatboxesForRoom = [...Chat.chatboxes].filter(chatbox => {
return chatbox.src == MozLoopServiceInternal.getChatURL(windowId);
});
Assert.strictEqual(chatboxesForRoom.length, 1, "Only one chatbox should be open");
LoopRooms.open(windowData);
Assert.ok(isAnyLoopChatOpen(), "chat window should have been opened");
});
add_task(function* test_mozLoop_hangupAllChatWindows() {
LoopRooms.open("fake2345");
let windowData = {
roomToken: "fake2345",
type: "room"
};
LoopRooms.open(windowData);
yield promiseWaitForCondition(() => {
MozLoopService.hangupAllChatWindows();
@ -37,30 +42,3 @@ add_task(function* test_mozLoop_hangupAllChatWindows() {
Assert.ok(!isAnyLoopChatOpen(), "chat window should have been closed");
});
add_task(function* test_mozLoop_hangupOnClose() {
let roomToken = "fake1234";
let hangupNowCalls = [];
LoopAPI.stubMessageHandlers({
HangupNow: function(message, reply) {
hangupNowCalls.push(message);
reply();
}
});
let windowId = LoopRooms.open(roomToken);
yield promiseWaitForCondition(() => {
MozLoopService.hangupAllChatWindows();
return !isAnyLoopChatOpen();
});
Assert.strictEqual(hangupNowCalls.length, 1, "HangupNow handler should be called once");
Assert.deepEqual(hangupNowCalls.pop(), {
name: "HangupNow",
data: [roomToken, windowId]
}, "Messages should be the same");
LoopAPI.restore();
});

View File

@ -7,6 +7,7 @@
*/
"use strict";
const { LoopAPI } = Cu.import("chrome://loop/content/modules/MozLoopAPI.jsm", {});
var [, gHandlers] = LoopAPI.inspect();
function promiseGetMetadata() {

View File

@ -6,15 +6,13 @@
*/
"use strict";
const { LoopAPI } = Cu.import("chrome://loop/content/modules/MozLoopAPI.jsm", {});
var [, gHandlers] = LoopAPI.inspect();
var handlers = [
{ windowId: null }, { windowId: null }
];
var listenerCount = 41;
var listenerIds = [];
function promiseWindowId() {
return new Promise(resolve => {
LoopAPI.stub([{
@ -26,8 +24,7 @@ function promiseWindowId() {
}
}
}]);
listenerIds.push(++listenerCount);
gHandlers.AddBrowserSharingListener({ data: [listenerCount] }, () => {});
gHandlers.AddBrowserSharingListener({}, () => {});
});
}
@ -81,7 +78,7 @@ add_task(function* test_singleListener() {
Assert.notEqual(initialWindowId, newWindowId, "Tab contentWindow IDs shouldn't be the same");
// Now remove the listener.
gHandlers.RemoveBrowserSharingListener({ data: [listenerIds.pop()] }, function() {});
gHandlers.RemoveBrowserSharingListener();
yield removeTabs();
});
@ -111,7 +108,7 @@ add_task(function* test_multipleListener() {
Assert.notEqual(initialWindowId0, newWindowId0, "Tab contentWindow IDs shouldn't be the same");
// Now remove the first listener.
gHandlers.RemoveBrowserSharingListener({ data: [listenerIds.pop()] }, function() {});
gHandlers.RemoveBrowserSharingListener();
// Check that a new tab updates the window id.
yield promiseWindowIdReceivedNewTab([handlers[1]]);
@ -124,7 +121,7 @@ add_task(function* test_multipleListener() {
Assert.notEqual(newWindowId1, nextWindowId1, "Second listener should have updated");
// Cleanup.
gHandlers.RemoveBrowserSharingListener({ data: [listenerIds.pop()] }, function() {});
gHandlers.RemoveBrowserSharingListener();
yield removeTabs();
});
@ -181,9 +178,7 @@ add_task(function* test_infoBar() {
Assert.equal(getInfoBar(), null, "The notification should still be hidden");
// Cleanup.
for (let listenerId of listenerIds) {
gHandlers.RemoveBrowserSharingListener({ data: [listenerId] }, function() {});
}
gHandlers.RemoveBrowserSharingListener();
yield removeTabs();
Services.prefs.clearUserPref(kPrefBrowserSharingInfoBar);
});

View File

@ -4,6 +4,7 @@
Cu.import("resource://gre/modules/Promise.jsm");
const { SocialService } = Cu.import("resource://gre/modules/SocialService.jsm", {});
const { LoopAPI } = Cu.import("chrome://loop/content/modules/MozLoopAPI.jsm", {});
var [, gHandlers] = LoopAPI.inspect();

View File

@ -7,6 +7,7 @@
"use strict";
const { LoopAPI } = Cu.import("chrome://loop/content/modules/MozLoopAPI.jsm", {});
var [, gHandlers] = LoopAPI.inspect();
var gConstants;
gHandlers.GetAllConstants({}, constants => gConstants = constants);

View File

@ -9,7 +9,6 @@ const {
MozLoopServiceInternal,
MozLoopService
} = Cu.import("chrome://loop/content/modules/MozLoopService.jsm", {});
const { LoopAPI } = Cu.import("chrome://loop/content/modules/MozLoopAPI.jsm", {});
const { LoopRooms } = Cu.import("chrome://loop/content/modules/LoopRooms.jsm", {});
// Cache this value only once, at the beginning of a

View File

@ -27,13 +27,13 @@ describe("loop.store.ActiveRoomStore", function() {
SetLoopPref: sinon.stub(),
AddConversationContext: sinon.stub(),
AddBrowserSharingListener: sinon.stub().returns(42),
HangupNow: sinon.stub(),
RemoveBrowserSharingListener: sinon.stub(),
"Rooms:Get": sinon.stub().returns({
roomUrl: "http://invalid"
}),
"Rooms:Join": sinon.stub().returns({}),
"Rooms:RefreshMembership": sinon.stub().returns({ expires: 42 }),
"Rooms:Leave": sinon.stub(),
"Rooms:SendConnectionStatus": sinon.stub(),
"Rooms:PushSubscription": sinon.stub(),
SetScreenShareState: sinon.stub(),
@ -95,8 +95,7 @@ describe("loop.store.ActiveRoomStore", function() {
store.setStoreState({
roomState: ROOM_STATES.JOINED,
roomToken: "fakeToken",
sessionToken: "1627384950",
windowId: "42"
sessionToken: "1627384950"
});
});
@ -179,6 +178,18 @@ describe("loop.store.ActiveRoomStore", function() {
sinon.assert.calledOnce(fakeMultiplexGum.reset);
});
it("should set screen sharing inactive", function() {
store.setStoreState({ windowId: "1234" });
store.roomFailure(new sharedActions.RoomFailure({
error: fakeError,
failedJoinRequest: false
}));
sinon.assert.calledOnce(requestStubs.SetScreenShareState);
sinon.assert.calledWithExactly(requestStubs.SetScreenShareState, "1234", false);
});
it("should disconnect from the servers via the sdk", function() {
store.roomFailure(new sharedActions.RoomFailure({
error: fakeError,
@ -201,8 +212,6 @@ describe("loop.store.ActiveRoomStore", function() {
});
it("should remove the sharing listener", function() {
sandbox.stub(loop, "unsubscribe");
// Setup the listener.
store.startBrowserShare(new sharedActions.StartBrowserShare());
@ -212,28 +221,27 @@ describe("loop.store.ActiveRoomStore", function() {
failedJoinRequest: false
}));
sinon.assert.calledOnce(loop.unsubscribe);
sinon.assert.calledWith(loop.unsubscribe, "BrowserSwitch");
sinon.assert.calledOnce(requestStubs.RemoveBrowserSharingListener);
});
it("should call 'HangupNow' Loop API", function() {
it("should call mozLoop.rooms.leave", function() {
store.roomFailure(new sharedActions.RoomFailure({
error: fakeError,
failedJoinRequest: false
}));
sinon.assert.calledOnce(requestStubs["HangupNow"]);
sinon.assert.calledWithExactly(requestStubs["HangupNow"],
"fakeToken", "1627384950", "42");
sinon.assert.calledOnce(requestStubs["Rooms:Leave"]);
sinon.assert.calledWithExactly(requestStubs["Rooms:Leave"],
"fakeToken", "1627384950");
});
it("should not call 'HangupNow' Loop API if failedJoinRequest is true", function() {
it("should not call mozLoop.rooms.leave if failedJoinRequest is true", function() {
store.roomFailure(new sharedActions.RoomFailure({
error: fakeError,
failedJoinRequest: true
}));
sinon.assert.notCalled(requestStubs["HangupNow"]);
sinon.assert.notCalled(requestStubs["Rooms:Leave"]);
});
});
@ -1207,8 +1215,7 @@ describe("loop.store.ActiveRoomStore", function() {
store.setStoreState({
roomState: ROOM_STATES.JOINED,
roomToken: "fakeToken",
sessionToken: "1627384950",
windowId: "42"
sessionToken: "1627384950"
});
connectionFailureAction = new sharedActions.ConnectionFailure({
@ -1228,6 +1235,15 @@ describe("loop.store.ActiveRoomStore", function() {
sinon.assert.calledOnce(fakeMultiplexGum.reset);
});
it("should set screen sharing inactive", function() {
store.setStoreState({ windowId: "1234" });
store.connectionFailure(connectionFailureAction);
sinon.assert.calledOnce(requestStubs.SetScreenShareState);
sinon.assert.calledWithExactly(requestStubs.SetScreenShareState, "1234", false);
});
it("should disconnect from the servers via the sdk", function() {
store.connectionFailure(connectionFailureAction);
@ -1243,25 +1259,22 @@ describe("loop.store.ActiveRoomStore", function() {
sinon.assert.calledOnce(clearTimeout);
});
it("should call 'HangupNow' Loop API", function() {
it("should call mozLoop.rooms.leave", function() {
store.connectionFailure(connectionFailureAction);
sinon.assert.calledOnce(requestStubs["HangupNow"]);
sinon.assert.calledWithExactly(requestStubs["HangupNow"],
"fakeToken", "1627384950", "42");
sinon.assert.calledOnce(requestStubs["Rooms:Leave"]);
sinon.assert.calledWithExactly(requestStubs["Rooms:Leave"],
"fakeToken", "1627384950");
});
it("should remove the sharing listener", function() {
sandbox.stub(loop, "unsubscribe");
// Setup the listener.
store.startBrowserShare(new sharedActions.StartBrowserShare());
// Now simulate connection failure.
store.connectionFailure(connectionFailureAction);
sinon.assert.calledOnce(loop.unsubscribe);
sinon.assert.calledWith(loop.unsubscribe, "BrowserSwitch");
sinon.assert.calledOnce(requestStubs.RemoveBrowserSharingListener);
});
it("should set the state to `FAILED`", function() {
@ -1807,36 +1820,33 @@ describe("loop.store.ActiveRoomStore", function() {
sinon.assert.calledOnce(clearTimeout);
});
it("should call 'HangupNow' Loop API", function() {
it("should call mozLoop.rooms.leave", function() {
store.windowUnload();
sinon.assert.calledOnce(requestStubs["HangupNow"]);
sinon.assert.calledWith(requestStubs["HangupNow"], "fakeToken",
"1627384950", "1234");
sinon.assert.calledOnce(requestStubs["Rooms:Leave"]);
sinon.assert.calledWithExactly(requestStubs["Rooms:Leave"],
"fakeToken", "1627384950");
});
it("should call 'HangupNow' Loop API if the room state is JOINING",
it("should call mozLoop.rooms.leave if the room state is JOINING",
function() {
store.setStoreState({ roomState: ROOM_STATES.JOINING });
store.windowUnload();
sinon.assert.calledOnce(requestStubs["HangupNow"]);
sinon.assert.calledWith(requestStubs["HangupNow"], "fakeToken",
"1627384950", "1234");
sinon.assert.calledOnce(requestStubs["Rooms:Leave"]);
sinon.assert.calledWithExactly(requestStubs["Rooms:Leave"],
"fakeToken", "1627384950");
});
it("should remove the sharing listener", function() {
sandbox.stub(loop, "unsubscribe");
// Setup the listener.
store.startBrowserShare(new sharedActions.StartBrowserShare());
// Now unload the window.
store.windowUnload();
sinon.assert.calledOnce(loop.unsubscribe);
sinon.assert.calledWith(loop.unsubscribe, "BrowserSwitch");
sinon.assert.calledOnce(requestStubs.RemoveBrowserSharingListener);
});
it("should set the state to CLOSING", function() {
@ -1876,32 +1886,22 @@ describe("loop.store.ActiveRoomStore", function() {
sinon.assert.calledOnce(clearTimeout);
});
it("should call 'HangupNow' Loop API", function() {
it("should call mozLoop.rooms.leave", function() {
store.leaveRoom();
sinon.assert.calledOnce(requestStubs["HangupNow"]);
sinon.assert.calledWith(requestStubs["HangupNow"], "fakeToken", "1627384950");
});
it("should not call 'HangupNow' Loop API when _isDesktop is true", function() {
store._isDesktop = true;
store.leaveRoom();
sinon.assert.notCalled(requestStubs["HangupNow"]);
sinon.assert.calledOnce(requestStubs["Rooms:Leave"]);
sinon.assert.calledWithExactly(requestStubs["Rooms:Leave"],
"fakeToken", "1627384950");
});
it("should remove the sharing listener", function() {
sandbox.stub(loop, "unsubscribe");
// Setup the listener.
store.startBrowserShare(new sharedActions.StartBrowserShare());
// Now leave the room.
store.leaveRoom();
sinon.assert.calledOnce(loop.unsubscribe);
sinon.assert.calledWith(loop.unsubscribe, "BrowserSwitch");
sinon.assert.calledOnce(requestStubs.RemoveBrowserSharingListener);
});
it("should set the state to ENDED", function() {

View File

@ -45,22 +45,6 @@ describe("loop.StandaloneMozLoop", function() {
});
});
describe("#hangupNow", function() {
it("should call rooms.leave", function() {
loop.request("HangupNow", "fakeToken", "fakeSessionToken");
expect(requests).to.have.length.of(1);
expect(requests[0].async).eql(false);
expect(requests[0].url).eql(fakeBaseServerUrl + "/rooms/fakeToken");
expect(requests[0].method).eql("POST");
expect(requests[0].requestHeaders.Authorization)
.eql("Basic " + btoa("fakeSessionToken"));
var requestData = JSON.parse(requests[0].requestBody);
expect(requestData.action).eql("leave");
});
});
describe("#setLoopPref", function() {
afterEach(function() {
localStorage.removeItem("fakePref");

View File

@ -60,40 +60,6 @@ add_test(function test_handleMessage() {
run_next_test();
});
add_test(function test_sendMessageToHandler() {
// Testing error branches.
LoopAPI.sendMessageToHandler({
name: "WellThisDoesNotExist"
}, err => {
Assert.ok(err.isError, "An error should be returned");
Assert.strictEqual(err.message,
"Ouch, no message handler available for 'WellThisDoesNotExist'",
"Error messages should match");
});
// Testing correct flow branches.
let hangupNowCalls = [];
LoopAPI.stubMessageHandlers({
HangupNow: function(message, reply) {
hangupNowCalls.push(message);
reply();
}
});
let message = {
name: "HangupNow",
data: ["fakeToken", 42]
};
LoopAPI.sendMessageToHandler(message);
Assert.strictEqual(hangupNowCalls.length, 1, "HangupNow handler should be called once");
Assert.deepEqual(hangupNowCalls.pop(), message, "Messages should be the same");
LoopAPI.restore();
run_next_test();
});
function run_test() {
do_register_cleanup(function() {
LoopAPI.destroy();