Merge "Flush account refresh debouncer on window focus"

This commit is contained in:
Wyatt Allen
2017-03-25 00:08:59 +00:00
committed by Gerrit Code Review
2 changed files with 12 additions and 10 deletions

View File

@@ -154,17 +154,12 @@
// undefined). // undefined).
if (document.hidden !== false) { return; } if (document.hidden !== false) { return; }
// If we're currently in a credential refresh, flush the debouncer so that // If not currently refreshing credentials and the credentials are old,
// it can be checked immediately. // request them to confirm their validity or (display an auth toast if it
if (this._refreshingCredentials) { // fails).
this.flushDebouncer('checkLoggedIn');
return;
}
// If the credentials are old, request them to confirm their validity or
// (display an auth toast if it fails).
var timeSinceLastCheck = Date.now() - this._lastCredentialCheck; var timeSinceLastCheck = Date.now() - this._lastCredentialCheck;
if (this.knownAccountId !== undefined && if (!this._refreshingCredentials &&
this.knownAccountId !== undefined &&
timeSinceLastCheck > STALE_CREDENTIAL_THRESHOLD_MS) { timeSinceLastCheck > STALE_CREDENTIAL_THRESHOLD_MS) {
this._lastCredentialCheck = Date.now(); this._lastCredentialCheck = Date.now();
this.$.restAPI.checkCredentials(); this.$.restAPI.checkCredentials();
@@ -212,13 +207,19 @@
'top=' + top, 'top=' + top,
]; ];
window.open('/login/%3FcloseAfterLogin', '_blank', options.join(',')); window.open('/login/%3FcloseAfterLogin', '_blank', options.join(','));
this.listen(window, 'focus', '_handleWindowFocus');
}, },
_handleCredentialRefreshed: function() { _handleCredentialRefreshed: function() {
this.unlisten(window, 'focus', '_handleWindowFocus');
this._refreshingCredentials = false; this._refreshingCredentials = false;
this.unlisten(this._alertElement, 'action', '_createLoginPopup'); this.unlisten(this._alertElement, 'action', '_createLoginPopup');
this._hideAlert(); this._hideAlert();
this._showAlert('Credentials refreshed.'); this._showAlert('Credentials refreshed.');
}, },
_handleWindowFocus: function() {
this.flushDebouncer('checkLoggedIn');
},
}); });
})(); })();

View File

@@ -130,6 +130,7 @@ limitations under the License.
var hideToastSpy = sandbox.spy(toast, 'hide'); var hideToastSpy = sandbox.spy(toast, 'hide');
element._handleWindowFocus();
assert.isTrue(refreshStub.called); assert.isTrue(refreshStub.called);
element.flushDebouncer('checkLoggedIn'); element.flushDebouncer('checkLoggedIn');
flush(function() { flush(function() {