Bug 1105347 If something goes wrong in a Loop room, ensure that devices are released and the room is left fully. r=nperriault
authorMark Banner <standard8@mozilla.com>
Wed, 26 Nov 2014 17:52:55 +0000
changeset 217684 6b28a301b9e9b73813c41285ec954941d9f01293
parent 217683 2f2f5bddfa605255c0149bcae9e709a29f111b55
child 217685 4ca1d6fffaf837eec33a760d76747fce9c868c85
push id27887
push userryanvm@gmail.com
push dateThu, 27 Nov 2014 02:08:38 +0000
treeherdermozilla-central@c63e741bca2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnperriault
bugs1105347
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 1105347 If something goes wrong in a Loop room, ensure that devices are released and the room is left fully. r=nperriault
browser/components/loop/content/shared/js/activeRoomStore.js
browser/components/loop/test/shared/activeRoomStore_test.js
--- a/browser/components/loop/content/shared/js/activeRoomStore.js
+++ b/browser/components/loop/content/shared/js/activeRoomStore.js
@@ -109,20 +109,21 @@ loop.store.ActiveRoomStore = (function()
         }
       }
 
       console.error("Error in state `" + this._storeState.roomState + "`:",
         actionData.error);
 
       this.setStoreState({
         error: actionData.error,
-        failureReason: getReason(actionData.error.errno),
-        roomState: actionData.error.errno === SERVER_CODES.ROOM_FULL ?
-          ROOM_STATES.FULL : ROOM_STATES.FAILED
+        failureReason: getReason(actionData.error.errno)
       });
+
+      this._leaveRoom(actionData.error.errno === SERVER_CODES.ROOM_FULL ?
+          ROOM_STATES.FULL : ROOM_STATES.FAILED);
     },
 
     /**
      * Registers the actions with the dispatcher that this store is interested
      * in after the initial setup has been performed.
      */
     _registerPostSetupActions: function() {
       this.dispatcher.register(this, [
--- a/browser/components/loop/test/shared/activeRoomStore_test.js
+++ b/browser/components/loop/test/shared/activeRoomStore_test.js
@@ -72,26 +72,28 @@ describe("loop.store.ActiveRoomStore", f
     var fakeError;
 
     beforeEach(function() {
       sandbox.stub(console, "error");
 
       fakeError = new Error("fake");
 
       store.setStoreState({
-        roomState: ROOM_STATES.READY
+        roomState: ROOM_STATES.JOINED,
+        roomToken: "fakeToken",
+        sessionToken: "1627384950"
       });
     });
 
     it("should log the error", function() {
       store.roomFailure({error: fakeError});
 
       sinon.assert.calledOnce(console.error);
       sinon.assert.calledWith(console.error,
-        sinon.match(ROOM_STATES.READY), fakeError);
+        sinon.match(ROOM_STATES.JOINED), fakeError);
     });
 
     it("should set the state to `FULL` on server error room full", function() {
       fakeError.errno = SERVER_CODES.ROOM_FULL;
 
       store.roomFailure({error: fakeError});
 
       expect(store._storeState.roomState).eql(ROOM_STATES.FULL);
@@ -118,16 +120,45 @@ describe("loop.store.ActiveRoomStore", f
       "expired", function() {
         fakeError.errno = SERVER_CODES.EXPIRED;
 
         store.roomFailure({error: fakeError});
 
         expect(store._storeState.roomState).eql(ROOM_STATES.FAILED);
         expect(store._storeState.failureReason).eql(FAILURE_REASONS.EXPIRED_OR_INVALID);
       });
+
+    it("should reset the multiplexGum", function() {
+      store.roomFailure({error: fakeError});
+
+      sinon.assert.calledOnce(fakeMultiplexGum.reset);
+    });
+
+    it("should disconnect from the servers via the sdk", function() {
+      store.roomFailure({error: fakeError});
+
+      sinon.assert.calledOnce(fakeSdkDriver.disconnectSession);
+    });
+
+    it("should clear any existing timeout", function() {
+      sandbox.stub(window, "clearTimeout");
+      store._timeout = {};
+
+      store.roomFailure({error: fakeError});
+
+      sinon.assert.calledOnce(clearTimeout);
+    });
+
+    it("should call mozLoop.rooms.leave", function() {
+      store.roomFailure({error: fakeError});
+
+      sinon.assert.calledOnce(fakeMozLoop.rooms.leave);
+      sinon.assert.calledWithExactly(fakeMozLoop.rooms.leave,
+        "fakeToken", "1627384950");
+    });
   });
 
   describe("#setupWindowData", function() {
     var fakeToken, fakeRoomData;
 
     beforeEach(function() {
       fakeToken = "337-ff-54";
       fakeRoomData = {
@@ -579,17 +610,17 @@ describe("loop.store.ActiveRoomStore", f
       store.setStoreState({
         roomState: ROOM_STATES.JOINED,
         roomToken: "fakeToken",
         sessionToken: "1627384950"
       });
     });
 
     it("should reset the multiplexGum", function() {
-      store.leaveRoom();
+      store.windowUnload();
 
       sinon.assert.calledOnce(fakeMultiplexGum.reset);
     });
 
     it("should disconnect from the servers via the sdk", function() {
       store.windowUnload();
 
       sinon.assert.calledOnce(fakeSdkDriver.disconnectSession);