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 * Stub out low-level functionality like the NativeLayer and
50 * CloudPrintInterface.
51 * @this {PrintPreviewWebUITest}
55 window.addEventListener('DOMContentLoaded', function() {
56 function NativeLayerStub() {
57 cr.EventTarget.call(this);
59 NativeLayerStub.prototype = {
60 __proto__: cr.EventTarget.prototype,
61 startGetInitialSettings: function() {},
62 startGetLocalDestinations: function() {},
63 startGetLocalDestinationCapabilities: function(destinationId) {}
65 var oldNativeLayerEventType = print_preview.NativeLayer.EventType;
66 var oldDuplexMode = print_preview.NativeLayer.DuplexMode;
67 print_preview.NativeLayer = NativeLayerStub;
68 print_preview.NativeLayer.EventType = oldNativeLayerEventType;
69 print_preview.NativeLayer.DuplexMode = oldDuplexMode;
71 function CloudPrintInterfaceStub() {
72 cr.EventTarget.call(this);
74 CloudPrintInterfaceStub.prototype = {
75 __proto__: cr.EventTarget.prototype,
76 search: function(isRecent) {}
78 var oldCpInterfaceEventType = cloudprint.CloudPrintInterface.EventType;
79 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
80 cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType;
82 print_preview.PreviewArea.prototype.checkPluginCompatibility_ =
90 * Generate a real C++ class; don't typedef.
94 typedefCppFixture: null,
97 * @this {PrintPreviewWebUITest}
101 Mock4JS.clearMocksToVerify();
103 this.initialSettings_ = new print_preview.NativeInitialSettings(
104 false /*isInKioskAutoPrintMode*/,
105 false /*hidePrintWithSystemDialogLink*/,
106 ',' /*thousandsDelimeter*/,
107 '.' /*decimalDelimeter*/,
109 true /*isDocumentModifiable*/,
110 'title' /*documentTitle*/,
111 true /*documentHasSelection*/,
112 false /*selectionOnly*/,
113 'FooDevice' /*systemDefaultDestinationId*/,
114 null /*serializedAppStateStr*/,
115 false /*documentHasSelection*/);
116 this.localDestinationInfos_ = [
117 { printerName: 'FooName', deviceName: 'FooDevice' },
118 { printerName: 'BarName', deviceName: 'BarDevice' }
120 this.nativeLayer_ = printPreview.nativeLayer_;
124 GEN('#include "chrome/test/data/webui/print_preview.h"');
126 // Test some basic assumptions about the print preview WebUI.
127 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
128 var initialSettingsSetEvent =
129 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
130 initialSettingsSetEvent.initialSettings = this.initialSettings_;
131 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
133 var localDestsSetEvent =
134 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
135 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
136 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
138 var recentList = $('destination-search').querySelector('.recent-list ul');
139 var localList = $('destination-search').querySelector('.local-list ul');
140 assertNotEquals(null, recentList);
141 assertEquals(1, recentList.childNodes.length);
142 assertEquals('FooName',
143 recentList.childNodes.item(0).querySelector(
144 '.destination-list-item-name').textContent);
146 assertNotEquals(null, localList);
147 assertEquals(3, localList.childNodes.length);
148 assertEquals('Save as PDF',
149 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
150 querySelector('.destination-list-item-name').textContent);
151 assertEquals('FooName',
152 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
153 querySelector('.destination-list-item-name').textContent);
154 assertEquals('BarName',
155 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
156 querySelector('.destination-list-item-name').textContent);
159 // Test that the printer list is structured correctly after calling
160 // addCloudPrinters with an empty list.
161 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
162 var initialSettingsSetEvent =
163 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
164 initialSettingsSetEvent.initialSettings = this.initialSettings_;
165 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
167 var localDestsSetEvent =
168 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
169 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
170 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
172 var cloudPrintEnableEvent =
173 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
174 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
175 this.nativeLayer_.dispatchEvent(cloudPrintEnableEvent);
177 var searchDoneEvent =
178 new Event(cloudprint.CloudPrintInterface.EventType.SEARCH_DONE);
179 searchDoneEvent.printers = [];
180 searchDoneEvent.isRecent = true;
181 searchDoneEvent.email = 'foo@chromium.org';
182 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent);
184 var recentList = $('destination-search').querySelector('.recent-list ul');
185 var localList = $('destination-search').querySelector('.local-list ul');
186 var cloudList = $('destination-search').querySelector('.cloud-list ul');
188 assertNotEquals(null, recentList);
189 assertEquals(1, recentList.childNodes.length);
190 assertEquals('FooName',
191 recentList.childNodes.item(0).querySelector(
192 '.destination-list-item-name').textContent);
194 assertNotEquals(null, localList);
195 assertEquals(3, localList.childNodes.length);
196 assertEquals('Save as PDF',
197 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
198 querySelector('.destination-list-item-name').textContent);
199 assertEquals('FooName',
200 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
201 querySelector('.destination-list-item-name').textContent);
202 assertEquals('BarName',
203 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
204 querySelector('.destination-list-item-name').textContent);
206 assertNotEquals(null, cloudList);
207 assertEquals(0, cloudList.childNodes.length);
211 * Verify that |section| visibility matches |visible|.
212 * @param {HTMLDivElement} section The section to check.
213 * @param {boolean} visible The expected state of visibility.
215 function checkSectionVisible(section, visible) {
216 assertNotEquals(null, section);
218 visible, section.classList.contains('visible'), 'section=' + section.id);
221 function checkElementDisplayed(el, isDisplayed) {
222 assertNotEquals(null, el);
223 expectEquals(isDisplayed, !el.hidden);
226 // Test that disabled settings hide the disabled sections.
227 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
228 checkSectionVisible($('layout-settings'), true);
229 checkSectionVisible($('color-settings'), true);
230 checkSectionVisible($('copies-settings'), true);
232 var initialSettingsSetEvent =
233 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
234 initialSettingsSetEvent.initialSettings = this.initialSettings_;
235 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
237 var localDestsSetEvent =
238 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
239 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
240 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
243 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
244 capsSetEvent.settingsInfo = {
245 'printerId': 'FooDevice',
246 'disableColorOption': true,
247 'setColorAsDefault': true,
248 'disableCopiesOption': true,
249 'disableLandscapeOption': true,
250 'printerDefaultDuplexValue': 0
252 this.nativeLayer_.dispatchEvent(capsSetEvent);
254 checkSectionVisible($('layout-settings'), false);
255 checkSectionVisible($('color-settings'), false);
256 checkSectionVisible($('copies-settings'), false);
259 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
260 // fit to page option.
261 TEST_F('PrintPreviewWebUITest',
262 'PrintToPDFSelectedHideFitToPageOption',
265 this.initialSettings_.isDocumentModifiable_ = false;
266 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
267 this.localDestinationInfos_.push(
268 {printerName: 'Save as PDF', deviceName: 'Save as PDF'});
270 var initialSettingsSetEvent =
271 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
272 initialSettingsSetEvent.initialSettings = this.initialSettings_;
273 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
275 var localDestsSetEvent =
276 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
277 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
278 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
281 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
282 capsSetEvent.settingsInfo = {
283 'printerId': 'FooDevice',
284 'disableColorOption': false,
285 'setColorAsDefault': true,
286 'disableCopiesOption': true,
287 'disableLandscapeOption': true,
288 'printerDefaultDuplexValue': 0
290 this.nativeLayer_.dispatchEvent(capsSetEvent);
292 checkElementDisplayed(
293 $('other-options-settings').querySelector('.fit-to-page-container'),
297 // When the source is 'HTML', we always hide the fit to page option.
298 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLHideFitToPageOption', function() {
299 var initialSettingsSetEvent =
300 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
301 initialSettingsSetEvent.initialSettings = this.initialSettings_;
302 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
304 var localDestsSetEvent =
305 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
306 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
307 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
310 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
311 capsSetEvent.settingsInfo = {
312 'printerId': 'FooDevice',
313 'disableColorOption': false,
314 'setColorAsDefault': true,
315 'disableCopiesOption': true,
316 'disableLandscapeOption': true,
317 'printerDefaultDuplexValue': 0
319 this.nativeLayer_.dispatchEvent(capsSetEvent);
321 checkElementDisplayed(
322 $('other-options-settings').querySelector('.fit-to-page-container'),
326 // When the source is "PDF", depending on the selected destination printer, we
327 // show/hide the fit to page option.
328 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFShowFitToPageOption', function() {
329 this.initialSettings_.isDocumentModifiable_ = false;
331 var initialSettingsSetEvent =
332 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
333 initialSettingsSetEvent.initialSettings = this.initialSettings_;
334 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
336 var localDestsSetEvent =
337 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
338 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
339 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
342 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
343 capsSetEvent.settingsInfo = {
344 'printerId': 'FooDevice',
345 'disableColorOption': false,
346 'setColorAsDefault': true,
347 'disableCopiesOption': true,
348 'disableLandscapeOption': true,
349 'printerDefaultDuplexValue': 0
351 this.nativeLayer_.dispatchEvent(capsSetEvent);
353 checkElementDisplayed(
354 $('other-options-settings').querySelector('.fit-to-page-container'),
357 $('other-options-settings').querySelector('.fit-to-page-checkbox').
361 // When the print scaling is disabled for the source "PDF", we show the fit
362 // to page option but the state is unchecked by default.
363 TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
364 this.initialSettings_.isDocumentModifiable_ = false;
366 var initialSettingsSetEvent =
367 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
368 initialSettingsSetEvent.initialSettings = this.initialSettings_;
369 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
371 var localDestsSetEvent =
372 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
373 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
374 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
377 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
378 capsSetEvent.settingsInfo = {
379 'printerId': 'FooDevice',
380 'disableColorOption': false,
381 'setColorAsDefault': true,
382 'disableCopiesOption': true,
383 'disableLandscapeOption': true,
384 'printerDefaultDuplexValue': 0
386 this.nativeLayer_.dispatchEvent(capsSetEvent);
388 // Indicate that the PDF does not support scaling by default.
389 cr.dispatchSimpleEvent(
390 this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING);
392 checkElementDisplayed(
393 $('other-options-settings').querySelector('.fit-to-page-container'),
396 $('other-options-settings').querySelector('.fit-to-page-checkbox').
400 // Page layout has zero margins. Hide header and footer option.
401 TEST_F('PrintPreviewWebUITest',
402 'PageLayoutHasNoMarginsHideHeaderFooter',
404 var initialSettingsSetEvent =
405 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
406 initialSettingsSetEvent.initialSettings = this.initialSettings_;
407 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
409 var localDestsSetEvent =
410 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
411 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
412 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
415 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
416 capsSetEvent.settingsInfo = {
417 'printerId': 'FooDevice',
418 'disableColorOption': false,
419 'setColorAsDefault': true,
420 'disableCopiesOption': true,
421 'disableLandscapeOption': true,
422 'printerDefaultDuplexValue': 0
424 this.nativeLayer_.dispatchEvent(capsSetEvent);
426 checkElementDisplayed(
427 $('other-options-settings').querySelector('.header-footer-container'),
430 printPreview.printTicketStore_.marginsType.updateValue(
431 print_preview.ticket_items.MarginsType.Value.CUSTOM);
432 printPreview.printTicketStore_.customMargins.updateValue(
433 new print_preview.Margins(0, 0, 0, 0));
435 checkElementDisplayed(
436 $('other-options-settings').querySelector('.header-footer-container'),
440 // Page layout has half-inch margins. Show header and footer option.
441 TEST_F('PrintPreviewWebUITest',
442 'PageLayoutHasMarginsShowHeaderFooter',
444 var initialSettingsSetEvent =
445 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
446 initialSettingsSetEvent.initialSettings = this.initialSettings_;
447 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
449 var localDestsSetEvent =
450 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
451 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
452 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
455 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
456 capsSetEvent.settingsInfo = {
457 'printerId': 'FooDevice',
458 'disableColorOption': false,
459 'setColorAsDefault': true,
460 'disableCopiesOption': true,
461 'disableLandscapeOption': true,
462 'printerDefaultDuplexValue': 0
464 this.nativeLayer_.dispatchEvent(capsSetEvent);
466 checkElementDisplayed(
467 $('other-options-settings').querySelector('.header-footer-container'),
470 printPreview.printTicketStore_.marginsType.updateValue(
471 print_preview.ticket_items.MarginsType.Value.CUSTOM);
472 printPreview.printTicketStore_.customMargins.updateValue(
473 new print_preview.Margins(36, 36, 36, 36));
475 checkElementDisplayed(
476 $('other-options-settings').querySelector('.header-footer-container'),
480 // Page layout has zero top and bottom margins. Hide header and footer option.
481 TEST_F('PrintPreviewWebUITest',
482 'ZeroTopAndBottomMarginsHideHeaderFooter',
484 var initialSettingsSetEvent =
485 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
486 initialSettingsSetEvent.initialSettings = this.initialSettings_;
487 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
489 var localDestsSetEvent =
490 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
491 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
492 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
495 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
496 capsSetEvent.settingsInfo = {
497 'printerId': 'FooDevice',
498 'disableColorOption': false,
499 'setColorAsDefault': true,
500 'disableCopiesOption': true,
501 'disableLandscapeOption': true,
502 'printerDefaultDuplexValue': 0
504 this.nativeLayer_.dispatchEvent(capsSetEvent);
506 checkElementDisplayed(
507 $('other-options-settings').querySelector('.header-footer-container'),
510 printPreview.printTicketStore_.marginsType.updateValue(
511 print_preview.ticket_items.MarginsType.Value.CUSTOM);
512 printPreview.printTicketStore_.customMargins.updateValue(
513 new print_preview.Margins(0, 36, 0, 36));
515 checkElementDisplayed(
516 $('other-options-settings').querySelector('.header-footer-container'),
520 // Page layout has zero top and half-inch bottom margin. Show header and footer
522 TEST_F('PrintPreviewWebUITest',
523 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
525 var initialSettingsSetEvent =
526 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
527 initialSettingsSetEvent.initialSettings = this.initialSettings_;
528 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
530 var localDestsSetEvent =
531 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
532 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
533 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
536 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
537 capsSetEvent.settingsInfo = {
538 'printerId': 'FooDevice',
539 'disableColorOption': false,
540 'setColorAsDefault': true,
541 'disableCopiesOption': true,
542 'disableLandscapeOption': true,
543 'printerDefaultDuplexValue': 0
545 this.nativeLayer_.dispatchEvent(capsSetEvent);
547 checkElementDisplayed(
548 $('other-options-settings').querySelector('.header-footer-container'),
551 printPreview.printTicketStore_.marginsType.updateValue(
552 print_preview.ticket_items.MarginsType.Value.CUSTOM);
553 printPreview.printTicketStore_.customMargins.updateValue(
554 new print_preview.Margins(0, 36, 36, 36));
556 checkElementDisplayed(
557 $('other-options-settings').querySelector('.header-footer-container'),
561 // Test that the color settings are set according to the printer capabilities.
562 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsTrue', function() {
563 var initialSettingsSetEvent =
564 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
565 initialSettingsSetEvent.initialSettings = this.initialSettings_;
566 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
568 var localDestsSetEvent =
569 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
570 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
571 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
573 checkSectionVisible($('color-settings'), true);
576 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
577 capsSetEvent.settingsInfo = {
578 'printerId': 'FooDevice',
579 'disableColorOption': false,
580 'setColorAsDefault': true,
581 'disableCopiesOption': false,
582 'disableLandscapeOption': true,
583 'printerDefaultDuplexValue': 0
585 this.nativeLayer_.dispatchEvent(capsSetEvent);
587 checkSectionVisible($('color-settings'), true);
589 var colorOption = $('color-settings').querySelector('.color-option');
590 var bwOption = $('color-settings').querySelector('.bw-option');
591 expectTrue(colorOption.checked);
592 expectFalse(bwOption.checked);
595 //Test that the color settings are set according to the printer capabilities.
596 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsFalse', function() {
597 var initialSettingsSetEvent =
598 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
599 initialSettingsSetEvent.initialSettings = this.initialSettings_;
600 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
602 var localDestsSetEvent =
603 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
604 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
605 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
607 checkSectionVisible($('color-settings'), true);
610 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
611 capsSetEvent.settingsInfo = {
612 'printerId': 'FooDevice',
613 'disableColorOption': true,
614 'setColorAsDefault': false,
615 'disableCopiesOption': false,
616 'disableLandscapeOption': true,
617 'printerDefaultDuplexValue': 0
619 this.nativeLayer_.dispatchEvent(capsSetEvent);
621 checkSectionVisible($('color-settings'), false);
623 var colorOption = $('color-settings').querySelector('.color-option');
624 var bwOption = $('color-settings').querySelector('.bw-option');
625 expectFalse(colorOption.checked);
626 expectTrue(bwOption.checked);
629 // Test to verify that duplex settings are set according to the printer
631 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
632 var initialSettingsSetEvent =
633 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
634 initialSettingsSetEvent.initialSettings = this.initialSettings_;
635 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
637 var localDestsSetEvent =
638 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
639 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
640 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
642 var otherOptionsDiv = $('other-options-settings');
643 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container');
644 var duplexCheckbox = otherOptionsDiv.querySelector('.duplex-checkbox');
647 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
648 capsSetEvent.settingsInfo = {
649 'printerId': 'FooDevice',
650 'disableColorOption': false,
651 'setColorAsDefault': true,
652 'disableCopiesOption': false,
653 'disableLandscapeOption': true,
654 'printerDefaultDuplexValue': 0,
655 'setDuplexAsDefault': false
657 this.nativeLayer_.dispatchEvent(capsSetEvent);
659 checkSectionVisible(otherOptionsDiv, true);
660 expectFalse(duplexDiv.hidden);
661 expectFalse(duplexCheckbox.checked);
664 //Test to verify that duplex settings are set according to the printer
666 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
667 var initialSettingsSetEvent =
668 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
669 initialSettingsSetEvent.initialSettings = this.initialSettings_;
670 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
672 var localDestsSetEvent =
673 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
674 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
675 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
677 var otherOptionsDiv = $('other-options-settings');
678 var duplexDiv = otherOptionsDiv.querySelector('.duplex-container');
681 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
682 capsSetEvent.settingsInfo = {
683 'printerId': 'FooDevice',
684 'disableColorOption': false,
685 'setColorAsDefault': true,
686 'disableCopiesOption': false,
687 'disableLandscapeOption': true,
688 'printerDefaultDuplexValue': -1,
689 'setDuplexAsDefault': false
691 this.nativeLayer_.dispatchEvent(capsSetEvent);
693 checkSectionVisible(otherOptionsDiv, true);
694 expectTrue(duplexDiv.hidden);
697 // Test that changing the selected printer updates the preview.
698 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
700 var initialSettingsSetEvent =
701 new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
702 initialSettingsSetEvent.initialSettings = this.initialSettings_;
703 this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
705 var localDestsSetEvent =
706 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
707 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
708 this.nativeLayer_.dispatchEvent(localDestsSetEvent);
711 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
712 capsSetEvent.settingsInfo = {
713 'printerId': 'FooDevice',
714 'disableColorOption': false,
715 'setColorAsDefault': true,
716 'disableCopiesOption': true,
717 'disableLandscapeOption': true,
718 'printerDefaultDuplexValue': 0
720 this.nativeLayer_.dispatchEvent(capsSetEvent);
722 var previewGenerator = mock(print_preview.PreviewGenerator);
723 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
724 previewGenerator.expects(exactly(6)).requestPreview();
727 var destinations = printPreview.destinationStore_.destinations;
728 for (var destination, i = 0; destination = destinations[i]; i++) {
729 if (destination.id == 'BarDevice') {
730 barDestination = destination;
735 printPreview.destinationStore_.selectDestination(barDestination);
738 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
739 capsSetEvent.settingsInfo = {
740 'printerId': 'BarDevice',
741 'disableColorOption': true,
742 'setColorAsDefault': false,
743 'disableCopiesOption': true,
744 'disableLandscapeOption': true,
745 'printerDefaultDuplexValue': 0
747 this.nativeLayer_.dispatchEvent(capsSetEvent);
750 // Test that error message is displayed when plugin doesn't exist.
751 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
752 var previewAreaEl = $('preview-area');
754 var loadingMessageEl =
755 previewAreaEl.getElementsByClassName('preview-area-loading-message')[0];
756 expectEquals(true, loadingMessageEl.hidden);
758 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
759 'preview-area-preview-failed-message')[0];
760 expectEquals(true, previewFailedMessageEl.hidden);
762 var printFailedMessageEl =
763 previewAreaEl.getElementsByClassName('preview-area-print-failed')[0];
764 expectEquals(true, printFailedMessageEl.hidden);
766 var customMessageEl =
767 previewAreaEl.getElementsByClassName('preview-area-custom-message')[0];
768 expectEquals(false, customMessageEl.hidden);