Bug 1105520 - Open Loop room conversation window right after it's created. r=mikedeboer

This commit is contained in:
Nicolas Perriault
2014-11-27 13:11:06 +01:00
parent 5f2408c8b7
commit 5f109f5f7e
3 changed files with 27 additions and 3 deletions

View File

@@ -51,7 +51,7 @@ const cloneErrorObject = function(error, targetWindow) {
if (typeof value != "string" && typeof value != "number") {
value = String(value);
}
Object.defineProperty(Cu.waiveXrays(obj), prop, {
configurable: false,
enumerable: true,
@@ -115,6 +115,8 @@ const injectObjectAPI = function(api, targetWindow) {
injectedAPI[func] = function(...params) {
let lastParam = params.pop();
let callbackIsFunction = (typeof lastParam == "function");
// Clone params coming from content to the current scope.
params = [cloneValueInto(p, api) for (p of params)];
// If the last parameter is a function, assume its a callback
// and wrap it differently.
@@ -134,6 +136,7 @@ const injectObjectAPI = function(api, targetWindow) {
});
} else {
try {
lastParam = cloneValueInto(lastParam, api);
return cloneValueInto(api[func](...params, lastParam), targetWindow);
} catch (ex) {
return cloneValueInto(ex, targetWindow);

View File

@@ -239,11 +239,16 @@ loop.store = loop.store || {};
expiresIn: this.defaultExpiresIn
};
this._mozLoop.rooms.create(roomCreationData, function(err) {
this._mozLoop.rooms.create(roomCreationData, function(err, createdRoom) {
this.setStoreState({pendingCreation: false});
if (err) {
this.dispatchAction(new sharedActions.CreateRoomError({error: err}));
return;
}
// Opens the newly created room
this.dispatchAction(new sharedActions.OpenRoom({
roomToken: createdRoom.roomToken
}));
}.bind(this));
},

View File

@@ -80,6 +80,7 @@ describe("loop.store.RoomStore", function () {
rooms: {
create: function() {},
getAll: function() {},
open: function() {},
on: sandbox.stub()
}
};
@@ -230,13 +231,28 @@ describe("loop.store.RoomStore", function () {
it("should switch the pendingCreation state flag to false once the " +
"operation is done", function() {
sandbox.stub(fakeMozLoop.rooms, "create", function(data, cb) {
cb();
cb(null, {roomToken: "fakeToken"});
});
store.createRoom(new sharedActions.CreateRoom(fakeRoomCreationData));
expect(store.getStoreState().pendingCreation).eql(false);
});
it("should dispatch an OpenRoom action once the operation is done",
function() {
var dispatch = sandbox.stub(dispatcher, "dispatch");
sandbox.stub(fakeMozLoop.rooms, "create", function(data, cb) {
cb(null, {roomToken: "fakeToken"});
});
store.createRoom(new sharedActions.CreateRoom(fakeRoomCreationData));
sinon.assert.calledOnce(dispatch);
sinon.assert.calledWithExactly(dispatch, new sharedActions.OpenRoom({
roomToken: "fakeToken"
}));
});
});
describe("#copyRoomUrl", function() {