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() { |
|
Dan Beam
2016/03/10 19:01:26
also, it probably makes sense to figure out if we
| |
| 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', | |
| 19 'editCaCertificateTrust', | |
| 18 'getCaCertificateTrust', | 20 'getCaCertificateTrust', |
| 19 'editCaCertificateTrust', | |
| 20 ]; | 21 ]; |
| 21 wrapperMethods.forEach(this.resetResolver, this); | 22 wrapperMethods.forEach(this.resetResolver, this); |
| 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 /** | 29 /** |
| 29 * @param {string} methodName | 30 * @param {string} methodName |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 55 return Promise.resolve(this.caTrustInfo_); | 56 return Promise.resolve(this.caTrustInfo_); |
| 56 }, | 57 }, |
| 57 | 58 |
| 58 /** @override */ | 59 /** @override */ |
| 59 editCaCertificateTrust: function(id, ssl, email, objSign) { | 60 editCaCertificateTrust: function(id, ssl, email, objSign) { |
| 60 this.resolverMap_.get('editCaCertificateTrust').resolve({ | 61 this.resolverMap_.get('editCaCertificateTrust').resolve({ |
| 61 id: id, ssl: ssl, email: email, objSign: objSign, | 62 id: id, ssl: ssl, email: email, objSign: objSign, |
| 62 }); | 63 }); |
| 63 return Promise.resolve(); | 64 return Promise.resolve(); |
| 64 }, | 65 }, |
| 66 | |
| 67 /** @override */ | |
| 68 deleteCertificate: function(id) { | |
| 69 this.resolverMap_.get('deleteCertificate').resolve(id); | |
| 70 return Promise.resolve(); | |
| 71 }, | |
| 65 }; | 72 }; |
| 66 | 73 |
| 67 /** @return {!CertificateSubnode} */ | 74 /** @return {!CertificateSubnode} */ |
| 68 var createSampleCertificateSubnode = function() { | 75 var createSampleCertificateSubnode = function() { |
| 69 return { | 76 return { |
| 70 extractable: false, | 77 extractable: false, |
| 71 id: 'dummyId', | 78 id: 'dummyId', |
| 72 name: 'dummyName', | 79 name: 'dummyName', |
| 73 policy: false, | 80 policy: false, |
| 74 readonly: false, | 81 readonly: false, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 assertEquals(caTrustInfo.email, !args.email); | 136 assertEquals(caTrustInfo.email, !args.email); |
| 130 assertEquals(caTrustInfo.objSign, !args.objSign); | 137 assertEquals(caTrustInfo.objSign, !args.objSign); |
| 131 // Check that the dialog is closed. | 138 // Check that the dialog is closed. |
| 132 assertFalse(dialog.$.dialog.opened); | 139 assertFalse(dialog.$.dialog.opened); |
| 133 }); | 140 }); |
| 134 }); | 141 }); |
| 135 }); | 142 }); |
| 136 }); | 143 }); |
| 137 } | 144 } |
| 138 | 145 |
| 146 function registerDeleteDialogTests() { | |
| 147 /** @type {?SettingsCertificateDeleteConfirmationDialogElement} */ | |
| 148 var dialog = null; | |
| 149 | |
| 150 /** @type {?TestCertificatesBrowserProxy} */ | |
| 151 var browserProxy = null; | |
| 152 | |
| 153 /** @type {!CertificateSubnode} */ | |
| 154 var model = createSampleCertificateSubnode(); | |
| 155 | |
| 156 suite('CertificateDeleteConfirmationDialogTests', function() { | |
| 157 setup(function() { | |
| 158 browserProxy = new TestCertificatesBrowserProxy(); | |
| 159 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; | |
| 160 PolymerTest.clearBody(); | |
| 161 dialog = document.createElement( | |
| 162 'settings-certificate-delete-confirmation-dialog'); | |
| 163 dialog.model = model; | |
| 164 dialog.certificateType = settings.CertificateType.PERSONAL; | |
| 165 document.body.appendChild(dialog); | |
| 166 }); | |
| 167 | |
| 168 teardown(function() { dialog.remove(); }); | |
| 169 | |
| 170 test('DeleteSuccess', function() { | |
| 171 assertTrue(dialog.$.dialog.opened); | |
| 172 // Check that the dialog title includes the certificate name. | |
| 173 var titleEl = Polymer.dom(dialog.$.dialog).querySelector('.title'); | |
| 174 assertTrue(titleEl.textContent.includes(model.name)); | |
| 175 | |
| 176 // Simulate clicking 'OK'. | |
| 177 MockInteractions.tap(dialog.$.ok); | |
| 178 | |
| 179 return browserProxy.whenCalled('deleteCertificate').then( | |
| 180 function(id) { | |
| 181 assertEquals(model.id, id); | |
| 182 // Check that the dialog is closed. | |
| 183 assertFalse(dialog.$.dialog.opened); | |
| 184 }); | |
| 185 }); | |
| 186 }); | |
| 187 } | |
| 188 | |
| 139 return { | 189 return { |
| 140 registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, | 190 registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, |
| 191 registerDeleteDialogTests: registerDeleteDialogTests, | |
| 141 }; | 192 }; |
| 142 }); | 193 }); |
| OLD | NEW |