Chromium Code Reviews| Index: chrome/test/data/webui/settings/certificate_manager_page_test.js |
| diff --git a/chrome/test/data/webui/settings/certificate_manager_page_test.js b/chrome/test/data/webui/settings/certificate_manager_page_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eae25952b14468339628876b380407d1c5740830 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/settings/certificate_manager_page_test.js |
| @@ -0,0 +1,142 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +cr.define('certificate_manager_page', function() { |
| + /** |
| + * A test version of CertificatesBrowserProxy. Provides helper methods |
| + * for allowing tests to know when a method was called, as well as |
| + * specifying mock responses. |
| + * |
| + * @constructor |
| + * @implements {settings.CertificatesBrowserProxy} |
| + */ |
| + var TestCertificatesBrowserProxy = function() { |
| + /** @private {!Map<string, !PromiseResolver>} */ |
| + this.resolverMap_ = new Map(); |
| + var wrapperMethods = [ |
| + 'getCaCertificateTrust', |
| + 'editCaCertificateTrust', |
| + ]; |
| + wrapperMethods.forEach(this.resetResolver, this); |
| + |
| + /** @private {!CaTrustInfo} */ |
| + 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.
|
| + }; |
| + |
| + TestCertificatesBrowserProxy.prototype = { |
| + /** |
| + * @param {string} methodName |
| + * @return {!Promise} A promise that is resolved when the given method |
| + * is called. |
| + */ |
| + whenCalled: function(methodName) { |
| + return this.resolverMap_.get(methodName).promise; |
| + }, |
| + |
| + /** |
| + * Resets the PromiseResolver associated with the given method. |
| + * @param {string} methodName |
| + */ |
| + resetResolver: function(methodName) { |
| + this.resolverMap_.set(methodName, new PromiseResolver()); |
| + }, |
| + |
| + /** |
| + * @param {!CaTrustInfo} caTrustInfo |
| + */ |
| + setCaCertificateTrust: function(caTrustInfo) { |
| + this.caTrustInfo_ = caTrustInfo; |
| + }, |
| + |
| + /** @override */ |
| + getCaCertificateTrust: function(id) { |
| + this.resolverMap_.get('getCaCertificateTrust').resolve(id); |
| + return Promise.resolve(this.caTrustInfo_); |
| + }, |
| + |
| + /** @override */ |
| + editCaCertificateTrust: function(id, ssl, email, objSign) { |
| + this.resolverMap_.get('editCaCertificateTrust').resolve({ |
| + id: id, ssl: ssl, email: email, objSign: objSign, |
| + }); |
|
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
|
| + return Promise.resolve(); |
| + }, |
| + }; |
| + |
| + /** @return {!CertificateSubnode} */ |
| + var createSampleCertificateSubnode = function() { |
| + return { |
| + extractable: false, |
| + id: 'dummyId', |
| + name: 'dummyName', |
| + policy: false, |
| + readonly: false, |
| + untrusted: false, |
| + urlLocked: false, |
| + }; |
| + }; |
| + |
| + function registerCaTrustEditDialogTests() { |
| + /** @type {?SettingsCaTrustEditDialogElement} */ |
| + var dialog = null; |
| + |
| + /** @type {?TestCertificatesBrowserProxy} */ |
| + var browserProxy = null; |
| + |
| + /** @type {!CertificateSubnode} */ |
| + var model = createSampleCertificateSubnode(); |
| + |
| + /** @type {!CaTrustInfo} */ |
| + var caTrustInfo = { ssl: true, email: false, objSign: false }; |
| + |
| + suite('CaTrustEditDialogTests', function() { |
| + setup(function() { |
| + browserProxy = new TestCertificatesBrowserProxy(); |
| + browserProxy.setCaCertificateTrust(caTrustInfo); |
| + |
| + settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
| + PolymerTest.clearBody(); |
| + dialog = document.createElement('settings-ca-trust-edit-dialog'); |
| + dialog.model = model; |
| + document.body.appendChild(dialog); |
| + }); |
| + |
| + teardown(function() { dialog.remove(); }); |
| + |
| + test('Dialog', function() { |
| + return browserProxy.whenCalled('getCaCertificateTrust').then( |
| + function(id) { |
| + assertEquals(model.id, id); |
| + assertEquals(caTrustInfo.ssl, dialog.$.ssl.checked); |
| + assertEquals(caTrustInfo.email, dialog.$.email.checked); |
| + assertEquals(caTrustInfo.objSign, dialog.$.objSign.checked); |
| + |
| + // Simulate toggling all checkboxes. |
| + MockInteractions.tap(dialog.$.ssl); |
| + MockInteractions.tap(dialog.$.email); |
| + MockInteractions.tap(dialog.$.objSign); |
| + |
| + // Simulate clicking 'OK'. |
| + MockInteractions.tap(dialog.$.ok); |
| + |
| + return browserProxy.whenCalled('editCaCertificateTrust').then( |
| + function(args) { |
| + assertEquals(model.id, args.id); |
| + // Checking that the values sent to C++ are reflecting the |
| + // changes made by the user (toggling all checkboxes). |
| + assertEquals(caTrustInfo.ssl, !args.ssl); |
| + assertEquals(caTrustInfo.email, !args.email); |
| + assertEquals(caTrustInfo.objSign, !args.objSign); |
| + // Check that the dialog is closed. |
| + assertFalse(dialog.$.dialog.opened); |
| + }); |
| + }); |
| + }); |
| + }); |
| + } |
| + |
| + return { |
| + registerCaTrustEditDialogTests: registerCaTrustEditDialogTests, |
| + }; |
| +}); |