OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 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)'); | |
8 | |
5 /** | 9 /** |
6 * TestFixture for certificate manager WebUI testing. | 10 * TestFixture for certificate manager WebUI testing. |
7 * @extends {testing.Test} | 11 * @extends {testing.Test} |
8 * @constructor | 12 * @constructor |
9 **/ | 13 **/ |
10 function CertificateManagerWebUITest() {} | 14 function CertificateManagerWebUIBaseTest() {} |
11 | 15 |
12 CertificateManagerWebUITest.prototype = { | 16 CertificateManagerWebUIBaseTest.prototype = { |
13 __proto__: testing.Test.prototype, | 17 __proto__: testing.Test.prototype, |
14 | 18 |
15 /** | 19 /** |
16 * Browse to the certificate manager. | 20 * Browse to the certificate manager. |
17 **/ | 21 **/ |
18 browsePreload: 'chrome://settings-frame/certificates', | 22 browsePreload: 'chrome://settings-frame/certificates', |
23 | |
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 chrome/browser/resources/shared/js/cr.js, maybe | |
28 // there's a better way to do this. | |
29 this.isChromeOS = /CrOS/.test(navigator.userAgent); | |
30 | |
31 this.makeAndRegisterMockHandler( | |
32 [ | |
33 'checkTpmTokenReady', | |
34 'editCaCertificateTrust', | |
35 'exportPersonalCertificate', | |
36 'importPersonalCertificate', | |
37 'importCaCertificate', | |
38 'exportCertificate', | |
39 'deleteCertificate', | |
40 'populateCertificateManager', | |
41 'viewCertificate', | |
42 ]); | |
43 }, | |
19 }; | 44 }; |
20 | 45 |
21 // Mac and Windows go to native certificate manager, and certificate manager | 46 /** |
22 // isn't implemented if OpenSSL is used. | 47 * TestFixture for certificate manager WebUI testing. |
23 GEN('#if !defined(USE_NSS)'); | 48 * @extends {CertificateManagerWebUIBaseTest} |
24 GEN('#define MAYBE_testOpenCertificateManager ' + | 49 * @constructor |
25 'DISABLED_testOpenCertificateManager'); | 50 **/ |
26 GEN('#else'); | 51 function CertificateManagerWebUIUnpopulatedTest() {} |
27 GEN('#define MAYBE_testOpenCertificateManager ' + | 52 |
28 'testOpenCertificateManager'); | 53 CertificateManagerWebUIUnpopulatedTest.prototype = { |
29 GEN('#endif // !defined(USE_NSS)'); | 54 __proto__: CertificateManagerWebUIBaseTest.prototype, |
30 // Test opening the certificate manager has correct location. | 55 |
56 /** @inheritDoc */ | |
57 preLoad: function() { | |
58 CertificateManagerWebUIBaseTest.prototype.preLoad.call(this); | |
59 | |
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(); | |
66 }, | |
67 }; | |
68 | |
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); | |
74 | |
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); | |
81 | |
82 expectTrue($('serverCertsTab-view').disabled); | |
83 expectTrue($('serverCertsTab-export').disabled); | |
84 expectTrue($('serverCertsTab-delete').disabled); | |
85 expectFalse($('serverCertsTab-import').disabled); | |
86 if (this.isChromeOS) | |
87 expectTrue($('serverCertsTab-import-and-bind').disabled); | |
88 | |
89 expectTrue($('caCertsTab-view').disabled); | |
90 expectTrue($('caCertsTab-edit').disabled); | |
91 expectTrue($('caCertsTab-export').disabled); | |
92 expectTrue($('caCertsTab-delete').disabled); | |
93 expectFalse($('caCertsTab-import').disabled); | |
94 if (this.isChromeOS) | |
95 expectTrue($('caCertsTab-import-and-bind').disabled); | |
96 | |
97 expectTrue($('otherCertsTab-view').disabled); | |
98 expectTrue($('otherCertsTab-export').disabled); | |
99 expectTrue($('otherCertsTab-delete').disabled); | |
100 }); | |
101 | |
102 | |
Evan Stade
2012/07/13 06:28:21
extra \n
mattm
2012/07/13 20:06:28
Done.
| |
103 /** | |
104 * TestFixture for certificate manager WebUI testing. | |
105 * @extends {CertificateManagerWebUIBaseTest} | |
106 * @constructor | |
107 **/ | |
108 function CertificateManagerWebUITest() {} | |
109 | |
110 CertificateManagerWebUITest.prototype = { | |
111 __proto__: CertificateManagerWebUIBaseTest.prototype, | |
112 | |
113 /** @inheritDoc */ | |
114 preLoad: function() { | |
115 CertificateManagerWebUIBaseTest.prototype.preLoad.call(this); | |
116 | |
117 this.mockHandler.expects(once()).populateCertificateManager().will( | |
118 callFunction(function() { | |
119 CertificateManager.onPopulateTree( | |
Evan Stade
2012/07/13 06:28:21
http://google-styleguide.googlecode.com/svn/trunk/
mattm
2012/07/13 20:06:28
Done.
| |
120 ['personalCertsTab-tree', | |
121 [{'id': 'o1', | |
122 'name': 'org1', | |
123 'subnodes': [ | |
124 {'id': 'c1', | |
125 'name': 'cert1', | |
126 'readonly': false, | |
127 'untrusted': false, | |
128 'extractable': true, | |
129 }, | |
130 ], | |
131 }, | |
132 ], | |
133 ])})); | |
134 | |
135 if (this.isChromeOS) | |
136 this.mockHandler.expects(once()).checkTpmTokenReady().will(callFunction( | |
137 function() { | |
138 CertificateManager.onCheckTpmTokenReady(true); | |
139 })); | |
140 }, | |
141 }; | |
142 | |
31 TEST_F('CertificateManagerWebUITest', | 143 TEST_F('CertificateManagerWebUITest', |
32 'MAYBE_testOpenCertificateManager', function() { | 144 'testViewAndDeleteCert', function() { |
33 assertEquals(this.browsePreload, document.location.href); | 145 assertEquals(this.browsePreload, document.location.href); |
Evan Stade
2012/07/13 06:28:21
this is too much indent by a lot.
mattm
2012/07/13 20:06:28
Done.
| |
146 | |
147 this.mockHandler.expects(once()).viewCertificate(['c1']); | |
148 | |
149 expectTrue($('personalCertsTab-view').disabled); | |
150 expectTrue($('personalCertsTab-backup').disabled); | |
151 expectTrue($('personalCertsTab-delete').disabled); | |
152 expectFalse($('personalCertsTab-import').disabled); | |
153 if (this.isChromeOS) | |
154 expectFalse($('personalCertsTab-import-and-bind').disabled); | |
155 | |
156 var personalCerts = $('personalCertsTab'); | |
157 | |
158 // Click on the first folder. | |
159 personalCerts.querySelector('div.tree-item').click(); | |
160 // Buttons should still be in same state. | |
161 expectTrue($('personalCertsTab-view').disabled); | |
162 expectTrue($('personalCertsTab-backup').disabled); | |
163 expectTrue($('personalCertsTab-delete').disabled); | |
164 expectFalse($('personalCertsTab-import').disabled); | |
165 if (this.isChromeOS) | |
166 expectFalse($('personalCertsTab-import-and-bind').disabled); | |
167 | |
168 // Click on the first cert. | |
169 personalCerts.querySelector('div.tree-item div.tree-item').click(); | |
170 // Buttons should now allow you to act on the cert. | |
171 expectFalse($('personalCertsTab-view').disabled); | |
172 expectFalse($('personalCertsTab-backup').disabled); | |
173 expectFalse($('personalCertsTab-delete').disabled); | |
174 expectFalse($('personalCertsTab-import').disabled); | |
175 if (this.isChromeOS) | |
176 expectFalse($('personalCertsTab-import-and-bind').disabled); | |
177 | |
178 // Click on the view button. | |
179 $('personalCertsTab-view').click(); | |
180 | |
181 Mock4JS.verifyAllMocks(); | |
182 Mock4JS.clearMocksToVerify(); | |
183 | |
184 this.mockHandler.expects(once()).deleteCertificate(['c1']).will( | |
185 callFunction(function() { | |
186 CertificateManager.onPopulateTree(['personalCertsTab-tree', []]); | |
187 })); | |
188 | |
189 // Click on the delete button. | |
190 $('personalCertsTab-delete').click(); | |
191 // Click on the ok button in the confirmation overlay. | |
192 $('alertOverlayOk').click(); | |
193 | |
194 // Context sensitive buttons should be disabled. | |
195 expectTrue($('personalCertsTab-view').disabled); | |
196 expectTrue($('personalCertsTab-backup').disabled); | |
197 expectTrue($('personalCertsTab-delete').disabled); | |
198 expectFalse($('personalCertsTab-import').disabled); | |
199 if (this.isChromeOS) | |
200 expectFalse($('personalCertsTab-import-and-bind').disabled); | |
201 // Tree should be empty. | |
202 expectTrue(personalCerts.querySelector('div.tree-item') === null); | |
34 }); | 203 }); |
204 | |
205 // TODO(mattm): add more tests. | |
206 | |
207 GEN('#endif // defined(USE_NSS)'); | |
OLD | NEW |