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 startGetPrivetDestinations: function() {},
64 startGetLocalDestinationCapabilities: function(destinationId) {}
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);
75 CloudPrintInterfaceStub.prototype = {
76 __proto__: cr.EventTarget.prototype,
77 search: function(isRecent) {}
79 var oldCpInterfaceEventType = cloudprint.CloudPrintInterface.EventType;
80 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
81 cloudprint.CloudPrintInterface.EventType = oldCpInterfaceEventType;
83 print_preview.PreviewArea.prototype.checkPluginCompatibility_ =
91 * Generate a real C++ class; don't typedef.
95 typedefCppFixture: null,
98 * @this {PrintPreviewWebUITest}
102 Mock4JS.clearMocksToVerify();
104 this.initialSettings_ = new print_preview.NativeInitialSettings(
105 false /*isInKioskAutoPrintMode*/,
106 false /*hidePrintWithSystemDialogLink*/,
107 ',' /*thousandsDelimeter*/,
108 '.' /*decimalDelimeter*/,
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' }
121 this.nativeLayer_ = printPreview.nativeLayer_;
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.
216 function checkSectionVisible(section, visible) {
217 assertNotEquals(null, section);
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);
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
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',
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);
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
291 this.nativeLayer_.dispatchEvent(capsSetEvent);
293 checkElementDisplayed(
294 $('other-options-settings').querySelector('.fit-to-page-container'),
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);
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
320 this.nativeLayer_.dispatchEvent(capsSetEvent);
322 checkElementDisplayed(
323 $('other-options-settings').querySelector('.fit-to-page-container'),
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);
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
352 this.nativeLayer_.dispatchEvent(capsSetEvent);
354 checkElementDisplayed(
355 $('other-options-settings').querySelector('.fit-to-page-container'),
358 $('other-options-settings').querySelector('.fit-to-page-checkbox').
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);
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
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'),
397 $('other-options-settings').querySelector('.fit-to-page-checkbox').
401 // Page layout has zero margins. Hide header and footer option.
402 TEST_F('PrintPreviewWebUITest',
403 'PageLayoutHasNoMarginsHideHeaderFooter',
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);
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
425 this.nativeLayer_.dispatchEvent(capsSetEvent);
427 checkElementDisplayed(
428 $('other-options-settings').querySelector('.header-footer-container'),
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'),
441 // Page layout has half-inch margins. Show header and footer option.
442 TEST_F('PrintPreviewWebUITest',
443 'PageLayoutHasMarginsShowHeaderFooter',
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);
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
465 this.nativeLayer_.dispatchEvent(capsSetEvent);
467 checkElementDisplayed(
468 $('other-options-settings').querySelector('.header-footer-container'),
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'),
481 // Page layout has zero top and bottom margins. Hide header and footer option.
482 TEST_F('PrintPreviewWebUITest',
483 'ZeroTopAndBottomMarginsHideHeaderFooter',
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);
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
505 this.nativeLayer_.dispatchEvent(capsSetEvent);
507 checkElementDisplayed(
508 $('other-options-settings').querySelector('.header-footer-container'),
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'),
521 // Page layout has zero top and half-inch bottom margin. Show header and footer
523 TEST_F('PrintPreviewWebUITest',
524 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
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);
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
546 this.nativeLayer_.dispatchEvent(capsSetEvent);
548 checkElementDisplayed(
549 $('other-options-settings').querySelector('.header-footer-container'),
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'),
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);
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
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);
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
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
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');
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
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
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');
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
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);
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
721 this.nativeLayer_.dispatchEvent(capsSetEvent);
723 var previewGenerator = mock(print_preview.PreviewGenerator);
724 printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy();
725 previewGenerator.expects(exactly(6)).requestPreview();
728 var destinations = printPreview.destinationStore_.destinations;
729 for (var destination, i = 0; destination = destinations[i]; i++) {
730 if (destination.id == 'BarDevice') {
731 barDestination = destination;
736 printPreview.destinationStore_.selectDestination(barDestination);
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
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);