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('certificate_manager_page', function() { | 5 cr.define('certificate_manager_page', function() { |
6 /** | 6 /** |
7 * A test version of CertificatesBrowserProxy. Provides helper methods | 7 * A test version of CertificatesBrowserProxy. Provides helper methods |
8 * for allowing tests to know when a method was called, as well as | 8 * for allowing tests to know when a method was called, as well as |
9 * specifying mock responses. | 9 * specifying mock responses. |
10 * | 10 * |
11 * @constructor | 11 * @constructor |
12 * @implements {settings.CertificatesBrowserProxy} | 12 * @implements {settings.CertificatesBrowserProxy} |
13 * @extends {settings.TestBrowserProxy} | 13 * @extends {settings.TestBrowserProxy} |
14 */ | 14 */ |
15 var TestCertificatesBrowserProxy = function() { | 15 var TestCertificatesBrowserProxy = function() { |
16 settings.TestBrowserProxy.call(this, [ | 16 settings.TestBrowserProxy.call(this, [ |
17 'deleteCertificate', | 17 'deleteCertificate', |
18 'editCaCertificateTrust', | 18 'editCaCertificateTrust', |
19 'exportPersonalCertificatePasswordSelected', | 19 'exportPersonalCertificatePasswordSelected', |
20 'getCaCertificateTrust', | 20 'getCaCertificateTrust', |
| 21 'importPersonalCertificatePasswordSelected', |
21 ]); | 22 ]); |
22 | 23 |
23 /** @private {!CaTrustInfo} */ | 24 /** @private {!CaTrustInfo} */ |
24 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; | 25 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; |
25 }; | 26 }; |
26 | 27 |
27 TestCertificatesBrowserProxy.prototype = { | 28 TestCertificatesBrowserProxy.prototype = { |
28 __proto__: settings.TestBrowserProxy.prototype, | 29 __proto__: settings.TestBrowserProxy.prototype, |
29 | 30 |
30 /** | 31 /** |
(...skipping 22 matching lines...) Expand all Loading... |
53 this.methodCalled('deleteCertificate', id); | 54 this.methodCalled('deleteCertificate', id); |
54 return Promise.resolve(); | 55 return Promise.resolve(); |
55 }, | 56 }, |
56 | 57 |
57 /** @override */ | 58 /** @override */ |
58 exportPersonalCertificatePasswordSelected: function(password) { | 59 exportPersonalCertificatePasswordSelected: function(password) { |
59 this.resolverMap_.get( | 60 this.resolverMap_.get( |
60 'exportPersonalCertificatePasswordSelected').resolve(password); | 61 'exportPersonalCertificatePasswordSelected').resolve(password); |
61 return Promise.resolve(); | 62 return Promise.resolve(); |
62 }, | 63 }, |
| 64 |
| 65 /** @override */ |
| 66 importPersonalCertificatePasswordSelected: function(password) { |
| 67 this.resolverMap_.get( |
| 68 'importPersonalCertificatePasswordSelected').resolve(password); |
| 69 return Promise.resolve(); |
| 70 }, |
63 }; | 71 }; |
64 | 72 |
65 /** @return {!CertificateSubnode} */ | 73 /** @return {!CertificateSubnode} */ |
66 var createSampleCertificateSubnode = function() { | 74 function createSampleCertificateSubnode() { |
67 return { | 75 return { |
68 extractable: false, | 76 extractable: false, |
69 id: 'dummyId', | 77 id: 'dummyId', |
70 name: 'dummyName', | 78 name: 'dummyName', |
71 policy: false, | 79 policy: false, |
72 readonly: false, | 80 readonly: false, |
73 untrusted: false, | 81 untrusted: false, |
74 urlLocked: false, | 82 urlLocked: false, |
75 }; | 83 }; |
76 }; | 84 } |
| 85 |
| 86 /** |
| 87 * Triggers an 'input' event on the given text input field (which triggers |
| 88 * validation to occur for password fields being tested in this file). |
| 89 * @param {!PaperInputElement} element |
| 90 */ |
| 91 function triggerInputEvent(element) { |
| 92 // The actual key code is irrelevant for tests. |
| 93 var kSpaceBar = 32; |
| 94 MockInteractions.keyEventOn(element, 'input', kSpaceBar); |
| 95 } |
77 | 96 |
78 function registerCaTrustEditDialogTests() { | 97 function registerCaTrustEditDialogTests() { |
79 /** @type {?SettingsCaTrustEditDialogElement} */ | 98 /** @type {?SettingsCaTrustEditDialogElement} */ |
80 var dialog = null; | 99 var dialog = null; |
81 | 100 |
82 /** @type {?TestCertificatesBrowserProxy} */ | 101 /** @type {?TestCertificatesBrowserProxy} */ |
83 var browserProxy = null; | 102 var browserProxy = null; |
84 | 103 |
85 /** @type {!CertificateSubnode} */ | 104 /** @type {!CertificateSubnode} */ |
86 var model = createSampleCertificateSubnode(); | 105 var model = createSampleCertificateSubnode(); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 221 |
203 test('EncryptSuccess', function() { | 222 test('EncryptSuccess', function() { |
204 var passwordInputElements = | 223 var passwordInputElements = |
205 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input'); | 224 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input'); |
206 var passwordInputElement = passwordInputElements[0]; | 225 var passwordInputElement = passwordInputElements[0]; |
207 var confirmPasswordInputElement = passwordInputElements[1]; | 226 var confirmPasswordInputElement = passwordInputElements[1]; |
208 | 227 |
209 assertTrue(dialog.$.dialog.opened); | 228 assertTrue(dialog.$.dialog.opened); |
210 assertTrue(dialog.$.ok.disabled); | 229 assertTrue(dialog.$.ok.disabled); |
211 | 230 |
212 var triggerValidation = function(element) { | |
213 // Simulating an 'input' event on the given password input field, | |
214 // which triggers validation to occur. The actual key code is | |
215 // irrelevant for this test. | |
216 var kSpaceBar = 32; | |
217 MockInteractions.keyEventOn(element, 'input', kSpaceBar); | |
218 }; | |
219 | |
220 // Test that the 'OK' button is disabled when the password fields are | 231 // Test that the 'OK' button is disabled when the password fields are |
221 // empty (even though they both have the same value). | 232 // empty (even though they both have the same value). |
222 triggerValidation(passwordInputElement); | 233 triggerInputEvent(passwordInputElement); |
223 assertTrue(dialog.$.ok.disabled); | 234 assertTrue(dialog.$.ok.disabled); |
224 | 235 |
225 // Test that the 'OK' button is disabled until the two password fields | 236 // Test that the 'OK' button is disabled until the two password fields |
226 // match. | 237 // match. |
227 passwordInputElement.value = 'foopassword'; | 238 passwordInputElement.value = 'foopassword'; |
228 triggerValidation(passwordInputElement); | 239 triggerInputEvent(passwordInputElement); |
229 assertTrue(dialog.$.ok.disabled); | 240 assertTrue(dialog.$.ok.disabled); |
230 confirmPasswordInputElement.value = passwordInputElement.value; | 241 confirmPasswordInputElement.value = passwordInputElement.value; |
231 triggerValidation(confirmPasswordInputElement); | 242 triggerInputEvent(confirmPasswordInputElement); |
232 assertFalse(dialog.$.ok.disabled); | 243 assertFalse(dialog.$.ok.disabled); |
233 | 244 |
234 // Simulate clicking 'OK'. | 245 // Simulate clicking 'OK'. |
235 MockInteractions.tap(dialog.$.ok); | 246 MockInteractions.tap(dialog.$.ok); |
236 | 247 |
237 var methodName = 'exportPersonalCertificatePasswordSelected'; | 248 var methodName = 'exportPersonalCertificatePasswordSelected'; |
238 return browserProxy.whenCalled(methodName).then(function(password) { | 249 return browserProxy.whenCalled(methodName).then(function(password) { |
239 assertEquals(passwordInputElement.value, password); | 250 assertEquals(passwordInputElement.value, password); |
240 // Check that the dialog is closed. | 251 // Check that the dialog is closed. |
241 assertFalse(dialog.$.dialog.opened); | 252 assertFalse(dialog.$.dialog.opened); |
242 }); | 253 }); |
243 }); | 254 }); |
244 }); | 255 }); |
245 } | 256 } |
246 | 257 |
| 258 function registerPasswordDecryptDialogTests() { |
| 259 /** @type {?SettingsCertificatePasswordDecryptionDialogElement} */ |
| 260 var dialog = null; |
| 261 |
| 262 /** @type {?TestCertificatesBrowserProxy} */ |
| 263 var browserProxy = null; |
| 264 |
| 265 suite('CertificatePasswordDecryptionDialogTests', function() { |
| 266 setup(function() { |
| 267 browserProxy = new TestCertificatesBrowserProxy(); |
| 268 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
| 269 PolymerTest.clearBody(); |
| 270 dialog = document.createElement( |
| 271 'settings-certificate-password-decryption-dialog'); |
| 272 document.body.appendChild(dialog); |
| 273 }); |
| 274 |
| 275 teardown(function() { dialog.remove(); }); |
| 276 |
| 277 test('DecryptSuccess', function() { |
| 278 var passwordInputElement = |
| 279 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); |
| 280 assertTrue(dialog.$.dialog.opened); |
| 281 assertTrue(dialog.$.ok.disabled); |
| 282 |
| 283 // Test that the 'OK' button is disabled when the password field is |
| 284 // empty. |
| 285 triggerInputEvent(passwordInputElement); |
| 286 assertTrue(dialog.$.ok.disabled); |
| 287 passwordInputElement.value = 'foopassword'; |
| 288 triggerInputEvent(passwordInputElement); |
| 289 assertFalse(dialog.$.ok.disabled); |
| 290 |
| 291 // Simulate clicking 'OK'. |
| 292 MockInteractions.tap(dialog.$.ok); |
| 293 |
| 294 var methodName = 'importPersonalCertificatePasswordSelected'; |
| 295 return browserProxy.whenCalled(methodName).then(function(password) { |
| 296 assertEquals(passwordInputElement.value, password); |
| 297 // Check that the dialog is closed. |
| 298 assertFalse(dialog.$.dialog.opened); |
| 299 }); |
| 300 }); |
| 301 }); |
| 302 } |
| 303 |
247 return { | 304 return { |
248 registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, | 305 registerTests: function() { |
249 registerDeleteDialogTests: registerDeleteDialogTests, | 306 registerCaTrustEditDialogTests(); |
250 registerPasswordEncryptDialogTests: registerPasswordEncryptDialogTests, | 307 registerDeleteDialogTests(); |
| 308 registerPasswordEncryptDialogTests(); |
| 309 registerPasswordDecryptDialogTests(); |
| 310 }, |
251 }; | 311 }; |
252 }); | 312 }); |
OLD | NEW |