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

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

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

Powered by Google App Engine
This is Rietveld 408576698