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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 registerCaTrustEditDialogTests(); | 848 registerCaTrustEditDialogTests(); |
849 registerDeleteDialogTests(); | 849 registerDeleteDialogTests(); |
850 registerPasswordEncryptDialogTests(); | 850 registerPasswordEncryptDialogTests(); |
851 registerPasswordDecryptDialogTests(); | 851 registerPasswordDecryptDialogTests(); |
852 registerPageTests(); | 852 registerPageTests(); |
853 registerCertificateSubentryTests(); | 853 registerCertificateSubentryTests(); |
854 registerCertificateListTests(); | 854 registerCertificateListTests(); |
855 }, | 855 }, |
856 }; | 856 }; |
857 }); | 857 }); |
OLD | NEW |