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

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

Issue 2101243004: [MD settings] certificate manager closure compilation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adding file Created 4 years, 5 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
« no previous file with comments | « chrome/browser/resources/settings/settings_resources.grd ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 *
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 var model = createSampleCertificateSubnode(); 299 var model = createSampleCertificateSubnode();
300 300
301 suite('CertificateDeleteConfirmationDialogTests', function() { 301 suite('CertificateDeleteConfirmationDialogTests', function() {
302 setup(function() { 302 setup(function() {
303 browserProxy = new TestCertificatesBrowserProxy(); 303 browserProxy = new TestCertificatesBrowserProxy();
304 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; 304 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy;
305 PolymerTest.clearBody(); 305 PolymerTest.clearBody();
306 dialog = document.createElement( 306 dialog = document.createElement(
307 'settings-certificate-delete-confirmation-dialog'); 307 'settings-certificate-delete-confirmation-dialog');
308 dialog.model = model; 308 dialog.model = model;
309 dialog.certificateType = settings.CertificateType.PERSONAL; 309 dialog.certificateType = CertificateType.PERSONAL;
310 document.body.appendChild(dialog); 310 document.body.appendChild(dialog);
311 }); 311 });
312 312
313 teardown(function() { dialog.remove(); }); 313 teardown(function() { dialog.remove(); });
314 314
315 test('DeleteSuccess', function() { 315 test('DeleteSuccess', function() {
316 assertTrue(dialog.$.dialog.opened); 316 assertTrue(dialog.$.dialog.opened);
317 // Check that the dialog title includes the certificate name. 317 // Check that the dialog title includes the certificate name.
318 var titleEl = Polymer.dom(dialog.$.dialog).querySelector('.title'); 318 var titleEl = Polymer.dom(dialog.$.dialog).querySelector('.title');
319 assertTrue(titleEl.textContent.includes(model.name)); 319 assertTrue(titleEl.textContent.includes(model.name));
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 return eventToPromise(settings.CertificateActionEvent, subentry); 500 return eventToPromise(settings.CertificateActionEvent, subentry);
501 }; 501 };
502 502
503 suite('CertificateManagerPageTests', function() { 503 suite('CertificateManagerPageTests', function() {
504 setup(function() { 504 setup(function() {
505 browserProxy = new TestCertificatesBrowserProxy(); 505 browserProxy = new TestCertificatesBrowserProxy();
506 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; 506 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy;
507 PolymerTest.clearBody(); 507 PolymerTest.clearBody();
508 subentry = document.createElement('settings-certificate-subentry'); 508 subentry = document.createElement('settings-certificate-subentry');
509 subentry.model = createSampleCertificateSubnode(); 509 subentry.model = createSampleCertificateSubnode();
510 subentry.certificateType = settings.CertificateType.PERSONAL; 510 subentry.certificateType = CertificateType.PERSONAL;
511 document.body.appendChild(subentry); 511 document.body.appendChild(subentry);
512 512
513 // Bring up the popup menu for the following tests to use. 513 // Bring up the popup menu for the following tests to use.
514 MockInteractions.tap(subentry.$.dots); 514 MockInteractions.tap(subentry.$.dots);
515 Polymer.dom.flush(); 515 Polymer.dom.flush();
516 }); 516 });
517 517
518 teardown(function() { subentry.remove(); }); 518 teardown(function() { subentry.remove(); });
519 519
520 // Test case where 'View' option is tapped. 520 // Test case where 'View' option is tapped.
521 test('MenuOptions_View', function() { 521 test('MenuOptions_View', function() {
522 var viewButton = subentry.shadowRoot.querySelector('#view'); 522 var viewButton = subentry.shadowRoot.querySelector('#view');
523 MockInteractions.tap(viewButton); 523 MockInteractions.tap(viewButton);
524 return browserProxy.whenCalled('viewCertificate').then(function(id) { 524 return browserProxy.whenCalled('viewCertificate').then(function(id) {
525 assertEquals(subentry.model.id, id); 525 assertEquals(subentry.model.id, id);
526 }); 526 });
527 }); 527 });
528 528
529 // Test that the 'Edit' option is only shown when appropriate and that 529 // Test that the 'Edit' option is only shown when appropriate and that
530 // once tapped the correct event is fired. 530 // once tapped the correct event is fired.
531 test('MenuOptions_Edit', function() { 531 test('MenuOptions_Edit', function() {
532 var editButton = subentry.shadowRoot.querySelector('#edit'); 532 var editButton = subentry.shadowRoot.querySelector('#edit');
533 assertTrue(!!editButton); 533 assertTrue(!!editButton);
534 // Should be disabled for any certificate type other than 534 // Should be disabled for any certificate type other than
535 // CertificateType.CA 535 // CertificateType.CA
536 assertTrue(editButton.hidden); 536 assertTrue(editButton.hidden);
537 subentry.certificateType = settings.CertificateType.CA; 537 subentry.certificateType = CertificateType.CA;
538 assertFalse(editButton.hidden); 538 assertFalse(editButton.hidden);
539 539
540 // Should be disabled if |policy| is true. 540 // Should be disabled if |policy| is true.
541 var model = createSampleCertificateSubnode(); 541 var model = createSampleCertificateSubnode();
542 model.policy = true; 542 model.policy = true;
543 subentry.model = model; 543 subentry.model = model;
544 assertTrue(editButton.hidden); 544 assertTrue(editButton.hidden);
545 545
546 subentry.model = createSampleCertificateSubnode(); 546 subentry.model = createSampleCertificateSubnode();
547 var waitForActionEvent = actionEventToPromise(); 547 var waitForActionEvent = actionEventToPromise();
548 MockInteractions.tap(editButton); 548 MockInteractions.tap(editButton);
549 return waitForActionEvent.then(function(event) { 549 return waitForActionEvent.then(function(event) {
550 var detail = /** @type {!CertificateActionEventDetail} */ ( 550 var detail = /** @type {!CertificateActionEventDetail} */ (
551 event.detail); 551 event.detail);
552 assertEquals(settings.CertificateAction.EDIT, detail.action); 552 assertEquals(CertificateAction.EDIT, detail.action);
553 assertEquals(subentry.model.id, detail.subnode.id); 553 assertEquals(subentry.model.id, detail.subnode.id);
554 assertEquals(subentry.certificateType, detail.certificateType); 554 assertEquals(subentry.certificateType, detail.certificateType);
555 }); 555 });
556 }); 556 });
557 557
558 // Test that the 'Delete' option is only shown when appropriate and that 558 // Test that the 'Delete' option is only shown when appropriate and that
559 // once tapped the correct event is fired. 559 // once tapped the correct event is fired.
560 test('MenuOptions_Delete', function() { 560 test('MenuOptions_Delete', function() {
561 var deleteButton = subentry.shadowRoot.querySelector('#delete'); 561 var deleteButton = subentry.shadowRoot.querySelector('#delete');
562 assertTrue(!!deleteButton); 562 assertTrue(!!deleteButton);
563 563
564 // Should be disabled when 'model.readonly' is true. 564 // Should be disabled when 'model.readonly' is true.
565 var model = createSampleCertificateSubnode(); 565 var model = createSampleCertificateSubnode();
566 model.readonly = true; 566 model.readonly = true;
567 subentry.model = model; 567 subentry.model = model;
568 assertTrue(deleteButton.hidden); 568 assertTrue(deleteButton.hidden);
569 569
570 // Should be disabled when 'model.policy' is true. 570 // Should be disabled when 'model.policy' is true.
571 var model = createSampleCertificateSubnode(); 571 var model = createSampleCertificateSubnode();
572 model.policy = true; 572 model.policy = true;
573 subentry.model = model; 573 subentry.model = model;
574 assertTrue(deleteButton.hidden); 574 assertTrue(deleteButton.hidden);
575 575
576 subentry.model = createSampleCertificateSubnode(); 576 subentry.model = createSampleCertificateSubnode();
577 var waitForActionEvent = actionEventToPromise(); 577 var waitForActionEvent = actionEventToPromise();
578 MockInteractions.tap(deleteButton); 578 MockInteractions.tap(deleteButton);
579 return waitForActionEvent.then(function(event) { 579 return waitForActionEvent.then(function(event) {
580 var detail = /** @type {!CertificateActionEventDetail} */ ( 580 var detail = /** @type {!CertificateActionEventDetail} */ (
581 event.detail); 581 event.detail);
582 assertEquals(settings.CertificateAction.DELETE, detail.action); 582 assertEquals(CertificateAction.DELETE, detail.action);
583 assertEquals(subentry.model.id, detail.subnode.id); 583 assertEquals(subentry.model.id, detail.subnode.id);
584 }); 584 });
585 }); 585 });
586 586
587 // Test that the 'Export' option is always shown when the certificate type 587 // Test that the 'Export' option is always shown when the certificate type
588 // is not PERSONAL and that once tapped the correct event is fired. 588 // is not PERSONAL and that once tapped the correct event is fired.
589 test('MenuOptions_Export', function() { 589 test('MenuOptions_Export', function() {
590 subentry.certificateType = settings.CertificateType.SERVER; 590 subentry.certificateType = CertificateType.SERVER;
591 var exportButton = subentry.shadowRoot.querySelector('#export'); 591 var exportButton = subentry.shadowRoot.querySelector('#export');
592 assertTrue(!!exportButton); 592 assertTrue(!!exportButton);
593 assertFalse(exportButton.hidden); 593 assertFalse(exportButton.hidden);
594 MockInteractions.tap(exportButton); 594 MockInteractions.tap(exportButton);
595 return browserProxy.whenCalled('exportCertificate').then(function(id) { 595 return browserProxy.whenCalled('exportCertificate').then(function(id) {
596 assertEquals(subentry.model.id, id); 596 assertEquals(subentry.model.id, id);
597 }); 597 });
598 }); 598 });
599 599
600 // Test case of exporting a PERSONAL certificate. 600 // Test case of exporting a PERSONAL certificate.
(...skipping 16 matching lines...) Expand all
617 assertEquals(subentry.model.id, id); 617 assertEquals(subentry.model.id, id);
618 618
619 // A promise firing once |settings.CertificateActionEvent| is 619 // A promise firing once |settings.CertificateActionEvent| is
620 // fired. 620 // fired.
621 return waitForActionEvent; 621 return waitForActionEvent;
622 }).then( 622 }).then(
623 function(event) { 623 function(event) {
624 var detail = /** @type {!CertificateActionEventDetail} */ ( 624 var detail = /** @type {!CertificateActionEventDetail} */ (
625 event.detail); 625 event.detail);
626 assertEquals( 626 assertEquals(
627 settings.CertificateAction.EXPORT_PERSONAL, 627 CertificateAction.EXPORT_PERSONAL,
628 detail.action); 628 detail.action);
629 assertEquals(subentry.model.id, detail.subnode.id); 629 assertEquals(subentry.model.id, detail.subnode.id);
630 }); 630 });
631 }); 631 });
632 }); 632 });
633 } 633 }
634 634
635 function registerPageTests() { 635 function registerPageTests() {
636 /** @type {?SettingsCertificateManagerPageElement} */ 636 /** @type {?SettingsCertificateManagerPageElement} */
637 var page = null; 637 var page = null;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 assertFalse(!!page.shadowRoot.querySelector(dialogTagName)); 718 assertFalse(!!page.shadowRoot.querySelector(dialogTagName));
719 page.fire(settings.CertificateActionEvent, eventDetail); 719 page.fire(settings.CertificateActionEvent, eventDetail);
720 Polymer.dom.flush(); 720 Polymer.dom.flush();
721 assertTrue(!!page.shadowRoot.querySelector(dialogTagName)); 721 assertTrue(!!page.shadowRoot.querySelector(dialogTagName));
722 } 722 }
723 723
724 test('OpensDialog_DeleteConfirmation', function() { 724 test('OpensDialog_DeleteConfirmation', function() {
725 testDialogOpensOnAction( 725 testDialogOpensOnAction(
726 'settings-certificate-delete-confirmation-dialog', 726 'settings-certificate-delete-confirmation-dialog',
727 /** @type {!CertificateActionEventDetail} */ ({ 727 /** @type {!CertificateActionEventDetail} */ ({
728 action: settings.CertificateAction.DELETE, 728 action: CertificateAction.DELETE,
729 subnode: createSampleCertificateSubnode(), 729 subnode: createSampleCertificateSubnode(),
730 certificateType: settings.CertificateType.PERSONAL 730 certificateType: CertificateType.PERSONAL
731 })); 731 }));
732 }); 732 });
733 733
734 test('OpensDialog_PasswordEncryption', function() { 734 test('OpensDialog_PasswordEncryption', function() {
735 testDialogOpensOnAction( 735 testDialogOpensOnAction(
736 'settings-certificate-password-encryption-dialog', 736 'settings-certificate-password-encryption-dialog',
737 /** @type {!CertificateActionEventDetail} */ ({ 737 /** @type {!CertificateActionEventDetail} */ ({
738 action: settings.CertificateAction.EXPORT_PERSONAL, 738 action: CertificateAction.EXPORT_PERSONAL,
739 subnode: createSampleCertificateSubnode(), 739 subnode: createSampleCertificateSubnode(),
740 certificateType: settings.CertificateType.PERSONAL 740 certificateType: CertificateType.PERSONAL
741 })); 741 }));
742 }); 742 });
743 743
744 test('OpensDialog_PasswordDecryption', function() { 744 test('OpensDialog_PasswordDecryption', function() {
745 testDialogOpensOnAction( 745 testDialogOpensOnAction(
746 'settings-certificate-password-decryption-dialog', 746 'settings-certificate-password-decryption-dialog',
747 /** @type {!CertificateActionEventDetail} */ ({ 747 /** @type {!CertificateActionEventDetail} */ ({
748 action: settings.CertificateAction.IMPORT, 748 action: CertificateAction.IMPORT,
749 subnode: createSampleCertificateSubnode(), 749 subnode: createSampleCertificateSubnode(),
750 certificateType: settings.CertificateType.PERSONAL 750 certificateType: CertificateType.PERSONAL
751 })); 751 }));
752 }); 752 });
753 753
754 test('OpensDialog_CaTrustEdit', function() { 754 test('OpensDialog_CaTrustEdit', function() {
755 testDialogOpensOnAction( 755 testDialogOpensOnAction(
756 'settings-ca-trust-edit-dialog', 756 'settings-ca-trust-edit-dialog',
757 /** @type {!CertificateActionEventDetail} */ ({ 757 /** @type {!CertificateActionEventDetail} */ ({
758 action: settings.CertificateAction.EDIT, 758 action: CertificateAction.EDIT,
759 subnode: createSampleCertificateSubnode(), 759 subnode: createSampleCertificateSubnode(),
760 certificateType: settings.CertificateType.CA 760 certificateType: CertificateType.CA
761 })); 761 }));
762 }); 762 });
763 763
764 test('OpensDialog_CaTrustImport', function() { 764 test('OpensDialog_CaTrustImport', function() {
765 testDialogOpensOnAction( 765 testDialogOpensOnAction(
766 'settings-ca-trust-edit-dialog', 766 'settings-ca-trust-edit-dialog',
767 /** @type {!CertificateActionEventDetail} */ ({ 767 /** @type {!CertificateActionEventDetail} */ ({
768 action: settings.CertificateAction.IMPORT, 768 action: CertificateAction.IMPORT,
769 subnode: {name: 'Dummy Certificate Name', id: null}, 769 subnode: {name: 'Dummy Certificate Name', id: null},
770 certificateType: settings.CertificateType.CA 770 certificateType: CertificateType.CA
771 })); 771 }));
772 }); 772 });
773 }); 773 });
774 } 774 }
775 775
776 function registerCertificateListTests() { 776 function registerCertificateListTests() {
777 /** @type {?SettingsCertificateListElement} */ 777 /** @type {?SettingsCertificateListElement} */
778 var element = null; 778 var element = null;
779 779
780 /** @type {?TestCertificatesBrowserProxy} */ 780 /** @type {?TestCertificatesBrowserProxy} */
781 var browserProxy = null; 781 var browserProxy = null;
782 782
783 suite('CertificateListTests', function() { 783 suite('CertificateListTests', function() {
784 setup(function() { 784 setup(function() {
785 browserProxy = new TestCertificatesBrowserProxy(); 785 browserProxy = new TestCertificatesBrowserProxy();
786 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; 786 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy;
787 PolymerTest.clearBody(); 787 PolymerTest.clearBody();
788 element = document.createElement('settings-certificate-list'); 788 element = document.createElement('settings-certificate-list');
789 document.body.appendChild(element); 789 document.body.appendChild(element);
790 }); 790 });
791 791
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 {!settings.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 */ 802 */
803 function testImportForCertificateType( 803 function testImportForCertificateType(
804 certificateType, proxyMethodName, actionEventExpected) { 804 certificateType, proxyMethodName, actionEventExpected) {
805 element.certificateType = certificateType 805 element.certificateType = certificateType
806 Polymer.dom.flush(); 806 Polymer.dom.flush();
807 807
808 var importButton = element.$$('paper-button'); 808 var importButton = element.$$('paper-button');
809 assertTrue(!!importButton); 809 assertTrue(!!importButton);
810 810
811 var waitForActionEvent = actionEventExpected ? 811 var waitForActionEvent = actionEventExpected ?
812 eventToPromise(settings.CertificateActionEvent, element) : 812 eventToPromise(settings.CertificateActionEvent, element) :
813 Promise.resolve(null); 813 Promise.resolve(null);
814 814
815 MockInteractions.tap(importButton); 815 MockInteractions.tap(importButton);
816 return browserProxy.whenCalled(proxyMethodName).then(function() { 816 return browserProxy.whenCalled(proxyMethodName).then(function() {
817 return waitForActionEvent; 817 return waitForActionEvent;
818 }).then(function(event) { 818 }).then(function(event) {
819 if (actionEventExpected) { 819 if (actionEventExpected) {
820 assertEquals( 820 assertEquals(
821 settings.CertificateAction.IMPORT, event.detail.action); 821 CertificateAction.IMPORT, event.detail.action);
822 assertEquals(certificateType, event.detail.certificateType); 822 assertEquals(certificateType, event.detail.certificateType);
823 } 823 }
824 }); 824 });
825 } 825 }
826 826
827 test('ImportButton_Personal', function() { 827 test('ImportButton_Personal', function() {
828 return testImportForCertificateType( 828 return testImportForCertificateType(
829 settings.CertificateType.PERSONAL, 829 CertificateType.PERSONAL,
830 'importPersonalCertificate', true); 830 'importPersonalCertificate', true);
831 }); 831 });
832 832
833 test('ImportButton_Server', function() { 833 test('ImportButton_Server', function() {
834 return testImportForCertificateType( 834 return testImportForCertificateType(
835 settings.CertificateType.SERVER, 'importServerCertificate', 835 CertificateType.SERVER, 'importServerCertificate',
836 false); 836 false);
837 }); 837 });
838 838
839 test('ImportButton_CA', function() { 839 test('ImportButton_CA', function() {
840 return testImportForCertificateType( 840 return testImportForCertificateType(
841 settings.CertificateType.CA, 'importCaCertificate', true); 841 CertificateType.CA, 'importCaCertificate', true);
842 }); 842 });
843 }); 843 });
844 } 844 }
845 845
846 return { 846 return {
847 registerTests: function() { 847 registerTests: function() {
848 registerCaTrustEditDialogTests(); 848 registerCaTrustEditDialogTests();
849 registerDeleteDialogTests(); 849 registerDeleteDialogTests();
850 registerPasswordEncryptDialogTests(); 850 registerPasswordEncryptDialogTests();
851 registerPasswordDecryptDialogTests(); 851 registerPasswordDecryptDialogTests();
852 registerPageTests(); 852 registerPageTests();
853 registerCertificateSubentryTests(); 853 registerCertificateSubentryTests();
854 registerCertificateListTests(); 854 registerCertificateListTests();
855 }, 855 },
856 }; 856 };
857 }); 857 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/settings_resources.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698