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

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

Issue 2341493003: MD Settings: Deflake attempt for CrSettingsPrivacyPageTest.PrivacyPage. (Closed)
Patch Set: Check for specific value. Created 4 years, 3 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
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
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 before
730 // listening for changes for the 'open' attribute. 720 // returning.
731 return new Promise(function(resolve, reject) { 721 return test_util.whenAttributeIs(dialog.$.dialog, 'open', true);
732 var observer = new MutationObserver(function(mutations) {
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 });
743 } 722 }
744 723
745 test('OpensDialog_DeleteConfirmation', function() { 724 test('OpensDialog_DeleteConfirmation', function() {
746 return testDialogOpensOnAction( 725 return testDialogOpensOnAction(
747 'settings-certificate-delete-confirmation-dialog', 726 'settings-certificate-delete-confirmation-dialog',
748 /** @type {!CertificateActionEventDetail} */ ({ 727 /** @type {!CertificateActionEventDetail} */ ({
749 action: CertificateAction.DELETE, 728 action: CertificateAction.DELETE,
750 subnode: createSampleCertificateSubnode(), 729 subnode: createSampleCertificateSubnode(),
751 certificateType: CertificateType.PERSONAL 730 certificateType: CertificateType.PERSONAL
752 })); 731 }));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 */ 802 */
824 function testImportForCertificateType( 803 function testImportForCertificateType(
825 certificateType, proxyMethodName, actionEventExpected) { 804 certificateType, proxyMethodName, actionEventExpected) {
826 element.certificateType = certificateType 805 element.certificateType = certificateType
827 Polymer.dom.flush(); 806 Polymer.dom.flush();
828 807
829 var importButton = element.$$('paper-button'); 808 var importButton = element.$$('paper-button');
830 assertTrue(!!importButton); 809 assertTrue(!!importButton);
831 810
832 var waitForActionEvent = actionEventExpected ? 811 var waitForActionEvent = actionEventExpected ?
833 eventToPromise(settings.CertificateActionEvent, element) : 812 test_util.eventToPromise(settings.CertificateActionEvent, element) :
834 Promise.resolve(null); 813 Promise.resolve(null);
835 814
836 MockInteractions.tap(importButton); 815 MockInteractions.tap(importButton);
837 return browserProxy.whenCalled(proxyMethodName).then(function() { 816 return browserProxy.whenCalled(proxyMethodName).then(function() {
838 return waitForActionEvent; 817 return waitForActionEvent;
839 }).then(function(event) { 818 }).then(function(event) {
840 if (actionEventExpected) { 819 if (actionEventExpected) {
841 assertEquals( 820 assertEquals(
842 CertificateAction.IMPORT, event.detail.action); 821 CertificateAction.IMPORT, event.detail.action);
843 assertEquals(certificateType, event.detail.certificateType); 822 assertEquals(certificateType, event.detail.certificateType);
(...skipping 25 matching lines...) Expand all
869 registerCaTrustEditDialogTests(); 848 registerCaTrustEditDialogTests();
870 registerDeleteDialogTests(); 849 registerDeleteDialogTests();
871 registerPasswordEncryptDialogTests(); 850 registerPasswordEncryptDialogTests();
872 registerPasswordDecryptDialogTests(); 851 registerPasswordDecryptDialogTests();
873 registerPageTests(); 852 registerPageTests();
874 registerCertificateSubentryTests(); 853 registerCertificateSubentryTests();
875 registerCertificateListTests(); 854 registerCertificateListTests();
876 }, 855 },
877 }; 856 };
878 }); 857 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/settings/about_page_tests.js ('k') | chrome/test/data/webui/settings/cr_settings_browsertest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698