| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 * Triggers an 'input' event on the given text input field (which triggers | 175 * Triggers an 'input' event on the given text input field (which triggers |
| 176 * validation to occur for password fields being tested in this file). | 176 * validation to occur for password fields being tested in this file). |
| 177 * @param {!PaperInputElement} element | 177 * @param {!PaperInputElement} element |
| 178 */ | 178 */ |
| 179 function triggerInputEvent(element) { | 179 function triggerInputEvent(element) { |
| 180 // The actual key code is irrelevant for tests. | 180 // The actual key code is irrelevant for tests. |
| 181 var kSpaceBar = 32; | 181 var kSpaceBar = 32; |
| 182 MockInteractions.keyEventOn(element, 'input', kSpaceBar); | 182 MockInteractions.keyEventOn(element, 'input', kSpaceBar); |
| 183 } | 183 } |
| 184 | 184 |
| 185 /** | |
| 186 * Converts an event occurrence to a promise. | |
| 187 * @param {string} eventType | |
| 188 * @param {!HTMLElement} target | |
| 189 * @return {!Promise} A promise firing once the event occurs. | |
| 190 */ | |
| 191 function eventToPromise(eventType, target) { | |
| 192 return new Promise(function(resolve, reject) { | |
| 193 target.addEventListener(eventType, resolve); | |
| 194 }); | |
| 195 } | |
| 196 | |
| 197 function registerCaTrustEditDialogTests() { | 185 function registerCaTrustEditDialogTests() { |
| 198 /** @type {?SettingsCaTrustEditDialogElement} */ | 186 /** @type {?SettingsCaTrustEditDialogElement} */ |
| 199 var dialog = null; | 187 var dialog = null; |
| 200 | 188 |
| 201 /** @type {?TestCertificatesBrowserProxy} */ | 189 /** @type {?TestCertificatesBrowserProxy} */ |
| 202 var browserProxy = null; | 190 var browserProxy = null; |
| 203 | 191 |
| 204 /** @type {!CaTrustInfo} */ | 192 /** @type {!CaTrustInfo} */ |
| 205 var caTrustInfo = { ssl: true, email: false, objSign: false }; | 193 var caTrustInfo = { ssl: true, email: false, objSign: false }; |
| 206 | 194 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 assertTrue(args.email); | 255 assertTrue(args.email); |
| 268 assertFalse(args.objSign); | 256 assertFalse(args.objSign); |
| 269 }); | 257 }); |
| 270 }); | 258 }); |
| 271 | 259 |
| 272 test('EditError', function() { | 260 test('EditError', function() { |
| 273 dialog.model = createSampleCertificateSubnode(); | 261 dialog.model = createSampleCertificateSubnode(); |
| 274 document.body.appendChild(dialog); | 262 document.body.appendChild(dialog); |
| 275 browserProxy.forceCertificatesError(); | 263 browserProxy.forceCertificatesError(); |
| 276 | 264 |
| 277 var whenErrorEventFired = eventToPromise('certificates-error', dialog); | 265 var whenErrorEventFired = |
| 266 test_util.eventToPromise('certificates-error', dialog); |
| 278 | 267 |
| 279 return browserProxy.whenCalled('getCaCertificateTrust').then( | 268 return browserProxy.whenCalled('getCaCertificateTrust').then( |
| 280 function() { | 269 function() { |
| 281 MockInteractions.tap(dialog.$.ok); | 270 MockInteractions.tap(dialog.$.ok); |
| 282 return browserProxy.whenCalled('editCaCertificateTrust'); | 271 return browserProxy.whenCalled('editCaCertificateTrust'); |
| 283 }).then( | 272 }).then( |
| 284 function() { | 273 function() { |
| 285 return whenErrorEventFired; | 274 return whenErrorEventFired; |
| 286 }); | 275 }); |
| 287 }); | 276 }); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 return browserProxy.whenCalled('deleteCertificate').then( | 313 return browserProxy.whenCalled('deleteCertificate').then( |
| 325 function(id) { | 314 function(id) { |
| 326 assertEquals(model.id, id); | 315 assertEquals(model.id, id); |
| 327 // Check that the dialog is closed. | 316 // Check that the dialog is closed. |
| 328 assertFalse(dialog.$.dialog.open); | 317 assertFalse(dialog.$.dialog.open); |
| 329 }); | 318 }); |
| 330 }); | 319 }); |
| 331 | 320 |
| 332 test('DeleteError', function() { | 321 test('DeleteError', function() { |
| 333 browserProxy.forceCertificatesError(); | 322 browserProxy.forceCertificatesError(); |
| 334 var whenErrorEventFired = eventToPromise('certificates-error', dialog); | 323 var whenErrorEventFired = |
| 324 test_util.eventToPromise('certificates-error', dialog); |
| 335 | 325 |
| 336 // Simulate clicking 'OK'. | 326 // Simulate clicking 'OK'. |
| 337 MockInteractions.tap(dialog.$.ok); | 327 MockInteractions.tap(dialog.$.ok); |
| 338 return browserProxy.whenCalled('deleteCertificate').then( | 328 return browserProxy.whenCalled('deleteCertificate').then( |
| 339 function(id) { | 329 function(id) { |
| 340 assertEquals(model.id, id); | 330 assertEquals(model.id, id); |
| 341 // Ensure that the 'error' event was fired. | 331 // Ensure that the 'error' event was fired. |
| 342 return whenErrorEventFired; | 332 return whenErrorEventFired; |
| 343 }); | 333 }); |
| 344 }); | 334 }); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 browserProxy.forceCertificatesError(); | 397 browserProxy.forceCertificatesError(); |
| 408 | 398 |
| 409 var passwordInputElements = | 399 var passwordInputElements = |
| 410 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input'); | 400 Polymer.dom(dialog.$.dialog).querySelectorAll('paper-input'); |
| 411 var passwordInputElement = passwordInputElements[0]; | 401 var passwordInputElement = passwordInputElements[0]; |
| 412 passwordInputElement.value = 'foopassword'; | 402 passwordInputElement.value = 'foopassword'; |
| 413 var confirmPasswordInputElement = passwordInputElements[1]; | 403 var confirmPasswordInputElement = passwordInputElements[1]; |
| 414 confirmPasswordInputElement.value = passwordInputElement.value; | 404 confirmPasswordInputElement.value = passwordInputElement.value; |
| 415 triggerInputEvent(passwordInputElement); | 405 triggerInputEvent(passwordInputElement); |
| 416 | 406 |
| 417 var whenErrorEventFired = eventToPromise('certificates-error', dialog); | 407 var whenErrorEventFired = |
| 408 test_util.eventToPromise('certificates-error', dialog); |
| 418 MockInteractions.tap(dialog.$.ok); | 409 MockInteractions.tap(dialog.$.ok); |
| 419 | 410 |
| 420 return browserProxy.whenCalled(methodName).then(function() { | 411 return browserProxy.whenCalled(methodName).then(function() { |
| 421 return whenErrorEventFired; | 412 return whenErrorEventFired; |
| 422 }); | 413 }); |
| 423 }); | 414 }); |
| 424 }); | 415 }); |
| 425 } | 416 } |
| 426 | 417 |
| 427 function registerPasswordDecryptDialogTests() { | 418 function registerPasswordDecryptDialogTests() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 }); | 461 }); |
| 471 | 462 |
| 472 test('DecryptError', function() { | 463 test('DecryptError', function() { |
| 473 browserProxy.forceCertificatesError(); | 464 browserProxy.forceCertificatesError(); |
| 474 // Simulate entering some password. | 465 // Simulate entering some password. |
| 475 var passwordInputElement = | 466 var passwordInputElement = |
| 476 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); | 467 Polymer.dom(dialog.$.dialog).querySelector('paper-input'); |
| 477 passwordInputElement.value = 'foopassword'; | 468 passwordInputElement.value = 'foopassword'; |
| 478 triggerInputEvent(passwordInputElement); | 469 triggerInputEvent(passwordInputElement); |
| 479 | 470 |
| 480 var whenErrorEventFired = eventToPromise('certificates-error', dialog); | 471 var whenErrorEventFired = |
| 472 test_util.eventToPromise('certificates-error', dialog); |
| 481 MockInteractions.tap(dialog.$.ok); | 473 MockInteractions.tap(dialog.$.ok); |
| 482 return browserProxy.whenCalled(methodName).then(function() { | 474 return browserProxy.whenCalled(methodName).then(function() { |
| 483 return whenErrorEventFired; | 475 return whenErrorEventFired; |
| 484 }); | 476 }); |
| 485 }); | 477 }); |
| 486 }); | 478 }); |
| 487 } | 479 } |
| 488 | 480 |
| 489 function registerCertificateSubentryTests() { | 481 function registerCertificateSubentryTests() { |
| 490 var subentry = null; | 482 var subentry = null; |
| 491 | 483 |
| 492 /** @type {?TestCertificatesBrowserProxy} */ | 484 /** @type {?TestCertificatesBrowserProxy} */ |
| 493 var browserProxy = null; | 485 var browserProxy = null; |
| 494 | 486 |
| 495 /** | 487 /** |
| 496 * @return {!Promise} A promise firing once a | 488 * @return {!Promise} A promise firing once a |
| 497 * |settings.CertificateActionEvent| fires. | 489 * |settings.CertificateActionEvent| fires. |
| 498 */ | 490 */ |
| 499 var actionEventToPromise = function() { | 491 var actionEventToPromise = function() { |
| 500 return eventToPromise(settings.CertificateActionEvent, subentry); | 492 return test_util.eventToPromise( |
| 493 settings.CertificateActionEvent, subentry); |
| 501 }; | 494 }; |
| 502 | 495 |
| 503 suite('CertificateSubentryTests', function() { | 496 suite('CertificateSubentryTests', function() { |
| 504 setup(function() { | 497 setup(function() { |
| 505 browserProxy = new TestCertificatesBrowserProxy(); | 498 browserProxy = new TestCertificatesBrowserProxy(); |
| 506 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; | 499 settings.CertificatesBrowserProxyImpl.instance_ = browserProxy; |
| 507 PolymerTest.clearBody(); | 500 PolymerTest.clearBody(); |
| 508 subentry = document.createElement('settings-certificate-subentry'); | 501 subentry = document.createElement('settings-certificate-subentry'); |
| 509 subentry.model = createSampleCertificateSubnode(); | 502 subentry.model = createSampleCertificateSubnode(); |
| 510 subentry.certificateType = CertificateType.PERSONAL; | 503 subentry.certificateType = CertificateType.PERSONAL; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 * @param {CertificateActionEventDetail} eventDetail | 708 * @param {CertificateActionEventDetail} eventDetail |
| 716 * @return {!Promise} | 709 * @return {!Promise} |
| 717 */ | 710 */ |
| 718 function testDialogOpensOnAction(dialogTagName, eventDetail) { | 711 function testDialogOpensOnAction(dialogTagName, eventDetail) { |
| 719 assertFalse(!!page.shadowRoot.querySelector(dialogTagName)); | 712 assertFalse(!!page.shadowRoot.querySelector(dialogTagName)); |
| 720 page.fire(settings.CertificateActionEvent, eventDetail); | 713 page.fire(settings.CertificateActionEvent, eventDetail); |
| 721 Polymer.dom.flush(); | 714 Polymer.dom.flush(); |
| 722 var dialog = page.shadowRoot.querySelector(dialogTagName); | 715 var dialog = page.shadowRoot.querySelector(dialogTagName); |
| 723 assertTrue(!!dialog); | 716 assertTrue(!!dialog); |
| 724 | 717 |
| 725 if (dialog.$.dialog.open) | |
| 726 return Promise.resolve(); | |
| 727 | |
| 728 // Some dialogs are opened after some async operation to fetch initial | 718 // Some dialogs are opened after some async operation to fetch initial |
| 729 // data. Ensure that the underlying cr-dialog is actually opened by | 719 // data. Ensure that the underlying cr-dialog is actually opened by |
| 730 // listening for changes for the 'open' attribute. | 720 // listening for changes for the 'open' attribute. |
| 731 return new Promise(function(resolve, reject) { | 721 return dialog.$.dialog.open ? |
| 732 var observer = new MutationObserver(function(mutations) { | 722 Promise.resolve() : |
| 733 assertEquals(1, mutations.length); | 723 test_util.whenAttributeChanges(dialog.$.dialog, 'open'); |
| 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 }); | |
| 743 } | 724 } |
| 744 | 725 |
| 745 test('OpensDialog_DeleteConfirmation', function() { | 726 test('OpensDialog_DeleteConfirmation', function() { |
| 746 return testDialogOpensOnAction( | 727 return testDialogOpensOnAction( |
| 747 'settings-certificate-delete-confirmation-dialog', | 728 'settings-certificate-delete-confirmation-dialog', |
| 748 /** @type {!CertificateActionEventDetail} */ ({ | 729 /** @type {!CertificateActionEventDetail} */ ({ |
| 749 action: CertificateAction.DELETE, | 730 action: CertificateAction.DELETE, |
| 750 subnode: createSampleCertificateSubnode(), | 731 subnode: createSampleCertificateSubnode(), |
| 751 certificateType: CertificateType.PERSONAL | 732 certificateType: CertificateType.PERSONAL |
| 752 })); | 733 })); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 */ | 804 */ |
| 824 function testImportForCertificateType( | 805 function testImportForCertificateType( |
| 825 certificateType, proxyMethodName, actionEventExpected) { | 806 certificateType, proxyMethodName, actionEventExpected) { |
| 826 element.certificateType = certificateType | 807 element.certificateType = certificateType |
| 827 Polymer.dom.flush(); | 808 Polymer.dom.flush(); |
| 828 | 809 |
| 829 var importButton = element.$$('paper-button'); | 810 var importButton = element.$$('paper-button'); |
| 830 assertTrue(!!importButton); | 811 assertTrue(!!importButton); |
| 831 | 812 |
| 832 var waitForActionEvent = actionEventExpected ? | 813 var waitForActionEvent = actionEventExpected ? |
| 833 eventToPromise(settings.CertificateActionEvent, element) : | 814 test_util.eventToPromise(settings.CertificateActionEvent, element) : |
| 834 Promise.resolve(null); | 815 Promise.resolve(null); |
| 835 | 816 |
| 836 MockInteractions.tap(importButton); | 817 MockInteractions.tap(importButton); |
| 837 return browserProxy.whenCalled(proxyMethodName).then(function() { | 818 return browserProxy.whenCalled(proxyMethodName).then(function() { |
| 838 return waitForActionEvent; | 819 return waitForActionEvent; |
| 839 }).then(function(event) { | 820 }).then(function(event) { |
| 840 if (actionEventExpected) { | 821 if (actionEventExpected) { |
| 841 assertEquals( | 822 assertEquals( |
| 842 CertificateAction.IMPORT, event.detail.action); | 823 CertificateAction.IMPORT, event.detail.action); |
| 843 assertEquals(certificateType, event.detail.certificateType); | 824 assertEquals(certificateType, event.detail.certificateType); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 869 registerCaTrustEditDialogTests(); | 850 registerCaTrustEditDialogTests(); |
| 870 registerDeleteDialogTests(); | 851 registerDeleteDialogTests(); |
| 871 registerPasswordEncryptDialogTests(); | 852 registerPasswordEncryptDialogTests(); |
| 872 registerPasswordDecryptDialogTests(); | 853 registerPasswordDecryptDialogTests(); |
| 873 registerPageTests(); | 854 registerPageTests(); |
| 874 registerCertificateSubentryTests(); | 855 registerCertificateSubentryTests(); |
| 875 registerCertificateListTests(); | 856 registerCertificateListTests(); |
| 876 }, | 857 }, |
| 877 }; | 858 }; |
| 878 }); | 859 }); |
| OLD | NEW |