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 // 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 // Make sure that custom margins controls are properly set up.
529 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
530 this.setInitialSettings();
531 this.setLocalDestinations();
532 this.setCapabilities(getCddTemplate("FooDevice"));
534 printPreview.printTicketStore_.marginsType.updateValue(
535 print_preview.ticket_items.MarginsType.Value.CUSTOM);
537 ['left', 'top', 'right', 'bottom'].forEach(function(margin) {
538 var control = $('preview-area').querySelector('.margin-control-' + margin);
539 assertNotEquals(null, control);
540 var input = control.querySelector('.margin-control-textbox');
541 assertTrue(input.hasAttribute('aria-label'));
542 assertNotEquals('undefined', input.getAttribute('aria-label'));
544 this.waitForAnimationToEnd('more-settings');
547 // Page layout has zero margins. Hide header and footer option.
548 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
550 this.setInitialSettings();
551 this.setLocalDestinations();
552 this.setCapabilities(getCddTemplate("FooDevice"));
554 var otherOptions = $('other-options-settings');
555 var headerFooter = otherOptions.querySelector('.header-footer-container');
557 // Check that options are collapsed (section is visible, because duplex is
559 checkSectionVisible(otherOptions, true);
560 checkElementDisplayed(headerFooter, false);
562 this.expandMoreSettings();
564 checkElementDisplayed(headerFooter, true);
566 printPreview.printTicketStore_.marginsType.updateValue(
567 print_preview.ticket_items.MarginsType.Value.CUSTOM);
568 printPreview.printTicketStore_.customMargins.updateValue(
569 new print_preview.Margins(0, 0, 0, 0));
571 checkElementDisplayed(headerFooter, false);
573 this.waitForAnimationToEnd('more-settings');
576 // Page layout has half-inch margins. Show header and footer option.
577 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
579 this.setInitialSettings();
580 this.setLocalDestinations();
581 this.setCapabilities(getCddTemplate("FooDevice"));
583 var otherOptions = $('other-options-settings');
584 var headerFooter = otherOptions.querySelector('.header-footer-container');
586 // Check that options are collapsed (section is visible, because duplex is
588 checkSectionVisible(otherOptions, true);
589 checkElementDisplayed(headerFooter, false);
591 this.expandMoreSettings();
593 checkElementDisplayed(headerFooter, true);
595 printPreview.printTicketStore_.marginsType.updateValue(
596 print_preview.ticket_items.MarginsType.Value.CUSTOM);
597 printPreview.printTicketStore_.customMargins.updateValue(
598 new print_preview.Margins(36, 36, 36, 36));
600 checkElementDisplayed(headerFooter, true);
602 this.waitForAnimationToEnd('more-settings');
605 // Page layout has zero top and bottom margins. Hide header and footer option.
606 TEST_F('PrintPreviewWebUITest',
607 'ZeroTopAndBottomMarginsHideHeaderFooter',
609 this.setInitialSettings();
610 this.setLocalDestinations();
611 this.setCapabilities(getCddTemplate("FooDevice"));
613 var otherOptions = $('other-options-settings');
614 var headerFooter = otherOptions.querySelector('.header-footer-container');
616 // Check that options are collapsed (section is visible, because duplex is
618 checkSectionVisible(otherOptions, true);
619 checkElementDisplayed(headerFooter, false);
621 this.expandMoreSettings();
623 checkElementDisplayed(headerFooter, true);
625 printPreview.printTicketStore_.marginsType.updateValue(
626 print_preview.ticket_items.MarginsType.Value.CUSTOM);
627 printPreview.printTicketStore_.customMargins.updateValue(
628 new print_preview.Margins(0, 36, 0, 36));
630 checkElementDisplayed(headerFooter, false);
632 this.waitForAnimationToEnd('more-settings');
635 // Page layout has zero top and half-inch bottom margin. Show header and footer
637 TEST_F('PrintPreviewWebUITest',
638 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
640 this.setInitialSettings();
641 this.setLocalDestinations();
642 this.setCapabilities(getCddTemplate("FooDevice"));
644 var otherOptions = $('other-options-settings');
645 var headerFooter = otherOptions.querySelector('.header-footer-container');
647 // Check that options are collapsed (section is visible, because duplex is
649 checkSectionVisible(otherOptions, true);
650 checkElementDisplayed(headerFooter, false);
652 this.expandMoreSettings();
654 checkElementDisplayed(headerFooter, true);
656 printPreview.printTicketStore_.marginsType.updateValue(
657 print_preview.ticket_items.MarginsType.Value.CUSTOM);
658 printPreview.printTicketStore_.customMargins.updateValue(
659 new print_preview.Margins(0, 36, 36, 36));
661 checkElementDisplayed(headerFooter, true);
663 this.waitForAnimationToEnd('more-settings');
666 // Test that the color settings, one option, standard monochrome.
667 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
668 this.setInitialSettings();
669 this.setLocalDestinations();
671 // Only one option, standard monochrome.
672 var device = getCddTemplate("FooDevice");
673 device.capabilities.printer.color = {
675 {"is_default": true, "type": "STANDARD_MONOCHROME"}
678 this.setCapabilities(device);
680 checkSectionVisible($('color-settings'), false);
682 this.waitForAnimationToEnd('more-settings');
685 // Test that the color settings, one option, custom monochrome.
686 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
688 this.setInitialSettings();
689 this.setLocalDestinations();
691 // Only one option, standard monochrome.
692 var device = getCddTemplate("FooDevice");
693 device.capabilities.printer.color = {
695 {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"}
698 this.setCapabilities(device);
700 checkSectionVisible($('color-settings'), false);
702 this.waitForAnimationToEnd('more-settings');
705 // Test that the color settings, one option, standard color.
706 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
707 this.setInitialSettings();
708 this.setLocalDestinations();
710 var device = getCddTemplate("FooDevice");
711 device.capabilities.printer.color = {
713 {"is_default": true, "type": "STANDARD_COLOR"}
716 this.setCapabilities(device);
718 checkSectionVisible($('color-settings'), false);
720 this.waitForAnimationToEnd('more-settings');
723 // Test that the color settings, one option, custom color.
724 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
725 this.setInitialSettings();
726 this.setLocalDestinations();
728 var device = getCddTemplate("FooDevice");
729 device.capabilities.printer.color = {
731 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"}
734 this.setCapabilities(device);
736 checkSectionVisible($('color-settings'), false);
738 this.waitForAnimationToEnd('more-settings');
741 // Test that the color settings, two options, both standard, defaults to color.
742 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
744 this.setInitialSettings();
745 this.setLocalDestinations();
747 var device = getCddTemplate("FooDevice");
748 device.capabilities.printer.color = {
750 {"type": "STANDARD_MONOCHROME"},
751 {"is_default": true, "type": "STANDARD_COLOR"}
754 this.setCapabilities(device);
756 checkSectionVisible($('color-settings'), true);
759 $('color-settings').querySelector('.color-settings-select').value);
761 this.waitForAnimationToEnd('more-settings');
764 // Test that the color settings, two options, both standard, defaults to
766 TEST_F('PrintPreviewWebUITest',
767 'TestColorSettingsBothStandardDefaultMonochrome', function() {
768 this.setInitialSettings();
769 this.setLocalDestinations();
771 var device = getCddTemplate("FooDevice");
772 device.capabilities.printer.color = {
774 {"is_default": true, "type": "STANDARD_MONOCHROME"},
775 {"type": "STANDARD_COLOR"}
778 this.setCapabilities(device);
780 checkSectionVisible($('color-settings'), true);
782 'bw', $('color-settings').querySelector('.color-settings-select').value);
784 this.waitForAnimationToEnd('more-settings');
787 // Test that the color settings, two options, both custom, defaults to color.
788 TEST_F('PrintPreviewWebUITest',
789 'TestColorSettingsBothCustomDefaultColor', function() {
790 this.setInitialSettings();
791 this.setLocalDestinations();
793 var device = getCddTemplate("FooDevice");
794 device.capabilities.printer.color = {
796 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"},
797 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"}
800 this.setCapabilities(device);
802 checkSectionVisible($('color-settings'), true);
805 $('color-settings').querySelector('.color-settings-select').value);
807 this.waitForAnimationToEnd('more-settings');
810 // Test to verify that duplex settings are set according to the printer
812 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
813 this.setInitialSettings();
814 this.setLocalDestinations();
815 this.setCapabilities(getCddTemplate("FooDevice"));
817 var otherOptions = $('other-options-settings');
818 checkSectionVisible(otherOptions, true);
819 expectFalse(otherOptions.querySelector('.duplex-container').hidden);
820 expectFalse(otherOptions.querySelector('.duplex-checkbox').checked);
822 this.waitForAnimationToEnd('more-settings');
825 // Test to verify that duplex settings are set according to the printer
827 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
828 this.setInitialSettings();
829 this.setLocalDestinations();
830 var device = getCddTemplate("FooDevice");
831 delete device.capabilities.printer.duplex;
832 this.setCapabilities(device);
834 // Check that it is collapsed.
835 var otherOptions = $('other-options-settings');
836 checkSectionVisible(otherOptions, false);
838 this.expandMoreSettings();
840 // Now it should be visible.
841 checkSectionVisible(otherOptions, true);
842 expectTrue(otherOptions.querySelector('.duplex-container').hidden);
844 this.waitForAnimationToEnd('more-settings');
847 // Test that changing the selected printer updates the preview.
848 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
849 this.setInitialSettings();
850 this.setLocalDestinations();
851 this.setCapabilities(getCddTemplate("FooDevice"));
853 var previewGenerator = mock(print_preview.PreviewGenerator);
854 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
855 previewGenerator.expects(exactly(6)).requestPreview();
858 var destinations = printPreview.destinationStore_.destinations();
859 for (var destination, i = 0; destination = destinations[i]; i++) {
860 if (destination.id == 'BarDevice') {
861 barDestination = destination;
866 printPreview.destinationStore_.selectDestination(barDestination);
868 var device = getCddTemplate("BarDevice");
869 device.capabilities.printer.color = {
871 {"is_default": true, "type": "STANDARD_MONOCHROME"}
874 this.setCapabilities(device);
876 this.waitForAnimationToEnd('more-settings');
879 // Test that error message is displayed when plugin doesn't exist.
880 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
881 var previewAreaEl = $('preview-area');
883 var loadingMessageEl =
884 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0];
885 expectEquals(true, loadingMessageEl.hidden);
887 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
888 'preview-area-preview-failed-message')[0];
889 expectEquals(true, previewFailedMessageEl.hidden);
891 var printFailedMessageEl =
892 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
893 expectEquals(true, printFailedMessageEl.hidden);
895 var customMessageEl =
896 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
897 expectEquals(false, customMessageEl.hidden);
902 // Test custom localized paper names.
903 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() {
904 this.setInitialSettings();
905 this.setLocalDestinations();
907 var customLocalizedMediaName = 'Vendor defined localized media name';
908 var customMediaName = 'Vendor defined media name';
910 var device = getCddTemplate("FooDevice");
911 device.capabilities.printer.media_size = {
914 width_microns: 15900,
915 height_microns: 79400,
917 custom_display_name_localized: [
918 { locale: navigator.language,
919 value: customLocalizedMediaName
924 width_microns: 15900,
925 height_microns: 79400,
926 custom_display_name: customMediaName
931 this.setCapabilities(device);
933 this.expandMoreSettings();
935 checkSectionVisible($('media-size-settings'), true);
936 var mediaSelect = $('media-size-settings').querySelector('.settings-select');
937 // Check the default media item.
939 customLocalizedMediaName,
940 mediaSelect.options[mediaSelect.selectedIndex].text);
941 // Check the other media item.
944 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text);
946 this.waitForAnimationToEnd('more-settings');