| 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 * |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 }, | 106 }, |
| 107 | 107 |
| 108 /** @override */ | 108 /** @override */ |
| 109 exportPersonalCertificatePasswordSelected: function(password) { | 109 exportPersonalCertificatePasswordSelected: function(password) { |
| 110 this.resolverMap_.get( | 110 this.resolverMap_.get( |
| 111 'exportPersonalCertificatePasswordSelected').resolve(password); | 111 'exportPersonalCertificatePasswordSelected').resolve(password); |
| 112 return this.fulfillRequest_(); | 112 return this.fulfillRequest_(); |
| 113 }, | 113 }, |
| 114 | 114 |
| 115 /** @override */ | 115 /** @override */ |
| 116 importPersonalCertificate: function() { | 116 importPersonalCertificate: function(useHardwareBacked) { |
| 117 this.methodCalled('importPersonalCertificate'); | 117 this.methodCalled('importPersonalCertificate', useHardwareBacked); |
| 118 return Promise.resolve(true); | 118 return Promise.resolve(true); |
| 119 }, | 119 }, |
| 120 | 120 |
| 121 /** @override */ | 121 /** @override */ |
| 122 importPersonalCertificatePasswordSelected: function(password) { | 122 importPersonalCertificatePasswordSelected: function(password) { |
| 123 this.resolverMap_.get( | 123 this.resolverMap_.get( |
| 124 'importPersonalCertificatePasswordSelected').resolve(password); | 124 'importPersonalCertificatePasswordSelected').resolve(password); |
| 125 return this.fulfillRequest_(); | 125 return this.fulfillRequest_(); |
| 126 }, | 126 }, |
| 127 | 127 |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 teardown(function() { element.remove(); }); | 792 teardown(function() { element.remove(); }); |
| 793 | 793 |
| 794 /** | 794 /** |
| 795 * Tests the "Import" button functionality. | 795 * Tests the "Import" button functionality. |
| 796 * @param {!CertificateType} certificateType | 796 * @param {!CertificateType} certificateType |
| 797 * @param {string} proxyMethodName The name of the proxy method expected | 797 * @param {string} proxyMethodName The name of the proxy method expected |
| 798 * to be called. | 798 * to be called. |
| 799 * @param {boolean} actionEventExpected Whether a | 799 * @param {boolean} actionEventExpected Whether a |
| 800 * settings.CertificateActionEvent is expected to fire as a result | 800 * settings.CertificateActionEvent is expected to fire as a result |
| 801 * tapping the Import button. | 801 * tapping the Import button. |
| 802 * @param {boolean} bindBtn Whether to click on the import and bind btn. |
| 802 */ | 803 */ |
| 803 function testImportForCertificateType( | 804 function testImportForCertificateType( |
| 804 certificateType, proxyMethodName, actionEventExpected) { | 805 certificateType, proxyMethodName, actionEventExpected, bindBtn) { |
| 805 element.certificateType = certificateType | 806 element.certificateType = certificateType; |
| 806 Polymer.dom.flush(); | 807 Polymer.dom.flush(); |
| 807 | 808 |
| 808 var importButton = element.$$('paper-button'); | 809 var importButton = |
| 810 bindBtn ? element.$$('#importAndBind') : element.$$('#import'); |
| 809 assertTrue(!!importButton); | 811 assertTrue(!!importButton); |
| 810 | 812 |
| 811 var waitForActionEvent = actionEventExpected ? | 813 var waitForActionEvent = actionEventExpected ? |
| 812 test_util.eventToPromise(settings.CertificateActionEvent, element) : | 814 test_util.eventToPromise(settings.CertificateActionEvent, element) : |
| 813 Promise.resolve(null); | 815 Promise.resolve(null); |
| 814 | 816 |
| 815 MockInteractions.tap(importButton); | 817 MockInteractions.tap(importButton); |
| 816 return browserProxy.whenCalled(proxyMethodName).then(function() { | 818 return browserProxy.whenCalled(proxyMethodName) |
| 817 return waitForActionEvent; | 819 .then(function(arg) { |
| 818 }).then(function(event) { | 820 if (proxyMethodName == 'importPersonalCertificate') { |
| 819 if (actionEventExpected) { | 821 assertNotEquals(arg, undefined); |
| 820 assertEquals( | 822 assertEquals(arg, bindBtn); |
| 821 CertificateAction.IMPORT, event.detail.action); | 823 } |
| 822 assertEquals(certificateType, event.detail.certificateType); | 824 return waitForActionEvent; |
| 823 } | 825 }) |
| 824 }); | 826 .then(function(event) { |
| 827 if (actionEventExpected) { |
| 828 assertEquals(CertificateAction.IMPORT, event.detail.action); |
| 829 assertEquals(certificateType, event.detail.certificateType); |
| 830 } |
| 831 }); |
| 825 } | 832 } |
| 826 | 833 |
| 827 test('ImportButton_Personal', function() { | 834 test('ImportButton_Personal', function() { |
| 828 return testImportForCertificateType( | 835 return testImportForCertificateType( |
| 829 CertificateType.PERSONAL, | 836 CertificateType.PERSONAL, 'importPersonalCertificate', true, false); |
| 830 'importPersonalCertificate', true); | |
| 831 }); | 837 }); |
| 832 | 838 |
| 839 if (cr.isChromeOS) { |
| 840 test('ImportAndBindButton_Personal', function() { |
| 841 return testImportForCertificateType( |
| 842 CertificateType.PERSONAL, 'importPersonalCertificate', true, |
| 843 true); |
| 844 }); |
| 845 } |
| 846 |
| 833 test('ImportButton_Server', function() { | 847 test('ImportButton_Server', function() { |
| 834 return testImportForCertificateType( | 848 return testImportForCertificateType( |
| 835 CertificateType.SERVER, 'importServerCertificate', | 849 CertificateType.SERVER, 'importServerCertificate', false, false); |
| 836 false); | |
| 837 }); | 850 }); |
| 838 | 851 |
| 839 test('ImportButton_CA', function() { | 852 test('ImportButton_CA', function() { |
| 840 return testImportForCertificateType( | 853 return testImportForCertificateType( |
| 841 CertificateType.CA, 'importCaCertificate', true); | 854 CertificateType.CA, 'importCaCertificate', true, false); |
| 842 }); | 855 }); |
| 843 }); | 856 }); |
| 844 } | 857 } |
| 845 | 858 |
| 846 return { | 859 return { |
| 847 registerTests: function() { | 860 registerTests: function() { |
| 848 registerCaTrustEditDialogTests(); | 861 registerCaTrustEditDialogTests(); |
| 849 registerDeleteDialogTests(); | 862 registerDeleteDialogTests(); |
| 850 registerPasswordEncryptDialogTests(); | 863 registerPasswordEncryptDialogTests(); |
| 851 registerPasswordDecryptDialogTests(); | 864 registerPasswordDecryptDialogTests(); |
| 852 registerPageTests(); | 865 registerPageTests(); |
| 853 registerCertificateSubentryTests(); | 866 registerCertificateSubentryTests(); |
| 854 registerCertificateListTests(); | 867 registerCertificateListTests(); |
| 855 }, | 868 }, |
| 856 }; | 869 }; |
| 857 }); | 870 }); |
| OLD | NEW |