Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(804)

Side by Side Diff: chrome/browser/resources/settings/people_page/password_prompt_dialog.js

Issue 2157673002: Browser tests for the quick_unlock settings pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pin-unlock-quick-unlock-interface
Patch Set: Rework for new settings design Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 7 *
8 * 'settings-password-prompt-dialog' shows a dialog which asks for the user to 8 * 'settings-password-prompt-dialog' shows a dialog which asks for the user to
9 * enter their password. It validates the password is correct. Once the user has 9 * enter their password. It validates the password is correct. Once the user has
10 * entered their account password, the page fires an 'authenticated' event and 10 * entered their account password, the page fires an 'authenticated' event and
(...skipping 11 matching lines...) Expand all
22 * </settings-password-prompt-dialog> 22 * </settings-password-prompt-dialog>
23 * 23 *
24 * this.$.passwordPrompt.open() 24 * this.$.passwordPrompt.open()
25 */ 25 */
26 26
27 (function() { 27 (function() {
28 'use strict'; 28 'use strict';
29 29
30 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes. 30 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes.
31 31
32 /**
33 * Helper method that checks if |password| is valid.
34 * @param {string} password
35 * @param {function(boolean):void} onCheck
36 */
37 function checkAccountPassword_(password, onCheck) {
38 // We check the account password by trying to update the active set of quick
39 // unlock modes without changing any credentials.
40 chrome.quickUnlockPrivate.getActiveModes(function(modes) {
41 var credentials =
42 /** @type {!Array<string>} */ (Array(modes.length).fill(''));
43 chrome.quickUnlockPrivate.setModes(password, modes, credentials, onCheck);
44 });
45 }
46
47 Polymer({ 32 Polymer({
48 is: 'settings-password-prompt-dialog', 33 is: 'settings-password-prompt-dialog',
49 34
50 properties: { 35 properties: {
51 /** 36 /**
52 * A wrapper around chrome.quickUnlockPrivate.setModes with the account 37 * A wrapper around chrome.quickUnlockPrivate.setModes with the account
53 * password already supplied. If this is null, the authentication screen 38 * password already supplied. If this is null, the authentication screen
54 * needs to be redisplayed. This property will be cleared after 39 * needs to be redisplayed. This property will be cleared after
55 * PASSWORD_ACTIVE_DURATION_MS milliseconds. 40 * |this.passwordActiveDurationMs_| milliseconds.
56 */ 41 */
57 setModes: { 42 setModes: {
58 type: Object, 43 type: Object,
59 notify: true 44 notify: true
60 }, 45 },
61 46
62 /** 47 /**
63 * The actual value of the password field. This is cleared whenever the 48 * The actual value of the password field. This is cleared whenever the
64 * authentication screen is not displayed so that the user's password is not 49 * authentication screen is not displayed so that the user's password is not
65 * easily available to an attacker. The actual password is stored as an 50 * easily available to an attacker. The actual password is stored as an
66 * captured closure variable inside of setModes. 51 * captured closure variable inside of setModes.
67 * @private 52 * @private
68 */ 53 */
69 password_: { 54 password_: {
70 type: String, 55 type: String,
71 observer: 'onPasswordChanged_' 56 observer: 'onPasswordChanged_'
72 }, 57 },
73 58
74 /** 59 /**
75 * Helper property which marks password as valid/invalid. 60 * Helper property which marks password as valid/invalid.
76 * @private 61 * @private
77 */ 62 */
78 passwordInvalid_: Boolean 63 passwordInvalid_: Boolean,
64
65 /**
66 * Interface for chrome.quickUnlockPrivate calls. May be overriden by tests.
67 * @private
68 */
69 quickUnlockPrivate_: {
70 //* @type {QuickUnlockPrivate}
jdufault 2016/10/06 19:19:05 I've been having a ton of trouble getting the clos
71 type: Object,
72 value: chrome.quickUnlockPrivate
73 },
74
75 /**
76 * PASSWORD_ACTIVE_DURATION_MS value. May be overridden by tests.
77 * @private
78 */
79 passwordActiveDurationMs_: {
80 type: Number,
81 value: PASSWORD_ACTIVE_DURATION_MS
82 },
79 }, 83 },
80 84
81 /** 85 /**
82 * Open up the dialog. This will wait until the dialog has loaded before 86 * Open up the dialog. This will wait until the dialog has loaded before
83 * opening it. 87 * opening it.
84 */ 88 */
85 open: function() { 89 open: function() {
86 // Wait until the dialog is attached to the DOM before trying to open it. 90 // Wait until the dialog is attached to the DOM before trying to open it.
87 var dialog = /** @type {{isConnected: boolean}} */ (this.$.dialog); 91 var dialog = /** @type {{isConnected: boolean}} */ (this.$.dialog);
88 if (!dialog.isConnected) { 92 if (!dialog.isConnected) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return; 134 return;
131 } 135 }
132 136
133 function onPasswordChecked(valid) { 137 function onPasswordChecked(valid) {
134 // The password might have been cleared during the duration of the 138 // The password might have been cleared during the duration of the
135 // getActiveModes call. 139 // getActiveModes call.
136 this.passwordInvalid_ = !valid && !!this.password_; 140 this.passwordInvalid_ = !valid && !!this.password_;
137 141
138 if (valid) { 142 if (valid) {
139 // Create the |this.setModes| closure and automatically clear it after 143 // Create the |this.setModes| closure and automatically clear it after
140 // |PASSWORD_ACTIVE_DURATION_MS|. 144 // |this.passwordActiveDurationMs_|.
141 var password = this.password_; 145 var password = this.password_;
142 this.password_ = ''; 146 this.password_ = '';
143 147
144 this.setModes = function(modes, credentials, onComplete) { 148 this.setModes = function(modes, credentials, onComplete) {
145 chrome.quickUnlockPrivate.setModes( 149 this.quickUnlockPrivate_.setModes(
146 password, modes, credentials, onComplete); 150 password, modes, credentials, onComplete);
147 }; 151 }.bind(this);
148 152
149 function clearSetModes() { 153 function clearSetModes() {
150 // Reset the password so that any cached references to this.setModes 154 // Reset the password so that any cached references to this.setModes
151 // will fail. 155 // will fail.
152 password = ''; 156 password = '';
153 this.setModes = null; 157 this.setModes = null;
154 } 158 }
155 159
156 this.clearAccountPasswordTimeout_ = setTimeout( 160 this.clearAccountPasswordTimeout_ = setTimeout(
157 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); 161 clearSetModes.bind(this), this.passwordActiveDurationMs_);
158 // Closing the dialog will clear this.password_. 162
159 this.$.dialog.close(); 163 // Clear stored password state and close the dialog.
164 this.password_ = '';
165 if (this.$.dialog.open)
166 this.$.dialog.close();
160 } 167 }
161 } 168 }
162 169
163 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); 170 this.checkAccountPassword_(this.password_, onPasswordChecked.bind(this));
164 }, 171 },
165 172
166 /** @private */ 173 /** @private */
167 onPasswordChanged_: function() { 174 onPasswordChanged_: function() {
168 this.passwordInvalid_ = false; 175 this.passwordInvalid_ = false;
169 }, 176 },
170 177
171 /** @private */ 178 /** @private */
172 enableConfirm_: function() { 179 enableConfirm_: function() {
173 return !!this.password_ && !this.passwordInvalid_; 180 return !!this.password_ && !this.passwordInvalid_;
181 },
182
183 /**
184 * Helper method that checks if |password| is valid.
185 * @param {string} password
186 * @param {function(boolean):void} onCheck
187 */
188 checkAccountPassword_: function(password, onCheck) {
189 // We check the account password by trying to update the active set of quick
190 // unlock modes without changing any credentials.
191 this.quickUnlockPrivate_.getActiveModes(function(modes) {
192 var credentials =
193 /** @type {!Array<string>} */ (Array(modes.length).fill(''));
194 this.quickUnlockPrivate_.setModes(password, modes, credentials, onCheck);
195 }.bind(this));
174 } 196 }
175 }); 197 });
176 198
177 })(); 199 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698