| 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 */ | 13 */ |
| 14 var TestCertificatesBrowserProxy = function() { | 14 var TestCertificatesBrowserProxy = function() { |
| 15 /** @private {!Map<string, !PromiseResolver>} */ | 15 /** @private {!Map<string, !PromiseResolver>} */ |
| 16 this.resolverMap_ = new Map(); | 16 this.resolverMap_ = new Map(); |
| 17 var wrapperMethods = [ | 17 var wrapperMethods = [ |
| 18 'deleteCertificate', | 18 'deleteCertificate', |
| 19 'editCaCertificateTrust', | 19 'editCaCertificateTrust', |
| 20 'exportPersonalCertificatePasswordSelected', |
| 20 'getCaCertificateTrust', | 21 'getCaCertificateTrust', |
| 21 ]; | 22 ]; |
| 22 wrapperMethods.forEach(this.resetResolver, this); | 23 wrapperMethods.forEach(this.resetResolver, this); |
| 23 | 24 |
| 24 /** @private {!CaTrustInfo} */ | 25 /** @private {!CaTrustInfo} */ |
| 25 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; | 26 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 TestCertificatesBrowserProxy.prototype = { | 29 TestCertificatesBrowserProxy.prototype = { |
| 29 /** | 30 /** |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 id: id, ssl: ssl, email: email, objSign: objSign, | 63 id: id, ssl: ssl, email: email, objSign: objSign, |
| 63 }); | 64 }); |
| 64 return Promise.resolve(); | 65 return Promise.resolve(); |
| 65 }, | 66 }, |
| 66 | 67 |
| 67 /** @override */ | 68 /** @override */ |
| 68 deleteCertificate: function(id) { | 69 deleteCertificate: function(id) { |
| 69 this.resolverMap_.get('deleteCertificate').resolve(id); | 70 this.resolverMap_.get('deleteCertificate').resolve(id); |
| 70 return Promise.resolve(); | 71 return Promise.resolve(); |
| 71 }, | 72 }, |
| 73 |
| 74 /** @override */ |
| 75 exportPersonalCertificatePasswordSelected: function(password) { |
| 76 this.resolverMap_.get( |
| 77 'exportPersonalCertificatePasswordSelected').resolve(password); |
| 78 return Promise.resolve(); |
| 79 }, |
| 72 }; | 80 }; |
| 73 | 81 |
| 74 /** @return {!CertificateSubnode} */ | 82 /** @return {!CertificateSubnode} */ |
| 75 var createSampleCertificateSubnode = function() { | 83 var createSampleCertificateSubnode = function() { |
| 76 return { | 84 return { |
| 77 extractable: false, | 85 extractable: false, |
| 78 id: 'dummyId', | 86 id: 'dummyId', |
| 79 name: 'dummyName', | 87 name: 'dummyName', |
| 80 policy: false, | 88 policy: false, |
| 81 readonly: false, | 89 readonly: false, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return browserProxy.whenCalled('deleteCertificate').then( | 187 return browserProxy.whenCalled('deleteCertificate').then( |
| 180 function(id) { | 188 function(id) { |
| 181 assertEquals(model.id, id); | 189 assertEquals(model.id, id); |
| 182 // Check that the dialog is closed. | 190 // Check that the dialog is closed. |
| 183 assertFalse(dialog.$.dialog.opened); | 191 assertFalse(dialog.$.dialog.opened); |
| 184 }); | 192 }); |
| 185 }); | 193 }); |
| 186 }); | 194 }); |
| 187 } | 195 } |
| 188 | 196 |
| 197 function registerPasswordEncryptDialogTests() { |
| 198 /** @type {?SettingsCertificatePasswordEncryptionDialogElement} */ |
| 199 var dialog = null; |
| 200 |
| 201 /** @type {?TestCertificatesBrowserProxy} */ |
| 202 var browserProxy = null; |
| 203 |
| 204 /** @type {!CertificateSubnode} */ |
| 205 var model = createSampleCertificateSubnode(); |
| 206 |
| 207 suite('CertificatePasswordEncryptionDialogTests', function() { |
| 208 setup(function() { |
| 209 browserProxy = new TestCertificatesBrowserProxy(); |
| 210 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
| 211 PolymerTest.clearBody(); |
| 212 dialog = document.createElement( |
| 213 'settings-certificate-password-encryption-dialog'); |
| 214 dialog.model = model; |
| 215 document.body.appendChild(dialog); |
| 216 }); |
| 217 |
| 218 teardown(function() { dialog.remove(); }); |
| 219 |
| 220 test('EncryptSuccess', function() { |
| 221 var passwordInputElements = |
| 222 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input'); |
| 223 var passwordInputElement = passwordInputElements[0]; |
| 224 var confirmPasswordInputElement = passwordInputElements[1]; |
| 225 |
| 226 assertTrue(dialog.$.dialog.opened); |
| 227 assertTrue(dialog.$.ok.disabled); |
| 228 |
| 229 var triggerValidation = function(element) { |
| 230 // Simulating an 'input' event on the given password input field, |
| 231 // which triggers validation to occur. The actual key code is |
| 232 // irrelevant for this test. |
| 233 var kSpaceBar = 32; |
| 234 MockInteractions.keyEventOn(element, 'input', kSpaceBar); |
| 235 }; |
| 236 |
| 237 // Test that the 'OK' button is disabled when the password fields are |
| 238 // empty (even though they both have the same value). |
| 239 triggerValidation(passwordInputElement); |
| 240 assertTrue(dialog.$.ok.disabled); |
| 241 |
| 242 // Test that the 'OK' button is disabled until the two password fields |
| 243 // match. |
| 244 passwordInputElement.value = 'foopassword'; |
| 245 triggerValidation(passwordInputElement); |
| 246 assertTrue(dialog.$.ok.disabled); |
| 247 confirmPasswordInputElement.value = passwordInputElement.value; |
| 248 triggerValidation(confirmPasswordInputElement); |
| 249 assertFalse(dialog.$.ok.disabled); |
| 250 |
| 251 // Simulate clicking 'OK'. |
| 252 MockInteractions.tap(dialog.$.ok); |
| 253 |
| 254 var methodName = 'exportPersonalCertificatePasswordSelected'; |
| 255 return browserProxy.whenCalled(methodName).then(function(password) { |
| 256 assertEquals(passwordInputElement.value, password); |
| 257 // Check that the dialog is closed. |
| 258 assertFalse(dialog.$.dialog.opened); |
| 259 }); |
| 260 }); |
| 261 }); |
| 262 } |
| 263 |
| 189 return { | 264 return { |
| 190 registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, | 265 registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, |
| 191 registerDeleteDialogTests: registerDeleteDialogTests, | 266 registerDeleteDialogTests: registerDeleteDialogTests, |
| 267 registerPasswordEncryptDialogTests: registerPasswordEncryptDialogTests, |
| 192 }; | 268 }; |
| 193 }); | 269 }); |
| OLD | NEW |