OLD | NEW |
| (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 PrintPreviewWebUITest.prototype = { | |
22 __proto__: testing.Test.prototype, | |
23 | |
24 /** | |
25 * Browse to the sample page, cause print preview & call preLoad(). | |
26 * @type {string} | |
27 * @override | |
28 */ | |
29 browsePrintPreload: 'print_preview/print_preview_hello_world_test.html', | |
30 | |
31 /** @override */ | |
32 runAccessibilityChecks: true, | |
33 | |
34 /** @override */ | |
35 accessibilityIssuesAreErrors: true, | |
36 | |
37 /** @override */ | |
38 isAsync: true, | |
39 | |
40 /** | |
41 * Stub out low-level functionality like the NativeLayer and | |
42 * CloudPrintInterface. | |
43 * @this {PrintPreviewWebUITest} | |
44 * @override | |
45 */ | |
46 preLoad: function() { | |
47 window.isTest = true; | |
48 window.addEventListener('DOMContentLoaded', function() { | |
49 function CloudPrintInterfaceStub() { | |
50 cr.EventTarget.call(this); | |
51 } | |
52 CloudPrintInterfaceStub.prototype = { | |
53 __proto__: cr.EventTarget.prototype, | |
54 search: function(isRecent) {} | |
55 }; | |
56 var oldCpInterfaceEventType = cloudprint.CloudPrintInterfaceEventType; | |
57 cloudprint.CloudPrintInterface = CloudPrintInterfaceStub; | |
58 cloudprint.CloudPrintInterfaceEventType = oldCpInterfaceEventType; | |
59 | |
60 print_preview.PreviewArea.prototype.checkPluginCompatibility_ = | |
61 function() { | |
62 return false; | |
63 }; | |
64 }.bind(this)); | |
65 }, | |
66 | |
67 extraLibraries: [ | |
68 ROOT_PATH + 'ui/webui/resources/js/cr.js', | |
69 ROOT_PATH + 'ui/webui/resources/js/promise_resolver.js', | |
70 ROOT_PATH + 'ui/webui/resources/js/util.js', | |
71 ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js', | |
72 'native_layer_stub.js', | |
73 ], | |
74 | |
75 /** | |
76 * Creates an instance of print_preview.PrintPreview and initializes the | |
77 * |nativeLayer_| and |previewArea_|. | |
78 */ | |
79 createPrintPreview: function() { | |
80 this.nativeLayer_ = new print_preview.NativeLayerStub(); | |
81 print_preview.NativeLayer.setInstance(this.nativeLayer_); | |
82 this.printPreview_ = new print_preview.PrintPreview(); | |
83 this.previewArea_ = this.printPreview_.getPreviewArea(); | |
84 }, | |
85 | |
86 /** | |
87 * Initialize print preview with the initial settings currently stored in | |
88 * |this.initialSettings_|. Creates |this.printPreview_| if it does not | |
89 * already exist. | |
90 */ | |
91 setInitialSettings: function() { | |
92 if (!this.printPreview_) | |
93 this.createPrintPreview(); | |
94 this.nativeLayer_.setInitialSettings(this.initialSettings_); | |
95 this.printPreview_.initialize(); | |
96 testing.Test.disableAnimationsAndTransitions(); | |
97 // Enable when failure is resolved. | |
98 // AX_TEXT_03: http://crbug.com/559209 | |
99 this.accessibilityAuditConfig.ignoreSelectors( | |
100 'multipleLabelableElementsPerLabel', | |
101 '#page-settings > .right-column > *'); | |
102 }, | |
103 | |
104 /** | |
105 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will | |
106 * happen in the same thread. | |
107 */ | |
108 setLocalDestinations: function() { | |
109 var localDestsSetEvent = | |
110 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | |
111 localDestsSetEvent.destinationInfos = this.localDestinationInfos_; | |
112 this.nativeLayer_.getEventTarget().dispatchEvent(localDestsSetEvent); | |
113 }, | |
114 | |
115 /** | |
116 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will | |
117 * happen in the same thread. | |
118 * @device - The device whose capabilities should be dispatched. | |
119 */ | |
120 setCapabilities: function(device) { | |
121 var capsSetEvent = | |
122 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
123 capsSetEvent.settingsInfo = device; | |
124 this.nativeLayer_.getEventTarget().dispatchEvent(capsSetEvent); | |
125 }, | |
126 | |
127 /** | |
128 * Dispatch the PREVIEW_GENERATION_DONE event. This call is NOT async and | |
129 * will happen in the same thread. | |
130 */ | |
131 dispatchPreviewDone: function() { | |
132 var previewDoneEvent = | |
133 new Event(print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); | |
134 this.previewArea_.dispatchEvent(previewDoneEvent); | |
135 }, | |
136 | |
137 /** | |
138 * Dispatch the SETTINGS_INVALID event. This call is NOT async and will | |
139 * happen in the same thread. | |
140 */ | |
141 dispatchInvalidSettings: function() { | |
142 var invalidSettingsEvent = | |
143 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); | |
144 this.nativeLayer_.getEventTarget().dispatchEvent(invalidSettingsEvent); | |
145 }, | |
146 | |
147 /** | |
148 * @return {boolean} Whether the UI has "printed" or not. (called startPrint | |
149 * on the native layer) | |
150 */ | |
151 hasPrinted: function() { | |
152 return this.nativeLayer_.isPrintStarted(); | |
153 }, | |
154 | |
155 /** | |
156 * @return {boolean} Whether the UI is "generating draft" in the most recent | |
157 * preview. (checking the result of the startGetPreview call in the native | |
158 * layer) | |
159 */ | |
160 generateDraft: function() { | |
161 return this.nativeLayer_.generateDraft(); | |
162 }, | |
163 | |
164 /** | |
165 * Even though animation duration and delay is set to zero, it is necessary to | |
166 * wait until the animation has finished. | |
167 */ | |
168 waitForAnimationToEnd: function(elementId) { | |
169 // add a listener for the animation end event | |
170 document.addEventListener('animationend', function f(e) { | |
171 if (e.target.id == elementId) { | |
172 document.removeEventListener(f, 'animationend'); | |
173 testDone(); | |
174 } | |
175 }); | |
176 }, | |
177 | |
178 /** | |
179 * Expand the 'More Settings' div to expose all options. | |
180 */ | |
181 expandMoreSettings: function() { | |
182 var moreSettings = $('more-settings'); | |
183 checkSectionVisible(moreSettings, true); | |
184 moreSettings.click(); | |
185 }, | |
186 | |
187 /** | |
188 * Repeated setup steps for the advanced settings tests. | |
189 * Disables accessiblity errors, sets initial settings, and verifies | |
190 * advanced options section is visible after expanding more settings. | |
191 */ | |
192 setupAdvancedSettingsTest: function(device) { | |
193 // Need to disable this since overlay animation will not fully complete. | |
194 this.setLocalDestinations(); | |
195 this.setCapabilities(device); | |
196 this.expandMoreSettings(); | |
197 | |
198 // Check that the advanced options settings section is visible. | |
199 checkSectionVisible($('advanced-options-settings'), true); | |
200 }, | |
201 | |
202 /** | |
203 * @this {PrintPreviewWebUITest} | |
204 * @override | |
205 */ | |
206 setUp: function() { | |
207 testing.Test.prototype.setUp.call(this); | |
208 Mock4JS.clearMocksToVerify(); | |
209 | |
210 this.initialSettings_ = new print_preview.NativeInitialSettings( | |
211 false /*isInKioskAutoPrintMode*/, | |
212 false /*isInAppKioskMode*/, | |
213 ',' /*thousandsDelimeter*/, | |
214 '.' /*decimalDelimeter*/, | |
215 1 /*unitType*/, | |
216 true /*isDocumentModifiable*/, | |
217 'title' /*documentTitle*/, | |
218 true /*documentHasSelection*/, | |
219 false /*selectionOnly*/, | |
220 'FooDevice' /*systemDefaultDestinationId*/, | |
221 null /*serializedAppStateStr*/, | |
222 null /*serializedDefaultDestinationSelectionRulesStr*/); | |
223 this.localDestinationInfos_ = [ | |
224 { printerName: 'FooName', deviceName: 'FooDevice' }, | |
225 { printerName: 'BarName', deviceName: 'BarDevice' } | |
226 ]; | |
227 }, | |
228 }; | |
229 | |
230 | |
231 /** | |
232 * Verify that |section| visibility matches |visible|. | |
233 * @param {HTMLDivElement} section The section to check. | |
234 * @param {boolean} visible The expected state of visibility. | |
235 */ | |
236 function checkSectionVisible(section, visible) { | |
237 assertNotEquals(null, section); | |
238 expectEquals( | |
239 visible, section.classList.contains('visible'), 'section=' + section.id); | |
240 } | |
241 | |
242 function checkElementDisplayed(el, isDisplayed) { | |
243 assertNotEquals(null, el); | |
244 expectEquals(isDisplayed, | |
245 !el.hidden, | |
246 'element="' + el.id + '" of class "' + el.classList + '"'); | |
247 } | |
248 | |
249 function getCddTemplate(printerId) { | |
250 return { | |
251 printerId: printerId, | |
252 capabilities: { | |
253 version: '1.0', | |
254 printer: { | |
255 supported_content_type: [{content_type: 'application/pdf'}], | |
256 collate: {}, | |
257 color: { | |
258 option: [ | |
259 {type: 'STANDARD_COLOR', is_default: true}, | |
260 {type: 'STANDARD_MONOCHROME'} | |
261 ] | |
262 }, | |
263 copies: {}, | |
264 duplex: { | |
265 option: [ | |
266 {type: 'NO_DUPLEX', is_default: true}, | |
267 {type: 'LONG_EDGE'}, | |
268 {type: 'SHORT_EDGE'} | |
269 ] | |
270 }, | |
271 page_orientation: { | |
272 option: [ | |
273 {type: 'PORTRAIT', is_default: true}, | |
274 {type: 'LANDSCAPE'}, | |
275 {type: 'AUTO'} | |
276 ] | |
277 }, | |
278 media_size: { | |
279 option: [ | |
280 { name: 'NA_LETTER', | |
281 width_microns: 215900, | |
282 height_microns: 279400, | |
283 is_default: true | |
284 } | |
285 ] | |
286 } | |
287 } | |
288 } | |
289 }; | |
290 } | |
291 | |
292 function isPrintAsImageEnabled() { | |
293 // Should be enabled by default on non Windows/Mac | |
294 return (!cr.isWindows && !cr.isMac && | |
295 loadTimeData.getBoolean('printPdfAsImageEnabled')); | |
296 } | |
297 | |
298 // Test to verify that duplex settings are set according to the printer | |
299 // capabilities. | |
300 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() { | |
301 this.setInitialSettings(); | |
302 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
303 function() { | |
304 this.setLocalDestinations(); | |
305 this.setCapabilities(getCddTemplate("FooDevice")); | |
306 | |
307 var otherOptions = $('other-options-settings'); | |
308 checkSectionVisible(otherOptions, true); | |
309 duplexContainer = otherOptions.querySelector('#duplex-container'); | |
310 expectFalse(duplexContainer.hidden); | |
311 expectFalse(duplexContainer.querySelector('.checkbox').checked); | |
312 | |
313 this.waitForAnimationToEnd('more-settings'); | |
314 }.bind(this)); | |
315 }); | |
316 | |
317 // Test to verify that duplex settings are set according to the printer | |
318 // capabilities. | |
319 TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() { | |
320 this.setInitialSettings(); | |
321 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
322 function() { | |
323 this.setLocalDestinations(); | |
324 var device = getCddTemplate("FooDevice"); | |
325 delete device.capabilities.printer.duplex; | |
326 this.setCapabilities(device); | |
327 | |
328 // Check that it is collapsed. | |
329 var otherOptions = $('other-options-settings'); | |
330 checkSectionVisible(otherOptions, false); | |
331 | |
332 this.expandMoreSettings(); | |
333 | |
334 // Now it should be visible. | |
335 checkSectionVisible(otherOptions, true); | |
336 expectTrue(otherOptions.querySelector('#duplex-container').hidden); | |
337 | |
338 this.waitForAnimationToEnd('more-settings'); | |
339 }.bind(this)); | |
340 }); | |
341 | |
342 // Test that changing the selected printer updates the preview. | |
343 TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { | |
344 this.setInitialSettings(); | |
345 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
346 function() { | |
347 this.setLocalDestinations(); | |
348 this.setCapabilities(getCddTemplate("FooDevice")); | |
349 | |
350 var previewGenerator = mock(print_preview.PreviewGenerator); | |
351 this.previewArea_.previewGenerator_ = | |
352 previewGenerator.proxy(); | |
353 | |
354 // The number of settings that can change due to a change in the | |
355 // destination that will therefore dispatch ticket item change events. | |
356 previewGenerator.expects(exactly(9)).requestPreview(); | |
357 | |
358 var barDestination = | |
359 this.printPreview_.destinationStore_.destinations().find( | |
360 function(d) { | |
361 return d.id == 'BarDevice'; | |
362 }); | |
363 | |
364 this.printPreview_.destinationStore_.selectDestination(barDestination); | |
365 | |
366 var device = getCddTemplate("BarDevice"); | |
367 device.capabilities.printer.color = { | |
368 "option": [ | |
369 {"is_default": true, "type": "STANDARD_MONOCHROME"} | |
370 ] | |
371 }; | |
372 this.setCapabilities(device); | |
373 | |
374 this.waitForAnimationToEnd('more-settings'); | |
375 }.bind(this)); | |
376 }); | |
377 | |
378 // Test that error message is displayed when plugin doesn't exist. | |
379 TEST_F('PrintPreviewWebUITest', 'TestNoPDFPluginErrorMessage', function() { | |
380 this.setInitialSettings(); | |
381 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
382 function() { | |
383 var previewAreaEl = $('preview-area'); | |
384 | |
385 var loadingMessageEl = | |
386 previewAreaEl. | |
387 getElementsByClassName('preview-area-loading-message')[0]; | |
388 expectTrue(loadingMessageEl.hidden); | |
389 | |
390 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( | |
391 'preview-area-preview-failed-message')[0]; | |
392 expectTrue(previewFailedMessageEl.hidden); | |
393 | |
394 var printFailedMessageEl = | |
395 previewAreaEl. | |
396 getElementsByClassName('preview-area-print-failed')[0]; | |
397 expectTrue(printFailedMessageEl.hidden); | |
398 | |
399 var customMessageEl = | |
400 previewAreaEl. | |
401 getElementsByClassName('preview-area-custom-message')[0]; | |
402 expectFalse(customMessageEl.hidden); | |
403 | |
404 testDone(); | |
405 }); | |
406 }); | |
407 | |
408 // Test custom localized paper names. | |
409 TEST_F('PrintPreviewWebUITest', 'TestCustomPaperNames', function() { | |
410 this.setInitialSettings(); | |
411 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
412 function() { | |
413 this.setLocalDestinations(); | |
414 | |
415 var customLocalizedMediaName = 'Vendor defined localized media name'; | |
416 var customMediaName = 'Vendor defined media name'; | |
417 | |
418 var device = getCddTemplate("FooDevice"); | |
419 device.capabilities.printer.media_size = { | |
420 option: [ | |
421 { name: 'CUSTOM', | |
422 width_microns: 15900, | |
423 height_microns: 79400, | |
424 is_default: true, | |
425 custom_display_name_localized: [ | |
426 { locale: navigator.language, | |
427 value: customLocalizedMediaName | |
428 } | |
429 ] | |
430 }, | |
431 { name: 'CUSTOM', | |
432 width_microns: 15900, | |
433 height_microns: 79400, | |
434 custom_display_name: customMediaName | |
435 } | |
436 ] | |
437 }; | |
438 | |
439 this.setCapabilities(device); | |
440 | |
441 this.expandMoreSettings(); | |
442 | |
443 checkSectionVisible($('media-size-settings'), true); | |
444 var mediaSelect = | |
445 $('media-size-settings').querySelector('.settings-select'); | |
446 // Check the default media item. | |
447 expectEquals( | |
448 customLocalizedMediaName, | |
449 mediaSelect.options[mediaSelect.selectedIndex].text); | |
450 // Check the other media item. | |
451 expectEquals( | |
452 customMediaName, | |
453 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); | |
454 | |
455 this.waitForAnimationToEnd('more-settings'); | |
456 }.bind(this)); | |
457 }); | |
458 | |
459 function getCddTemplateWithAdvancedSettings(printerId) { | |
460 return { | |
461 printerId: printerId, | |
462 capabilities: { | |
463 version: '1.0', | |
464 printer: { | |
465 supported_content_type: [{content_type: 'application/pdf'}], | |
466 vendor_capability: | |
467 [ | |
468 {display_name: 'Print Area', | |
469 id: 'Print Area', | |
470 type: 'SELECT', | |
471 select_cap: { | |
472 option: [ | |
473 {display_name: 'A4', value: 4, is_default: true}, | |
474 {display_name: 'A6', value: 6}, | |
475 {display_name: 'A7', value: 7} | |
476 ] | |
477 } | |
478 } | |
479 ], | |
480 collate: {}, | |
481 color: { | |
482 option: [ | |
483 {type: 'STANDARD_COLOR', is_default: true}, | |
484 {type: 'STANDARD_MONOCHROME'} | |
485 ] | |
486 }, | |
487 copies: {}, | |
488 duplex: { | |
489 option: [ | |
490 {type: 'NO_DUPLEX', is_default: true}, | |
491 {type: 'LONG_EDGE'}, | |
492 {type: 'SHORT_EDGE'} | |
493 ] | |
494 }, | |
495 page_orientation: { | |
496 option: [ | |
497 {type: 'PORTRAIT', is_default: true}, | |
498 {type: 'LANDSCAPE'}, | |
499 {type: 'AUTO'} | |
500 ] | |
501 }, | |
502 media_size: { | |
503 option: [ | |
504 { name: 'NA_LETTER', | |
505 width_microns: 215900, | |
506 height_microns: 279400, | |
507 is_default: true | |
508 } | |
509 ] | |
510 }, | |
511 } | |
512 } | |
513 }; | |
514 } | |
515 | |
516 // Simulates a click of the advanced options settings button to bring up the | |
517 // advanced settings overlay. | |
518 function openAdvancedSettings() { | |
519 // Check for button and click to view advanced settings section. | |
520 var advancedOptionsSettingsButton = | |
521 $('advanced-options-settings'). | |
522 querySelector('.advanced-options-settings-button'); | |
523 checkElementDisplayed(advancedOptionsSettingsButton, true); | |
524 // Button is disabled during testing due to test version of | |
525 // testPluginCompatibility() being set to always return false. Enable button | |
526 // to send click event. | |
527 advancedOptionsSettingsButton.disabled = false; | |
528 advancedOptionsSettingsButton.click(); | |
529 } | |
530 | |
531 // Test advanced settings with 1 capability (should not display settings search | |
532 // box). | |
533 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings1Option', function() { | |
534 var device = getCddTemplateWithAdvancedSettings("FooDevice"); | |
535 this.accessibilityIssuesAreErrors = false; | |
536 this.setInitialSettings(); | |
537 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
538 function() { | |
539 this.setupAdvancedSettingsTest(device); | |
540 | |
541 // Open the advanced settings overlay. | |
542 openAdvancedSettings(); | |
543 | |
544 // Check that advanced settings close button is now visible, | |
545 // but not the search box (only 1 capability). | |
546 var advancedSettingsCloseButton = $('advanced-settings'). | |
547 querySelector('.close-button'); | |
548 checkElementDisplayed(advancedSettingsCloseButton, true); | |
549 checkElementDisplayed($('advanced-settings'). | |
550 querySelector('.search-box-area'), false); | |
551 | |
552 this.waitForAnimationToEnd('more-settings'); | |
553 }.bind(this)); | |
554 }); | |
555 | |
556 | |
557 // Test advanced settings with 2 capabilities (should have settings search box). | |
558 TEST_F('PrintPreviewWebUITest', 'TestAdvancedSettings2Options', function() { | |
559 var device = getCddTemplateWithAdvancedSettings("FooDevice"); | |
560 // Add new capability. | |
561 device.capabilities.printer.vendor_capability.push({ | |
562 display_name: 'Paper Type', | |
563 id: 'Paper Type', | |
564 type: 'SELECT', | |
565 select_cap: { | |
566 option: [ | |
567 {display_name: 'Standard', value: 0, is_default: true}, | |
568 {display_name: 'Recycled', value: 1}, | |
569 {display_name: 'Special', value: 2} | |
570 ] | |
571 } | |
572 }); | |
573 this.accessibilityIssuesAreErrors = false; | |
574 this.setInitialSettings(); | |
575 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
576 function() { | |
577 this.setupAdvancedSettingsTest(device); | |
578 | |
579 // Open the advanced settings overlay. | |
580 openAdvancedSettings(); | |
581 | |
582 // Check advanced settings is visible and that the search box now | |
583 // appears. | |
584 var advancedSettingsCloseButton = $('advanced-settings'). | |
585 querySelector('.close-button'); | |
586 checkElementDisplayed(advancedSettingsCloseButton, true); | |
587 checkElementDisplayed($('advanced-settings'). | |
588 querySelector('.search-box-area'), true); | |
589 | |
590 this.waitForAnimationToEnd('more-settings'); | |
591 }.bind(this)); | |
592 }); | |
593 | |
594 // Test that initialization with saved destination only issues one call | |
595 // to startPreview. | |
596 TEST_F('PrintPreviewWebUITest', 'TestInitIssuesOneRequest', function() { | |
597 this.createPrintPreview(); | |
598 // Load in a bunch of recent destinations with non null capabilities. | |
599 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; | |
600 var initSettings = { | |
601 version: 2, | |
602 recentDestinations: [1, 2, 3].map(function(i) { | |
603 return { | |
604 id: 'ID' + i, origin: origin, account: '', | |
605 capabilities: getCddTemplate('ID' + i), name: '', | |
606 extensionId: '', extensionName: '' | |
607 }; | |
608 }), | |
609 }; | |
610 this.initialSettings_.serializedAppStateStr_ = JSON.stringify(initSettings); | |
611 this.setCapabilities(getCddTemplate('ID1')); | |
612 this.setCapabilities(getCddTemplate('ID2')); | |
613 this.setCapabilities(getCddTemplate('ID3')); | |
614 | |
615 // Use a real preview generator. | |
616 this.previewArea_.previewGenerator_ = | |
617 new print_preview.PreviewGenerator(this.printPreview_.destinationStore_, | |
618 this.printPreview_.printTicketStore_, this.nativeLayer_, | |
619 this.printPreview_.documentInfo_); | |
620 | |
621 // Preview generator starts out with inFlightRequestId_ == -1. The id | |
622 // increments by 1 for each startGetPreview call it makes. It should only | |
623 // make one such call during initialization or there will be a race; see | |
624 // crbug.com/666595 | |
625 expectEquals( | |
626 -1, | |
627 this.previewArea_.previewGenerator_.inFlightRequestId_); | |
628 this.setInitialSettings(); | |
629 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
630 function() { | |
631 expectEquals( | |
632 0, | |
633 this.previewArea_.previewGenerator_. | |
634 inFlightRequestId_); | |
635 testDone(); | |
636 }.bind(this)); | |
637 }); | |
638 | |
639 // Test that invalid settings errors disable the print preview and display | |
640 // an error and that the preview dialog can be recovered by selecting a | |
641 // new destination. | |
642 TEST_F('PrintPreviewWebUITest', 'TestInvalidSettingsError', function() { | |
643 // Setup | |
644 this.setInitialSettings(); | |
645 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
646 function() { | |
647 this.setLocalDestinations(); | |
648 this.setCapabilities(getCddTemplate("FooDevice")); | |
649 | |
650 // Manually enable the print header. This is needed since there is no | |
651 // plugin during test, so it will be set as disabled normally. | |
652 this.printPreview_.printHeader_.isEnabled = true; | |
653 | |
654 // There will be an error message in the preview area since the plugin | |
655 // is not running. However, it should not be the invalid settings error. | |
656 var previewAreaEl = $('preview-area'); | |
657 var customMessageEl = | |
658 previewAreaEl. | |
659 getElementsByClassName('preview-area-custom-message')[0]; | |
660 expectFalse(customMessageEl.hidden); | |
661 var expectedMessageStart = 'The selected printer is not available or ' | |
662 + 'not installed correctly.' | |
663 expectFalse(customMessageEl.textContent.includes(expectedMessageStart)); | |
664 | |
665 // Verify that the print button is enabled. | |
666 var printHeader = $('print-header'); | |
667 var printButton = printHeader.querySelector('button.print'); | |
668 checkElementDisplayed(printButton, true); | |
669 expectFalse(printButton.disabled); | |
670 | |
671 // Report invalid settings error. | |
672 this.dispatchInvalidSettings(); | |
673 | |
674 // Should be in an error state, print button disabled, invalid custom | |
675 // error message shown. | |
676 expectFalse(customMessageEl.hidden); | |
677 expectTrue(customMessageEl.textContent.includes(expectedMessageStart)); | |
678 expectTrue(printButton.disabled); | |
679 | |
680 // Select a new destination | |
681 var barDestination = | |
682 this.printPreview_.destinationStore_.destinations().find( | |
683 function(d) { | |
684 return d.id == 'BarDevice'; | |
685 }); | |
686 | |
687 this.printPreview_.destinationStore_.selectDestination(barDestination); | |
688 | |
689 // Dispatch events indicating capabilities were fetched and new preview | |
690 // has loaded. | |
691 this.setCapabilities(getCddTemplate("BarDevice")); | |
692 this.dispatchPreviewDone(); | |
693 | |
694 // Has active print button and successfully "prints", indicating | |
695 // recovery from error state. | |
696 expectFalse(printButton.disabled); | |
697 expectFalse(this.hasPrinted()); | |
698 printButton.click(); | |
699 expectTrue(this.hasPrinted()); | |
700 testDone(); | |
701 }.bind(this)); | |
702 }); | |
703 | |
704 // Test the preview generator to make sure the generate draft parameter is set | |
705 // correctly. It should be false if the only change is the page range. | |
706 TEST_F('PrintPreviewWebUITest', 'TestGenerateDraft', function() { | |
707 this.createPrintPreview(); | |
708 | |
709 // Use a real preview generator. | |
710 this.previewArea_.previewGenerator_ = | |
711 new print_preview.PreviewGenerator(this.printPreview_.destinationStore_, | |
712 this.printPreview_.printTicketStore_, this.nativeLayer_, | |
713 this.printPreview_.documentInfo_); | |
714 | |
715 this.setInitialSettings(); | |
716 this.nativeLayer_.whenCalled('getInitialSettings').then( | |
717 function() { | |
718 this.setLocalDestinations(); | |
719 this.setCapabilities(getCddTemplate("FooDevice")); | |
720 | |
721 // The first request should generate draft because there was no | |
722 // previous print preview draft. | |
723 expectTrue(this.generateDraft()); | |
724 | |
725 // Change the page range - no new draft needed. | |
726 this.printPreview_.printTicketStore_.pageRange.updateValue("2"); | |
727 expectFalse(this.generateDraft()); | |
728 | |
729 // Change the margin type - need to regenerate again. | |
730 this.printPreview_.printTicketStore_.marginsType.updateValue( | |
731 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); | |
732 expectTrue(this.generateDraft()); | |
733 | |
734 testDone(); | |
735 }.bind(this)); | |
736 }); | |
OLD | NEW |