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

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: Rebase 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: Object,
71 value: chrome.quickUnlockPrivate
72 },
73
74 /**
75 * PASSWORD_ACTIVE_DURATION_MS value. May be overridden by tests.
76 * @private
77 */
78 passwordActiveDurationMs_: {
79 type: Number,
80 value: PASSWORD_ACTIVE_DURATION_MS
81 },
79 }, 82 },
80 83
81 /** 84 /**
82 * Open up the dialog. This will wait until the dialog has loaded before 85 * Open up the dialog. This will wait until the dialog has loaded before
83 * opening it. 86 * opening it.
84 */ 87 */
85 open: function() { 88 open: function() {
86 // Wait until the dialog is attached to the DOM before trying to open it. 89 // Wait until the dialog is attached to the DOM before trying to open it.
87 var dialog = /** @type {{isConnected: boolean}} */ (this.$.dialog); 90 var dialog = /** @type {{isConnected: boolean}} */ (this.$.dialog);
88 if (!dialog.isConnected) { 91 if (!dialog.isConnected) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return; 133 return;
131 } 134 }
132 135
133 function onPasswordChecked(valid) { 136 function onPasswordChecked(valid) {
134 // The password might have been cleared during the duration of the 137 // The password might have been cleared during the duration of the
135 // getActiveModes call. 138 // getActiveModes call.
136 this.passwordInvalid_ = !valid && !!this.password_; 139 this.passwordInvalid_ = !valid && !!this.password_;
137 140
138 if (valid) { 141 if (valid) {
139 // Create the |this.setModes| closure and automatically clear it after 142 // Create the |this.setModes| closure and automatically clear it after
140 // |PASSWORD_ACTIVE_DURATION_MS|. 143 // |this.passwordActiveDurationMs_|.
141 var password = this.password_; 144 var password = this.password_;
142 this.password_ = ''; 145 this.password_ = '';
143 146
144 this.setModes = function(modes, credentials, onComplete) { 147 this.setModes = function(modes, credentials, onComplete) {
145 chrome.quickUnlockPrivate.setModes( 148 this.quickUnlockPrivate_.setModes(
146 password, modes, credentials, onComplete); 149 password, modes, credentials, onComplete);
147 }; 150 }.bind(this);
148 151
149 function clearSetModes() { 152 function clearSetModes() {
150 // Reset the password so that any cached references to this.setModes 153 // Reset the password so that any cached references to this.setModes
151 // will fail. 154 // will fail.
152 password = ''; 155 password = '';
153 this.setModes = null; 156 this.setModes = null;
154 } 157 }
155 158
156 this.clearAccountPasswordTimeout_ = setTimeout( 159 this.clearAccountPasswordTimeout_ = setTimeout(
157 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); 160 clearSetModes.bind(this), this.passwordActiveDurationMs_);
158 // Closing the dialog will clear this.password_. 161
159 this.$.dialog.close(); 162 // Clear stored password state and close the dialog.
163 this.password_ = '';
164 if (this.$.dialog.open)
165 this.$.dialog.close();
160 } 166 }
161 } 167 }
162 168
163 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); 169 this.checkAccountPassword_(this.password_, onPasswordChecked.bind(this));
164 }, 170 },
165 171
166 /** @private */ 172 /** @private */
167 onPasswordChanged_: function() { 173 onPasswordChanged_: function() {
168 this.passwordInvalid_ = false; 174 this.passwordInvalid_ = false;
169 }, 175 },
170 176
171 /** @private */ 177 /** @private */
172 enableConfirm_: function() { 178 enableConfirm_: function() {
173 return !!this.password_ && !this.passwordInvalid_; 179 return !!this.password_ && !this.passwordInvalid_;
180 },
181
182 /**
183 * Helper method that checks if |password| is valid.
184 * @param {string} password
185 * @param {function(boolean):void} onCheck
stevenjb 2016/10/13 21:36:45 Since this is now a member function we don't need
jdufault 2016/10/13 23:41:23 |onCheck| comes from a local, but I've inlined |pa
stevenjb 2016/10/14 01:49:11 Oh, so it is. There doesn't seem to be much reason
186 */
187 checkAccountPassword_: function(password, onCheck) {
188 // We check the account password by trying to update the active set of quick
189 // unlock modes without changing any credentials.
190 this.quickUnlockPrivate_.getActiveModes(function(modes) {
191 var credentials =
192 /** @type {!Array<string>} */ (Array(modes.length).fill(''));
193 this.quickUnlockPrivate_.setModes(password, modes, credentials, onCheck);
194 }.bind(this));
174 } 195 }
175 }); 196 });
176 197
177 })(); 198 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698