Bug 1084362 When a third-party enters a room, stop displaying the ToS and privacy links in the Loop panel. r=nperriault a=lsblakk
authorMark Banner <standard8@mozilla.com>
Tue, 18 Nov 2014 20:50:56 +0000
changeset 233974 db16908a9a20ac9c3a64138c2c3dbbdbf37942cb
parent 233973 6453507eedd1e890d280dadfbf942d96e5891137
child 233975 2a62197daafe2b1b019ba6ec4def60072a5197a9
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersnperriault, lsblakk
bugs1084362
milestone35.0a2
Bug 1084362 When a third-party enters a room, stop displaying the ToS and privacy links in the Loop panel. r=nperriault a=lsblakk
browser/components/loop/content/shared/js/activeRoomStore.js
browser/components/loop/standalone/content/js/standaloneMozLoop.js
browser/components/loop/test/shared/activeRoomStore_test.js
browser/components/loop/test/standalone/standaloneMozLoop_test.js
--- a/browser/components/loop/content/shared/js/activeRoomStore.js
+++ b/browser/components/loop/content/shared/js/activeRoomStore.js
@@ -362,16 +362,19 @@ loop.store.ActiveRoomStore = (function()
 
     /**
      * Handles recording when a remote peer has connected to the servers.
      */
     remotePeerConnected: function() {
       this.setStoreState({
         roomState: ROOM_STATES.HAS_PARTICIPANTS
       });
+
+      // We've connected with a third-party, therefore stop displaying the ToS etc.
+      this._mozLoop.setLoopCharPref("seenToS", "seen");
     },
 
     /**
      * Handles a remote peer disconnecting from the session.
      */
     remotePeerDisconnected: function() {
       // As we only support two users at the moment, we just set this
       // back to joined.
--- a/browser/components/loop/standalone/content/js/standaloneMozLoop.js
+++ b/browser/components/loop/standalone/content/js/standaloneMozLoop.js
@@ -185,10 +185,38 @@ loop.StandaloneMozLoop = (function(mozL1
       throw new Error("missing required baseServerUrl");
     }
 
     this._baseServerUrl = options.baseServerUrl;
 
     this.rooms = new StandaloneMozLoopRooms(options);
   };
 
+  StandaloneMozLoop.prototype = {
+    /**
+     * Stores a preference in the local storage for standalone.
+     * Note: Some prefs are filtered out as they are not applicable
+     * to the standalone UI.
+     *
+     * @param {String} prefName The name of the pref
+     * @param {String} value The value to set.
+     */
+    setLoopCharPref: function(prefName, value) {
+      if (prefName === "seenToS") {
+        return;
+      }
+
+      localStorage.setItem(prefName, value);
+    },
+
+    /**
+     * Gets a preference from the local storage for standalone.
+     *
+     * @param {String} prefName The name of the pref
+     * @param {String} value The value to set.
+     */
+    getLoopCharPref: function(prefName) {
+      return localStorage.getItem(prefName);
+    }
+  };
+
   return StandaloneMozLoop;
 })(navigator.mozL10n);
--- a/browser/components/loop/test/shared/activeRoomStore_test.js
+++ b/browser/components/loop/test/shared/activeRoomStore_test.js
@@ -15,16 +15,17 @@ describe("loop.store.ActiveRoomStore", f
   beforeEach(function() {
     sandbox = sinon.sandbox.create();
     sandbox.useFakeTimers();
 
     dispatcher = new loop.Dispatcher();
     sandbox.stub(dispatcher, "dispatch");
 
     fakeMozLoop = {
+      setLoopCharPref: sandbox.stub(),
       rooms: {
         get: sinon.stub(),
         join: sinon.stub(),
         refreshMembership: sinon.stub(),
         leave: sinon.stub(),
         on: sinon.stub(),
         off: sinon.stub()
       }
@@ -515,16 +516,24 @@ describe("loop.store.ActiveRoomStore", f
   });
 
   describe("#remotePeerConnected", function() {
     it("should set the state to `HAS_PARTICIPANTS`", function() {
       store.remotePeerConnected();
 
       expect(store.getStoreState().roomState).eql(ROOM_STATES.HAS_PARTICIPANTS);
     });
+
+    it("should set the pref for ToS to `seen`", function() {
+      store.remotePeerConnected();
+
+      sinon.assert.calledOnce(fakeMozLoop.setLoopCharPref);
+      sinon.assert.calledWithExactly(fakeMozLoop.setLoopCharPref,
+        "seenToS", "seen");
+    });
   });
 
   describe("#remotePeerDisconnected", function() {
     it("should set the state to `SESSION_CONNECTED`", function() {
       store.remotePeerDisconnected();
 
       expect(store.getStoreState().roomState).eql(ROOM_STATES.SESSION_CONNECTED);
     });
--- a/browser/components/loop/test/standalone/standaloneMozLoop_test.js
+++ b/browser/components/loop/test/standalone/standaloneMozLoop_test.js
@@ -41,16 +41,46 @@ describe("loop.StandaloneMozLoop", funct
   describe("#constructor", function() {
     it("should require a baseServerUrl setting", function() {
       expect(function() {
         new loop.StandaloneMozLoop();
       }).to.Throw(Error, /required/);
     });
   });
 
+  describe("#setLoopCharPref", function() {
+    afterEach(function() {
+      localStorage.removeItem("fakePref");
+    });
+
+    it("should store the value of the preference", function() {
+      mozLoop.setLoopCharPref("fakePref", "fakeValue");
+
+      expect(localStorage.getItem("fakePref")).eql("fakeValue");
+    });
+
+    it("should not store the value of seenToS", function() {
+      mozLoop.setLoopCharPref("seenToS", "fakeValue1");
+
+      expect(localStorage.getItem("seenToS")).eql(null);
+    });
+  });
+
+  describe("#getLoopCharPref", function() {
+    afterEach(function() {
+      localStorage.removeItem("fakePref");
+    });
+
+    it("should return the value of the preference", function() {
+      localStorage.setItem("fakePref", "fakeValue");
+
+      expect(mozLoop.getLoopCharPref("fakePref")).eql("fakeValue");
+    });
+  });
+
   describe("#rooms.join", function() {
     it("should POST to the server", function() {
       mozLoop.rooms.join("fakeToken", callback);
 
       expect(requests).to.have.length.of(1);
       expect(requests[0].url).eql(fakeBaseServerUrl + "/rooms/fakeToken");
       expect(requests[0].method).eql("POST");