NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / certificate_manager_browsertest.js
blob73db5a8e969ddbadb2f2c25468c3aca0efa2c7dd
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)');
9 /**
10 * TestFixture for certificate manager WebUI testing.
11 * @extends {testing.Test}
12 * @constructor
13 **/
14 function CertificateManagerWebUIBaseTest() {}
16 CertificateManagerWebUIBaseTest.prototype = {
17 __proto__: testing.Test.prototype,
19 /**
20 * Browse to the certificate manager.
21 **/
22 browsePreload: 'chrome://settings-frame/certificates',
24 /** @inheritDoc */
25 preLoad: function() {
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',
37 'exportCertificate',
38 'deleteCertificate',
39 'populateCertificateManager',
40 'viewCertificate',
41 ]);
45 /**
46 * TestFixture for certificate manager WebUI testing.
47 * @extends {CertificateManagerWebUIBaseTest}
48 * @constructor
49 **/
50 function CertificateManagerWebUIUnpopulatedTest() {}
52 CertificateManagerWebUIUnpopulatedTest.prototype = {
53 __proto__: CertificateManagerWebUIBaseTest.prototype,
55 /** @inheritDoc */
56 preLoad: function() {
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
61 // from NSS is slow.
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);
77 if (this.isChromeOS)
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
122 // present.
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}
133 * @constructor
135 function CertificateManagerWebUITest() {}
137 CertificateManagerWebUITest.prototype = {
138 __proto__: CertificateManagerWebUIBaseTest.prototype,
140 /** @inheritDoc */
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',
150 [{'id': 'o1',
151 'name': 'org1',
152 'subnodes': [{ 'id': 'c1',
153 'name': 'cert1',
154 'readonly': false,
155 'untrusted': false,
156 'extractable': true }],
159 ['caCertsTab-tree',
160 [{'id': 'o2',
161 'name': 'org2',
162 'subnodes': [{ 'id': 'ca_cert0',
163 'name': 'ca_cert0',
164 'readonly': false,
165 'untrusted': false,
166 'extractable': true,
167 'policy': false },
168 { 'id': 'ca_cert1',
169 'name': 'ca_cert1',
170 'readonly': false,
171 'untrusted': false,
172 'extractable': true,
173 'policy': true }],
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);
190 if (this.isChromeOS)
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);
202 if (this.isChromeOS)
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);
212 if (this.isChromeOS)
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(
221 function() {
222 CertificateManager.onPopulateTree(['personalCertsTab-tree', []]);
223 }));
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);
235 if (this.isChromeOS)
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'));
255 cert0.click();
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'));
264 cert1.click();
265 expectTrue($('caCertsTab-edit').disabled);
266 expectTrue($('caCertsTab-delete').disabled);
269 GEN('#endif // defined(USE_NSS)');