Bug 1110155 - Added minimal Loop room name validation. r=mikedeboer
authorNicolas Perriault <nperriault@mozilla.com>
Fri, 19 Dec 2014 15:22:39 +0100
changeset 220631 d9029ab107a801b2e95b5eb562bf8ea571eec5d5
parent 220630 6b6e49450b85eb7f74fc6a2afa73403265aabc70
child 220632 b052018cf239f73ec54b8f0f555ebc6f7ee6e824
child 220661 577fdd522d0c78ad1f9378d158b2d5455bbc31fd
push id27991
push userkwierso@gmail.com
push dateFri, 19 Dec 2014 23:43:54 +0000
treeherdermozilla-central@b052018cf239 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1110155
milestone37.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 1110155 - Added minimal Loop room name validation. r=mikedeboer
browser/components/loop/content/js/roomViews.js
browser/components/loop/content/js/roomViews.jsx
browser/components/loop/content/shared/js/roomStore.js
browser/components/loop/test/desktop-local/roomViews_test.js
browser/components/loop/test/shared/roomStore_test.js
--- a/browser/components/loop/content/js/roomViews.js
+++ b/browser/components/loop/content/js/roomViews.js
@@ -89,25 +89,20 @@ loop.roomViews = (function(mozL10n) {
       if (event.which === 13) {
         this.handleFormSubmit(event);
       }
     },
 
     handleFormSubmit: function(event) {
       event.preventDefault();
 
-      var newRoomName = this.state.newRoomName;
-
-      if (newRoomName && this.state.roomName != newRoomName) {
-        this.props.dispatcher.dispatch(
-          new sharedActions.RenameRoom({
-            roomToken: this.state.roomToken,
-            newRoomName: newRoomName
-          }));
-      }
+      this.props.dispatcher.dispatch(new sharedActions.RenameRoom({
+        roomToken: this.state.roomToken,
+        newRoomName: this.state.newRoomName
+      }));
     },
 
     handleEmailButtonClick: function(event) {
       event.preventDefault();
 
       this.props.dispatcher.dispatch(
         new sharedActions.EmailRoomUrl({roomUrl: this.state.roomUrl}));
     },
--- a/browser/components/loop/content/js/roomViews.jsx
+++ b/browser/components/loop/content/js/roomViews.jsx
@@ -89,25 +89,20 @@ loop.roomViews = (function(mozL10n) {
       if (event.which === 13) {
         this.handleFormSubmit(event);
       }
     },
 
     handleFormSubmit: function(event) {
       event.preventDefault();
 
-      var newRoomName = this.state.newRoomName;
-
-      if (newRoomName && this.state.roomName != newRoomName) {
-        this.props.dispatcher.dispatch(
-          new sharedActions.RenameRoom({
-            roomToken: this.state.roomToken,
-            newRoomName: newRoomName
-          }));
-      }
+      this.props.dispatcher.dispatch(new sharedActions.RenameRoom({
+        roomToken: this.state.roomToken,
+        newRoomName: this.state.newRoomName
+      }));
     },
 
     handleEmailButtonClick: function(event) {
       event.preventDefault();
 
       this.props.dispatcher.dispatch(
         new sharedActions.EmailRoomUrl({roomUrl: this.state.roomUrl}));
     },
--- a/browser/components/loop/content/shared/js/roomStore.js
+++ b/browser/components/loop/content/shared/js/roomStore.js
@@ -418,18 +418,25 @@ loop.store = loop.store || {};
     },
 
     /**
      * Renames a room.
      *
      * @param {sharedActions.RenameRoom} actionData
      */
     renameRoom: function(actionData) {
+      var newRoomName = actionData.newRoomName.trim();
+
+      // Skip update if name is unchanged or empty.
+      if (!newRoomName || this.getStoreState("roomName") === newRoomName) {
+        return;
+      }
+
       this.setStoreState({error: null});
-      this._mozLoop.rooms.rename(actionData.roomToken, actionData.newRoomName,
+      this._mozLoop.rooms.rename(actionData.roomToken, newRoomName,
         function(err) {
           if (err) {
             this.dispatchAction(new sharedActions.RenameRoomError({error: err}));
           }
         }.bind(this));
     },
 
     renameRoomError: function(actionData) {
--- a/browser/components/loop/test/desktop-local/roomViews_test.js
+++ b/browser/components/loop/test/desktop-local/roomViews_test.js
@@ -123,36 +123,40 @@ describe("loop.roomViews", function () {
       beforeEach(function() {
         view = mountTestComponent();
         view.setState({
           roomToken: "fakeToken",
           roomName: "fakeName"
         });
 
         roomNameBox = view.getDOMNode().querySelector('.input-room-name');
-
-        React.addons.TestUtils.Simulate.change(roomNameBox, { target: {
-          value: "reallyFake"
-        }});
       });
 
       it("should dispatch a RenameRoom action when the focus is lost",
         function() {
+          React.addons.TestUtils.Simulate.change(roomNameBox, { target: {
+            value: "reallyFake"
+          }});
+
           React.addons.TestUtils.Simulate.blur(roomNameBox);
 
           sinon.assert.calledOnce(dispatcher.dispatch);
           sinon.assert.calledWithExactly(dispatcher.dispatch,
             new sharedActions.RenameRoom({
               roomToken: "fakeToken",
               newRoomName: "reallyFake"
             }));
         });
 
       it("should dispatch a RenameRoom action when Enter key is pressed",
         function() {
+          React.addons.TestUtils.Simulate.change(roomNameBox, { target: {
+            value: "reallyFake"
+          }});
+
           TestUtils.Simulate.keyDown(roomNameBox, {key: "Enter", which: 13});
 
           sinon.assert.calledOnce(dispatcher.dispatch);
           sinon.assert.calledWithExactly(dispatcher.dispatch,
             new sharedActions.RenameRoom({
               roomToken: "fakeToken",
               newRoomName: "reallyFake"
             }));
--- a/browser/components/loop/test/shared/roomStore_test.js
+++ b/browser/components/loop/test/shared/roomStore_test.js
@@ -545,10 +545,21 @@ describe("loop.store.RoomStore", functio
 
       dispatcher.dispatch(new sharedActions.RenameRoom({
         roomToken: "42abc",
         newRoomName: "silly name"
       }));
 
       expect(store.getStoreState().error).eql(err);
     });
+
+    it("should ensure only submitting a non-empty room name", function() {
+      fakeMozLoop.rooms.rename = sinon.spy();
+
+      dispatcher.dispatch(new sharedActions.RenameRoom({
+        roomToken: "42abc",
+        newRoomName: " \t  \t "
+      }));
+
+      sinon.assert.notCalled(fakeMozLoop.rooms.rename);
+    });
   });
 });