Bug 1079656 - Make the Loop Account menu item work after a restart. r=jaws a=lmandel
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 13 Oct 2014 22:47:47 -0700
changeset 233362 ef87188cc41efd8380ac49632aefd3880790fd94
parent 233361 616f0c964391ce10ee1938d3b7a642822dc4ac31
child 233363 7907c5abdae0adb31da74c31de029030bdacbc73
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, lmandel
bugs1079656
milestone35.0a2
Bug 1079656 - Make the Loop Account menu item work after a restart. r=jaws a=lmandel
browser/components/loop/MozLoopService.jsm
browser/components/loop/test/mochitest/browser_fxa_login.js
--- a/browser/components/loop/MozLoopService.jsm
+++ b/browser/components/loop/MozLoopService.jsm
@@ -1600,21 +1600,31 @@ this.MozLoopService = {
 
     // clearError calls notifyStatusChanged so should be done last when the
     // state is clean.
     MozLoopServiceInternal.clearError("registration");
     MozLoopServiceInternal.clearError("login");
     MozLoopServiceInternal.clearError("profile");
   }),
 
-  openFxASettings: function() {
-    let url = new URL("/settings", gFxAOAuthClient.parameters.content_uri);
-    let win = Services.wm.getMostRecentWindow("navigator:browser");
-    win.switchToTabHavingURI(url.toString(), true);
-  },
+  openFxASettings: Task.async(function() {
+    try {
+      let fxAOAuthClient = yield MozLoopServiceInternal.promiseFxAOAuthClient();
+      if (!fxAOAuthClient) {
+        log.error("Could not get the OAuth client");
+        return;
+      }
+
+      let url = new URL("/settings", fxAOAuthClient.parameters.content_uri);
+      let win = Services.wm.getMostRecentWindow("navigator:browser");
+      win.switchToTabHavingURI(url.toString(), true);
+    } catch (ex) {
+      log.error("Error opening FxA settings", ex);
+    }
+  }),
 
   /**
    * Performs a hawk based request to the loop server.
    *
    * @param {LOOP_SESSION_TYPE} sessionType The type of session to use for the request.
    *                                        One of the LOOP_SESSION_TYPE members.
    * @param {String} path The path to make the request to.
    * @param {String} method The request method, e.g. 'POST', 'GET'.
--- a/browser/components/loop/test/mochitest/browser_fxa_login.js
+++ b/browser/components/loop/test/mochitest/browser_fxa_login.js
@@ -386,8 +386,46 @@ add_task(function* loginWithRegistration
   },
   error => {
     ise(error.code, 401, "Check error code");
     checkFxAOAuthTokenData(null);
   });
 
   yield checkFxA401();
 });
+
+add_task(function* openFxASettings() {
+  yield resetFxA();
+
+  // Since the default b-c window has a blank tab, open a new non-blank tab to
+  // force switchToTabHavingURI to open a new tab instead of reusing the current
+  // blank tab.
+  gBrowser.selectedTab = gBrowser.addTab(BASE_URL);
+
+  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 deferredTab = Promise.defer();
+  let progressListener = {
+    onLocationChange: function onLocationChange(aBrowser) {
+      gBrowser.removeTabsProgressListener(progressListener);
+      let contentURI = Services.io.newURI(params.content_uri, null, null);
+      is(aBrowser.currentURI.spec, Services.io.newURI("/settings", null, contentURI).spec,
+         "Check settings tab URL");
+      deferredTab.resolve();
+    },
+  };
+  gBrowser.addTabsProgressListener(progressListener);
+
+  MozLoopService.openFxASettings();
+
+  yield deferredTab.promise;
+  while (gBrowser.tabs.length > 1) {
+    gBrowser.removeTab(gBrowser.tabs[1]);
+  }
+});