Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / test / data / webui / print_preview.js
blob6f8d2460f592535a626e90cb0b900350e9078c9a
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   /**
49    * Stub out low-level functionality like the NativeLayer and
50    * CloudPrintInterface.
51    * @this {PrintPreviewWebUITest}
52    * @override
53    */
54   preLoad: function() {
55     window.addEventListener('DOMContentLoaded', function() {
56       function NativeLayerStub() {
57         cr.EventTarget.call(this);
58       }
59       NativeLayerStub.prototype = {
60         __proto__: cr.EventTarget.prototype,
61         startGetInitialSettings: function() {},
62         startGetLocalDestinations: function() {},
63         startGetPrivetDestinations: function() {},
64         startGetLocalDestinationCapabilities: function(destinationId) {}
65       };
66       var oldNativeLayerEventType = print_preview.NativeLayer.EventType;
67       var oldDuplexMode = print_preview.NativeLayer.DuplexMode;
68       print_preview.NativeLayer = NativeLayerStub;
69       print_preview.NativeLayer.EventType = oldNativeLayerEventType;
70       print_preview.NativeLayer.DuplexMode = oldDuplexMode;
72       function CloudPrintInterfaceStub() {
73         cr.EventTarget.call(this);
74       }
75       CloudPrintInterfaceStub.prototype = {
76         __proto__: cr.EventTarget.prototype,
77         search: function(isRecent) {}
78       };
79       var oldCpInterfaceEventType = cloudprint.CloudPrintInterface.EventType;
80       cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
81       cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType;
83       print_preview.PreviewArea.prototype.checkPluginCompatibility_ =
84           function() {
85         return false;
86       };
87     }.bind(this));
88   },
90   /**
91    * Generate a real C++ class; don't typedef.
92    * @type {?string}
93    * @override
94    */
95   typedefCppFixture: null,
97   /**
98    * @this {PrintPreviewWebUITest}
99    * @override
100    */
101   setUp: function() {
102     Mock4JS.clearMocksToVerify();
104     this.initialSettings_ = new print_preview.NativeInitialSettings(
105       false /*isInKioskAutoPrintMode*/,
106       false /*hidePrintWithSystemDialogLink*/,
107       ',' /*thousandsDelimeter*/,
108       '.' /*decimalDelimeter*/,
109       1 /*unitType*/,
110       true /*isDocumentModifiable*/,
111       'title' /*documentTitle*/,
112       true /*documentHasSelection*/,
113       false /*selectionOnly*/,
114       'FooDevice' /*systemDefaultDestinationId*/,
115       null /*serializedAppStateStr*/,
116       false /*documentHasSelection*/);
117     this.localDestinationInfos_ = [
118       { printerName: 'FooName', deviceName: 'FooDevice' },
119       { printerName: 'BarName', deviceName: 'BarDevice' }
120     ];
121     this.nativeLayer_ = printPreview.nativeLayer_;
122   }
125 GEN('#include "chrome/test/data/webui/print_preview.h"');
127 // Test some basic assumptions about the print preview WebUI.
128 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
129   var initialSettingsSetEvent =
130       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
131   initialSettingsSetEvent.initialSettings = this.initialSettings_;
132   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
134   var localDestsSetEvent =
135       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
136   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
137   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
139   var recentList = $('destination-search').querySelector('.recent-list ul');
140   var localList = $('destination-search').querySelector('.local-list ul');
141   assertNotEquals(null, recentList);
142   assertEquals(1, recentList.childNodes.length);
143   assertEquals('FooName',
144                recentList.childNodes.item(0).querySelector(
145                    '.destination-list-item-name').textContent);
147   assertNotEquals(null, localList);
148   assertEquals(3, localList.childNodes.length);
149   assertEquals('Save as PDF',
150                localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
151                    querySelector('.destination-list-item-name').textContent);
152   assertEquals('FooName',
153                localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
154                    querySelector('.destination-list-item-name').textContent);
155   assertEquals('BarName',
156                localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
157                    querySelector('.destination-list-item-name').textContent);
160 // Test that the printer list is structured correctly after calling
161 // addCloudPrinters with an empty list.
162 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
163   var initialSettingsSetEvent =
164       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
165   initialSettingsSetEvent.initialSettings = this.initialSettings_;
166   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
168   var localDestsSetEvent =
169       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
170   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
171   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
173   var cloudPrintEnableEvent =
174       new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
175   cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
176   this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent);
178   var searchDoneEvent =
179       new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE);
180   searchDoneEvent.printers = [];
181   searchDoneEvent.isRecent = true;
182   searchDoneEvent.email = 'foo@chromium.org';
183   printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent);
185   var recentList = $('destination-search').querySelector('.recent-list ul');
186   var localList = $('destination-search').querySelector('.local-list ul');
187   var cloudList = $('destination-search').querySelector('.cloud-list ul');
189   assertNotEquals(null, recentList);
190   assertEquals(1, recentList.childNodes.length);
191   assertEquals('FooName',
192                recentList.childNodes.item(0).querySelector(
193                    '.destination-list-item-name').textContent);
195   assertNotEquals(null, localList);
196   assertEquals(3, localList.childNodes.length);
197   assertEquals('Save as PDF',
198                localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
199                    querySelector('.destination-list-item-name').textContent);
200   assertEquals('FooName',
201                localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
202                    querySelector('.destination-list-item-name').textContent);
203   assertEquals('BarName',
204                localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
205                    querySelector('.destination-list-item-name').textContent);
207   assertNotEquals(null, cloudList);
208   assertEquals(0, cloudList.childNodes.length);
212  * Verify that |section| visibility matches |visible|.
213  * @param {HTMLDivElement} section The section to check.
214  * @param {boolean} visible The expected state of visibility.
215  */
216 function checkSectionVisible(section, visible) {
217   assertNotEquals(null, section);
218   expectEquals(
219       visible, section.classList.contains('visible'), 'section=' + section.id);
222 function checkElementDisplayed(el, isDisplayed) {
223   assertNotEquals(null, el);
224   expectEquals(isDisplayed, !el.hidden);
227 // Test that disabled settings hide the disabled sections.
228 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
229   checkSectionVisible($('layout-settings'), true);
230   checkSectionVisible($('color-settings'), true);
231   checkSectionVisible($('copies-settings'), true);
233   var initialSettingsSetEvent =
234       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
235   initialSettingsSetEvent.initialSettings = this.initialSettings_;
236   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
238   var localDestsSetEvent =
239       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
240   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
241   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
243   var capsSetEvent =
244       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
245   capsSetEvent.settingsInfo = {
246     'printerId': 'FooDevice',
247     'disableColorOption': true,
248     'setColorAsDefault': true,
249     'disableCopiesOption': true,
250     'disableLandscapeOption': true,
251     'printerDefaultDuplexValue': 0
252   };
253   this.nativeLayer_.dispatchEvent(capsSetEvent);
255   checkSectionVisible($('layout-settings'), false);
256   checkSectionVisible($('color-settings'), false);
257   checkSectionVisible($('copies-settings'), false);
260 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
261 // fit to page option.
262 TEST_F('PrintPreviewWebUITest',
263        'PrintToPDFSelectedHideFitToPageOption',
264        function() {
265   // Add PDF printer.
266   this.initialSettings_.isDocumentModifiable_ = false;
267   this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
268   this.localDestinationInfos_.push(
269       {printerName: 'Save as PDF', deviceName: 'Save as PDF'});
271   var initialSettingsSetEvent =
272       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
273   initialSettingsSetEvent.initialSettings = this.initialSettings_;
274   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
276   var localDestsSetEvent =
277       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
278   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
279   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
281   var capsSetEvent =
282       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
283   capsSetEvent.settingsInfo = {
284     'printerId': 'FooDevice',
285     'disableColorOption': false,
286     'setColorAsDefault': true,
287     'disableCopiesOption': true,
288     'disableLandscapeOption': true,
289     'printerDefaultDuplexValue': 0
290   };
291   this.nativeLayer_.dispatchEvent(capsSetEvent);
293   checkElementDisplayed(
294       $('other-options-settings').querySelector('.fit-to-page-container'),
295       false);
298 // When the source is 'HTML', we always hide the fit to page option.
299 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLHideFitToPageOption', function() {
300   var initialSettingsSetEvent =
301       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
302   initialSettingsSetEvent.initialSettings = this.initialSettings_;
303   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
305   var localDestsSetEvent =
306       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
307   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
308   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
310   var capsSetEvent =
311       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
312   capsSetEvent.settingsInfo = {
313     'printerId': 'FooDevice',
314     'disableColorOption': false,
315     'setColorAsDefault': true,
316     'disableCopiesOption': true,
317     'disableLandscapeOption': true,
318     'printerDefaultDuplexValue': 0
319   };
320   this.nativeLayer_.dispatchEvent(capsSetEvent);
322   checkElementDisplayed(
323       $('other-options-settings').querySelector('.fit-to-page-container'),
324       false);
327 // When the source is "PDF", depending on the selected destination printer, we
328 // show/hide the fit to page option.
329 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFShowFitToPageOption', function() {
330   this.initialSettings_.isDocumentModifiable_ = false;
332   var initialSettingsSetEvent =
333       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
334   initialSettingsSetEvent.initialSettings = this.initialSettings_;
335   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
337   var localDestsSetEvent =
338       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
339   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
340   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
342   var capsSetEvent =
343       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
344   capsSetEvent.settingsInfo = {
345     'printerId': 'FooDevice',
346     'disableColorOption': false,
347     'setColorAsDefault': true,
348     'disableCopiesOption': true,
349     'disableLandscapeOption': true,
350     'printerDefaultDuplexValue': 0
351   };
352   this.nativeLayer_.dispatchEvent(capsSetEvent);
354   checkElementDisplayed(
355       $('other-options-settings').querySelector('.fit-to-page-container'),
356       true);
357   expectTrue(
358       $('other-options-settings').querySelector('.fit-to-page-checkbox').
359           checked);
362 // When the print scaling is disabled for the source "PDF", we show the fit
363 // to page option but the state is unchecked by default.
364 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
365   this.initialSettings_.isDocumentModifiable_ = false;
367   var initialSettingsSetEvent =
368       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
369   initialSettingsSetEvent.initialSettings = this.initialSettings_;
370   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
372   var localDestsSetEvent =
373       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
374   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
375   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
377   var capsSetEvent =
378       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
379   capsSetEvent.settingsInfo = {
380     'printerId': 'FooDevice',
381     'disableColorOption': false,
382     'setColorAsDefault': true,
383     'disableCopiesOption': true,
384     'disableLandscapeOption': true,
385     'printerDefaultDuplexValue': 0
386   };
387   this.nativeLayer_.dispatchEvent(capsSetEvent);
389   // Indicate that the PDF does not support scaling by default.
390   cr.dispatchSimpleEvent(
391       this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING);
393   checkElementDisplayed(
394       $('other-options-settings').querySelector('.fit-to-page-container'),
395       true);
396   expectFalse(
397       $('other-options-settings').querySelector('.fit-to-page-checkbox').
398           checked);
401 // Page layout has zero margins. Hide header and footer option.
402 TEST_F('PrintPreviewWebUITest',
403        'PageLayoutHasNoMarginsHideHeaderFooter',
404        function() {
405   var initialSettingsSetEvent =
406       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
407   initialSettingsSetEvent.initialSettings = this.initialSettings_;
408   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
410   var localDestsSetEvent =
411       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
412   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
413   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
415   var capsSetEvent =
416       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
417   capsSetEvent.settingsInfo = {
418     'printerId': 'FooDevice',
419     'disableColorOption': false,
420     'setColorAsDefault': true,
421     'disableCopiesOption': true,
422     'disableLandscapeOption': true,
423     'printerDefaultDuplexValue': 0
424   };
425   this.nativeLayer_.dispatchEvent(capsSetEvent);
427   checkElementDisplayed(
428       $('other-options-settings').querySelector('.header-footer-container'),
429       true);
431   printPreview.printTicketStore_.marginsType.updateValue(
432       print_preview.ticket_items.MarginsType.Value.CUSTOM);
433   printPreview.printTicketStore_.customMargins.updateValue(
434       new print_preview.Margins(0, 0, 0, 0));
436   checkElementDisplayed(
437       $('other-options-settings').querySelector('.header-footer-container'),
438       false);
441 // Page layout has half-inch margins. Show header and footer option.
442 TEST_F('PrintPreviewWebUITest',
443        'PageLayoutHasMarginsShowHeaderFooter',
444        function() {
445   var initialSettingsSetEvent =
446       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
447   initialSettingsSetEvent.initialSettings = this.initialSettings_;
448   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
450   var localDestsSetEvent =
451       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
452   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
453   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
455   var capsSetEvent =
456       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
457   capsSetEvent.settingsInfo = {
458     'printerId': 'FooDevice',
459     'disableColorOption': false,
460     'setColorAsDefault': true,
461     'disableCopiesOption': true,
462     'disableLandscapeOption': true,
463     'printerDefaultDuplexValue': 0
464   };
465   this.nativeLayer_.dispatchEvent(capsSetEvent);
467   checkElementDisplayed(
468       $('other-options-settings').querySelector('.header-footer-container'),
469       true);
471   printPreview.printTicketStore_.marginsType.updateValue(
472       print_preview.ticket_items.MarginsType.Value.CUSTOM);
473   printPreview.printTicketStore_.customMargins.updateValue(
474       new print_preview.Margins(36, 36, 36, 36));
476   checkElementDisplayed(
477       $('other-options-settings').querySelector('.header-footer-container'),
478       true);
481 // Page layout has zero top and bottom margins. Hide header and footer option.
482 TEST_F('PrintPreviewWebUITest',
483        'ZeroTopAndBottomMarginsHideHeaderFooter',
484        function() {
485   var initialSettingsSetEvent =
486       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
487   initialSettingsSetEvent.initialSettings = this.initialSettings_;
488   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
490   var localDestsSetEvent =
491       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
492   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
493   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
495   var capsSetEvent =
496       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
497   capsSetEvent.settingsInfo = {
498     'printerId': 'FooDevice',
499     'disableColorOption': false,
500     'setColorAsDefault': true,
501     'disableCopiesOption': true,
502     'disableLandscapeOption': true,
503     'printerDefaultDuplexValue': 0
504   };
505   this.nativeLayer_.dispatchEvent(capsSetEvent);
507   checkElementDisplayed(
508       $('other-options-settings').querySelector('.header-footer-container'),
509       true);
511   printPreview.printTicketStore_.marginsType.updateValue(
512       print_preview.ticket_items.MarginsType.Value.CUSTOM);
513   printPreview.printTicketStore_.customMargins.updateValue(
514       new print_preview.Margins(0, 36, 0, 36));
516   checkElementDisplayed(
517       $('other-options-settings').querySelector('.header-footer-container'),
518       false);
521 // Page layout has zero top and half-inch bottom margin. Show header and footer
522 // option.
523 TEST_F('PrintPreviewWebUITest',
524        'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
525        function() {
526   var initialSettingsSetEvent =
527       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
528   initialSettingsSetEvent.initialSettings = this.initialSettings_;
529   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
531   var localDestsSetEvent =
532       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
533   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
534   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
536   var capsSetEvent =
537       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
538   capsSetEvent.settingsInfo = {
539     'printerId': 'FooDevice',
540     'disableColorOption': false,
541     'setColorAsDefault': true,
542     'disableCopiesOption': true,
543     'disableLandscapeOption': true,
544     'printerDefaultDuplexValue': 0
545   };
546   this.nativeLayer_.dispatchEvent(capsSetEvent);
548   checkElementDisplayed(
549       $('other-options-settings').querySelector('.header-footer-container'),
550       true);
552   printPreview.printTicketStore_.marginsType.updateValue(
553       print_preview.ticket_items.MarginsType.Value.CUSTOM);
554   printPreview.printTicketStore_.customMargins.updateValue(
555       new print_preview.Margins(0, 36, 36, 36));
557   checkElementDisplayed(
558       $('other-options-settings').querySelector('.header-footer-container'),
559       true);
562 // Test that the color settings are set according to the printer capabilities.
563 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsTrue', function() {
564   var initialSettingsSetEvent =
565       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
566   initialSettingsSetEvent.initialSettings = this.initialSettings_;
567   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
569   var localDestsSetEvent =
570       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
571   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
572   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
574   checkSectionVisible($('color-settings'), true);
576   var capsSetEvent =
577       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
578   capsSetEvent.settingsInfo = {
579     'printerId': 'FooDevice',
580     'disableColorOption': false,
581     'setColorAsDefault': true,
582     'disableCopiesOption': false,
583     'disableLandscapeOption': true,
584     'printerDefaultDuplexValue': 0
585   };
586   this.nativeLayer_.dispatchEvent(capsSetEvent);
588   checkSectionVisible($('color-settings'), true);
590   var colorOption = $('color-settings').querySelector('.color-option');
591   var bwOption = $('color-settings').querySelector('.bw-option');
592   expectTrue(colorOption.checked);
593   expectFalse(bwOption.checked);
596 //Test that the color settings are set according to the printer capabilities.
597 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsFalse', function() {
598   var initialSettingsSetEvent =
599       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
600   initialSettingsSetEvent.initialSettings = this.initialSettings_;
601   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
603   var localDestsSetEvent =
604       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
605   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
606   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
608   checkSectionVisible($('color-settings'), true);
610   var capsSetEvent =
611       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
612   capsSetEvent.settingsInfo = {
613     'printerId': 'FooDevice',
614     'disableColorOption': true,
615     'setColorAsDefault': false,
616     'disableCopiesOption': false,
617     'disableLandscapeOption': true,
618     'printerDefaultDuplexValue': 0
619   };
620   this.nativeLayer_.dispatchEvent(capsSetEvent);
622   checkSectionVisible($('color-settings'), false);
624   var colorOption = $('color-settings').querySelector('.color-option');
625   var bwOption = $('color-settings').querySelector('.bw-option');
626   expectFalse(colorOption.checked);
627   expectTrue(bwOption.checked);
630 // Test to verify that duplex settings are set according to the printer
631 // capabilities.
632 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
633   var initialSettingsSetEvent =
634       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
635   initialSettingsSetEvent.initialSettings = this.initialSettings_;
636   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
638   var localDestsSetEvent =
639       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
640   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
641   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
643   var otherOptionsDiv = $('other-options-settings');
644   var duplexDiv = otherOptionsDiv.querySelector('.duplex-container');
645   var duplexCheckbox = otherOptionsDiv.querySelector('.duplex-checkbox');
647   var capsSetEvent =
648       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
649   capsSetEvent.settingsInfo = {
650     'printerId': 'FooDevice',
651     'disableColorOption': false,
652     'setColorAsDefault': true,
653     'disableCopiesOption': false,
654     'disableLandscapeOption': true,
655     'printerDefaultDuplexValue': 0,
656     'setDuplexAsDefault': false
657   };
658   this.nativeLayer_.dispatchEvent(capsSetEvent);
660   checkSectionVisible(otherOptionsDiv, true);
661   expectFalse(duplexDiv.hidden);
662   expectFalse(duplexCheckbox.checked);
665 //Test to verify that duplex settings are set according to the printer
666 //capabilities.
667 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
668   var initialSettingsSetEvent =
669      new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
670   initialSettingsSetEvent.initialSettings = this.initialSettings_;
671   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
673   var localDestsSetEvent =
674      new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
675   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
676   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
678   var otherOptionsDiv = $('other-options-settings');
679   var duplexDiv = otherOptionsDiv.querySelector('.duplex-container');
681   var capsSetEvent =
682      new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
683   capsSetEvent.settingsInfo = {
684    'printerId': 'FooDevice',
685    'disableColorOption': false,
686    'setColorAsDefault': true,
687    'disableCopiesOption': false,
688    'disableLandscapeOption': true,
689    'printerDefaultDuplexValue': -1,
690    'setDuplexAsDefault': false
691   };
692   this.nativeLayer_.dispatchEvent(capsSetEvent);
694   checkSectionVisible(otherOptionsDiv, true);
695   expectTrue(duplexDiv.hidden);
698 // Test that changing the selected printer updates the preview.
699 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
701   var initialSettingsSetEvent =
702       new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
703   initialSettingsSetEvent.initialSettings = this.initialSettings_;
704   this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
706   var localDestsSetEvent =
707       new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
708   localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
709   this.nativeLayer_.dispatchEvent(localDestsSetEvent);
711   var capsSetEvent =
712       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
713   capsSetEvent.settingsInfo = {
714     'printerId': 'FooDevice',
715     'disableColorOption': false,
716     'setColorAsDefault': true,
717     'disableCopiesOption': true,
718     'disableLandscapeOption': true,
719     'printerDefaultDuplexValue': 0
720   };
721   this.nativeLayer_.dispatchEvent(capsSetEvent);
723   var previewGenerator = mock(print_preview.PreviewGenerator);
724   printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
725   previewGenerator.expects(exactly(6)).requestPreview();
727   var barDestination;
728   var destinations = printPreview.destinationStore_.destinations;
729   for (var destination, i = 0; destination = destinations[i]; i++) {
730     if (destination.id == 'BarDevice') {
731       barDestination = destination;
732       break;
733     }
734   }
736   printPreview.destinationStore_.selectDestination(barDestination);
738   var capsSetEvent =
739       new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
740   capsSetEvent.settingsInfo = {
741     'printerId': 'BarDevice',
742     'disableColorOption': true,
743     'setColorAsDefault': false,
744     'disableCopiesOption': true,
745     'disableLandscapeOption': true,
746     'printerDefaultDuplexValue': 0
747   };
748   this.nativeLayer_.dispatchEvent(capsSetEvent);
751 // Test that error message is displayed when plugin doesn't exist.
752 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
753   var previewAreaEl = $('preview-area');
755   var loadingMessageEl =
756       previewAreaEl.getElementsByClassName('preview-area-loading-message')[0];
757   expectEquals(true, loadingMessageEl.hidden);
759   var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
760       'preview-area-preview-failed-message')[0];
761   expectEquals(true, previewFailedMessageEl.hidden);
763   var printFailedMessageEl =
764       previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
765   expectEquals(true, printFailedMessageEl.hidden);
767   var customMessageEl =
768       previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
769   expectEquals(false, customMessageEl.hidden);