Bug 1061756 - Remove MozLoopService #ifdef DEBUG and fix tests. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 04 Sep 2014 11:13:01 -0400
changeset 225330 282f7c4d08e1807d2b136b367644562b3e15649a
parent 225329 e7cfb34378deafa51eab9d052f8df47d4b1cbe14
child 225331 9919cec3771e1e2eb30d325d9e24f06e478cecaa
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1061756
milestone34.0a2
Bug 1061756 - Remove MozLoopService #ifdef DEBUG and fix tests. r=jaws
browser/components/loop/MozLoopService.jsm
browser/components/loop/moz.build
browser/components/loop/test/mochitest/browser.ini
browser/components/loop/test/mochitest/browser_fxa_login.js
browser/components/loop/test/mochitest/browser_toolbarbutton.js
browser/components/loop/test/mochitest/head.js
--- a/browser/components/loop/MozLoopService.jsm
+++ b/browser/components/loop/MozLoopService.jsm
@@ -622,33 +622,16 @@ let gInitializeTimerFunc = () => {
   },
   MozLoopServiceInternal.initialRegistrationDelayMilliseconds, Ci.nsITimer.TYPE_ONE_SHOT);
 };
 
 /**
  * Public API
  */
 this.MozLoopService = {
-#ifdef DEBUG
-  // Test-only helpers
-  get internal() {
-    return MozLoopServiceInternal;
-  },
-
-  get gFxAOAuthTokenData() {
-    return gFxAOAuthTokenData;
-  },
-
-  resetFxA: function() {
-    gFxAOAuthClientPromise = null;
-    gFxAOAuthClient = null;
-    gFxAOAuthTokenData = null;
-  },
-#endif
-
   _DNSService: gDNSService,
 
   set initializeTimerFunc(value) {
     gInitializeTimerFunc = value;
   },
 
   /**
    * Initialized the loop service, and starts registration with the
--- a/browser/components/loop/moz.build
+++ b/browser/components/loop/moz.build
@@ -13,14 +13,11 @@ BROWSER_CHROME_MANIFESTS += [
 ]
 
 EXTRA_JS_MODULES.loop += [
     'CardDavImporter.jsm',
     'LoopContacts.jsm',
     'LoopStorage.jsm',
     'MozLoopAPI.jsm',
     'MozLoopPushHandler.jsm',
+    'MozLoopService.jsm',
     'MozLoopWorker.js',
 ]
-
-EXTRA_PP_JS_MODULES.loop += [
-    'MozLoopService.jsm',
-]
--- a/browser/components/loop/test/mochitest/browser.ini
+++ b/browser/components/loop/test/mochitest/browser.ini
@@ -1,17 +1,17 @@
 [DEFAULT]
 support-files =
     head.js
     loop_fxa.sjs
     ../../../../base/content/test/general/browser_fxa_oauth.html
 
 [browser_CardDavImporter.js]
 [browser_fxa_login.js]
-skip-if = !debug
++skip-if = e10s
 [browser_loop_fxa_server.js]
 [browser_LoopContacts.js]
 [browser_mozLoop_appVersionInfo.js]
 [browser_mozLoop_prefs.js]
 [browser_mozLoop_doNotDisturb.js]
 [browser_mozLoop_softStart.js]
 skip-if = buildapp == 'mulet'
 [browser_toolbarbutton.js]
--- a/browser/components/loop/test/mochitest/browser_fxa_login.js
+++ b/browser/components/loop/test/mochitest/browser_fxa_login.js
@@ -2,16 +2,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Test FxA logins with Loop.
  */
 
 "use strict";
 
+const gFxAOAuthTokenData = Cu.import("resource:///modules/loop/MozLoopService.jsm", {}).gFxAOAuthTokenData;
 const BASE_URL = "http://mochi.test:8888/browser/browser/components/loop/test/mochitest/loop_fxa.sjs?";
 
 add_task(function* setup() {
   Services.prefs.setCharPref("loop.server", BASE_URL);
   Services.prefs.setCharPref("services.push.serverURL", "ws://localhost/");
   registerCleanupFunction(function* () {
     info("cleanup time");
     yield promiseDeletedOAuthParams(BASE_URL);
@@ -24,188 +25,188 @@ add_task(function* checkOAuthParams() {
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
     profile_uri: BASE_URL + "/profile",
     state: "state",
   };
   yield promiseOAuthParamsSetup(BASE_URL, params);
-  let client = yield MozLoopService.internal.promiseFxAOAuthClient();
+  let client = yield MozLoopServiceInternal.promiseFxAOAuthClient();
   for (let key of Object.keys(params)) {
     ise(client.parameters[key], params[key], "Check " + key + " was passed to the OAuth client");
   }
 });
 
 add_task(function* basicAuthorization() {
-  let result = yield MozLoopService.internal.promiseFxAOAuthAuthorization();
+  let result = yield MozLoopServiceInternal.promiseFxAOAuthAuthorization();
   is(result.code, "code1", "Check code");
   is(result.state, "state", "Check state");
 });
 
 add_task(function* sameOAuthClientForTwoCalls() {
-  MozLoopService.resetFxA();
-  let client1 = yield MozLoopService.internal.promiseFxAOAuthClient();
-  let client2 = yield MozLoopService.internal.promiseFxAOAuthClient();
+  resetFxA();
+  let client1 = yield MozLoopServiceInternal.promiseFxAOAuthClient();
+  let client2 = yield MozLoopServiceInternal.promiseFxAOAuthClient();
   ise(client1, client2, "The same client should be returned");
 });
 
 add_task(function* paramsInvalid() {
-  MozLoopService.resetFxA();
+  resetFxA();
   // Delete the params so an empty object is returned.
   yield promiseDeletedOAuthParams(BASE_URL);
   let result = null;
   let loginPromise = MozLoopService.logInToFxA();
   let caught = false;
   yield loginPromise.catch(() => {
     ok(true, "The login promise should be rejected due to invalid params");
     caught = true;
   });
   ok(caught, "Should have caught the rejection");
   is(result, null, "No token data should be returned");
 });
 
 add_task(function* params_nonJSON() {
-  MozLoopService.resetFxA();
+  resetFxA();
   Services.prefs.setCharPref("loop.server", "https://loop.invalid");
   let result = null;
   let loginPromise = MozLoopService.logInToFxA();
   yield loginPromise.catch(() => {
     ok(true, "The login promise should be rejected due to non-JSON params");
   });
   is(result, null, "No token data should be returned");
   Services.prefs.setCharPref("loop.server", BASE_URL);
 });
 
 add_task(function* invalidState() {
-  MozLoopService.resetFxA();
+  resetFxA();
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
     profile_uri: BASE_URL + "/profile",
     state: "invalid_state",
   };
   yield promiseOAuthParamsSetup(BASE_URL, params);
   let loginPromise = MozLoopService.logInToFxA();
   yield loginPromise.catch((error) => {
     ok(error, "The login promise should be rejected due to invalid state");
   });
 });
 
 add_task(function* basicRegistration() {
-  MozLoopService.resetFxA();
+  resetFxA();
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
     profile_uri: BASE_URL + "/profile",
     state: "state",
   };
   yield promiseOAuthParamsSetup(BASE_URL, params);
 
-  let tokenData = yield MozLoopService.internal.promiseFxAOAuthToken("code1", "state");
+  let tokenData = yield MozLoopServiceInternal.promiseFxAOAuthToken("code1", "state");
   is(tokenData.access_token, "code1_access_token", "Check access_token");
   is(tokenData.scope, "profile", "Check scope");
   is(tokenData.token_type, "bearer", "Check token_type");
 });
 
 add_task(function* registrationWithInvalidState() {
-  MozLoopService.resetFxA();
+  resetFxA();
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
     profile_uri: BASE_URL + "/profile",
     state: "invalid_state",
   };
   yield promiseOAuthParamsSetup(BASE_URL, params);
 
-  let tokenPromise = MozLoopService.internal.promiseFxAOAuthToken("code1", "state");
+  let tokenPromise = MozLoopServiceInternal.promiseFxAOAuthToken("code1", "state");
   yield tokenPromise.then(body => {
     ok(false, "Promise should have rejected");
   },
   error => {
     is(error.code, 400, "Check error code");
   });
 });
 
 add_task(function* registrationWith401() {
-  MozLoopService.resetFxA();
+  resetFxA();
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
     profile_uri: BASE_URL + "/profile",
     state: "state",
     test_error: "token_401",
   };
   yield promiseOAuthParamsSetup(BASE_URL, params);
 
-  let tokenPromise = MozLoopService.internal.promiseFxAOAuthToken("code1", "state");
+  let tokenPromise = MozLoopServiceInternal.promiseFxAOAuthToken("code1", "state");
   yield tokenPromise.then(body => {
     ok(false, "Promise should have rejected");
   },
   error => {
     is(error.code, 401, "Check error code");
   });
 });
 
 add_task(function* basicAuthorizationAndRegistration() {
-  MozLoopService.resetFxA();
+  resetFxA();
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
     profile_uri: BASE_URL + "/profile",
     state: "state",
   };
   yield promiseOAuthParamsSetup(BASE_URL, params);
 
   let tokenData = yield MozLoopService.logInToFxA();
   ise(tokenData.access_token, "code1_access_token", "Check access_token");
   ise(tokenData.scope, "profile", "Check scope");
   ise(tokenData.token_type, "bearer", "Check token_type");
 });
 
 add_task(function* loginWithParams401() {
-  MozLoopService.resetFxA();
+  resetFxA();
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
     profile_uri: BASE_URL + "/profile",
     state: "state",
     test_error: "params_401",
   };
   yield promiseOAuthParamsSetup(BASE_URL, params);
 
   let loginPromise = MozLoopService.logInToFxA();
   yield loginPromise.then(tokenData => {
     ok(false, "Promise should have rejected");
   },
   error => {
     ise(error.code, 401, "Check error code");
-    ise(MozLoopService.gFxAOAuthTokenData, null, "Check there is no saved token data");
+    ise(gFxAOAuthTokenData, null, "Check there is no saved token data");
   });
 });
 
 add_task(function* loginWithRegistration401() {
-  MozLoopService.resetFxA();
+  resetFxA();
   let params = {
     client_id: "client_id",
     content_uri: BASE_URL + "/content",
     oauth_uri: BASE_URL + "/oauth",
     profile_uri: BASE_URL + "/profile",
     state: "state",
     test_error: "token_401",
   };
   yield promiseOAuthParamsSetup(BASE_URL, params);
 
   let loginPromise = MozLoopService.logInToFxA();
   yield loginPromise.then(tokenData => {
     ok(false, "Promise should have rejected");
   },
   error => {
     ise(error.code, 401, "Check error code");
-    ise(MozLoopService.gFxAOAuthTokenData, null, "Check there is no saved token data");
+    ise(gFxAOAuthTokenData, null, "Check there is no saved token data");
   });
 });
--- a/browser/components/loop/test/mochitest/browser_toolbarbutton.js
+++ b/browser/components/loop/test/mochitest/browser_toolbarbutton.js
@@ -2,19 +2,16 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Test the toolbar button states.
  */
 
 "use strict";
 
-const MozLoopServiceInternal = Cu.import("resource:///modules/loop/MozLoopService.jsm", {}).
-                               MozLoopServiceInternal;
-
 registerCleanupFunction(function*() {
   MozLoopService.doNotDisturb = false;
   yield MozLoopServiceInternal.clearError("testing");
 });
 
 add_task(function* test_doNotDisturb() {
   yield MozLoopService.doNotDisturb = true;
   Assert.strictEqual(LoopUI.toolbarButton.node.getAttribute("state"), "disabled", "Check button is in disabled state");
--- a/browser/components/loop/test/mochitest/head.js
+++ b/browser/components/loop/test/mochitest/head.js
@@ -1,11 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+const MozLoopServiceInternal = Cu.import("resource:///modules/loop/MozLoopService.jsm", {}).
+                               MozLoopServiceInternal;
+
 var gMozLoopAPI;
 
 function promiseGetMozLoopAPI() {
   let deferred = Promise.defer();
   let loopPanel = document.getElementById("loop-notification-panel");
   let btn = document.getElementById("loop-call-button");
 
   // Wait for the popup to be shown, then we can get the iframe and
@@ -86,16 +89,23 @@ function promiseOAuthParamsSetup(baseURL
   xhr.setRequestHeader("X-Params", JSON.stringify(params));
   xhr.addEventListener("load", () => deferred.resolve(xhr));
   xhr.addEventListener("error", error => deferred.reject(error));
   xhr.send();
 
   return deferred.promise;
 }
 
+function resetFxA() {
+  let global = Cu.import("resource:///modules/loop/MozLoopService.jsm", {});
+  global.gFxAOAuthClientPromise = null;
+  global.gFxAOAuthClient = null;
+  global.gFxAOAuthTokenData = null;
+}
+
 function promiseDeletedOAuthParams(baseURL) {
   let deferred = Promise.defer();
   let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
               createInstance(Ci.nsIXMLHttpRequest);
   xhr.open("DELETE", baseURL + "/setup_params", true);
   xhr.addEventListener("load", () => deferred.resolve(xhr));
   xhr.addEventListener("error", deferred.reject);
   xhr.send();