Follow-up to bug 1099128 - fix issues with error values not being correctly handled by the room store, and switch the tests back to running with rooms enabled by default. r=nperriault a=lsblakk
authorMark Banner <standard8@mozilla.com>
Mon, 24 Nov 2014 21:39:57 +0000
changeset 234060 64f199adc34de3653eb4a714d3fe005958455fa5
parent 234059 b2c3adb502a601740fefd3b0f303657b650bbfb6
child 234061 44491e3dc7af1e20395b9620e1bb9a3520353838
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersnperriault, lsblakk
bugs1099128
milestone35.0a2
Follow-up to bug 1099128 - fix issues with error values not being correctly handled by the room store, and switch the tests back to running with rooms enabled by default. r=nperriault a=lsblakk
browser/components/loop/MozLoopService.jsm
browser/components/loop/content/shared/js/actions.js
browser/components/loop/test/mochitest/head.js
browser/components/loop/test/xpcshell/test_loopservice_token_validation.js
--- a/browser/components/loop/MozLoopService.jsm
+++ b/browser/components/loop/MozLoopService.jsm
@@ -328,18 +328,18 @@ let MozLoopServiceInternal = {
    * This should only be called from promiseRegisteredWithServers to prevent reentrancy.
    *
    * @param {LOOP_SESSION_TYPE} sessionType
    * @return {Promise} resolves with all push endpoints
    *                   rejects if any of the push registrations failed
    */
   promiseRegisteredWithPushServer: function(sessionType) {
     if (!this.deferredRegistrations.has(sessionType)) {
-      return Promise.reject("promiseRegisteredWithPushServer must be called while there is a " +
-                            "deferred in deferredRegistrations in order to prevent reentrancy");
+      return Promise.reject(new Error("promiseRegisteredWithPushServer must be called while there is a " +
+                            "deferred in deferredRegistrations in order to prevent reentrancy"));
     }
     // Wrap push notification registration call-back in a Promise.
     function registerForNotification(channelID, onNotification) {
       log.debug("registerForNotification", channelID);
       return new Promise((resolve, reject) => {
         function onRegistered(error, pushUrl) {
           log.debug("registerForNotification onRegistered:", error, pushUrl);
           if (error) {
@@ -375,17 +375,17 @@ let MozLoopServiceInternal = {
       let callsRegFxA = registerForNotification(MozLoopService.channelIDs.callsFxA,
                                                 LoopCalls.onNotification);
 
       let roomsRegFxA = registerForNotification(MozLoopService.channelIDs.roomsFxA,
                                                 roomsPushNotification);
       return Promise.all([callsRegFxA, roomsRegFxA]);
     }
 
-    return Promise.reject("promiseRegisteredWithPushServer: Invalid sessionType");
+    return Promise.reject(new Error("promiseRegisteredWithPushServer: Invalid sessionType"));
   },
 
   /**
    * Starts registration of Loop with the push server, and then will register
    * with the Loop server. It will return early if already registered.
    *
    * @param {LOOP_SESSION_TYPE} sessionType
    * @returns {Promise} a promise that is resolved with no params on completion, or
@@ -593,33 +593,33 @@ let MozLoopServiceInternal = {
       callsPushURL = this.pushHandler.registeredChannels[MozLoopService.channelIDs.callsFxA];
       roomsPushURL = this.pushHandler.registeredChannels[MozLoopService.channelIDs.roomsFxA];
     } else if (sessionType == LOOP_SESSION_TYPE.GUEST) {
       callsPushURL = this.pushHandler.registeredChannels[MozLoopService.channelIDs.callsGuest];
       roomsPushURL = this.pushHandler.registeredChannels[MozLoopService.channelIDs.roomsGuest];
     }
 
     if (!callsPushURL || !roomsPushURL) {
-      return Promise.reject("Invalid sessionType or missing push URLs for registerWithLoopServer: " + sessionType);
+      return Promise.reject(new Error("Invalid sessionType or missing push URLs for registerWithLoopServer: " + sessionType));
     }
 
     // create a registration payload with a backwards compatible attribute (simplePushURL)
     // that will register only the calls notification.
     let msg = {
         simplePushURL: callsPushURL,
         simplePushURLs: {
           calls: callsPushURL,
           rooms: roomsPushURL,
         },
     };
     return this.hawkRequestInternal(sessionType, "/registration", "POST", msg)
       .then((response) => {
         // If this failed we got an invalid token.
         if (!this.storeSessionToken(sessionType, response.headers)) {
-          return Promise.reject("session-token-wrong-size");
+          return Promise.reject(new Error("session-token-wrong-size"));
         }
 
         log.debug("Successfully registered with server for sessionType", sessionType);
         this.clearError("registration");
         return undefined;
       }, (error) => {
         // There's other errors than invalid auth token, but we should only do the reset
         // as a last resort.
@@ -1010,17 +1010,17 @@ this.MozLoopService = {
     Object.freeze(this);
 
     // Clear the old throttling mechanism.
     Services.prefs.clearUserPref("loop.throttled");
 
     // Don't do anything if loop is not enabled.
     if (!Services.prefs.getBoolPref("loop.enabled") ||
         Services.prefs.getBoolPref("loop.throttled2")) {
-      return Promise.reject("loop is not enabled");
+      return Promise.reject(new Error("loop is not enabled"));
     }
 
     if (Services.prefs.getPrefType("loop.fxa.enabled") == Services.prefs.PREF_BOOL) {
       gFxAEnabled = Services.prefs.getBoolPref("loop.fxa.enabled");
       if (!gFxAEnabled) {
         yield this.logOutFromFxA();
       }
     }
--- a/browser/components/loop/content/shared/js/actions.js
+++ b/browser/components/loop/content/shared/js/actions.js
@@ -220,17 +220,20 @@ loop.shared.actions = (function() {
     GetAllRooms: Action.define("getAllRooms", {
     }),
 
     /**
      * An error occured while trying to fetch the room list.
      * XXX: should move to some roomActions module - refs bug 1079284
      */
     GetAllRoomsError: Action.define("getAllRoomsError", {
-      error: Error
+      // There's two types of error possible - one thrown by our code (and Error)
+      // and the other is an Object about the error codes from the server as
+      // returned by the Hawk request.
+      error: [Error, Object]
     }),
 
     /**
      * Updates room list.
      * XXX: should move to some roomActions module - refs bug 1079284
      */
     UpdateRoomList: Action.define("updateRoomList", {
       roomList: Array
--- a/browser/components/loop/test/mochitest/head.js
+++ b/browser/components/loop/test/mochitest/head.js
@@ -72,21 +72,16 @@ function promiseGetMozLoopAPI() {
 
 /**
  * Loads the loop panel by clicking the button and waits for its open to complete.
  * It also registers
  *
  * This assumes that the tests are running in a generatorTest.
  */
 function loadLoopPanel(aOverrideOptions = {}) {
-  Services.prefs.setBoolPref("loop.rooms.enabled", false);
-  registerCleanupFunction(function() {
-     Services.prefs.clearUserPref("loop.rooms.enabled");
-  });
-
   // Set prefs to ensure we don't access the network externally.
   Services.prefs.setCharPref("services.push.serverURL", aOverrideOptions.pushURL || "ws://localhost/");
   Services.prefs.setCharPref("loop.server", aOverrideOptions.loopURL || "http://localhost/");
 
   // Turn off the network for loop tests, so that we don't
   // try to access the remote servers. If we want to turn this
   // back on in future, be careful to check for intermittent
   // failures.
--- a/browser/components/loop/test/xpcshell/test_loopservice_token_validation.js
+++ b/browser/components/loop/test/xpcshell/test_loopservice_token_validation.js
@@ -15,17 +15,17 @@ add_test(function test_registration_hand
     response.processAsync();
     response.finish();
   });
 
   MozLoopService.promiseRegisteredWithServers().then(() => {
     do_throw("should not succeed with a bogus token");
   }, err => {
 
-    Assert.equal(err, "session-token-wrong-size", "Should cause an error to be" +
+    Assert.equal(err.message, "session-token-wrong-size", "Should cause an error to be" +
       " called back if the session-token is not 64 characters long");
 
     // for some reason, Assert.throw is misbehaving, so....
     var ex;
     try {
       Services.prefs.getCharPref("loop.hawk-session-token");
     } catch (e) {
       ex = e;