OLD | NEW |
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 cr.define('settings_people_page_quick_unlock', function() { | 5 cr.define('settings_people_page_quick_unlock', function() { |
6 var element = null; | 6 var element = null; |
7 var quickUnlockPrivateApi = null; | 7 var quickUnlockPrivateApi = null; |
8 var QuickUnlockMode = chrome.quickUnlockPrivate.QuickUnlockMode; | 8 var QuickUnlockMode = chrome.quickUnlockPrivate.QuickUnlockMode; |
9 var fakeUma = null; | 9 var fakeUma = null; |
10 | 10 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 139 } |
140 | 140 |
141 function registerLockScreenTests() { | 141 function registerLockScreenTests() { |
142 suite('lock-screen', function() { | 142 suite('lock-screen', function() { |
143 /** @const */ var ENABLE_LOCK_SCREEN_PREF = 'settings.enable_screen_lock'; | 143 /** @const */ var ENABLE_LOCK_SCREEN_PREF = 'settings.enable_screen_lock'; |
144 | 144 |
145 var fakeSettings = null; | 145 var fakeSettings = null; |
146 var passwordRadioButton = null; | 146 var passwordRadioButton = null; |
147 var pinPasswordRadioButton = null; | 147 var pinPasswordRadioButton = null; |
148 var noneRadioButton = null; | 148 var noneRadioButton = null; |
149 var configureButton = null; | |
150 | 149 |
151 /** | 150 /** |
152 * Asserts that only the given radio button is active and all of the | 151 * Asserts that only the given radio button is active and all of the |
153 * others are inactive. | 152 * others are inactive. |
154 * @param {Element} radioButton | 153 * @param {Element} radioButton |
155 */ | 154 */ |
156 function assertRadioButtonActive(radioButton) { | 155 function assertRadioButtonActive(radioButton) { |
157 function doAssert(element, name) { | 156 function doAssert(element, name) { |
158 if (radioButton == element) | 157 if (radioButton == element) |
159 assertTrue(element.active, 'Expected ' + name + ' to be active'); | 158 assertTrue(element.active, 'Expected ' + name + ' to be active'); |
(...skipping 20 matching lines...) Expand all Loading... |
180 | 179 |
181 /** | 180 /** |
182 * Changes the lock screen pref value using the settings API; this is like | 181 * Changes the lock screen pref value using the settings API; this is like |
183 * the pref got changed from an unkown source such as another tab. | 182 * the pref got changed from an unkown source such as another tab. |
184 * @param {boolean} value | 183 * @param {boolean} value |
185 */ | 184 */ |
186 function setLockScreenPref(value) { | 185 function setLockScreenPref(value) { |
187 fakeSettings.setPref(ENABLE_LOCK_SCREEN_PREF, value, '', assertTrue); | 186 fakeSettings.setPref(ENABLE_LOCK_SCREEN_PREF, value, '', assertTrue); |
188 } | 187 } |
189 | 188 |
| 189 function isSetupPinButtonVisible() { |
| 190 Polymer.dom.flush(); |
| 191 var setupPinButton = element.$$('#setupPinButton'); |
| 192 return isVisible(setupPinButton); |
| 193 } |
| 194 |
190 setup(function(done) { | 195 setup(function(done) { |
191 PolymerTest.clearBody(); | 196 PolymerTest.clearBody(); |
192 | 197 |
193 CrSettingsPrefs.deferInitialization = true; | 198 CrSettingsPrefs.deferInitialization = true; |
194 | 199 |
195 // Build pref fakes. | 200 // Build pref fakes. |
196 var fakePrefs = [{ | 201 var fakePrefs = [{ |
197 key: ENABLE_LOCK_SCREEN_PREF, | 202 key: ENABLE_LOCK_SCREEN_PREF, |
198 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 203 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
199 value: true | 204 value: true |
(...skipping 22 matching lines...) Expand all Loading... |
222 document.body.appendChild(element); | 227 document.body.appendChild(element); |
223 Polymer.dom.flush(); | 228 Polymer.dom.flush(); |
224 | 229 |
225 element.setModes_ = | 230 element.setModes_ = |
226 quickUnlockPrivateApi.setModes.bind(quickUnlockPrivateApi, ''); | 231 quickUnlockPrivateApi.setModes.bind(quickUnlockPrivateApi, ''); |
227 | 232 |
228 passwordRadioButton = | 233 passwordRadioButton = |
229 getFromElement('paper-radio-button[name="password"]'); | 234 getFromElement('paper-radio-button[name="password"]'); |
230 pinPasswordRadioButton = | 235 pinPasswordRadioButton = |
231 getFromElement('paper-radio-button[name="pin+password"]'); | 236 getFromElement('paper-radio-button[name="pin+password"]'); |
232 configureButton = getFromElement('a[is="action-link"]'); | |
233 | 237 |
234 done(); | 238 done(); |
235 }); | 239 }); |
236 }); | 240 }); |
237 | 241 |
238 // Showing the choose method screen does not make any destructive pref or | 242 // Showing the choose method screen does not make any destructive pref or |
239 // quickUnlockPrivate calls. | 243 // quickUnlockPrivate calls. |
240 test('ShowingScreenDoesNotModifyPrefs', function() { | 244 test('ShowingScreenDoesNotModifyPrefs', function() { |
241 assertTrue(getLockScreenPref()); | 245 assertTrue(getLockScreenPref()); |
242 assertRadioButtonActive(passwordRadioButton); | 246 assertRadioButtonActive(passwordRadioButton); |
243 assertDeepEquals([], quickUnlockPrivateApi.activeModes); | 247 assertDeepEquals([], quickUnlockPrivateApi.activeModes); |
244 }); | 248 }); |
245 | 249 |
246 // The various radio buttons update internal state and do not modify | 250 // The various radio buttons update internal state and do not modify |
247 // prefs. | 251 // prefs. |
248 test('TappingButtonsChangesUnderlyingState', function() { | 252 test('TappingButtonsChangesUnderlyingState', function() { |
249 function togglePin() { | 253 function togglePin() { |
250 assertRadioButtonActive(passwordRadioButton); | 254 assertRadioButtonActive(passwordRadioButton); |
251 | 255 |
252 // Tap pin+password button. | 256 // Tap pin+password button. |
253 MockInteractions.tap(pinPasswordRadioButton); | 257 MockInteractions.tap(pinPasswordRadioButton); |
254 assertRadioButtonActive(pinPasswordRadioButton); | 258 assertRadioButtonActive(pinPasswordRadioButton); |
255 assertTrue(isVisible(configureButton)); | 259 assertTrue(isSetupPinButtonVisible()); |
256 assertDeepEquals([], quickUnlockPrivateApi.activeModes); | 260 assertDeepEquals([], quickUnlockPrivateApi.activeModes); |
257 | 261 |
258 // Enable quick unlock so that we verify tapping password disables it. | 262 // Enable quick unlock so that we verify tapping password disables it. |
259 setActiveModes([QuickUnlockMode.PIN]); | 263 setActiveModes([QuickUnlockMode.PIN]); |
260 | 264 |
261 // Tap password button and verify quick unlock is disabled. | 265 // Tap password button and verify quick unlock is disabled. |
262 MockInteractions.tap(passwordRadioButton); | 266 MockInteractions.tap(passwordRadioButton); |
263 assertRadioButtonActive(passwordRadioButton); | 267 assertRadioButtonActive(passwordRadioButton); |
264 assertFalse(isVisible(configureButton)); | 268 assertFalse(isSetupPinButtonVisible()); |
265 assertDeepEquals([], quickUnlockPrivateApi.activeModes); | 269 assertDeepEquals([], quickUnlockPrivateApi.activeModes); |
266 } | 270 } |
267 | 271 |
268 // Verify toggling PIN on/off does not disable screen lock. | 272 // Verify toggling PIN on/off does not disable screen lock. |
269 setLockScreenPref(true); | 273 setLockScreenPref(true); |
270 togglePin(); | 274 togglePin(); |
271 assertTrue(getLockScreenPref()); | 275 assertTrue(getLockScreenPref()); |
272 | 276 |
273 // Verify toggling PIN on/off does not enable screen lock. | 277 // Verify toggling PIN on/off does not enable screen lock. |
274 setLockScreenPref(false); | 278 setLockScreenPref(false); |
275 togglePin(); | 279 togglePin(); |
276 assertFalse(getLockScreenPref()); | 280 assertFalse(getLockScreenPref()); |
277 }); | 281 }); |
278 | 282 |
279 // If quick unlock is changed by another settings page the radio button | 283 // If quick unlock is changed by another settings page the radio button |
280 // will update to show quick unlock is active. | 284 // will update to show quick unlock is active. |
281 test('EnablingQuickUnlockChangesButtonState', function() { | 285 test('EnablingQuickUnlockChangesButtonState', function() { |
282 setActiveModes([QuickUnlockMode.PIN]); | 286 setActiveModes([QuickUnlockMode.PIN]); |
283 assertRadioButtonActive(pinPasswordRadioButton); | 287 assertRadioButtonActive(pinPasswordRadioButton); |
284 assertTrue(isVisible(configureButton)); | 288 assertTrue(isSetupPinButtonVisible()); |
285 | 289 |
286 setActiveModes([]); | 290 setActiveModes([]); |
287 assertRadioButtonActive(passwordRadioButton); | 291 assertRadioButtonActive(passwordRadioButton); |
288 assertDeepEquals([], quickUnlockPrivateApi.activeModes); | 292 assertDeepEquals([], quickUnlockPrivateApi.activeModes); |
289 }); | 293 }); |
290 | 294 |
291 // Tapping the PIN configure button opens up the setup PIN dialog, and | 295 // Tapping the PIN configure button opens up the setup PIN dialog, and |
292 // records a chose pin or password uma. | 296 // records a chose pin or password uma. |
293 test('TappingConfigureOpensSetupPin', function() { | 297 test('TappingConfigureOpensSetupPin', function() { |
294 assertEquals(0, fakeUma.getHistogramValue( | 298 assertEquals(0, fakeUma.getHistogramValue( |
295 LockScreenProgress.CHOOSE_PIN_OR_PASSWORD)); | 299 LockScreenProgress.CHOOSE_PIN_OR_PASSWORD)); |
296 assertRadioButtonActive(passwordRadioButton); | 300 assertRadioButtonActive(passwordRadioButton); |
297 | 301 |
298 MockInteractions.tap(pinPasswordRadioButton); | 302 MockInteractions.tap(pinPasswordRadioButton); |
299 assertTrue(isVisible(configureButton)); | 303 assertTrue(isSetupPinButtonVisible()); |
300 assertRadioButtonActive(pinPasswordRadioButton) | 304 assertRadioButtonActive(pinPasswordRadioButton) |
301 | 305 |
302 MockInteractions.tap(configureButton); | 306 Polymer.dom.flush(); |
| 307 MockInteractions.tap(getFromElement('#setupPinButton')); |
303 var setupPinDialog = getFromElement('#setupPin'); | 308 var setupPinDialog = getFromElement('#setupPin'); |
304 assertTrue(setupPinDialog.$.dialog.open); | 309 assertTrue(setupPinDialog.$.dialog.open); |
305 assertEquals(1, fakeUma.getHistogramValue( | 310 assertEquals(1, fakeUma.getHistogramValue( |
306 LockScreenProgress.CHOOSE_PIN_OR_PASSWORD)); | 311 LockScreenProgress.CHOOSE_PIN_OR_PASSWORD)); |
307 }); | 312 }); |
308 }); | 313 }); |
309 } | 314 } |
310 | 315 |
311 function registerSetupPinDialogTests() { | 316 function registerSetupPinDialogTests() { |
312 suite('setup-pin-dialog', function() { | 317 suite('setup-pin-dialog', function() { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 }); | 490 }); |
486 }); | 491 }); |
487 } | 492 } |
488 | 493 |
489 return { | 494 return { |
490 registerAuthenticateTests: registerAuthenticateTests, | 495 registerAuthenticateTests: registerAuthenticateTests, |
491 registerLockScreenTests: registerLockScreenTests, | 496 registerLockScreenTests: registerLockScreenTests, |
492 registerSetupPinDialogTests: registerSetupPinDialogTests | 497 registerSetupPinDialogTests: registerSetupPinDialogTests |
493 }; | 498 }; |
494 }); | 499 }); |
OLD | NEW |