Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: chrome/test/data/webui/settings/certificate_manager_page_test.js

Issue 1842403004: MD Settings: Certificate manager, move "Import" button to the tab level. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
Dan Beam 2016/04/01 18:38:02 nit: \n\n -> \n
dpapad 2016/04/01 21:13:17 Done.
725
726 /**
727 * Tests the "Import" button functionality.
728 * @param {!settings.CertificateType} certificateType
729 * @param {string} proxyMethodName The name of the proxy method expected
730 * to be called.
731 * @param {boolean} actionEventExpected Whether a
732 * settings.CertificateActionEvent is expected to fire as a result
733 * tapping the Import button.
734 */
735 function testImportForCertificateType(
736 certificateType, proxyMethodName, actionEventExpected) {
737 element.certificateType = certificateType
738 Polymer.dom.flush();
739
740 var importButton = element.$$('paper-button');
741 assertTrue(!!importButton);
742
743 var waitForActionEvent = actionEventExpected ?
744 eventToPromise(settings.CertificateActionEvent, element) :
745 Promise.resolve(null);
746
747 MockInteractions.tap(importButton);
748 return browserProxy.whenCalled(proxyMethodName).then(
749 function() {
750 return waitForActionEvent;
751 }).then(
752 function(event) {
Dan Beam 2016/04/01 18:38:02 should this be .then(function(event) { on the
dpapad 2016/04/01 21:13:17 Done. Personally I am equally OK with either way.
753 if (actionEventExpected) {
754 assertEquals(
755 settings.CertificateAction.IMPORT, event.detail.action);
756 assertEquals(certificateType, event.detail.certificateType);
757 }
758 });
Dan Beam 2016/04/01 18:38:02 i'm not trying to enforce my ident on you, but re
dpapad 2016/04/01 21:13:17 Done.
759 }
760
761 test('ImportButton_Personal', function() {
762 return testImportForCertificateType(
763 settings.CertificateType.PERSONAL,
764 'importPersonalCertificate', true);
765 });
766
767 test('ImportButton_Server', function() {
768 return testImportForCertificateType(
769 settings.CertificateType.SERVER, 'importServerCertificate',
770 false);
771 });
772
773 test('ImportButton_CA', function() {
774 return testImportForCertificateType(
775 settings.CertificateType.CA, 'importCaCertificate', true);
776 });
777 });
778 }
685 779
686 return { 780 return {
687 registerTests: function() { 781 registerTests: function() {
688 registerCaTrustEditDialogTests(); 782 registerCaTrustEditDialogTests();
689 registerDeleteDialogTests(); 783 registerDeleteDialogTests();
690 registerPasswordEncryptDialogTests(); 784 registerPasswordEncryptDialogTests();
691 registerPasswordDecryptDialogTests(); 785 registerPasswordDecryptDialogTests();
692 registerPageTests(); 786 registerPageTests();
693 registerCertificateSubentryTests(); 787 registerCertificateSubentryTests();
788 registerCertificateListTests();
694 }, 789 },
695 }; 790 };
696 }); 791 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698