Bug 1359733 - (pt. 4) Pull out browser-sync.js badges r=eoger

See also commit message for pt. 4. We're moving app menu
notification state into a jsm.

MozReview-Commit-ID: 3RehYcHyfLu

--HG--
extra : rebase_source : 56d364ce6fd3afe54fc1be797c3efb3dda7623aa
This commit is contained in:
Doug Thayer 2017-05-18 13:17:38 -07:00
Родитель 26f8bae28d
Коммит df2779bb50
5 изменённых файлов: 90 добавлений и 27 удалений

Просмотреть файл

@ -143,7 +143,6 @@ var gSync = {
},
updateAllUI(state) {
this.updatePanelBadge(state);
this.updatePanelPopup(state);
this.updateStateBroadcasters(state);
this.updateSyncButtonsTooltip(state);
@ -203,15 +202,6 @@ var gSync = {
}
},
updatePanelBadge(state) {
if (state.status == UIState.STATUS_LOGIN_FAILED ||
state.status == UIState.STATUS_NOT_VERIFIED) {
PanelUI.showBadgeOnlyNotification("fxa-needs-authentication");
} else {
PanelUI.removeNotification("fxa-needs-authentication");
}
},
updateStateBroadcasters(state) {
const status = state.status;

Просмотреть файл

@ -2,6 +2,7 @@
[browser_fxa_web_channel.js]
support-files=
browser_fxa_web_channel.html
[browser_fxa_badge.js]
[browser_aboutAccounts.js]
skip-if = os == "linux" # Bug 958026
support-files =

Просмотреть файл

@ -0,0 +1,68 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
Cu.import("resource://gre/modules/AppMenuNotifications.jsm");
add_task(async function test_unconfigured_no_badge() {
const oldUIState = UIState.get;
UIState.get = () => ({
status: UIState.STATUS_NOT_CONFIGURED
});
Services.obs.notifyObservers(null, UIState.ON_UPDATE);
checkFxABadge(false);
UIState.get = oldUIState;
});
add_task(async function test_signedin_no_badge() {
const oldUIState = UIState.get;
UIState.get = () => ({
status: UIState.STATUS_SIGNED_IN,
email: "foo@bar.com"
});
Services.obs.notifyObservers(null, UIState.ON_UPDATE);
checkFxABadge(false);
UIState.get = oldUIState;
});
add_task(async function test_unverified_badge_shown() {
const oldUIState = UIState.get;
UIState.get = () => ({
status: UIState.STATUS_NOT_VERIFIED,
email: "foo@bar.com"
});
Services.obs.notifyObservers(null, UIState.ON_UPDATE);
checkFxABadge(true);
UIState.get = oldUIState;
});
add_task(async function test_loginFailed_badge_shown() {
const oldUIState = UIState.get;
UIState.get = () => ({
status: UIState.STATUS_LOGIN_FAILED,
email: "foo@bar.com"
});
Services.obs.notifyObservers(null, UIState.ON_UPDATE);
checkFxABadge(true);
UIState.get = oldUIState;
});
function checkFxABadge(shouldBeShown) {
let isShown = false;
for (let notification of AppMenuNotifications.notifications) {
if (notification.id == "fxa-needs-authentication") {
isShown = true;
break;
}
}
is(isShown, shouldBeShown, "Fxa badge shown matches expected value.");
}

Просмотреть файл

@ -26,7 +26,6 @@ add_task(async function test_ui_state_signedin() {
gSync.updateAllUI(state);
checkFxABadge(false);
let statusBarTooltip = gSync.appMenuStatus.getAttribute("signedinTooltiptext");
let lastSyncTooltip = gSync.formatLastSyncDate(new Date(state.lastSync));
checkPanelUIStatusBar({
@ -74,7 +73,6 @@ add_task(async function test_ui_state_unconfigured() {
gSync.updateAllUI(state);
checkFxABadge(false);
let signedOffLabel = gSync.appMenuStatus.getAttribute("defaultlabel");
let statusBarTooltip = gSync.appMenuStatus.getAttribute("signedinTooltiptext");
checkPanelUIStatusBar({
@ -95,7 +93,6 @@ add_task(async function test_ui_state_unverified() {
gSync.updateAllUI(state);
checkFxABadge(true);
let expectedLabel = gSync.appMenuStatus.getAttribute("unverifiedlabel");
let tooltipText = gSync.fxaStrings.formatStringFromName("verifyDescription", [state.email], 1);
checkPanelUIStatusBar({
@ -118,7 +115,6 @@ add_task(async function test_ui_state_loginFailed() {
gSync.updateAllUI(state);
checkFxABadge(true);
let expectedLabel = gSync.appMenuStatus.getAttribute("errorlabel");
let tooltipText = gSync.fxaStrings.formatStringFromName("reconnectDescription", [state.email], 1);
checkPanelUIStatusBar({
@ -148,17 +144,6 @@ add_task(async function test_FormatLastSyncDateMonthAgo() {
"The date is correctly formatted");
});
function checkFxABadge(shouldBeShown) {
let isShown = false;
for (let notification of PanelUI.notifications) {
if (notification.id == "fxa-needs-authentication") {
isShown = true;
break;
}
}
is(isShown, shouldBeShown, "the fxa badge has the right visibility");
}
function checkPanelUIStatusBar({label, tooltip, fxastatus, avatarURL, syncing, syncNowTooltip}) {
let prefix = gPhotonStructure ? "appMenu" : "PanelUI"
let labelNode = document.getElementById(`${prefix}-fxa-label`);

Просмотреть файл

@ -22,7 +22,7 @@ XPCOMUtils.defineLazyGetter(this, "WeaveService", () =>
// lazy module getters
/* global AboutHome:false, AboutNewTab:false, AddonManager:false,
/* global AboutHome:false, AboutNewTab:false, AddonManager:false, AppMenuNotifications:false,
AsyncShutdown:false, AutoCompletePopup:false, BookmarkHTMLUtils:false,
BookmarkJSONUtils:false, BrowserUITelemetry:false, BrowserUsageTelemetry:false,
ContentClick:false, ContentPrefServiceParent:false, ContentSearch:false,
@ -36,9 +36,11 @@ XPCOMUtils.defineLazyGetter(this, "WeaveService", () =>
ProcessHangMonitor:false, ReaderParent:false, RecentWindow:false,
RemotePrompt:false, SessionStore:false,
ShellService:false, SimpleServiceDiscovery:false, TabCrashHandler:false,
Task:false, UITour:false, UpdateListener:false, WebChannel:false,
Task:false, UITour:false, UIState:false, UpdateListener:false, WebChannel:false,
WindowsRegistry:false, webrtcUI:false */
/**
* IF YOU ADD OR REMOVE FROM THIS LIST, PLEASE UPDATE THE LIST ABOVE AS WELL.
* XXX Bug 1325373 is for making eslint detect these automatically.
@ -50,6 +52,7 @@ let initializedModules = {};
["AboutHome", "resource:///modules/AboutHome.jsm", "init"],
["AboutNewTab", "resource:///modules/AboutNewTab.jsm"],
["AddonManager", "resource://gre/modules/AddonManager.jsm"],
["AppMenuNotifications", "resource://gre/modules/AppMenuNotifications.jsm"],
["AsyncShutdown", "resource://gre/modules/AsyncShutdown.jsm"],
["AutoCompletePopup", "resource://gre/modules/AutoCompletePopup.jsm"],
["BookmarkHTMLUtils", "resource://gre/modules/BookmarkHTMLUtils.jsm"],
@ -88,6 +91,7 @@ let initializedModules = {};
["SimpleServiceDiscovery", "resource://gre/modules/SimpleServiceDiscovery.jsm"],
["TabCrashHandler", "resource:///modules/ContentCrashHandlers.jsm"],
["Task", "resource://gre/modules/Task.jsm"],
["UIState", "resource://services-sync/UIState.jsm"],
["UITour", "resource:///modules/UITour.jsm"],
["UpdateListener", "resource://gre/modules/UpdateListener.jsm", "init"],
["WebChannel", "resource://gre/modules/WebChannel.jsm"],
@ -490,6 +494,9 @@ BrowserGlue.prototype = {
case "test-initialize-sanitizer":
this._sanitizer.onStartup();
break;
case "sync-ui-state:update":
this._updateFxaBadges();
break;
}
},
@ -528,6 +535,7 @@ BrowserGlue.prototype = {
os.addObserver(this, "restart-in-safe-mode");
os.addObserver(this, "flash-plugin-hang");
os.addObserver(this, "xpi-signature-changed");
os.addObserver(this, "sync-ui-state:update");
this._flashHangCount = 0;
this._firstWindowReady = new Promise(resolve => this._firstWindowLoaded = resolve);
@ -580,6 +588,7 @@ BrowserGlue.prototype = {
os.removeObserver(this, "browser-search-engine-modified");
os.removeObserver(this, "flash-plugin-hang");
os.removeObserver(this, "xpi-signature-changed");
os.removeObserver(this, "sync-ui-state:update");
},
_onAppDefaults: function BG__onAppDefaults() {
@ -2338,6 +2347,16 @@ BrowserGlue.prototype = {
nb.PRIORITY_INFO_MEDIUM, buttons);
},
_updateFxaBadges() {
let state = UIState.get();
if (state.status == UIState.STATUS_LOGIN_FAILED ||
state.status == UIState.STATUS_NOT_VERIFIED) {
AppMenuNotifications.showBadgeOnlyNotification("fxa-needs-authentication");
} else {
AppMenuNotifications.removeNotification("fxa-needs-authentication");
}
},
// for XPCOM
classID: Components.ID("{eab9012e-5f74-4cbc-b2b5-a590235513cc}"),