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(
34 'editCaCertificateTrust',
35 'exportPersonalCertificate',
36 'importPersonalCertificate',
37 'importCaCertificate',
40 'populateCertificateManager',
47 * TestFixture for certificate manager WebUI testing.
48 * @extends {CertificateManagerWebUIBaseTest}
51 function CertificateManagerWebUIUnpopulatedTest() {}
53 CertificateManagerWebUIUnpopulatedTest
.prototype = {
54 __proto__
: CertificateManagerWebUIBaseTest
.prototype,
58 CertificateManagerWebUIBaseTest
.prototype.preLoad
.call(this);
60 // We expect the populateCertificateManager callback, but do not reply to
61 // it. This simulates what will be displayed if retrieving the cert list
63 this.mockHandler
.expects(once()).populateCertificateManager();
65 this.mockHandler
.expects(atLeastOnce()).checkTpmTokenReady();
69 // Test opening the certificate manager has correct location and buttons have
70 // correct initial states when onPopulateTree has not been called.
71 TEST_F('CertificateManagerWebUIUnpopulatedTest',
72 'testUnpopulatedCertificateManager', function() {
73 assertEquals(this.browsePreload
, document
.location
.href
);
75 expectTrue($('personalCertsTab-view').disabled
);
76 expectTrue($('personalCertsTab-backup').disabled
);
77 expectTrue($('personalCertsTab-delete').disabled
);
78 expectFalse($('personalCertsTab-import').disabled
);
80 expectTrue($('personalCertsTab-import-and-bind').disabled
);
82 expectTrue($('serverCertsTab-view').disabled
);
83 expectTrue($('serverCertsTab-export').disabled
);
84 expectTrue($('serverCertsTab-delete').disabled
);
85 expectFalse($('serverCertsTab-import').disabled
);
87 expectTrue($('caCertsTab-view').disabled
);
88 expectTrue($('caCertsTab-edit').disabled
);
89 expectTrue($('caCertsTab-export').disabled
);
90 expectTrue($('caCertsTab-delete').disabled
);
91 expectFalse($('caCertsTab-import').disabled
);
93 expectTrue($('otherCertsTab-view').disabled
);
94 expectTrue($('otherCertsTab-export').disabled
);
95 expectTrue($('otherCertsTab-delete').disabled
);
99 * TestFixture for certificate manager WebUI testing.
100 * @extends {CertificateManagerWebUIBaseTest}
103 function CertificateManagerWebUITest() {}
105 CertificateManagerWebUITest
.prototype = {
106 __proto__
: CertificateManagerWebUIBaseTest
.prototype,
109 preLoad: function() {
110 CertificateManagerWebUIBaseTest
.prototype.preLoad
.call(this);
112 this.mockHandler
.expects(once()).populateCertificateManager().will(
113 callFunction(function() {
114 [['personalCertsTab-tree',
117 'subnodes': [{ 'id': 'c1',
121 'extractable': true }],
127 'subnodes': [{ 'id': 'ca_cert0',
141 ].forEach(CertificateManager
.onPopulateTree
)}));
144 this.mockHandler
.expects(once()).checkTpmTokenReady().will(callFunction(
146 CertificateManager
.onCheckTpmTokenReady(true);
151 TEST_F('CertificateManagerWebUITest',
152 'testViewAndDeleteCert', function() {
153 assertEquals(this.browsePreload
, document
.location
.href
);
155 this.mockHandler
.expects(once()).viewCertificate(['c1']);
157 expectTrue($('personalCertsTab-view').disabled
);
158 expectTrue($('personalCertsTab-backup').disabled
);
159 expectTrue($('personalCertsTab-delete').disabled
);
160 expectFalse($('personalCertsTab-import').disabled
);
162 expectFalse($('personalCertsTab-import-and-bind').disabled
);
164 var personalCerts
= $('personalCertsTab');
166 // Click on the first folder.
167 personalCerts
.querySelector('div.tree-item').click();
168 // Buttons should still be in same state.
169 expectTrue($('personalCertsTab-view').disabled
);
170 expectTrue($('personalCertsTab-backup').disabled
);
171 expectTrue($('personalCertsTab-delete').disabled
);
172 expectFalse($('personalCertsTab-import').disabled
);
174 expectFalse($('personalCertsTab-import-and-bind').disabled
);
176 // Click on the first cert.
177 personalCerts
.querySelector('div.tree-item div.tree-item').click();
178 // Buttons should now allow you to act on the cert.
179 expectFalse($('personalCertsTab-view').disabled
);
180 expectFalse($('personalCertsTab-backup').disabled
);
181 expectFalse($('personalCertsTab-delete').disabled
);
182 expectFalse($('personalCertsTab-import').disabled
);
184 expectFalse($('personalCertsTab-import-and-bind').disabled
);
186 // Click on the view button.
187 $('personalCertsTab-view').click();
189 Mock4JS
.verifyAllMocks();
191 this.mockHandler
.expects(once()).deleteCertificate(['c1']).will(callFunction(
193 CertificateManager
.onPopulateTree(['personalCertsTab-tree', []]);
196 // Click on the delete button.
197 $('personalCertsTab-delete').click();
198 // Click on the ok button in the confirmation overlay.
199 $('alertOverlayOk').click();
201 // Context sensitive buttons should be disabled.
202 expectTrue($('personalCertsTab-view').disabled
);
203 expectTrue($('personalCertsTab-backup').disabled
);
204 expectTrue($('personalCertsTab-delete').disabled
);
205 expectFalse($('personalCertsTab-import').disabled
);
207 expectFalse($('personalCertsTab-import-and-bind').disabled
);
208 // Tree should be empty.
209 expectTrue(personalCerts
.querySelector('div.tree-item') === null);
212 // Ensure certificate objects with the 'policy' property set have
213 // the cert-policy CSS class appended.
214 TEST_F('CertificateManagerWebUITest',
215 'testPolicyInstalledCertificate', function() {
216 // Click on the first folder and get the certificates.
217 var caCertsTab
= $('caCertsTab');
218 caCertsTab
.querySelector('div.tree-item').click();
219 var certs
= caCertsTab
.querySelectorAll('div.tree-item div.tree-item');
221 // First cert shouldn't show the controlled setting badge, and the
222 // edit and delete buttons should be enabled.
223 var cert0
= certs
[0];
224 expectEquals('ca_cert0', cert0
.data
.name
);
225 expectEquals(null, cert0
.querySelector('.cert-policy'));
227 expectFalse($('caCertsTab-edit').disabled
);
228 expectFalse($('caCertsTab-delete').disabled
);
230 // But the second should show the controlled setting badge, and the
231 // edit and delete buttons should be disabled.
232 var cert1
= certs
[1];
233 expectEquals('ca_cert1', cert1
.data
.name
);
234 expectNotEquals(null, cert1
.querySelector('.cert-policy'));
236 expectTrue($('caCertsTab-edit').disabled
);
237 expectTrue($('caCertsTab-delete').disabled
);
240 GEN('#endif // defined(USE_NSS)');