1 // Copyright (c) 2012 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.
5 // Mac and Windows go to native certificate manager, and certificate manager
6 // isn't implemented if OpenSSL is used.
7 GEN('#if defined(USE_NSS)');
10 * TestFixture for certificate manager WebUI testing.
11 * @extends {testing.Test}
14 function CertificateManagerWebUIBaseTest() {}
16 CertificateManagerWebUIBaseTest
.prototype = {
17 __proto__
: testing
.Test
.prototype,
20 * Browse to the certificate manager.
22 browsePreload
: 'chrome://settings-frame/certificates',
26 // We can't check cr.isChromeOS in the preLoad since "cr" doesn't exist yet.
27 // This is copied from ui/webui/resources/js/cr.js, maybe
28 // there's a better way to do this.
29 this.isChromeOS
= /CrOS/.test(navigator
.userAgent
);
31 this.makeAndRegisterMockHandler(
33 'editCaCertificateTrust',
34 'exportPersonalCertificate',
35 'importPersonalCertificate',
36 'importCaCertificate',
39 'populateCertificateManager',
46 * TestFixture for certificate manager WebUI testing.
47 * @extends {CertificateManagerWebUIBaseTest}
50 function CertificateManagerWebUIUnpopulatedTest() {}
52 CertificateManagerWebUIUnpopulatedTest
.prototype = {
53 __proto__
: CertificateManagerWebUIBaseTest
.prototype,
57 CertificateManagerWebUIBaseTest
.prototype.preLoad
.call(this);
59 // We expect the populateCertificateManager callback, but do not reply to
60 // it. This simulates what will be displayed if retrieving the cert list
62 this.mockHandler
.expects(once()).populateCertificateManager();
66 // Test opening the certificate manager has correct location and buttons have
67 // correct initial states when onPopulateTree has not been called.
68 TEST_F('CertificateManagerWebUIUnpopulatedTest',
69 'testUnpopulatedCertificateManager', function() {
70 assertEquals(this.browsePreload
, document
.location
.href
);
72 // All buttons should be disabled to start.
73 expectTrue($('personalCertsTab-view').disabled
);
74 expectTrue($('personalCertsTab-backup').disabled
);
75 expectTrue($('personalCertsTab-delete').disabled
);
76 expectTrue($('personalCertsTab-import').disabled
);
78 expectTrue($('personalCertsTab-import-and-bind').disabled
);
80 expectTrue($('serverCertsTab-view').disabled
);
81 expectTrue($('serverCertsTab-export').disabled
);
82 expectTrue($('serverCertsTab-delete').disabled
);
83 expectTrue($('serverCertsTab-import').disabled
);
85 expectTrue($('caCertsTab-view').disabled
);
86 expectTrue($('caCertsTab-edit').disabled
);
87 expectTrue($('caCertsTab-export').disabled
);
88 expectTrue($('caCertsTab-delete').disabled
);
89 expectTrue($('caCertsTab-import').disabled
);
91 expectTrue($('otherCertsTab-view').disabled
);
92 expectTrue($('otherCertsTab-export').disabled
);
93 expectTrue($('otherCertsTab-delete').disabled
);
95 Mock4JS
.verifyAllMocks();
97 // Once we get the onModelReady call, the import buttons should be enabled,
98 // others should still be disabled.
99 CertificateManager
.onModelReady(false /* tpm_available */);
101 expectTrue($('personalCertsTab-view').disabled
);
102 expectTrue($('personalCertsTab-backup').disabled
);
103 expectTrue($('personalCertsTab-delete').disabled
);
104 expectFalse($('personalCertsTab-import').disabled
);
106 expectTrue($('serverCertsTab-view').disabled
);
107 expectTrue($('serverCertsTab-export').disabled
);
108 expectTrue($('serverCertsTab-delete').disabled
);
109 expectFalse($('serverCertsTab-import').disabled
);
111 expectTrue($('caCertsTab-view').disabled
);
112 expectTrue($('caCertsTab-edit').disabled
);
113 expectTrue($('caCertsTab-export').disabled
);
114 expectTrue($('caCertsTab-delete').disabled
);
115 expectFalse($('caCertsTab-import').disabled
);
117 expectTrue($('otherCertsTab-view').disabled
);
118 expectTrue($('otherCertsTab-export').disabled
);
119 expectTrue($('otherCertsTab-delete').disabled
);
121 // On ChromeOS, the import and bind button should only be enabled if TPM is
123 if (this.isChromeOS
) {
124 expectTrue($('personalCertsTab-import-and-bind').disabled
);
125 CertificateManager
.onModelReady(true /* tpm_available */);
126 expectFalse($('personalCertsTab-import-and-bind').disabled
);
131 * TestFixture for certificate manager WebUI testing.
132 * @extends {CertificateManagerWebUIBaseTest}
135 function CertificateManagerWebUITest() {}
137 CertificateManagerWebUITest
.prototype = {
138 __proto__
: CertificateManagerWebUIBaseTest
.prototype,
141 preLoad: function() {
142 CertificateManagerWebUIBaseTest
.prototype.preLoad
.call(this);
144 var tpm_available
= this.isChromeOS
;
145 this.mockHandler
.expects(once()).populateCertificateManager().will(
146 callFunction(function() {
147 CertificateManager
.onModelReady(tpm_available
);
149 [['personalCertsTab-tree',
152 'subnodes': [{ 'id': 'c1',
156 'extractable': true }],
162 'subnodes': [{ 'id': 'ca_cert0',
176 ].forEach(CertificateManager
.onPopulateTree
)}));
180 TEST_F('CertificateManagerWebUITest',
181 'testViewAndDeleteCert', function() {
182 assertEquals(this.browsePreload
, document
.location
.href
);
184 this.mockHandler
.expects(once()).viewCertificate(['c1']);
186 expectTrue($('personalCertsTab-view').disabled
);
187 expectTrue($('personalCertsTab-backup').disabled
);
188 expectTrue($('personalCertsTab-delete').disabled
);
189 expectFalse($('personalCertsTab-import').disabled
);
191 expectFalse($('personalCertsTab-import-and-bind').disabled
);
193 var personalCerts
= $('personalCertsTab');
195 // Click on the first folder.
196 personalCerts
.querySelector('div.tree-item').click();
197 // Buttons should still be in same state.
198 expectTrue($('personalCertsTab-view').disabled
);
199 expectTrue($('personalCertsTab-backup').disabled
);
200 expectTrue($('personalCertsTab-delete').disabled
);
201 expectFalse($('personalCertsTab-import').disabled
);
203 expectFalse($('personalCertsTab-import-and-bind').disabled
);
205 // Click on the first cert.
206 personalCerts
.querySelector('div.tree-item div.tree-item').click();
207 // Buttons should now allow you to act on the cert.
208 expectFalse($('personalCertsTab-view').disabled
);
209 expectFalse($('personalCertsTab-backup').disabled
);
210 expectFalse($('personalCertsTab-delete').disabled
);
211 expectFalse($('personalCertsTab-import').disabled
);
213 expectFalse($('personalCertsTab-import-and-bind').disabled
);
215 // Click on the view button.
216 $('personalCertsTab-view').click();
218 Mock4JS
.verifyAllMocks();
220 this.mockHandler
.expects(once()).deleteCertificate(['c1']).will(callFunction(
222 CertificateManager
.onPopulateTree(['personalCertsTab-tree', []]);
225 // Click on the delete button.
226 $('personalCertsTab-delete').click();
227 // Click on the ok button in the confirmation overlay.
228 $('alertOverlayOk').click();
230 // Context sensitive buttons should be disabled.
231 expectTrue($('personalCertsTab-view').disabled
);
232 expectTrue($('personalCertsTab-backup').disabled
);
233 expectTrue($('personalCertsTab-delete').disabled
);
234 expectFalse($('personalCertsTab-import').disabled
);
236 expectFalse($('personalCertsTab-import-and-bind').disabled
);
237 // Tree should be empty.
238 expectTrue(personalCerts
.querySelector('div.tree-item') === null);
241 // Ensure certificate objects with the 'policy' property set have
242 // the cert-policy CSS class appended.
243 TEST_F('CertificateManagerWebUITest',
244 'testPolicyInstalledCertificate', function() {
245 // Click on the first folder and get the certificates.
246 var caCertsTab
= $('caCertsTab');
247 caCertsTab
.querySelector('div.tree-item').click();
248 var certs
= caCertsTab
.querySelectorAll('div.tree-item div.tree-item');
250 // First cert shouldn't show the controlled setting badge, and the
251 // edit and delete buttons should be enabled.
252 var cert0
= certs
[0];
253 expectEquals('ca_cert0', cert0
.data
.name
);
254 expectEquals(null, cert0
.querySelector('.cert-policy'));
256 expectFalse($('caCertsTab-edit').disabled
);
257 expectFalse($('caCertsTab-delete').disabled
);
259 // But the second should show the controlled setting badge, and the
260 // edit and delete buttons should be disabled.
261 var cert1
= certs
[1];
262 expectEquals('ca_cert1', cert1
.data
.name
);
263 expectNotEquals(null, cert1
.querySelector('.cert-policy'));
265 expectTrue($('caCertsTab-edit').disabled
);
266 expectTrue($('caCertsTab-delete').disabled
);
269 GEN('#endif // defined(USE_NSS)');