Bug 1101494 - Fix joining a room in guest mode. r=mikedeboer, a=lsblakk
authorMark Banner <standard8@mozilla.com>
Wed, 19 Nov 2014 20:05:56 +0000
changeset 235330 54ff7db0635f5b26bc13fa239e99e75737efa6eb
parent 235329 a41bd0a6c40cd7c72a48075c9d5927b3aa66b8c6
child 235331 6908b4d5326e8b60d6e94c18b450ad40c433ceeb
push id611
push userraliiev@mozilla.com
push dateMon, 05 Jan 2015 23:23:16 +0000
treeherdermozilla-release@345cd3b9c445 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer, lsblakk
bugs1101494
milestone35.0a2
Bug 1101494 - Fix joining a room in guest mode. r=mikedeboer, a=lsblakk
browser/components/loop/LoopRooms.jsm
browser/components/loop/test/xpcshell/test_looprooms.js
--- a/browser/components/loop/LoopRooms.jsm
+++ b/browser/components/loop/LoopRooms.jsm
@@ -1,25 +1,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
 const {MozLoopService, LOOP_SESSION_TYPE} = Cu.import("resource:///modules/loop/MozLoopService.jsm", {});
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
                                   "resource://gre/modules/Promise.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
                                   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyGetter(this, "eventEmitter", function() {
   const {EventEmitter} = Cu.import("resource://gre/modules/devtools/event-emitter.js", {});
   return new EventEmitter();
 });
+XPCOMUtils.defineLazyGetter(this, "gLoopBundle", function() {
+  return Services.strings.createBundle('chrome://browser/locale/loop/loop.properties');
+});
 
 this.EXPORTED_SYMBOLS = ["LoopRooms", "roomsPushNotification"];
 
 // The maximum number of clients that we support currently.
 const CLIENT_MAX_SIZE = 2;
 
 const roomsPushNotification = function(version, channelID) {
   return LoopRoomsInternal.onNotification(version, channelID);
@@ -322,19 +326,26 @@ let LoopRoomsInternal = {
    * Joins a room
    *
    * @param {String} roomToken  The room token.
    * @param {Function} callback Function that will be invoked once the operation
    *                            finished. The first argument passed will be an
    *                            `Error` object or `null`.
    */
   join: function(roomToken, callback) {
+    let displayName;
+    if (MozLoopService.userProfile && MozLoopService.userProfile.email) {
+      displayName = MozLoopService.userProfile.email;
+    } else {
+      displayName = gLoopBundle.GetStringFromName("display_name_guest");
+    }
+
     this._postToRoom(roomToken, {
       action: "join",
-      displayName: MozLoopService.userProfile.email,
+      displayName: displayName,
       clientMaxSize: CLIENT_MAX_SIZE
     }, callback);
   },
 
   /**
    * Refreshes a room
    *
    * @param {String} roomToken    The room token.
--- a/browser/components/loop/test/xpcshell/test_looprooms.js
+++ b/browser/components/loop/test/xpcshell/test_looprooms.js
@@ -333,29 +333,39 @@ add_task(function* test_roomUpdates() {
   gExpectedJoins["_nxD4V4FflQ"] = [
     "2a1787a6-4a73-43b5-ae3e-906ec1e763cb",
     "5de6281c-6568-455f-af08-c0b0a973100e"];
   roomsPushNotification("4");
   yield waitForCondition(() => Object.getOwnPropertyNames(gExpectedJoins).length === 0);
 });
 
 // Test if joining a room works as expected.
+add_task(function* test_joinRoomGuest() {
+  // We need these set up for getting the email address.
+  let roomToken = "_nxD4V4FflQ";
+  let joinedData = yield LoopRooms.promise("join", roomToken);
+  Assert.equal(joinedData.action, "join");
+});
+
 add_task(function* test_joinRoom() {
   // We need these set up for getting the email address.
   Services.prefs.setCharPref("loop.fxa_oauth.profile", JSON.stringify({
     email: "fake@invalid.com"
   }));
   Services.prefs.setCharPref("loop.fxa_oauth.tokendata", JSON.stringify({
     token_type: "bearer"
   }));
 
   let roomToken = "_nxD4V4FflQ";
   let joinedData = yield LoopRooms.promise("join", roomToken);
   Assert.equal(joinedData.action, "join");
   Assert.equal(joinedData.displayName, "fake@invalid.com");
+
+  Services.prefs.clearUserPref("loop.fxa_oauth.profile");
+  Services.prefs.clearUserPref("loop.fxa_oauth.tokendata");
 });
 
 // Test if refreshing a room works as expected.
 add_task(function* test_refreshMembership() {
   let roomToken = "_nxD4V4FflQ";
   let refreshedData = yield LoopRooms.promise("refreshMembership", roomToken,
     "fakeSessionToken");
   Assert.equal(refreshedData.action, "refresh");