| 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', | 19 'exportCertificate', |
| 20 'exportPersonalCertificate', | 20 'exportPersonalCertificate', |
| 21 'exportPersonalCertificatePasswordSelected', | 21 'exportPersonalCertificatePasswordSelected', |
| 22 'getCaCertificateTrust', | 22 'getCaCertificateTrust', |
| 23 'importCaCertificate', |
| 24 'importPersonalCertificate', |
| 23 'importPersonalCertificatePasswordSelected', | 25 'importPersonalCertificatePasswordSelected', |
| 26 'importServerCertificate', |
| 24 'refreshCertificates', | 27 'refreshCertificates', |
| 25 'viewCertificate', | 28 'viewCertificate', |
| 26 ]); | 29 ]); |
| 27 | 30 |
| 28 /** @private {!CaTrustInfo} */ | 31 /** @private {!CaTrustInfo} */ |
| 29 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; | 32 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; |
| 30 | 33 |
| 31 /** @private {?CertificatesError} */ | 34 /** @private {?CertificatesError} */ |
| 32 this.certificatesError_ = null; | 35 this.certificatesError_ = null; |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 TestCertificatesBrowserProxy.prototype = { | 38 TestCertificatesBrowserProxy.prototype = { |
| 36 __proto__: settings.TestBrowserProxy.prototype, | 39 __proto__: settings.TestBrowserProxy.prototype, |
| 37 | 40 |
| 38 /** | 41 /** |
| 39 * @param {!CaTrustInfo} caTrustInfo | 42 * @param {!CaTrustInfo} caTrustInfo |
| 40 */ | 43 */ |
| 41 setCaCertificateTrust: function(caTrustInfo) { | 44 setCaCertificateTrust: function(caTrustInfo) { |
| 42 this.caTrustInfo_ = caTrustInfo; | 45 this.caTrustInfo_ = caTrustInfo; |
| 43 }, | 46 }, |
| 44 | 47 |
| 45 /** @override */ | 48 /** @override */ |
| 46 getCaCertificateTrust: function(id) { | 49 getCaCertificateTrust: function(id) { |
| 47 this.methodCalled('getCaCertificateTrust', id); | 50 this.methodCalled('getCaCertificateTrust', id); |
| 48 return Promise.resolve(this.caTrustInfo_); | 51 return Promise.resolve(this.caTrustInfo_); |
| 49 }, | 52 }, |
| 50 | 53 |
| 51 /** @override */ | 54 /** @override */ |
| 55 importServerCertificate: function() { |
| 56 this.methodCalled('importServerCertificate'); |
| 57 return Promise.resolve(); |
| 58 }, |
| 59 |
| 60 /** @override */ |
| 61 importCaCertificate: function() { |
| 62 this.methodCalled('importCaCertificate'); |
| 63 return Promise.resolve('dummyName'); |
| 64 }, |
| 65 |
| 66 /** @override */ |
| 52 editCaCertificateTrust: function(id, ssl, email, objSign) { | 67 editCaCertificateTrust: function(id, ssl, email, objSign) { |
| 53 this.methodCalled('editCaCertificateTrust', { | 68 this.methodCalled('editCaCertificateTrust', { |
| 54 id: id, ssl: ssl, email: email, objSign: objSign, | 69 id: id, ssl: ssl, email: email, objSign: objSign, |
| 55 }); | 70 }); |
| 56 return this.fulfillRequest_(); | 71 return this.fulfillRequest_(); |
| 57 }, | 72 }, |
| 58 | 73 |
| 59 /** | 74 /** |
| 60 * Forces some of the browser proxy methods to start returning errors. | 75 * Forces some of the browser proxy methods to start returning errors. |
| 61 */ | 76 */ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 }, | 97 }, |
| 83 | 98 |
| 84 /** @override */ | 99 /** @override */ |
| 85 exportPersonalCertificatePasswordSelected: function(password) { | 100 exportPersonalCertificatePasswordSelected: function(password) { |
| 86 this.resolverMap_.get( | 101 this.resolverMap_.get( |
| 87 'exportPersonalCertificatePasswordSelected').resolve(password); | 102 'exportPersonalCertificatePasswordSelected').resolve(password); |
| 88 return this.fulfillRequest_(); | 103 return this.fulfillRequest_(); |
| 89 }, | 104 }, |
| 90 | 105 |
| 91 /** @override */ | 106 /** @override */ |
| 107 importPersonalCertificate: function() { |
| 108 this.methodCalled('importPersonalCertificate'); |
| 109 return Promise.resolve(true); |
| 110 }, |
| 111 |
| 112 /** @override */ |
| 92 importPersonalCertificatePasswordSelected: function(password) { | 113 importPersonalCertificatePasswordSelected: function(password) { |
| 93 this.resolverMap_.get( | 114 this.resolverMap_.get( |
| 94 'importPersonalCertificatePasswordSelected').resolve(password); | 115 'importPersonalCertificatePasswordSelected').resolve(password); |
| 95 return this.fulfillRequest_(); | 116 return this.fulfillRequest_(); |
| 96 }, | 117 }, |
| 97 | 118 |
| 98 /** @override */ | 119 /** @override */ |
| 99 refreshCertificates: function() { | 120 refreshCertificates: function() { |
| 100 this.methodCalled('refreshCertificates'); | 121 this.methodCalled('refreshCertificates'); |
| 101 }, | 122 }, |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 assertEquals( | 568 assertEquals( |
| 548 settings.CertificateAction.EXPORT_PERSONAL, | 569 settings.CertificateAction.EXPORT_PERSONAL, |
| 549 detail.action); | 570 detail.action); |
| 550 assertEquals(subentry.model.id, detail.subnode.id); | 571 assertEquals(subentry.model.id, detail.subnode.id); |
| 551 }); | 572 }); |
| 552 }); | 573 }); |
| 553 }); | 574 }); |
| 554 } | 575 } |
| 555 | 576 |
| 556 function registerPageTests() { | 577 function registerPageTests() { |
| 557 /** @type {?SettingsCertificateManagerPage} */ | 578 /** @type {?SettingsCertificateManagerPageElement} */ |
| 558 var page = null; | 579 var page = null; |
| 559 | 580 |
| 560 /** @type {?TestCertificatesBrowserProxy} */ | 581 /** @type {?TestCertificatesBrowserProxy} */ |
| 561 var browserProxy = null; | 582 var browserProxy = null; |
| 562 | 583 |
| 563 /** @enum {number} */ | 584 /** @enum {number} */ |
| 564 var CertificateCategoryIndex = { | 585 var CertificateCategoryIndex = { |
| 565 PERSONAL: 0, | 586 PERSONAL: 0, |
| 566 SERVER: 1, | 587 SERVER: 1, |
| 567 CA: 2, | 588 CA: 2, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); | 649 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); |
| 629 }); | 650 }); |
| 630 }); | 651 }); |
| 631 | 652 |
| 632 /** | 653 /** |
| 633 * Dispatches a settings.CertificateActionEvent. | 654 * Dispatches a settings.CertificateActionEvent. |
| 634 * @param {!settings.CertificateAction} action The type of action to | 655 * @param {!settings.CertificateAction} action The type of action to |
| 635 * simulate. | 656 * simulate. |
| 636 */ | 657 */ |
| 637 function dispatchCertificateActionEvent(action) { | 658 function dispatchCertificateActionEvent(action) { |
| 638 var eventDetail = /** @type {!CertificateActionEventDetail} */ ({ | 659 page.fire( |
| 660 settings.CertificateActionEvent, |
| 661 /** @type {!CertificateActionEventDetail} */ ({ |
| 639 action: action, | 662 action: action, |
| 640 subnode: createSampleCertificateSubnode(), | 663 subnode: createSampleCertificateSubnode(), |
| 641 certificateType: settings.CertificateType.PERSONAL | 664 certificateType: settings.CertificateType.PERSONAL |
| 642 }); | 665 })); |
| 643 page.dispatchEvent(new CustomEvent( | |
| 644 settings.CertificateActionEvent, {detail: eventDetail})); | |
| 645 } | 666 } |
| 646 | 667 |
| 647 /** | 668 /** |
| 648 * Tests that a dialog opens as a response to a | 669 * Tests that a dialog opens as a response to a |
| 649 * settings.CertificateActionEvent. | 670 * settings.CertificateActionEvent. |
| 650 * @param {string} dialogTagName The type of dialog to test. | 671 * @param {string} dialogTagName The type of dialog to test. |
| 651 * @param {!settings.CertificateAction} action The action that is supposed | 672 * @param {!settings.CertificateAction} action The action that is supposed |
| 652 * to trigger the dialog. | 673 * to trigger the dialog. |
| 653 */ | 674 */ |
| 654 function testDialogOpensOnAction(dialogTagName, action) { | 675 function testDialogOpensOnAction(dialogTagName, action) { |
| 655 assertFalse(!!page.shadowRoot.querySelector(dialogTagName)); | 676 assertFalse(!!page.shadowRoot.querySelector(dialogTagName)); |
| 656 dispatchCertificateActionEvent(action); | 677 dispatchCertificateActionEvent(action); |
| 657 Polymer.dom.flush(); | 678 Polymer.dom.flush(); |
| 658 assertTrue(!!page.shadowRoot.querySelector(dialogTagName)); | 679 assertTrue(!!page.shadowRoot.querySelector(dialogTagName)); |
| 659 } | 680 } |
| 660 | 681 |
| 661 test('OpensDialog_DeleteConfirmation', function() { | 682 test('OpensDialog_DeleteConfirmation', function() { |
| 662 testDialogOpensOnAction( | 683 testDialogOpensOnAction( |
| 663 'settings-certificate-delete-confirmation-dialog', | 684 'settings-certificate-delete-confirmation-dialog', |
| 664 settings.CertificateAction.DELETE); | 685 settings.CertificateAction.DELETE); |
| 665 }); | 686 }); |
| 666 | 687 |
| 667 test('OpensDialog_PasswordEncryption', function() { | 688 test('OpensDialog_PasswordEncryption', function() { |
| 668 testDialogOpensOnAction( | 689 testDialogOpensOnAction( |
| 669 'settings-certificate-password-encryption-dialog', | 690 'settings-certificate-password-encryption-dialog', |
| 670 settings.CertificateAction.EXPORT_PERSONAL); | 691 settings.CertificateAction.EXPORT_PERSONAL); |
| 671 }); | 692 }); |
| 672 | 693 |
| 673 test('OpensDialog_PasswordDecryption', function() { | 694 test('OpensDialog_PasswordDecryption', function() { |
| 674 testDialogOpensOnAction( | 695 testDialogOpensOnAction( |
| 675 'settings-certificate-password-decryption-dialog', | 696 'settings-certificate-password-decryption-dialog', |
| 676 settings.CertificateAction.IMPORT_PERSONAL); | 697 settings.CertificateAction.IMPORT); |
| 677 }); | 698 }); |
| 678 | 699 |
| 679 test('OpensDialog_CaTrustEdit', function() { | 700 test('OpensDialog_CaTrustEdit', function() { |
| 680 testDialogOpensOnAction( | 701 testDialogOpensOnAction( |
| 681 'settings-ca-trust-edit-dialog', settings.CertificateAction.EDIT); | 702 'settings-ca-trust-edit-dialog', settings.CertificateAction.EDIT); |
| 682 }); | 703 }); |
| 683 }); | 704 }); |
| 684 } | 705 } |
| 706 |
| 707 function registerCertificateListTests() { |
| 708 /** @type {?SettingsCertificateListElement} */ |
| 709 var element = null; |
| 710 |
| 711 /** @type {?TestCertificatesBrowserProxy} */ |
| 712 var browserProxy = null; |
| 713 |
| 714 suite('CertificateListTests', function() { |
| 715 setup(function() { |
| 716 browserProxy = new TestCertificatesBrowserProxy(); |
| 717 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
| 718 PolymerTest.clearBody(); |
| 719 element = document.createElement('settings-certificate-list'); |
| 720 document.body.appendChild(element); |
| 721 }); |
| 722 |
| 723 teardown(function() { element.remove(); }); |
| 724 |
| 725 /** |
| 726 * Tests the "Import" button functionality. |
| 727 * @param {!settings.CertificateType} certificateType |
| 728 * @param {string} proxyMethodName The name of the proxy method expected |
| 729 * to be called. |
| 730 * @param {boolean} actionEventExpected Whether a |
| 731 * settings.CertificateActionEvent is expected to fire as a result |
| 732 * tapping the Import button. |
| 733 */ |
| 734 function testImportForCertificateType( |
| 735 certificateType, proxyMethodName, actionEventExpected) { |
| 736 element.certificateType = certificateType |
| 737 Polymer.dom.flush(); |
| 738 |
| 739 var importButton = element.$$('paper-button'); |
| 740 assertTrue(!!importButton); |
| 741 |
| 742 var waitForActionEvent = actionEventExpected ? |
| 743 eventToPromise(settings.CertificateActionEvent, element) : |
| 744 Promise.resolve(null); |
| 745 |
| 746 MockInteractions.tap(importButton); |
| 747 return browserProxy.whenCalled(proxyMethodName).then(function() { |
| 748 return waitForActionEvent; |
| 749 }).then(function(event) { |
| 750 if (actionEventExpected) { |
| 751 assertEquals( |
| 752 settings.CertificateAction.IMPORT, event.detail.action); |
| 753 assertEquals(certificateType, event.detail.certificateType); |
| 754 } |
| 755 }); |
| 756 } |
| 757 |
| 758 test('ImportButton_Personal', function() { |
| 759 return testImportForCertificateType( |
| 760 settings.CertificateType.PERSONAL, |
| 761 'importPersonalCertificate', true); |
| 762 }); |
| 763 |
| 764 test('ImportButton_Server', function() { |
| 765 return testImportForCertificateType( |
| 766 settings.CertificateType.SERVER, 'importServerCertificate', |
| 767 false); |
| 768 }); |
| 769 |
| 770 test('ImportButton_CA', function() { |
| 771 return testImportForCertificateType( |
| 772 settings.CertificateType.CA, 'importCaCertificate', true); |
| 773 }); |
| 774 }); |
| 775 } |
| 685 | 776 |
| 686 return { | 777 return { |
| 687 registerTests: function() { | 778 registerTests: function() { |
| 688 registerCaTrustEditDialogTests(); | 779 registerCaTrustEditDialogTests(); |
| 689 registerDeleteDialogTests(); | 780 registerDeleteDialogTests(); |
| 690 registerPasswordEncryptDialogTests(); | 781 registerPasswordEncryptDialogTests(); |
| 691 registerPasswordDecryptDialogTests(); | 782 registerPasswordDecryptDialogTests(); |
| 692 registerPageTests(); | 783 registerPageTests(); |
| 693 registerCertificateSubentryTests(); | 784 registerCertificateSubentryTests(); |
| 785 registerCertificateListTests(); |
| 694 }, | 786 }, |
| 695 }; | 787 }; |
| 696 }); | 788 }); |
| OLD | NEW |