webui: make 0 into 0ms when it's a <time>.
[chromium-blink-merge.git] / chrome / test / data / webui / print_preview.js
blob55425bb0a6904230f30e1aab01ef4bbf69497fd3
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.
5 /**
6  * Test fixture for print preview WebUI testing.
7  * @constructor
8  * @extends {testing.Test}
9  */
10 function PrintPreviewWebUITest() {
11   testing.Test.call(this);
12   this.nativeLayer_ = null;
13   this.initialSettings_ = null;
14   this.localDestinationInfos_ = null;
17 /**
18  * Index of the "Save as PDF" printer.
19  * @type {number}
20  * @const
21  */
22 PrintPreviewWebUITest.PDF_INDEX = 0;
24 /**
25  * Index of the Foo printer.
26  * @type {number}
27  * @const
28  */
29 PrintPreviewWebUITest.FOO_INDEX = 1;
31 /**
32  * Index of the Bar printer.
33  * @type {number}
34  * @const
35  */
36 PrintPreviewWebUITest.BAR_INDEX = 2;
38 PrintPreviewWebUITest.prototype = {
39   __proto__: testing.Test.prototype,
41   /**
42    * Browse to the sample page, cause print preview & call preLoad().
43    * @type {string}
44    * @override
45    */
46   browsePrintPreload: 'print_preview_hello_world_test.html',
48   /** @override */
49   runAccessibilityChecks: true,
51   /** @override */
52   accessibilityIssuesAreErrors: true,
54   /** @override */
55   isAsync: true,
57   /**
58    * Stub out low-level functionality like the NativeLayer and
59    * CloudPrintInterface.
60    * @this {PrintPreviewWebUITest}
61    * @override
62    */
63   preLoad: function() {
64     window.addEventListener('DOMContentLoaded', function() {
65       function NativeLayerStub() {
66         cr.EventTarget.call(this);
67       }
68       NativeLayerStub.prototype = {
69         __proto__: cr.EventTarget.prototype,
70         startGetInitialSettings: function() {},
71         startGetLocalDestinations: function() {},
72         startGetPrivetDestinations: function() {},
73         startGetLocalDestinationCapabilities: function(destinationId) {}
74       };
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);
83       }
84       CloudPrintInterfaceStub.prototype = {
85         __proto__: cr.EventTarget.prototype,
86         search: function(isRecent) {}
87       };
88       var oldCpInterfaceEventType = cloudprint.CloudPrintInterface.EventType;
89       cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
90       cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType;
92       print_preview.PreviewArea.prototype.getPluginType_ =
93           function() {
94         return print_preview.PreviewArea.PluginType_.NONE;
95       };
96     }.bind(this));
97   },
99   /**
100    * Dispatch the INITIAL_SETTINGS_SET event. This call is NOT async and will
101    * happen in the same thread.
102    */
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);
108   },
110   /**
111    * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will
112    * happen in the same thread.
113    */
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);
119   },
121   /**
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.
125    */
126   setCapabilities: function(device) {
127     var capsSetEvent =
128       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
129     capsSetEvent.settingsInfo = device;
130     this.nativeLayer_.dispatchEvent(capsSetEvent);
131   },
133   /**
134    * Even though animation duration and delay is set to zero, it is necessary to
135    * wait until the animation has finished.
136    */
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');
142         testDone();
143       }
144     });
145   },
147   /**
148    * Expand the 'More Settings' div to expose all options.
149    */
150   expandMoreSettings: function() {
151     var moreSettings = $('more-settings');
152     checkSectionVisible(moreSettings, true);
153     moreSettings.click();
154   },
156   /**
157    * Generate a real C++ class; don't typedef.
158    * @type {?string}
159    * @override
160    */
161   typedefCppFixture: null,
163   /**
164    * @this {PrintPreviewWebUITest}
165    * @override
166    */
167   setUp: function() {
168     Mock4JS.clearMocksToVerify();
170     this.initialSettings_ = new print_preview.NativeInitialSettings(
171       false /*isInKioskAutoPrintMode*/,
172       false /*isInAppKioskMode*/,
173       false /*hidePrintWithSystemDialogLink*/,
174       ',' /*thousandsDelimeter*/,
175       '.' /*decimalDelimeter*/,
176       1 /*unitType*/,
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' }
187     ];
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 =
194       '* {' +
195       '  -webkit-transition-duration: 0ms !important;' +
196       '  -webkit-transition-delay: 0ms !important;' +
197       '  -webkit-animation-duration: 0ms !important;' +
198       '  -webkit-animation-delay: 0ms !important;' +
199       '}';
200     document.querySelector('head').appendChild(noAnimationStyle);
201   }
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);
231   testDone();
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);
277   testDone();
281  * Verify that |section| visibility matches |visible|.
282  * @param {HTMLDivElement} section The section to check.
283  * @param {boolean} visible The expected state of visibility.
284  */
285 function checkSectionVisible(section, visible) {
286   assertNotEquals(null, section);
287   expectEquals(
288       visible, section.classList.contains('visible'), 'section=' + section.id);
291 function checkElementDisplayed(el, isDisplayed) {
292   assertNotEquals(null, el);
293   expectEquals(isDisplayed,
294                !el.hidden,
295                'element="' + el.id + '" of class "' + el.classList + '"');
298 function getCddTemplate(printerId) {
299   return {
300     printerId: printerId,
301     capabilities: {
302       version: '1.0',
303       printer: {
304         supported_content_type: [{content_type: 'application/pdf'}],
305         collate: {},
306         color: {
307           option: [
308             {type: 'STANDARD_COLOR', is_default: true},
309             {type: 'STANDARD_MONOCHROME'}
310           ]
311         },
312         copies: {},
313         duplex: {
314           option: [
315             {type: 'NO_DUPLEX', is_default: true},
316             {type: 'LONG_EDGE'},
317             {type: 'SHORT_EDGE'}
318           ]
319         },
320         page_orientation: {
321           option: [
322             {type: 'PORTRAIT', is_default: true},
323             {type: 'LANDSCAPE'},
324             {type: 'AUTO'}
325           ]
326         },
327         media_size: {
328           option: [
329             { name: 'NA_LETTER',
330               width_microns: 215900,
331               height_microns: 279400,
332               is_default: true
333             }
334           ]
335         }
336       }
337     }
338   };
341 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode',
342     function() {
343   if (cr.isChromeOS) {
344     assertEquals(null, $('system-dialog-link'));
345   } else {
346     this.initialSettings_.isInAppKioskMode_ = true;
347     this.setInitialSettings();
349     checkElementDisplayed($('system-dialog-link'), false);
350   }
352   testDone();
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 = {
365     "option": [
366       {"is_default": true, "type": "STANDARD_COLOR"}
367     ]
368   };
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() {
382   // Add PDF printer.
383   this.initialSettings_.isDocumentModifiable_ = false;
384   this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
385   this.setInitialSettings();
387   var device = {
388     printerId: 'Save as PDF',
389     capabilities: {
390       version: '1.0',
391       printer: {
392         page_orientation: {
393           option: [
394             {type: 'AUTO', is_default: true},
395             {type: 'PORTRAIT'},
396             {type: 'LANDSCAPE'}
397           ]
398         },
399         color: {
400           option: [
401             {type: 'STANDARD_COLOR', is_default: true}
402           ]
403         },
404         media_size: {
405           option: [
406             { name: 'NA_LETTER',
407               width_microns: 0,
408               height_microns: 0,
409               is_default: true
410             }
411           ]
412         }
413       }
414     }
415   };
416   this.setCapabilities(device);
418   checkSectionVisible($('other-options-settings'), false);
419   checkSectionVisible($('media-size-settings'), false);
421   testDone();
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
436   // available).
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);
461   expectTrue(
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);
486   expectFalse(
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 // 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,
503     copies: 2
504   };
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);
511   expectEquals(
512       printPresetOptions.copies,
513       parseInt($('copies-settings').querySelector('.copies').value));
515   this.waitForAnimationToEnd('other-options-collapsible');
518 // Make sure that custom margins controls are properly set up.
519 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
520   this.setInitialSettings();
521   this.setLocalDestinations();
522   this.setCapabilities(getCddTemplate("FooDevice"));
524   printPreview.printTicketStore_.marginsType.updateValue(
525       print_preview.ticket_items.MarginsType.Value.CUSTOM);
527   ['left', 'top', 'right', 'bottom'].forEach(function(margin) {
528     var control = $('preview-area').querySelector('.margin-control-' + margin);
529     assertNotEquals(null, control);
530     var input = control.querySelector('.margin-control-textbox');
531     assertTrue(input.hasAttribute('aria-label'));
532     assertNotEquals('undefined', input.getAttribute('aria-label'));
533   });
534   this.waitForAnimationToEnd('more-settings');
537 // Page layout has zero margins. Hide header and footer option.
538 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
539     function() {
540   this.setInitialSettings();
541   this.setLocalDestinations();
542   this.setCapabilities(getCddTemplate("FooDevice"));
544   var otherOptions = $('other-options-settings');
545   var headerFooter = otherOptions.querySelector('.header-footer-container');
547   // Check that options are collapsed (section is visible, because duplex is
548   // available).
549   checkSectionVisible(otherOptions, true);
550   checkElementDisplayed(headerFooter, false);
552   this.expandMoreSettings();
554   checkElementDisplayed(headerFooter, true);
556   printPreview.printTicketStore_.marginsType.updateValue(
557       print_preview.ticket_items.MarginsType.Value.CUSTOM);
558   printPreview.printTicketStore_.customMargins.updateValue(
559       new print_preview.Margins(0, 0, 0, 0));
561   checkElementDisplayed(headerFooter, false);
563   this.waitForAnimationToEnd('more-settings');
566 // Page layout has half-inch margins. Show header and footer option.
567 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
568     function() {
569   this.setInitialSettings();
570   this.setLocalDestinations();
571   this.setCapabilities(getCddTemplate("FooDevice"));
573   var otherOptions = $('other-options-settings');
574   var headerFooter = otherOptions.querySelector('.header-footer-container');
576   // Check that options are collapsed (section is visible, because duplex is
577   // available).
578   checkSectionVisible(otherOptions, true);
579   checkElementDisplayed(headerFooter, false);
581   this.expandMoreSettings();
583   checkElementDisplayed(headerFooter, true);
585   printPreview.printTicketStore_.marginsType.updateValue(
586       print_preview.ticket_items.MarginsType.Value.CUSTOM);
587   printPreview.printTicketStore_.customMargins.updateValue(
588       new print_preview.Margins(36, 36, 36, 36));
590   checkElementDisplayed(headerFooter, true);
592   this.waitForAnimationToEnd('more-settings');
595 // Page layout has zero top and bottom margins. Hide header and footer option.
596 TEST_F('PrintPreviewWebUITest',
597        'ZeroTopAndBottomMarginsHideHeaderFooter',
598        function() {
599   this.setInitialSettings();
600   this.setLocalDestinations();
601   this.setCapabilities(getCddTemplate("FooDevice"));
603   var otherOptions = $('other-options-settings');
604   var headerFooter = otherOptions.querySelector('.header-footer-container');
606   // Check that options are collapsed (section is visible, because duplex is
607   // available).
608   checkSectionVisible(otherOptions, true);
609   checkElementDisplayed(headerFooter, false);
611   this.expandMoreSettings();
613   checkElementDisplayed(headerFooter, true);
615   printPreview.printTicketStore_.marginsType.updateValue(
616       print_preview.ticket_items.MarginsType.Value.CUSTOM);
617   printPreview.printTicketStore_.customMargins.updateValue(
618       new print_preview.Margins(0, 36, 0, 36));
620   checkElementDisplayed(headerFooter, false);
622   this.waitForAnimationToEnd('more-settings');
625 // Page layout has zero top and half-inch bottom margin. Show header and footer
626 // option.
627 TEST_F('PrintPreviewWebUITest',
628        'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
629        function() {
630   this.setInitialSettings();
631   this.setLocalDestinations();
632   this.setCapabilities(getCddTemplate("FooDevice"));
634   var otherOptions = $('other-options-settings');
635   var headerFooter = otherOptions.querySelector('.header-footer-container');
637   // Check that options are collapsed (section is visible, because duplex is
638   // available).
639   checkSectionVisible(otherOptions, true);
640   checkElementDisplayed(headerFooter, false);
642   this.expandMoreSettings();
644   checkElementDisplayed(headerFooter, true);
646   printPreview.printTicketStore_.marginsType.updateValue(
647       print_preview.ticket_items.MarginsType.Value.CUSTOM);
648   printPreview.printTicketStore_.customMargins.updateValue(
649       new print_preview.Margins(0, 36, 36, 36));
651   checkElementDisplayed(headerFooter, true);
653   this.waitForAnimationToEnd('more-settings');
656 // Test that the color settings, one option, standard monochrome.
657 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
658   this.setInitialSettings();
659   this.setLocalDestinations();
661   // Only one option, standard monochrome.
662   var device = getCddTemplate("FooDevice");
663   device.capabilities.printer.color = {
664     "option": [
665       {"is_default": true, "type": "STANDARD_MONOCHROME"}
666     ]
667   };
668   this.setCapabilities(device);
670   checkSectionVisible($('color-settings'), false);
672   this.waitForAnimationToEnd('more-settings');
675 // Test that the color settings, one option, custom monochrome.
676 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
677     function() {
678   this.setInitialSettings();
679   this.setLocalDestinations();
681   // Only one option, standard monochrome.
682   var device = getCddTemplate("FooDevice");
683   device.capabilities.printer.color = {
684     "option": [
685       {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"}
686     ]
687   };
688   this.setCapabilities(device);
690   checkSectionVisible($('color-settings'), false);
692   this.waitForAnimationToEnd('more-settings');
695 // Test that the color settings, one option, standard color.
696 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
697   this.setInitialSettings();
698   this.setLocalDestinations();
700   var device = getCddTemplate("FooDevice");
701   device.capabilities.printer.color = {
702     "option": [
703       {"is_default": true, "type": "STANDARD_COLOR"}
704     ]
705   };
706   this.setCapabilities(device);
708   checkSectionVisible($('color-settings'), false);
710   this.waitForAnimationToEnd('more-settings');
713 // Test that the color settings, one option, custom color.
714 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
715   this.setInitialSettings();
716   this.setLocalDestinations();
718   var device = getCddTemplate("FooDevice");
719   device.capabilities.printer.color = {
720     "option": [
721       {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"}
722     ]
723   };
724   this.setCapabilities(device);
726   checkSectionVisible($('color-settings'), false);
728   this.waitForAnimationToEnd('more-settings');
731 // Test that the color settings, two options, both standard, defaults to color.
732 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
733     function() {
734   this.setInitialSettings();
735   this.setLocalDestinations();
737   var device = getCddTemplate("FooDevice");
738   device.capabilities.printer.color = {
739     "option": [
740       {"type": "STANDARD_MONOCHROME"},
741       {"is_default": true, "type": "STANDARD_COLOR"}
742     ]
743   };
744   this.setCapabilities(device);
746   checkSectionVisible($('color-settings'), true);
747   expectEquals(
748       'color',
749       $('color-settings').querySelector('.color-settings-select').value);
751   this.waitForAnimationToEnd('more-settings');
754 // Test that the color settings, two options, both standard, defaults to
755 // monochrome.
756 TEST_F('PrintPreviewWebUITest',
757     'TestColorSettingsBothStandardDefaultMonochrome', function() {
758   this.setInitialSettings();
759   this.setLocalDestinations();
761   var device = getCddTemplate("FooDevice");
762   device.capabilities.printer.color = {
763     "option": [
764       {"is_default": true, "type": "STANDARD_MONOCHROME"},
765       {"type": "STANDARD_COLOR"}
766     ]
767   };
768   this.setCapabilities(device);
770   checkSectionVisible($('color-settings'), true);
771   expectEquals(
772       'bw', $('color-settings').querySelector('.color-settings-select').value);
774   this.waitForAnimationToEnd('more-settings');
777 // Test that the color settings, two options, both custom, defaults to color.
778 TEST_F('PrintPreviewWebUITest',
779     'TestColorSettingsBothCustomDefaultColor', function() {
780   this.setInitialSettings();
781   this.setLocalDestinations();
783   var device = getCddTemplate("FooDevice");
784   device.capabilities.printer.color = {
785     "option": [
786       {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"},
787       {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"}
788     ]
789   };
790   this.setCapabilities(device);
792   checkSectionVisible($('color-settings'), true);
793   expectEquals(
794       'color',
795       $('color-settings').querySelector('.color-settings-select').value);
797   this.waitForAnimationToEnd('more-settings');
800 // Test to verify that duplex settings are set according to the printer
801 // capabilities.
802 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
803   this.setInitialSettings();
804   this.setLocalDestinations();
805   this.setCapabilities(getCddTemplate("FooDevice"));
807   var otherOptions = $('other-options-settings');
808   checkSectionVisible(otherOptions, true);
809   expectFalse(otherOptions.querySelector('.duplex-container').hidden);
810   expectFalse(otherOptions.querySelector('.duplex-checkbox').checked);
812   this.waitForAnimationToEnd('more-settings');
815 // Test to verify that duplex settings are set according to the printer
816 // capabilities.
817 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
818   this.setInitialSettings();
819   this.setLocalDestinations();
820   var device = getCddTemplate("FooDevice");
821   delete device.capabilities.printer.duplex;
822   this.setCapabilities(device);
824   // Check that it is collapsed.
825   var otherOptions = $('other-options-settings');
826   checkSectionVisible(otherOptions, false);
828   this.expandMoreSettings();
830   // Now it should be visible.
831   checkSectionVisible(otherOptions, true);
832   expectTrue(otherOptions.querySelector('.duplex-container').hidden);
834   this.waitForAnimationToEnd('more-settings');
837 // Test that changing the selected printer updates the preview.
838 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
839   this.setInitialSettings();
840   this.setLocalDestinations();
841   this.setCapabilities(getCddTemplate("FooDevice"));
843   var previewGenerator = mock(print_preview.PreviewGenerator);
844   printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
845   previewGenerator.expects(exactly(6)).requestPreview();
847   var barDestination;
848   var destinations = printPreview.destinationStore_.destinations();
849   for (var destination, i = 0; destination = destinations[i]; i++) {
850     if (destination.id == 'BarDevice') {
851       barDestination = destination;
852       break;
853     }
854   }
856   printPreview.destinationStore_.selectDestination(barDestination);
858   var device = getCddTemplate("BarDevice");
859   device.capabilities.printer.color = {
860     "option": [
861       {"is_default": true, "type": "STANDARD_MONOCHROME"}
862     ]
863   };
864   this.setCapabilities(device);
866   this.waitForAnimationToEnd('more-settings');
869 // Test that error message is displayed when plugin doesn't exist.
870 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
871   var previewAreaEl = $('preview-area');
873   var loadingMessageEl =
874       previewAreaEl.getElementsByClassName('preview-area-loading-message')[0];
875   expectEquals(true, loadingMessageEl.hidden);
877   var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
878       'preview-area-preview-failed-message')[0];
879   expectEquals(true, previewFailedMessageEl.hidden);
881   var printFailedMessageEl =
882       previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
883   expectEquals(true, printFailedMessageEl.hidden);
885   var customMessageEl =
886       previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
887   expectEquals(false, customMessageEl.hidden);
889   testDone();
892 // Test custom localized paper names.
893 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() {
894   this.setInitialSettings();
895   this.setLocalDestinations();
897   var customLocalizedMediaName = 'Vendor defined localized media name';
898   var customMediaName = 'Vendor defined media name';
900   var device = getCddTemplate("FooDevice");
901   device.capabilities.printer.media_size = {
902     option: [
903       { name: 'CUSTOM',
904         width_microns: 15900,
905         height_microns: 79400,
906         is_default: true,
907         custom_display_name_localized: [
908           { locale: navigator.language,
909             value: customLocalizedMediaName
910           }
911         ]
912       },
913       { name: 'CUSTOM',
914         width_microns: 15900,
915         height_microns: 79400,
916         custom_display_name: customMediaName
917       }
918     ]
919   };
921   this.setCapabilities(device);
923   this.expandMoreSettings();
925   checkSectionVisible($('media-size-settings'), true);
926   var mediaSelect = $('media-size-settings').querySelector('.settings-select');
927   // Check the default media item.
928   expectEquals(
929       customLocalizedMediaName,
930       mediaSelect.options[mediaSelect.selectedIndex].text);
931   // Check the other media item.
932   expectEquals(
933       customMediaName,
934       mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text);
936   this.waitForAnimationToEnd('more-settings');