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.getPluginType_ =
94 return print_preview.PreviewArea.PluginType_.NONE;
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 // Make all transitions and animations take 0ms for testing purposes.
191 // Animations still happen and must be waited on.
192 var noAnimationStyle = document.createElement('style');
193 noAnimationStyle.textContent =
195 ' -webkit-transition-duration: 0ms !important;' +
196 ' -webkit-transition-delay: 0ms !important;' +
197 ' -webkit-animation-duration: 0ms !important;' +
198 ' -webkit-animation-delay: 0ms !important;' +
200 document.querySelector('head').appendChild(noAnimationStyle);
204 GEN('#include "chrome/test/data/webui/print_preview.h"');
206 // Test some basic assumptions about the print preview WebUI.
207 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
208 this.setInitialSettings();
209 this.setLocalDestinations();
211 var recentList = $('destination-search').querySelector('.recent-list ul');
212 var localList = $('destination-search').querySelector('.local-list ul');
213 assertNotEquals(null, recentList);
214 assertEquals(1, recentList.childNodes.length);
215 assertEquals('FooName',
216 recentList.childNodes.item(0).querySelector(
217 '.destination-list-item-name').textContent);
219 assertNotEquals(null, localList);
220 assertEquals(3, localList.childNodes.length);
221 assertEquals('Save as PDF',
222 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
223 querySelector('.destination-list-item-name').textContent);
224 assertEquals('FooName',
225 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
226 querySelector('.destination-list-item-name').textContent);
227 assertEquals('BarName',
228 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
229 querySelector('.destination-list-item-name').textContent);
234 // Test that the printer list is structured correctly after calling
235 // addCloudPrinters with an empty list.
236 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
237 this.setInitialSettings();
238 this.setLocalDestinations();
240 var cloudPrintEnableEvent =
241 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
242 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
243 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent);
245 var searchDoneEvent =
246 new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE);
247 searchDoneEvent.printers = [];
248 searchDoneEvent.isRecent = true;
249 searchDoneEvent.email = 'foo@chromium.org';
250 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent);
252 var recentList = $('destination-search').querySelector('.recent-list ul');
253 var localList = $('destination-search').querySelector('.local-list ul');
254 var cloudList = $('destination-search').querySelector('.cloud-list ul');
256 assertNotEquals(null, recentList);
257 assertEquals(1, recentList.childNodes.length);
258 assertEquals('FooName',
259 recentList.childNodes.item(0).querySelector(
260 '.destination-list-item-name').textContent);
262 assertNotEquals(null, localList);
263 assertEquals(3, localList.childNodes.length);
264 assertEquals('Save as PDF',
265 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
266 querySelector('.destination-list-item-name').textContent);
267 assertEquals('FooName',
268 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
269 querySelector('.destination-list-item-name').textContent);
270 assertEquals('BarName',
271 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
272 querySelector('.destination-list-item-name').textContent);
274 assertNotEquals(null, cloudList);
275 assertEquals(0, cloudList.childNodes.length);
281 * Verify that |section| visibility matches |visible|.
282 * @param {HTMLDivElement} section The section to check.
283 * @param {boolean} visible The expected state of visibility.
285 function checkSectionVisible(section, visible) {
286 assertNotEquals(null, section);
288 visible, section.classList.contains('visible'), 'section=' + section.id);
291 function checkElementDisplayed(el, isDisplayed) {
292 assertNotEquals(null, el);
293 expectEquals(isDisplayed,
295 'element="' + el.id + '" of class "' + el.classList + '"');
298 function getCddTemplate(printerId) {
300 printerId: printerId,
304 supported_content_type: [{content_type: 'application/pdf'}],
308 {type: 'STANDARD_COLOR', is_default: true},
309 {type: 'STANDARD_MONOCHROME'}
315 {type: 'NO_DUPLEX', is_default: true},
322 {type: 'PORTRAIT', is_default: true},
330 width_microns: 215900,
331 height_microns: 279400,
341 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination',
343 this.initialSettings_.serializedAppStateStr_ =
344 '{"version":2,"selectedDestinationId":"ID",' +
345 '"selectedDestinationOrigin":"local"}';
346 this.setInitialSettings();
351 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode',
354 assertEquals(null, $('system-dialog-link'));
356 this.initialSettings_.isInAppKioskMode_ = true;
357 this.setInitialSettings();
359 checkElementDisplayed($('system-dialog-link'), false);
365 // Test that disabled settings hide the disabled sections.
366 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
367 checkSectionVisible($('layout-settings'), false);
368 checkSectionVisible($('color-settings'), false);
369 checkSectionVisible($('copies-settings'), false);
371 this.setInitialSettings();
372 this.setLocalDestinations();
373 var device = getCddTemplate("FooDevice");
374 device.capabilities.printer.color = {
376 {"is_default": true, "type": "STANDARD_COLOR"}
379 delete device.capabilities.printer.copies;
380 this.setCapabilities(device);
382 checkSectionVisible($('layout-settings'), true);
383 checkSectionVisible($('color-settings'), false);
384 checkSectionVisible($('copies-settings'), false);
386 this.waitForAnimationToEnd('other-options-collapsible');
389 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
390 // fit to page option.
391 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() {
393 this.initialSettings_.isDocumentModifiable_ = false;
394 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
395 this.setInitialSettings();
398 printerId: 'Save as PDF',
404 {type: 'AUTO', is_default: true},
411 {type: 'STANDARD_COLOR', is_default: true}
426 this.setCapabilities(device);
428 checkSectionVisible($('other-options-settings'), false);
429 checkSectionVisible($('media-size-settings'), false);
434 // When the source is 'HTML', we always hide the fit to page option and show
435 // media size option.
436 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() {
437 this.setInitialSettings();
438 this.setLocalDestinations();
439 this.setCapabilities(getCddTemplate("FooDevice"));
441 var otherOptions = $('other-options-settings');
442 var fitToPage = otherOptions.querySelector('.fit-to-page-container');
443 var mediaSize = $('media-size-settings');
445 // Check that options are collapsed (section is visible, because duplex is
447 checkSectionVisible(otherOptions, true);
448 checkElementDisplayed(fitToPage, false);
449 checkSectionVisible(mediaSize, false);
451 this.expandMoreSettings();
453 checkElementDisplayed(fitToPage, false);
454 checkSectionVisible(mediaSize, true);
456 this.waitForAnimationToEnd('more-settings');
459 // When the source is "PDF", depending on the selected destination printer, we
460 // show/hide the fit to page option and hide media size selection.
461 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
462 this.initialSettings_.isDocumentModifiable_ = false;
463 this.setInitialSettings();
464 this.setLocalDestinations();
465 this.setCapabilities(getCddTemplate("FooDevice"));
467 var otherOptions = $('other-options-settings');
468 checkSectionVisible(otherOptions, true);
469 checkElementDisplayed(
470 otherOptions.querySelector('.fit-to-page-container'), true);
472 otherOptions.querySelector('.fit-to-page-checkbox').checked);
473 checkSectionVisible($('media-size-settings'), true);
475 this.waitForAnimationToEnd('other-options-collapsible');
478 // When the print scaling is disabled for the source "PDF", we show the fit
479 // to page option but the state is unchecked by default.
480 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
481 this.initialSettings_.isDocumentModifiable_ = false;
482 this.setInitialSettings();
483 this.setLocalDestinations();
484 this.setCapabilities(getCddTemplate("FooDevice"));
486 // Indicate that the PDF does not support scaling by default.
487 var printPresetOptionsEvent = new Event(
488 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
489 printPresetOptionsEvent.optionsFromDocument = {disableScaling: true};
490 this.nativeLayer_.dispatchEvent(printPresetOptionsEvent);
492 var otherOptions = $('other-options-settings');
493 checkSectionVisible(otherOptions, true);
494 checkElementDisplayed(
495 otherOptions.querySelector('.fit-to-page-container'), true);
497 otherOptions.querySelector('.fit-to-page-checkbox').checked);
499 this.waitForAnimationToEnd('other-options-collapsible');
502 // When the number of copies print preset is set for source 'PDF', we update
503 // the copies value if capability is supported by printer.
504 TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() {
505 this.initialSettings_.isDocumentModifiable_ = false;
506 this.setInitialSettings();
507 this.setLocalDestinations();
508 this.setCapabilities(getCddTemplate("FooDevice"));
510 // Indicate that the number of copies print preset is set for source PDF.
511 var printPresetOptions = {
512 disableScaling: true,
515 var printPresetOptionsEvent = new Event(
516 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
517 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
518 this.nativeLayer_.dispatchEvent(printPresetOptionsEvent);
520 checkSectionVisible($('copies-settings'), true);
522 printPresetOptions.copies,
523 parseInt($('copies-settings').querySelector('.copies').value));
525 this.waitForAnimationToEnd('other-options-collapsible');
528 // When the duplex print preset is set for source 'PDF', we update the
529 // duplex setting if capability is supported by printer.
530 TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() {
531 this.initialSettings_.isDocumentModifiable_ = false;
532 this.setInitialSettings();
533 this.setLocalDestinations();
534 this.setCapabilities(getCddTemplate("FooDevice"));
536 // Indicate that the duplex print preset is set to "long edge" for source PDF.
537 var printPresetOptions = {
540 var printPresetOptionsEvent = new Event(
541 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
542 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
543 this.nativeLayer_.dispatchEvent(printPresetOptionsEvent);
545 var otherOptions = $('other-options-settings');
546 checkSectionVisible(otherOptions, true);
547 checkElementDisplayed(otherOptions.querySelector('.duplex-container'), true);
548 expectTrue(otherOptions.querySelector('.duplex-checkbox').checked);
550 this.waitForAnimationToEnd('other-options-collapsible');
553 // Make sure that custom margins controls are properly set up.
554 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
555 this.setInitialSettings();
556 this.setLocalDestinations();
557 this.setCapabilities(getCddTemplate("FooDevice"));
559 printPreview.printTicketStore_.marginsType.updateValue(
560 print_preview.ticket_items.MarginsType.Value.CUSTOM);
562 ['left', 'top', 'right', 'bottom'].forEach(function(margin) {
563 var control = $('preview-area').querySelector('.margin-control-' + margin);
564 assertNotEquals(null, control);
565 var input = control.querySelector('.margin-control-textbox');
566 assertTrue(input.hasAttribute('aria-label'));
567 assertNotEquals('undefined', input.getAttribute('aria-label'));
569 this.waitForAnimationToEnd('more-settings');
572 // Page layout has zero margins. Hide header and footer option.
573 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
575 this.setInitialSettings();
576 this.setLocalDestinations();
577 this.setCapabilities(getCddTemplate("FooDevice"));
579 var otherOptions = $('other-options-settings');
580 var headerFooter = otherOptions.querySelector('.header-footer-container');
582 // Check that options are collapsed (section is visible, because duplex is
584 checkSectionVisible(otherOptions, true);
585 checkElementDisplayed(headerFooter, false);
587 this.expandMoreSettings();
589 checkElementDisplayed(headerFooter, true);
591 printPreview.printTicketStore_.marginsType.updateValue(
592 print_preview.ticket_items.MarginsType.Value.CUSTOM);
593 printPreview.printTicketStore_.customMargins.updateValue(
594 new print_preview.Margins(0, 0, 0, 0));
596 checkElementDisplayed(headerFooter, false);
598 this.waitForAnimationToEnd('more-settings');
601 // Page layout has half-inch margins. Show header and footer option.
602 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
604 this.setInitialSettings();
605 this.setLocalDestinations();
606 this.setCapabilities(getCddTemplate("FooDevice"));
608 var otherOptions = $('other-options-settings');
609 var headerFooter = otherOptions.querySelector('.header-footer-container');
611 // Check that options are collapsed (section is visible, because duplex is
613 checkSectionVisible(otherOptions, true);
614 checkElementDisplayed(headerFooter, false);
616 this.expandMoreSettings();
618 checkElementDisplayed(headerFooter, true);
620 printPreview.printTicketStore_.marginsType.updateValue(
621 print_preview.ticket_items.MarginsType.Value.CUSTOM);
622 printPreview.printTicketStore_.customMargins.updateValue(
623 new print_preview.Margins(36, 36, 36, 36));
625 checkElementDisplayed(headerFooter, true);
627 this.waitForAnimationToEnd('more-settings');
630 // Page layout has zero top and bottom margins. Hide header and footer option.
631 TEST_F('PrintPreviewWebUITest',
632 'ZeroTopAndBottomMarginsHideHeaderFooter',
634 this.setInitialSettings();
635 this.setLocalDestinations();
636 this.setCapabilities(getCddTemplate("FooDevice"));
638 var otherOptions = $('other-options-settings');
639 var headerFooter = otherOptions.querySelector('.header-footer-container');
641 // Check that options are collapsed (section is visible, because duplex is
643 checkSectionVisible(otherOptions, true);
644 checkElementDisplayed(headerFooter, false);
646 this.expandMoreSettings();
648 checkElementDisplayed(headerFooter, true);
650 printPreview.printTicketStore_.marginsType.updateValue(
651 print_preview.ticket_items.MarginsType.Value.CUSTOM);
652 printPreview.printTicketStore_.customMargins.updateValue(
653 new print_preview.Margins(0, 36, 0, 36));
655 checkElementDisplayed(headerFooter, false);
657 this.waitForAnimationToEnd('more-settings');
660 // Page layout has zero top and half-inch bottom margin. Show header and footer
662 TEST_F('PrintPreviewWebUITest',
663 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
665 this.setInitialSettings();
666 this.setLocalDestinations();
667 this.setCapabilities(getCddTemplate("FooDevice"));
669 var otherOptions = $('other-options-settings');
670 var headerFooter = otherOptions.querySelector('.header-footer-container');
672 // Check that options are collapsed (section is visible, because duplex is
674 checkSectionVisible(otherOptions, true);
675 checkElementDisplayed(headerFooter, false);
677 this.expandMoreSettings();
679 checkElementDisplayed(headerFooter, true);
681 printPreview.printTicketStore_.marginsType.updateValue(
682 print_preview.ticket_items.MarginsType.Value.CUSTOM);
683 printPreview.printTicketStore_.customMargins.updateValue(
684 new print_preview.Margins(0, 36, 36, 36));
686 checkElementDisplayed(headerFooter, true);
688 this.waitForAnimationToEnd('more-settings');
691 // Test that the color settings, one option, standard monochrome.
692 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
693 this.setInitialSettings();
694 this.setLocalDestinations();
696 // Only one option, standard monochrome.
697 var device = getCddTemplate("FooDevice");
698 device.capabilities.printer.color = {
700 {"is_default": true, "type": "STANDARD_MONOCHROME"}
703 this.setCapabilities(device);
705 checkSectionVisible($('color-settings'), false);
707 this.waitForAnimationToEnd('more-settings');
710 // Test that the color settings, one option, custom monochrome.
711 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
713 this.setInitialSettings();
714 this.setLocalDestinations();
716 // Only one option, standard monochrome.
717 var device = getCddTemplate("FooDevice");
718 device.capabilities.printer.color = {
720 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"}
723 this.setCapabilities(device);
725 checkSectionVisible($('color-settings'), false);
727 this.waitForAnimationToEnd('more-settings');
730 // Test that the color settings, one option, standard color.
731 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
732 this.setInitialSettings();
733 this.setLocalDestinations();
735 var device = getCddTemplate("FooDevice");
736 device.capabilities.printer.color = {
738 {"is_default": true, "type": "STANDARD_COLOR"}
741 this.setCapabilities(device);
743 checkSectionVisible($('color-settings'), false);
745 this.waitForAnimationToEnd('more-settings');
748 // Test that the color settings, one option, custom color.
749 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
750 this.setInitialSettings();
751 this.setLocalDestinations();
753 var device = getCddTemplate("FooDevice");
754 device.capabilities.printer.color = {
756 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"}
759 this.setCapabilities(device);
761 checkSectionVisible($('color-settings'), false);
763 this.waitForAnimationToEnd('more-settings');
766 // Test that the color settings, two options, both standard, defaults to color.
767 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
769 this.setInitialSettings();
770 this.setLocalDestinations();
772 var device = getCddTemplate("FooDevice");
773 device.capabilities.printer.color = {
775 {"type": "STANDARD_MONOCHROME"},
776 {"is_default": true, "type": "STANDARD_COLOR"}
779 this.setCapabilities(device);
781 checkSectionVisible($('color-settings'), true);
784 $('color-settings').querySelector('.color-settings-select').value);
786 this.waitForAnimationToEnd('more-settings');
789 // Test that the color settings, two options, both standard, defaults to
791 TEST_F('PrintPreviewWebUITest',
792 'TestColorSettingsBothStandardDefaultMonochrome', function() {
793 this.setInitialSettings();
794 this.setLocalDestinations();
796 var device = getCddTemplate("FooDevice");
797 device.capabilities.printer.color = {
799 {"is_default": true, "type": "STANDARD_MONOCHROME"},
800 {"type": "STANDARD_COLOR"}
803 this.setCapabilities(device);
805 checkSectionVisible($('color-settings'), true);
807 'bw', $('color-settings').querySelector('.color-settings-select').value);
809 this.waitForAnimationToEnd('more-settings');
812 // Test that the color settings, two options, both custom, defaults to color.
813 TEST_F('PrintPreviewWebUITest',
814 'TestColorSettingsBothCustomDefaultColor', function() {
815 this.setInitialSettings();
816 this.setLocalDestinations();
818 var device = getCddTemplate("FooDevice");
819 device.capabilities.printer.color = {
821 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"},
822 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"}
825 this.setCapabilities(device);
827 checkSectionVisible($('color-settings'), true);
830 $('color-settings').querySelector('.color-settings-select').value);
832 this.waitForAnimationToEnd('more-settings');
835 // Test to verify that duplex settings are set according to the printer
837 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
838 this.setInitialSettings();
839 this.setLocalDestinations();
840 this.setCapabilities(getCddTemplate("FooDevice"));
842 var otherOptions = $('other-options-settings');
843 checkSectionVisible(otherOptions, true);
844 expectFalse(otherOptions.querySelector('.duplex-container').hidden);
845 expectFalse(otherOptions.querySelector('.duplex-checkbox').checked);
847 this.waitForAnimationToEnd('more-settings');
850 // Test to verify that duplex settings are set according to the printer
852 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
853 this.setInitialSettings();
854 this.setLocalDestinations();
855 var device = getCddTemplate("FooDevice");
856 delete device.capabilities.printer.duplex;
857 this.setCapabilities(device);
859 // Check that it is collapsed.
860 var otherOptions = $('other-options-settings');
861 checkSectionVisible(otherOptions, false);
863 this.expandMoreSettings();
865 // Now it should be visible.
866 checkSectionVisible(otherOptions, true);
867 expectTrue(otherOptions.querySelector('.duplex-container').hidden);
869 this.waitForAnimationToEnd('more-settings');
872 // Test that changing the selected printer updates the preview.
873 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
874 this.setInitialSettings();
875 this.setLocalDestinations();
876 this.setCapabilities(getCddTemplate("FooDevice"));
878 var previewGenerator = mock(print_preview.PreviewGenerator);
879 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
880 previewGenerator.expects(exactly(6)).requestPreview();
883 var destinations = printPreview.destinationStore_.destinations();
884 for (var destination, i = 0; destination = destinations[i]; i++) {
885 if (destination.id == 'BarDevice') {
886 barDestination = destination;
891 printPreview.destinationStore_.selectDestination(barDestination);
893 var device = getCddTemplate("BarDevice");
894 device.capabilities.printer.color = {
896 {"is_default": true, "type": "STANDARD_MONOCHROME"}
899 this.setCapabilities(device);
901 this.waitForAnimationToEnd('more-settings');
904 // Test that error message is displayed when plugin doesn't exist.
905 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
906 var previewAreaEl = $('preview-area');
908 var loadingMessageEl =
909 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0];
910 expectEquals(true, loadingMessageEl.hidden);
912 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
913 'preview-area-preview-failed-message')[0];
914 expectEquals(true, previewFailedMessageEl.hidden);
916 var printFailedMessageEl =
917 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
918 expectEquals(true, printFailedMessageEl.hidden);
920 var customMessageEl =
921 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
922 expectEquals(false, customMessageEl.hidden);
927 // Test custom localized paper names.
928 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() {
929 this.setInitialSettings();
930 this.setLocalDestinations();
932 var customLocalizedMediaName = 'Vendor defined localized media name';
933 var customMediaName = 'Vendor defined media name';
935 var device = getCddTemplate("FooDevice");
936 device.capabilities.printer.media_size = {
939 width_microns: 15900,
940 height_microns: 79400,
942 custom_display_name_localized: [
943 { locale: navigator.language,
944 value: customLocalizedMediaName
949 width_microns: 15900,
950 height_microns: 79400,
951 custom_display_name: customMediaName
956 this.setCapabilities(device);
958 this.expandMoreSettings();
960 checkSectionVisible($('media-size-settings'), true);
961 var mediaSelect = $('media-size-settings').querySelector('.settings-select');
962 // Check the default media item.
964 customLocalizedMediaName,
965 mediaSelect.options[mediaSelect.selectedIndex].text);
966 // Check the other media item.
969 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text);
971 this.waitForAnimationToEnd('more-settings');