Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3017)

Unified Diff: chrome/test/data/webui/settings/certificate_manager_page_test.js

Issue 1772203002: MD Settings: Certificate manager, CA edit trust dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix presubmit error. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b43390d12c1d4e8f4175db13a7996b19f028fbbb
--- /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};
+ };
+
+ 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,
+ });
+ 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,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698