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

Side by Side Diff: chrome/browser/ui/webui/options/certificate_manager_browsertest.js

Issue 2919343005: Remove tests for deprecated Options UI (Closed)
Patch Set: and more Created 3 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
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)');
8
9 GEN_INCLUDE(['options_browsertest_base.js']);
10
11 /**
12 * URL of the Certificates dialog in the Settings page.
13 * @const
14 */
15 var CERTIFICATE_MANAGER_SETTINGS_PAGE_URL =
16 'chrome://settings-frame/certificates';
17
18 // Standalone certificate manager dialog page is implemented only in Chrome OS.
19 GEN('#if defined(OS_CHROMEOS)');
20
21 /**
22 * URL of the standalone certificate manager dialog page.
23 * @const
24 */
25 var CERTIFICATE_MANAGER_STANDALONE_PAGE_URL = 'chrome://certificate-manager/';
26
27 GEN('#endif // defined(OS_CHROMEOS)');
28
29 /**
30 * TestFixture for certificate manager WebUI testing.
31 * @extends {testing.Test}
32 * @constructor
33 */
34 function CertificateManagerWebUIBaseTest() {}
35
36 CertificateManagerWebUIBaseTest.prototype = {
37 __proto__: OptionsBrowsertestBase.prototype,
38
39 /** @override */
40 preLoad: function() {
41 // We can't check cr.isChromeOS in the preLoad since "cr" doesn't exist yet.
42 // This is copied from ui/webui/resources/js/cr.js, maybe
43 // there's a better way to do this.
44 this.isChromeOS = /CrOS/.test(navigator.userAgent);
45
46 this.makeAndRegisterMockHandler(
47 [
48 'editCaCertificateTrust',
49 'exportPersonalCertificate',
50 'importPersonalCertificate',
51 'importCaCertificate',
52 'exportCertificate',
53 'deleteCertificate',
54 'populateCertificateManager',
55 'viewCertificate',
56 ]);
57 },
58
59 /** @override */
60 setUp: function() {
61 OptionsBrowsertestBase.prototype.setUp.call(this);
62
63 var ariaRoleNotScopedSelectors = [
64 '#tree-item-autogen-id-0',
65 '#tree-item-autogen-id-1',
66 '#tree-item-autogen-id-2',
67 '#tree-item-autogen-id-3',
68 '#tree-item-autogen-id-4',
69 ];
70
71 // Enable when failure is resolved.
72 // AX_ARIA_09: http://crbug.com/570567
73 this.accessibilityAuditConfig.ignoreSelectors(
74 'ariaRoleNotScoped',
75 ariaRoleNotScopedSelectors);
76
77 // Enable when failure is resolved.
78 // AX_ARIA_10: http://crbug.com/570566
79 this.accessibilityAuditConfig.ignoreSelectors(
80 'unsupportedAriaAttribute',
81 '#caCertsTab-tree');
82
83 var focusableElementNotVisibleAndNotAriaHiddenSelectors = [
84 '#personalCertsTab-tree',
85 '#personalCertsTab-import',
86 '#personalCertsTab-import-and-bind',
87 '#certificate-confirm',
88 ];
89
90 // Enable when failure is resolved.
91 // AX_FOCUS_01: http://crbug.com/570568
92 this.accessibilityAuditConfig.ignoreSelectors(
93 'focusableElementNotVisibleAndNotAriaHidden',
94 focusableElementNotVisibleAndNotAriaHiddenSelectors);
95 },
96 };
97
98 /**
99 * TestFixture for certificate manager WebUI testing.
100 * @extends {CertificateManagerWebUIBaseTest}
101 * @constructor
102 */
103 function CertificateManagerWebUIUnpopulatedTest() {}
104
105 CertificateManagerWebUIUnpopulatedTest.prototype = {
106 __proto__: CertificateManagerWebUIBaseTest.prototype,
107
108 /**
109 * Browse to the certificate manager dialog in the Settings page.
110 */
111 browsePreload: CERTIFICATE_MANAGER_SETTINGS_PAGE_URL,
112
113 /** @override */
114 preLoad: function() {
115 CertificateManagerWebUIBaseTest.prototype.preLoad.call(this);
116
117 // We expect the populateCertificateManager callback, but do not reply to
118 // it. This simulates what will be displayed if retrieving the cert list
119 // from NSS is slow.
120 this.mockHandler.expects(once()).populateCertificateManager();
121 },
122 };
123
124 // Test opening the certificate manager has correct location and buttons have
125 // correct initial states when onPopulateTree has not been called.
126 TEST_F('CertificateManagerWebUIUnpopulatedTest',
127 'testUnpopulatedCertificateManager', function() {
128 assertEquals(this.browsePreload, document.location.href);
129
130 // All buttons should be disabled to start.
131 expectTrue($('personalCertsTab-view').disabled);
132 expectTrue($('personalCertsTab-backup').disabled);
133 expectTrue($('personalCertsTab-delete').disabled);
134 expectTrue($('personalCertsTab-import').disabled);
135 if (this.isChromeOS)
136 expectTrue($('personalCertsTab-import-and-bind').disabled);
137
138 expectTrue($('serverCertsTab-view').disabled);
139 expectTrue($('serverCertsTab-export').disabled);
140 expectTrue($('serverCertsTab-delete').disabled);
141 expectTrue($('serverCertsTab-import').disabled);
142
143 expectTrue($('caCertsTab-view').disabled);
144 expectTrue($('caCertsTab-edit').disabled);
145 expectTrue($('caCertsTab-export').disabled);
146 expectTrue($('caCertsTab-delete').disabled);
147 expectTrue($('caCertsTab-import').disabled);
148
149 expectTrue($('otherCertsTab-view').disabled);
150 expectTrue($('otherCertsTab-export').disabled);
151 expectTrue($('otherCertsTab-delete').disabled);
152
153 Mock4JS.verifyAllMocks();
154
155 // If user database is not available, import buttons should be disabled.
156 CertificateManager.onModelReady(false /* userDbAvailable*/,
157 false /* tpmAvailable */);
158
159 expectTrue($('personalCertsTab-import').disabled);
160 expectTrue($('serverCertsTab-import').disabled);
161 expectTrue($('caCertsTab-import').disabled);
162
163 // Once we get the onModelReady call, the import buttons should be enabled,
164 // others should still be disabled.
165 CertificateManager.onModelReady(true /* userDbAvailable*/,
166 false /* tpmAvailable */);
167
168 expectTrue($('personalCertsTab-view').disabled);
169 expectTrue($('personalCertsTab-backup').disabled);
170 expectTrue($('personalCertsTab-delete').disabled);
171 expectFalse($('personalCertsTab-import').disabled);
172
173 expectTrue($('serverCertsTab-view').disabled);
174 expectTrue($('serverCertsTab-export').disabled);
175 expectTrue($('serverCertsTab-delete').disabled);
176 expectFalse($('serverCertsTab-import').disabled);
177
178 expectTrue($('caCertsTab-view').disabled);
179 expectTrue($('caCertsTab-edit').disabled);
180 expectTrue($('caCertsTab-export').disabled);
181 expectTrue($('caCertsTab-delete').disabled);
182 expectFalse($('caCertsTab-import').disabled);
183
184 expectTrue($('otherCertsTab-view').disabled);
185 expectTrue($('otherCertsTab-export').disabled);
186 expectTrue($('otherCertsTab-delete').disabled);
187
188 // On ChromeOS, the import and bind button should only be enabled if TPM is
189 // present.
190 if (this.isChromeOS) {
191 expectTrue($('personalCertsTab-import-and-bind').disabled);
192 CertificateManager.onModelReady(true /* userDbAvailable*/,
193 true /* tpmAvailable */);
194 expectFalse($('personalCertsTab-import-and-bind').disabled);
195 }
196 });
197
198 /**
199 * TestFixture for certificate manager WebUI testing.
200 * @extends {CertificateManagerWebUIBaseTest}
201 * @constructor
202 */
203 function CertificateManagerWebUITest() {}
204
205 CertificateManagerWebUITest.prototype = {
206 __proto__: CertificateManagerWebUIBaseTest.prototype,
207
208 /** @override */
209 preLoad: function() {
210 CertificateManagerWebUIBaseTest.prototype.preLoad.call(this);
211
212 var tpmAvailable = this.isChromeOS;
213 var userDbAvailable = true;
214 this.mockHandler.expects(once()).populateCertificateManager().will(
215 callFunction(function() {
216 CertificateManager.onModelReady(userDbAvailable, tpmAvailable);
217
218 [['personalCertsTab-tree',
219 [{'id': 'o1',
220 'name': 'org1',
221 'subnodes': [{ 'id': 'c1',
222 'name': 'cert1',
223 'readonly': false,
224 'untrusted': false,
225 'extractable': true }],
226 }],
227 ],
228 ['caCertsTab-tree',
229 [{'id': 'o2',
230 'name': 'org2',
231 'subnodes': [{ 'id': 'ca_cert0',
232 'name': 'ca_cert0',
233 'readonly': false,
234 'untrusted': false,
235 'extractable': true,
236 'policy': false },
237 { 'id': 'ca_cert1',
238 'name': 'ca_cert1',
239 'readonly': false,
240 'untrusted': false,
241 'extractable': true,
242 'policy': true },
243 { 'id': 'ca_cert2',
244 'name': 'ca_cert2',
245 'readonly': false,
246 'untrusted': false,
247 'extractable': true,
248 'policy': false }],
249 }],
250 ]
251 ].forEach(CertificateManager.onPopulateTree);}));
252 },
253 };
254
255 /**
256 * TestFixture for testing certificate manager WebUI in the Settings page.
257 * @extends {CertificateManagerWebUITest}
258 * @constructor
259 */
260 function CertificateManagerSettingsWebUITest() {}
261
262 CertificateManagerSettingsWebUITest.prototype = {
263 __proto__: CertificateManagerWebUITest.prototype,
264
265 /**
266 * Browse to the certificate manager dialog in the Settings page.
267 */
268 browsePreload: CERTIFICATE_MANAGER_SETTINGS_PAGE_URL,
269 };
270
271 TEST_F('CertificateManagerSettingsWebUITest',
272 'testViewAndDeleteCert', function() {
273 assertEquals(this.browsePreload, document.location.href);
274
275 this.mockHandler.expects(once()).viewCertificate(['c1']);
276
277 expectTrue($('personalCertsTab-view').disabled);
278 expectTrue($('personalCertsTab-backup').disabled);
279 expectTrue($('personalCertsTab-delete').disabled);
280 expectFalse($('personalCertsTab-import').disabled);
281 if (this.isChromeOS)
282 expectFalse($('personalCertsTab-import-and-bind').disabled);
283
284 var personalCerts = $('personalCertsTab');
285
286 // Click on the first folder.
287 personalCerts.querySelector('div.tree-item').click();
288 // Buttons should still be in same state.
289 expectTrue($('personalCertsTab-view').disabled);
290 expectTrue($('personalCertsTab-backup').disabled);
291 expectTrue($('personalCertsTab-delete').disabled);
292 expectFalse($('personalCertsTab-import').disabled);
293 if (this.isChromeOS)
294 expectFalse($('personalCertsTab-import-and-bind').disabled);
295
296 // Click on the first cert.
297 personalCerts.querySelector('div.tree-item div.tree-item').click();
298 // Buttons should now allow you to act on the cert.
299 expectFalse($('personalCertsTab-view').disabled);
300 expectFalse($('personalCertsTab-backup').disabled);
301 expectFalse($('personalCertsTab-delete').disabled);
302 expectFalse($('personalCertsTab-import').disabled);
303 if (this.isChromeOS)
304 expectFalse($('personalCertsTab-import-and-bind').disabled);
305
306 // Click on the view button.
307 $('personalCertsTab-view').click();
308
309 Mock4JS.verifyAllMocks();
310
311 this.mockHandler.expects(once()).deleteCertificate(['c1']).will(callFunction(
312 function() {
313 CertificateManager.onPopulateTree(['personalCertsTab-tree', []]);
314 }));
315
316 // Click on the delete button.
317 $('personalCertsTab-delete').click();
318
319 // Click on the cancel button to verify the confirmation overlay closes.
320 $('alertOverlayCancel').click();
321 expectTrue($('alertOverlay').parentNode.classList.contains('transparent'));
322
323 // Click on the delete button.
324 $('personalCertsTab-delete').click();
325
326 // Click on the ok button in the confirmation overlay.
327 $('alertOverlayOk').click();
328 expectTrue($('alertOverlay').parentNode.classList.contains('transparent'));
329
330 // Context sensitive buttons should be disabled.
331 expectTrue($('personalCertsTab-view').disabled);
332 expectTrue($('personalCertsTab-backup').disabled);
333 expectTrue($('personalCertsTab-delete').disabled);
334 expectFalse($('personalCertsTab-import').disabled);
335 if (this.isChromeOS)
336 expectFalse($('personalCertsTab-import-and-bind').disabled);
337 // Tree should be empty.
338 expectTrue(personalCerts.querySelector('div.tree-item') === null);
339 });
340
341 // Ensure certificate objects with the 'policy' property set have
342 // the cert-policy CSS class appended.
343 TEST_F('CertificateManagerSettingsWebUITest',
344 'testPolicyInstalledCertificate', function() {
345 // Click on the first folder and get the certificates.
346 var caCertsTab = $('caCertsTab');
347 caCertsTab.querySelector('div.tree-item').click();
348 var certs = caCertsTab.querySelectorAll('div.tree-item div.tree-item');
349
350 // First cert shouldn't show the controlled setting badge, and the
351 // edit and delete buttons should be enabled.
352 var cert0 = certs[0];
353 expectEquals('ca_cert0', cert0.data.name);
354 expectEquals(null, cert0.querySelector('.cert-policy'));
355 cert0.click();
356 expectFalse($('caCertsTab-edit').disabled);
357 expectFalse($('caCertsTab-delete').disabled);
358
359 // But the second should show the controlled setting badge, and the
360 // edit and delete buttons should be disabled.
361 var cert1 = certs[1];
362 expectEquals('ca_cert1', cert1.data.name);
363 expectNotEquals(null, cert1.querySelector('.cert-policy'));
364 cert1.click();
365 expectTrue($('caCertsTab-edit').disabled);
366 expectTrue($('caCertsTab-delete').disabled);
367 });
368
369 // Standalone certificate manager dialog page is implemented only in Chrome OS.
370 GEN('#if defined(OS_CHROMEOS)');
371
372 /**
373 * TestFixture for testing standalone certificate manager WebUI.
374 * @extends {CertificateManagerWebUITest}
375 * @constructor
376 */
377 function CertificateManagerStandaloneWebUITest() {}
378
379 CertificateManagerStandaloneWebUITest.prototype = {
380 __proto__: CertificateManagerWebUITest.prototype,
381
382 /**
383 * Browse to the certificate manager page.
384 */
385 browsePreload: CERTIFICATE_MANAGER_STANDALONE_PAGE_URL,
386 };
387
388 // Ensure that the standalone certificate manager page loads and displays the
389 // ceertificates correctly.
390 TEST_F('CertificateManagerStandaloneWebUITest', 'testCertsDisplaying',
391 function() {
392 assertEquals(this.browsePreload, document.location.href);
393
394 // Click on the first folder and get the certificates.
395 var caCertsTab = $('caCertsTab');
396 caCertsTab.querySelector('div.tree-item').click();
397 var certs = caCertsTab.querySelectorAll('div.tree-item div.tree-item');
398
399 // There should be exactly three certificates displayed.
400 expectEquals(certs.length, 3);
401 });
402
403 GEN('#endif // defined(OS_CHROMEOS)');
404
405 GEN('#endif // defined(USE_NSS_CERTS)');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698