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 |
| 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); |
| 92 |
| 93 expectTrue($('otherCertsTab-view').disabled); |
| 94 expectTrue($('otherCertsTab-export').disabled); |
| 95 expectTrue($('otherCertsTab-delete').disabled); |
| 96 }); |
| 97 |
| 98 /** |
| 99 * TestFixture for certificate manager WebUI testing. |
| 100 * @extends {CertificateManagerWebUIBaseTest} |
| 101 * @constructor |
| 102 **/ |
| 103 function CertificateManagerWebUITest() {} |
| 104 |
| 105 CertificateManagerWebUITest.prototype = { |
| 106 __proto__: CertificateManagerWebUIBaseTest.prototype, |
| 107 |
| 108 /** @inheritDoc */ |
| 109 preLoad: function() { |
| 110 CertificateManagerWebUIBaseTest.prototype.preLoad.call(this); |
| 111 |
| 112 this.mockHandler.expects(once()).populateCertificateManager().will( |
| 113 callFunction(function() { |
| 114 CertificateManager.onPopulateTree( |
| 115 ['personalCertsTab-tree', |
| 116 [{'id': 'o1', |
| 117 'name': 'org1', |
| 118 'subnodes': [ |
| 119 {'id': 'c1', |
| 120 'name': 'cert1', |
| 121 'readonly': false, |
| 122 'untrusted': false, |
| 123 'extractable': true, |
| 124 }, |
| 125 ], |
| 126 }, |
| 127 ], |
| 128 ])})); |
| 129 |
| 130 if (this.isChromeOS) |
| 131 this.mockHandler.expects(once()).checkTpmTokenReady().will(callFunction( |
| 132 function() { |
| 133 CertificateManager.onCheckTpmTokenReady(true); |
| 134 })); |
| 135 }, |
| 136 }; |
| 137 |
31 TEST_F('CertificateManagerWebUITest', | 138 TEST_F('CertificateManagerWebUITest', |
32 'MAYBE_testOpenCertificateManager', function() { | 139 'testViewAndDeleteCert', function() { |
33 assertEquals(this.browsePreload, document.location.href); | 140 assertEquals(this.browsePreload, document.location.href); |
34 }); | 141 |
| 142 this.mockHandler.expects(once()).viewCertificate(['c1']); |
| 143 |
| 144 expectTrue($('personalCertsTab-view').disabled); |
| 145 expectTrue($('personalCertsTab-backup').disabled); |
| 146 expectTrue($('personalCertsTab-delete').disabled); |
| 147 expectFalse($('personalCertsTab-import').disabled); |
| 148 if (this.isChromeOS) |
| 149 expectFalse($('personalCertsTab-import-and-bind').disabled); |
| 150 |
| 151 var personalCerts = $('personalCertsTab'); |
| 152 |
| 153 // Click on the first folder. |
| 154 personalCerts.querySelector('div.tree-item').click(); |
| 155 // Buttons should still be in same state. |
| 156 expectTrue($('personalCertsTab-view').disabled); |
| 157 expectTrue($('personalCertsTab-backup').disabled); |
| 158 expectTrue($('personalCertsTab-delete').disabled); |
| 159 expectFalse($('personalCertsTab-import').disabled); |
| 160 if (this.isChromeOS) |
| 161 expectFalse($('personalCertsTab-import-and-bind').disabled); |
| 162 |
| 163 // Click on the first cert. |
| 164 personalCerts.querySelector('div.tree-item div.tree-item').click(); |
| 165 // Buttons should now allow you to act on the cert. |
| 166 expectFalse($('personalCertsTab-view').disabled); |
| 167 expectFalse($('personalCertsTab-backup').disabled); |
| 168 expectFalse($('personalCertsTab-delete').disabled); |
| 169 expectFalse($('personalCertsTab-import').disabled); |
| 170 if (this.isChromeOS) |
| 171 expectFalse($('personalCertsTab-import-and-bind').disabled); |
| 172 |
| 173 // Click on the view button. |
| 174 $('personalCertsTab-view').click(); |
| 175 |
| 176 Mock4JS.verifyAllMocks(); |
| 177 Mock4JS.clearMocksToVerify(); |
| 178 |
| 179 this.mockHandler.expects(once()).deleteCertificate(['c1']).will(callFunction( |
| 180 function() { |
| 181 CertificateManager.onPopulateTree(['personalCertsTab-tree', []]); |
| 182 })); |
| 183 |
| 184 // Click on the delete button. |
| 185 $('personalCertsTab-delete').click(); |
| 186 // Click on the ok button in the confirmation overlay. |
| 187 $('alertOverlayOk').click(); |
| 188 |
| 189 // Context sensitive buttons should be disabled. |
| 190 expectTrue($('personalCertsTab-view').disabled); |
| 191 expectTrue($('personalCertsTab-backup').disabled); |
| 192 expectTrue($('personalCertsTab-delete').disabled); |
| 193 expectFalse($('personalCertsTab-import').disabled); |
| 194 if (this.isChromeOS) |
| 195 expectFalse($('personalCertsTab-import-and-bind').disabled); |
| 196 // Tree should be empty. |
| 197 expectTrue(personalCerts.querySelector('div.tree-item') === null); |
| 198 }); |
| 199 |
| 200 // TODO(mattm): add more tests. |
| 201 |
| 202 GEN('#endif // defined(USE_NSS)'); |
OLD | NEW |