OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
Devlin
2016/05/31 22:58:39
no (c)
jdufault
2016/06/01 00:07:36
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 var QuickUnlockMode = chrome.quickUnlockPrivate.QuickUnlockMode; | |
6 | |
7 function checkPassword(password, callback) { | |
8 chrome.quickUnlockPrivate.getActiveModes(onGetActiveModes); | |
9 | |
10 function onGetActiveModes(modes) { | |
11 var passwords = Array(modes.length).fill(''); | |
12 chrome.quickUnlockPrivate.setModes(password, modes, passwords, callback); | |
13 } | |
14 } | |
15 | |
16 // Verifies that the valid password is accepted. This uses a fake authentication | |
17 // backend. | |
18 function checkValidPasswordTest() { | |
19 checkPassword('valid', onCheckPassword); | |
20 | |
21 function onCheckPassword(result) { | |
22 chrome.test.assertTrue(result); | |
23 chrome.test.succeed(); | |
24 }; | |
25 } | |
26 | |
27 // Verifies that the invalid password is rejected. This uses a fake | |
28 // authentication backend. | |
29 function checkInvalidPasswordTest() { | |
30 checkPassword('invalid', onCheckPassword); | |
31 | |
32 function onCheckPassword(result) { | |
33 chrome.test.assertFalse(result); | |
34 chrome.test.succeed(); | |
35 }; | |
36 } | |
37 | |
38 // Verifies that chrome.quickUnlockPrivate.getAvailableModes returns only PIN. | |
39 function checkAvailableModes() { | |
40 chrome.quickUnlockPrivate.getAvailableModes(onGetAvailableModes); | |
41 | |
42 function onGetAvailableModes(modes) { | |
43 chrome.test.checkDeepEq(modes, [QuickUnlockMode.PIN]); | |
44 chrome.test.succeed(); | |
45 } | |
46 } | |
47 | |
48 // Verifies that we cannot change modes with an invalid password. | |
49 function checkSetModesFailsWithInvalidPassword() { | |
50 function onActiveModesChanged(newModes) { | |
51 chrome.test.fail('Mode change callback should not be called'); | |
52 } | |
53 | |
54 chrome.quickUnlockPrivate.onActiveModesChanged.addListener( | |
55 onActiveModesChanged); | |
56 | |
57 chrome.quickUnlockPrivate.setModes( | |
58 'invalid', [QuickUnlockMode.PIN], ['111'], onModeSet); | |
59 | |
60 function onModeSet(success) { | |
61 chrome.quickUnlockPrivate.onActiveModesChanged.removeListener( | |
62 onActiveModesChanged); | |
63 | |
64 chrome.test.assertFalse(success); | |
65 chrome.test.succeed(); | |
66 } | |
67 } | |
68 | |
69 // Verifies that we can set the quick unlock mode to PIN, we can fetch that mode | |
70 // using getActiveModes, and that we can clear the pin with setModes. | |
71 function checkSetAndGetModes() { | |
72 chrome.quickUnlockPrivate.setModes( | |
73 'valid', [QuickUnlockMode.PIN], ['111'], onModeSet); | |
74 | |
75 function onModeSet(result) { | |
76 chrome.test.assertTrue(result); | |
77 chrome.quickUnlockPrivate.getActiveModes(onGetActiveModesExpectPin); | |
78 } | |
79 | |
80 function onGetActiveModesExpectPin(modes) { | |
81 chrome.test.checkDeepEq(modes, [QuickUnlockMode.PIN]); | |
82 chrome.quickUnlockPrivate.setModes('valid', [], [], onModeClear); | |
83 } | |
84 | |
85 function onModeClear(result) { | |
86 chrome.test.assertTrue(result); | |
87 chrome.quickUnlockPrivate.getActiveModes(onGetActiveModesExpectNone); | |
88 } | |
89 | |
90 function onGetActiveModesExpectNone(modes) { | |
91 chrome.test.checkDeepEq(modes, []); | |
92 chrome.test.succeed(); | |
93 } | |
94 } | |
95 | |
96 // Verifies that the onActiveModesChange event gets called. | |
97 function checkActiveModesChangedEvent() { | |
98 chrome.quickUnlockPrivate.setModes('valid', [], [], chrome.test.assertTrue); | |
99 | |
100 chrome.quickUnlockPrivate.onActiveModesChanged.addListener( | |
101 onActiveModesChanged); | |
102 function onActiveModesChanged(newModes) { | |
103 chrome.quickUnlockPrivate.onActiveModesChanged.removeListener( | |
104 onActiveModesChanged); | |
105 | |
106 chrome.test.checkDeepEq(newModes, [QuickUnlockMode.PIN]); | |
107 chrome.test.succeed(); | |
108 } | |
109 | |
110 chrome.quickUnlockPrivate.setModes( | |
111 'valid', [QuickUnlockMode.PIN], ['111'], chrome.test.assertTrue); | |
112 } | |
113 | |
114 chrome.test.sendMessage('ready'); | |
115 chrome.test.runTests( | |
116 [checkValidPasswordTest, checkInvalidPasswordTest, checkAvailableModes, | |
117 checkSetModesFailsWithInvalidPassword, checkSetAndGetModes, | |
118 checkActiveModesChangedEvent]); | |
OLD | NEW |