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({ ...@@ -70,7 +70,6 @@ Polymer({
}, },
listeners: { listeners: {
'auth-token-changed': 'onAuthTokenChanged_',
'close': 'onDialogClose_', 'close': 'onDialogClose_',
'feature-toggle-clicked': 'onFeatureToggleClicked_', 'feature-toggle-clicked': 'onFeatureToggleClicked_',
'forget-device-requested': 'onForgetDeviceRequested_', 'forget-device-requested': 'onForgetDeviceRequested_',
...@@ -272,14 +271,6 @@ Polymer({ ...@@ -272,14 +271,6 @@ Polymer({
this.showPasswordPromptDialog_ = false; 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., * Attempt to enable the provided feature. If not authenticated (i.e.,
* |authToken_| is invalid), display the password prompt to begin the * |authToken_| is invalid), display the password prompt to begin the
......
...@@ -56,9 +56,10 @@ ...@@ -56,9 +56,10 @@
</div> </div>
</iron-collapse> </iron-collapse>
<template is="dom-if" if="[[showPasswordPromptDialog_]]" restamp> <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> </settings-password-prompt-dialog>
</template> </template>
</template> </template>
<script src="multidevice_smartlock_subpage.js"></script> <script src="multidevice_smartlock_subpage.js"></script>
</dom-module> </dom-module>
\ No newline at end of file
...@@ -76,10 +76,15 @@ Polymer({ ...@@ -76,10 +76,15 @@ Polymer({
type: Boolean, type: Boolean,
value: false, value: false,
}, },
},
listeners: { /**
'auth-token-changed': 'onAuthTokenChanged_', * Authentication token provided by password-prompt-dialog.
* @private {string}
*/
authToken_: {
type: String,
value: '',
},
}, },
/** @private {?settings.MultiDeviceBrowserProxy} */ /** @private {?settings.MultiDeviceBrowserProxy} */
...@@ -163,30 +168,22 @@ Polymer({ ...@@ -163,30 +168,22 @@ Polymer({
}, },
/** /**
* Completes the transaction of setting the Smart Lock 'sign-in enabled' pref * Updates the state of the password dialog controller flag when the UI
* after the user authenticates. * element closes.
* @param {!CustomEvent<!{value: string}>} event The event containing the auth
* token.
* @private * @private
*/ */
onAuthTokenChanged_: function(event) { onEnableSignInDialogClose_: function() {
const authToken = event.detail.value; this.showPasswordPromptDialog_ = false;
// The auth-token-changed event fires after the expiration period ( // If |this.authToken_| is set when the dialog has been closed, this means
// represented by the empty string), so only move forward when the auth // that the user entered the correct password into the dialog when
// token is non-empty. // attempting to enable SignIn with Smart Lock.
if (authToken !== '') { if (this.authToken_ !== '') {
this.browserProxy_.setSmartLockSignInEnabled( this.browserProxy_.setSmartLockSignInEnabled(
true /* enabled */, authToken); true /* enabled */, this.authToken_);
} }
},
/** // Always require password entry if re-enabling SignIn with Smart Lock.
* Updates the state of the password dialog controller flag when the UI this.authToken_ = '';
* element closes.
* @private
*/
onDialogClose_: function() {
this.showPasswordPromptDialog_ = false;
}, },
}); });
...@@ -237,11 +237,15 @@ suite('Multidevice', function() { ...@@ -237,11 +237,15 @@ suite('Multidevice', function() {
assertEquals(settings.SignInEnabledState.DISABLED, assertEquals(settings.SignInEnabledState.DISABLED,
smartLockSignInRadio.selected); smartLockSignInRadio.selected);
// Simulate the user entering a valid password. // Simulate the user entering a valid password into the dialog.
smartLockSubPage.fire('auth-token-changed', {value: 'validAuthToken'}); passwordDialog.authToken = 'validAuthToken';
passwordDialog.dispatchEvent(new CustomEvent('close'));
Polymer.dom.flush();
assertEquals(settings.SignInEnabledState.ENABLED, return browserProxy.whenCalled('getSmartLockSignInEnabled').then(params => {
smartLockSignInRadio.selected); assertEquals(
settings.SignInEnabledState.ENABLED, smartLockSignInRadio.selected);
});
}); });
test('Smart Lock sign in cancel authentication', function() { 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