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 'exportPersonalCertificatePasswordSelected', | 19 'exportPersonalCertificatePasswordSelected', |
20 'getCaCertificateTrust', | 20 'getCaCertificateTrust', |
21 'importPersonalCertificatePasswordSelected', | 21 'importPersonalCertificatePasswordSelected', |
| 22 'refreshCertificates', |
22 ]); | 23 ]); |
23 | 24 |
24 /** @private {!CaTrustInfo} */ | 25 /** @private {!CaTrustInfo} */ |
25 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; | 26 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; |
26 }; | 27 }; |
27 | 28 |
28 TestCertificatesBrowserProxy.prototype = { | 29 TestCertificatesBrowserProxy.prototype = { |
29 __proto__: settings.TestBrowserProxy.prototype, | 30 __proto__: settings.TestBrowserProxy.prototype, |
30 | 31 |
31 /** | 32 /** |
(...skipping 29 matching lines...) Expand all Loading... |
61 'exportPersonalCertificatePasswordSelected').resolve(password); | 62 'exportPersonalCertificatePasswordSelected').resolve(password); |
62 return Promise.resolve(); | 63 return Promise.resolve(); |
63 }, | 64 }, |
64 | 65 |
65 /** @override */ | 66 /** @override */ |
66 importPersonalCertificatePasswordSelected: function(password) { | 67 importPersonalCertificatePasswordSelected: function(password) { |
67 this.resolverMap_.get( | 68 this.resolverMap_.get( |
68 'importPersonalCertificatePasswordSelected').resolve(password); | 69 'importPersonalCertificatePasswordSelected').resolve(password); |
69 return Promise.resolve(); | 70 return Promise.resolve(); |
70 }, | 71 }, |
| 72 |
| 73 /** @override */ |
| 74 refreshCertificates: function() { |
| 75 this.methodCalled('refreshCertificates'); |
| 76 }, |
71 }; | 77 }; |
72 | 78 |
| 79 /** @return {!Certificate} */ |
| 80 function createSampleCertificate() { |
| 81 return { |
| 82 id: 'dummyCertificateId', |
| 83 name: 'dummyCertificateName', |
| 84 subnodes: [ |
| 85 createSampleCertificateSubnode() |
| 86 ], |
| 87 }; |
| 88 } |
| 89 |
73 /** @return {!CertificateSubnode} */ | 90 /** @return {!CertificateSubnode} */ |
74 function createSampleCertificateSubnode() { | 91 function createSampleCertificateSubnode() { |
75 return { | 92 return { |
76 extractable: false, | 93 extractable: false, |
77 id: 'dummyId', | 94 id: 'dummySubnodeId', |
78 name: 'dummyName', | 95 name: 'dummySubnodeName', |
79 policy: false, | 96 policy: false, |
80 readonly: false, | 97 readonly: false, |
81 untrusted: false, | 98 untrusted: false, |
82 urlLocked: false, | 99 urlLocked: false, |
83 }; | 100 }; |
84 } | 101 } |
85 | 102 |
86 /** | 103 /** |
87 * Triggers an 'input' event on the given text input field (which triggers | 104 * Triggers an 'input' event on the given text input field (which triggers |
88 * validation to occur for password fields being tested in this file). | 105 * validation to occur for password fields being tested in this file). |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 var methodName = 'importPersonalCertificatePasswordSelected'; | 311 var methodName = 'importPersonalCertificatePasswordSelected'; |
295 return browserProxy.whenCalled(methodName).then(function(password) { | 312 return browserProxy.whenCalled(methodName).then(function(password) { |
296 assertEquals(passwordInputElement.value, password); | 313 assertEquals(passwordInputElement.value, password); |
297 // Check that the dialog is closed. | 314 // Check that the dialog is closed. |
298 assertFalse(dialog.$.dialog.opened); | 315 assertFalse(dialog.$.dialog.opened); |
299 }); | 316 }); |
300 }); | 317 }); |
301 }); | 318 }); |
302 } | 319 } |
303 | 320 |
| 321 function registerPageTests() { |
| 322 /** @type {?SettingsCertificateManagerPage} */ |
| 323 var page = null; |
| 324 |
| 325 /** @type {?TestCertificatesBrowserProxy} */ |
| 326 var browserProxy = null; |
| 327 |
| 328 /** @enum {number} */ |
| 329 var CertificateCategoryIndex = { |
| 330 PERSONAL: 0, |
| 331 SERVER: 1, |
| 332 CA: 2, |
| 333 OTHER: 3, |
| 334 }; |
| 335 |
| 336 suite('CertificateManagerPageTests', function() { |
| 337 setup(function() { |
| 338 browserProxy = new TestCertificatesBrowserProxy(); |
| 339 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
| 340 PolymerTest.clearBody(); |
| 341 page = document.createElement('settings-certificate-manager-page'); |
| 342 document.body.appendChild(page); |
| 343 }); |
| 344 |
| 345 teardown(function() { page.remove(); }); |
| 346 |
| 347 /** |
| 348 * Test that the page requests information from the browser on startup and |
| 349 * that it gets populated accordingly. |
| 350 */ |
| 351 test('Initialization', function() { |
| 352 // Trigger all category tabs to be added to the DOM. |
| 353 var paperTabsElement = page.shadowRoot.querySelector('paper-tabs'); |
| 354 paperTabsElement.selected = CertificateCategoryIndex.PERSONAL; |
| 355 Polymer.dom.flush(); |
| 356 paperTabsElement.selected = CertificateCategoryIndex.SERVER; |
| 357 Polymer.dom.flush(); |
| 358 paperTabsElement.selected = CertificateCategoryIndex.CA; |
| 359 Polymer.dom.flush(); |
| 360 paperTabsElement.selected = CertificateCategoryIndex.OTHER; |
| 361 Polymer.dom.flush(); |
| 362 var certificateLists = page.shadowRoot.querySelectorAll( |
| 363 'settings-certificate-list'); |
| 364 assertEquals(4, certificateLists.length); |
| 365 |
| 366 var assertCertificateListLength = function( |
| 367 listIndex, expectedSize) { |
| 368 var certificateEntries = |
| 369 certificateLists[listIndex].shadowRoot.querySelectorAll( |
| 370 'settings-certificate-entry'); |
| 371 assertEquals(expectedSize, certificateEntries.length); |
| 372 }; |
| 373 |
| 374 assertCertificateListLength(CertificateCategoryIndex.PERSONAL, 0); |
| 375 assertCertificateListLength(CertificateCategoryIndex.SERVER, 0); |
| 376 assertCertificateListLength(CertificateCategoryIndex.CA, 0); |
| 377 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); |
| 378 |
| 379 return browserProxy.whenCalled('refreshCertificates').then( |
| 380 function() { |
| 381 // Simulate response for personal and CA certificates. |
| 382 cr.webUIListenerCallback( |
| 383 'certificates-changed', 'personalCerts', |
| 384 [createSampleCertificate()]); |
| 385 cr.webUIListenerCallback( |
| 386 'certificates-changed', 'caCerts', |
| 387 [createSampleCertificate(), createSampleCertificate()]); |
| 388 Polymer.dom.flush(); |
| 389 |
| 390 assertCertificateListLength(CertificateCategoryIndex.PERSONAL, 1); |
| 391 assertCertificateListLength(CertificateCategoryIndex.SERVER, 0); |
| 392 assertCertificateListLength(CertificateCategoryIndex.CA, 2); |
| 393 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); |
| 394 }); |
| 395 }); |
| 396 }); |
| 397 } |
| 398 |
304 return { | 399 return { |
305 registerTests: function() { | 400 registerTests: function() { |
306 registerCaTrustEditDialogTests(); | 401 registerCaTrustEditDialogTests(); |
307 registerDeleteDialogTests(); | 402 registerDeleteDialogTests(); |
308 registerPasswordEncryptDialogTests(); | 403 registerPasswordEncryptDialogTests(); |
309 registerPasswordDecryptDialogTests(); | 404 registerPasswordDecryptDialogTests(); |
| 405 registerPageTests(); |
310 }, | 406 }, |
311 }; | 407 }; |
312 }); | 408 }); |
OLD | NEW |