OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 cr.define('certificate_manager_page', function() { | 5 cr.define('certificate_manager_page', function() { |
6 /** | 6 /** |
7 * A test version of CertificatesBrowserProxy. Provides helper methods | 7 * A test version of CertificatesBrowserProxy. Provides helper methods |
8 * for allowing tests to know when a method was called, as well as | 8 * for allowing tests to know when a method was called, as well as |
9 * specifying mock responses. | 9 * specifying mock responses. |
10 * | 10 * |
11 * @constructor | 11 * @constructor |
12 * @implements {settings.CertificatesBrowserProxy} | 12 * @implements {settings.CertificatesBrowserProxy} |
13 * @extends {settings.TestBrowserProxy} | 13 * @extends {settings.TestBrowserProxy} |
14 */ | 14 */ |
15 var TestCertificatesBrowserProxy = function() { | 15 var TestCertificatesBrowserProxy = function() { |
16 settings.TestBrowserProxy.call(this, [ | 16 settings.TestBrowserProxy.call(this, [ |
17 'deleteCertificate', | 17 'deleteCertificate', |
18 'editCaCertificateTrust', | 18 'editCaCertificateTrust', |
| 19 'exportCertificate', |
| 20 'exportPersonalCertificate', |
19 'exportPersonalCertificatePasswordSelected', | 21 'exportPersonalCertificatePasswordSelected', |
20 'getCaCertificateTrust', | 22 'getCaCertificateTrust', |
21 'importPersonalCertificatePasswordSelected', | 23 'importPersonalCertificatePasswordSelected', |
22 'refreshCertificates', | 24 'refreshCertificates', |
| 25 'viewCertificate', |
23 ]); | 26 ]); |
24 | 27 |
25 /** @private {!CaTrustInfo} */ | 28 /** @private {!CaTrustInfo} */ |
26 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; | 29 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; |
| 30 |
| 31 /** @private {?CertificatesError} */ |
| 32 this.certificatesError_ = null; |
27 }; | 33 }; |
28 | 34 |
29 TestCertificatesBrowserProxy.prototype = { | 35 TestCertificatesBrowserProxy.prototype = { |
30 __proto__: settings.TestBrowserProxy.prototype, | 36 __proto__: settings.TestBrowserProxy.prototype, |
31 | 37 |
32 /** | 38 /** |
33 * @param {!CaTrustInfo} caTrustInfo | 39 * @param {!CaTrustInfo} caTrustInfo |
34 */ | 40 */ |
35 setCaCertificateTrust: function(caTrustInfo) { | 41 setCaCertificateTrust: function(caTrustInfo) { |
36 this.caTrustInfo_ = caTrustInfo; | 42 this.caTrustInfo_ = caTrustInfo; |
37 }, | 43 }, |
38 | 44 |
39 /** @override */ | 45 /** @override */ |
40 getCaCertificateTrust: function(id) { | 46 getCaCertificateTrust: function(id) { |
41 this.methodCalled('getCaCertificateTrust', id); | 47 this.methodCalled('getCaCertificateTrust', id); |
42 return Promise.resolve(this.caTrustInfo_); | 48 return Promise.resolve(this.caTrustInfo_); |
43 }, | 49 }, |
44 | 50 |
45 /** @override */ | 51 /** @override */ |
46 editCaCertificateTrust: function(id, ssl, email, objSign) { | 52 editCaCertificateTrust: function(id, ssl, email, objSign) { |
47 this.methodCalled('editCaCertificateTrust', { | 53 this.methodCalled('editCaCertificateTrust', { |
48 id: id, ssl: ssl, email: email, objSign: objSign, | 54 id: id, ssl: ssl, email: email, objSign: objSign, |
49 }); | 55 }); |
50 return Promise.resolve(); | 56 return this.fulfillRequest_(); |
| 57 }, |
| 58 |
| 59 /** |
| 60 * Forces some of the browser proxy methods to start returning errors. |
| 61 */ |
| 62 forceCertificatesError: function() { |
| 63 this.certificatesError_ = /** @type {!CertificatesError} */ ({ |
| 64 title: 'DummyError', description: 'DummyDescription' |
| 65 }); |
| 66 }, |
| 67 |
| 68 /** |
| 69 * @return {!Promise} A promise that is resolved or rejected based on the |
| 70 * value of |certificatesError_|. |
| 71 * @private |
| 72 */ |
| 73 fulfillRequest_: function() { |
| 74 return this.certificatesError_ === null ? |
| 75 Promise.resolve() : Promise.reject(this.certificatesError_); |
51 }, | 76 }, |
52 | 77 |
53 /** @override */ | 78 /** @override */ |
54 deleteCertificate: function(id) { | 79 deleteCertificate: function(id) { |
55 this.methodCalled('deleteCertificate', id); | 80 this.methodCalled('deleteCertificate', id); |
56 return Promise.resolve(); | 81 return this.fulfillRequest_(); |
57 }, | 82 }, |
58 | 83 |
59 /** @override */ | 84 /** @override */ |
60 exportPersonalCertificatePasswordSelected: function(password) { | 85 exportPersonalCertificatePasswordSelected: function(password) { |
61 this.resolverMap_.get( | 86 this.resolverMap_.get( |
62 'exportPersonalCertificatePasswordSelected').resolve(password); | 87 'exportPersonalCertificatePasswordSelected').resolve(password); |
63 return Promise.resolve(); | 88 return this.fulfillRequest_(); |
64 }, | 89 }, |
65 | 90 |
66 /** @override */ | 91 /** @override */ |
67 importPersonalCertificatePasswordSelected: function(password) { | 92 importPersonalCertificatePasswordSelected: function(password) { |
68 this.resolverMap_.get( | 93 this.resolverMap_.get( |
69 'importPersonalCertificatePasswordSelected').resolve(password); | 94 'importPersonalCertificatePasswordSelected').resolve(password); |
70 return Promise.resolve(); | 95 return this.fulfillRequest_(); |
71 }, | 96 }, |
72 | 97 |
73 /** @override */ | 98 /** @override */ |
74 refreshCertificates: function() { | 99 refreshCertificates: function() { |
75 this.methodCalled('refreshCertificates'); | 100 this.methodCalled('refreshCertificates'); |
76 }, | 101 }, |
| 102 |
| 103 /** @override */ |
| 104 viewCertificate: function(id) { |
| 105 this.methodCalled('viewCertificate', id); |
| 106 }, |
| 107 |
| 108 /** @override */ |
| 109 exportCertificate: function(id) { |
| 110 this.methodCalled('exportCertificate', id); |
| 111 }, |
| 112 |
| 113 /** @override */ |
| 114 exportPersonalCertificate: function(id) { |
| 115 this.methodCalled('exportPersonalCertificate', id); |
| 116 return Promise.resolve(); |
| 117 }, |
77 }; | 118 }; |
78 | 119 |
79 /** @return {!Certificate} */ | 120 /** @return {!Certificate} */ |
80 function createSampleCertificate() { | 121 function createSampleCertificate() { |
81 return { | 122 return { |
82 id: 'dummyCertificateId', | 123 id: 'dummyCertificateId', |
83 name: 'dummyCertificateName', | 124 name: 'dummyCertificateName', |
84 subnodes: [ | 125 subnodes: [ |
85 createSampleCertificateSubnode() | 126 createSampleCertificateSubnode() |
86 ], | 127 ], |
(...skipping 17 matching lines...) Expand all Loading... |
104 * Triggers an 'input' event on the given text input field (which triggers | 145 * Triggers an 'input' event on the given text input field (which triggers |
105 * validation to occur for password fields being tested in this file). | 146 * validation to occur for password fields being tested in this file). |
106 * @param {!PaperInputElement} element | 147 * @param {!PaperInputElement} element |
107 */ | 148 */ |
108 function triggerInputEvent(element) { | 149 function triggerInputEvent(element) { |
109 // The actual key code is irrelevant for tests. | 150 // The actual key code is irrelevant for tests. |
110 var kSpaceBar = 32; | 151 var kSpaceBar = 32; |
111 MockInteractions.keyEventOn(element, 'input', kSpaceBar); | 152 MockInteractions.keyEventOn(element, 'input', kSpaceBar); |
112 } | 153 } |
113 | 154 |
| 155 /** |
| 156 * Converts an event occurrence to a promise. |
| 157 * @param {string} eventType |
| 158 * @param {!HTMLElement} target |
| 159 * @return {!Promise} A promise firing once the event occurs. |
| 160 */ |
| 161 function eventToPromise(eventType, target) { |
| 162 return new Promise(function(resolve, reject) { |
| 163 target.addEventListener(eventType, resolve); |
| 164 }); |
| 165 } |
| 166 |
114 function registerCaTrustEditDialogTests() { | 167 function registerCaTrustEditDialogTests() { |
115 /** @type {?SettingsCaTrustEditDialogElement} */ | 168 /** @type {?SettingsCaTrustEditDialogElement} */ |
116 var dialog = null; | 169 var dialog = null; |
117 | 170 |
118 /** @type {?TestCertificatesBrowserProxy} */ | 171 /** @type {?TestCertificatesBrowserProxy} */ |
119 var browserProxy = null; | 172 var browserProxy = null; |
120 | 173 |
121 /** @type {!CertificateSubnode} */ | 174 /** @type {!CertificateSubnode} */ |
122 var model = createSampleCertificateSubnode(); | 175 var model = createSampleCertificateSubnode(); |
123 | 176 |
124 /** @type {!CaTrustInfo} */ | 177 /** @type {!CaTrustInfo} */ |
125 var caTrustInfo = { ssl: true, email: false, objSign: false }; | 178 var caTrustInfo = { ssl: true, email: false, objSign: false }; |
126 | 179 |
127 suite('CaTrustEditDialogTests', function() { | 180 suite('CaTrustEditDialogTests', function() { |
128 setup(function() { | 181 setup(function() { |
129 browserProxy = new TestCertificatesBrowserProxy(); | 182 browserProxy = new TestCertificatesBrowserProxy(); |
130 browserProxy.setCaCertificateTrust(caTrustInfo); | 183 browserProxy.setCaCertificateTrust(caTrustInfo); |
131 | 184 |
132 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; | 185 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
133 PolymerTest.clearBody(); | 186 PolymerTest.clearBody(); |
134 dialog = document.createElement('settings-ca-trust-edit-dialog'); | 187 dialog = document.createElement('settings-ca-trust-edit-dialog'); |
135 dialog.model = model; | 188 dialog.model = model; |
136 document.body.appendChild(dialog); | 189 document.body.appendChild(dialog); |
137 }); | 190 }); |
138 | 191 |
139 teardown(function() { dialog.remove(); }); | 192 teardown(function() { dialog.remove(); }); |
140 | 193 |
141 test('Dialog', function() { | 194 test('EditSuccess', function() { |
142 return browserProxy.whenCalled('getCaCertificateTrust').then( | 195 return browserProxy.whenCalled('getCaCertificateTrust').then( |
143 function(id) { | 196 function(id) { |
144 assertEquals(model.id, id); | 197 assertEquals(model.id, id); |
145 assertEquals(caTrustInfo.ssl, dialog.$.ssl.checked); | 198 assertEquals(caTrustInfo.ssl, dialog.$.ssl.checked); |
146 assertEquals(caTrustInfo.email, dialog.$.email.checked); | 199 assertEquals(caTrustInfo.email, dialog.$.email.checked); |
147 assertEquals(caTrustInfo.objSign, dialog.$.objSign.checked); | 200 assertEquals(caTrustInfo.objSign, dialog.$.objSign.checked); |
148 | 201 |
149 // Simulate toggling all checkboxes. | 202 // Simulate toggling all checkboxes. |
150 MockInteractions.tap(dialog.$.ssl); | 203 MockInteractions.tap(dialog.$.ssl); |
151 MockInteractions.tap(dialog.$.email); | 204 MockInteractions.tap(dialog.$.email); |
152 MockInteractions.tap(dialog.$.objSign); | 205 MockInteractions.tap(dialog.$.objSign); |
153 | 206 |
154 // Simulate clicking 'OK'. | 207 // Simulate clicking 'OK'. |
155 MockInteractions.tap(dialog.$.ok); | 208 MockInteractions.tap(dialog.$.ok); |
156 | 209 |
157 return browserProxy.whenCalled('editCaCertificateTrust').then( | 210 return browserProxy.whenCalled('editCaCertificateTrust'); |
158 function(args) { | 211 }).then( |
159 assertEquals(model.id, args.id); | 212 function(args) { |
160 // Checking that the values sent to C++ are reflecting the | 213 assertEquals(model.id, args.id); |
161 // changes made by the user (toggling all checkboxes). | 214 // Checking that the values sent to C++ are reflecting the |
162 assertEquals(caTrustInfo.ssl, !args.ssl); | 215 // changes made by the user (toggling all checkboxes). |
163 assertEquals(caTrustInfo.email, !args.email); | 216 assertEquals(caTrustInfo.ssl, !args.ssl); |
164 assertEquals(caTrustInfo.objSign, !args.objSign); | 217 assertEquals(caTrustInfo.email, !args.email); |
165 // Check that the dialog is closed. | 218 assertEquals(caTrustInfo.objSign, !args.objSign); |
166 assertFalse(dialog.$.dialog.opened); | 219 // Check that the dialog is closed. |
167 }); | 220 assertFalse(dialog.$.dialog.opened); |
| 221 }); |
| 222 }); |
| 223 |
| 224 test('EditError', function() { |
| 225 browserProxy.forceCertificatesError(); |
| 226 var whenErrorEventFired = eventToPromise('certificates-error', dialog); |
| 227 |
| 228 return browserProxy.whenCalled('getCaCertificateTrust').then( |
| 229 function() { |
| 230 MockInteractions.tap(dialog.$.ok); |
| 231 return browserProxy.whenCalled('editCaCertificateTrust'); |
| 232 }).then( |
| 233 function() { |
| 234 return whenErrorEventFired; |
168 }); | 235 }); |
169 }); | 236 }); |
170 }); | 237 }); |
171 } | 238 } |
172 | 239 |
173 function registerDeleteDialogTests() { | 240 function registerDeleteDialogTests() { |
174 /** @type {?SettingsCertificateDeleteConfirmationDialogElement} */ | 241 /** @type {?SettingsCertificateDeleteConfirmationDialogElement} */ |
175 var dialog = null; | 242 var dialog = null; |
176 | 243 |
177 /** @type {?TestCertificatesBrowserProxy} */ | 244 /** @type {?TestCertificatesBrowserProxy} */ |
(...skipping 25 matching lines...) Expand all Loading... |
203 // Simulate clicking 'OK'. | 270 // Simulate clicking 'OK'. |
204 MockInteractions.tap(dialog.$.ok); | 271 MockInteractions.tap(dialog.$.ok); |
205 | 272 |
206 return browserProxy.whenCalled('deleteCertificate').then( | 273 return browserProxy.whenCalled('deleteCertificate').then( |
207 function(id) { | 274 function(id) { |
208 assertEquals(model.id, id); | 275 assertEquals(model.id, id); |
209 // Check that the dialog is closed. | 276 // Check that the dialog is closed. |
210 assertFalse(dialog.$.dialog.opened); | 277 assertFalse(dialog.$.dialog.opened); |
211 }); | 278 }); |
212 }); | 279 }); |
| 280 |
| 281 test('DeleteError', function() { |
| 282 browserProxy.forceCertificatesError(); |
| 283 var whenErrorEventFired = eventToPromise('certificates-error', dialog); |
| 284 |
| 285 // Simulate clicking 'OK'. |
| 286 MockInteractions.tap(dialog.$.ok); |
| 287 return browserProxy.whenCalled('deleteCertificate').then( |
| 288 function(id) { |
| 289 assertEquals(model.id, id); |
| 290 // Ensure that the 'error' event was fired. |
| 291 return whenErrorEventFired; |
| 292 }); |
| 293 }); |
213 }); | 294 }); |
214 } | 295 } |
215 | 296 |
216 function registerPasswordEncryptDialogTests() { | 297 function registerPasswordEncryptDialogTests() { |
217 /** @type {?SettingsCertificatePasswordEncryptionDialogElement} */ | 298 /** @type {?SettingsCertificatePasswordEncryptionDialogElement} */ |
218 var dialog = null; | 299 var dialog = null; |
219 | 300 |
220 /** @type {?TestCertificatesBrowserProxy} */ | 301 /** @type {?TestCertificatesBrowserProxy} */ |
221 var browserProxy = null; | 302 var browserProxy = null; |
222 | 303 |
223 /** @type {!CertificateSubnode} */ | 304 /** @type {!CertificateSubnode} */ |
224 var model = createSampleCertificateSubnode(); | 305 var model = createSampleCertificateSubnode(); |
225 | 306 |
| 307 var methodName = 'exportPersonalCertificatePasswordSelected'; |
| 308 |
226 suite('CertificatePasswordEncryptionDialogTests', function() { | 309 suite('CertificatePasswordEncryptionDialogTests', function() { |
227 setup(function() { | 310 setup(function() { |
228 browserProxy = new TestCertificatesBrowserProxy(); | 311 browserProxy = new TestCertificatesBrowserProxy(); |
229 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; | 312 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
230 PolymerTest.clearBody(); | 313 PolymerTest.clearBody(); |
231 dialog = document.createElement( | 314 dialog = document.createElement( |
232 'settings-certificate-password-encryption-dialog'); | 315 'settings-certificate-password-encryption-dialog'); |
233 dialog.model = model; | 316 dialog.model = model; |
234 document.body.appendChild(dialog); | 317 document.body.appendChild(dialog); |
235 }); | 318 }); |
(...skipping 19 matching lines...) Expand all Loading... |
255 passwordInputElement.value = 'foopassword'; | 338 passwordInputElement.value = 'foopassword'; |
256 triggerInputEvent(passwordInputElement); | 339 triggerInputEvent(passwordInputElement); |
257 assertTrue(dialog.$.ok.disabled); | 340 assertTrue(dialog.$.ok.disabled); |
258 confirmPasswordInputElement.value = passwordInputElement.value; | 341 confirmPasswordInputElement.value = passwordInputElement.value; |
259 triggerInputEvent(confirmPasswordInputElement); | 342 triggerInputEvent(confirmPasswordInputElement); |
260 assertFalse(dialog.$.ok.disabled); | 343 assertFalse(dialog.$.ok.disabled); |
261 | 344 |
262 // Simulate clicking 'OK'. | 345 // Simulate clicking 'OK'. |
263 MockInteractions.tap(dialog.$.ok); | 346 MockInteractions.tap(dialog.$.ok); |
264 | 347 |
265 var methodName = 'exportPersonalCertificatePasswordSelected'; | |
266 return browserProxy.whenCalled(methodName).then(function(password) { | 348 return browserProxy.whenCalled(methodName).then(function(password) { |
267 assertEquals(passwordInputElement.value, password); | 349 assertEquals(passwordInputElement.value, password); |
268 // Check that the dialog is closed. | 350 // Check that the dialog is closed. |
269 assertFalse(dialog.$.dialog.opened); | 351 assertFalse(dialog.$.dialog.opened); |
270 }); | 352 }); |
271 }); | 353 }); |
| 354 |
| 355 test('EncryptError', function() { |
| 356 browserProxy.forceCertificatesError(); |
| 357 |
| 358 var passwordInputElements = |
| 359 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input'); |
| 360 var passwordInputElement = passwordInputElements[0]; |
| 361 passwordInputElement.value = 'foopassword'; |
| 362 var confirmPasswordInputElement = passwordInputElements[1]; |
| 363 confirmPasswordInputElement.value = passwordInputElement.value; |
| 364 triggerInputEvent(passwordInputElement); |
| 365 |
| 366 var whenErrorEventFired = eventToPromise('certificates-error', dialog); |
| 367 MockInteractions.tap(dialog.$.ok); |
| 368 |
| 369 return browserProxy.whenCalled(methodName).then(function() { |
| 370 return whenErrorEventFired; |
| 371 }); |
| 372 }); |
272 }); | 373 }); |
273 } | 374 } |
274 | 375 |
275 function registerPasswordDecryptDialogTests() { | 376 function registerPasswordDecryptDialogTests() { |
276 /** @type {?SettingsCertificatePasswordDecryptionDialogElement} */ | 377 /** @type {?SettingsCertificatePasswordDecryptionDialogElement} */ |
277 var dialog = null; | 378 var dialog = null; |
278 | 379 |
279 /** @type {?TestCertificatesBrowserProxy} */ | 380 /** @type {?TestCertificatesBrowserProxy} */ |
280 var browserProxy = null; | 381 var browserProxy = null; |
281 | 382 |
| 383 var methodName = 'importPersonalCertificatePasswordSelected'; |
| 384 |
282 suite('CertificatePasswordDecryptionDialogTests', function() { | 385 suite('CertificatePasswordDecryptionDialogTests', function() { |
283 setup(function() { | 386 setup(function() { |
284 browserProxy = new TestCertificatesBrowserProxy(); | 387 browserProxy = new TestCertificatesBrowserProxy(); |
285 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; | 388 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
286 PolymerTest.clearBody(); | 389 PolymerTest.clearBody(); |
287 dialog = document.createElement( | 390 dialog = document.createElement( |
288 'settings-certificate-password-decryption-dialog'); | 391 'settings-certificate-password-decryption-dialog'); |
289 document.body.appendChild(dialog); | 392 document.body.appendChild(dialog); |
290 }); | 393 }); |
291 | 394 |
292 teardown(function() { dialog.remove(); }); | 395 teardown(function() { dialog.remove(); }); |
293 | 396 |
294 test('DecryptSuccess', function() { | 397 test('DecryptSuccess', function() { |
295 var passwordInputElement = | 398 var passwordInputElement = |
296 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); | 399 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); |
297 assertTrue(dialog.$.dialog.opened); | 400 assertTrue(dialog.$.dialog.opened); |
298 assertTrue(dialog.$.ok.disabled); | 401 assertTrue(dialog.$.ok.disabled); |
299 | 402 |
300 // Test that the 'OK' button is disabled when the password field is | 403 // Test that the 'OK' button is disabled when the password field is |
301 // empty. | 404 // empty. |
302 triggerInputEvent(passwordInputElement); | 405 triggerInputEvent(passwordInputElement); |
303 assertTrue(dialog.$.ok.disabled); | 406 assertTrue(dialog.$.ok.disabled); |
304 passwordInputElement.value = 'foopassword'; | 407 passwordInputElement.value = 'foopassword'; |
305 triggerInputEvent(passwordInputElement); | 408 triggerInputEvent(passwordInputElement); |
306 assertFalse(dialog.$.ok.disabled); | 409 assertFalse(dialog.$.ok.disabled); |
307 | 410 |
308 // Simulate clicking 'OK'. | 411 // Simulate clicking 'OK'. |
309 MockInteractions.tap(dialog.$.ok); | 412 MockInteractions.tap(dialog.$.ok); |
310 | 413 |
311 var methodName = 'importPersonalCertificatePasswordSelected'; | |
312 return browserProxy.whenCalled(methodName).then(function(password) { | 414 return browserProxy.whenCalled(methodName).then(function(password) { |
313 assertEquals(passwordInputElement.value, password); | 415 assertEquals(passwordInputElement.value, password); |
314 // Check that the dialog is closed. | 416 // Check that the dialog is closed. |
315 assertFalse(dialog.$.dialog.opened); | 417 assertFalse(dialog.$.dialog.opened); |
316 }); | 418 }); |
317 }); | 419 }); |
| 420 |
| 421 test('DecryptError', function() { |
| 422 browserProxy.forceCertificatesError(); |
| 423 // Simulate entering some password. |
| 424 var passwordInputElement = |
| 425 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); |
| 426 passwordInputElement.value = 'foopassword'; |
| 427 triggerInputEvent(passwordInputElement); |
| 428 |
| 429 var whenErrorEventFired = eventToPromise('certificates-error', dialog); |
| 430 MockInteractions.tap(dialog.$.ok); |
| 431 return browserProxy.whenCalled(methodName).then(function() { |
| 432 return whenErrorEventFired; |
| 433 }); |
| 434 }); |
318 }); | 435 }); |
319 } | 436 } |
320 | 437 |
| 438 function registerCertificateSubentryTests() { |
| 439 var subentry = null; |
| 440 |
| 441 /** @type {?TestCertificatesBrowserProxy} */ |
| 442 var browserProxy = null; |
| 443 |
| 444 /** |
| 445 * @return {!Promise} A promise firing once a |
| 446 * |settings.CertificateActionEvent| fires. |
| 447 */ |
| 448 var actionEventToPromise = function() { |
| 449 return eventToPromise(settings.CertificateActionEvent, subentry); |
| 450 }; |
| 451 |
| 452 suite('CertificateManagerPageTests', function() { |
| 453 setup(function() { |
| 454 browserProxy = new TestCertificatesBrowserProxy(); |
| 455 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
| 456 PolymerTest.clearBody(); |
| 457 subentry = document.createElement('settings-certificate-subentry'); |
| 458 subentry.model = createSampleCertificateSubnode(); |
| 459 subentry.certificateType = settings.CertificateType.PERSONAL; |
| 460 document.body.appendChild(subentry); |
| 461 |
| 462 // Bring up the popup menu for the following tests to use. |
| 463 MockInteractions.tap(subentry.$.dots); |
| 464 Polymer.dom.flush(); |
| 465 }); |
| 466 |
| 467 teardown(function() { subentry.remove(); }); |
| 468 |
| 469 // Test case where 'View' option is tapped. |
| 470 test('MenuOptions_View', function() { |
| 471 var viewButton = subentry.shadowRoot.querySelector('#view'); |
| 472 MockInteractions.tap(viewButton); |
| 473 return browserProxy.whenCalled('viewCertificate').then(function(id) { |
| 474 assertEquals(subentry.model.id, id); |
| 475 }); |
| 476 }); |
| 477 |
| 478 // Test that the 'Edit' option is only shown when appropriate and that |
| 479 // once tapped the correct event is fired. |
| 480 test('MenuOptions_Edit', function() { |
| 481 var editButton = subentry.shadowRoot.querySelector('#edit'); |
| 482 // Should be disabled for any certificate type other than |
| 483 // CertificateType.CA |
| 484 assertTrue(editButton.hidden); |
| 485 subentry.certificateType = settings.CertificateType.CA; |
| 486 assertFalse(editButton.hidden); |
| 487 |
| 488 var waitForActionEvent = actionEventToPromise(); |
| 489 MockInteractions.tap(editButton); |
| 490 return waitForActionEvent.then(function(event) { |
| 491 var detail = /** @type {!CertificateActionEventDetail} */ ( |
| 492 event.detail); |
| 493 assertEquals(settings.CertificateAction.EDIT, detail.action); |
| 494 assertEquals(subentry.model.id, detail.subnode.id); |
| 495 assertEquals(subentry.certificateType, detail.certificateType); |
| 496 }); |
| 497 }); |
| 498 |
| 499 // Test that the 'Delete' option is only shown when appropriate and that |
| 500 // once tapped the correct event is fired. |
| 501 test('MenuOptions_Delete', function() { |
| 502 subentry.set('model.readonly', true); |
| 503 |
| 504 var deleteButton = subentry.shadowRoot.querySelector('#delete'); |
| 505 // Should be disabled when 'model.readonly' is true. |
| 506 assertTrue(deleteButton.hidden); |
| 507 subentry.set('model.readonly', false); |
| 508 assertFalse(deleteButton.hidden); |
| 509 |
| 510 var waitForActionEvent = actionEventToPromise(); |
| 511 MockInteractions.tap(deleteButton); |
| 512 return waitForActionEvent.then(function(event) { |
| 513 var detail = /** @type {!CertificateActionEventDetail} */ ( |
| 514 event.detail); |
| 515 assertEquals(settings.CertificateAction.DELETE, detail.action); |
| 516 assertEquals(subentry.model.id, detail.subnode.id); |
| 517 }); |
| 518 }); |
| 519 |
| 520 // Test case of exporting a certificate that is not PERSONAL. |
| 521 test('MenuOptions_Export', function() { |
| 522 subentry.certificateType = settings.CertificateType.SERVER; |
| 523 var exportButton = subentry.shadowRoot.querySelector('#export'); |
| 524 MockInteractions.tap(exportButton); |
| 525 return browserProxy.whenCalled('exportCertificate').then(function(id) { |
| 526 assertEquals(subentry.model.id, id); |
| 527 }); |
| 528 }); |
| 529 |
| 530 // Test case of exporting a PERSONAL certificate. |
| 531 test('MenuOptions_ExportPersonal', function() { |
| 532 var waitForActionEvent = actionEventToPromise(); |
| 533 |
| 534 var exportButton = subentry.shadowRoot.querySelector('#export'); |
| 535 MockInteractions.tap(exportButton); |
| 536 return browserProxy.whenCalled('exportPersonalCertificate').then( |
| 537 function(id) { |
| 538 assertEquals(subentry.model.id, id); |
| 539 |
| 540 // A promise firing once |settings.CertificateActionEvent| is |
| 541 // fired. |
| 542 return waitForActionEvent; |
| 543 }).then( |
| 544 function(event) { |
| 545 var detail = /** @type {!CertificateActionEventDetail} */ ( |
| 546 event.detail); |
| 547 assertEquals( |
| 548 settings.CertificateAction.EXPORT_PERSONAL, |
| 549 detail.action); |
| 550 assertEquals(subentry.model.id, detail.subnode.id); |
| 551 }); |
| 552 }); |
| 553 }); |
| 554 } |
| 555 |
321 function registerPageTests() { | 556 function registerPageTests() { |
322 /** @type {?SettingsCertificateManagerPage} */ | 557 /** @type {?SettingsCertificateManagerPage} */ |
323 var page = null; | 558 var page = null; |
324 | 559 |
325 /** @type {?TestCertificatesBrowserProxy} */ | 560 /** @type {?TestCertificatesBrowserProxy} */ |
326 var browserProxy = null; | 561 var browserProxy = null; |
327 | 562 |
328 /** @enum {number} */ | 563 /** @enum {number} */ |
329 var CertificateCategoryIndex = { | 564 var CertificateCategoryIndex = { |
330 PERSONAL: 0, | 565 PERSONAL: 0, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 'certificates-changed', 'caCerts', | 621 'certificates-changed', 'caCerts', |
387 [createSampleCertificate(), createSampleCertificate()]); | 622 [createSampleCertificate(), createSampleCertificate()]); |
388 Polymer.dom.flush(); | 623 Polymer.dom.flush(); |
389 | 624 |
390 assertCertificateListLength(CertificateCategoryIndex.PERSONAL, 1); | 625 assertCertificateListLength(CertificateCategoryIndex.PERSONAL, 1); |
391 assertCertificateListLength(CertificateCategoryIndex.SERVER, 0); | 626 assertCertificateListLength(CertificateCategoryIndex.SERVER, 0); |
392 assertCertificateListLength(CertificateCategoryIndex.CA, 2); | 627 assertCertificateListLength(CertificateCategoryIndex.CA, 2); |
393 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); | 628 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); |
394 }); | 629 }); |
395 }); | 630 }); |
| 631 |
| 632 /** |
| 633 * Dispatches a settings.CertificateActionEvent. |
| 634 * @param {!settings.CertificateAction} action The type of action to |
| 635 * simulate. |
| 636 */ |
| 637 function dispatchCertificateActionEvent(action) { |
| 638 var eventDetail = /** @type {!CertificateActionEventDetail} */ ({ |
| 639 action: action, |
| 640 subnode: createSampleCertificateSubnode(), |
| 641 certificateType: settings.CertificateType.PERSONAL |
| 642 }); |
| 643 page.dispatchEvent(new CustomEvent( |
| 644 settings.CertificateActionEvent, {detail: eventDetail})); |
| 645 } |
| 646 |
| 647 /** |
| 648 * Tests that a dialog opens as a response to a |
| 649 * settings.CertificateActionEvent. |
| 650 * @param {string} dialogTagName The type of dialog to test. |
| 651 * @param {!settings.CertificateAction} action The action that is supposed |
| 652 * to trigger the dialog. |
| 653 */ |
| 654 function testDialogOpensOnAction(dialogTagName, action) { |
| 655 assertFalse(!!page.shadowRoot.querySelector(dialogTagName)); |
| 656 dispatchCertificateActionEvent(action); |
| 657 Polymer.dom.flush(); |
| 658 assertTrue(!!page.shadowRoot.querySelector(dialogTagName)); |
| 659 } |
| 660 |
| 661 test('OpensDialog_DeleteConfirmation', function() { |
| 662 testDialogOpensOnAction( |
| 663 'settings-certificate-delete-confirmation-dialog', |
| 664 settings.CertificateAction.DELETE); |
| 665 }); |
| 666 |
| 667 test('OpensDialog_PasswordEncryption', function() { |
| 668 testDialogOpensOnAction( |
| 669 'settings-certificate-password-encryption-dialog', |
| 670 settings.CertificateAction.EXPORT_PERSONAL); |
| 671 }); |
| 672 |
| 673 test('OpensDialog_PasswordDecryption', function() { |
| 674 testDialogOpensOnAction( |
| 675 'settings-certificate-password-decryption-dialog', |
| 676 settings.CertificateAction.IMPORT_PERSONAL); |
| 677 }); |
| 678 |
| 679 test('OpensDialog_CaTrustEdit', function() { |
| 680 testDialogOpensOnAction( |
| 681 'settings-ca-trust-edit-dialog', settings.CertificateAction.EDIT); |
| 682 }); |
396 }); | 683 }); |
397 } | 684 } |
398 | 685 |
399 return { | 686 return { |
400 registerTests: function() { | 687 registerTests: function() { |
401 registerCaTrustEditDialogTests(); | 688 registerCaTrustEditDialogTests(); |
402 registerDeleteDialogTests(); | 689 registerDeleteDialogTests(); |
403 registerPasswordEncryptDialogTests(); | 690 registerPasswordEncryptDialogTests(); |
404 registerPasswordDecryptDialogTests(); | 691 registerPasswordDecryptDialogTests(); |
405 registerPageTests(); | 692 registerPageTests(); |
| 693 registerCertificateSubentryTests(); |
406 }, | 694 }, |
407 }; | 695 }; |
408 }); | 696 }); |
OLD | NEW |