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
3 // found in the LICENSE file.
6 * Test fixture for print preview WebUI testing.
8 * @extends {testing.Test}
10 function PrintPreviewWebUITest() {
11 testing
.Test
.call(this);
12 this.nativeLayer_
= null;
13 this.initialSettings_
= null;
14 this.localDestinationInfos_
= null;
18 * Index of the "Save as PDF" printer.
22 PrintPreviewWebUITest
.PDF_INDEX
= 0;
25 * Index of the Foo printer.
29 PrintPreviewWebUITest
.FOO_INDEX
= 1;
32 * Index of the Bar printer.
36 PrintPreviewWebUITest
.BAR_INDEX
= 2;
38 PrintPreviewWebUITest
.prototype = {
39 __proto__
: testing
.Test
.prototype,
42 * Browse to the sample page, cause print preview & call preLoad().
46 browsePrintPreload
: 'print_preview_hello_world_test.html',
49 runAccessibilityChecks
: true,
52 accessibilityIssuesAreErrors
: true,
58 * Stub out low-level functionality like the NativeLayer and
59 * CloudPrintInterface.
60 * @this {PrintPreviewWebUITest}
64 window
.addEventListener('DOMContentLoaded', function() {
65 function NativeLayerStub() {
66 cr
.EventTarget
.call(this);
68 NativeLayerStub
.prototype = {
69 __proto__
: cr
.EventTarget
.prototype,
70 startGetInitialSettings: function() {},
71 startGetLocalDestinations: function() {},
72 startGetPrivetDestinations: function() {},
73 startGetLocalDestinationCapabilities: function(destinationId
) {}
75 var oldNativeLayerEventType
= print_preview
.NativeLayer
.EventType
;
76 var oldDuplexMode
= print_preview
.NativeLayer
.DuplexMode
;
77 print_preview
.NativeLayer
= NativeLayerStub
;
78 print_preview
.NativeLayer
.EventType
= oldNativeLayerEventType
;
79 print_preview
.NativeLayer
.DuplexMode
= oldDuplexMode
;
81 function CloudPrintInterfaceStub() {
82 cr
.EventTarget
.call(this);
84 CloudPrintInterfaceStub
.prototype = {
85 __proto__
: cr
.EventTarget
.prototype,
86 search: function(isRecent
) {}
88 var oldCpInterfaceEventType
= cloudprint
.CloudPrintInterface
.EventType
;
89 cloudprint
.CloudPrintInterface
= CloudPrintInterfaceStub
;
90 cloudprint
.CloudPrintInterface
.EventType
= oldCpInterfaceEventType
;
92 print_preview
.PreviewArea
.prototype.checkPluginCompatibility_
=
100 * Dispatch the INITIAL_SETTINGS_SET event. This call is NOT async and will
101 * happen in the same thread.
103 setInitialSettings: function() {
104 var initialSettingsSetEvent
=
105 new Event(print_preview
.NativeLayer
.EventType
.INITIAL_SETTINGS_SET
);
106 initialSettingsSetEvent
.initialSettings
= this.initialSettings_
;
107 this.nativeLayer_
.dispatchEvent(initialSettingsSetEvent
);
111 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will
112 * happen in the same thread.
114 setLocalDestinations: function() {
115 var localDestsSetEvent
=
116 new Event(print_preview
.NativeLayer
.EventType
.LOCAL_DESTINATIONS_SET
);
117 localDestsSetEvent
.destinationInfos
= this.localDestinationInfos_
;
118 this.nativeLayer_
.dispatchEvent(localDestsSetEvent
);
122 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will
123 * happen in the same thread.
124 * @device - The device whose capabilities should be dispatched.
126 setCapabilities: function(device
) {
128 new Event(print_preview
.NativeLayer
.EventType
.CAPABILITIES_SET
);
129 capsSetEvent
.settingsInfo
= device
;
130 this.nativeLayer_
.dispatchEvent(capsSetEvent
);
134 * Even though animation duration and delay is set to zero, it is necessary to
135 * wait until the animation has finished.
137 waitForAnimationToEnd: function(elementId
) {
138 // add a listener for the animation end event
139 document
.addEventListener('webkitAnimationEnd', function f(e
) {
140 if (e
.target
.id
== elementId
) {
141 document
.removeEventListener(f
, 'webkitAnimationEnd');
148 * Expand the 'More Settings' div to expose all options.
150 expandMoreSettings: function() {
151 var moreSettings
= $('more-settings');
152 checkSectionVisible(moreSettings
, true);
153 moreSettings
.click();
157 * Generate a real C++ class; don't typedef.
161 typedefCppFixture
: null,
164 * @this {PrintPreviewWebUITest}
168 Mock4JS
.clearMocksToVerify();
170 this.initialSettings_
= new print_preview
.NativeInitialSettings(
171 false /*isInKioskAutoPrintMode*/,
172 false /*isInAppKioskMode*/,
173 false /*hidePrintWithSystemDialogLink*/,
174 ',' /*thousandsDelimeter*/,
175 '.' /*decimalDelimeter*/,
177 true /*isDocumentModifiable*/,
178 'title' /*documentTitle*/,
179 true /*documentHasSelection*/,
180 false /*selectionOnly*/,
181 'FooDevice' /*systemDefaultDestinationId*/,
182 null /*serializedAppStateStr*/,
183 false /*documentHasSelection*/);
184 this.localDestinationInfos_
= [
185 { printerName
: 'FooName', deviceName
: 'FooDevice' },
186 { printerName
: 'BarName', deviceName
: 'BarDevice' }
188 this.nativeLayer_
= printPreview
.nativeLayer_
;
190 testing
.Test
.disableAnimationsAndTransitions();
194 GEN('#include "chrome/test/data/webui/print_preview.h"');
196 // Test some basic assumptions about the print preview WebUI.
197 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
198 this.setInitialSettings();
199 this.setLocalDestinations();
201 var recentList
= $('destination-search').querySelector('.recent-list ul');
202 var localList
= $('destination-search').querySelector('.local-list ul');
203 assertNotEquals(null, recentList
);
204 assertEquals(1, recentList
.childNodes
.length
);
205 assertEquals('FooName',
206 recentList
.childNodes
.item(0).querySelector(
207 '.destination-list-item-name').textContent
);
209 assertNotEquals(null, localList
);
210 assertEquals(3, localList
.childNodes
.length
);
211 assertEquals('Save as PDF',
212 localList
.childNodes
.item(PrintPreviewWebUITest
.PDF_INDEX
).
213 querySelector('.destination-list-item-name').textContent
);
214 assertEquals('FooName',
215 localList
.childNodes
.item(PrintPreviewWebUITest
.FOO_INDEX
).
216 querySelector('.destination-list-item-name').textContent
);
217 assertEquals('BarName',
218 localList
.childNodes
.item(PrintPreviewWebUITest
.BAR_INDEX
).
219 querySelector('.destination-list-item-name').textContent
);
224 // Test that the printer list is structured correctly after calling
225 // addCloudPrinters with an empty list.
226 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
227 this.setInitialSettings();
228 this.setLocalDestinations();
230 var cloudPrintEnableEvent
=
231 new Event(print_preview
.NativeLayer
.EventType
.CLOUD_PRINT_ENABLE
);
232 cloudPrintEnableEvent
.baseCloudPrintUrl
= 'cloudprint url';
233 this.nativeLayer_
.dispatchEvent(cloudPrintEnableEvent
);
235 var searchDoneEvent
=
236 new Event(cloudprint
.CloudPrintInterface
.EventType
.SEARCH_DONE
);
237 searchDoneEvent
.printers
= [];
238 searchDoneEvent
.isRecent
= true;
239 searchDoneEvent
.email
= 'foo@chromium.org';
240 printPreview
.cloudPrintInterface_
.dispatchEvent(searchDoneEvent
);
242 var recentList
= $('destination-search').querySelector('.recent-list ul');
243 var localList
= $('destination-search').querySelector('.local-list ul');
244 var cloudList
= $('destination-search').querySelector('.cloud-list ul');
246 assertNotEquals(null, recentList
);
247 assertEquals(1, recentList
.childNodes
.length
);
248 assertEquals('FooName',
249 recentList
.childNodes
.item(0).querySelector(
250 '.destination-list-item-name').textContent
);
252 assertNotEquals(null, localList
);
253 assertEquals(3, localList
.childNodes
.length
);
254 assertEquals('Save as PDF',
255 localList
.childNodes
.item(PrintPreviewWebUITest
.PDF_INDEX
).
256 querySelector('.destination-list-item-name').textContent
);
257 assertEquals('FooName',
258 localList
.childNodes
.item(PrintPreviewWebUITest
.FOO_INDEX
).
259 querySelector('.destination-list-item-name').textContent
);
260 assertEquals('BarName',
261 localList
.childNodes
.item(PrintPreviewWebUITest
.BAR_INDEX
).
262 querySelector('.destination-list-item-name').textContent
);
264 assertNotEquals(null, cloudList
);
265 assertEquals(0, cloudList
.childNodes
.length
);
271 * Verify that |section| visibility matches |visible|.
272 * @param {HTMLDivElement} section The section to check.
273 * @param {boolean} visible The expected state of visibility.
275 function checkSectionVisible(section
, visible
) {
276 assertNotEquals(null, section
);
278 visible
, section
.classList
.contains('visible'), 'section=' + section
.id
);
281 function checkElementDisplayed(el
, isDisplayed
) {
282 assertNotEquals(null, el
);
283 expectEquals(isDisplayed
,
285 'element="' + el
.id
+ '" of class "' + el
.classList
+ '"');
288 function getCddTemplate(printerId
) {
290 printerId
: printerId
,
294 supported_content_type
: [{content_type
: 'application/pdf'}],
298 {type
: 'STANDARD_COLOR', is_default
: true},
299 {type
: 'STANDARD_MONOCHROME'}
305 {type
: 'NO_DUPLEX', is_default
: true},
312 {type
: 'PORTRAIT', is_default
: true},
320 width_microns
: 215900,
321 height_microns
: 279400,
331 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination',
333 this.initialSettings_
.serializedAppStateStr_
=
334 '{"version":2,"selectedDestinationId":"ID",' +
335 '"selectedDestinationOrigin":"local"}';
336 this.setInitialSettings();
341 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode',
344 assertEquals(null, $('system-dialog-link'));
346 this.initialSettings_
.isInAppKioskMode_
= true;
347 this.setInitialSettings();
349 checkElementDisplayed($('system-dialog-link'), false);
355 // Test that disabled settings hide the disabled sections.
356 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
357 checkSectionVisible($('layout-settings'), false);
358 checkSectionVisible($('color-settings'), false);
359 checkSectionVisible($('copies-settings'), false);
361 this.setInitialSettings();
362 this.setLocalDestinations();
363 var device
= getCddTemplate("FooDevice");
364 device
.capabilities
.printer
.color
= {
366 {"is_default": true, "type": "STANDARD_COLOR"}
369 delete device
.capabilities
.printer
.copies
;
370 this.setCapabilities(device
);
372 checkSectionVisible($('layout-settings'), true);
373 checkSectionVisible($('color-settings'), false);
374 checkSectionVisible($('copies-settings'), false);
376 this.waitForAnimationToEnd('other-options-collapsible');
379 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
380 // fit to page option.
381 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() {
383 this.initialSettings_
.isDocumentModifiable_
= false;
384 this.initialSettings_
.systemDefaultDestinationId_
= 'Save as PDF';
385 this.setInitialSettings();
388 printerId
: 'Save as PDF',
394 {type
: 'AUTO', is_default
: true},
401 {type
: 'STANDARD_COLOR', is_default
: true}
416 this.setCapabilities(device
);
418 checkSectionVisible($('other-options-settings'), false);
419 checkSectionVisible($('media-size-settings'), false);
424 // When the source is 'HTML', we always hide the fit to page option and show
425 // media size option.
426 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() {
427 this.setInitialSettings();
428 this.setLocalDestinations();
429 this.setCapabilities(getCddTemplate("FooDevice"));
431 var otherOptions
= $('other-options-settings');
432 var fitToPage
= otherOptions
.querySelector('.fit-to-page-container');
433 var mediaSize
= $('media-size-settings');
435 // Check that options are collapsed (section is visible, because duplex is
437 checkSectionVisible(otherOptions
, true);
438 checkElementDisplayed(fitToPage
, false);
439 checkSectionVisible(mediaSize
, false);
441 this.expandMoreSettings();
443 checkElementDisplayed(fitToPage
, false);
444 checkSectionVisible(mediaSize
, true);
446 this.waitForAnimationToEnd('more-settings');
449 // When the source is "PDF", depending on the selected destination printer, we
450 // show/hide the fit to page option and hide media size selection.
451 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
452 this.initialSettings_
.isDocumentModifiable_
= false;
453 this.setInitialSettings();
454 this.setLocalDestinations();
455 this.setCapabilities(getCddTemplate("FooDevice"));
457 var otherOptions
= $('other-options-settings');
458 checkSectionVisible(otherOptions
, true);
459 checkElementDisplayed(
460 otherOptions
.querySelector('.fit-to-page-container'), true);
462 otherOptions
.querySelector('.fit-to-page-checkbox').checked
);
463 checkSectionVisible($('media-size-settings'), true);
465 this.waitForAnimationToEnd('other-options-collapsible');
468 // When the print scaling is disabled for the source "PDF", we show the fit
469 // to page option but the state is unchecked by default.
470 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
471 this.initialSettings_
.isDocumentModifiable_
= false;
472 this.setInitialSettings();
473 this.setLocalDestinations();
474 this.setCapabilities(getCddTemplate("FooDevice"));
476 // Indicate that the PDF does not support scaling by default.
477 var printPresetOptionsEvent
= new Event(
478 print_preview
.NativeLayer
.EventType
.PRINT_PRESET_OPTIONS
);
479 printPresetOptionsEvent
.optionsFromDocument
= {disableScaling
: true};
480 this.nativeLayer_
.dispatchEvent(printPresetOptionsEvent
);
482 var otherOptions
= $('other-options-settings');
483 checkSectionVisible(otherOptions
, true);
484 checkElementDisplayed(
485 otherOptions
.querySelector('.fit-to-page-container'), true);
487 otherOptions
.querySelector('.fit-to-page-checkbox').checked
);
489 this.waitForAnimationToEnd('other-options-collapsible');
492 // When the number of copies print preset is set for source 'PDF', we update
493 // the copies value if capability is supported by printer.
494 TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() {
495 this.initialSettings_
.isDocumentModifiable_
= false;
496 this.setInitialSettings();
497 this.setLocalDestinations();
498 this.setCapabilities(getCddTemplate("FooDevice"));
500 // Indicate that the number of copies print preset is set for source PDF.
501 var printPresetOptions
= {
502 disableScaling
: true,
505 var printPresetOptionsEvent
= new Event(
506 print_preview
.NativeLayer
.EventType
.PRINT_PRESET_OPTIONS
);
507 printPresetOptionsEvent
.optionsFromDocument
= printPresetOptions
;
508 this.nativeLayer_
.dispatchEvent(printPresetOptionsEvent
);
510 checkSectionVisible($('copies-settings'), true);
512 printPresetOptions
.copies
,
513 parseInt($('copies-settings').querySelector('.copies').value
));
515 this.waitForAnimationToEnd('other-options-collapsible');
518 // When the duplex print preset is set for source 'PDF', we update the
519 // duplex setting if capability is supported by printer.
520 TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() {
521 this.initialSettings_
.isDocumentModifiable_
= false;
522 this.setInitialSettings();
523 this.setLocalDestinations();
524 this.setCapabilities(getCddTemplate("FooDevice"));
526 // Indicate that the duplex print preset is set to "long edge" for source PDF.
527 var printPresetOptions
= {
530 var printPresetOptionsEvent
= new Event(
531 print_preview
.NativeLayer
.EventType
.PRINT_PRESET_OPTIONS
);
532 printPresetOptionsEvent
.optionsFromDocument
= printPresetOptions
;
533 this.nativeLayer_
.dispatchEvent(printPresetOptionsEvent
);
535 var otherOptions
= $('other-options-settings');
536 checkSectionVisible(otherOptions
, true);
537 checkElementDisplayed(otherOptions
.querySelector('.duplex-container'), true);
538 expectTrue(otherOptions
.querySelector('.duplex-checkbox').checked
);
540 this.waitForAnimationToEnd('other-options-collapsible');
543 // Make sure that custom margins controls are properly set up.
544 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
545 this.setInitialSettings();
546 this.setLocalDestinations();
547 this.setCapabilities(getCddTemplate("FooDevice"));
549 printPreview
.printTicketStore_
.marginsType
.updateValue(
550 print_preview
.ticket_items
.MarginsType
.Value
.CUSTOM
);
552 ['left', 'top', 'right', 'bottom'].forEach(function(margin
) {
553 var control
= $('preview-area').querySelector('.margin-control-' + margin
);
554 assertNotEquals(null, control
);
555 var input
= control
.querySelector('.margin-control-textbox');
556 assertTrue(input
.hasAttribute('aria-label'));
557 assertNotEquals('undefined', input
.getAttribute('aria-label'));
559 this.waitForAnimationToEnd('more-settings');
562 // Page layout has zero margins. Hide header and footer option.
563 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
565 this.setInitialSettings();
566 this.setLocalDestinations();
567 this.setCapabilities(getCddTemplate("FooDevice"));
569 var otherOptions
= $('other-options-settings');
570 var headerFooter
= otherOptions
.querySelector('.header-footer-container');
572 // Check that options are collapsed (section is visible, because duplex is
574 checkSectionVisible(otherOptions
, true);
575 checkElementDisplayed(headerFooter
, false);
577 this.expandMoreSettings();
579 checkElementDisplayed(headerFooter
, true);
581 printPreview
.printTicketStore_
.marginsType
.updateValue(
582 print_preview
.ticket_items
.MarginsType
.Value
.CUSTOM
);
583 printPreview
.printTicketStore_
.customMargins
.updateValue(
584 new print_preview
.Margins(0, 0, 0, 0));
586 checkElementDisplayed(headerFooter
, false);
588 this.waitForAnimationToEnd('more-settings');
591 // Page layout has half-inch margins. Show header and footer option.
592 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
594 this.setInitialSettings();
595 this.setLocalDestinations();
596 this.setCapabilities(getCddTemplate("FooDevice"));
598 var otherOptions
= $('other-options-settings');
599 var headerFooter
= otherOptions
.querySelector('.header-footer-container');
601 // Check that options are collapsed (section is visible, because duplex is
603 checkSectionVisible(otherOptions
, true);
604 checkElementDisplayed(headerFooter
, false);
606 this.expandMoreSettings();
608 checkElementDisplayed(headerFooter
, true);
610 printPreview
.printTicketStore_
.marginsType
.updateValue(
611 print_preview
.ticket_items
.MarginsType
.Value
.CUSTOM
);
612 printPreview
.printTicketStore_
.customMargins
.updateValue(
613 new print_preview
.Margins(36, 36, 36, 36));
615 checkElementDisplayed(headerFooter
, true);
617 this.waitForAnimationToEnd('more-settings');
620 // Page layout has zero top and bottom margins. Hide header and footer option.
621 TEST_F('PrintPreviewWebUITest',
622 'ZeroTopAndBottomMarginsHideHeaderFooter',
624 this.setInitialSettings();
625 this.setLocalDestinations();
626 this.setCapabilities(getCddTemplate("FooDevice"));
628 var otherOptions
= $('other-options-settings');
629 var headerFooter
= otherOptions
.querySelector('.header-footer-container');
631 // Check that options are collapsed (section is visible, because duplex is
633 checkSectionVisible(otherOptions
, true);
634 checkElementDisplayed(headerFooter
, false);
636 this.expandMoreSettings();
638 checkElementDisplayed(headerFooter
, true);
640 printPreview
.printTicketStore_
.marginsType
.updateValue(
641 print_preview
.ticket_items
.MarginsType
.Value
.CUSTOM
);
642 printPreview
.printTicketStore_
.customMargins
.updateValue(
643 new print_preview
.Margins(0, 36, 0, 36));
645 checkElementDisplayed(headerFooter
, false);
647 this.waitForAnimationToEnd('more-settings');
650 // Page layout has zero top and half-inch bottom margin. Show header and footer
652 TEST_F('PrintPreviewWebUITest',
653 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
655 this.setInitialSettings();
656 this.setLocalDestinations();
657 this.setCapabilities(getCddTemplate("FooDevice"));
659 var otherOptions
= $('other-options-settings');
660 var headerFooter
= otherOptions
.querySelector('.header-footer-container');
662 // Check that options are collapsed (section is visible, because duplex is
664 checkSectionVisible(otherOptions
, true);
665 checkElementDisplayed(headerFooter
, false);
667 this.expandMoreSettings();
669 checkElementDisplayed(headerFooter
, true);
671 printPreview
.printTicketStore_
.marginsType
.updateValue(
672 print_preview
.ticket_items
.MarginsType
.Value
.CUSTOM
);
673 printPreview
.printTicketStore_
.customMargins
.updateValue(
674 new print_preview
.Margins(0, 36, 36, 36));
676 checkElementDisplayed(headerFooter
, true);
678 this.waitForAnimationToEnd('more-settings');
681 // Test that the color settings, one option, standard monochrome.
682 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
683 this.setInitialSettings();
684 this.setLocalDestinations();
686 // Only one option, standard monochrome.
687 var device
= getCddTemplate("FooDevice");
688 device
.capabilities
.printer
.color
= {
690 {"is_default": true, "type": "STANDARD_MONOCHROME"}
693 this.setCapabilities(device
);
695 checkSectionVisible($('color-settings'), false);
697 this.waitForAnimationToEnd('more-settings');
700 // Test that the color settings, one option, custom monochrome.
701 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
703 this.setInitialSettings();
704 this.setLocalDestinations();
706 // Only one option, standard monochrome.
707 var device
= getCddTemplate("FooDevice");
708 device
.capabilities
.printer
.color
= {
710 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"}
713 this.setCapabilities(device
);
715 checkSectionVisible($('color-settings'), false);
717 this.waitForAnimationToEnd('more-settings');
720 // Test that the color settings, one option, standard color.
721 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
722 this.setInitialSettings();
723 this.setLocalDestinations();
725 var device
= getCddTemplate("FooDevice");
726 device
.capabilities
.printer
.color
= {
728 {"is_default": true, "type": "STANDARD_COLOR"}
731 this.setCapabilities(device
);
733 checkSectionVisible($('color-settings'), false);
735 this.waitForAnimationToEnd('more-settings');
738 // Test that the color settings, one option, custom color.
739 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
740 this.setInitialSettings();
741 this.setLocalDestinations();
743 var device
= getCddTemplate("FooDevice");
744 device
.capabilities
.printer
.color
= {
746 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"}
749 this.setCapabilities(device
);
751 checkSectionVisible($('color-settings'), false);
753 this.waitForAnimationToEnd('more-settings');
756 // Test that the color settings, two options, both standard, defaults to color.
757 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
759 this.setInitialSettings();
760 this.setLocalDestinations();
762 var device
= getCddTemplate("FooDevice");
763 device
.capabilities
.printer
.color
= {
765 {"type": "STANDARD_MONOCHROME"},
766 {"is_default": true, "type": "STANDARD_COLOR"}
769 this.setCapabilities(device
);
771 checkSectionVisible($('color-settings'), true);
774 $('color-settings').querySelector('.color-settings-select').value
);
776 this.waitForAnimationToEnd('more-settings');
779 // Test that the color settings, two options, both standard, defaults to
781 TEST_F('PrintPreviewWebUITest',
782 'TestColorSettingsBothStandardDefaultMonochrome', function() {
783 this.setInitialSettings();
784 this.setLocalDestinations();
786 var device
= getCddTemplate("FooDevice");
787 device
.capabilities
.printer
.color
= {
789 {"is_default": true, "type": "STANDARD_MONOCHROME"},
790 {"type": "STANDARD_COLOR"}
793 this.setCapabilities(device
);
795 checkSectionVisible($('color-settings'), true);
797 'bw', $('color-settings').querySelector('.color-settings-select').value
);
799 this.waitForAnimationToEnd('more-settings');
802 // Test that the color settings, two options, both custom, defaults to color.
803 TEST_F('PrintPreviewWebUITest',
804 'TestColorSettingsBothCustomDefaultColor', function() {
805 this.setInitialSettings();
806 this.setLocalDestinations();
808 var device
= getCddTemplate("FooDevice");
809 device
.capabilities
.printer
.color
= {
811 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"},
812 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"}
815 this.setCapabilities(device
);
817 checkSectionVisible($('color-settings'), true);
820 $('color-settings').querySelector('.color-settings-select').value
);
822 this.waitForAnimationToEnd('more-settings');
825 // Test to verify that duplex settings are set according to the printer
827 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
828 this.setInitialSettings();
829 this.setLocalDestinations();
830 this.setCapabilities(getCddTemplate("FooDevice"));
832 var otherOptions
= $('other-options-settings');
833 checkSectionVisible(otherOptions
, true);
834 expectFalse(otherOptions
.querySelector('.duplex-container').hidden
);
835 expectFalse(otherOptions
.querySelector('.duplex-checkbox').checked
);
837 this.waitForAnimationToEnd('more-settings');
840 // Test to verify that duplex settings are set according to the printer
842 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
843 this.setInitialSettings();
844 this.setLocalDestinations();
845 var device
= getCddTemplate("FooDevice");
846 delete device
.capabilities
.printer
.duplex
;
847 this.setCapabilities(device
);
849 // Check that it is collapsed.
850 var otherOptions
= $('other-options-settings');
851 checkSectionVisible(otherOptions
, false);
853 this.expandMoreSettings();
855 // Now it should be visible.
856 checkSectionVisible(otherOptions
, true);
857 expectTrue(otherOptions
.querySelector('.duplex-container').hidden
);
859 this.waitForAnimationToEnd('more-settings');
862 // Test that changing the selected printer updates the preview.
863 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
864 this.setInitialSettings();
865 this.setLocalDestinations();
866 this.setCapabilities(getCddTemplate("FooDevice"));
868 var previewGenerator
= mock(print_preview
.PreviewGenerator
);
869 printPreview
.previewArea_
.previewGenerator_
= previewGenerator
.proxy();
870 previewGenerator
.expects(exactly(6)).requestPreview();
873 var destinations
= printPreview
.destinationStore_
.destinations();
874 for (var destination
, i
= 0; destination
= destinations
[i
]; i
++) {
875 if (destination
.id
== 'BarDevice') {
876 barDestination
= destination
;
881 printPreview
.destinationStore_
.selectDestination(barDestination
);
883 var device
= getCddTemplate("BarDevice");
884 device
.capabilities
.printer
.color
= {
886 {"is_default": true, "type": "STANDARD_MONOCHROME"}
889 this.setCapabilities(device
);
891 this.waitForAnimationToEnd('more-settings');
894 // Test that error message is displayed when plugin doesn't exist.
895 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
896 var previewAreaEl
= $('preview-area');
898 var loadingMessageEl
=
899 previewAreaEl
.getElementsByClassName('preview-area-loading-message')[0];
900 expectEquals(true, loadingMessageEl
.hidden
);
902 var previewFailedMessageEl
= previewAreaEl
.getElementsByClassName(
903 'preview-area-preview-failed-message')[0];
904 expectEquals(true, previewFailedMessageEl
.hidden
);
906 var printFailedMessageEl
=
907 previewAreaEl
.getElementsByClassName('preview-area-print-failed')[0];
908 expectEquals(true, printFailedMessageEl
.hidden
);
910 var customMessageEl
=
911 previewAreaEl
.getElementsByClassName('preview-area-custom-message')[0];
912 expectEquals(false, customMessageEl
.hidden
);
917 // Test custom localized paper names.
918 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() {
919 this.setInitialSettings();
920 this.setLocalDestinations();
922 var customLocalizedMediaName
= 'Vendor defined localized media name';
923 var customMediaName
= 'Vendor defined media name';
925 var device
= getCddTemplate("FooDevice");
926 device
.capabilities
.printer
.media_size
= {
929 width_microns
: 15900,
930 height_microns
: 79400,
932 custom_display_name_localized
: [
933 { locale
: navigator
.language
,
934 value
: customLocalizedMediaName
939 width_microns
: 15900,
940 height_microns
: 79400,
941 custom_display_name
: customMediaName
946 this.setCapabilities(device
);
948 this.expandMoreSettings();
950 checkSectionVisible($('media-size-settings'), true);
951 var mediaSelect
= $('media-size-settings').querySelector('.settings-select');
952 // Check the default media item.
954 customLocalizedMediaName
,
955 mediaSelect
.options
[mediaSelect
.selectedIndex
].text
);
956 // Check the other media item.
959 mediaSelect
.options
[mediaSelect
.selectedIndex
== 0 ? 1 : 0].text
);
961 this.waitForAnimationToEnd('more-settings');