Bug 1298011 - Update the Synced Tabs sidebar UI when account password changed. r=markh

MozReview-Commit-ID: 2cJK8ZAQH5R

--HG--
extra : rebase_source : 7ea9455093467e34b4daec0da2bcc08b40f17de6
This commit is contained in:
Edouard Oger 2017-01-05 16:54:12 -05:00
parent 99b4c17c30
commit d2b4472abe
3 changed files with 32 additions and 7 deletions

View File

@ -137,15 +137,15 @@ var gSyncUI = {
// Note that we don't show login errors in a notification bar here, but do
// still need to track a login-failed state so the "Tools" menu updates
// with the correct state.
_loginFailed() {
loginFailed() {
// If Sync isn't already ready, we don't want to force it to initialize
// by referencing Weave.Status - and it isn't going to be accurate before
// Sync is ready anyway.
if (!this.weaveService.ready) {
this.log.debug("_loginFailed has sync not ready, so returning false");
this.log.debug("loginFailed has sync not ready, so returning false");
return false;
}
this.log.debug("_loginFailed has sync state=${sync}",
this.log.debug("loginFailed has sync state=${sync}",
{ sync: Weave.Status.login});
return Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED;
},
@ -163,7 +163,7 @@ var gSyncUI = {
if (!gBrowser)
return Promise.resolve();
let loginFailed = this._loginFailed();
let loginFailed = this.loginFailed();
// Start off with a clean slate
document.getElementById("sync-reauth-state").hidden = true;
@ -266,7 +266,7 @@ var gSyncUI = {
// via the UI.
handleToolbarButton() {
this._needsSetup().then(needsSetup => {
if (needsSetup || this._loginFailed()) {
if (needsSetup || this.loginFailed()) {
this.openSetup();
} else {
this.doSync();
@ -380,7 +380,7 @@ var gSyncUI = {
let needsSetup = yield this._needsSetup();
let needsVerification = yield this._needsVerification();
let loginFailed = this._loginFailed();
let loginFailed = this.loginFailed();
// This is a little messy as the Sync buttons are 1/2 Sync related and
// 1/2 FxA related - so for some strings we use Sync strings, but for
// others we reach into gFxAccounts for strings.

View File

@ -72,6 +72,7 @@ SyncedTabsDeckComponent.prototype = {
init() {
Services.obs.addObserver(this, this._SyncedTabs.TOPIC_TABS_CHANGED, false);
Services.obs.addObserver(this, FxAccountsCommon.ONLOGIN_NOTIFICATION, false);
Services.obs.addObserver(this, "weave:service:login:change", false);
// Go ahead and trigger sync
this._SyncedTabs.syncTabs()
@ -94,6 +95,7 @@ SyncedTabsDeckComponent.prototype = {
uninit() {
Services.obs.removeObserver(this, this._SyncedTabs.TOPIC_TABS_CHANGED);
Services.obs.removeObserver(this, FxAccountsCommon.ONLOGIN_NOTIFICATION);
Services.obs.removeObserver(this, "weave:service:login:change");
this._deckView.destroy();
},
@ -104,6 +106,7 @@ SyncedTabsDeckComponent.prototype = {
this.updatePanel();
break;
case FxAccountsCommon.ONLOGIN_NOTIFICATION:
case "weave:service:login:change":
this.updatePanel();
break;
default:
@ -119,7 +122,7 @@ SyncedTabsDeckComponent.prototype = {
getPanelStatus() {
return this._accountStatus().then(exists => {
if (!exists) {
if (!exists || this._getChromeWindow(this._window).gSyncUI.loginFailed()) {
return this.PANELS.NOT_AUTHED_INFO;
}
if (!this._SyncedTabs.isConfiguredToSyncTabs) {

View File

@ -122,6 +122,12 @@ add_task(function* testObserver() {
Assert.ok(component.observe.calledWith(null, FxAccountsCommon.ONLOGIN_NOTIFICATION, ""),
"component is notified of login");
Assert.equal(component.updatePanel.callCount, 3, "triggers panel update again");
Services.obs.notifyObservers(null, "weave:service:login:change", "");
Assert.ok(component.observe.calledWith(null, "weave:service:login:change", ""),
"component is notified of login change");
Assert.equal(component.updatePanel.callCount, 4, "triggers panel update again");
});
add_task(function* testPanelStatus() {
@ -134,6 +140,16 @@ add_task(function* testPanelStatus() {
let SyncedTabsMock = {
getTabClients() {}
};
let loginFailed = false;
let chromeWindowMock = {
gSyncUI: {
loginFailed() {
return loginFailed;
}
}
};
let getChromeWindowMock = sinon.stub();
getChromeWindowMock.returns(chromeWindowMock);
sinon.stub(listStore, "getData");
@ -143,6 +159,7 @@ add_task(function* testPanelStatus() {
deckStore,
listComponent,
SyncedTabs: SyncedTabsMock,
getChromeWindowMock
});
let isAuthed = false;
@ -152,6 +169,11 @@ add_task(function* testPanelStatus() {
isAuthed = true;
loginFailed = true;
result = yield component.getPanelStatus();
Assert.equal(result, component.PANELS.NOT_AUTHED_INFO);
loginFailed = false;
SyncedTabsMock.isConfiguredToSyncTabs = false;
result = yield component.getPanelStatus();
Assert.equal(result, component.PANELS.TABS_DISABLED);