Chromium Code Reviews| 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 // Test that the 'OK' button is disabled when the password fields are | |
| 230 // empty (even though they both have the same value). | |
| 231 MockInteractions.keyEventOn(passwordInputElement, 'input', 32); | |
|
dschuyler
2016/03/11 21:18:15
If this is a space bar key code, please
make a co
dpapad
2016/03/14 19:34:50
Done.
| |
| 232 assertTrue(dialog.$.ok.disabled); | |
| 233 | |
| 234 // Test that the 'OK' button is disabled until the two password fields | |
| 235 // match. | |
| 236 passwordInputElement.value = 'foopassword'; | |
| 237 MockInteractions.keyEventOn(passwordInputElement, 'input', 32); | |
| 238 assertTrue(dialog.$.ok.disabled); | |
| 239 confirmPasswordInputElement.value = passwordInputElement.value; | |
| 240 MockInteractions.keyEventOn(passwordInputElement, 'input', 32); | |
| 241 assertFalse(dialog.$.ok.disabled); | |
| 242 | |
| 243 // Simulate clicking 'OK'. | |
| 244 MockInteractions.tap(dialog.$.ok); | |
| 245 | |
| 246 var methodName = 'exportPersonalCertificatePasswordSelected'; | |
| 247 return browserProxy.whenCalled(methodName).then(function(password) { | |
| 248 assertEquals(passwordInputElement.value, password); | |
| 249 // Check that the dialog is closed. | |
| 250 assertFalse(dialog.$.dialog.opened); | |
| 251 }); | |
| 252 }); | |
| 253 }); | |
| 254 } | |
| 255 | |
| 189 return { | 256 return { |
| 190 registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, | 257 registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, |
| 191 registerDeleteDialogTests: registerDeleteDialogTests, | 258 registerDeleteDialogTests: registerDeleteDialogTests, |
| 259 registerPasswordEncryptDialogTests: registerPasswordEncryptDialogTests, | |
| 192 }; | 260 }; |
| 193 }); | 261 }); |
| OLD | NEW |