Bug 1105520 - Open Loop room conversation window right after it's created. r=mikedeboer
authorNicolas Perriault <nperriault@mozilla.com>
Thu, 27 Nov 2014 13:11:06 +0100
changeset 217905 67e4cff50baa6418715425088f138f2818f4fd10
parent 217862 02c38fde676cdf87066d13165c64c9c2ab7f490e
child 217906 95664554402d911899b20bf916e0e97b538938ad
push id27896
push userphilringnalda@gmail.com
push dateFri, 28 Nov 2014 01:33:57 +0000
treeherderautoland@63abc656b865 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1105520
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1105520 - Open Loop room conversation window right after it's created. r=mikedeboer
browser/components/loop/MozLoopAPI.jsm
browser/components/loop/content/shared/js/roomStore.js
browser/components/loop/test/shared/roomStore_test.js
--- a/browser/components/loop/MozLoopAPI.jsm
+++ b/browser/components/loop/MozLoopAPI.jsm
@@ -46,17 +46,17 @@ this.EXPORTED_SYMBOLS = ["injectLoopAPI"
  */
 const cloneErrorObject = function(error, targetWindow) {
   let obj = new targetWindow.Error();
   for (let prop of Object.getOwnPropertyNames(error)) {
     let value = error[prop];
     if (typeof value != "string" && typeof value != "number") {
       value = String(value);
     }
-    
+
     Object.defineProperty(Cu.waiveXrays(obj), prop, {
       configurable: false,
       enumerable: true,
       value: value,
       writable: false
     });
   }
   return obj;
@@ -110,16 +110,18 @@ const cloneValueInto = function(value, t
 const injectObjectAPI = function(api, targetWindow) {
   let injectedAPI = {};
   // Wrap all the methods in `api` to help results passed to callbacks get
   // through the priv => unpriv barrier with `Cu.cloneInto()`.
   Object.keys(api).forEach(func => {
     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.
       if (callbackIsFunction) {
         api[func](...params, function(...results) {
           // When the function was garbage collected due to async events, like
           // closing a window, we want to circumvent a JS error.
           if (callbackIsFunction && typeof lastParam != "function") {
@@ -129,16 +131,17 @@ const injectObjectAPI = function(api, ta
               MozLoopService.log.error(func + " error:", results[0]);
             }
             return;
           }
           lastParam(...[cloneValueInto(r, targetWindow) for (r of results)]);
         });
       } else {
         try {
+          lastParam = cloneValueInto(lastParam, api);
           return cloneValueInto(api[func](...params, lastParam), targetWindow);
         } catch (ex) {
           return cloneValueInto(ex, targetWindow);
         }
       }
     };
   });
 
--- a/browser/components/loop/content/shared/js/roomStore.js
+++ b/browser/components/loop/content/shared/js/roomStore.js
@@ -234,21 +234,26 @@ loop.store = loop.store || {};
 
       var roomCreationData = {
         roomName:  this._generateNewRoomName(actionData.nameTemplate),
         roomOwner: actionData.roomOwner,
         maxSize:   this.maxRoomCreationSize,
         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));
     },
 
     /**
      * Executed when a room creation error occurs.
      *
      * @param {sharedActions.CreateRoomError} actionData The action data.
      */
--- a/browser/components/loop/test/shared/roomStore_test.js
+++ b/browser/components/loop/test/shared/roomStore_test.js
@@ -75,16 +75,17 @@ describe("loop.store.RoomStore", functio
     };
 
     beforeEach(function() {
       fakeMozLoop = {
         copyString: function() {},
         rooms: {
           create: function() {},
           getAll: function() {},
+          open: function() {},
           on: sandbox.stub()
         }
       };
       store = new loop.store.RoomStore(dispatcher, {mozLoop: fakeMozLoop});
       store.setStoreState(defaultStoreState);
     });
 
     describe("MozLoop rooms event listeners", function() {
@@ -225,23 +226,38 @@ describe("loop.store.RoomStore", functio
         store.createRoom(new sharedActions.CreateRoom(fakeRoomCreationData));
 
         expect(store.getStoreState().pendingCreation).eql(true);
       });
 
       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() {
       it("should copy the room URL", function() {
         var copyString = sandbox.stub(fakeMozLoop, "copyString");
 
         store.copyRoomUrl(new sharedActions.CopyRoomUrl({
           roomUrl: "http://invalid"