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

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

Issue 2180823004: Migrate <cr-dialog> from PaperDialogBehavior to native <dialog>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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 *
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 return browserProxy.whenCalled('editCaCertificateTrust'); 238 return browserProxy.whenCalled('editCaCertificateTrust');
239 }).then(function(args) { 239 }).then(function(args) {
240 assertEquals(dialog.model.id, args.id); 240 assertEquals(dialog.model.id, args.id);
241 // Checking that the values sent to C++ are reflecting the 241 // Checking that the values sent to C++ are reflecting the
242 // changes made by the user (toggling all checkboxes). 242 // changes made by the user (toggling all checkboxes).
243 assertEquals(caTrustInfo.ssl, !args.ssl); 243 assertEquals(caTrustInfo.ssl, !args.ssl);
244 assertEquals(caTrustInfo.email, !args.email); 244 assertEquals(caTrustInfo.email, !args.email);
245 assertEquals(caTrustInfo.objSign, !args.objSign); 245 assertEquals(caTrustInfo.objSign, !args.objSign);
246 // Check that the dialog is closed. 246 // Check that the dialog is closed.
247 assertFalse(dialog.$.dialog.opened); 247 assertFalse(dialog.$.dialog.open);
248 }); 248 });
249 }); 249 });
250 250
251 test('ImportSuccess', function() { 251 test('ImportSuccess', function() {
252 dialog.model = {name: 'Dummy certificate name'}; 252 dialog.model = {name: 'Dummy certificate name'};
253 document.body.appendChild(dialog); 253 document.body.appendChild(dialog);
254 254
255 assertFalse(dialog.$.ssl.checked); 255 assertFalse(dialog.$.ssl.checked);
256 assertFalse(dialog.$.email.checked); 256 assertFalse(dialog.$.email.checked);
257 assertFalse(dialog.$.objSign.checked); 257 assertFalse(dialog.$.objSign.checked);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = 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.open);
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));
320 320
321 // Simulate clicking 'OK'. 321 // Simulate clicking 'OK'.
322 MockInteractions.tap(dialog.$.ok); 322 MockInteractions.tap(dialog.$.ok);
323 323
324 return browserProxy.whenCalled('deleteCertificate').then( 324 return browserProxy.whenCalled('deleteCertificate').then(
325 function(id) { 325 function(id) {
326 assertEquals(model.id, id); 326 assertEquals(model.id, id);
327 // Check that the dialog is closed. 327 // Check that the dialog is closed.
328 assertFalse(dialog.$.dialog.opened); 328 assertFalse(dialog.$.dialog.open);
329 }); 329 });
330 }); 330 });
331 331
332 test('DeleteError', function() { 332 test('DeleteError', function() {
333 browserProxy.forceCertificatesError(); 333 browserProxy.forceCertificatesError();
334 var whenErrorEventFired = eventToPromise('certificates-error', dialog); 334 var whenErrorEventFired = eventToPromise('certificates-error', dialog);
335 335
336 // Simulate clicking 'OK'. 336 // Simulate clicking 'OK'.
337 MockInteractions.tap(dialog.$.ok); 337 MockInteractions.tap(dialog.$.ok);
338 return browserProxy.whenCalled('deleteCertificate').then( 338 return browserProxy.whenCalled('deleteCertificate').then(
(...skipping 30 matching lines...) Expand all
369 }); 369 });
370 370
371 teardown(function() { dialog.remove(); }); 371 teardown(function() { dialog.remove(); });
372 372
373 test('EncryptSuccess', function() { 373 test('EncryptSuccess', function() {
374 var passwordInputElements = 374 var passwordInputElements =
375 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input'); 375 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input');
376 var passwordInputElement = passwordInputElements[0]; 376 var passwordInputElement = passwordInputElements[0];
377 var confirmPasswordInputElement = passwordInputElements[1]; 377 var confirmPasswordInputElement = passwordInputElements[1];
378 378
379 assertTrue(dialog.$.dialog.opened); 379 assertTrue(dialog.$.dialog.open);
380 assertTrue(dialog.$.ok.disabled); 380 assertTrue(dialog.$.ok.disabled);
381 381
382 // Test that the 'OK' button is disabled when the password fields are 382 // Test that the 'OK' button is disabled when the password fields are
383 // empty (even though they both have the same value). 383 // empty (even though they both have the same value).
384 triggerInputEvent(passwordInputElement); 384 triggerInputEvent(passwordInputElement);
385 assertTrue(dialog.$.ok.disabled); 385 assertTrue(dialog.$.ok.disabled);
386 386
387 // Test that the 'OK' button is disabled until the two password fields 387 // Test that the 'OK' button is disabled until the two password fields
388 // match. 388 // match.
389 passwordInputElement.value = 'foopassword'; 389 passwordInputElement.value = 'foopassword';
390 triggerInputEvent(passwordInputElement); 390 triggerInputEvent(passwordInputElement);
391 assertTrue(dialog.$.ok.disabled); 391 assertTrue(dialog.$.ok.disabled);
392 confirmPasswordInputElement.value = passwordInputElement.value; 392 confirmPasswordInputElement.value = passwordInputElement.value;
393 triggerInputEvent(confirmPasswordInputElement); 393 triggerInputEvent(confirmPasswordInputElement);
394 assertFalse(dialog.$.ok.disabled); 394 assertFalse(dialog.$.ok.disabled);
395 395
396 // Simulate clicking 'OK'. 396 // Simulate clicking 'OK'.
397 MockInteractions.tap(dialog.$.ok); 397 MockInteractions.tap(dialog.$.ok);
398 398
399 return browserProxy.whenCalled(methodName).then(function(password) { 399 return browserProxy.whenCalled(methodName).then(function(password) {
400 assertEquals(passwordInputElement.value, password); 400 assertEquals(passwordInputElement.value, password);
401 // Check that the dialog is closed. 401 // Check that the dialog is closed.
402 assertFalse(dialog.$.dialog.opened); 402 assertFalse(dialog.$.dialog.open);
403 }); 403 });
404 }); 404 });
405 405
406 test('EncryptError', function() { 406 test('EncryptError', function() {
407 browserProxy.forceCertificatesError(); 407 browserProxy.forceCertificatesError();
408 408
409 var passwordInputElements = 409 var passwordInputElements =
410 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input'); 410 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input');
411 var passwordInputElement = passwordInputElements[0]; 411 var passwordInputElement = passwordInputElements[0];
412 passwordInputElement.value = 'foopassword'; 412 passwordInputElement.value = 'foopassword';
(...skipping 28 matching lines...) Expand all
441 dialog = document.createElement( 441 dialog = document.createElement(
442 'settings-certificate-password-decryption-dialog'); 442 'settings-certificate-password-decryption-dialog');
443 document.body.appendChild(dialog); 443 document.body.appendChild(dialog);
444 }); 444 });
445 445
446 teardown(function() { dialog.remove(); }); 446 teardown(function() { dialog.remove(); });
447 447
448 test('DecryptSuccess', function() { 448 test('DecryptSuccess', function() {
449 var passwordInputElement = 449 var passwordInputElement =
450 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); 450 Polymer.dom(dialog.$.dialog).querySelector('paper-input');
451 assertTrue(dialog.$.dialog.opened); 451 assertTrue(dialog.$.dialog.open);
452 assertTrue(dialog.$.ok.disabled); 452 assertTrue(dialog.$.ok.disabled);
453 453
454 // Test that the 'OK' button is disabled when the password field is 454 // Test that the 'OK' button is disabled when the password field is
455 // empty. 455 // empty.
456 triggerInputEvent(passwordInputElement); 456 triggerInputEvent(passwordInputElement);
457 assertTrue(dialog.$.ok.disabled); 457 assertTrue(dialog.$.ok.disabled);
458 passwordInputElement.value = 'foopassword'; 458 passwordInputElement.value = 'foopassword';
459 triggerInputEvent(passwordInputElement); 459 triggerInputEvent(passwordInputElement);
460 assertFalse(dialog.$.ok.disabled); 460 assertFalse(dialog.$.ok.disabled);
461 461
462 // Simulate clicking 'OK'. 462 // Simulate clicking 'OK'.
463 MockInteractions.tap(dialog.$.ok); 463 MockInteractions.tap(dialog.$.ok);
464 464
465 return browserProxy.whenCalled(methodName).then(function(password) { 465 return browserProxy.whenCalled(methodName).then(function(password) {
466 assertEquals(passwordInputElement.value, password); 466 assertEquals(passwordInputElement.value, password);
467 // Check that the dialog is closed. 467 // Check that the dialog is closed.
468 assertFalse(dialog.$.dialog.opened); 468 assertFalse(dialog.$.dialog.open);
469 }); 469 });
470 }); 470 });
471 471
472 test('DecryptError', function() { 472 test('DecryptError', function() {
473 browserProxy.forceCertificatesError(); 473 browserProxy.forceCertificatesError();
474 // Simulate entering some password. 474 // Simulate entering some password.
475 var passwordInputElement = 475 var passwordInputElement =
476 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); 476 Polymer.dom(dialog.$.dialog).querySelector('paper-input');
477 passwordInputElement.value = 'foopassword'; 477 passwordInputElement.value = 'foopassword';
478 triggerInputEvent(passwordInputElement); 478 triggerInputEvent(passwordInputElement);
(...skipping 14 matching lines...) Expand all
493 var browserProxy = null; 493 var browserProxy = null;
494 494
495 /** 495 /**
496 * @return {!Promise} A promise firing once a 496 * @return {!Promise} A promise firing once a
497 * |settings.CertificateActionEvent| fires. 497 * |settings.CertificateActionEvent| fires.
498 */ 498 */
499 var actionEventToPromise = function() { 499 var actionEventToPromise = function() {
500 return eventToPromise(settings.CertificateActionEvent, subentry); 500 return eventToPromise(settings.CertificateActionEvent, subentry);
501 }; 501 };
502 502
503 suite('CertificateManagerPageTests', function() { 503 suite('CertificateSubentryTests', 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 = 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.
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 assertCertificateListLength(CertificateCategoryIndex.CA, 2); 706 assertCertificateListLength(CertificateCategoryIndex.CA, 2);
707 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0); 707 assertCertificateListLength(CertificateCategoryIndex.OTHER, 0);
708 }); 708 });
709 }); 709 });
710 710
711 /** 711 /**
712 * Tests that a dialog opens as a response to a 712 * Tests that a dialog opens as a response to a
713 * settings.CertificateActionEvent. 713 * settings.CertificateActionEvent.
714 * @param {string} dialogTagName The type of dialog to test. 714 * @param {string} dialogTagName The type of dialog to test.
715 * @param {CertificateActionEventDetail} eventDetail 715 * @param {CertificateActionEventDetail} eventDetail
716 * @return {!Promise}
716 */ 717 */
717 function testDialogOpensOnAction(dialogTagName, eventDetail) { 718 function testDialogOpensOnAction(dialogTagName, eventDetail) {
718 assertFalse(!!page.shadowRoot.querySelector(dialogTagName)); 719 assertFalse(!!page.shadowRoot.querySelector(dialogTagName));
719 page.fire(settings.CertificateActionEvent, eventDetail); 720 page.fire(settings.CertificateActionEvent, eventDetail);
720 Polymer.dom.flush(); 721 Polymer.dom.flush();
721 assertTrue(!!page.shadowRoot.querySelector(dialogTagName)); 722 var dialog = page.shadowRoot.querySelector(dialogTagName);
723 assertTrue(!!dialog);
724
725 if (dialog.$.dialog.open)
726 return Promise.resolve();
727
728 // Some dialogs are opened after some async operation to fetch initial
729 // data. Ensure that the underlying cr-dialog is actually opened by
730 // listening for changes for the 'open' attribute.
731 return new Promise(function(resolve, reject) {
732 var observer = new MutationObserver(function(mutations) {
Dan Beam 2016/07/28 19:09:35 mind == blown
dpapad 2016/07/28 19:29:31 Ack!
733 assertEquals(1, mutations.length);
734 assertEquals('attributes', mutations[0].type);
735 assertEquals('open', mutations[0].attributeName);
736 observer.disconnect();
737 resolve();
738 });
739 observer.observe(
740 dialog.$.dialog,
741 {attributes: true, childList: false, characterData: false});
742 });
722 } 743 }
723 744
724 test('OpensDialog_DeleteConfirmation', function() { 745 test('OpensDialog_DeleteConfirmation', function() {
725 testDialogOpensOnAction( 746 return testDialogOpensOnAction(
726 'settings-certificate-delete-confirmation-dialog', 747 'settings-certificate-delete-confirmation-dialog',
727 /** @type {!CertificateActionEventDetail} */ ({ 748 /** @type {!CertificateActionEventDetail} */ ({
728 action: CertificateAction.DELETE, 749 action: CertificateAction.DELETE,
729 subnode: createSampleCertificateSubnode(), 750 subnode: createSampleCertificateSubnode(),
730 certificateType: CertificateType.PERSONAL 751 certificateType: CertificateType.PERSONAL
731 })); 752 }));
732 }); 753 });
733 754
734 test('OpensDialog_PasswordEncryption', function() { 755 test('OpensDialog_PasswordEncryption', function() {
735 testDialogOpensOnAction( 756 return testDialogOpensOnAction(
736 'settings-certificate-password-encryption-dialog', 757 'settings-certificate-password-encryption-dialog',
737 /** @type {!CertificateActionEventDetail} */ ({ 758 /** @type {!CertificateActionEventDetail} */ ({
738 action: CertificateAction.EXPORT_PERSONAL, 759 action: CertificateAction.EXPORT_PERSONAL,
739 subnode: createSampleCertificateSubnode(), 760 subnode: createSampleCertificateSubnode(),
740 certificateType: CertificateType.PERSONAL 761 certificateType: CertificateType.PERSONAL
741 })); 762 }));
742 }); 763 });
743 764
744 test('OpensDialog_PasswordDecryption', function() { 765 test('OpensDialog_PasswordDecryption', function() {
745 testDialogOpensOnAction( 766 return testDialogOpensOnAction(
746 'settings-certificate-password-decryption-dialog', 767 'settings-certificate-password-decryption-dialog',
747 /** @type {!CertificateActionEventDetail} */ ({ 768 /** @type {!CertificateActionEventDetail} */ ({
748 action: CertificateAction.IMPORT, 769 action: CertificateAction.IMPORT,
749 subnode: createSampleCertificateSubnode(), 770 subnode: createSampleCertificateSubnode(),
750 certificateType: CertificateType.PERSONAL 771 certificateType: CertificateType.PERSONAL
751 })); 772 }));
752 }); 773 });
753 774
754 test('OpensDialog_CaTrustEdit', function() { 775 test('OpensDialog_CaTrustEdit', function() {
755 testDialogOpensOnAction( 776 return testDialogOpensOnAction(
756 'settings-ca-trust-edit-dialog', 777 'settings-ca-trust-edit-dialog',
757 /** @type {!CertificateActionEventDetail} */ ({ 778 /** @type {!CertificateActionEventDetail} */ ({
758 action: CertificateAction.EDIT, 779 action: CertificateAction.EDIT,
759 subnode: createSampleCertificateSubnode(), 780 subnode: createSampleCertificateSubnode(),
760 certificateType: CertificateType.CA 781 certificateType: CertificateType.CA
761 })); 782 }));
762 }); 783 });
763 784
764 test('OpensDialog_CaTrustImport', function() { 785 test('OpensDialog_CaTrustImport', function() {
765 testDialogOpensOnAction( 786 return testDialogOpensOnAction(
766 'settings-ca-trust-edit-dialog', 787 'settings-ca-trust-edit-dialog',
767 /** @type {!CertificateActionEventDetail} */ ({ 788 /** @type {!CertificateActionEventDetail} */ ({
768 action: CertificateAction.IMPORT, 789 action: CertificateAction.IMPORT,
769 subnode: {name: 'Dummy Certificate Name', id: null}, 790 subnode: {name: 'Dummy Certificate Name', id: null},
770 certificateType: CertificateType.CA 791 certificateType: CertificateType.CA
771 })); 792 }));
772 }); 793 });
773 }); 794 });
774 } 795 }
775 796
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 registerCaTrustEditDialogTests(); 869 registerCaTrustEditDialogTests();
849 registerDeleteDialogTests(); 870 registerDeleteDialogTests();
850 registerPasswordEncryptDialogTests(); 871 registerPasswordEncryptDialogTests();
851 registerPasswordDecryptDialogTests(); 872 registerPasswordDecryptDialogTests();
852 registerPageTests(); 873 registerPageTests();
853 registerCertificateSubentryTests(); 874 registerCertificateSubentryTests();
854 registerCertificateListTests(); 875 registerCertificateListTests();
855 }, 876 },
856 }; 877 };
857 }); 878 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698