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