Bug 1079656 - Make the Loop Account menu item work after a restart. r=jaws
--- 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]);
+ }
+});