Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / certificate_manager_browsertest.js
blobec3e1a662ec65cac4b24e4addba4c574128ff59b
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_CERTS)');
9 /**
10 * TestFixture for certificate manager WebUI testing.
11 * @extends {testing.Test}
12 * @constructor
14 function CertificateManagerWebUIBaseTest() {}
16 CertificateManagerWebUIBaseTest.prototype = {
17 __proto__: testing.Test.prototype,
19 /**
20 * Browse to the certificate manager.
22 browsePreload: 'chrome://settings-frame/certificates',
24 /** @override */
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
50 function CertificateManagerWebUIUnpopulatedTest() {}
52 CertificateManagerWebUIUnpopulatedTest.prototype = {
53 __proto__: CertificateManagerWebUIBaseTest.prototype,
55 /** @override */
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 // If user database is not available, import buttons should be disabled.
98 CertificateManager.onModelReady(false /* userDbAvailable*/,
99 false /* tpmAvailable */);
101 expectTrue($('personalCertsTab-import').disabled);
102 expectTrue($('serverCertsTab-import').disabled);
103 expectTrue($('caCertsTab-import').disabled);
105 // Once we get the onModelReady call, the import buttons should be enabled,
106 // others should still be disabled.
107 CertificateManager.onModelReady(true /* userDbAvailable*/,
108 false /* tpmAvailable */);
110 expectTrue($('personalCertsTab-view').disabled);
111 expectTrue($('personalCertsTab-backup').disabled);
112 expectTrue($('personalCertsTab-delete').disabled);
113 expectFalse($('personalCertsTab-import').disabled);
115 expectTrue($('serverCertsTab-view').disabled);
116 expectTrue($('serverCertsTab-export').disabled);
117 expectTrue($('serverCertsTab-delete').disabled);
118 expectFalse($('serverCertsTab-import').disabled);
120 expectTrue($('caCertsTab-view').disabled);
121 expectTrue($('caCertsTab-edit').disabled);
122 expectTrue($('caCertsTab-export').disabled);
123 expectTrue($('caCertsTab-delete').disabled);
124 expectFalse($('caCertsTab-import').disabled);
126 expectTrue($('otherCertsTab-view').disabled);
127 expectTrue($('otherCertsTab-export').disabled);
128 expectTrue($('otherCertsTab-delete').disabled);
130 // On ChromeOS, the import and bind button should only be enabled if TPM is
131 // present.
132 if (this.isChromeOS) {
133 expectTrue($('personalCertsTab-import-and-bind').disabled);
134 CertificateManager.onModelReady(true /* userDbAvailable*/,
135 true /* tpmAvailable */);
136 expectFalse($('personalCertsTab-import-and-bind').disabled);
141 * TestFixture for certificate manager WebUI testing.
142 * @extends {CertificateManagerWebUIBaseTest}
143 * @constructor
145 function CertificateManagerWebUITest() {}
147 CertificateManagerWebUITest.prototype = {
148 __proto__: CertificateManagerWebUIBaseTest.prototype,
150 /** @override */
151 preLoad: function() {
152 CertificateManagerWebUIBaseTest.prototype.preLoad.call(this);
154 var tpmAvailable = this.isChromeOS;
155 var userDbAvailable = true;
156 this.mockHandler.expects(once()).populateCertificateManager().will(
157 callFunction(function() {
158 CertificateManager.onModelReady(userDbAvailable, tpmAvailable);
160 [['personalCertsTab-tree',
161 [{'id': 'o1',
162 'name': 'org1',
163 'subnodes': [{ 'id': 'c1',
164 'name': 'cert1',
165 'readonly': false,
166 'untrusted': false,
167 'extractable': true }],
170 ['caCertsTab-tree',
171 [{'id': 'o2',
172 'name': 'org2',
173 'subnodes': [{ 'id': 'ca_cert0',
174 'name': 'ca_cert0',
175 'readonly': false,
176 'untrusted': false,
177 'extractable': true,
178 'policy': false },
179 { 'id': 'ca_cert1',
180 'name': 'ca_cert1',
181 'readonly': false,
182 'untrusted': false,
183 'extractable': true,
184 'policy': true }],
187 ].forEach(CertificateManager.onPopulateTree)}));
191 TEST_F('CertificateManagerWebUITest',
192 'testViewAndDeleteCert', function() {
193 assertEquals(this.browsePreload, document.location.href);
195 this.mockHandler.expects(once()).viewCertificate(['c1']);
197 expectTrue($('personalCertsTab-view').disabled);
198 expectTrue($('personalCertsTab-backup').disabled);
199 expectTrue($('personalCertsTab-delete').disabled);
200 expectFalse($('personalCertsTab-import').disabled);
201 if (this.isChromeOS)
202 expectFalse($('personalCertsTab-import-and-bind').disabled);
204 var personalCerts = $('personalCertsTab');
206 // Click on the first folder.
207 personalCerts.querySelector('div.tree-item').click();
208 // Buttons should still be in same state.
209 expectTrue($('personalCertsTab-view').disabled);
210 expectTrue($('personalCertsTab-backup').disabled);
211 expectTrue($('personalCertsTab-delete').disabled);
212 expectFalse($('personalCertsTab-import').disabled);
213 if (this.isChromeOS)
214 expectFalse($('personalCertsTab-import-and-bind').disabled);
216 // Click on the first cert.
217 personalCerts.querySelector('div.tree-item div.tree-item').click();
218 // Buttons should now allow you to act on the cert.
219 expectFalse($('personalCertsTab-view').disabled);
220 expectFalse($('personalCertsTab-backup').disabled);
221 expectFalse($('personalCertsTab-delete').disabled);
222 expectFalse($('personalCertsTab-import').disabled);
223 if (this.isChromeOS)
224 expectFalse($('personalCertsTab-import-and-bind').disabled);
226 // Click on the view button.
227 $('personalCertsTab-view').click();
229 Mock4JS.verifyAllMocks();
231 this.mockHandler.expects(once()).deleteCertificate(['c1']).will(callFunction(
232 function() {
233 CertificateManager.onPopulateTree(['personalCertsTab-tree', []]);
234 }));
236 // Click on the delete button.
237 $('personalCertsTab-delete').click();
239 // Click on the cancel button to verify the confirmation overlay closes.
240 $('alertOverlayCancel').click();
241 expectTrue($('alertOverlay').parentNode.classList.contains('transparent'));
243 // Click on the delete button.
244 $('personalCertsTab-delete').click();
246 // Click on the ok button in the confirmation overlay.
247 $('alertOverlayOk').click();
248 expectTrue($('alertOverlay').parentNode.classList.contains('transparent'));
250 // Context sensitive buttons should be disabled.
251 expectTrue($('personalCertsTab-view').disabled);
252 expectTrue($('personalCertsTab-backup').disabled);
253 expectTrue($('personalCertsTab-delete').disabled);
254 expectFalse($('personalCertsTab-import').disabled);
255 if (this.isChromeOS)
256 expectFalse($('personalCertsTab-import-and-bind').disabled);
257 // Tree should be empty.
258 expectTrue(personalCerts.querySelector('div.tree-item') === null);
261 // Ensure certificate objects with the 'policy' property set have
262 // the cert-policy CSS class appended.
263 TEST_F('CertificateManagerWebUITest',
264 'testPolicyInstalledCertificate', function() {
265 // Click on the first folder and get the certificates.
266 var caCertsTab = $('caCertsTab');
267 caCertsTab.querySelector('div.tree-item').click();
268 var certs = caCertsTab.querySelectorAll('div.tree-item div.tree-item');
270 // First cert shouldn't show the controlled setting badge, and the
271 // edit and delete buttons should be enabled.
272 var cert0 = certs[0];
273 expectEquals('ca_cert0', cert0.data.name);
274 expectEquals(null, cert0.querySelector('.cert-policy'));
275 cert0.click();
276 expectFalse($('caCertsTab-edit').disabled);
277 expectFalse($('caCertsTab-delete').disabled);
279 // But the second should show the controlled setting badge, and the
280 // edit and delete buttons should be disabled.
281 var cert1 = certs[1];
282 expectEquals('ca_cert1', cert1.data.name);
283 expectNotEquals(null, cert1.querySelector('.cert-policy'));
284 cert1.click();
285 expectTrue($('caCertsTab-edit').disabled);
286 expectTrue($('caCertsTab-delete').disabled);
289 GEN('#endif // defined(USE_NSS_CERTS)');