| 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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Should be disabled for any certificate type other than | 534 // Should be disabled for any certificate type other than |
| 534 // CertificateType.CA | 535 // CertificateType.CA |
| 535 assertTrue(editButton.hidden); | 536 assertTrue(editButton.hidden); |
| 536 subentry.certificateType = settings.CertificateType.CA; | 537 subentry.certificateType = settings.CertificateType.CA; |
| 537 assertFalse(editButton.hidden); | 538 assertFalse(editButton.hidden); |
| 538 | 539 |
| 540 // Should be disabled if |policy| is true. |
| 541 var model = createSampleCertificateSubnode(); |
| 542 model.policy = true; |
| 543 subentry.model = model; |
| 544 assertTrue(editButton.hidden); |
| 545 |
| 546 subentry.model = createSampleCertificateSubnode(); |
| 539 var waitForActionEvent = actionEventToPromise(); | 547 var waitForActionEvent = actionEventToPromise(); |
| 540 MockInteractions.tap(editButton); | 548 MockInteractions.tap(editButton); |
| 541 return waitForActionEvent.then(function(event) { | 549 return waitForActionEvent.then(function(event) { |
| 542 var detail = /** @type {!CertificateActionEventDetail} */ ( | 550 var detail = /** @type {!CertificateActionEventDetail} */ ( |
| 543 event.detail); | 551 event.detail); |
| 544 assertEquals(settings.CertificateAction.EDIT, detail.action); | 552 assertEquals(settings.CertificateAction.EDIT, detail.action); |
| 545 assertEquals(subentry.model.id, detail.subnode.id); | 553 assertEquals(subentry.model.id, detail.subnode.id); |
| 546 assertEquals(subentry.certificateType, detail.certificateType); | 554 assertEquals(subentry.certificateType, detail.certificateType); |
| 547 }); | 555 }); |
| 548 }); | 556 }); |
| 549 | 557 |
| 550 // 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 |
| 551 // once tapped the correct event is fired. | 559 // once tapped the correct event is fired. |
| 552 test('MenuOptions_Delete', function() { | 560 test('MenuOptions_Delete', function() { |
| 553 subentry.set('model.readonly', true); | 561 var deleteButton = subentry.shadowRoot.querySelector('#delete'); |
| 562 assertTrue(!!deleteButton); |
| 554 | 563 |
| 555 var deleteButton = subentry.shadowRoot.querySelector('#delete'); | |
| 556 // Should be disabled when 'model.readonly' is true. | 564 // Should be disabled when 'model.readonly' is true. |
| 565 var model = createSampleCertificateSubnode(); |
| 566 model.readonly = true; |
| 567 subentry.model = model; |
| 557 assertTrue(deleteButton.hidden); | 568 assertTrue(deleteButton.hidden); |
| 558 subentry.set('model.readonly', false); | |
| 559 assertFalse(deleteButton.hidden); | |
| 560 | 569 |
| 570 // Should be disabled when 'model.policy' is true. |
| 571 var model = createSampleCertificateSubnode(); |
| 572 model.policy = true; |
| 573 subentry.model = model; |
| 574 assertTrue(deleteButton.hidden); |
| 575 |
| 576 subentry.model = createSampleCertificateSubnode(); |
| 561 var waitForActionEvent = actionEventToPromise(); | 577 var waitForActionEvent = actionEventToPromise(); |
| 562 MockInteractions.tap(deleteButton); | 578 MockInteractions.tap(deleteButton); |
| 563 return waitForActionEvent.then(function(event) { | 579 return waitForActionEvent.then(function(event) { |
| 564 var detail = /** @type {!CertificateActionEventDetail} */ ( | 580 var detail = /** @type {!CertificateActionEventDetail} */ ( |
| 565 event.detail); | 581 event.detail); |
| 566 assertEquals(settings.CertificateAction.DELETE, detail.action); | 582 assertEquals(settings.CertificateAction.DELETE, detail.action); |
| 567 assertEquals(subentry.model.id, detail.subnode.id); | 583 assertEquals(subentry.model.id, detail.subnode.id); |
| 568 }); | 584 }); |
| 569 }); | 585 }); |
| 570 | 586 |
| 571 // Test case of exporting a certificate that is not PERSONAL. | 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. |
| 572 test('MenuOptions_Export', function() { | 589 test('MenuOptions_Export', function() { |
| 573 subentry.certificateType = settings.CertificateType.SERVER; | 590 subentry.certificateType = settings.CertificateType.SERVER; |
| 574 var exportButton = subentry.shadowRoot.querySelector('#export'); | 591 var exportButton = subentry.shadowRoot.querySelector('#export'); |
| 592 assertTrue(!!exportButton); |
| 593 assertFalse(exportButton.hidden); |
| 575 MockInteractions.tap(exportButton); | 594 MockInteractions.tap(exportButton); |
| 576 return browserProxy.whenCalled('exportCertificate').then(function(id) { | 595 return browserProxy.whenCalled('exportCertificate').then(function(id) { |
| 577 assertEquals(subentry.model.id, id); | 596 assertEquals(subentry.model.id, id); |
| 578 }); | 597 }); |
| 579 }); | 598 }); |
| 580 | 599 |
| 581 // Test case of exporting a PERSONAL certificate. | 600 // Test case of exporting a PERSONAL certificate. |
| 582 test('MenuOptions_ExportPersonal', function() { | 601 test('MenuOptions_ExportPersonal', function() { |
| 602 var exportButton = subentry.shadowRoot.querySelector('#export'); |
| 603 assertTrue(!!exportButton); |
| 604 |
| 605 // Should be disabled when 'model.extractable' is false. |
| 606 assertTrue(exportButton.hidden); |
| 607 |
| 608 var model = createSampleCertificateSubnode(); |
| 609 model.extractable = true; |
| 610 subentry.model = model; |
| 611 assertFalse(exportButton.hidden); |
| 612 |
| 583 var waitForActionEvent = actionEventToPromise(); | 613 var waitForActionEvent = actionEventToPromise(); |
| 584 | |
| 585 var exportButton = subentry.shadowRoot.querySelector('#export'); | |
| 586 MockInteractions.tap(exportButton); | 614 MockInteractions.tap(exportButton); |
| 587 return browserProxy.whenCalled('exportPersonalCertificate').then( | 615 return browserProxy.whenCalled('exportPersonalCertificate').then( |
| 588 function(id) { | 616 function(id) { |
| 589 assertEquals(subentry.model.id, id); | 617 assertEquals(subentry.model.id, id); |
| 590 | 618 |
| 591 // A promise firing once |settings.CertificateActionEvent| is | 619 // A promise firing once |settings.CertificateActionEvent| is |
| 592 // fired. | 620 // fired. |
| 593 return waitForActionEvent; | 621 return waitForActionEvent; |
| 594 }).then( | 622 }).then( |
| 595 function(event) { | 623 function(event) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 registerCaTrustEditDialogTests(); | 848 registerCaTrustEditDialogTests(); |
| 821 registerDeleteDialogTests(); | 849 registerDeleteDialogTests(); |
| 822 registerPasswordEncryptDialogTests(); | 850 registerPasswordEncryptDialogTests(); |
| 823 registerPasswordDecryptDialogTests(); | 851 registerPasswordDecryptDialogTests(); |
| 824 registerPageTests(); | 852 registerPageTests(); |
| 825 registerCertificateSubentryTests(); | 853 registerCertificateSubentryTests(); |
| 826 registerCertificateListTests(); | 854 registerCertificateListTests(); |
| 827 }, | 855 }, |
| 828 }; | 856 }; |
| 829 }); | 857 }); |
| OLD | NEW |