OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 var ROOT_PATH = '../../../../../'; | 5 var ROOT_PATH = '../../../../../'; |
6 | 6 |
7 /** | 7 /** |
8 * Test fixture for print preview WebUI testing. | 8 * Test fixture for print preview WebUI testing. |
9 * @constructor | 9 * @constructor |
10 * @extends {testing.Test} | 10 * @extends {testing.Test} |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 }; | 289 }; |
290 } | 290 } |
291 | 291 |
292 function isPrintAsImageEnabled() { | 292 function isPrintAsImageEnabled() { |
293 // Should be enabled by default on non Windows/Mac | 293 // Should be enabled by default on non Windows/Mac |
294 return (!cr.isWindows && !cr.isMac && | 294 return (!cr.isWindows && !cr.isMac && |
295 loadTimeData.getBoolean('printPdfAsImageEnabled')); | 295 loadTimeData.getBoolean('printPdfAsImageEnabled')); |
296 } | 296 } |
297 | 297 |
298 | 298 |
299 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode', | |
300 function() { | |
301 if (!cr.isChromeOS) | |
302 this.initialSettings_.isInAppKioskMode_ = true; | |
303 | |
304 this.setInitialSettings(); | |
305 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
306 function() { | |
307 if (cr.isChromeOS) | |
308 assertEquals(null, $('system-dialog-link')); | |
309 else | |
310 checkElementDisplayed($('system-dialog-link'), false); | |
311 testDone(); | |
312 }); | |
313 }); | |
314 | |
315 // Test that disabled settings hide the disabled sections. | |
316 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() { | |
317 this.createPrintPreview(); | |
318 checkSectionVisible($('layout-settings'), false); | |
319 checkSectionVisible($('color-settings'), false); | |
320 checkSectionVisible($('copies-settings'), false); | |
321 | |
322 this.setInitialSettings(); | |
323 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
324 function() { | |
325 this.setLocalDestinations(); | |
326 var device = getCddTemplate("FooDevice"); | |
327 device.capabilities.printer.color = { | |
328 "option": [ | |
329 {"is_default": true, "type": "STANDARD_COLOR"} | |
330 ] | |
331 }; | |
332 delete device.capabilities.printer.copies; | |
333 this.setCapabilities(device); | |
334 | |
335 checkSectionVisible($('layout-settings'), true); | |
336 checkSectionVisible($('color-settings'), false); | |
337 checkSectionVisible($('copies-settings'), false); | |
338 | |
339 this.waitForAnimationToEnd('other-options-collapsible'); | |
340 }.bind(this)); | |
341 }); | |
342 | |
343 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the | |
344 // fit to page option. | |
345 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() { | |
346 // Add PDF printer. | |
347 this.initialSettings_.isDocumentModifiable_ = false; | |
348 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF'; | |
349 this.setInitialSettings(); | |
350 | |
351 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
352 function() { | |
353 var device = { | |
354 printerId: 'Save as PDF', | |
355 capabilities: { | |
356 version: '1.0', | |
357 printer: { | |
358 page_orientation: { | |
359 option: [ | |
360 {type: 'AUTO', is_default: true}, | |
361 {type: 'PORTRAIT'}, | |
362 {type: 'LANDSCAPE'} | |
363 ] | |
364 }, | |
365 color: { | |
366 option: [ | |
367 {type: 'STANDARD_COLOR', is_default: true} | |
368 ] | |
369 }, | |
370 media_size: { | |
371 option: [ | |
372 { name: 'NA_LETTER', | |
373 width_microns: 0, | |
374 height_microns: 0, | |
375 is_default: true | |
376 } | |
377 ] | |
378 } | |
379 } | |
380 } | |
381 }; | |
382 this.setCapabilities(device); | |
383 | |
384 var otherOptions = $('other-options-settings'); | |
385 // If rasterization is an option, other options should be visible. If | |
386 // not, there should be no available other options. | |
387 checkSectionVisible(otherOptions, isPrintAsImageEnabled()); | |
388 if (isPrintAsImageEnabled()) { | |
389 checkElementDisplayed( | |
390 otherOptions.querySelector('#fit-to-page-container'), false); | |
391 checkElementDisplayed( | |
392 otherOptions.querySelector('#rasterize-container'), true); | |
393 } | |
394 checkSectionVisible($('media-size-settings'), false); | |
395 checkSectionVisible($('scaling-settings'), false); | |
396 | |
397 testDone(); | |
398 }.bind(this)); | |
399 }); | |
400 | |
401 // When the source is 'HTML', we always hide the fit to page option and show | |
402 // media size option. | |
403 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() { | |
404 this.setInitialSettings(); | |
405 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
406 function() { | |
407 this.setLocalDestinations(); | |
408 this.setCapabilities(getCddTemplate("FooDevice")); | |
409 | |
410 var otherOptions = $('other-options-settings'); | |
411 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); | |
412 var rasterize; | |
413 if (isPrintAsImageEnabled()) | |
414 rasterize = otherOptions.querySelector('#rasterize-container'); | |
415 var mediaSize = $('media-size-settings'); | |
416 var scalingSettings = $('scaling-settings'); | |
417 | |
418 // Check that options are collapsed (section is visible, because duplex | |
419 // is available). | |
420 checkSectionVisible(otherOptions, true); | |
421 checkElementDisplayed(fitToPage, false); | |
422 if (isPrintAsImageEnabled()) | |
423 checkElementDisplayed(rasterize, false); | |
424 checkSectionVisible(mediaSize, false); | |
425 checkSectionVisible(scalingSettings, false); | |
426 | |
427 this.expandMoreSettings(); | |
428 | |
429 checkElementDisplayed(fitToPage, false); | |
430 if (isPrintAsImageEnabled()) | |
431 checkElementDisplayed(rasterize, false); | |
432 checkSectionVisible(mediaSize, true); | |
433 checkSectionVisible(scalingSettings, true); | |
434 | |
435 this.waitForAnimationToEnd('more-settings'); | |
436 }.bind(this)); | |
437 }); | |
438 | |
439 // When the source is "PDF", depending on the selected destination printer, we | |
440 // show/hide the fit to page option and hide media size selection. | |
441 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() { | |
442 this.initialSettings_.isDocumentModifiable_ = false; | |
443 this.setInitialSettings(); | |
444 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
445 function() { | |
446 this.setLocalDestinations(); | |
447 this.setCapabilities(getCddTemplate("FooDevice")); | |
448 | |
449 var otherOptions = $('other-options-settings'); | |
450 var scalingSettings = $('scaling-settings'); | |
451 var fitToPageContainer = | |
452 otherOptions.querySelector('#fit-to-page-container'); | |
453 var rasterizeContainer; | |
454 if (isPrintAsImageEnabled()) { | |
455 rasterizeContainer = | |
456 otherOptions.querySelector('#rasterize-container'); | |
457 } | |
458 | |
459 checkSectionVisible(otherOptions, true); | |
460 checkElementDisplayed(fitToPageContainer, true); | |
461 if (isPrintAsImageEnabled()) | |
462 checkElementDisplayed(rasterizeContainer, false); | |
463 expectTrue( | |
464 fitToPageContainer.querySelector('.checkbox').checked); | |
465 this.expandMoreSettings(); | |
466 if (isPrintAsImageEnabled()) { | |
467 checkElementDisplayed(rasterizeContainer, true); | |
468 expectFalse( | |
469 rasterizeContainer.querySelector('.checkbox').checked); | |
470 } | |
471 checkSectionVisible($('media-size-settings'), true); | |
472 checkSectionVisible(scalingSettings, true); | |
473 | |
474 this.waitForAnimationToEnd('other-options-collapsible'); | |
475 }.bind(this)); | |
476 }); | |
477 | |
478 // When the source is "PDF", depending on the selected destination printer, we | |
479 // show/hide the fit to page option and hide media size selection. | |
480 TEST_F('PrintPreviewWebUITest', 'ScalingUnchecksFitToPage', function() { | |
481 this.initialSettings_.isDocumentModifiable_ = false; | |
482 this.setInitialSettings(); | |
483 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
484 function() { | |
485 this.setLocalDestinations(); | |
486 this.setCapabilities(getCddTemplate("FooDevice")); | |
487 | |
488 var otherOptions = $('other-options-settings'); | |
489 var scalingSettings = $('scaling-settings'); | |
490 | |
491 checkSectionVisible(otherOptions, true); | |
492 var fitToPageContainer = | |
493 otherOptions.querySelector('#fit-to-page-container'); | |
494 checkElementDisplayed(fitToPageContainer, true); | |
495 expectTrue( | |
496 fitToPageContainer.querySelector('.checkbox').checked); | |
497 this.expandMoreSettings(); | |
498 checkSectionVisible($('media-size-settings'), true); | |
499 checkSectionVisible(scalingSettings, true); | |
500 | |
501 // Change scaling input | |
502 var scalingInput = scalingSettings.querySelector('.user-value'); | |
503 expectEquals('100', scalingInput.value); | |
504 scalingInput.stepUp(5); | |
505 expectEquals('105', scalingInput.value); | |
506 | |
507 // Trigger the event | |
508 var enterEvent = document.createEvent('Event'); | |
509 enterEvent.initEvent('keydown'); | |
510 enterEvent.keyCode = 'Enter'; | |
511 scalingInput.dispatchEvent(enterEvent); | |
512 expectFalse( | |
513 fitToPageContainer.querySelector('.checkbox').checked); | |
514 | |
515 this.waitForAnimationToEnd('other-options-collapsible'); | |
516 }.bind(this)); | |
517 }); | |
518 | |
519 // When the number of copies print preset is set for source 'PDF', we update | |
520 // the copies value if capability is supported by printer. | |
521 TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() { | |
522 this.initialSettings_.isDocumentModifiable_ = false; | |
523 this.setInitialSettings(); | |
524 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
525 function() { | |
526 this.setLocalDestinations(); | |
527 this.setCapabilities(getCddTemplate("FooDevice")); | |
528 | |
529 // Indicate that the number of copies print preset is set for source | |
530 // PDF. | |
531 var printPresetOptions = { | |
532 disableScaling: true, | |
533 copies: 2 | |
534 }; | |
535 var printPresetOptionsEvent = new Event( | |
536 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); | |
537 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; | |
538 this.nativeLayer_.getEventTarget(). | |
539 dispatchEvent(printPresetOptionsEvent); | |
540 | |
541 checkSectionVisible($('copies-settings'), true); | |
542 expectEquals( | |
543 printPresetOptions.copies, | |
544 parseInt($('copies-settings').querySelector('.user-value').value)); | |
545 | |
546 this.waitForAnimationToEnd('other-options-collapsible'); | |
547 }.bind(this)); | |
548 }); | |
549 | |
550 // When the duplex print preset is set for source 'PDF', we update the | |
551 // duplex setting if capability is supported by printer. | |
552 TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() { | |
553 this.initialSettings_.isDocumentModifiable_ = false; | |
554 this.setInitialSettings(); | |
555 | |
556 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
557 function() { | |
558 this.setLocalDestinations(); | |
559 this.setCapabilities(getCddTemplate("FooDevice")); | |
560 | |
561 // Indicate that the duplex print preset is set to "long edge" for | |
562 // source PDF. | |
563 var printPresetOptions = { | |
564 duplex: 1 | |
565 }; | |
566 var printPresetOptionsEvent = new Event( | |
567 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); | |
568 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; | |
569 this.nativeLayer_.getEventTarget(). | |
570 dispatchEvent(printPresetOptionsEvent); | |
571 | |
572 var otherOptions = $('other-options-settings'); | |
573 checkSectionVisible(otherOptions, true); | |
574 var duplexContainer = otherOptions.querySelector('#duplex-container'); | |
575 checkElementDisplayed(duplexContainer, true); | |
576 expectTrue(duplexContainer.querySelector('.checkbox').checked); | |
577 | |
578 this.waitForAnimationToEnd('other-options-collapsible'); | |
579 }.bind(this)); | |
580 }); | |
581 | |
582 // Make sure that custom margins controls are properly set up. | |
583 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() { | |
584 this.setInitialSettings(); | |
585 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
586 function() { | |
587 this.setLocalDestinations(); | |
588 this.setCapabilities(getCddTemplate("FooDevice")); | |
589 | |
590 this.printPreview_.printTicketStore_.marginsType.updateValue( | |
591 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | |
592 | |
593 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { | |
594 var control = | |
595 $('preview-area').querySelector('.margin-control-' + margin); | |
596 assertNotEquals(null, control); | |
597 var input = control.querySelector('.margin-control-textbox'); | |
598 assertTrue(input.hasAttribute('aria-label')); | |
599 assertNotEquals('undefined', input.getAttribute('aria-label')); | |
600 }); | |
601 this.waitForAnimationToEnd('more-settings'); | |
602 }.bind(this)); | |
603 }); | |
604 | |
605 // Page layout has zero margins. Hide header and footer option. | |
606 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter', | |
607 function() { | |
608 this.setInitialSettings(); | |
609 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
610 function() { | |
611 this.setLocalDestinations(); | |
612 this.setCapabilities(getCddTemplate("FooDevice")); | |
613 | |
614 var otherOptions = $('other-options-settings'); | |
615 var headerFooter = | |
616 otherOptions.querySelector('#header-footer-container'); | |
617 | |
618 // Check that options are collapsed (section is visible, because duplex | |
619 // is available). | |
620 checkSectionVisible(otherOptions, true); | |
621 checkElementDisplayed(headerFooter, false); | |
622 | |
623 this.expandMoreSettings(); | |
624 | |
625 checkElementDisplayed(headerFooter, true); | |
626 | |
627 this.printPreview_.printTicketStore_.marginsType.updateValue( | |
628 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | |
629 this.printPreview_.printTicketStore_.customMargins.updateValue( | |
630 new print_preview.Margins(0, 0, 0, 0)); | |
631 | |
632 checkElementDisplayed(headerFooter, false); | |
633 | |
634 this.waitForAnimationToEnd('more-settings'); | |
635 }.bind(this)); | |
636 }); | |
637 | |
638 // Page layout has half-inch margins. Show header and footer option. | |
639 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter', | |
640 function() { | |
641 this.setInitialSettings(); | |
642 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
643 function() { | |
644 this.setLocalDestinations(); | |
645 this.setCapabilities(getCddTemplate("FooDevice")); | |
646 | |
647 var otherOptions = $('other-options-settings'); | |
648 var headerFooter = | |
649 otherOptions.querySelector('#header-footer-container'); | |
650 | |
651 // Check that options are collapsed (section is visible, because duplex | |
652 // is available). | |
653 checkSectionVisible(otherOptions, true); | |
654 checkElementDisplayed(headerFooter, false); | |
655 | |
656 this.expandMoreSettings(); | |
657 | |
658 checkElementDisplayed(headerFooter, true); | |
659 | |
660 this.printPreview_.printTicketStore_.marginsType.updateValue( | |
661 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | |
662 this.printPreview_.printTicketStore_.customMargins.updateValue( | |
663 new print_preview.Margins(36, 36, 36, 36)); | |
664 | |
665 checkElementDisplayed(headerFooter, true); | |
666 | |
667 this.waitForAnimationToEnd('more-settings'); | |
668 }.bind(this)); | |
669 }); | |
670 | |
671 // Page layout has zero top and bottom margins. Hide header and footer option. | 299 // Page layout has zero top and bottom margins. Hide header and footer option. |
672 TEST_F('PrintPreviewWebUITest', | 300 TEST_F('PrintPreviewWebUITest', |
673 'ZeroTopAndBottomMarginsHideHeaderFooter', | 301 'ZeroTopAndBottomMarginsHideHeaderFooter', |
674 function() { | 302 function() { |
675 this.setInitialSettings(); | 303 this.setInitialSettings(); |
676 this.nativeLayer_.whenCalled('getInitialSettings').then( | 304 this.nativeLayer_.whenCalled('getInitialSettings').then( |
677 function() { | 305 function() { |
678 this.setLocalDestinations(); | 306 this.setLocalDestinations(); |
679 this.setCapabilities(getCddTemplate("FooDevice")); | 307 this.setCapabilities(getCddTemplate("FooDevice")); |
680 | 308 |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 expectFalse(this.generateDraft()); | 1009 expectFalse(this.generateDraft()); |
1382 | 1010 |
1383 // Change the margin type - need to regenerate again. | 1011 // Change the margin type - need to regenerate again. |
1384 this.printPreview_.printTicketStore_.marginsType.updateValue( | 1012 this.printPreview_.printTicketStore_.marginsType.updateValue( |
1385 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); | 1013 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); |
1386 expectTrue(this.generateDraft()); | 1014 expectTrue(this.generateDraft()); |
1387 | 1015 |
1388 testDone(); | 1016 testDone(); |
1389 }.bind(this)); | 1017 }.bind(this)); |
1390 }); | 1018 }); |
OLD | NEW |