Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / certificate_manager_browsertest.js
blob112ca7fb0e6ad120c5ca49a92e1be2254755f9c2
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 'checkTpmTokenReady',
34 'editCaCertificateTrust',
35 'exportPersonalCertificate',
36 'importPersonalCertificate',
37 'importCaCertificate',
38 'exportCertificate',
39 'deleteCertificate',
40 'populateCertificateManager',
41 'viewCertificate',
42 ]);
46 /**
47 * TestFixture for certificate manager WebUI testing.
48 * @extends {CertificateManagerWebUIBaseTest}
49 * @constructor
50 **/
51 function CertificateManagerWebUIUnpopulatedTest() {}
53 CertificateManagerWebUIUnpopulatedTest.prototype = {
54 __proto__: CertificateManagerWebUIBaseTest.prototype,
56 /** @inheritDoc */
57 preLoad: function() {
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
62 // from NSS is slow.
63 this.mockHandler.expects(once()).populateCertificateManager();
64 if (this.isChromeOS)
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);
79 if (this.isChromeOS)
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);
96 });
98 /**
99 * TestFixture for certificate manager WebUI testing.
100 * @extends {CertificateManagerWebUIBaseTest}
101 * @constructor
103 function CertificateManagerWebUITest() {}
105 CertificateManagerWebUITest.prototype = {
106 __proto__: CertificateManagerWebUIBaseTest.prototype,
108 /** @inheritDoc */
109 preLoad: function() {
110 CertificateManagerWebUIBaseTest.prototype.preLoad.call(this);
112 this.mockHandler.expects(once()).populateCertificateManager().will(
113 callFunction(function() {
114 [['personalCertsTab-tree',
115 [{'id': 'o1',
116 'name': 'org1',
117 'subnodes': [{ 'id': 'c1',
118 'name': 'cert1',
119 'readonly': false,
120 'untrusted': false,
121 'extractable': true }],
124 ['caCertsTab-tree',
125 [{'id': 'o2',
126 'name': 'org2',
127 'subnodes': [{ 'id': 'ca_cert0',
128 'name': 'ca_cert0',
129 'readonly': false,
130 'untrusted': false,
131 'extractable': true,
132 'policy': false },
133 { 'id': 'ca_cert1',
134 'name': 'ca_cert1',
135 'readonly': false,
136 'untrusted': false,
137 'extractable': true,
138 'policy': true }],
141 ].forEach(CertificateManager.onPopulateTree)}));
143 if (this.isChromeOS)
144 this.mockHandler.expects(once()).checkTpmTokenReady().will(callFunction(
145 function() {
146 CertificateManager.onCheckTpmTokenReady(true);
147 }));
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);
161 if (this.isChromeOS)
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);
173 if (this.isChromeOS)
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);
183 if (this.isChromeOS)
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(
192 function() {
193 CertificateManager.onPopulateTree(['personalCertsTab-tree', []]);
194 }));
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);
206 if (this.isChromeOS)
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'));
226 cert0.click();
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'));
235 cert1.click();
236 expectTrue($('caCertsTab-edit').disabled);
237 expectTrue($('caCertsTab-delete').disabled);
240 GEN('#endif // defined(USE_NSS)');