Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: chrome/test/data/webui/print_preview.js

Issue 2893003003: Print Preview: Merge NativeLayerStubs for tests (Closed)
Patch Set: Remove extra variable Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 var ROOT_PATH = '../../../../';
6
7 /**
8 * Test fixture for print preview WebUI testing.
9 * @constructor
10 * @extends {testing.Test}
11 */
12 function PrintPreviewWebUITest() {
13 testing.Test.call(this);
14 this.printPreview_ = null;
15 this.nativeLayer_ = null;
16 this.initialSettings_ = null;
17 this.localDestinationInfos_ = null;
18 this.previewArea_ = null;
19 }
20
21 /**
22 * Index of the "Save as PDF" printer.
23 * @type {number}
24 * @const
25 */
26 PrintPreviewWebUITest.PDF_INDEX = 0;
27
28 /**
29 * Index of the Foo printer.
30 * @type {number}
31 * @const
32 */
33 PrintPreviewWebUITest.FOO_INDEX = 1;
34
35 /**
36 * Index of the Bar printer.
37 * @type {number}
38 * @const
39 */
40 PrintPreviewWebUITest.BAR_INDEX = 2;
41
42 PrintPreviewWebUITest.prototype = {
43 __proto__: testing.Test.prototype,
44
45 /**
46 * Browse to the sample page, cause print preview & call preLoad().
47 * @type {string}
48 * @override
49 */
50 browsePrintPreload: 'print_preview_hello_world_test.html',
51
52 /** @override */
53 runAccessibilityChecks: true,
54
55 /** @override */
56 accessibilityIssuesAreErrors: true,
57
58 /** @override */
59 isAsync: true,
60
61 /**
62 * Stub out low-level functionality like the NativeLayer and
63 * CloudPrintInterface.
64 * @this {PrintPreviewWebUITest}
65 * @override
66 */
67 preLoad: function() {
68 window.isTest = true;
69 window.addEventListener('DOMContentLoaded', function() {
70 /**
71 * Test version of the native layer.
72 * @constructor
73 * @extends {settings.TestBrowserProxy}
74 */
75 function NativeLayerStub() {
76 settings.TestBrowserProxy.call(this, [ 'getInitialSettings' ]);
77 this.eventTarget_ = new cr.EventTarget();
78 this.printStarted_ = false;
79 this.generateDraft_ = false;
80 this.initialSettings_ = null;
81 }
82 NativeLayerStub.prototype = {
83 __proto__: settings.TestBrowserProxy.prototype,
84 getEventTarget: function() { return this.eventTarget_; },
85 isPrintStarted: function() { return this.printStarted_; },
86 generateDraft: function() { return this.generateDraft_; },
87 getInitialSettings: function() {
88 this.methodCalled('getInitialSettings');
89 return Promise.resolve(this.initialSettings_);
90 },
91 previewReadyForTest: function() {},
92 startGetLocalDestinations: function() {},
93 startGetPrivetDestinations: function() {},
94 startGetExtensionDestinations: function() {},
95 startGetLocalDestinationCapabilities: function(destinationId) {},
96 startGetPreview: function(destination, printTicketStore, documentInfo,
97 generateDraft, requestId) {
98 this.generateDraft_ = generateDraft;
99 },
100 startHideDialog: function () {},
101 startPrint: function () { this.printStarted_ = true; }
102 };
103 var oldNativeLayerEventType = print_preview.NativeLayer.EventType;
104 var oldDuplexMode = print_preview.NativeLayer.DuplexMode;
105 print_preview.NativeLayer = NativeLayerStub;
106 print_preview.NativeLayer.EventType = oldNativeLayerEventType;
107 print_preview.NativeLayer.DuplexMode = oldDuplexMode;
108
109 function CloudPrintInterfaceStub() {
110 cr.EventTarget.call(this);
111 }
112 CloudPrintInterfaceStub.prototype = {
113 __proto__: cr.EventTarget.prototype,
114 search: function(isRecent) {}
115 };
116 var oldCpInterfaceEventType = cloudprint.CloudPrintInterfaceEventType;
117 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub;
118 cloudprint.CloudPrintInterfaceEventType = oldCpInterfaceEventType;
119
120 print_preview.PreviewArea.prototype.checkPluginCompatibility_ =
121 function() {
122 return false;
123 };
124 }.bind(this));
125 },
126
127 extraLibraries: [
128 ROOT_PATH + 'ui/webui/resources/js/cr.js',
129 ROOT_PATH + 'ui/webui/resources/js/promise_resolver.js',
130 ROOT_PATH + 'ui/webui/resources/js/util.js',
131 ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js',
132 ],
133
134 /**
135 * Creates an instance of print_preview.PrintPreview and initializes the
136 * |nativeLayer_| and |previewArea_|.
137 */
138 createPrintPreview: function() {
139 this.printPreview_ = new print_preview.PrintPreview();
140 this.nativeLayer_ = this.printPreview_.nativeLayer_;
141 this.previewArea_ = this.printPreview_.previewArea_;
142 },
143
144 /**
145 * Initialize print preview with the initial settings currently stored in
146 * |this.initialSettings_|. Creates |this.printPreview_| if it does not
147 * already exist.
148 */
149 setInitialSettings: function() {
150 if (!this.printPreview_) {
151 this.printPreview_ = new print_preview.PrintPreview();
152 this.nativeLayer_ = this.printPreview_.nativeLayer_;
153 this.previewArea_ = this.printPreview_.previewArea_;
154 }
155 this.nativeLayer_.initialSettings_ = this.initialSettings_;
156 this.printPreview_.initialize();
157 testing.Test.disableAnimationsAndTransitions();
158 // Enable when failure is resolved.
159 // AX_TEXT_03: http://crbug.com/559209
160 this.accessibilityAuditConfig.ignoreSelectors(
161 'multipleLabelableElementsPerLabel',
162 '#page-settings > .right-column > *');
163 },
164
165 /**
166 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will
167 * happen in the same thread.
168 */
169 setLocalDestinations: function() {
170 var localDestsSetEvent =
171 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
172 localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
173 this.nativeLayer_.getEventTarget().dispatchEvent(localDestsSetEvent);
174 },
175
176 /**
177 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will
178 * happen in the same thread.
179 * @device - The device whose capabilities should be dispatched.
180 */
181 setCapabilities: function(device) {
182 var capsSetEvent =
183 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
184 capsSetEvent.settingsInfo = device;
185 this.nativeLayer_.getEventTarget().dispatchEvent(capsSetEvent);
186 },
187
188 /**
189 * Dispatch the PREVIEW_GENERATION_DONE event. This call is NOT async and
190 * will happen in the same thread.
191 */
192 dispatchPreviewDone: function() {
193 var previewDoneEvent =
194 new Event(print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE);
195 this.previewArea_.dispatchEvent(previewDoneEvent);
196 },
197
198 /**
199 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will
200 * happen in the same thread.
201 */
202 dispatchInvalidSettings: function() {
203 var invalidSettingsEvent =
204 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID);
205 this.nativeLayer_.getEventTarget().dispatchEvent(invalidSettingsEvent);
206 },
207
208 /**
209 * @return {boolean} Whether the UI has "printed" or not. (called startPrint
210 * on the native layer)
211 */
212 hasPrinted: function() {
213 return this.nativeLayer_.isPrintStarted();
214 },
215
216 /**
217 * @return {boolean} Whether the UI is "generating draft" in the most recent
218 * preview. (checking the result of the startGetPreview call in the native
219 * layer)
220 */
221 generateDraft: function() {
222 return this.nativeLayer_.generateDraft();
223 },
224
225 /**
226 * Even though animation duration and delay is set to zero, it is necessary to
227 * wait until the animation has finished.
228 */
229 waitForAnimationToEnd: function(elementId) {
230 // add a listener for the animation end event
231 document.addEventListener('animationend', function f(e) {
232 if (e.target.id == elementId) {
233 document.removeEventListener(f, 'animationend');
234 testDone();
235 }
236 });
237 },
238
239 /**
240 * Expand the 'More Settings' div to expose all options.
241 */
242 expandMoreSettings: function() {
243 var moreSettings = $('more-settings');
244 checkSectionVisible(moreSettings, true);
245 moreSettings.click();
246 },
247
248 /**
249 * Repeated setup steps for the advanced settings tests.
250 * Disables accessiblity errors, sets initial settings, and verifies
251 * advanced options section is visible after expanding more settings.
252 */
253 setupAdvancedSettingsTest: function(device) {
254 // Need to disable this since overlay animation will not fully complete.
255 this.setLocalDestinations();
256 this.setCapabilities(device);
257 this.expandMoreSettings();
258
259 // Check that the advanced options settings section is visible.
260 checkSectionVisible($('advanced-options-settings'), true);
261 },
262
263 /**
264 * @this {PrintPreviewWebUITest}
265 * @override
266 */
267 setUp: function() {
268 testing.Test.prototype.setUp.call(this);
269 Mock4JS.clearMocksToVerify();
270
271 this.initialSettings_ = new print_preview.NativeInitialSettings(
272 false /*isInKioskAutoPrintMode*/,
273 false /*isInAppKioskMode*/,
274 ',' /*thousandsDelimeter*/,
275 '.' /*decimalDelimeter*/,
276 1 /*unitType*/,
277 true /*isDocumentModifiable*/,
278 'title' /*documentTitle*/,
279 true /*documentHasSelection*/,
280 false /*selectionOnly*/,
281 'FooDevice' /*systemDefaultDestinationId*/,
282 null /*serializedAppStateStr*/,
283 null /*serializedDefaultDestinationSelectionRulesStr*/);
284 this.localDestinationInfos_ = [
285 { printerName: 'FooName', deviceName: 'FooDevice' },
286 { printerName: 'BarName', deviceName: 'BarDevice' }
287 ];
288 },
289 };
290
291 // Test some basic assumptions about the print preview WebUI.
292 TEST_F('PrintPreviewWebUITest', 'TestPrinterList', function() {
293 this.setInitialSettings();
294 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
295 function() {
296 this.setLocalDestinations();
297 var recentList =
298 $('destination-search').querySelector('.recent-list ul');
299 var localList =
300 $('destination-search').querySelector('.local-list ul');
301 assertNotEquals(null, recentList);
302 assertEquals(1, recentList.childNodes.length);
303 assertEquals('FooName',
304 recentList.childNodes.item(0).querySelector(
305 '.destination-list-item-name').textContent);
306 assertNotEquals(null, localList);
307 assertEquals(3, localList.childNodes.length);
308 assertEquals('Save as PDF',
309 localList.childNodes.item(PrintPreviewWebUITest.PDF_INDEX).
310 querySelector('.destination-list-item-name').textContent);
311 assertEquals('FooName',
312 localList.childNodes.item(PrintPreviewWebUITest.FOO_INDEX).
313 querySelector('.destination-list-item-name').textContent);
314 assertEquals('BarName',
315 localList.childNodes.item(PrintPreviewWebUITest.BAR_INDEX).
316 querySelector('.destination-list-item-name').textContent);
317 testDone();
318 }.bind(this));
319 });
320
321 // Test that the printer list is structured correctly after calling
322 // addCloudPrinters with an empty list.
323 TEST_F('PrintPreviewWebUITest', 'TestPrinterListCloudEmpty', function() {
324 this.setInitialSettings();
325
326 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
327 function() {
328 this.setLocalDestinations();
329
330 var cloudPrintEnableEvent =
331 new Event(print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE);
332 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url';
333 this.nativeLayer_.getEventTarget().dispatchEvent(
334 cloudPrintEnableEvent);
335
336 var searchDoneEvent =
337 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE);
338 searchDoneEvent.printers = [];
339 searchDoneEvent.isRecent = true;
340 searchDoneEvent.email = 'foo@chromium.org';
341 this.printPreview_.cloudPrintInterface_.dispatchEvent(searchDoneEvent);
342
343 var recentList =
344 $('destination-search').querySelector('.recent-list ul');
345 var localList =
346 $('destination-search').querySelector('.local-list ul');
347 var cloudList =
348 $('destination-search').querySelector('.cloud-list ul');
349
350 assertNotEquals(null, recentList);
351 assertEquals(1, recentList.childNodes.length);
352 assertEquals('FooName',
353 recentList.childNodes.item(0).
354 querySelector('.destination-list-item-name').
355 textContent);
356
357 assertNotEquals(null, localList);
358 assertEquals(3, localList.childNodes.length);
359 assertEquals('Save as PDF',
360 localList.childNodes.item(
361 PrintPreviewWebUITest.PDF_INDEX).
362 querySelector('.destination-list-item-name').
363 textContent);
364 assertEquals('FooName',
365 localList.childNodes.
366 item(PrintPreviewWebUITest.FOO_INDEX).
367 querySelector('.destination-list-item-name').
368 textContent);
369 assertEquals('BarName',
370 localList.childNodes.
371 item(PrintPreviewWebUITest.BAR_INDEX).
372 querySelector('.destination-list-item-name').
373 textContent);
374
375 assertNotEquals(null, cloudList);
376 assertEquals(0, cloudList.childNodes.length);
377
378 testDone();
379 }.bind(this));
380 });
381
382 /**
383 * Verify that |section| visibility matches |visible|.
384 * @param {HTMLDivElement} section The section to check.
385 * @param {boolean} visible The expected state of visibility.
386 */
387 function checkSectionVisible(section, visible) {
388 assertNotEquals(null, section);
389 expectEquals(
390 visible, section.classList.contains('visible'), 'section=' + section.id);
391 }
392
393 function checkElementDisplayed(el, isDisplayed) {
394 assertNotEquals(null, el);
395 expectEquals(isDisplayed,
396 !el.hidden,
397 'element="' + el.id + '" of class "' + el.classList + '"');
398 }
399
400 function getCddTemplate(printerId) {
401 return {
402 printerId: printerId,
403 capabilities: {
404 version: '1.0',
405 printer: {
406 supported_content_type: [{content_type: 'application/pdf'}],
407 collate: {},
408 color: {
409 option: [
410 {type: 'STANDARD_COLOR', is_default: true},
411 {type: 'STANDARD_MONOCHROME'}
412 ]
413 },
414 copies: {},
415 duplex: {
416 option: [
417 {type: 'NO_DUPLEX', is_default: true},
418 {type: 'LONG_EDGE'},
419 {type: 'SHORT_EDGE'}
420 ]
421 },
422 page_orientation: {
423 option: [
424 {type: 'PORTRAIT', is_default: true},
425 {type: 'LANDSCAPE'},
426 {type: 'AUTO'}
427 ]
428 },
429 media_size: {
430 option: [
431 { name: 'NA_LETTER',
432 width_microns: 215900,
433 height_microns: 279400,
434 is_default: true
435 }
436 ]
437 }
438 }
439 }
440 };
441 }
442
443 function isPrintAsImageEnabled() {
444 // Should be enabled by default on non Windows/Mac
445 return (!cr.isWindows && !cr.isMac &&
446 loadTimeData.getBoolean('printPdfAsImageEnabled'));
447 }
448
449 // Test restore settings with one destination.
450 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreLocalDestination',
451 function() {
452 this.initialSettings_.serializedAppStateStr_ =
453 '{"version":2,"recentDestinations":[{"id":"ID", "origin":"local",' +
454 '"account":"", "capabilities":0, "name":"", "extensionId":"",' +
455 '"extensionName":""}]}';
456
457 this.setInitialSettings();
458 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
459 function() {
460 testDone();
461 });
462 });
463
464 // Test with multiple destinations
465 TEST_F('PrintPreviewWebUITest', 'TestPrintPreviewRestoreMultipleDestinations',
466 function() {
467 var origin = cr.isChromeOS ? "chrome_os" : "local";
468
469 var appState = {
470 'version': 2,
471 'recentDestinations': [
472 {
473 'id': 'ID1',
474 'origin': origin,
475 'account': '',
476 'capabilities': 0,
477 'name': '',
478 'extensionId': '',
479 'extensionName': ''
480 },
481 {
482 'id': 'ID2',
483 'origin': origin,
484 'account': '',
485 'capabilities': 0,
486 'name': '',
487 'extensionId': '',
488 'extensionName': ''
489 },
490 {
491 'id': 'ID3',
492 'origin': origin,
493 'account': '',
494 'capabilities': 0,
495 'name': '',
496 'extensionId': '',
497 'extensionName': ''
498 }
499 ]
500 };
501
502 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(appState);
503 this.setInitialSettings();
504
505 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
506 function() {
507 // Set capabilities for the three recently used destinations + 1 more
508 this.setCapabilities(getCddTemplate('ID1'));
509 this.setCapabilities(getCddTemplate('ID2'));
510 this.setCapabilities(getCddTemplate('ID3'));
511 this.setCapabilities(getCddTemplate('ID4'));
512
513 // The most recently used destination should be the currently selected
514 // one. This is ID1.
515 assertEquals(
516 'ID1', this.printPreview_.destinationStore_.selectedDestination.id);
517
518 // Look through the destinations. ID1, ID2, and ID3 should all be
519 // recent.
520 var destinations = this.printPreview_.destinationStore_.destinations_;
521 var idsFound = [];
522
523 for (var i = 0; i < destinations.length; i++) {
524 if (!destinations[i])
525 continue;
526 if (destinations[i].isRecent)
527 idsFound.push(destinations[i].id);
528 }
529
530 // Make sure there were 3 recent destinations and that they are the
531 // correct IDs.
532 assertEquals(3, idsFound.length);
533 assertNotEquals(-1, idsFound.indexOf("ID1"));
534 assertNotEquals(-1, idsFound.indexOf("ID2"));
535 assertNotEquals(-1, idsFound.indexOf("ID3"));
536
537 testDone();
538 }.bind(this));
539 });
540
541 TEST_F('PrintPreviewWebUITest',
542 'TestPrintPreviewDefaultDestinationSelectionRules', function() {
543 // It also makes sure these rules do override system default destination.
544 this.initialSettings_.serializedDefaultDestinationSelectionRulesStr_ =
545 '{"namePattern":".*Bar.*"}';
546 this.setInitialSettings();
547 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
548 function() {
549 this.setLocalDestinations();
550
551 assertEquals(
552 'BarDevice',
553 this.printPreview_.destinationStore_.selectedDestination.id);
554
555 testDone();
556 }.bind(this));
557 });
558
559 TEST_F('PrintPreviewWebUITest', 'TestSystemDialogLinkIsHiddenInAppKioskMode',
560 function() {
561 if (!cr.isChromeOS)
562 this.initialSettings_.isInAppKioskMode_ = true;
563
564 this.setInitialSettings();
565 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
566 function() {
567 if (cr.isChromeOS)
568 assertEquals(null, $('system-dialog-link'));
569 else
570 checkElementDisplayed($('system-dialog-link'), false);
571 testDone();
572 });
573 });
574
575 // Test that disabled settings hide the disabled sections.
576 TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
577 this.createPrintPreview();
578 checkSectionVisible($('layout-settings'), false);
579 checkSectionVisible($('color-settings'), false);
580 checkSectionVisible($('copies-settings'), false);
581
582 this.setInitialSettings();
583 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
584 function() {
585 this.setLocalDestinations();
586 var device = getCddTemplate("FooDevice");
587 device.capabilities.printer.color = {
588 "option": [
589 {"is_default": true, "type": "STANDARD_COLOR"}
590 ]
591 };
592 delete device.capabilities.printer.copies;
593 this.setCapabilities(device);
594
595 checkSectionVisible($('layout-settings'), true);
596 checkSectionVisible($('color-settings'), false);
597 checkSectionVisible($('copies-settings'), false);
598
599 this.waitForAnimationToEnd('other-options-collapsible');
600 }.bind(this));
601 });
602
603 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide the
604 // fit to page option.
605 TEST_F('PrintPreviewWebUITest', 'PrintToPDFSelectedCapabilities', function() {
606 // Add PDF printer.
607 this.initialSettings_.isDocumentModifiable_ = false;
608 this.initialSettings_.systemDefaultDestinationId_ = 'Save as PDF';
609 this.setInitialSettings();
610
611 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
612 function() {
613 var device = {
614 printerId: 'Save as PDF',
615 capabilities: {
616 version: '1.0',
617 printer: {
618 page_orientation: {
619 option: [
620 {type: 'AUTO', is_default: true},
621 {type: 'PORTRAIT'},
622 {type: 'LANDSCAPE'}
623 ]
624 },
625 color: {
626 option: [
627 {type: 'STANDARD_COLOR', is_default: true}
628 ]
629 },
630 media_size: {
631 option: [
632 { name: 'NA_LETTER',
633 width_microns: 0,
634 height_microns: 0,
635 is_default: true
636 }
637 ]
638 }
639 }
640 }
641 };
642 this.setCapabilities(device);
643
644 var otherOptions = $('other-options-settings');
645 // If rasterization is an option, other options should be visible. If
646 // not, there should be no available other options.
647 checkSectionVisible(otherOptions, isPrintAsImageEnabled());
648 if (isPrintAsImageEnabled()) {
649 checkElementDisplayed(
650 otherOptions.querySelector('#fit-to-page-container'), false);
651 checkElementDisplayed(
652 otherOptions.querySelector('#rasterize-container'), true);
653 }
654 checkSectionVisible($('media-size-settings'), false);
655 checkSectionVisible($('scaling-settings'), false);
656
657 testDone();
658 }.bind(this));
659 });
660
661 // When the source is 'HTML', we always hide the fit to page option and show
662 // media size option.
663 TEST_F('PrintPreviewWebUITest', 'SourceIsHTMLCapabilities', function() {
664 this.setInitialSettings();
665 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
666 function() {
667 this.setLocalDestinations();
668 this.setCapabilities(getCddTemplate("FooDevice"));
669
670 var otherOptions = $('other-options-settings');
671 var fitToPage = otherOptions.querySelector('#fit-to-page-container');
672 var rasterize;
673 if (isPrintAsImageEnabled())
674 rasterize = otherOptions.querySelector('#rasterize-container');
675 var mediaSize = $('media-size-settings');
676 var scalingSettings = $('scaling-settings');
677
678 // Check that options are collapsed (section is visible, because duplex
679 // is available).
680 checkSectionVisible(otherOptions, true);
681 checkElementDisplayed(fitToPage, false);
682 if (isPrintAsImageEnabled())
683 checkElementDisplayed(rasterize, false);
684 checkSectionVisible(mediaSize, false);
685 checkSectionVisible(scalingSettings, false);
686
687 this.expandMoreSettings();
688
689 checkElementDisplayed(fitToPage, false);
690 if (isPrintAsImageEnabled())
691 checkElementDisplayed(rasterize, false);
692 checkSectionVisible(mediaSize, true);
693 checkSectionVisible(scalingSettings, true);
694
695 this.waitForAnimationToEnd('more-settings');
696 }.bind(this));
697 });
698
699 // When the source is "PDF", depending on the selected destination printer, we
700 // show/hide the fit to page option and hide media size selection.
701 TEST_F('PrintPreviewWebUITest', 'SourceIsPDFCapabilities', function() {
702 this.initialSettings_.isDocumentModifiable_ = false;
703 this.setInitialSettings();
704 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
705 function() {
706 this.setLocalDestinations();
707 this.setCapabilities(getCddTemplate("FooDevice"));
708
709 var otherOptions = $('other-options-settings');
710 var scalingSettings = $('scaling-settings');
711 var fitToPageContainer =
712 otherOptions.querySelector('#fit-to-page-container');
713 var rasterizeContainer;
714 if (isPrintAsImageEnabled()) {
715 rasterizeContainer =
716 otherOptions.querySelector('#rasterize-container');
717 }
718
719 checkSectionVisible(otherOptions, true);
720 checkElementDisplayed(fitToPageContainer, true);
721 if (isPrintAsImageEnabled())
722 checkElementDisplayed(rasterizeContainer, false);
723 expectTrue(
724 fitToPageContainer.querySelector('.checkbox').checked);
725 this.expandMoreSettings();
726 if (isPrintAsImageEnabled()) {
727 checkElementDisplayed(rasterizeContainer, true);
728 expectFalse(
729 rasterizeContainer.querySelector('.checkbox').checked);
730 }
731 checkSectionVisible($('media-size-settings'), true);
732 checkSectionVisible(scalingSettings, true);
733
734 this.waitForAnimationToEnd('other-options-collapsible');
735 }.bind(this));
736 });
737
738 // When the source is "PDF", depending on the selected destination printer, we
739 // show/hide the fit to page option and hide media size selection.
740 TEST_F('PrintPreviewWebUITest', 'ScalingUnchecksFitToPage', function() {
741 this.initialSettings_.isDocumentModifiable_ = false;
742 this.setInitialSettings();
743 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
744 function() {
745 this.setLocalDestinations();
746 this.setCapabilities(getCddTemplate("FooDevice"));
747
748 var otherOptions = $('other-options-settings');
749 var scalingSettings = $('scaling-settings');
750
751 checkSectionVisible(otherOptions, true);
752 var fitToPageContainer =
753 otherOptions.querySelector('#fit-to-page-container');
754 checkElementDisplayed(fitToPageContainer, true);
755 expectTrue(
756 fitToPageContainer.querySelector('.checkbox').checked);
757 this.expandMoreSettings();
758 checkSectionVisible($('media-size-settings'), true);
759 checkSectionVisible(scalingSettings, true);
760
761 // Change scaling input
762 var scalingInput = scalingSettings.querySelector('.user-value');
763 expectEquals('100', scalingInput.value);
764 scalingInput.stepUp(5);
765 expectEquals('105', scalingInput.value);
766
767 // Trigger the event
768 var enterEvent = document.createEvent('Event');
769 enterEvent.initEvent('keydown');
770 enterEvent.keyCode = 'Enter';
771 scalingInput.dispatchEvent(enterEvent);
772 expectFalse(
773 fitToPageContainer.querySelector('.checkbox').checked);
774
775 this.waitForAnimationToEnd('other-options-collapsible');
776 }.bind(this));
777 });
778
779 // When the number of copies print preset is set for source 'PDF', we update
780 // the copies value if capability is supported by printer.
781 TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() {
782 this.initialSettings_.isDocumentModifiable_ = false;
783 this.setInitialSettings();
784 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
785 function() {
786 this.setLocalDestinations();
787 this.setCapabilities(getCddTemplate("FooDevice"));
788
789 // Indicate that the number of copies print preset is set for source
790 // PDF.
791 var printPresetOptions = {
792 disableScaling: true,
793 copies: 2
794 };
795 var printPresetOptionsEvent = new Event(
796 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
797 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
798 this.nativeLayer_.getEventTarget().
799 dispatchEvent(printPresetOptionsEvent);
800
801 checkSectionVisible($('copies-settings'), true);
802 expectEquals(
803 printPresetOptions.copies,
804 parseInt($('copies-settings').querySelector('.user-value').value));
805
806 this.waitForAnimationToEnd('other-options-collapsible');
807 }.bind(this));
808 });
809
810 // When the duplex print preset is set for source 'PDF', we update the
811 // duplex setting if capability is supported by printer.
812 TEST_F('PrintPreviewWebUITest', 'CheckDuplexPrintPreset', function() {
813 this.initialSettings_.isDocumentModifiable_ = false;
814 this.setInitialSettings();
815
816 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
817 function() {
818 this.setLocalDestinations();
819 this.setCapabilities(getCddTemplate("FooDevice"));
820
821 // Indicate that the duplex print preset is set to "long edge" for
822 // source PDF.
823 var printPresetOptions = {
824 duplex: 1
825 };
826 var printPresetOptionsEvent = new Event(
827 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
828 printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
829 this.nativeLayer_.getEventTarget().
830 dispatchEvent(printPresetOptionsEvent);
831
832 var otherOptions = $('other-options-settings');
833 checkSectionVisible(otherOptions, true);
834 var duplexContainer = otherOptions.querySelector('#duplex-container');
835 checkElementDisplayed(duplexContainer, true);
836 expectTrue(duplexContainer.querySelector('.checkbox').checked);
837
838 this.waitForAnimationToEnd('other-options-collapsible');
839 }.bind(this));
840 });
841
842 // Make sure that custom margins controls are properly set up.
843 TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
844 this.setInitialSettings();
845 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
846 function() {
847 this.setLocalDestinations();
848 this.setCapabilities(getCddTemplate("FooDevice"));
849
850 this.printPreview_.printTicketStore_.marginsType.updateValue(
851 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
852
853 ['left', 'top', 'right', 'bottom'].forEach(function(margin) {
854 var control =
855 $('preview-area').querySelector('.margin-control-' + margin);
856 assertNotEquals(null, control);
857 var input = control.querySelector('.margin-control-textbox');
858 assertTrue(input.hasAttribute('aria-label'));
859 assertNotEquals('undefined', input.getAttribute('aria-label'));
860 });
861 this.waitForAnimationToEnd('more-settings');
862 }.bind(this));
863 });
864
865 // Page layout has zero margins. Hide header and footer option.
866 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasNoMarginsHideHeaderFooter',
867 function() {
868 this.setInitialSettings();
869 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
870 function() {
871 this.setLocalDestinations();
872 this.setCapabilities(getCddTemplate("FooDevice"));
873
874 var otherOptions = $('other-options-settings');
875 var headerFooter =
876 otherOptions.querySelector('#header-footer-container');
877
878 // Check that options are collapsed (section is visible, because duplex
879 // is available).
880 checkSectionVisible(otherOptions, true);
881 checkElementDisplayed(headerFooter, false);
882
883 this.expandMoreSettings();
884
885 checkElementDisplayed(headerFooter, true);
886
887 this.printPreview_.printTicketStore_.marginsType.updateValue(
888 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
889 this.printPreview_.printTicketStore_.customMargins.updateValue(
890 new print_preview.Margins(0, 0, 0, 0));
891
892 checkElementDisplayed(headerFooter, false);
893
894 this.waitForAnimationToEnd('more-settings');
895 }.bind(this));
896 });
897
898 // Page layout has half-inch margins. Show header and footer option.
899 TEST_F('PrintPreviewWebUITest', 'PageLayoutHasMarginsShowHeaderFooter',
900 function() {
901 this.setInitialSettings();
902 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
903 function() {
904 this.setLocalDestinations();
905 this.setCapabilities(getCddTemplate("FooDevice"));
906
907 var otherOptions = $('other-options-settings');
908 var headerFooter =
909 otherOptions.querySelector('#header-footer-container');
910
911 // Check that options are collapsed (section is visible, because duplex
912 // is available).
913 checkSectionVisible(otherOptions, true);
914 checkElementDisplayed(headerFooter, false);
915
916 this.expandMoreSettings();
917
918 checkElementDisplayed(headerFooter, true);
919
920 this.printPreview_.printTicketStore_.marginsType.updateValue(
921 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
922 this.printPreview_.printTicketStore_.customMargins.updateValue(
923 new print_preview.Margins(36, 36, 36, 36));
924
925 checkElementDisplayed(headerFooter, true);
926
927 this.waitForAnimationToEnd('more-settings');
928 }.bind(this));
929 });
930
931 // Page layout has zero top and bottom margins. Hide header and footer option.
932 TEST_F('PrintPreviewWebUITest',
933 'ZeroTopAndBottomMarginsHideHeaderFooter',
934 function() {
935 this.setInitialSettings();
936 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
937 function() {
938 this.setLocalDestinations();
939 this.setCapabilities(getCddTemplate("FooDevice"));
940
941 var otherOptions = $('other-options-settings');
942 var headerFooter =
943 otherOptions.querySelector('#header-footer-container');
944
945 // Check that options are collapsed (section is visible, because duplex
946 // is available).
947 checkSectionVisible(otherOptions, true);
948 checkElementDisplayed(headerFooter, false);
949
950 this.expandMoreSettings();
951
952 checkElementDisplayed(headerFooter, true);
953
954 this.printPreview_.printTicketStore_.marginsType.updateValue(
955 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
956 this.printPreview_.printTicketStore_.customMargins.updateValue(
957 new print_preview.Margins(0, 36, 0, 36));
958
959 checkElementDisplayed(headerFooter, false);
960
961 this.waitForAnimationToEnd('more-settings');
962 }.bind(this));
963 });
964
965 // Page layout has zero top and half-inch bottom margin. Show header and footer
966 // option.
967 TEST_F('PrintPreviewWebUITest',
968 'ZeroTopAndNonZeroBottomMarginShowHeaderFooter',
969 function() {
970 this.setInitialSettings();
971 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
972 function() {
973 this.setLocalDestinations();
974 this.setCapabilities(getCddTemplate("FooDevice"));
975
976 var otherOptions = $('other-options-settings');
977 var headerFooter =
978 otherOptions.querySelector('#header-footer-container');
979
980 // Check that options are collapsed (section is visible, because duplex
981 // is available).
982 checkSectionVisible(otherOptions, true);
983 checkElementDisplayed(headerFooter, false);
984
985 this.expandMoreSettings();
986
987 checkElementDisplayed(headerFooter, true);
988
989 this.printPreview_.printTicketStore_.marginsType.updateValue(
990 print_preview.ticket_items.MarginsTypeValue.CUSTOM);
991 this.printPreview_.printTicketStore_.customMargins.updateValue(
992 new print_preview.Margins(0, 36, 36, 36));
993
994 checkElementDisplayed(headerFooter, true);
995
996 this.waitForAnimationToEnd('more-settings');
997 }.bind(this));
998 });
999
1000 // Check header footer availability with small (label) page size.
1001 TEST_F('PrintPreviewWebUITest', 'SmallPaperSizeHeaderFooter', function() {
1002 this.setInitialSettings();
1003 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1004 function() {
1005 this.setLocalDestinations();
1006 var device = getCddTemplate("FooDevice");
1007 device.capabilities.printer.media_size = {
1008 "option": [
1009 {"name": "SmallLabel", "width_microns": 38100,
1010 "height_microns": 12700, "is_default": false},
1011 {"name": "BigLabel", "width_microns": 50800,
1012 "height_microns": 76200, "is_default": true}
1013 ]
1014 };
1015 this.setCapabilities(device);
1016
1017 var otherOptions = $('other-options-settings');
1018 var headerFooter =
1019 otherOptions.querySelector('#header-footer-container');
1020
1021 // Check that options are collapsed (section is visible, because duplex
1022 // is available).
1023 checkSectionVisible(otherOptions, true);
1024 checkElementDisplayed(headerFooter, false);
1025
1026 this.expandMoreSettings();
1027
1028 // Big label should have header/footer
1029 checkElementDisplayed(headerFooter, true);
1030
1031 // Small label should not
1032 this.printPreview_.printTicketStore_.mediaSize.updateValue(
1033 device.capabilities.printer.media_size.option[0]);
1034 checkElementDisplayed(headerFooter, false);
1035
1036 // Oriented in landscape, there should be enough space for
1037 // header/footer.
1038 this.printPreview_.printTicketStore_.landscape.updateValue(true);
1039 checkElementDisplayed(headerFooter, true);
1040
1041 this.waitForAnimationToEnd('more-settings');
1042 }.bind(this));
1043 });
1044
1045 // Test that the color settings, one option, standard monochrome.
1046 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
1047 this.setInitialSettings();
1048 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1049 function() {
1050 this.setLocalDestinations();
1051
1052 // Only one option, standard monochrome.
1053 var device = getCddTemplate("FooDevice");
1054 device.capabilities.printer.color = {
1055 "option": [
1056 {"is_default": true, "type": "STANDARD_MONOCHROME"}
1057 ]
1058 };
1059 this.setCapabilities(device);
1060
1061 checkSectionVisible($('color-settings'), false);
1062
1063 this.waitForAnimationToEnd('more-settings');
1064 }.bind(this));
1065 });
1066
1067 // Test that the color settings, one option, custom monochrome.
1068 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
1069 function() {
1070 this.setInitialSettings();
1071 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1072 function() {
1073 this.setLocalDestinations();
1074
1075 // Only one option, standard monochrome.
1076 var device = getCddTemplate("FooDevice");
1077 device.capabilities.printer.color = {
1078 "option": [
1079 {"is_default": true, "type": "CUSTOM_MONOCHROME",
1080 "vendor_id": "42"}
1081 ]
1082 };
1083 this.setCapabilities(device);
1084
1085 checkSectionVisible($('color-settings'), false);
1086
1087 this.waitForAnimationToEnd('more-settings');
1088 }.bind(this));
1089 });
1090
1091 // Test that the color settings, one option, standard color.
1092 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
1093 this.setInitialSettings();
1094 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1095 function() {
1096 this.setLocalDestinations();
1097
1098 var device = getCddTemplate("FooDevice");
1099 device.capabilities.printer.color = {
1100 "option": [
1101 {"is_default": true, "type": "STANDARD_COLOR"}
1102 ]
1103 };
1104 this.setCapabilities(device);
1105
1106 checkSectionVisible($('color-settings'), false);
1107
1108 this.waitForAnimationToEnd('more-settings');
1109 }.bind(this));
1110 });
1111
1112 // Test that the color settings, one option, custom color.
1113 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
1114 this.setInitialSettings();
1115 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1116 function() {
1117 this.setLocalDestinations();
1118
1119 var device = getCddTemplate("FooDevice");
1120 device.capabilities.printer.color = {
1121 "option": [
1122 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"}
1123 ]
1124 };
1125 this.setCapabilities(device);
1126
1127 checkSectionVisible($('color-settings'), false);
1128
1129 this.waitForAnimationToEnd('more-settings');
1130 }.bind(this));
1131 });
1132
1133 // Test that the color settings, two options, both standard, defaults to color.
1134 TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
1135 function() {
1136 this.setInitialSettings();
1137 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1138 function() {
1139 this.setLocalDestinations();
1140
1141 var device = getCddTemplate("FooDevice");
1142 device.capabilities.printer.color = {
1143 "option": [
1144 {"type": "STANDARD_MONOCHROME"},
1145 {"is_default": true, "type": "STANDARD_COLOR"}
1146 ]
1147 };
1148 this.setCapabilities(device);
1149
1150 checkSectionVisible($('color-settings'), true);
1151 expectEquals(
1152 'color',
1153 $('color-settings').querySelector('.color-settings-select').value);
1154
1155 this.waitForAnimationToEnd('more-settings');
1156 }.bind(this));
1157 });
1158
1159 // Test that the color settings, two options, both standard, defaults to
1160 // monochrome.
1161 TEST_F('PrintPreviewWebUITest',
1162 'TestColorSettingsBothStandardDefaultMonochrome', function() {
1163 this.setInitialSettings();
1164 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1165 function() {
1166 this.setLocalDestinations();
1167
1168 var device = getCddTemplate("FooDevice");
1169 device.capabilities.printer.color = {
1170 "option": [
1171 {"is_default": true, "type": "STANDARD_MONOCHROME"},
1172 {"type": "STANDARD_COLOR"}
1173 ]
1174 };
1175 this.setCapabilities(device);
1176
1177 checkSectionVisible($('color-settings'), true);
1178 expectEquals(
1179 'bw',
1180 $('color-settings').querySelector('.color-settings-select').value);
1181
1182 this.waitForAnimationToEnd('more-settings');
1183 }.bind(this));
1184 });
1185
1186 // Test that the color settings, two options, both custom, defaults to color.
1187 TEST_F('PrintPreviewWebUITest',
1188 'TestColorSettingsBothCustomDefaultColor', function() {
1189 this.setInitialSettings();
1190 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1191 function() {
1192 this.setLocalDestinations();
1193
1194 var device = getCddTemplate("FooDevice");
1195 device.capabilities.printer.color = {
1196 "option": [
1197 {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"},
1198 {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"}
1199 ]
1200 };
1201 this.setCapabilities(device);
1202
1203 checkSectionVisible($('color-settings'), true);
1204 expectEquals(
1205 'color',
1206 $('color-settings').querySelector('.color-settings-select').value);
1207
1208 this.waitForAnimationToEnd('more-settings');
1209 }.bind(this));
1210 });
1211
1212 // Test to verify that duplex settings are set according to the printer
1213 // capabilities.
1214 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
1215 this.setInitialSettings();
1216 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1217 function() {
1218 this.setLocalDestinations();
1219 this.setCapabilities(getCddTemplate("FooDevice"));
1220
1221 var otherOptions = $('other-options-settings');
1222 checkSectionVisible(otherOptions, true);
1223 duplexContainer = otherOptions.querySelector('#duplex-container');
1224 expectFalse(duplexContainer.hidden);
1225 expectFalse(duplexContainer.querySelector('.checkbox').checked);
1226
1227 this.waitForAnimationToEnd('more-settings');
1228 }.bind(this));
1229 });
1230
1231 // Test to verify that duplex settings are set according to the printer
1232 // capabilities.
1233 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
1234 this.setInitialSettings();
1235 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1236 function() {
1237 this.setLocalDestinations();
1238 var device = getCddTemplate("FooDevice");
1239 delete device.capabilities.printer.duplex;
1240 this.setCapabilities(device);
1241
1242 // Check that it is collapsed.
1243 var otherOptions = $('other-options-settings');
1244 checkSectionVisible(otherOptions, false);
1245
1246 this.expandMoreSettings();
1247
1248 // Now it should be visible.
1249 checkSectionVisible(otherOptions, true);
1250 expectTrue(otherOptions.querySelector('#duplex-container').hidden);
1251
1252 this.waitForAnimationToEnd('more-settings');
1253 }.bind(this));
1254 });
1255
1256 // Test that changing the selected printer updates the preview.
1257 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
1258 this.setInitialSettings();
1259 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1260 function() {
1261 this.setLocalDestinations();
1262 this.setCapabilities(getCddTemplate("FooDevice"));
1263
1264 var previewGenerator = mock(print_preview.PreviewGenerator);
1265 this.printPreview_.previewArea_.previewGenerator_ =
1266 previewGenerator.proxy();
1267
1268 // The number of settings that can change due to a change in the
1269 // destination that will therefore dispatch ticket item change events.
1270 previewGenerator.expects(exactly(9)).requestPreview();
1271
1272 var barDestination =
1273 this.printPreview_.destinationStore_.destinations().find(
1274 function(d) {
1275 return d.id == 'BarDevice';
1276 });
1277
1278 this.printPreview_.destinationStore_.selectDestination(barDestination);
1279
1280 var device = getCddTemplate("BarDevice");
1281 device.capabilities.printer.color = {
1282 "option": [
1283 {"is_default": true, "type": "STANDARD_MONOCHROME"}
1284 ]
1285 };
1286 this.setCapabilities(device);
1287
1288 this.waitForAnimationToEnd('more-settings');
1289 }.bind(this));
1290 });
1291
1292 // Test that error message is displayed when plugin doesn't exist.
1293 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() {
1294 this.setInitialSettings();
1295 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1296 function() {
1297 var previewAreaEl = $('preview-area');
1298
1299 var loadingMessageEl =
1300 previewAreaEl.
1301 getElementsByClassName('preview-area-loading-message')[0];
1302 expectTrue(loadingMessageEl.hidden);
1303
1304 var previewFailedMessageEl = previewAreaEl.getElementsByClassName(
1305 'preview-area-preview-failed-message')[0];
1306 expectTrue(previewFailedMessageEl.hidden);
1307
1308 var printFailedMessageEl =
1309 previewAreaEl.
1310 getElementsByClassName('preview-area-print-failed')[0];
1311 expectTrue(printFailedMessageEl.hidden);
1312
1313 var customMessageEl =
1314 previewAreaEl.
1315 getElementsByClassName('preview-area-custom-message')[0];
1316 expectFalse(customMessageEl.hidden);
1317
1318 testDone();
1319 });
1320 });
1321
1322 // Test custom localized paper names.
1323 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() {
1324 this.setInitialSettings();
1325 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1326 function() {
1327 this.setLocalDestinations();
1328
1329 var customLocalizedMediaName = 'Vendor defined localized media name';
1330 var customMediaName = 'Vendor defined media name';
1331
1332 var device = getCddTemplate("FooDevice");
1333 device.capabilities.printer.media_size = {
1334 option: [
1335 { name: 'CUSTOM',
1336 width_microns: 15900,
1337 height_microns: 79400,
1338 is_default: true,
1339 custom_display_name_localized: [
1340 { locale: navigator.language,
1341 value: customLocalizedMediaName
1342 }
1343 ]
1344 },
1345 { name: 'CUSTOM',
1346 width_microns: 15900,
1347 height_microns: 79400,
1348 custom_display_name: customMediaName
1349 }
1350 ]
1351 };
1352
1353 this.setCapabilities(device);
1354
1355 this.expandMoreSettings();
1356
1357 checkSectionVisible($('media-size-settings'), true);
1358 var mediaSelect =
1359 $('media-size-settings').querySelector('.settings-select');
1360 // Check the default media item.
1361 expectEquals(
1362 customLocalizedMediaName,
1363 mediaSelect.options[mediaSelect.selectedIndex].text);
1364 // Check the other media item.
1365 expectEquals(
1366 customMediaName,
1367 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text);
1368
1369 this.waitForAnimationToEnd('more-settings');
1370 }.bind(this));
1371 });
1372
1373 function getCddTemplateWithAdvancedSettings(printerId) {
1374 return {
1375 printerId: printerId,
1376 capabilities: {
1377 version: '1.0',
1378 printer: {
1379 supported_content_type: [{content_type: 'application/pdf'}],
1380 vendor_capability:
1381 [
1382 {display_name: 'Print Area',
1383 id: 'Print Area',
1384 type: 'SELECT',
1385 select_cap: {
1386 option: [
1387 {display_name: 'A4', value: 4, is_default: true},
1388 {display_name: 'A6', value: 6},
1389 {display_name: 'A7', value: 7}
1390 ]
1391 }
1392 }
1393 ],
1394 collate: {},
1395 color: {
1396 option: [
1397 {type: 'STANDARD_COLOR', is_default: true},
1398 {type: 'STANDARD_MONOCHROME'}
1399 ]
1400 },
1401 copies: {},
1402 duplex: {
1403 option: [
1404 {type: 'NO_DUPLEX', is_default: true},
1405 {type: 'LONG_EDGE'},
1406 {type: 'SHORT_EDGE'}
1407 ]
1408 },
1409 page_orientation: {
1410 option: [
1411 {type: 'PORTRAIT', is_default: true},
1412 {type: 'LANDSCAPE'},
1413 {type: 'AUTO'}
1414 ]
1415 },
1416 media_size: {
1417 option: [
1418 { name: 'NA_LETTER',
1419 width_microns: 215900,
1420 height_microns: 279400,
1421 is_default: true
1422 }
1423 ]
1424 },
1425 }
1426 }
1427 };
1428 }
1429
1430 // Simulates a click of the advanced options settings button to bring up the
1431 // advanced settings overlay.
1432 function openAdvancedSettings() {
1433 // Check for button and click to view advanced settings section.
1434 var advancedOptionsSettingsButton =
1435 $('advanced-options-settings').
1436 querySelector('.advanced-options-settings-button');
1437 checkElementDisplayed(advancedOptionsSettingsButton, true);
1438 // Button is disabled during testing due to test version of
1439 // testPluginCompatibility() being set to always return false. Enable button
1440 // to send click event.
1441 advancedOptionsSettingsButton.disabled = false;
1442 advancedOptionsSettingsButton.click();
1443 }
1444
1445 // Test advanced settings with 1 capability (should not display settings search
1446 // box).
1447 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings1Option', function() {
1448 var device = getCddTemplateWithAdvancedSettings("FooDevice");
1449 this.accessibilityIssuesAreErrors = false;
1450 this.setInitialSettings();
1451 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1452 function() {
1453 this.setupAdvancedSettingsTest(device);
1454
1455 // Open the advanced settings overlay.
1456 openAdvancedSettings();
1457
1458 // Check that advanced settings close button is now visible,
1459 // but not the search box (only 1 capability).
1460 var advancedSettingsCloseButton = $('advanced-settings').
1461 querySelector('.close-button');
1462 checkElementDisplayed(advancedSettingsCloseButton, true);
1463 checkElementDisplayed($('advanced-settings').
1464 querySelector('.search-box-area'), false);
1465
1466 this.waitForAnimationToEnd('more-settings');
1467 }.bind(this));
1468 });
1469
1470
1471 // Test advanced settings with 2 capabilities (should have settings search box).
1472 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings2Options', function() {
1473 var device = getCddTemplateWithAdvancedSettings("FooDevice");
1474 // Add new capability.
1475 device.capabilities.printer.vendor_capability.push({
1476 display_name: 'Paper Type',
1477 id: 'Paper Type',
1478 type: 'SELECT',
1479 select_cap: {
1480 option: [
1481 {display_name: 'Standard', value: 0, is_default: true},
1482 {display_name: 'Recycled', value: 1},
1483 {display_name: 'Special', value: 2}
1484 ]
1485 }
1486 });
1487 this.accessibilityIssuesAreErrors = false;
1488 this.setInitialSettings();
1489 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1490 function() {
1491 this.setupAdvancedSettingsTest(device);
1492
1493 // Open the advanced settings overlay.
1494 openAdvancedSettings();
1495
1496 // Check advanced settings is visible and that the search box now
1497 // appears.
1498 var advancedSettingsCloseButton = $('advanced-settings').
1499 querySelector('.close-button');
1500 checkElementDisplayed(advancedSettingsCloseButton, true);
1501 checkElementDisplayed($('advanced-settings').
1502 querySelector('.search-box-area'), true);
1503
1504 this.waitForAnimationToEnd('more-settings');
1505 }.bind(this));
1506 });
1507
1508 // Test that initialization with saved destination only issues one call
1509 // to startPreview.
1510 TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() {
1511 this.createPrintPreview();
1512 // Load in a bunch of recent destinations with non null capabilities.
1513 var origin = cr.isChromeOS ? 'chrome_os' : 'local';
1514 var initSettings = {
1515 version: 2,
1516 recentDestinations: [1, 2, 3].map(function(i) {
1517 return {
1518 id: 'ID' + i, origin: origin, account: '',
1519 capabilities: getCddTemplate('ID' + i), name: '',
1520 extensionId: '', extensionName: ''
1521 };
1522 }),
1523 };
1524 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(initSettings);
1525 this.setCapabilities(getCddTemplate('ID1'));
1526 this.setCapabilities(getCddTemplate('ID2'));
1527 this.setCapabilities(getCddTemplate('ID3'));
1528
1529 // Use a real preview generator.
1530 this.printPreview_.previewArea_.previewGenerator_ =
1531 new print_preview.PreviewGenerator(this.printPreview_.destinationStore_,
1532 this.printPreview_.printTicketStore_, this.nativeLayer_,
1533 this.printPreview_.documentInfo_);
1534
1535 // Preview generator starts out with inFlightRequestId_ == -1. The id
1536 // increments by 1 for each startGetPreview call it makes. It should only
1537 // make one such call during initialization or there will be a race; see
1538 // crbug.com/666595
1539 expectEquals(
1540 -1,
1541 this.printPreview_.previewArea_.previewGenerator_.inFlightRequestId_);
1542 this.setInitialSettings();
1543 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1544 function() {
1545 expectEquals(
1546 0,
1547 this.printPreview_.previewArea_.previewGenerator_.
1548 inFlightRequestId_);
1549 testDone();
1550 }.bind(this));
1551 });
1552
1553 // Test that invalid settings errors disable the print preview and display
1554 // an error and that the preview dialog can be recovered by selecting a
1555 // new destination.
1556 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() {
1557 // Setup
1558 this.setInitialSettings();
1559 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1560 function() {
1561 this.setLocalDestinations();
1562 this.setCapabilities(getCddTemplate("FooDevice"));
1563
1564 // Manually enable the print header. This is needed since there is no
1565 // plugin during test, so it will be set as disabled normally.
1566 this.printPreview_.printHeader_.isEnabled = true;
1567
1568 // There will be an error message in the preview area since the plugin
1569 // is not running. However, it should not be the invalid settings error.
1570 var previewAreaEl = $('preview-area');
1571 var customMessageEl =
1572 previewAreaEl.
1573 getElementsByClassName('preview-area-custom-message')[0];
1574 expectFalse(customMessageEl.hidden);
1575 var expectedMessageStart = 'The selected printer is not available or '
1576 + 'not installed correctly.'
1577 expectFalse(customMessageEl.textContent.includes(expectedMessageStart));
1578
1579 // Verify that the print button is enabled.
1580 var printHeader = $('print-header');
1581 var printButton = printHeader.querySelector('button.print');
1582 checkElementDisplayed(printButton, true);
1583 expectFalse(printButton.disabled);
1584
1585 // Report invalid settings error.
1586 this.dispatchInvalidSettings();
1587
1588 // Should be in an error state, print button disabled, invalid custom
1589 // error message shown.
1590 expectFalse(customMessageEl.hidden);
1591 expectTrue(customMessageEl.textContent.includes(expectedMessageStart));
1592 expectTrue(printButton.disabled);
1593
1594 // Select a new destination
1595 var barDestination =
1596 this.printPreview_.destinationStore_.destinations().find(
1597 function(d) {
1598 return d.id == 'BarDevice';
1599 });
1600
1601 this.printPreview_.destinationStore_.selectDestination(barDestination);
1602
1603 // Dispatch events indicating capabilities were fetched and new preview
1604 // has loaded.
1605 this.setCapabilities(getCddTemplate("BarDevice"));
1606 this.dispatchPreviewDone();
1607
1608 // Has active print button and successfully "prints", indicating
1609 // recovery from error state.
1610 expectFalse(printButton.disabled);
1611 expectFalse(this.hasPrinted());
1612 printButton.click();
1613 expectTrue(this.hasPrinted());
1614 testDone();
1615 }.bind(this));
1616 });
1617
1618 // Test the preview generator to make sure the generate draft parameter is set
1619 // correctly. It should be false if the only change is the page range.
1620 TEST_F('PrintPreviewWebUITest', 'TestGenerateDraft', function() {
1621 this.createPrintPreview();
1622
1623 // Use a real preview generator.
1624 this.printPreview_.previewArea_.previewGenerator_ =
1625 new print_preview.PreviewGenerator(this.printPreview_.destinationStore_,
1626 this.printPreview_.printTicketStore_, this.nativeLayer_,
1627 this.printPreview_.documentInfo_);
1628
1629 this.setInitialSettings();
1630 this.printPreview_.nativeLayer_.whenCalled('getInitialSettings').then(
1631 function() {
1632 this.setLocalDestinations();
1633 this.setCapabilities(getCddTemplate("FooDevice"));
1634
1635 // The first request should generate draft because there was no
1636 // previous print preview draft.
1637 expectTrue(this.generateDraft());
1638
1639 // Change the page range - no new draft needed.
1640 this.printPreview_.printTicketStore_.pageRange.updateValue("2");
1641 expectFalse(this.generateDraft());
1642
1643 // Change the margin type - need to regenerate again.
1644 this.printPreview_.printTicketStore_.marginsType.updateValue(
1645 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS);
1646 expectTrue(this.generateDraft());
1647
1648 testDone();
1649 }.bind(this));
1650 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698