Bug 1112552 - Clean up global-scope pollution from browser-fxaccounts.js. r=dao

--HG--
extra : rebase_source : 17c65f8c9f40df6e1cd49f07a779b71b002a5e23
This commit is contained in:
abdelrhman 2014-12-22 15:14:17 +01:00
parent 12aff5740c
commit b1c1b6380c
2 changed files with 29 additions and 29 deletions

View File

@ -2,19 +2,12 @@
# 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/.
XPCOMUtils.defineLazyGetter(this, "FxAccountsCommon", function () {
return Cu.import("resource://gre/modules/FxAccountsCommon.js", {});
});
XPCOMUtils.defineLazyModuleGetter(this, "fxaMigrator",
"resource://services-sync/FxaMigrator.jsm");
const PREF_SYNC_START_DOORHANGER = "services.sync.ui.showSyncStartDoorhanger";
const DOORHANGER_ACTIVATE_DELAY_MS = 5000;
const SYNC_MIGRATION_NOTIFICATION_TITLE = "fxa-migration";
let gFxAccounts = {
PREF_SYNC_START_DOORHANGER: "services.sync.ui.showSyncStartDoorhanger",
DOORHANGER_ACTIVATE_DELAY_MS: 5000,
SYNC_MIGRATION_NOTIFICATION_TITLE: "fxa-migration",
_initialized: false,
_inCustomizationMode: false,
@ -34,8 +27,8 @@ let gFxAccounts = {
"weave:service:login:error",
"weave:service:setup-complete",
"fxa-migration:state-changed",
FxAccountsCommon.ONVERIFIED_NOTIFICATION,
FxAccountsCommon.ONLOGOUT_NOTIFICATION
this.FxAccountsCommon.ONVERIFIED_NOTIFICATION,
this.FxAccountsCommon.ONLOGOUT_NOTIFICATION
];
},
@ -108,8 +101,8 @@ let gFxAccounts = {
observe: function (subject, topic, data) {
switch (topic) {
case FxAccountsCommon.ONVERIFIED_NOTIFICATION:
Services.prefs.setBoolPref(PREF_SYNC_START_DOORHANGER, true);
case this.FxAccountsCommon.ONVERIFIED_NOTIFICATION:
Services.prefs.setBoolPref(this.PREF_SYNC_START_DOORHANGER, true);
break;
case "weave:service:sync:start":
this.onSyncStart();
@ -131,11 +124,11 @@ let gFxAccounts = {
let showDoorhanger = false;
try {
showDoorhanger = Services.prefs.getBoolPref(PREF_SYNC_START_DOORHANGER);
showDoorhanger = Services.prefs.getBoolPref(this.PREF_SYNC_START_DOORHANGER);
} catch (e) { /* The pref might not exist. */ }
if (showDoorhanger) {
Services.prefs.clearUserPref(PREF_SYNC_START_DOORHANGER);
Services.prefs.clearUserPref(this.PREF_SYNC_START_DOORHANGER);
this.showSyncStartedDoorhanger();
}
},
@ -155,7 +148,7 @@ let gFxAccounts = {
// a short delay. Without this delay the doorhanger would not show up
// or with a too small delay show up while we're still animating the
// window.
setTimeout(() => this.onSyncStart(), DOORHANGER_ACTIVATE_DELAY_MS);
setTimeout(() => this.onSyncStart(), this.DOORHANGER_ACTIVATE_DELAY_MS);
} else {
this._inCustomizationMode = event.type == "customizationstarting";
this.updateAppMenuItem();
@ -251,12 +244,12 @@ let gFxAccounts = {
let status = null;
let label = null;
switch (this._migrationInfo.state) {
case fxaMigrator.STATE_USER_FXA:
case this.fxaMigrator.STATE_USER_FXA:
status = "migrate-signup";
label = this.strings.formatStringFromName("needUserShort",
[this.button.getAttribute("fxabrandname")], 1);
break;
case fxaMigrator.STATE_USER_FXA_VERIFIED:
case this.fxaMigrator.STATE_USER_FXA_VERIFIED:
status = "migrate-verify";
label = this.strings.formatStringFromName("needVerifiedUserShort",
[this._migrationInfo.email],
@ -270,7 +263,7 @@ let gFxAccounts = {
updateMigrationNotification: Task.async(function* () {
if (!this._migrationInfo) {
Weave.Notifications.removeAll(SYNC_MIGRATION_NOTIFICATION_TITLE);
Weave.Notifications.removeAll(this.SYNC_MIGRATION_NOTIFICATION_TITLE);
return;
}
if (gBrowser.currentURI.spec.split("?")[0] == "about:accounts") {
@ -280,7 +273,7 @@ let gFxAccounts = {
}
let note = null;
switch (this._migrationInfo.state) {
case fxaMigrator.STATE_USER_FXA: {
case this.fxaMigrator.STATE_USER_FXA: {
let msg = this.strings.GetStringFromName("needUserLong");
let upgradeLabel =
this.strings.GetStringFromName("upgradeToFxA.label");
@ -289,13 +282,13 @@ let gFxAccounts = {
note = new Weave.Notification(
undefined, msg, undefined, Weave.Notifications.PRIORITY_WARNING, [
new Weave.NotificationButton(upgradeLabel, upgradeAccessKey, () => {
fxaMigrator.createFxAccount(window);
this.fxaMigrator.createFxAccount(window);
}),
]
);
break;
}
case fxaMigrator.STATE_USER_FXA_VERIFIED: {
case this.fxaMigrator.STATE_USER_FXA_VERIFIED: {
let msg =
this.strings.formatStringFromName("needVerifiedUserLong",
[this._migrationInfo.email], 1);
@ -306,14 +299,14 @@ let gFxAccounts = {
note = new Weave.Notification(
undefined, msg, undefined, Weave.Notifications.PRIORITY_INFO, [
new Weave.NotificationButton(resendLabel, resendAccessKey, () => {
fxaMigrator.resendVerificationMail();
this.fxaMigrator.resendVerificationMail();
}),
]
);
break;
}
}
note.title = SYNC_MIGRATION_NOTIFICATION_TITLE;
note.title = this.SYNC_MIGRATION_NOTIFICATION_TITLE;
Weave.Notifications.replaceTitle(note);
}),
@ -328,7 +321,7 @@ let gFxAccounts = {
this.openSignInAgainPage("menupanel");
break;
case "migrate-signup":
fxaMigrator.createFxAccount(window);
this.fxaMigrator.createFxAccount(window);
break;
case "migrate-verify":
// Instead of using the migrator module directly here the UX calls for
@ -374,3 +367,10 @@ let gFxAccounts = {
this.openAccountsPage("reauth", { entryPoint: entryPoint });
},
};
XPCOMUtils.defineLazyGetter(gFxAccounts, "FxAccountsCommon", function () {
return Cu.import("resource://gre/modules/FxAccountsCommon.js", {});
});
XPCOMUtils.defineLazyModuleGetter(gFxAccounts, "fxaMigrator",
"resource://services-sync/FxaMigrator.jsm");

View File

@ -11,7 +11,7 @@ add_task(function* test() {
// Fake the state where we need an FxA user.
let buttonPromise = promiseButtonMutation();
Services.obs.notifyObservers(null, STATE_CHANGED_TOPIC,
fxaMigrator.STATE_USER_FXA);
imports.fxaMigrator.STATE_USER_FXA);
let buttonState = yield buttonPromise;
assertButtonState(buttonState, "migrate-signup", true);
Assert.ok(Weave.Notifications.notifications.some(n => {
@ -24,7 +24,7 @@ add_task(function* test() {
createInstance(Ci.nsISupportsString);
email.data = "foo@example.com";
Services.obs.notifyObservers(email, STATE_CHANGED_TOPIC,
fxaMigrator.STATE_USER_FXA_VERIFIED);
imports.fxaMigrator.STATE_USER_FXA_VERIFIED);
buttonState = yield buttonPromise;
assertButtonState(buttonState, "migrate-verify", true,
"foo@example.com not verified");