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 /** | 5 /** |
6 * @fileoverview Fake implementation of chrome.quickUnlockPrivate for testing. | 6 * @fileoverview Fake implementation of chrome.quickUnlockPrivate for testing. |
7 */ | 7 */ |
| 8 |
| 9 /** |
| 10 * A couple weak pins to use for testing. |
| 11 * @const |
| 12 */ |
| 13 var TEST_WEAK_PINS = ['1111', '1234', '1313', '2001', '1010']; |
| 14 |
8 cr.define('settings', function() { | 15 cr.define('settings', function() { |
9 /** | 16 /** |
10 * Fake of the chrome.quickUnlockPrivate API. | 17 * Fake of the chrome.quickUnlockPrivate API. |
11 * @constructor | 18 * @constructor |
12 * @implements {QuickUnlockPrivate} | 19 * @implements {QuickUnlockPrivate} |
13 */ | 20 */ |
14 function FakeQuickUnlockPrivate() { | 21 function FakeQuickUnlockPrivate() { |
15 /** @type {!Array<!chrome.quickUnlockPrivate.QuickUnlockMode>} */ | 22 /** @type {!Array<!chrome.quickUnlockPrivate.QuickUnlockMode>} */ |
16 this.availableModes = [chrome.quickUnlockPrivate.QuickUnlockMode.PIN]; | 23 this.availableModes = [chrome.quickUnlockPrivate.QuickUnlockMode.PIN]; |
17 /** @type {!Array<!chrome.quickUnlockPrivate.QuickUnlockMode>} */ | 24 /** @type {!Array<!chrome.quickUnlockPrivate.QuickUnlockMode>} */ |
18 this.activeModes = []; | 25 this.activeModes = []; |
19 /** @type {!Array<string>} */ this.credentials = []; | 26 /** @type {!Array<string>} */ this.credentials = []; |
20 /** @type {string} */ this.accountPassword = ''; | 27 /** @type {string} */ this.accountPassword = ''; |
| 28 /** @type {!chrome.quickUnlockPrivate.CredentialRequirements} */ |
| 29 this.credentialRequirements = {minLength: 4, maxLength: 0}; |
21 } | 30 } |
22 | 31 |
23 FakeQuickUnlockPrivate.prototype = { | 32 FakeQuickUnlockPrivate.prototype = { |
24 // Public testing methods. | 33 // Public testing methods. |
25 /** | 34 /** |
26 * @override | 35 * @override |
27 * @param {function( | 36 * @param {function( |
28 * !Array<!chrome.quickUnlockPrivate.QuickUnlockMode>):void} onComplete | 37 * !Array<!chrome.quickUnlockPrivate.QuickUnlockMode>):void} onComplete |
29 */ | 38 */ |
30 getAvailableModes: function(onComplete) { | 39 getAvailableModes: function(onComplete) { |
(...skipping 16 matching lines...) Expand all Loading... |
47 * @param {!Array<string>} credentials | 56 * @param {!Array<string>} credentials |
48 * @param {function(boolean):void} onComplete | 57 * @param {function(boolean):void} onComplete |
49 */ | 58 */ |
50 setModes: function(accountPassword, modes, credentials, onComplete) { | 59 setModes: function(accountPassword, modes, credentials, onComplete) { |
51 // Even if the account password is wrong we still update activeModes and | 60 // Even if the account password is wrong we still update activeModes and |
52 // credentials so that the mock owner has a chance to see what was given | 61 // credentials so that the mock owner has a chance to see what was given |
53 // to the API. | 62 // to the API. |
54 this.activeModes = modes; | 63 this.activeModes = modes; |
55 this.credentials = credentials; | 64 this.credentials = credentials; |
56 onComplete(this.accountPassword == accountPassword); | 65 onComplete(this.accountPassword == accountPassword); |
57 } | 66 }, |
| 67 |
| 68 /** |
| 69 * @override |
| 70 * @param {!chrome.quickUnlockPrivate.QuickUnlockMode} mode |
| 71 * @param {string} credential |
| 72 * @param {function( |
| 73 * !chrome.quickUnlockPrivate.CredentialCheck):void} onComplete |
| 74 */ |
| 75 checkCredential: function(mode, credential, onComplete) { |
| 76 var message = {}; |
| 77 var errors = []; |
| 78 var warnings = []; |
| 79 |
| 80 if (!!credential && |
| 81 credential.length < this.credentialRequirements.minLength) { |
| 82 errors.push(chrome.quickUnlockPrivate.CredentialProblem.TOO_SHORT); |
| 83 } |
| 84 |
| 85 if (!!credential && this.credentialRequirements.maxLength != 0 && |
| 86 credential.length > this.credentialRequirements.maxLength) { |
| 87 errors.push(chrome.quickUnlockPrivate.CredentialProblem.TOO_LONG); |
| 88 } |
| 89 |
| 90 if (!!credential && TEST_WEAK_PINS.includes(credential)) |
| 91 warnings.push(chrome.quickUnlockPrivate.CredentialProblem.TOO_WEAK); |
| 92 |
| 93 message.errors = errors; |
| 94 message.warnings = warnings; |
| 95 onComplete(message); |
| 96 }, |
| 97 |
| 98 /** |
| 99 * @override. |
| 100 * @param {!chrome.quickUnlockPrivate.QuickUnlockMode} mode |
| 101 * @param {function( |
| 102 * !chrome.quickUnlockPrivate.CredentialRequirements):void onComplete |
| 103 */ |
| 104 getCredentialRequirements: function(mode, onComplete) { |
| 105 onComplete(this.credentialRequirements); |
| 106 }, |
58 }; | 107 }; |
59 | 108 |
60 /** @type {!ChromeEvent} */ | 109 /** @type {!ChromeEvent} */ |
61 FakeQuickUnlockPrivate.prototype.onActiveModesChanged = new FakeChromeEvent(); | 110 FakeQuickUnlockPrivate.prototype.onActiveModesChanged = new FakeChromeEvent(); |
62 | 111 |
63 return {FakeQuickUnlockPrivate: FakeQuickUnlockPrivate}; | 112 return {FakeQuickUnlockPrivate: FakeQuickUnlockPrivate}; |
64 }); | 113 }); |
OLD | NEW |