| 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 | 10 |
| 10 /** | 11 /** |
| 11 * Returns if the element is visible. | 12 * Returns if the element is visible. |
| 12 * @param {!Element} element | 13 * @param {!Element} element |
| 13 */ | 14 */ |
| 14 function isVisible(element) { | 15 function isVisible(element) { |
| 15 while (element) { | 16 while (element) { |
| 16 if (element.offsetWidth <= 0 || element.offsetHeight <= 0 || | 17 if (element.offsetWidth <= 0 || element.offsetHeight <= 0 || |
| 17 element.hidden) { | 18 element.hidden) { |
| 18 return false; | 19 return false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 55 } |
| 55 | 56 |
| 56 function registerAuthenticateTests() { | 57 function registerAuthenticateTests() { |
| 57 suite('authenticate', function() { | 58 suite('authenticate', function() { |
| 58 var passwordElement = null; | 59 var passwordElement = null; |
| 59 | 60 |
| 60 setup(function() { | 61 setup(function() { |
| 61 PolymerTest.clearBody(); | 62 PolymerTest.clearBody(); |
| 62 | 63 |
| 63 quickUnlockPrivateApi = new settings.FakeQuickUnlockPrivate(); | 64 quickUnlockPrivateApi = new settings.FakeQuickUnlockPrivate(); |
| 65 fakeUma = new settings.FakeQuickUnlockUma(); |
| 64 | 66 |
| 65 element = document.createElement('settings-password-prompt-dialog'); | 67 element = document.createElement('settings-password-prompt-dialog'); |
| 66 element.quickUnlockPrivate_ = quickUnlockPrivateApi; | 68 element.quickUnlockPrivate_ = quickUnlockPrivateApi; |
| 69 element.writeUma_ = fakeUma.recordProgress.bind(fakeUma); |
| 67 document.body.appendChild(element); | 70 document.body.appendChild(element); |
| 68 | 71 |
| 69 passwordElement = getFromElement('#passwordInput'); | 72 passwordElement = getFromElement('#passwordInput'); |
| 70 }); | 73 }); |
| 71 | 74 |
| 72 test('PasswordCheckDoesNotChangeActiveMode', function() { | 75 test('PasswordCheckDoesNotChangeActiveMode', function() { |
| 73 // No active modes. | 76 // No active modes. |
| 74 quickUnlockPrivateApi.activeModes = []; | 77 quickUnlockPrivateApi.activeModes = []; |
| 75 passwordElement.value = 'foo'; | 78 passwordElement.value = 'foo'; |
| 76 element.submitPassword_(); | 79 element.submitPassword_(); |
| 77 assertDeepEquals([], quickUnlockPrivateApi.activeModes); | 80 assertDeepEquals([], quickUnlockPrivateApi.activeModes); |
| 78 assertDeepEquals([], quickUnlockPrivateApi.credentials); | 81 assertDeepEquals([], quickUnlockPrivateApi.credentials); |
| 79 | 82 |
| 80 // PIN is active. | 83 // PIN is active. |
| 81 quickUnlockPrivateApi.activeModes = [QuickUnlockMode.PIN]; | 84 quickUnlockPrivateApi.activeModes = [QuickUnlockMode.PIN]; |
| 82 passwordElement.value = 'foo'; | 85 passwordElement.value = 'foo'; |
| 83 element.submitPassword_(); | 86 element.submitPassword_(); |
| 84 assertDeepEquals([QuickUnlockMode.PIN], | 87 assertDeepEquals([QuickUnlockMode.PIN], |
| 85 quickUnlockPrivateApi.activeModes); | 88 quickUnlockPrivateApi.activeModes); |
| 86 assertDeepEquals([''], quickUnlockPrivateApi.credentials); | 89 assertDeepEquals([''], quickUnlockPrivateApi.credentials); |
| 87 }); | 90 }); |
| 88 | 91 |
| 89 // A bad password does not provide an authenticated setModes object. | 92 // A bad password does not provide an authenticated setModes object, and a |
| 93 // entered password correctly uma should not be recorded. |
| 90 test('InvalidPasswordDoesNotProvideAuthentication', function() { | 94 test('InvalidPasswordDoesNotProvideAuthentication', function() { |
| 91 quickUnlockPrivateApi.accountPassword = 'bar'; | 95 quickUnlockPrivateApi.accountPassword = 'bar'; |
| 92 | 96 |
| 93 passwordElement.value = 'foo'; | 97 passwordElement.value = 'foo'; |
| 94 element.submitPassword_(); | 98 element.submitPassword_(); |
| 95 | 99 |
| 100 assertEquals(0, fakeUma.getHistogramValue( |
| 101 LockScreenProgress.ENTER_PASSWORD_CORRECTLY)); |
| 96 assertFalse(!!element.setModes); | 102 assertFalse(!!element.setModes); |
| 97 }); | 103 }); |
| 98 | 104 |
| 99 // A valid password provides an authenticated setModes object. | 105 // A valid password provides an authenticated setModes object, and a |
| 106 // entered password correctly uma should be recorded. |
| 100 test('ValidPasswordProvidesAuthentication', function() { | 107 test('ValidPasswordProvidesAuthentication', function() { |
| 101 quickUnlockPrivateApi.accountPassword = 'foo'; | 108 quickUnlockPrivateApi.accountPassword = 'foo'; |
| 102 | 109 |
| 103 passwordElement.value = 'foo'; | 110 passwordElement.value = 'foo'; |
| 104 element.submitPassword_(); | 111 element.submitPassword_(); |
| 105 | 112 |
| 113 assertEquals(1, fakeUma.getHistogramValue( |
| 114 LockScreenProgress.ENTER_PASSWORD_CORRECTLY)); |
| 106 assertTrue(!!element.setModes); | 115 assertTrue(!!element.setModes); |
| 107 }); | 116 }); |
| 108 | 117 |
| 109 // The setModes objects times out after a delay. | 118 // The setModes objects times out after a delay. |
| 110 test('AuthenticationTimesOut', function(done) { | 119 test('AuthenticationTimesOut', function(done) { |
| 111 quickUnlockPrivateApi.accountPassword = 'foo'; | 120 quickUnlockPrivateApi.accountPassword = 'foo'; |
| 112 | 121 |
| 113 element.passwordActiveDurationMs_ = 0; | 122 element.passwordActiveDurationMs_ = 0; |
| 114 passwordElement.value = 'foo'; | 123 passwordElement.value = 'foo'; |
| 115 element.submitPassword_(); | 124 element.submitPassword_(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 200 |
| 192 CrSettingsPrefs.deferInitialization = true; | 201 CrSettingsPrefs.deferInitialization = true; |
| 193 | 202 |
| 194 // Build pref fakes. | 203 // Build pref fakes. |
| 195 var fakePrefs = [{ | 204 var fakePrefs = [{ |
| 196 key: ENABLE_LOCK_SCREEN_PREF, | 205 key: ENABLE_LOCK_SCREEN_PREF, |
| 197 type: chrome.settingsPrivate.PrefType.BOOLEAN, | 206 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 198 value: true | 207 value: true |
| 199 }]; | 208 }]; |
| 200 fakeSettings = new settings.FakeSettingsPrivate(fakePrefs); | 209 fakeSettings = new settings.FakeSettingsPrivate(fakePrefs); |
| 210 fakeUma = new settings.FakeQuickUnlockUma(); |
| 201 setLockScreenPref(true); | 211 setLockScreenPref(true); |
| 202 var prefElement = document.createElement('settings-prefs'); | 212 var prefElement = document.createElement('settings-prefs'); |
| 203 prefElement.initialize(fakeSettings); | 213 prefElement.initialize(fakeSettings); |
| 204 document.body.appendChild(prefElement); | 214 document.body.appendChild(prefElement); |
| 205 | 215 |
| 206 // Wait for prefElement to finish initializing; it takes some time for | 216 // Wait for prefElement to finish initializing; it takes some time for |
| 207 // the prefs element to get allocated. | 217 // the prefs element to get allocated. |
| 208 prefElement.addEventListener('prefs-changed', function prefsReady() { | 218 prefElement.addEventListener('prefs-changed', function prefsReady() { |
| 209 prefElement.removeEventListener('prefs-changed', prefsReady); | 219 prefElement.removeEventListener('prefs-changed', prefsReady); |
| 210 | 220 |
| 211 quickUnlockPrivateApi = new settings.FakeQuickUnlockPrivate(); | 221 quickUnlockPrivateApi = new settings.FakeQuickUnlockPrivate(); |
| 212 | 222 |
| 213 // Create choose-method element. | 223 // Create choose-method element. |
| 214 element = document.createElement('settings-lock-screen'); | 224 element = document.createElement('settings-lock-screen'); |
| 215 element.settingsPrivate_ = fakeSettings; | 225 element.settingsPrivate_ = fakeSettings; |
| 216 element.quickUnlockPrivate_ = quickUnlockPrivateApi; | 226 element.quickUnlockPrivate_ = quickUnlockPrivateApi; |
| 217 element.prefs = prefElement.prefs; | 227 element.prefs = prefElement.prefs; |
| 228 element.writeUma_ = fakeUma.recordProgress.bind(fakeUma); |
| 218 | 229 |
| 219 document.body.appendChild(element); | 230 document.body.appendChild(element); |
| 220 Polymer.dom.flush(); | 231 Polymer.dom.flush(); |
| 221 | 232 |
| 222 element.setModes_ = | 233 element.setModes_ = |
| 223 quickUnlockPrivateApi.setModes.bind(quickUnlockPrivateApi, ''); | 234 quickUnlockPrivateApi.setModes.bind(quickUnlockPrivateApi, ''); |
| 224 | 235 |
| 225 passwordRadioButton = | 236 passwordRadioButton = |
| 226 getFromElement('paper-radio-button[name="password"]'); | 237 getFromElement('paper-radio-button[name="password"]'); |
| 227 pinPasswordRadioButton = | 238 pinPasswordRadioButton = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 test('EnablingQuickUnlockChangesButtonState', function() { | 289 test('EnablingQuickUnlockChangesButtonState', function() { |
| 279 setActiveModes([QuickUnlockMode.PIN]); | 290 setActiveModes([QuickUnlockMode.PIN]); |
| 280 assertRadioButtonActive(pinPasswordRadioButton); | 291 assertRadioButtonActive(pinPasswordRadioButton); |
| 281 assertTrue(isVisible(configureButton)); | 292 assertTrue(isVisible(configureButton)); |
| 282 | 293 |
| 283 setActiveModes([]); | 294 setActiveModes([]); |
| 284 assertRadioButtonActive(passwordRadioButton); | 295 assertRadioButtonActive(passwordRadioButton); |
| 285 assertDeepEquals([], quickUnlockPrivateApi.activeModes); | 296 assertDeepEquals([], quickUnlockPrivateApi.activeModes); |
| 286 }); | 297 }); |
| 287 | 298 |
| 288 // Tapping the PIN configure button opens up the setup PIN dialog. | 299 // Tapping the PIN configure button opens up the setup PIN dialog, and |
| 300 // records a chose pin or password uma. |
| 289 test('TappingConfigureOpensSetupPin', function() { | 301 test('TappingConfigureOpensSetupPin', function() { |
| 302 assertEquals(0, fakeUma.getHistogramValue( |
| 303 LockScreenProgress.CHOOSE_PIN_OR_PASSWORD)); |
| 290 assertRadioButtonActive(passwordRadioButton); | 304 assertRadioButtonActive(passwordRadioButton); |
| 291 | 305 |
| 292 MockInteractions.tap(pinPasswordRadioButton); | 306 MockInteractions.tap(pinPasswordRadioButton); |
| 293 assertTrue(isVisible(configureButton)); | 307 assertTrue(isVisible(configureButton)); |
| 294 assertRadioButtonActive(pinPasswordRadioButton) | 308 assertRadioButtonActive(pinPasswordRadioButton) |
| 295 | 309 |
| 296 MockInteractions.tap(configureButton); | 310 MockInteractions.tap(configureButton); |
| 297 var setupPinDialog = getFromElement('#setupPin'); | 311 var setupPinDialog = getFromElement('#setupPin'); |
| 298 assertTrue(setupPinDialog.$.dialog.open); | 312 assertTrue(setupPinDialog.$.dialog.open); |
| 313 assertEquals(1, fakeUma.getHistogramValue( |
| 314 LockScreenProgress.CHOOSE_PIN_OR_PASSWORD)); |
| 299 }); | 315 }); |
| 300 }); | 316 }); |
| 301 } | 317 } |
| 302 | 318 |
| 303 function registerSetupPinDialogTests() { | 319 function registerSetupPinDialogTests() { |
| 304 suite('setup-pin-dialog', function() { | 320 suite('setup-pin-dialog', function() { |
| 305 var titleDiv = null; | 321 var titleDiv = null; |
| 306 var problemDiv = null; | 322 var problemDiv = null; |
| 307 var pinKeyboard = null; | 323 var pinKeyboard = null; |
| 308 var backButton = null; | 324 var backButton = null; |
| 309 var continueButton = null; | 325 var continueButton = null; |
| 310 | 326 |
| 311 suiteSetup(function() { | 327 suiteSetup(function() { |
| 312 var urls = ['chrome://md-settings/i18n_setup.html']; | 328 var urls = ['chrome://md-settings/i18n_setup.html']; |
| 313 return Promise.all(urls.map(PolymerTest.importHtml)); | 329 return Promise.all(urls.map(PolymerTest.importHtml)); |
| 314 }); | 330 }); |
| 315 | 331 |
| 316 setup(function() { | 332 setup(function() { |
| 317 PolymerTest.clearBody(); | 333 PolymerTest.clearBody(); |
| 318 | 334 |
| 319 quickUnlockPrivateApi = new settings.FakeQuickUnlockPrivate(); | 335 quickUnlockPrivateApi = new settings.FakeQuickUnlockPrivate(); |
| 336 fakeUma = new settings.FakeQuickUnlockUma(); |
| 320 | 337 |
| 321 // Create setup-pin element. | 338 // Create setup-pin element. |
| 322 element = document.createElement('settings-setup-pin-dialog'); | 339 element = document.createElement('settings-setup-pin-dialog'); |
| 323 element.setModes = | 340 element.setModes = |
| 324 quickUnlockPrivateApi.setModes.bind(quickUnlockPrivateApi, ''); | 341 quickUnlockPrivateApi.setModes.bind(quickUnlockPrivateApi, ''); |
| 342 element.writeUma_ = fakeUma.recordProgress.bind(fakeUma); |
| 325 | 343 |
| 326 document.body.appendChild(element); | 344 document.body.appendChild(element); |
| 327 Polymer.dom.flush(); | 345 Polymer.dom.flush(); |
| 328 | 346 |
| 329 element.open(); | 347 element.open(); |
| 330 | 348 |
| 331 titleDiv = getFromElement('div[class="title"]'); | 349 titleDiv = getFromElement('div[class="title"]'); |
| 332 problemDiv = getFromElement('#problemDiv'); | 350 problemDiv = getFromElement('#problemDiv'); |
| 333 pinKeyboard = getFromElement('pin-keyboard'); | 351 pinKeyboard = getFromElement('pin-keyboard'); |
| 334 backButton = getFromElement('paper-button[class="cancel-button"]'); | 352 backButton = getFromElement('paper-button[class="cancel-button"]'); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 }); | 449 }); |
| 432 | 450 |
| 433 // User has to re-enter PIN for confirm step. | 451 // User has to re-enter PIN for confirm step. |
| 434 test('PinKeyboardIsResetForConfirmStep', function() { | 452 test('PinKeyboardIsResetForConfirmStep', function() { |
| 435 pinKeyboard.value = '1111'; | 453 pinKeyboard.value = '1111'; |
| 436 MockInteractions.tap(continueButton); | 454 MockInteractions.tap(continueButton); |
| 437 assertEquals('', pinKeyboard.value); | 455 assertEquals('', pinKeyboard.value); |
| 438 }); | 456 }); |
| 439 | 457 |
| 440 // Completing the flow results in a call to the quick unlock private API. | 458 // Completing the flow results in a call to the quick unlock private API. |
| 459 // Check that uma stats are called as expected. |
| 441 test('SubmittingPinCallsQuickUnlockApi', function() { | 460 test('SubmittingPinCallsQuickUnlockApi', function() { |
| 442 // Entering the same (even weak) pin twice calls the quick unlock API | 461 // Entering the same (even weak) pin twice calls the quick unlock API |
| 443 // and sets up a PIN. | 462 // and sets up a PIN. |
| 463 assertEquals(0, fakeUma.getHistogramValue( |
| 464 LockScreenProgress.ENTER_PIN)); |
| 465 assertEquals(0, fakeUma.getHistogramValue( |
| 466 LockScreenProgress.CONFIRM_PIN)); |
| 444 pinKeyboard.value = '1111'; | 467 pinKeyboard.value = '1111'; |
| 445 MockInteractions.tap(continueButton); | 468 MockInteractions.tap(continueButton); |
| 469 assertEquals(1, fakeUma.getHistogramValue( |
| 470 LockScreenProgress.ENTER_PIN)); |
| 471 |
| 446 pinKeyboard.value = '1111'; | 472 pinKeyboard.value = '1111'; |
| 447 MockInteractions.tap(continueButton); | 473 MockInteractions.tap(continueButton); |
| 448 | 474 |
| 475 assertEquals(1, fakeUma.getHistogramValue( |
| 476 LockScreenProgress.CONFIRM_PIN)); |
| 449 assertDeepEquals(['PIN'], quickUnlockPrivateApi.activeModes); | 477 assertDeepEquals(['PIN'], quickUnlockPrivateApi.activeModes); |
| 450 assertDeepEquals(['1111'], quickUnlockPrivateApi.credentials); | 478 assertDeepEquals(['1111'], quickUnlockPrivateApi.credentials); |
| 451 }); | 479 }); |
| 452 }); | 480 }); |
| 453 } | 481 } |
| 454 | 482 |
| 455 return { | 483 return { |
| 456 registerAuthenticateTests: registerAuthenticateTests, | 484 registerAuthenticateTests: registerAuthenticateTests, |
| 457 registerLockScreenTests: registerLockScreenTests, | 485 registerLockScreenTests: registerLockScreenTests, |
| 458 registerSetupPinDialogTests: registerSetupPinDialogTests | 486 registerSetupPinDialogTests: registerSetupPinDialogTests |
| 459 }; | 487 }; |
| 460 }); | 488 }); |
| OLD | NEW |