Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 cr.define('certificate_manager_page', function() { | |
| 6 /** | |
| 7 * A test version of CertificatesBrowserProxy. Provides helper methods | |
| 8 * for allowing tests to know when a method was called, as well as | |
| 9 * specifying mock responses. | |
| 10 * | |
| 11 * @constructor | |
| 12 * @implements {settings.CertificatesBrowserProxy} | |
| 13 */ | |
| 14 var TestCertificatesBrowserProxy = function() { | |
| 15 /** @private {!Map<string, !PromiseResolver>} */ | |
| 16 this.resolverMap_ = new Map(); | |
| 17 var wrapperMethods = [ | |
| 18 'getCaCertificateTrust', | |
| 19 'editCaCertificateTrust', | |
| 20 ]; | |
| 21 wrapperMethods.forEach(this.resetResolver, this); | |
| 22 | |
| 23 /** @private {!CaTrustInfo} */ | |
| 24 this.caTrustInfo_ = { ssl: true, email: true, objSign: true }; | |
|
Dan Beam
2016/03/09 21:46:38
no spaces between braces
dpapad
2016/03/09 22:33:56
Done.
| |
| 25 }; | |
| 26 | |
| 27 TestCertificatesBrowserProxy.prototype = { | |
| 28 /** | |
| 29 * @param {string} methodName | |
| 30 * @return {!Promise} A promise that is resolved when the given method | |
| 31 * is called. | |
| 32 */ | |
| 33 whenCalled: function(methodName) { | |
| 34 return this.resolverMap_.get(methodName).promise; | |
| 35 }, | |
| 36 | |
| 37 /** | |
| 38 * Resets the PromiseResolver associated with the given method. | |
| 39 * @param {string} methodName | |
| 40 */ | |
| 41 resetResolver: function(methodName) { | |
| 42 this.resolverMap_.set(methodName, new PromiseResolver()); | |
| 43 }, | |
| 44 | |
| 45 /** | |
| 46 * @param {!CaTrustInfo} caTrustInfo | |
| 47 */ | |
| 48 setCaCertificateTrust: function(caTrustInfo) { | |
| 49 this.caTrustInfo_ = caTrustInfo; | |
| 50 }, | |
| 51 | |
| 52 /** @override */ | |
| 53 getCaCertificateTrust: function(id) { | |
| 54 this.resolverMap_.get('getCaCertificateTrust').resolve(id); | |
| 55 return Promise.resolve(this.caTrustInfo_); | |
| 56 }, | |
| 57 | |
| 58 /** @override */ | |
| 59 editCaCertificateTrust: function(id, ssl, email, objSign) { | |
| 60 this.resolverMap_.get('editCaCertificateTrust').resolve({ | |
| 61 id: id, ssl: ssl, email: email, objSign: objSign, | |
| 62 }); | |
|
Dan Beam
2016/03/09 21:46:38
why can't we just return the result of this .resol
dpapad
2016/03/09 22:33:56
There are two separate promises being resolved her
| |
| 63 return Promise.resolve(); | |
| 64 }, | |
| 65 }; | |
| 66 | |
| 67 /** @return {!CertificateSubnode} */ | |
| 68 var createSampleCertificateSubnode = function() { | |
| 69 return { | |
| 70 extractable: false, | |
| 71 id: 'dummyId', | |
| 72 name: 'dummyName', | |
| 73 policy: false, | |
| 74 readonly: false, | |
| 75 untrusted: false, | |
| 76 urlLocked: false, | |
| 77 }; | |
| 78 }; | |
| 79 | |
| 80 function registerCaTrustEditDialogTests() { | |
| 81 /** @type {?SettingsCaTrustEditDialogElement} */ | |
| 82 var dialog = null; | |
| 83 | |
| 84 /** @type {?TestCertificatesBrowserProxy} */ | |
| 85 var browserProxy = null; | |
| 86 | |
| 87 /** @type {!CertificateSubnode} */ | |
| 88 var model = createSampleCertificateSubnode(); | |
| 89 | |
| 90 /** @type {!CaTrustInfo} */ | |
| 91 var caTrustInfo = { ssl: true, email: false, objSign: false }; | |
| 92 | |
| 93 suite('CaTrustEditDialogTests', function() { | |
| 94 setup(function() { | |
| 95 browserProxy = new TestCertificatesBrowserProxy(); | |
| 96 browserProxy.setCaCertificateTrust(caTrustInfo); | |
| 97 | |
| 98 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; | |
| 99 PolymerTest.clearBody(); | |
| 100 dialog = document.createElement('settings-ca-trust-edit-dialog'); | |
| 101 dialog.model = model; | |
| 102 document.body.appendChild(dialog); | |
| 103 }); | |
| 104 | |
| 105 teardown(function() { dialog.remove(); }); | |
| 106 | |
| 107 test('Dialog', function() { | |
| 108 return browserProxy.whenCalled('getCaCertificateTrust').then( | |
| 109 function(id) { | |
| 110 assertEquals(model.id, id); | |
| 111 assertEquals(caTrustInfo.ssl, dialog.$.ssl.checked); | |
| 112 assertEquals(caTrustInfo.email, dialog.$.email.checked); | |
| 113 assertEquals(caTrustInfo.objSign, dialog.$.objSign.checked); | |
| 114 | |
| 115 // Simulate toggling all checkboxes. | |
| 116 MockInteractions.tap(dialog.$.ssl); | |
| 117 MockInteractions.tap(dialog.$.email); | |
| 118 MockInteractions.tap(dialog.$.objSign); | |
| 119 | |
| 120 // Simulate clicking 'OK'. | |
| 121 MockInteractions.tap(dialog.$.ok); | |
| 122 | |
| 123 return browserProxy.whenCalled('editCaCertificateTrust').then( | |
| 124 function(args) { | |
| 125 assertEquals(model.id, args.id); | |
| 126 // Checking that the values sent to C++ are reflecting the | |
| 127 // changes made by the user (toggling all checkboxes). | |
| 128 assertEquals(caTrustInfo.ssl, !args.ssl); | |
| 129 assertEquals(caTrustInfo.email, !args.email); | |
| 130 assertEquals(caTrustInfo.objSign, !args.objSign); | |
| 131 // Check that the dialog is closed. | |
| 132 assertFalse(dialog.$.dialog.opened); | |
| 133 }); | |
| 134 }); | |
| 135 }); | |
| 136 }); | |
| 137 } | |
| 138 | |
| 139 return { | |
| 140 registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, | |
| 141 }; | |
| 142 }); | |
| OLD | NEW |