OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 * @constructor | 6 * @constructor |
7 * @implements {settings.FingerprintBrowserProxy} | 7 * @implements {settings.FingerprintBrowserProxy} |
8 * @extends {settings.TestBrowserProxy} | 8 * @extends {settings.TestBrowserProxy} |
9 */ | 9 */ |
10 var TestFingerprintBrowserProxy = function() { | 10 var TestFingerprintBrowserProxy = function() { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 var browserProxy = null; | 113 var browserProxy = null; |
114 | 114 |
115 /** | 115 /** |
116 * @param {number} index | 116 * @param {number} index |
117 * @param {string=} opt_label | 117 * @param {string=} opt_label |
118 */ | 118 */ |
119 function createFakeEvent(index, opt_label) { | 119 function createFakeEvent(index, opt_label) { |
120 return {model: {index: index, item: opt_label || ''}}; | 120 return {model: {index: index, item: opt_label || ''}}; |
121 } | 121 } |
122 | 122 |
| 123 function openDialog() { |
| 124 MockInteractions.tap(fingerprintList.$$('.action-button')); |
| 125 Polymer.dom.flush(); |
| 126 dialog = fingerprintList.$$('settings-setup-fingerprint-dialog'); |
| 127 addAnotherButton = dialog.$$('#addAnotherButton'); |
| 128 } |
| 129 |
123 /** | 130 /** |
124 * @param {!Element} element | 131 * @param {!Element} element |
125 */ | 132 */ |
126 function isVisible(element) { | 133 function isVisible(element) { |
127 return element.offsetWidth > 0 && element.offsetHeight > 0; | 134 return element.offsetWidth > 0 && element.offsetHeight > 0; |
128 } | 135 } |
129 | 136 |
130 setup(function() { | 137 setup(function() { |
131 browserProxy = new TestFingerprintBrowserProxy(); | 138 browserProxy = new TestFingerprintBrowserProxy(); |
132 settings.FingerprintBrowserProxyImpl.instance_ = browserProxy; | 139 settings.FingerprintBrowserProxyImpl.instance_ = browserProxy; |
133 | 140 |
134 PolymerTest.clearBody(); | 141 PolymerTest.clearBody(); |
135 fingerprintList = document.createElement('settings-fingerprint-list'); | 142 fingerprintList = document.createElement('settings-fingerprint-list'); |
136 document.body.appendChild(fingerprintList); | 143 document.body.appendChild(fingerprintList); |
137 dialog = fingerprintList.$.setupFingerprint; | |
138 addAnotherButton = dialog.$.addAnotherButton; | |
139 Polymer.dom.flush(); | 144 Polymer.dom.flush(); |
140 return Promise.all([ | 145 return Promise.all([ |
141 browserProxy.whenCalled('startAuthentication'), | 146 browserProxy.whenCalled('startAuthentication'), |
142 browserProxy.whenCalled('getFingerprintsList')]).then(function() { | 147 browserProxy.whenCalled('getFingerprintsList')]).then(function() { |
143 assertEquals(0, fingerprintList.fingerprints_.length); | 148 assertEquals(0, fingerprintList.fingerprints_.length); |
144 browserProxy.resetResolver('getFingerprintsList'); | 149 browserProxy.resetResolver('getFingerprintsList'); |
145 }); | 150 }); |
146 }); | 151 }); |
147 | 152 |
148 // Verify running through the enroll session workflow | 153 // Verify running through the enroll session workflow |
149 // (settings-setup-fingerprint-dialog) works as expected. | 154 // (settings-setup-fingerprint-dialog) works as expected. |
150 test('EnrollingFingerprint', function() { | 155 test('EnrollingFingerprint', function() { |
151 assertFalse(dialog.$.dialog.open); | 156 openDialog(); |
152 MockInteractions.tap(fingerprintList.$$('.action-button')); | |
153 return browserProxy.whenCalled('startEnroll').then(function() { | 157 return browserProxy.whenCalled('startEnroll').then(function() { |
154 assertTrue(dialog.$.dialog.open); | 158 assertTrue(dialog.$$('#dialog').open); |
155 assertEquals(0, dialog.receivedScanCount_); | 159 assertEquals(0, dialog.receivedScanCount_); |
156 assertEquals(settings.FingerprintSetupStep.LOCATE_SCANNER, dialog.step_); | 160 assertEquals(settings.FingerprintSetupStep.LOCATE_SCANNER, dialog.step_); |
157 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, false); | 161 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, false); |
158 assertEquals(1, dialog.receivedScanCount_); | 162 assertEquals(1, dialog.receivedScanCount_); |
159 assertEquals(settings.FingerprintSetupStep.MOVE_FINGER, dialog.step_); | 163 assertEquals(settings.FingerprintSetupStep.MOVE_FINGER, dialog.step_); |
160 | 164 |
161 // Verify that by sending a scan problem, the div that contains the | 165 // Verify that by sending a scan problem, the div that contains the |
162 // problem message and icon should be visible. | 166 // problem message and icon should be visible. |
163 browserProxy.scanReceived(settings.FingerprintResultType.TOO_FAST, false); | 167 browserProxy.scanReceived(settings.FingerprintResultType.TOO_FAST, false); |
164 assertEquals(1, dialog.receivedScanCount_); | 168 assertEquals(1, dialog.receivedScanCount_); |
165 assertEquals('visible', | 169 assertEquals('visible', |
166 window.getComputedStyle(dialog.$.problemDiv).visibility); | 170 window.getComputedStyle(dialog.$$('#problemDiv')).visibility); |
167 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, false); | 171 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, false); |
168 assertEquals('hidden', | 172 assertEquals('hidden', |
169 window.getComputedStyle(dialog.$.problemDiv).visibility); | 173 window.getComputedStyle(dialog.$$('#problemDiv')).visibility); |
170 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, false); | 174 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, false); |
171 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, true); | 175 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, true); |
172 assertEquals(settings.FingerprintSetupStep.READY, dialog.step_); | 176 assertEquals(settings.FingerprintSetupStep.READY, dialog.step_); |
173 | 177 |
174 // Verify that by tapping the continue button we should exit the dialog | 178 // Verify that by tapping the continue button we should exit the dialog |
175 // and the fingerprint list should have one fingerprint registered. | 179 // and the fingerprint list should have one fingerprint registered. |
176 MockInteractions.tap(dialog.$.closeButton); | 180 MockInteractions.tap(dialog.$$('#closeButton')); |
177 return PolymerTest.flushTasks().then(function() { | 181 return PolymerTest.flushTasks().then(function() { |
178 Promise.all([ | 182 Promise.all([ |
179 browserProxy.whenCalled('startAuthentication'), | 183 browserProxy.whenCalled('startAuthentication'), |
180 browserProxy.whenCalled('getFingerprintsList')]).then( | 184 browserProxy.whenCalled('getFingerprintsList')]).then( |
181 function() { | 185 function() { |
182 assertEquals(1, fingerprintList.fingerprints_.length); | 186 assertEquals(1, fingerprintList.fingerprints_.length); |
183 }); | 187 }); |
184 }); | 188 }); |
185 }); | 189 }); |
186 }); | 190 }); |
187 | 191 |
188 // Verify enrolling a fingerprint, then enrolling another without closing the | 192 // Verify enrolling a fingerprint, then enrolling another without closing the |
189 // dialog works as intended. | 193 // dialog works as intended. |
190 test('EnrollingAnotherFingerprint', function() { | 194 test('EnrollingAnotherFingerprint', function() { |
191 assertFalse(dialog.$.dialog.open); | 195 openDialog(); |
192 MockInteractions.tap(fingerprintList.$$('.action-button')); | |
193 return browserProxy.whenCalled('startEnroll').then(function() { | 196 return browserProxy.whenCalled('startEnroll').then(function() { |
194 browserProxy.resetResolver('startEnroll'); | 197 browserProxy.resetResolver('startEnroll'); |
195 | 198 |
196 assertTrue(dialog.$.dialog.open); | 199 assertTrue(dialog.$$('#dialog').open); |
197 assertEquals(0, dialog.receivedScanCount_); | 200 assertEquals(0, dialog.receivedScanCount_); |
198 assertFalse(isVisible(addAnotherButton)); | 201 assertFalse(isVisible(addAnotherButton)); |
199 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, true); | 202 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, true); |
200 assertEquals(settings.FingerprintSetupStep.READY, dialog.step_); | 203 assertEquals(settings.FingerprintSetupStep.READY, dialog.step_); |
201 | 204 |
202 assertTrue(dialog.$.dialog.open); | 205 assertTrue(dialog.$$('#dialog').open); |
203 assertTrue(isVisible(addAnotherButton)); | 206 assertTrue(isVisible(addAnotherButton)); |
204 MockInteractions.tap(addAnotherButton); | 207 MockInteractions.tap(addAnotherButton); |
205 | 208 |
206 // Once the first fingerprint is enrolled, verify that enrolling the | 209 // Once the first fingerprint is enrolled, verify that enrolling the |
207 // second fingerprint without closing the dialog works as expected. | 210 // second fingerprint without closing the dialog works as expected. |
208 return Promise.all([ | 211 return Promise.all([ |
209 browserProxy.whenCalled('startEnroll'), | 212 browserProxy.whenCalled('startEnroll'), |
210 browserProxy.whenCalled('getFingerprintsList')]); | 213 browserProxy.whenCalled('getFingerprintsList')]); |
211 }).then(function() { | 214 }).then(function() { |
212 browserProxy.resetResolver('getFingerprintsList'); | 215 browserProxy.resetResolver('getFingerprintsList'); |
213 | 216 |
214 assertTrue(dialog.$.dialog.open); | 217 assertTrue(dialog.$$('#dialog').open); |
215 assertFalse(isVisible(addAnotherButton)); | 218 assertFalse(isVisible(addAnotherButton)); |
216 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, true); | 219 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, true); |
217 | 220 |
218 // Verify that by tapping the continue button we should exit the dialog | 221 // Verify that by tapping the continue button we should exit the dialog |
219 // and the fingerprint list should have two fingerprints registered. | 222 // and the fingerprint list should have two fingerprints registered. |
220 MockInteractions.tap(dialog.$.closeButton); | 223 MockInteractions.tap(dialog.$$('#closeButton')); |
221 return browserProxy.whenCalled('getFingerprintsList'); | 224 return browserProxy.whenCalled('getFingerprintsList'); |
222 }).then(function() { | 225 }).then(function() { |
223 assertEquals(2, fingerprintList.fingerprints_.length); | 226 assertEquals(2, fingerprintList.fingerprints_.length); |
224 }); | 227 }); |
225 }); | 228 }); |
226 | 229 |
227 test('CancelEnrollingFingerprint', function() { | 230 test('CancelEnrollingFingerprint', function() { |
228 assertFalse(dialog.$.dialog.open); | 231 openDialog(); |
229 MockInteractions.tap(fingerprintList.$$('.action-button')); | |
230 return browserProxy.whenCalled('startEnroll').then(function() { | 232 return browserProxy.whenCalled('startEnroll').then(function() { |
231 assertTrue(dialog.$.dialog.open); | 233 assertTrue(dialog.$$('#dialog').open); |
232 assertEquals(0, dialog.receivedScanCount_); | 234 assertEquals(0, dialog.receivedScanCount_); |
233 assertEquals(settings.FingerprintSetupStep.LOCATE_SCANNER, dialog.step_); | 235 assertEquals(settings.FingerprintSetupStep.LOCATE_SCANNER, dialog.step_); |
234 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, false); | 236 browserProxy.scanReceived(settings.FingerprintResultType.SUCCESS, false); |
235 assertEquals(1, dialog.receivedScanCount_); | 237 assertEquals(1, dialog.receivedScanCount_); |
236 assertEquals(settings.FingerprintSetupStep.MOVE_FINGER, dialog.step_); | 238 assertEquals(settings.FingerprintSetupStep.MOVE_FINGER, dialog.step_); |
237 | 239 |
238 // Verify that by tapping the exit button we should exit the dialog | 240 // Verify that by tapping the exit button we should exit the dialog |
239 // and the fingerprint list should have zero fingerprints registered. | 241 // and the fingerprint list should have zero fingerprints registered. |
240 MockInteractions.tap(dialog.$.closeButton); | 242 MockInteractions.tap(dialog.$$('#closeButton')); |
241 return Promise.all([ | 243 return Promise.all([ |
242 browserProxy.whenCalled('cancelCurrentEnroll'), | 244 browserProxy.whenCalled('cancelCurrentEnroll'), |
243 browserProxy.whenCalled('startAuthentication')]); | 245 browserProxy.whenCalled('startAuthentication')]); |
244 }).then(function() { | 246 }).then(function() { |
245 assertEquals(0, fingerprintList.fingerprints_.length); | 247 assertEquals(0, fingerprintList.fingerprints_.length); |
246 }); | 248 }); |
247 }); | 249 }); |
248 | 250 |
249 test('RemoveFingerprint', function() { | 251 test('RemoveFingerprint', function() { |
250 browserProxy.setFingerprints(['Label 1', 'Label 2']); | 252 browserProxy.setFingerprints(['Label 1', 'Label 2']); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 return Promise.all([ | 301 return Promise.all([ |
300 browserProxy.whenCalled('removeEnrollment'), | 302 browserProxy.whenCalled('removeEnrollment'), |
301 browserProxy.whenCalled('getFingerprintsList')]); | 303 browserProxy.whenCalled('getFingerprintsList')]); |
302 }).then(function() { | 304 }).then(function() { |
303 assertEquals(4, fingerprintList.fingerprints_.length); | 305 assertEquals(4, fingerprintList.fingerprints_.length); |
304 assertFalse( | 306 assertFalse( |
305 fingerprintList.$$('.action-button').disabled); | 307 fingerprintList.$$('.action-button').disabled); |
306 }); | 308 }); |
307 }); | 309 }); |
308 }); | 310 }); |
OLD | NEW |