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

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

Issue 1863733003: MD Settings: Certificate manager, implement importing CA certificate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove hasOwnProperty. 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
« no previous file with comments | « chrome/browser/resources/settings/certificate_manager_page/certificates_error_dialog.js ('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 *
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', 23 'importCaCertificate',
24 'importCaCertificateTrustSelected',
24 'importPersonalCertificate', 25 'importPersonalCertificate',
25 'importPersonalCertificatePasswordSelected', 26 'importPersonalCertificatePasswordSelected',
26 'importServerCertificate', 27 'importServerCertificate',
27 'refreshCertificates', 28 'refreshCertificates',
28 'viewCertificate', 29 'viewCertificate',
29 ]); 30 ]);
30 31
31 /** @private {!CaTrustInfo} */ 32 /** @private {!CaTrustInfo} */
32 this.caTrustInfo_ = {ssl: true, email: true, objSign: true}; 33 this.caTrustInfo_ = {ssl: true, email: true, objSign: true};
33 34
(...skipping 23 matching lines...) Expand all
57 return Promise.resolve(); 58 return Promise.resolve();
58 }, 59 },
59 60
60 /** @override */ 61 /** @override */
61 importCaCertificate: function() { 62 importCaCertificate: function() {
62 this.methodCalled('importCaCertificate'); 63 this.methodCalled('importCaCertificate');
63 return Promise.resolve('dummyName'); 64 return Promise.resolve('dummyName');
64 }, 65 },
65 66
66 /** @override */ 67 /** @override */
68 importCaCertificateTrustSelected: function(ssl, email, objSign) {
69 this.methodCalled('importCaCertificateTrustSelected', {
70 ssl: ssl, email: email, objSign: objSign,
71 });
72 return this.fulfillRequest_();
73 },
74
75 /** @override */
67 editCaCertificateTrust: function(id, ssl, email, objSign) { 76 editCaCertificateTrust: function(id, ssl, email, objSign) {
68 this.methodCalled('editCaCertificateTrust', { 77 this.methodCalled('editCaCertificateTrust', {
69 id: id, ssl: ssl, email: email, objSign: objSign, 78 id: id, ssl: ssl, email: email, objSign: objSign,
70 }); 79 });
71 return this.fulfillRequest_(); 80 return this.fulfillRequest_();
72 }, 81 },
73 82
74 /** 83 /**
75 * Forces some of the browser proxy methods to start returning errors. 84 * Forces some of the browser proxy methods to start returning errors.
76 */ 85 */
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 }); 194 });
186 } 195 }
187 196
188 function registerCaTrustEditDialogTests() { 197 function registerCaTrustEditDialogTests() {
189 /** @type {?SettingsCaTrustEditDialogElement} */ 198 /** @type {?SettingsCaTrustEditDialogElement} */
190 var dialog = null; 199 var dialog = null;
191 200
192 /** @type {?TestCertificatesBrowserProxy} */ 201 /** @type {?TestCertificatesBrowserProxy} */
193 var browserProxy = null; 202 var browserProxy = null;
194 203
195 /** @type {!CertificateSubnode} */
196 var model = createSampleCertificateSubnode();
197
198 /** @type {!CaTrustInfo} */ 204 /** @type {!CaTrustInfo} */
199 var caTrustInfo = { ssl: true, email: false, objSign: false }; 205 var caTrustInfo = { ssl: true, email: false, objSign: false };
200 206
201 suite('CaTrustEditDialogTests', function() { 207 suite('CaTrustEditDialogTests', function() {
202 setup(function() { 208 setup(function() {
203 browserProxy = new TestCertificatesBrowserProxy(); 209 browserProxy = new TestCertificatesBrowserProxy();
204 browserProxy.setCaCertificateTrust(caTrustInfo); 210 browserProxy.setCaCertificateTrust(caTrustInfo);
205 211
206 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; 212 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy;
207 PolymerTest.clearBody(); 213 PolymerTest.clearBody();
208 dialog = document.createElement('settings-ca-trust-edit-dialog'); 214 dialog = document.createElement('settings-ca-trust-edit-dialog');
209 dialog.model = model;
210 document.body.appendChild(dialog);
211 }); 215 });
212 216
213 teardown(function() { dialog.remove(); }); 217 teardown(function() { dialog.remove(); });
214 218
215 test('EditSuccess', function() { 219 test('EditSuccess', function() {
220 dialog.model = createSampleCertificateSubnode();
221 document.body.appendChild(dialog);
222
216 return browserProxy.whenCalled('getCaCertificateTrust').then( 223 return browserProxy.whenCalled('getCaCertificateTrust').then(
217 function(id) { 224 function(id) {
218 assertEquals(model.id, id); 225 assertEquals(dialog.model.id, id);
219 assertEquals(caTrustInfo.ssl, dialog.$.ssl.checked); 226 assertEquals(caTrustInfo.ssl, dialog.$.ssl.checked);
220 assertEquals(caTrustInfo.email, dialog.$.email.checked); 227 assertEquals(caTrustInfo.email, dialog.$.email.checked);
221 assertEquals(caTrustInfo.objSign, dialog.$.objSign.checked); 228 assertEquals(caTrustInfo.objSign, dialog.$.objSign.checked);
222 229
223 // Simulate toggling all checkboxes. 230 // Simulate toggling all checkboxes.
224 MockInteractions.tap(dialog.$.ssl); 231 MockInteractions.tap(dialog.$.ssl);
225 MockInteractions.tap(dialog.$.email); 232 MockInteractions.tap(dialog.$.email);
226 MockInteractions.tap(dialog.$.objSign); 233 MockInteractions.tap(dialog.$.objSign);
227 234
228 // Simulate clicking 'OK'. 235 // Simulate clicking 'OK'.
229 MockInteractions.tap(dialog.$.ok); 236 MockInteractions.tap(dialog.$.ok);
230 237
231 return browserProxy.whenCalled('editCaCertificateTrust'); 238 return browserProxy.whenCalled('editCaCertificateTrust');
232 }).then( 239 }).then(function(args) {
233 function(args) { 240 assertEquals(dialog.model.id, args.id);
234 assertEquals(model.id, args.id);
235 // Checking that the values sent to C++ are reflecting the 241 // Checking that the values sent to C++ are reflecting the
236 // changes made by the user (toggling all checkboxes). 242 // changes made by the user (toggling all checkboxes).
237 assertEquals(caTrustInfo.ssl, !args.ssl); 243 assertEquals(caTrustInfo.ssl, !args.ssl);
238 assertEquals(caTrustInfo.email, !args.email); 244 assertEquals(caTrustInfo.email, !args.email);
239 assertEquals(caTrustInfo.objSign, !args.objSign); 245 assertEquals(caTrustInfo.objSign, !args.objSign);
240 // Check that the dialog is closed. 246 // Check that the dialog is closed.
241 assertFalse(dialog.$.dialog.opened); 247 assertFalse(dialog.$.dialog.opened);
242 }); 248 });
243 }); 249 });
244 250
251 test('ImportSuccess', function() {
252 dialog.model = {name: 'Dummy certificate name'};
253 document.body.appendChild(dialog);
254
255 assertFalse(dialog.$.ssl.checked);
256 assertFalse(dialog.$.email.checked);
257 assertFalse(dialog.$.objSign.checked);
258
259 MockInteractions.tap(dialog.$.ssl);
260 MockInteractions.tap(dialog.$.email);
261
262 // Simulate clicking 'OK'.
263 MockInteractions.tap(dialog.$.ok);
264 return browserProxy.whenCalled('importCaCertificateTrustSelected').then(
265 function(args) {
266 assertTrue(args.ssl);
267 assertTrue(args.email);
268 assertFalse(args.objSign);
269 });
270 });
271
245 test('EditError', function() { 272 test('EditError', function() {
273 dialog.model = createSampleCertificateSubnode();
274 document.body.appendChild(dialog);
246 browserProxy.forceCertificatesError(); 275 browserProxy.forceCertificatesError();
276
247 var whenErrorEventFired = eventToPromise('certificates-error', dialog); 277 var whenErrorEventFired = eventToPromise('certificates-error', dialog);
248 278
249 return browserProxy.whenCalled('getCaCertificateTrust').then( 279 return browserProxy.whenCalled('getCaCertificateTrust').then(
250 function() { 280 function() {
251 MockInteractions.tap(dialog.$.ok); 281 MockInteractions.tap(dialog.$.ok);
252 return browserProxy.whenCalled('editCaCertificateTrust'); 282 return browserProxy.whenCalled('editCaCertificateTrust');
253 }).then( 283 }).then(
254 function() { 284 function() {
255 return whenErrorEventFired; 285 return whenErrorEventFired;
256 }); 286 });
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 Polymer.dom.flush(); 674 Polymer.dom.flush();
645 675
646 assertCertificateListLength(CertificateCategoryIndex.PERSONAL, 1); 676 assertCertificateListLength(CertificateCategoryIndex.PERSONAL, 1);
647 assertCertificateListLength(CertificateCategoryIndex.SERVER, 0); 677 assertCertificateListLength(CertificateCategoryIndex.SERVER, 0);
648 assertCertificateListLength(CertificateCategoryIndex.CA, 2); 678 assertCertificateListLength(CertificateCategoryIndex.CA, 2);
649 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); 679 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0);
650 }); 680 });
651 }); 681 });
652 682
653 /** 683 /**
654 * Dispatches a settings.CertificateActionEvent.
655 * @param {!settings.CertificateAction} action The type of action to
656 * simulate.
657 */
658 function dispatchCertificateActionEvent(action) {
659 page.fire(
660 settings.CertificateActionEvent,
661 /** @type {!CertificateActionEventDetail} */ ({
662 action: action,
663 subnode: createSampleCertificateSubnode(),
664 certificateType: settings.CertificateType.PERSONAL
665 }));
666 }
667
668 /**
669 * Tests that a dialog opens as a response to a 684 * Tests that a dialog opens as a response to a
670 * settings.CertificateActionEvent. 685 * settings.CertificateActionEvent.
671 * @param {string} dialogTagName The type of dialog to test. 686 * @param {string} dialogTagName The type of dialog to test.
672 * @param {!settings.CertificateAction} action The action that is supposed 687 * @param {CertificateActionEventDetail} eventDetail
673 * to trigger the dialog.
674 */ 688 */
675 function testDialogOpensOnAction(dialogTagName, action) { 689 function testDialogOpensOnAction(dialogTagName, eventDetail) {
676 assertFalse(!!page.shadowRoot.querySelector(dialogTagName)); 690 assertFalse(!!page.shadowRoot.querySelector(dialogTagName));
677 dispatchCertificateActionEvent(action); 691 page.fire(settings.CertificateActionEvent, eventDetail);
678 Polymer.dom.flush(); 692 Polymer.dom.flush();
679 assertTrue(!!page.shadowRoot.querySelector(dialogTagName)); 693 assertTrue(!!page.shadowRoot.querySelector(dialogTagName));
680 } 694 }
681 695
682 test('OpensDialog_DeleteConfirmation', function() { 696 test('OpensDialog_DeleteConfirmation', function() {
683 testDialogOpensOnAction( 697 testDialogOpensOnAction(
684 'settings-certificate-delete-confirmation-dialog', 698 'settings-certificate-delete-confirmation-dialog',
685 settings.CertificateAction.DELETE); 699 /** @type {!CertificateActionEventDetail} */ ({
700 action: settings.CertificateAction.DELETE,
701 subnode: createSampleCertificateSubnode(),
702 certificateType: settings.CertificateType.PERSONAL
703 }));
686 }); 704 });
687 705
688 test('OpensDialog_PasswordEncryption', function() { 706 test('OpensDialog_PasswordEncryption', function() {
689 testDialogOpensOnAction( 707 testDialogOpensOnAction(
690 'settings-certificate-password-encryption-dialog', 708 'settings-certificate-password-encryption-dialog',
691 settings.CertificateAction.EXPORT_PERSONAL); 709 /** @type {!CertificateActionEventDetail} */ ({
710 action: settings.CertificateAction.EXPORT_PERSONAL,
711 subnode: createSampleCertificateSubnode(),
712 certificateType: settings.CertificateType.PERSONAL
713 }));
692 }); 714 });
693 715
694 test('OpensDialog_PasswordDecryption', function() { 716 test('OpensDialog_PasswordDecryption', function() {
695 testDialogOpensOnAction( 717 testDialogOpensOnAction(
696 'settings-certificate-password-decryption-dialog', 718 'settings-certificate-password-decryption-dialog',
697 settings.CertificateAction.IMPORT); 719 /** @type {!CertificateActionEventDetail} */ ({
720 action: settings.CertificateAction.IMPORT,
721 subnode: createSampleCertificateSubnode(),
722 certificateType: settings.CertificateType.PERSONAL
723 }));
698 }); 724 });
699 725
700 test('OpensDialog_CaTrustEdit', function() { 726 test('OpensDialog_CaTrustEdit', function() {
701 testDialogOpensOnAction( 727 testDialogOpensOnAction(
702 'settings-ca-trust-edit-dialog', settings.CertificateAction.EDIT); 728 'settings-ca-trust-edit-dialog',
729 /** @type {!CertificateActionEventDetail} */ ({
730 action: settings.CertificateAction.EDIT,
731 subnode: createSampleCertificateSubnode(),
732 certificateType: settings.CertificateType.CA
733 }));
734 });
735
736 test('OpensDialog_CaTrustImport', function() {
737 testDialogOpensOnAction(
738 'settings-ca-trust-edit-dialog',
739 /** @type {!CertificateActionEventDetail} */ ({
740 action: settings.CertificateAction.IMPORT,
741 subnode: {name: 'Dummy Certificate Name', id: null},
742 certificateType: settings.CertificateType.CA
743 }));
703 }); 744 });
704 }); 745 });
705 } 746 }
706 747
707 function registerCertificateListTests() { 748 function registerCertificateListTests() {
708 /** @type {?SettingsCertificateListElement} */ 749 /** @type {?SettingsCertificateListElement} */
709 var element = null; 750 var element = null;
710 751
711 /** @type {?TestCertificatesBrowserProxy} */ 752 /** @type {?TestCertificatesBrowserProxy} */
712 var browserProxy = null; 753 var browserProxy = null;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 registerCaTrustEditDialogTests(); 820 registerCaTrustEditDialogTests();
780 registerDeleteDialogTests(); 821 registerDeleteDialogTests();
781 registerPasswordEncryptDialogTests(); 822 registerPasswordEncryptDialogTests();
782 registerPasswordDecryptDialogTests(); 823 registerPasswordDecryptDialogTests();
783 registerPageTests(); 824 registerPageTests();
784 registerCertificateSubentryTests(); 825 registerCertificateSubentryTests();
785 registerCertificateListTests(); 826 registerCertificateListTests();
786 }, 827 },
787 }; 828 };
788 }); 829 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/certificate_manager_page/certificates_error_dialog.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698