Commit 39c769b2 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

Reland 'Smart Lock: Remove authToken listeners'

This change previously landed at crrev.com/c/1484495, but was
reverted at crrev.com/c/1491658 because of a test failure. This
relands the original CL with a fix for the test. Patch 4 is the
original CL, and Patch 5 is the fix.

Text of the original CL:

This is a necessary change now that Polymer 2 is enabled.

Previously, Multidevice and Smart Lock pages were being informed
of an authToken change by their child element passwordPrompt, but that
is no longer bubbling up to the parent. Now, explicitly bind to the
authToken of passwordPrompt as a property, and use it when the dialog
close event is fired. As a consequence of this, the authTokenChanged()
callbacks in both parents is unnecessary and has been removed.

Bug: 934987
Change-Id: Iae34ae9677fe555264c9a59b05f4b9f184fad324
Reviewed-on: https://chromium-review.googlesource.com/c/1492362
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636283}
parent 21fe97f0
......@@ -70,7 +70,6 @@ Polymer({
},
listeners: {
'auth-token-changed': 'onAuthTokenChanged_',
'close': 'onDialogClose_',
'feature-toggle-clicked': 'onFeatureToggleClicked_',
'forget-device-requested': 'onForgetDeviceRequested_',
......@@ -272,14 +271,6 @@ Polymer({
this.showPasswordPromptDialog_ = false;
},
/**
* @param {!CustomEvent<!{value: string}>} event
* @private
*/
onAuthTokenChanged_: function(event) {
this.authToken_ = event.detail.value;
},
/**
* Attempt to enable the provided feature. If not authenticated (i.e.,
* |authToken_| is invalid), display the password prompt to begin the
......
......@@ -56,7 +56,8 @@
</div>
</iron-collapse>
<template is="dom-if" if="[[showPasswordPromptDialog_]]" restamp>
<settings-password-prompt-dialog on-close="onDialogClose_">
<settings-password-prompt-dialog id="smartLockSignInPasswordPrompt"
on-close="onEnableSignInDialogClose_" auth-token="{{authToken_}}">
</settings-password-prompt-dialog>
</template>
</template>
......
......@@ -76,10 +76,15 @@ Polymer({
type: Boolean,
value: false,
},
},
listeners: {
'auth-token-changed': 'onAuthTokenChanged_',
/**
* Authentication token provided by password-prompt-dialog.
* @private {string}
*/
authToken_: {
type: String,
value: '',
},
},
/** @private {?settings.MultiDeviceBrowserProxy} */
......@@ -163,30 +168,22 @@ Polymer({
},
/**
* Completes the transaction of setting the Smart Lock 'sign-in enabled' pref
* after the user authenticates.
* @param {!CustomEvent<!{value: string}>} event The event containing the auth
* token.
* Updates the state of the password dialog controller flag when the UI
* element closes.
* @private
*/
onAuthTokenChanged_: function(event) {
const authToken = event.detail.value;
onEnableSignInDialogClose_: function() {
this.showPasswordPromptDialog_ = false;
// The auth-token-changed event fires after the expiration period (
// represented by the empty string), so only move forward when the auth
// token is non-empty.
if (authToken !== '') {
// If |this.authToken_| is set when the dialog has been closed, this means
// that the user entered the correct password into the dialog when
// attempting to enable SignIn with Smart Lock.
if (this.authToken_ !== '') {
this.browserProxy_.setSmartLockSignInEnabled(
true /* enabled */, authToken);
true /* enabled */, this.authToken_);
}
},
/**
* Updates the state of the password dialog controller flag when the UI
* element closes.
* @private
*/
onDialogClose_: function() {
this.showPasswordPromptDialog_ = false;
// Always require password entry if re-enabling SignIn with Smart Lock.
this.authToken_ = '';
},
});
......@@ -237,11 +237,15 @@ suite('Multidevice', function() {
assertEquals(settings.SignInEnabledState.DISABLED,
smartLockSignInRadio.selected);
// Simulate the user entering a valid password.
smartLockSubPage.fire('auth-token-changed', {value: 'validAuthToken'});
// Simulate the user entering a valid password into the dialog.
passwordDialog.authToken = 'validAuthToken';
passwordDialog.dispatchEvent(new CustomEvent('close'));
Polymer.dom.flush();
assertEquals(settings.SignInEnabledState.ENABLED,
smartLockSignInRadio.selected);
return browserProxy.whenCalled('getSmartLockSignInEnabled').then(params => {
assertEquals(
settings.SignInEnabledState.ENABLED, smartLockSignInRadio.selected);
});
});
test('Smart Lock sign in cancel authentication', function() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment