mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1074678 - Open a room window when the user selects the room in the Loop panel. r=mikedeboer
This commit is contained in:
parent
ffc3020035
commit
8a9f2df9f2
@ -166,6 +166,15 @@ let LoopRoomsInternal = {
|
||||
}, error => callback(error)).catch(error => callback(error));
|
||||
},
|
||||
|
||||
open: function(roomToken) {
|
||||
let windowData = {
|
||||
roomToken: roomToken,
|
||||
type: "room"
|
||||
};
|
||||
|
||||
MozLoopService.openChatWindow(windowData);
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback used to indicate changes to rooms data on the LoopServer.
|
||||
*
|
||||
@ -205,6 +214,10 @@ this.LoopRooms = {
|
||||
return LoopRoomsInternal.create(options, callback);
|
||||
},
|
||||
|
||||
open: function(roomToken) {
|
||||
return LoopRoomsInternal.open(roomToken);
|
||||
},
|
||||
|
||||
promise: function(method, ...params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this[method](...params, (error, result) => {
|
||||
|
@ -61,13 +61,7 @@ loop.store.ConversationAppStore = (function() {
|
||||
* @param {sharedActions.GetWindowData} actionData The action data
|
||||
*/
|
||||
getWindowData: function(actionData) {
|
||||
var windowData;
|
||||
// XXX Remove me in bug 1074678
|
||||
if (this._mozLoop.getLoopBoolPref("test.alwaysUseRooms")) {
|
||||
windowData = {type: "room", localRoomId: "42"};
|
||||
} else {
|
||||
windowData = this._mozLoop.getConversationWindowData(actionData.windowId);
|
||||
}
|
||||
var windowData = this._mozLoop.getConversationWindowData(actionData.windowId);
|
||||
|
||||
if (!windowData) {
|
||||
console.error("Failed to get the window data");
|
||||
|
@ -582,7 +582,9 @@ loop.panel = (function(_, mozL10n) {
|
||||
},
|
||||
|
||||
openRoom: function(room) {
|
||||
// XXX implement me; see bug 1074678
|
||||
this.props.dispatcher.dispatch(new sharedActions.OpenRoom({
|
||||
roomToken: room.roomToken
|
||||
}));
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
@ -582,7 +582,9 @@ loop.panel = (function(_, mozL10n) {
|
||||
},
|
||||
|
||||
openRoom: function(room) {
|
||||
// XXX implement me; see bug 1074678
|
||||
this.props.dispatcher.dispatch(new sharedActions.OpenRoom({
|
||||
roomToken: room.roomToken
|
||||
}));
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
@ -179,6 +179,14 @@ loop.shared.actions = (function() {
|
||||
*/
|
||||
UpdateRoomList: Action.define("updateRoomList", {
|
||||
roomList: Array
|
||||
}),
|
||||
|
||||
/**
|
||||
* Opens a room.
|
||||
* XXX: should move to some roomActions module - refs bug 1079284
|
||||
*/
|
||||
OpenRoom: Action.define("openRoom", {
|
||||
roomToken: String
|
||||
})
|
||||
};
|
||||
})();
|
||||
|
@ -71,25 +71,8 @@ loop.store.LocalRoomStore = (function() {
|
||||
},
|
||||
|
||||
/**
|
||||
* Proxy to mozLoop.rooms.getRoomData for setupEmptyRoom action.
|
||||
*
|
||||
* XXXremoveMe Can probably be removed when bug 1074664 lands.
|
||||
*
|
||||
* @param {Integer} roomId The id of the room.
|
||||
* @param {Function} cb Callback(error, roomData)
|
||||
*/
|
||||
_fetchRoomData: function(roomId, cb) {
|
||||
// XXX Remove me in bug 1074678
|
||||
if (!this.mozLoop.getLoopBoolPref("test.alwaysUseRooms")) {
|
||||
this.mozLoop.rooms.getRoomData(roomId, cb);
|
||||
} else {
|
||||
cb(null, {roomName: "Donkeys"});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute setupEmptyRoom event action from the dispatcher. This primes
|
||||
* the store with the localRoomId, and calls MozLoop.getRoomData on that
|
||||
* Execute setupWindowData event action from the dispatcher. This primes
|
||||
* the store with the roomToken, and calls MozLoop.getRoomData on that
|
||||
* ID. This will return either a reflection of state on the server, or,
|
||||
* if the createRoom call hasn't yet returned, it will have at least the
|
||||
* roomName as specified to the createRoom method.
|
||||
@ -105,11 +88,11 @@ loop.store.LocalRoomStore = (function() {
|
||||
return;
|
||||
}
|
||||
|
||||
this._fetchRoomData(actionData.localRoomId,
|
||||
this.mozLoop.rooms.get(actionData.roomToken,
|
||||
function(error, roomData) {
|
||||
this.setStoreState({
|
||||
error: error,
|
||||
localRoomId: actionData.localRoomId,
|
||||
roomToken: actionData.roomToken,
|
||||
serverData: roomData
|
||||
});
|
||||
}.bind(this));
|
||||
|
@ -328,6 +328,15 @@ loop.store = loop.store || {};
|
||||
rooms: this._processRoomList(actionData.roomList)
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Opens a room
|
||||
*
|
||||
* @param {sharedActions.OpenRoom} actionData The action data.
|
||||
*/
|
||||
openRoom: function(actionData) {
|
||||
this._mozLoop.rooms.open(actionData.roomToken);
|
||||
}
|
||||
}, Backbone.Events);
|
||||
|
||||
loop.store.RoomListStore = RoomListStore;
|
||||
|
@ -45,8 +45,6 @@ describe("loop.store.ConversationAppStore", function () {
|
||||
};
|
||||
|
||||
fakeMozLoop = {
|
||||
// XXX Remove me in bug 1074678
|
||||
getLoopBoolPref: function() { return false; },
|
||||
getConversationWindowData: function(windowId) {
|
||||
if (windowId === "42") {
|
||||
return fakeWindowData;
|
||||
|
@ -775,6 +775,20 @@ describe("loop.panel", function() {
|
||||
var buttonNode = view.getDOMNode().querySelector("button[disabled]");
|
||||
expect(buttonNode).to.not.equal(null);
|
||||
});
|
||||
|
||||
describe("#openRoom", function() {
|
||||
it("should dispatch an OpenRoom action", function() {
|
||||
var view = createTestComponent();
|
||||
var dispatch = sandbox.stub(dispatcher, "dispatch");
|
||||
|
||||
view.openRoom({roomToken: "42cba"});
|
||||
|
||||
sinon.assert.calledOnce(dispatch);
|
||||
sinon.assert.calledWithExactly(dispatch, new sharedActions.OpenRoom({
|
||||
roomToken: "42cba"
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('loop.panel.ToSView', function() {
|
||||
|
@ -32,20 +32,19 @@ describe("loop.store.LocalRoomStore", function () {
|
||||
});
|
||||
|
||||
describe("#setupWindowData", function() {
|
||||
var store, fakeMozLoop, fakeRoomId, fakeRoomName;
|
||||
var store, fakeMozLoop, fakeToken, fakeRoomName;
|
||||
|
||||
beforeEach(function() {
|
||||
fakeRoomId = "337-ff-54";
|
||||
fakeToken = "337-ff-54";
|
||||
fakeRoomName = "Monkeys";
|
||||
fakeMozLoop = {
|
||||
rooms: { getRoomData: sandbox.stub() },
|
||||
getLoopBoolPref: function () { return false; }
|
||||
rooms: { get: sandbox.stub() }
|
||||
};
|
||||
|
||||
store = new loop.store.LocalRoomStore(
|
||||
{mozLoop: fakeMozLoop, dispatcher: dispatcher});
|
||||
fakeMozLoop.rooms.getRoomData.
|
||||
withArgs(fakeRoomId).
|
||||
fakeMozLoop.rooms.get.
|
||||
withArgs(fakeToken).
|
||||
callsArgOnWith(1, // index of callback argument
|
||||
store, // |this| to call it on
|
||||
null, // args to call the callback with...
|
||||
@ -61,7 +60,7 @@ describe("loop.store.LocalRoomStore", function () {
|
||||
dispatcher.dispatch(new sharedActions.SetupWindowData({
|
||||
windowId: "42",
|
||||
type: "room",
|
||||
localRoomId: fakeRoomId
|
||||
roomToken: fakeToken
|
||||
}));
|
||||
});
|
||||
|
||||
@ -70,14 +69,14 @@ describe("loop.store.LocalRoomStore", function () {
|
||||
|
||||
store.once("change", function () {
|
||||
expect(store.getStoreState()).
|
||||
to.have.property('localRoomId', fakeRoomId);
|
||||
to.have.property('roomToken', fakeToken);
|
||||
done();
|
||||
});
|
||||
|
||||
dispatcher.dispatch(new sharedActions.SetupWindowData({
|
||||
windowId: "42",
|
||||
type: "room",
|
||||
localRoomId: fakeRoomId
|
||||
roomToken: fakeToken
|
||||
}));
|
||||
});
|
||||
|
||||
@ -93,7 +92,7 @@ describe("loop.store.LocalRoomStore", function () {
|
||||
dispatcher.dispatch(new sharedActions.SetupWindowData({
|
||||
windowId: "42",
|
||||
type: "room",
|
||||
localRoomId: fakeRoomId
|
||||
roomToken: fakeToken
|
||||
}));
|
||||
});
|
||||
|
||||
@ -101,8 +100,8 @@ describe("loop.store.LocalRoomStore", function () {
|
||||
function(done) {
|
||||
|
||||
var fakeError = new Error("fake error");
|
||||
fakeMozLoop.rooms.getRoomData.
|
||||
withArgs(fakeRoomId).
|
||||
fakeMozLoop.rooms.get.
|
||||
withArgs(fakeToken).
|
||||
callsArgOnWith(1, // index of callback argument
|
||||
store, // |this| to call it on
|
||||
fakeError); // args to call the callback with...
|
||||
@ -115,7 +114,7 @@ describe("loop.store.LocalRoomStore", function () {
|
||||
dispatcher.dispatch(new sharedActions.SetupWindowData({
|
||||
windowId: "42",
|
||||
type: "room",
|
||||
localRoomId: fakeRoomId
|
||||
roomToken: fakeToken
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -326,4 +326,27 @@ describe("loop.store.RoomListStore", function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#openRoom", function() {
|
||||
var store, fakeMozLoop;
|
||||
|
||||
beforeEach(function() {
|
||||
fakeMozLoop = {
|
||||
rooms: {
|
||||
open: sinon.spy()
|
||||
}
|
||||
};
|
||||
store = new loop.store.RoomListStore({
|
||||
dispatcher: dispatcher,
|
||||
mozLoop: fakeMozLoop
|
||||
});
|
||||
});
|
||||
|
||||
it("should open the room via mozLoop", function() {
|
||||
dispatcher.dispatch(new sharedActions.OpenRoom({roomToken: "42abc"}));
|
||||
|
||||
sinon.assert.calledOnce(fakeMozLoop.rooms.open);
|
||||
sinon.assert.calledWithExactly(fakeMozLoop.rooms.open, "42abc");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
Cu.import("resource://services-common/utils.js");
|
||||
Cu.import("resource:///modules/loop/LoopRooms.jsm");
|
||||
Cu.import("resource:///modules/Chat.jsm");
|
||||
|
||||
let openChatOrig = Chat.open;
|
||||
|
||||
const kRooms = new Map([
|
||||
["_nxD4V4FflQ", {
|
||||
@ -168,7 +171,30 @@ add_task(function* test_createRoom() {
|
||||
Assert.ok(eventCalled, "Event should have fired");
|
||||
});
|
||||
|
||||
add_task(function* test_openRoom() {
|
||||
let openedUrl;
|
||||
Chat.open = function(contentWindow, origin, title, url) {
|
||||
openedUrl = url;
|
||||
};
|
||||
|
||||
LoopRooms.open("fakeToken");
|
||||
|
||||
Assert.ok(openedUrl, "should open a chat window");
|
||||
|
||||
// Stop the busy kicking in for following tests.
|
||||
let windowId = openedUrl.match(/about:loopconversation\#(\d+)$/)[1];
|
||||
let windowData = MozLoopService.getConversationWindowData(windowId);
|
||||
|
||||
Assert.equal(windowData.type, "room", "window data should contain room as the type");
|
||||
Assert.equal(windowData.roomToken, "fakeToken", "window data should have the roomToken");
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
do_register_cleanup(function() {
|
||||
// Revert original Chat.open implementation
|
||||
Chat.open = openChatOrig;
|
||||
});
|
||||
|
||||
setupFakeLoopServer();
|
||||
|
||||
run_next_test();
|
||||
|
Loading…
Reference in New Issue
Block a user