| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('print_preview_test', function() { | 5 cr.define('print_preview_test', function() { |
| 6 /** | 6 /** |
| 7 * Index of the "Save as PDF" printer. | 7 * Index of the "Save as PDF" printer. |
| 8 * @type {number} | 8 * @type {number} |
| 9 * @const | 9 * @const |
| 10 */ | 10 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 var BAR_INDEX = 2; | 25 var BAR_INDEX = 2; |
| 26 | 26 |
| 27 var printPreview = null; | 27 var printPreview = null; |
| 28 var nativeLayer = null; | 28 var nativeLayer = null; |
| 29 var initialSettings = null; | 29 var initialSettings = null; |
| 30 var localDestinationInfos = null; | 30 var localDestinationInfos = null; |
| 31 var previewArea = null; | 31 var previewArea = null; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Initialize print preview with the initial settings currently stored in | 34 * Initialize print preview with the initial settings currently stored in |
| 35 * |initialSettings|. Creates |printPreview| if it does not | 35 * |initialSettings|. |
| 36 * already exist. | |
| 37 */ | 36 */ |
| 38 function setInitialSettings() { | 37 function setInitialSettings() { |
| 39 nativeLayer.setInitialSettings(initialSettings); | 38 nativeLayer.setInitialSettings(initialSettings); |
| 40 printPreview.initialize(); | 39 printPreview.initialize(); |
| 41 } | 40 } |
| 42 | 41 |
| 43 /** | 42 /** |
| 44 * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will | 43 * Start loading the local destinations using the destination infos currently |
| 45 * happen in the same thread. | 44 * stored in |localDestinationInfos|. |
| 46 */ | 45 */ |
| 47 function setLocalDestinations() { | 46 function setLocalDestinations() { |
| 48 var localDestsSetEvent = | 47 nativeLayer.setLocalDestinations(localDestinationInfos); |
| 49 new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); | 48 printPreview.destinationStore_.startLoadLocalDestinations(); |
| 50 localDestsSetEvent.destinationInfos = localDestinationInfos; | |
| 51 nativeLayer.getEventTarget().dispatchEvent(localDestsSetEvent); | |
| 52 } | 49 } |
| 53 | 50 |
| 54 /** | 51 /** |
| 52 * Initializes print preview with the initial settings currently stored in |
| 53 * |initialSettings|, waits for the getInitialSettings promise to resolve, |
| 54 * and loads local destinations using destination infos currently stored in |
| 55 * |localDestinationInfos|. |
| 56 * @return {!Promise<!Array<!print_preview.LocalDestinationInfo>>} a |
| 57 * promise that will resolve when getPrinters has been resolved by |
| 58 * the native layer stub. |
| 59 */ |
| 60 function setupSettingsAndDestinations() { |
| 61 setInitialSettings(); |
| 62 return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| 63 setLocalDestinations(); |
| 64 return nativeLayer.whenCalled('getPrinters'); |
| 65 }); |
| 66 } |
| 67 |
| 68 /** |
| 55 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will | 69 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will |
| 56 * happen in the same thread. | 70 * happen in the same thread. |
| 57 * @param {!Object} device The device whose capabilities should be dispatched. | 71 * @param {!Object} device The device whose capabilities should be dispatched. |
| 58 */ | 72 */ |
| 59 function setCapabilities(device) { | 73 function setCapabilities(device) { |
| 60 var capsSetEvent = | 74 var capsSetEvent = |
| 61 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | 75 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
| 62 capsSetEvent.settingsInfo = device; | 76 capsSetEvent.settingsInfo = device; |
| 63 nativeLayer.getEventTarget().dispatchEvent(capsSetEvent); | 77 nativeLayer.getEventTarget().dispatchEvent(capsSetEvent); |
| 64 } | 78 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 checkElementDisplayed(advancedOptionsSettingsButton, true); | 203 checkElementDisplayed(advancedOptionsSettingsButton, true); |
| 190 // Button is disabled during testing due to test version of | 204 // Button is disabled during testing due to test version of |
| 191 // testPluginCompatibility() being set to always return false. Enable button | 205 // testPluginCompatibility() being set to always return false. Enable button |
| 192 // to send click event. | 206 // to send click event. |
| 193 advancedOptionsSettingsButton.disabled = false; | 207 advancedOptionsSettingsButton.disabled = false; |
| 194 advancedOptionsSettingsButton.click(); | 208 advancedOptionsSettingsButton.click(); |
| 195 } | 209 } |
| 196 | 210 |
| 197 /** | 211 /** |
| 198 * Repeated setup steps for the advanced settings tests. | 212 * Repeated setup steps for the advanced settings tests. |
| 199 * Sets initial settings, and verifies advanced options section is visible | 213 * Sets capabilities, and verifies advanced options section is visible |
| 200 * after expanding more settings. | 214 * after expanding more settings. Then opens the advanced settings overlay |
| 215 * and verifies it is displayed. |
| 201 */ | 216 */ |
| 202 function setupAdvancedSettingsTest(device) { | 217 function startAdvancedSettingsTest(device) { |
| 203 setLocalDestinations(); | |
| 204 setCapabilities(device); | 218 setCapabilities(device); |
| 205 expandMoreSettings(); | 219 expandMoreSettings(); |
| 206 | 220 |
| 207 // Check that the advanced options settings section is visible. | 221 // Check that the advanced options settings section is visible. |
| 208 checkSectionVisible($('advanced-options-settings'), true); | 222 checkSectionVisible($('advanced-options-settings'), true); |
| 223 |
| 224 // Open the advanced settings overlay. |
| 225 openAdvancedSettings(); |
| 226 |
| 227 // Check advanced settings overlay is visible by checking that the close |
| 228 // button is displayed. |
| 229 var advancedSettingsCloseButton = $('advanced-settings'). |
| 230 querySelector('.close-button'); |
| 231 checkElementDisplayed(advancedSettingsCloseButton, true); |
| 209 } | 232 } |
| 210 | 233 |
| 211 /** @return {boolean} */ | 234 /** @return {boolean} */ |
| 212 function isPrintAsImageEnabled() { | 235 function isPrintAsImageEnabled() { |
| 213 // Should be enabled by default on non Windows/Mac. | 236 // Should be enabled by default on non Windows/Mac. |
| 214 return (!cr.isWindows && !cr.isMac && | 237 return (!cr.isWindows && !cr.isMac && |
| 215 loadTimeData.getBoolean('printPdfAsImageEnabled')); | 238 loadTimeData.getBoolean('printPdfAsImageEnabled')); |
| 216 } | 239 } |
| 217 | 240 |
| 218 suite('PrintPreview', function() { | 241 suite('PrintPreview', function() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 ]; | 278 ]; |
| 256 | 279 |
| 257 nativeLayer = new print_preview.NativeLayerStub(); | 280 nativeLayer = new print_preview.NativeLayerStub(); |
| 258 print_preview.NativeLayer.setInstance(nativeLayer); | 281 print_preview.NativeLayer.setInstance(nativeLayer); |
| 259 printPreview = new print_preview.PrintPreview(); | 282 printPreview = new print_preview.PrintPreview(); |
| 260 previewArea = printPreview.getPreviewArea(); | 283 previewArea = printPreview.getPreviewArea(); |
| 261 }); | 284 }); |
| 262 | 285 |
| 263 // Test some basic assumptions about the print preview WebUI. | 286 // Test some basic assumptions about the print preview WebUI. |
| 264 test('PrinterList', function() { | 287 test('PrinterList', function() { |
| 265 setInitialSettings(); | 288 return setupSettingsAndDestinations().then(function() { |
| 266 return nativeLayer.whenCalled('getInitialSettings').then( | 289 var recentList = |
| 267 function() { | 290 $('destination-search').querySelector('.recent-list ul'); |
| 268 setLocalDestinations(); | 291 var localList = |
| 269 var recentList = | 292 $('destination-search').querySelector('.local-list ul'); |
| 270 $('destination-search').querySelector('.recent-list ul'); | 293 assertNotEquals(null, recentList); |
| 271 var localList = | 294 assertEquals(1, recentList.childNodes.length); |
| 272 $('destination-search').querySelector('.local-list ul'); | 295 assertEquals('FooName', |
| 273 assertNotEquals(null, recentList); | 296 recentList.childNodes.item(0).querySelector( |
| 274 assertEquals(1, recentList.childNodes.length); | 297 '.destination-list-item-name').textContent); |
| 275 assertEquals('FooName', | 298 assertNotEquals(null, localList); |
| 276 recentList.childNodes.item(0).querySelector( | 299 assertEquals(3, localList.childNodes.length); |
| 277 '.destination-list-item-name').textContent); | 300 assertEquals( |
| 278 assertNotEquals(null, localList); | 301 'Save as PDF', |
| 279 assertEquals(3, localList.childNodes.length); | 302 localList.childNodes.item(PDF_INDEX). |
| 280 assertEquals( | 303 querySelector('.destination-list-item-name').textContent); |
| 281 'Save as PDF', | 304 assertEquals( |
| 282 localList.childNodes.item(PDF_INDEX). | 305 'FooName', |
| 283 querySelector('.destination-list-item-name').textContent); | 306 localList.childNodes.item(FOO_INDEX). |
| 284 assertEquals( | 307 querySelector('.destination-list-item-name').textContent); |
| 285 'FooName', | 308 assertEquals( |
| 286 localList.childNodes.item(FOO_INDEX). | 309 'BarName', |
| 287 querySelector('.destination-list-item-name').textContent); | 310 localList.childNodes.item(BAR_INDEX). |
| 288 assertEquals( | 311 querySelector('.destination-list-item-name').textContent); |
| 289 'BarName', | 312 }); |
| 290 localList.childNodes.item(BAR_INDEX). | |
| 291 querySelector('.destination-list-item-name').textContent); | |
| 292 }); | |
| 293 }); | 313 }); |
| 294 | 314 |
| 295 // Test that the printer list is structured correctly after calling | 315 // Test that the printer list is structured correctly after calling |
| 296 // addCloudPrinters with an empty list. | 316 // addCloudPrinters with an empty list. |
| 297 test('PrinterListCloudEmpty', function() { | 317 test('PrinterListCloudEmpty', function() { |
| 298 setInitialSettings(); | 318 return setupSettingsAndDestinations().then(function() { |
| 319 var cloudPrintEnableEvent = new Event( |
| 320 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
| 321 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; |
| 322 nativeLayer.getEventTarget().dispatchEvent( |
| 323 cloudPrintEnableEvent); |
| 299 | 324 |
| 300 return nativeLayer.whenCalled('getInitialSettings').then( | 325 var searchDoneEvent = |
| 301 function() { | 326 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); |
| 302 setLocalDestinations(); | 327 searchDoneEvent.printers = []; |
| 328 searchDoneEvent.isRecent = true; |
| 329 searchDoneEvent.email = 'foo@chromium.org'; |
| 330 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent); |
| 303 | 331 |
| 304 var cloudPrintEnableEvent = new Event( | 332 var recentList = |
| 305 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); | 333 $('destination-search').querySelector('.recent-list ul'); |
| 306 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; | 334 var localList = |
| 307 nativeLayer.getEventTarget().dispatchEvent( | 335 $('destination-search').querySelector('.local-list ul'); |
| 308 cloudPrintEnableEvent); | 336 var cloudList = |
| 337 $('destination-search').querySelector('.cloud-list ul'); |
| 309 | 338 |
| 310 var searchDoneEvent = | 339 assertNotEquals(null, recentList); |
| 311 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); | 340 assertEquals(1, recentList.childNodes.length); |
| 312 searchDoneEvent.printers = []; | 341 assertEquals('FooName', |
| 313 searchDoneEvent.isRecent = true; | 342 recentList.childNodes.item(0). |
| 314 searchDoneEvent.email = 'foo@chromium.org'; | 343 querySelector('.destination-list-item-name'). |
| 315 printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent); | 344 textContent); |
| 316 | 345 |
| 317 var recentList = | 346 assertNotEquals(null, localList); |
| 318 $('destination-search').querySelector('.recent-list ul'); | 347 assertEquals(3, localList.childNodes.length); |
| 319 var localList = | 348 assertEquals('Save as PDF', |
| 320 $('destination-search').querySelector('.local-list ul'); | 349 localList.childNodes.item(PDF_INDEX). |
| 321 var cloudList = | 350 querySelector('.destination-list-item-name'). |
| 322 $('destination-search').querySelector('.cloud-list ul'); | 351 textContent); |
| 352 assertEquals('FooName', |
| 353 localList.childNodes. |
| 354 item(FOO_INDEX). |
| 355 querySelector('.destination-list-item-name'). |
| 356 textContent); |
| 357 assertEquals('BarName', |
| 358 localList.childNodes. |
| 359 item(BAR_INDEX). |
| 360 querySelector('.destination-list-item-name'). |
| 361 textContent); |
| 323 | 362 |
| 324 assertNotEquals(null, recentList); | 363 assertNotEquals(null, cloudList); |
| 325 assertEquals(1, recentList.childNodes.length); | 364 assertEquals(0, cloudList.childNodes.length); |
| 326 assertEquals('FooName', | 365 }); |
| 327 recentList.childNodes.item(0). | |
| 328 querySelector('.destination-list-item-name'). | |
| 329 textContent); | |
| 330 | |
| 331 assertNotEquals(null, localList); | |
| 332 assertEquals(3, localList.childNodes.length); | |
| 333 assertEquals('Save as PDF', | |
| 334 localList.childNodes.item(PDF_INDEX). | |
| 335 querySelector('.destination-list-item-name'). | |
| 336 textContent); | |
| 337 assertEquals('FooName', | |
| 338 localList.childNodes. | |
| 339 item(FOO_INDEX). | |
| 340 querySelector('.destination-list-item-name'). | |
| 341 textContent); | |
| 342 assertEquals('BarName', | |
| 343 localList.childNodes. | |
| 344 item(BAR_INDEX). | |
| 345 querySelector('.destination-list-item-name'). | |
| 346 textContent); | |
| 347 | |
| 348 assertNotEquals(null, cloudList); | |
| 349 assertEquals(0, cloudList.childNodes.length); | |
| 350 }); | |
| 351 }); | 366 }); |
| 352 | 367 |
| 353 // Test restore settings with one destination. | 368 // Test restore settings with one destination. |
| 354 test('RestoreLocalDestination', function() { | 369 test('RestoreLocalDestination', function() { |
| 355 initialSettings.serializedAppStateStr_ = JSON.stringify({ | 370 initialSettings.serializedAppStateStr_ = JSON.stringify({ |
| 356 version: 2, | 371 version: 2, |
| 357 recentDestinations: [ | 372 recentDestinations: [ |
| 358 { | 373 { |
| 359 id: 'ID', | 374 id: 'ID', |
| 360 origin: cr.isChromeOS ? 'chrome_os' : 'local', | 375 origin: cr.isChromeOS ? 'chrome_os' : 'local', |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 assertNotEquals(-1, idsFound.indexOf('ID1')); | 454 assertNotEquals(-1, idsFound.indexOf('ID1')); |
| 440 assertNotEquals(-1, idsFound.indexOf('ID2')); | 455 assertNotEquals(-1, idsFound.indexOf('ID2')); |
| 441 assertNotEquals(-1, idsFound.indexOf('ID3')); | 456 assertNotEquals(-1, idsFound.indexOf('ID3')); |
| 442 }); | 457 }); |
| 443 }); | 458 }); |
| 444 | 459 |
| 445 test('DefaultDestinationSelectionRules', function() { | 460 test('DefaultDestinationSelectionRules', function() { |
| 446 // It also makes sure these rules do override system default destination. | 461 // It also makes sure these rules do override system default destination. |
| 447 initialSettings.serializedDefaultDestinationSelectionRulesStr_ = | 462 initialSettings.serializedDefaultDestinationSelectionRulesStr_ = |
| 448 JSON.stringify({namePattern: '.*Bar.*'}); | 463 JSON.stringify({namePattern: '.*Bar.*'}); |
| 464 // Set this early as the app state selection string will trigger a load |
| 465 // of local destinations on initialization. |
| 466 nativeLayer.setLocalDestinations(localDestinationInfos); |
| 449 setInitialSettings(); | 467 setInitialSettings(); |
| 450 return nativeLayer.whenCalled('getInitialSettings').then( | 468 return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| 451 function() { | 469 return nativeLayer.whenCalled('getPrinters').then(function() { |
| 452 setLocalDestinations(); | 470 assertEquals('BarDevice', |
| 453 assertEquals( | 471 printPreview.destinationStore_.selectedDestination.id); |
| 454 'BarDevice', | 472 }); |
| 455 printPreview.destinationStore_.selectedDestination.id); | 473 }); |
| 456 }); | |
| 457 }); | 474 }); |
| 458 | 475 |
| 459 test('SystemDialogLinkIsHiddenInAppKioskMode', function() { | 476 test('SystemDialogLinkIsHiddenInAppKioskMode', function() { |
| 460 if (!cr.isChromeOS) | 477 if (!cr.isChromeOS) |
| 461 initialSettings.isInAppKioskMode_ = true; | 478 initialSettings.isInAppKioskMode_ = true; |
| 462 | 479 |
| 463 setInitialSettings(); | 480 setInitialSettings(); |
| 464 return nativeLayer.whenCalled('getInitialSettings').then( | 481 return nativeLayer.whenCalled('getInitialSettings').then( |
| 465 function() { | 482 function() { |
| 466 if (cr.isChromeOS) | 483 if (cr.isChromeOS) |
| 467 assertEquals(null, $('system-dialog-link')); | 484 assertEquals(null, $('system-dialog-link')); |
| 468 else | 485 else |
| 469 checkElementDisplayed($('system-dialog-link'), false); | 486 checkElementDisplayed($('system-dialog-link'), false); |
| 470 }); | 487 }); |
| 471 }); | 488 }); |
| 472 | 489 |
| 473 test('SectionsDisabled', function() { | 490 test('SectionsDisabled', function() { |
| 474 checkSectionVisible($('layout-settings'), false); | 491 checkSectionVisible($('layout-settings'), false); |
| 475 checkSectionVisible($('color-settings'), false); | 492 checkSectionVisible($('color-settings'), false); |
| 476 checkSectionVisible($('copies-settings'), false); | 493 checkSectionVisible($('copies-settings'), false); |
| 477 | 494 |
| 478 setInitialSettings(); | 495 return setupSettingsAndDestinations().then(function() { |
| 479 return nativeLayer.whenCalled('getInitialSettings').then( | 496 var device = getCddTemplate('FooDevice'); |
| 480 function() { | 497 device.capabilities.printer.color = { |
| 481 setLocalDestinations(); | 498 option: [{is_default: true, type: 'STANDARD_COLOR'}] |
| 482 var device = getCddTemplate('FooDevice'); | 499 }; |
| 483 device.capabilities.printer.color = { | 500 delete device.capabilities.printer.copies; |
| 484 option: [{is_default: true, type: 'STANDARD_COLOR'}] | 501 setCapabilities(device); |
| 485 }; | |
| 486 delete device.capabilities.printer.copies; | |
| 487 setCapabilities(device); | |
| 488 | 502 |
| 489 checkSectionVisible($('layout-settings'), true); | 503 checkSectionVisible($('layout-settings'), true); |
| 490 checkSectionVisible($('color-settings'), false); | 504 checkSectionVisible($('color-settings'), false); |
| 491 checkSectionVisible($('copies-settings'), false); | 505 checkSectionVisible($('copies-settings'), false); |
| 492 | 506 |
| 493 return whenAnimationDone('other-options-collapsible'); | 507 return whenAnimationDone('other-options-collapsible'); |
| 494 }); | 508 }); |
| 495 }); | 509 }); |
| 496 | 510 |
| 497 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide | 511 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide |
| 498 // the fit to page option. | 512 // the fit to page option. |
| 499 test('PrintToPDFSelectedCapabilities', function() { | 513 test('PrintToPDFSelectedCapabilities', function() { |
| 500 // Add PDF printer. | 514 // Add PDF printer. |
| 501 initialSettings.isDocumentModifiable_ = false; | 515 initialSettings.isDocumentModifiable_ = false; |
| 502 initialSettings.systemDefaultDestinationId_ = 'Save as PDF'; | 516 initialSettings.systemDefaultDestinationId_ = 'Save as PDF'; |
| 503 setInitialSettings(); | 517 setInitialSettings(); |
| 504 | 518 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 526 width_microns: 0, | 540 width_microns: 0, |
| 527 height_microns: 0, | 541 height_microns: 0, |
| 528 is_default: true | 542 is_default: true |
| 529 } | 543 } |
| 530 ] | 544 ] |
| 531 } | 545 } |
| 532 } | 546 } |
| 533 } | 547 } |
| 534 }; | 548 }; |
| 535 setCapabilities(device); | 549 setCapabilities(device); |
| 536 | |
| 537 var otherOptions = $('other-options-settings'); | 550 var otherOptions = $('other-options-settings'); |
| 538 // If rasterization is an option, other options should be visible. If | 551 // If rasterization is an option, other options should be visible. |
| 539 // not, there should be no available other options. | 552 // If not, there should be no available other options. |
| 540 checkSectionVisible(otherOptions, isPrintAsImageEnabled()); | 553 checkSectionVisible(otherOptions, isPrintAsImageEnabled()); |
| 541 if (isPrintAsImageEnabled()) { | 554 if (isPrintAsImageEnabled()) { |
| 542 checkElementDisplayed( | 555 checkElementDisplayed( |
| 543 otherOptions.querySelector('#fit-to-page-container'), false); | 556 otherOptions.querySelector('#fit-to-page-container'), false); |
| 544 checkElementDisplayed( | 557 checkElementDisplayed( |
| 545 otherOptions.querySelector('#rasterize-container'), true); | 558 otherOptions.querySelector('#rasterize-container'), true); |
| 546 } | 559 } |
| 547 checkSectionVisible($('media-size-settings'), false); | 560 checkSectionVisible($('media-size-settings'), false); |
| 548 checkSectionVisible($('scaling-settings'), false); | 561 checkSectionVisible($('scaling-settings'), false); |
| 549 }); | 562 }); |
| 550 }); | 563 }); |
| 551 | 564 |
| 552 // When the source is 'HTML', we always hide the fit to page option and show | 565 // When the source is 'HTML', we always hide the fit to page option and show |
| 553 // media size option. | 566 // media size option. |
| 554 test('SourceIsHTMLCapabilities', function() { | 567 test('SourceIsHTMLCapabilities', function() { |
| 555 setInitialSettings(); | 568 return setupSettingsAndDestinations().then(function() { |
| 556 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 557 setLocalDestinations(); | |
| 558 setCapabilities(getCddTemplate('FooDevice')); | 569 setCapabilities(getCddTemplate('FooDevice')); |
| 559 | 570 |
| 560 var otherOptions = $('other-options-settings'); | 571 var otherOptions = $('other-options-settings'); |
| 561 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); | 572 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); |
| 562 var rasterize; | 573 var rasterize; |
| 563 if (isPrintAsImageEnabled()) | 574 if (isPrintAsImageEnabled()) |
| 564 rasterize = otherOptions.querySelector('#rasterize-container'); | 575 rasterize = otherOptions.querySelector('#rasterize-container'); |
| 565 var mediaSize = $('media-size-settings'); | 576 var mediaSize = $('media-size-settings'); |
| 566 var scalingSettings = $('scaling-settings'); | 577 var scalingSettings = $('scaling-settings'); |
| 567 | 578 |
| 568 // Check that options are collapsed (section is visible, because duplex | 579 // Check that options are collapsed (section is visible, because |
| 569 // is available). | 580 // duplex is available). |
| 570 checkSectionVisible(otherOptions, true); | 581 checkSectionVisible(otherOptions, true); |
| 571 checkElementDisplayed(fitToPage, false); | 582 checkElementDisplayed(fitToPage, false); |
| 572 if (isPrintAsImageEnabled()) | 583 if (isPrintAsImageEnabled()) |
| 573 checkElementDisplayed(rasterize, false); | 584 checkElementDisplayed(rasterize, false); |
| 574 checkSectionVisible(mediaSize, false); | 585 checkSectionVisible(mediaSize, false); |
| 575 checkSectionVisible(scalingSettings, false); | 586 checkSectionVisible(scalingSettings, false); |
| 576 | 587 |
| 577 expandMoreSettings(); | 588 expandMoreSettings(); |
| 578 | 589 |
| 579 checkElementDisplayed(fitToPage, false); | 590 checkElementDisplayed(fitToPage, false); |
| 580 if (isPrintAsImageEnabled()) | 591 if (isPrintAsImageEnabled()) |
| 581 checkElementDisplayed(rasterize, false); | 592 checkElementDisplayed(rasterize, false); |
| 582 checkSectionVisible(mediaSize, true); | 593 checkSectionVisible(mediaSize, true); |
| 583 checkSectionVisible(scalingSettings, true); | 594 checkSectionVisible(scalingSettings, true); |
| 584 | 595 |
| 585 return whenAnimationDone('more-settings'); | 596 return whenAnimationDone('more-settings'); |
| 586 }); | 597 }); |
| 587 }); | 598 }); |
| 588 | 599 |
| 589 // When the source is 'PDF', depending on the selected destination printer, | 600 // When the source is 'PDF', depending on the selected destination printer, |
| 590 // we show/hide the fit to page option and hide media size selection. | 601 // we show/hide the fit to page option and hide media size selection. |
| 591 test('SourceIsPDFCapabilities', function() { | 602 test('SourceIsPDFCapabilities', function() { |
| 592 initialSettings.isDocumentModifiable_ = false; | 603 initialSettings.isDocumentModifiable_ = false; |
| 593 setInitialSettings(); | 604 return setupSettingsAndDestinations().then(function() { |
| 594 return nativeLayer.whenCalled('getInitialSettings').then( | 605 setCapabilities(getCddTemplate('FooDevice')); |
| 595 function() { | |
| 596 setLocalDestinations(); | |
| 597 setCapabilities(getCddTemplate('FooDevice')); | |
| 598 | 606 |
| 599 var otherOptions = $('other-options-settings'); | 607 var otherOptions = $('other-options-settings'); |
| 600 var scalingSettings = $('scaling-settings'); | 608 var scalingSettings = $('scaling-settings'); |
| 601 var fitToPageContainer = | 609 var fitToPageContainer = |
| 602 otherOptions.querySelector('#fit-to-page-container'); | 610 otherOptions.querySelector('#fit-to-page-container'); |
| 603 var rasterizeContainer; | 611 var rasterizeContainer; |
| 604 if (isPrintAsImageEnabled()) { | 612 if (isPrintAsImageEnabled()) { |
| 605 rasterizeContainer = | 613 rasterizeContainer = |
| 606 otherOptions.querySelector('#rasterize-container'); | 614 otherOptions.querySelector('#rasterize-container'); |
| 607 } | 615 } |
| 608 | 616 |
| 609 checkSectionVisible(otherOptions, true); | 617 checkSectionVisible(otherOptions, true); |
| 610 checkElementDisplayed(fitToPageContainer, true); | 618 checkElementDisplayed(fitToPageContainer, true); |
| 611 if (isPrintAsImageEnabled()) | 619 if (isPrintAsImageEnabled()) |
| 612 checkElementDisplayed(rasterizeContainer, false); | 620 checkElementDisplayed(rasterizeContainer, false); |
| 613 expectTrue( | 621 expectTrue( |
| 614 fitToPageContainer.querySelector('.checkbox').checked); | 622 fitToPageContainer.querySelector('.checkbox').checked); |
| 615 expandMoreSettings(); | 623 expandMoreSettings(); |
| 616 if (isPrintAsImageEnabled()) { | 624 if (isPrintAsImageEnabled()) { |
| 617 checkElementDisplayed(rasterizeContainer, true); | 625 checkElementDisplayed(rasterizeContainer, true); |
| 618 expectFalse( | 626 expectFalse( |
| 619 rasterizeContainer.querySelector('.checkbox').checked); | 627 rasterizeContainer.querySelector('.checkbox').checked); |
| 620 } | 628 } |
| 621 checkSectionVisible($('media-size-settings'), true); | 629 checkSectionVisible($('media-size-settings'), true); |
| 622 checkSectionVisible(scalingSettings, true); | 630 checkSectionVisible(scalingSettings, true); |
| 623 | 631 |
| 624 return whenAnimationDone('other-options-collapsible'); | 632 return whenAnimationDone('other-options-collapsible'); |
| 625 }); | 633 }); |
| 626 }); | 634 }); |
| 627 | 635 |
| 628 // When the source is 'PDF', depending on the selected destination printer, | 636 // When the source is 'PDF', depending on the selected destination printer, |
| 629 // we show/hide the fit to page option and hide media size selection. | 637 // we show/hide the fit to page option and hide media size selection. |
| 630 test('ScalingUnchecksFitToPage', function() { | 638 test('ScalingUnchecksFitToPage', function() { |
| 631 initialSettings.isDocumentModifiable_ = false; | 639 initialSettings.isDocumentModifiable_ = false; |
| 632 setInitialSettings(); | 640 return setupSettingsAndDestinations().then(function() { |
| 633 return nativeLayer.whenCalled('getInitialSettings').then( | 641 setCapabilities(getCddTemplate('FooDevice')); |
| 634 function() { | |
| 635 setLocalDestinations(); | |
| 636 setCapabilities(getCddTemplate('FooDevice')); | |
| 637 | 642 |
| 638 var otherOptions = $('other-options-settings'); | 643 var otherOptions = $('other-options-settings'); |
| 639 var scalingSettings = $('scaling-settings'); | 644 var scalingSettings = $('scaling-settings'); |
| 640 | 645 |
| 641 checkSectionVisible(otherOptions, true); | 646 checkSectionVisible(otherOptions, true); |
| 642 var fitToPageContainer = | 647 var fitToPageContainer = |
| 643 otherOptions.querySelector('#fit-to-page-container'); | 648 otherOptions.querySelector('#fit-to-page-container'); |
| 644 checkElementDisplayed(fitToPageContainer, true); | 649 checkElementDisplayed(fitToPageContainer, true); |
| 645 expectTrue( | 650 expectTrue( |
| 646 fitToPageContainer.querySelector('.checkbox').checked); | 651 fitToPageContainer.querySelector('.checkbox').checked); |
| 647 expandMoreSettings(); | 652 expandMoreSettings(); |
| 648 checkSectionVisible($('media-size-settings'), true); | 653 checkSectionVisible($('media-size-settings'), true); |
| 649 checkSectionVisible(scalingSettings, true); | 654 checkSectionVisible(scalingSettings, true); |
| 650 | 655 |
| 651 // Change scaling input | 656 // Change scaling input |
| 652 var scalingInput = scalingSettings.querySelector('.user-value'); | 657 var scalingInput = scalingSettings.querySelector('.user-value'); |
| 653 expectEquals('100', scalingInput.value); | 658 expectEquals('100', scalingInput.value); |
| 654 scalingInput.stepUp(5); | 659 scalingInput.stepUp(5); |
| 655 expectEquals('105', scalingInput.value); | 660 expectEquals('105', scalingInput.value); |
| 656 | 661 |
| 657 // Trigger the event | 662 // Trigger the event |
| 658 var enterEvent = document.createEvent('Event'); | 663 var enterEvent = document.createEvent('Event'); |
| 659 enterEvent.initEvent('keydown'); | 664 enterEvent.initEvent('keydown'); |
| 660 enterEvent.keyCode = 'Enter'; | 665 enterEvent.keyCode = 'Enter'; |
| 661 scalingInput.dispatchEvent(enterEvent); | 666 scalingInput.dispatchEvent(enterEvent); |
| 662 expectFalse( | 667 expectFalse( |
| 663 fitToPageContainer.querySelector('.checkbox').checked); | 668 fitToPageContainer.querySelector('.checkbox').checked); |
| 664 | 669 |
| 665 return whenAnimationDone('other-options-collapsible'); | 670 return whenAnimationDone('other-options-collapsible'); |
| 666 }); | 671 }); |
| 667 }); | 672 }); |
| 668 | 673 |
| 669 // When the number of copies print preset is set for source 'PDF', we update | 674 // When the number of copies print preset is set for source 'PDF', we update |
| 670 // the copies value if capability is supported by printer. | 675 // the copies value if capability is supported by printer. |
| 671 test('CheckNumCopiesPrintPreset', function() { | 676 test('CheckNumCopiesPrintPreset', function() { |
| 672 initialSettings.isDocumentModifiable_ = false; | 677 initialSettings.isDocumentModifiable_ = false; |
| 673 setInitialSettings(); | 678 return setupSettingsAndDestinations().then(function() { |
| 674 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 675 setLocalDestinations(); | |
| 676 setCapabilities(getCddTemplate('FooDevice')); | 679 setCapabilities(getCddTemplate('FooDevice')); |
| 677 | 680 |
| 678 // Indicate that the number of copies print preset is set for source | 681 // Indicate that the number of copies print preset is set for source |
| 679 // PDF. | 682 // PDF. |
| 680 var printPresetOptions = { | 683 var printPresetOptions = { |
| 681 disableScaling: true, | 684 disableScaling: true, |
| 682 copies: 2 | 685 copies: 2 |
| 683 }; | 686 }; |
| 684 var printPresetOptionsEvent = new Event( | 687 var printPresetOptionsEvent = new Event( |
| 685 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); | 688 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| 686 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; | 689 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| 687 nativeLayer.getEventTarget(). | 690 nativeLayer.getEventTarget(). |
| 688 dispatchEvent(printPresetOptionsEvent); | 691 dispatchEvent(printPresetOptionsEvent); |
| 689 | 692 |
| 690 checkSectionVisible($('copies-settings'), true); | 693 checkSectionVisible($('copies-settings'), true); |
| 691 expectEquals( | 694 expectEquals( |
| 692 printPresetOptions.copies, | 695 printPresetOptions.copies, |
| 693 parseInt($('copies-settings').querySelector('.user-value').value)); | 696 parseInt($('copies-settings'). |
| 697 querySelector('.user-value').value)); |
| 694 | 698 |
| 695 return whenAnimationDone('other-options-collapsible'); | 699 return whenAnimationDone('other-options-collapsible'); |
| 696 }); | 700 }); |
| 697 }); | 701 }); |
| 698 | 702 |
| 699 // When the duplex print preset is set for source 'PDF', we update the | 703 // When the duplex print preset is set for source 'PDF', we update the |
| 700 // duplex setting if capability is supported by printer. | 704 // duplex setting if capability is supported by printer. |
| 701 test('CheckDuplexPrintPreset', function() { | 705 test('CheckDuplexPrintPreset', function() { |
| 702 initialSettings.isDocumentModifiable_ = false; | 706 initialSettings.isDocumentModifiable_ = false; |
| 703 setInitialSettings(); | 707 return setupSettingsAndDestinations().then(function() { |
| 708 setCapabilities(getCddTemplate('FooDevice')); |
| 704 | 709 |
| 705 return nativeLayer.whenCalled('getInitialSettings').then( | 710 // Indicate that the duplex print preset is set to 'long edge' for |
| 706 function() { | 711 // source PDF. |
| 707 setLocalDestinations(); | 712 var printPresetOptions = { |
| 708 setCapabilities(getCddTemplate('FooDevice')); | 713 duplex: 1 |
| 714 }; |
| 715 var printPresetOptionsEvent = new Event( |
| 716 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| 717 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| 718 nativeLayer.getEventTarget(). |
| 719 dispatchEvent(printPresetOptionsEvent); |
| 709 | 720 |
| 710 // Indicate that the duplex print preset is set to 'long edge' for | 721 var otherOptions = $('other-options-settings'); |
| 711 // source PDF. | 722 checkSectionVisible(otherOptions, true); |
| 712 var printPresetOptions = { | 723 var duplexContainer = |
| 713 duplex: 1 | 724 otherOptions.querySelector('#duplex-container'); |
| 714 }; | 725 checkElementDisplayed(duplexContainer, true); |
| 715 var printPresetOptionsEvent = new Event( | 726 expectTrue(duplexContainer.querySelector('.checkbox').checked); |
| 716 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); | |
| 717 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; | |
| 718 nativeLayer.getEventTarget(). | |
| 719 dispatchEvent(printPresetOptionsEvent); | |
| 720 | 727 |
| 721 var otherOptions = $('other-options-settings'); | 728 return whenAnimationDone('other-options-collapsible'); |
| 722 checkSectionVisible(otherOptions, true); | 729 }); |
| 723 var duplexContainer = | |
| 724 otherOptions.querySelector('#duplex-container'); | |
| 725 checkElementDisplayed(duplexContainer, true); | |
| 726 expectTrue(duplexContainer.querySelector('.checkbox').checked); | |
| 727 | |
| 728 return whenAnimationDone('other-options-collapsible'); | |
| 729 }); | |
| 730 }); | 730 }); |
| 731 | 731 |
| 732 // Make sure that custom margins controls are properly set up. | 732 // Make sure that custom margins controls are properly set up. |
| 733 test('CustomMarginsControlsCheck', function() { | 733 test('CustomMarginsControlsCheck', function() { |
| 734 setInitialSettings(); | 734 return setupSettingsAndDestinations().then(function() { |
| 735 return nativeLayer.whenCalled('getInitialSettings').then( | 735 setCapabilities(getCddTemplate('FooDevice')); |
| 736 function() { | |
| 737 setLocalDestinations(); | |
| 738 setCapabilities(getCddTemplate('FooDevice')); | |
| 739 | 736 |
| 740 printPreview.printTicketStore_.marginsType.updateValue( | 737 printPreview.printTicketStore_.marginsType.updateValue( |
| 741 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 738 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 742 | 739 |
| 743 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { | 740 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { |
| 744 var control = | 741 var control = |
| 745 $('preview-area').querySelector('.margin-control-' + margin); | 742 $('preview-area').querySelector('.margin-control-' + margin); |
| 746 assertNotEquals(null, control); | 743 assertNotEquals(null, control); |
| 747 var input = control.querySelector('.margin-control-textbox'); | 744 var input = control.querySelector('.margin-control-textbox'); |
| 748 assertTrue(input.hasAttribute('aria-label')); | 745 assertTrue(input.hasAttribute('aria-label')); |
| 749 assertNotEquals('undefined', input.getAttribute('aria-label')); | 746 assertNotEquals('undefined', input.getAttribute('aria-label')); |
| 750 }); | 747 }); |
| 751 return whenAnimationDone('more-settings'); | 748 return whenAnimationDone('more-settings'); |
| 752 }); | 749 }); |
| 753 }); | 750 }); |
| 754 | 751 |
| 755 // Page layout has zero margins. Hide header and footer option. | 752 // Page layout has zero margins. Hide header and footer option. |
| 756 test('PageLayoutHasNoMarginsHideHeaderFooter', function() { | 753 test('PageLayoutHasNoMarginsHideHeaderFooter', function() { |
| 757 setInitialSettings(); | 754 return setupSettingsAndDestinations().then(function() { |
| 758 return nativeLayer.whenCalled('getInitialSettings').then( | 755 setCapabilities(getCddTemplate('FooDevice')); |
| 759 function() { | |
| 760 setLocalDestinations(); | |
| 761 setCapabilities(getCddTemplate('FooDevice')); | |
| 762 | 756 |
| 763 var otherOptions = $('other-options-settings'); | 757 var otherOptions = $('other-options-settings'); |
| 764 var headerFooter = | 758 var headerFooter = |
| 765 otherOptions.querySelector('#header-footer-container'); | 759 otherOptions.querySelector('#header-footer-container'); |
| 766 | 760 |
| 767 // Check that options are collapsed (section is visible, because | 761 // Check that options are collapsed (section is visible, because |
| 768 // duplex is available). | 762 // duplex is available). |
| 769 checkSectionVisible(otherOptions, true); | 763 checkSectionVisible(otherOptions, true); |
| 770 checkElementDisplayed(headerFooter, false); | 764 checkElementDisplayed(headerFooter, false); |
| 771 | 765 |
| 772 expandMoreSettings(); | 766 expandMoreSettings(); |
| 773 | 767 |
| 774 checkElementDisplayed(headerFooter, true); | 768 checkElementDisplayed(headerFooter, true); |
| 775 | 769 |
| 776 printPreview.printTicketStore_.marginsType.updateValue( | 770 printPreview.printTicketStore_.marginsType.updateValue( |
| 777 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 771 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 778 printPreview.printTicketStore_.customMargins.updateValue( | 772 printPreview.printTicketStore_.customMargins.updateValue( |
| 779 new print_preview.Margins(0, 0, 0, 0)); | 773 new print_preview.Margins(0, 0, 0, 0)); |
| 780 | 774 |
| 781 checkElementDisplayed(headerFooter, false); | 775 checkElementDisplayed(headerFooter, false); |
| 782 | 776 |
| 783 return whenAnimationDone('more-settings'); | 777 return whenAnimationDone('more-settings'); |
| 784 }); | 778 }); |
| 785 }); | 779 }); |
| 786 | 780 |
| 787 // Page layout has half-inch margins. Show header and footer option. | 781 // Page layout has half-inch margins. Show header and footer option. |
| 788 test('PageLayoutHasMarginsShowHeaderFooter', function() { | 782 test('PageLayoutHasMarginsShowHeaderFooter', function() { |
| 789 setInitialSettings(); | 783 return setupSettingsAndDestinations().then(function() { |
| 790 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 791 setLocalDestinations(); | |
| 792 setCapabilities(getCddTemplate('FooDevice')); | 784 setCapabilities(getCddTemplate('FooDevice')); |
| 793 | 785 |
| 794 var otherOptions = $('other-options-settings'); | 786 var otherOptions = $('other-options-settings'); |
| 795 var headerFooter = | 787 var headerFooter = |
| 796 otherOptions.querySelector('#header-footer-container'); | 788 otherOptions.querySelector('#header-footer-container'); |
| 797 | 789 |
| 798 // Check that options are collapsed (section is visible, because | 790 // Check that options are collapsed (section is visible, because |
| 799 // duplex is available). | 791 // duplex is available). |
| 800 checkSectionVisible(otherOptions, true); | 792 checkSectionVisible(otherOptions, true); |
| 801 checkElementDisplayed(headerFooter, false); | 793 checkElementDisplayed(headerFooter, false); |
| 802 | 794 |
| 803 expandMoreSettings(); | 795 expandMoreSettings(); |
| 804 | 796 |
| 805 checkElementDisplayed(headerFooter, true); | 797 checkElementDisplayed(headerFooter, true); |
| 806 | 798 |
| 807 printPreview.printTicketStore_.marginsType.updateValue( | 799 printPreview.printTicketStore_.marginsType.updateValue( |
| 808 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 800 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 809 printPreview.printTicketStore_.customMargins.updateValue( | 801 printPreview.printTicketStore_.customMargins.updateValue( |
| 810 new print_preview.Margins(36, 36, 36, 36)); | 802 new print_preview.Margins(36, 36, 36, 36)); |
| 811 | 803 |
| 812 checkElementDisplayed(headerFooter, true); | 804 checkElementDisplayed(headerFooter, true); |
| 813 | 805 |
| 814 return whenAnimationDone('more-settings'); | 806 return whenAnimationDone('more-settings'); |
| 815 }); | 807 }); |
| 816 }); | 808 }); |
| 817 | 809 |
| 818 | |
| 819 // Page layout has zero top and bottom margins. Hide header and footer | 810 // Page layout has zero top and bottom margins. Hide header and footer |
| 820 // option. | 811 // option. |
| 821 test('ZeroTopAndBottomMarginsHideHeaderFooter', function() { | 812 test('ZeroTopAndBottomMarginsHideHeaderFooter', function() { |
| 822 setInitialSettings(); | 813 return setupSettingsAndDestinations().then(function() { |
| 823 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 824 setLocalDestinations(); | |
| 825 setCapabilities(getCddTemplate('FooDevice')); | 814 setCapabilities(getCddTemplate('FooDevice')); |
| 826 | 815 |
| 827 var otherOptions = $('other-options-settings'); | 816 var otherOptions = $('other-options-settings'); |
| 828 var headerFooter = | 817 var headerFooter = |
| 829 otherOptions.querySelector('#header-footer-container'); | 818 otherOptions.querySelector('#header-footer-container'); |
| 830 | 819 |
| 831 // Check that options are collapsed (section is visible, because duplex | 820 // Check that options are collapsed (section is visible, because |
| 832 // is available). | 821 // duplex is available). |
| 833 checkSectionVisible(otherOptions, true); | 822 checkSectionVisible(otherOptions, true); |
| 834 checkElementDisplayed(headerFooter, false); | 823 checkElementDisplayed(headerFooter, false); |
| 835 | 824 |
| 836 expandMoreSettings(); | 825 expandMoreSettings(); |
| 837 | 826 |
| 838 checkElementDisplayed(headerFooter, true); | 827 checkElementDisplayed(headerFooter, true); |
| 839 | 828 |
| 840 printPreview.printTicketStore_.marginsType.updateValue( | 829 printPreview.printTicketStore_.marginsType.updateValue( |
| 841 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 830 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 842 printPreview.printTicketStore_.customMargins.updateValue( | 831 printPreview.printTicketStore_.customMargins.updateValue( |
| 843 new print_preview.Margins(0, 36, 0, 36)); | 832 new print_preview.Margins(0, 36, 0, 36)); |
| 844 | 833 |
| 845 checkElementDisplayed(headerFooter, false); | 834 checkElementDisplayed(headerFooter, false); |
| 846 | 835 |
| 847 return whenAnimationDone('more-settings'); | 836 return whenAnimationDone('more-settings'); |
| 848 }); | 837 }); |
| 849 }); | 838 }); |
| 850 | 839 |
| 851 // Page layout has zero top and half-inch bottom margin. Show header and | 840 // Page layout has zero top and half-inch bottom margin. Show header and |
| 852 // footer option. | 841 // footer option. |
| 853 test('ZeroTopAndNonZeroBottomMarginShowHeaderFooter', function() { | 842 test('ZeroTopAndNonZeroBottomMarginShowHeaderFooter', function() { |
| 854 setInitialSettings(); | 843 return setupSettingsAndDestinations().then(function() { |
| 855 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 856 setLocalDestinations(); | |
| 857 setCapabilities(getCddTemplate('FooDevice')); | 844 setCapabilities(getCddTemplate('FooDevice')); |
| 858 | 845 |
| 859 var otherOptions = $('other-options-settings'); | 846 var otherOptions = $('other-options-settings'); |
| 860 var headerFooter = | 847 var headerFooter = |
| 861 otherOptions.querySelector('#header-footer-container'); | 848 otherOptions.querySelector('#header-footer-container'); |
| 862 | 849 |
| 863 // Check that options are collapsed (section is visible, because duplex | 850 // Check that options are collapsed (section is visible, because |
| 864 // is available). | 851 // duplex is available). |
| 865 checkSectionVisible(otherOptions, true); | 852 checkSectionVisible(otherOptions, true); |
| 866 checkElementDisplayed(headerFooter, false); | 853 checkElementDisplayed(headerFooter, false); |
| 867 | 854 |
| 868 expandMoreSettings(); | 855 expandMoreSettings(); |
| 869 | 856 |
| 870 checkElementDisplayed(headerFooter, true); | 857 checkElementDisplayed(headerFooter, true); |
| 871 | 858 |
| 872 printPreview.printTicketStore_.marginsType.updateValue( | 859 printPreview.printTicketStore_.marginsType.updateValue( |
| 873 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 860 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 874 printPreview.printTicketStore_.customMargins.updateValue( | 861 printPreview.printTicketStore_.customMargins.updateValue( |
| 875 new print_preview.Margins(0, 36, 36, 36)); | 862 new print_preview.Margins(0, 36, 36, 36)); |
| 876 | 863 |
| 877 checkElementDisplayed(headerFooter, true); | 864 checkElementDisplayed(headerFooter, true); |
| 878 | 865 |
| 879 return whenAnimationDone('more-settings'); | 866 return whenAnimationDone('more-settings'); |
| 880 }); | 867 }); |
| 881 }); | 868 }); |
| 882 | 869 |
| 883 // Check header footer availability with small (label) page size. | 870 // Check header footer availability with small (label) page size. |
| 884 test('SmallPaperSizeHeaderFooter', function() { | 871 test('SmallPaperSizeHeaderFooter', function() { |
| 885 setInitialSettings(); | 872 return setupSettingsAndDestinations().then(function() { |
| 886 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 887 setLocalDestinations(); | |
| 888 var device = getCddTemplate('FooDevice'); | 873 var device = getCddTemplate('FooDevice'); |
| 889 device.capabilities.printer.media_size = { | 874 device.capabilities.printer.media_size = { |
| 890 'option': [ | 875 'option': [ |
| 891 {'name': 'SmallLabel', 'width_microns': 38100, | 876 {'name': 'SmallLabel', 'width_microns': 38100, |
| 892 'height_microns': 12700, 'is_default': false}, | 877 'height_microns': 12700, 'is_default': false}, |
| 893 {'name': 'BigLabel', 'width_microns': 50800, | 878 {'name': 'BigLabel', 'width_microns': 50800, |
| 894 'height_microns': 76200, 'is_default': true} | 879 'height_microns': 76200, 'is_default': true} |
| 895 ] | 880 ] |
| 896 }; | 881 }; |
| 897 setCapabilities(device); | 882 setCapabilities(device); |
| 898 | 883 |
| 899 var otherOptions = $('other-options-settings'); | 884 var otherOptions = $('other-options-settings'); |
| 900 var headerFooter = | 885 var headerFooter = |
| 901 otherOptions.querySelector('#header-footer-container'); | 886 otherOptions.querySelector('#header-footer-container'); |
| 902 | 887 |
| 903 // Check that options are collapsed (section is visible, because duplex | 888 // Check that options are collapsed (section is visible, because |
| 904 // is available). | 889 // duplex is available). |
| 905 checkSectionVisible(otherOptions, true); | 890 checkSectionVisible(otherOptions, true); |
| 906 checkElementDisplayed(headerFooter, false); | 891 checkElementDisplayed(headerFooter, false); |
| 907 | 892 |
| 908 expandMoreSettings(); | 893 expandMoreSettings(); |
| 909 | 894 |
| 910 // Big label should have header/footer | 895 // Big label should have header/footer |
| 911 checkElementDisplayed(headerFooter, true); | 896 checkElementDisplayed(headerFooter, true); |
| 912 | 897 |
| 913 // Small label should not | 898 // Small label should not |
| 914 printPreview.printTicketStore_.mediaSize.updateValue( | 899 printPreview.printTicketStore_.mediaSize.updateValue( |
| 915 device.capabilities.printer.media_size.option[0]); | 900 device.capabilities.printer.media_size.option[0]); |
| 916 checkElementDisplayed(headerFooter, false); | 901 checkElementDisplayed(headerFooter, false); |
| 917 | 902 |
| 918 // Oriented in landscape, there should be enough space for | 903 // Oriented in landscape, there should be enough space for |
| 919 // header/footer. | 904 // header/footer. |
| 920 printPreview.printTicketStore_.landscape.updateValue(true); | 905 printPreview.printTicketStore_.landscape.updateValue(true); |
| 921 checkElementDisplayed(headerFooter, true); | 906 checkElementDisplayed(headerFooter, true); |
| 922 | 907 |
| 923 return whenAnimationDone('more-settings'); | 908 return whenAnimationDone('more-settings'); |
| 924 }); | 909 }); |
| 925 }); | 910 }); |
| 926 | 911 |
| 927 // Test that the color settings, one option, standard monochrome. | 912 // Test that the color settings, one option, standard monochrome. |
| 928 test('ColorSettingsMonochrome', function() { | 913 test('ColorSettingsMonochrome', function() { |
| 929 setInitialSettings(); | 914 return setupSettingsAndDestinations().then(function() { |
| 930 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 931 setLocalDestinations(); | |
| 932 | |
| 933 // Only one option, standard monochrome. | 915 // Only one option, standard monochrome. |
| 934 var device = getCddTemplate('FooDevice'); | 916 var device = getCddTemplate('FooDevice'); |
| 935 device.capabilities.printer.color = { | 917 device.capabilities.printer.color = { |
| 936 'option': [ | 918 'option': [ |
| 937 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} | 919 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} |
| 938 ] | 920 ] |
| 939 }; | 921 }; |
| 940 setCapabilities(device); | 922 setCapabilities(device); |
| 941 | 923 |
| 942 checkSectionVisible($('color-settings'), false); | 924 checkSectionVisible($('color-settings'), false); |
| 943 | 925 |
| 944 return whenAnimationDone('more-settings'); | 926 return whenAnimationDone('more-settings'); |
| 945 }); | 927 }); |
| 946 }); | 928 }); |
| 947 | 929 |
| 948 // Test that the color settings, one option, custom monochrome. | 930 // Test that the color settings, one option, custom monochrome. |
| 949 test('ColorSettingsCustomMonochrome', function() { | 931 test('ColorSettingsCustomMonochrome', function() { |
| 950 setInitialSettings(); | 932 return setupSettingsAndDestinations().then(function() { |
| 951 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 952 setLocalDestinations(); | |
| 953 | |
| 954 // Only one option, standard monochrome. | 933 // Only one option, standard monochrome. |
| 955 var device = getCddTemplate('FooDevice'); | 934 var device = getCddTemplate('FooDevice'); |
| 956 device.capabilities.printer.color = { | 935 device.capabilities.printer.color = { |
| 957 'option': [ | 936 'option': [ |
| 958 {'is_default': true, 'type': 'CUSTOM_MONOCHROME', | 937 {'is_default': true, 'type': 'CUSTOM_MONOCHROME', |
| 959 'vendor_id': '42'} | 938 'vendor_id': '42'} |
| 960 ] | 939 ] |
| 961 }; | 940 }; |
| 962 setCapabilities(device); | 941 setCapabilities(device); |
| 963 | 942 |
| 964 checkSectionVisible($('color-settings'), false); | 943 checkSectionVisible($('color-settings'), false); |
| 965 | 944 |
| 966 return whenAnimationDone('more-settings'); | 945 return whenAnimationDone('more-settings'); |
| 967 }); | 946 }); |
| 968 }); | 947 }); |
| 969 | 948 |
| 970 // Test that the color settings, one option, standard color. | 949 // Test that the color settings, one option, standard color. |
| 971 test('ColorSettingsColor', function() { | 950 test('ColorSettingsColor', function() { |
| 972 setInitialSettings(); | 951 return setupSettingsAndDestinations().then(function() { |
| 973 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 974 setLocalDestinations(); | |
| 975 | |
| 976 var device = getCddTemplate('FooDevice'); | 952 var device = getCddTemplate('FooDevice'); |
| 977 device.capabilities.printer.color = { | 953 device.capabilities.printer.color = { |
| 978 'option': [ | 954 'option': [ |
| 979 {'is_default': true, 'type': 'STANDARD_COLOR'} | 955 {'is_default': true, 'type': 'STANDARD_COLOR'} |
| 980 ] | 956 ] |
| 981 }; | 957 }; |
| 982 setCapabilities(device); | 958 setCapabilities(device); |
| 983 | 959 |
| 984 checkSectionVisible($('color-settings'), false); | 960 checkSectionVisible($('color-settings'), false); |
| 985 | 961 |
| 986 return whenAnimationDone('more-settings'); | 962 return whenAnimationDone('more-settings'); |
| 987 }); | 963 }); |
| 988 }); | 964 }); |
| 989 | 965 |
| 990 // Test that the color settings, one option, custom color. | 966 // Test that the color settings, one option, custom color. |
| 991 test('ColorSettingsCustomColor', function() { | 967 test('ColorSettingsCustomColor', function() { |
| 992 setInitialSettings(); | 968 return setupSettingsAndDestinations().then(function() { |
| 993 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 994 setLocalDestinations(); | |
| 995 | |
| 996 var device = getCddTemplate('FooDevice'); | 969 var device = getCddTemplate('FooDevice'); |
| 997 device.capabilities.printer.color = { | 970 device.capabilities.printer.color = { |
| 998 'option': [ | 971 'option': [ |
| 999 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'} | 972 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'} |
| 1000 ] | 973 ] |
| 1001 }; | 974 }; |
| 1002 setCapabilities(device); | 975 setCapabilities(device); |
| 1003 | 976 |
| 1004 checkSectionVisible($('color-settings'), false); | 977 checkSectionVisible($('color-settings'), false); |
| 1005 | 978 |
| 1006 return whenAnimationDone('more-settings'); | 979 return whenAnimationDone('more-settings'); |
| 1007 }); | 980 }); |
| 1008 }); | 981 }); |
| 1009 | 982 |
| 1010 // Test that the color settings, two options, both standard, defaults to | 983 // Test that the color settings, two options, both standard, defaults to |
| 1011 // color. | 984 // color. |
| 1012 test('ColorSettingsBothStandardDefaultColor', function() { | 985 test('ColorSettingsBothStandardDefaultColor', function() { |
| 1013 setInitialSettings(); | 986 return setupSettingsAndDestinations().then(function() { |
| 1014 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1015 setLocalDestinations(); | |
| 1016 | |
| 1017 var device = getCddTemplate('FooDevice'); | 987 var device = getCddTemplate('FooDevice'); |
| 1018 device.capabilities.printer.color = { | 988 device.capabilities.printer.color = { |
| 1019 'option': [ | 989 'option': [ |
| 1020 {'type': 'STANDARD_MONOCHROME'}, | 990 {'type': 'STANDARD_MONOCHROME'}, |
| 1021 {'is_default': true, 'type': 'STANDARD_COLOR'} | 991 {'is_default': true, 'type': 'STANDARD_COLOR'} |
| 1022 ] | 992 ] |
| 1023 }; | 993 }; |
| 1024 setCapabilities(device); | 994 setCapabilities(device); |
| 1025 | 995 |
| 1026 checkSectionVisible($('color-settings'), true); | 996 checkSectionVisible($('color-settings'), true); |
| 1027 expectEquals( | 997 expectEquals( |
| 1028 'color', | 998 'color', |
| 1029 $('color-settings').querySelector('.color-settings-select').value); | 999 $('color-settings').querySelector( |
| 1000 '.color-settings-select').value); |
| 1030 | 1001 |
| 1031 return whenAnimationDone('more-settings'); | 1002 return whenAnimationDone('more-settings'); |
| 1032 }); | 1003 }); |
| 1033 }); | 1004 }); |
| 1034 | 1005 |
| 1035 // Test that the color settings, two options, both standard, defaults to | 1006 // Test that the color settings, two options, both standard, defaults to |
| 1036 // monochrome. | 1007 // monochrome. |
| 1037 test('ColorSettingsBothStandardDefaultMonochrome', function() { | 1008 test('ColorSettingsBothStandardDefaultMonochrome', function() { |
| 1038 setInitialSettings(); | 1009 return setupSettingsAndDestinations().then(function() { |
| 1039 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1040 setLocalDestinations(); | |
| 1041 | |
| 1042 var device = getCddTemplate('FooDevice'); | 1010 var device = getCddTemplate('FooDevice'); |
| 1043 device.capabilities.printer.color = { | 1011 device.capabilities.printer.color = { |
| 1044 'option': [ | 1012 'option': [ |
| 1045 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}, | 1013 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}, |
| 1046 {'type': 'STANDARD_COLOR'} | 1014 {'type': 'STANDARD_COLOR'} |
| 1047 ] | 1015 ] |
| 1048 }; | 1016 }; |
| 1049 setCapabilities(device); | 1017 setCapabilities(device); |
| 1050 | 1018 |
| 1051 checkSectionVisible($('color-settings'), true); | 1019 checkSectionVisible($('color-settings'), true); |
| 1052 expectEquals( | 1020 expectEquals( |
| 1053 'bw', | 1021 'bw', |
| 1054 $('color-settings').querySelector('.color-settings-select').value); | 1022 $('color-settings').querySelector( |
| 1023 '.color-settings-select').value); |
| 1055 | 1024 |
| 1056 return whenAnimationDone('more-settings'); | 1025 return whenAnimationDone('more-settings'); |
| 1057 }); | 1026 }); |
| 1058 }); | 1027 }); |
| 1059 | 1028 |
| 1060 // Test that the color settings, two options, both custom, defaults to | 1029 // Test that the color settings, two options, both custom, defaults to |
| 1061 // color. | 1030 // color. |
| 1062 test('ColorSettingsBothCustomDefaultColor', function() { | 1031 test('ColorSettingsBothCustomDefaultColor', function() { |
| 1063 setInitialSettings(); | 1032 return setupSettingsAndDestinations().then(function() { |
| 1064 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1065 setLocalDestinations(); | |
| 1066 | |
| 1067 var device = getCddTemplate('FooDevice'); | 1033 var device = getCddTemplate('FooDevice'); |
| 1068 device.capabilities.printer.color = { | 1034 device.capabilities.printer.color = { |
| 1069 'option': [ | 1035 'option': [ |
| 1070 {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'}, | 1036 {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'}, |
| 1071 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'} | 1037 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'} |
| 1072 ] | 1038 ] |
| 1073 }; | 1039 }; |
| 1074 setCapabilities(device); | 1040 setCapabilities(device); |
| 1075 | 1041 |
| 1076 checkSectionVisible($('color-settings'), true); | 1042 checkSectionVisible($('color-settings'), true); |
| 1077 expectEquals( | 1043 expectEquals( |
| 1078 'color', | 1044 'color', |
| 1079 $('color-settings').querySelector( | 1045 $('color-settings').querySelector( |
| 1080 '.color-settings-select').value); | 1046 '.color-settings-select').value); |
| 1081 | 1047 |
| 1082 return whenAnimationDone('more-settings'); | 1048 return whenAnimationDone('more-settings'); |
| 1083 }); | 1049 }); |
| 1084 }); | 1050 }); |
| 1085 | 1051 |
| 1086 // Test to verify that duplex settings are set according to the printer | 1052 // Test to verify that duplex settings are set according to the printer |
| 1087 // capabilities. | 1053 // capabilities. |
| 1088 test('DuplexSettingsTrue', function() { | 1054 test('DuplexSettingsTrue', function() { |
| 1089 setInitialSettings(); | 1055 return setupSettingsAndDestinations().then(function() { |
| 1090 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1091 setLocalDestinations(); | |
| 1092 setCapabilities(getCddTemplate('FooDevice')); | 1056 setCapabilities(getCddTemplate('FooDevice')); |
| 1093 | 1057 |
| 1094 var otherOptions = $('other-options-settings'); | 1058 var otherOptions = $('other-options-settings'); |
| 1095 checkSectionVisible(otherOptions, true); | 1059 checkSectionVisible(otherOptions, true); |
| 1096 duplexContainer = otherOptions.querySelector('#duplex-container'); | 1060 duplexContainer = otherOptions.querySelector('#duplex-container'); |
| 1097 expectFalse(duplexContainer.hidden); | 1061 expectFalse(duplexContainer.hidden); |
| 1098 expectFalse(duplexContainer.querySelector('.checkbox').checked); | 1062 expectFalse(duplexContainer.querySelector('.checkbox').checked); |
| 1099 | 1063 |
| 1100 return whenAnimationDone('more-settings'); | 1064 return whenAnimationDone('more-settings'); |
| 1101 }); | 1065 }); |
| 1102 }); | 1066 }); |
| 1103 | 1067 |
| 1104 // Test to verify that duplex settings are set according to the printer | 1068 // Test to verify that duplex settings are set according to the printer |
| 1105 // capabilities. | 1069 // capabilities. |
| 1106 test('DuplexSettingsFalse', function() { | 1070 test('DuplexSettingsFalse', function() { |
| 1107 setInitialSettings(); | 1071 return setupSettingsAndDestinations().then(function() { |
| 1108 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1109 setLocalDestinations(); | |
| 1110 var device = getCddTemplate('FooDevice'); | 1072 var device = getCddTemplate('FooDevice'); |
| 1111 delete device.capabilities.printer.duplex; | 1073 delete device.capabilities.printer.duplex; |
| 1112 setCapabilities(device); | 1074 setCapabilities(device); |
| 1113 | 1075 |
| 1114 // Check that it is collapsed. | 1076 // Check that it is collapsed. |
| 1115 var otherOptions = $('other-options-settings'); | 1077 var otherOptions = $('other-options-settings'); |
| 1116 checkSectionVisible(otherOptions, false); | 1078 checkSectionVisible(otherOptions, false); |
| 1117 | 1079 |
| 1118 expandMoreSettings(); | 1080 expandMoreSettings(); |
| 1119 | 1081 |
| 1120 // Now it should be visible. | 1082 // Now it should be visible. |
| 1121 checkSectionVisible(otherOptions, true); | 1083 checkSectionVisible(otherOptions, true); |
| 1122 expectTrue(otherOptions.querySelector('#duplex-container').hidden); | 1084 expectTrue(otherOptions.querySelector('#duplex-container').hidden); |
| 1123 | 1085 |
| 1124 return whenAnimationDone('more-settings'); | 1086 return whenAnimationDone('more-settings'); |
| 1125 }); | 1087 }); |
| 1126 }); | 1088 }); |
| 1127 | 1089 |
| 1128 // Test that changing the selected printer updates the preview. | 1090 // Test that changing the selected printer updates the preview. |
| 1129 test('PrinterChangeUpdatesPreview', function() { | 1091 test('PrinterChangeUpdatesPreview', function() { |
| 1130 setInitialSettings(); | 1092 return setupSettingsAndDestinations().then(function() { |
| 1131 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1132 setLocalDestinations(); | |
| 1133 setCapabilities(getCddTemplate('FooDevice')); | 1093 setCapabilities(getCddTemplate('FooDevice')); |
| 1134 | 1094 |
| 1135 var previewGenerator = mock(print_preview.PreviewGenerator); | 1095 var previewGenerator = mock(print_preview.PreviewGenerator); |
| 1136 previewArea.previewGenerator_ = previewGenerator.proxy(); | 1096 previewArea.previewGenerator_ = previewGenerator.proxy(); |
| 1137 | 1097 |
| 1138 // The number of settings that can change due to a change in the | 1098 // The number of settings that can change due to a change in the |
| 1139 // destination that will therefore dispatch ticket item change events. | 1099 // destination that will therefore dispatch ticket item change events. |
| 1140 previewGenerator.expects(exactly(9)).requestPreview(); | 1100 previewGenerator.expects(exactly(9)).requestPreview(); |
| 1141 | 1101 |
| 1142 var barDestination = | 1102 var barDestination = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 | 1141 |
| 1182 var customMessageEl = | 1142 var customMessageEl = |
| 1183 previewAreaEl. | 1143 previewAreaEl. |
| 1184 getElementsByClassName('preview-area-custom-message')[0]; | 1144 getElementsByClassName('preview-area-custom-message')[0]; |
| 1185 expectFalse(customMessageEl.hidden); | 1145 expectFalse(customMessageEl.hidden); |
| 1186 }); | 1146 }); |
| 1187 }); | 1147 }); |
| 1188 | 1148 |
| 1189 // Test custom localized paper names. | 1149 // Test custom localized paper names. |
| 1190 test('CustomPaperNames', function() { | 1150 test('CustomPaperNames', function() { |
| 1191 setInitialSettings(); | 1151 return setupSettingsAndDestinations().then(function() { |
| 1192 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1193 setLocalDestinations(); | |
| 1194 | |
| 1195 var customLocalizedMediaName = 'Vendor defined localized media name'; | 1152 var customLocalizedMediaName = 'Vendor defined localized media name'; |
| 1196 var customMediaName = 'Vendor defined media name'; | 1153 var customMediaName = 'Vendor defined media name'; |
| 1197 | 1154 |
| 1198 var device = getCddTemplate('FooDevice'); | 1155 var device = getCddTemplate('FooDevice'); |
| 1199 device.capabilities.printer.media_size = { | 1156 device.capabilities.printer.media_size = { |
| 1200 option: [ | 1157 option: [ |
| 1201 { name: 'CUSTOM', | 1158 { name: 'CUSTOM', |
| 1202 width_microns: 15900, | 1159 width_microns: 15900, |
| 1203 height_microns: 79400, | 1160 height_microns: 79400, |
| 1204 is_default: true, | 1161 is_default: true, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1233 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); | 1190 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); |
| 1234 | 1191 |
| 1235 return whenAnimationDone('more-settings'); | 1192 return whenAnimationDone('more-settings'); |
| 1236 }); | 1193 }); |
| 1237 }); | 1194 }); |
| 1238 | 1195 |
| 1239 // Test advanced settings with 1 capability (should not display settings | 1196 // Test advanced settings with 1 capability (should not display settings |
| 1240 // search box). | 1197 // search box). |
| 1241 test('AdvancedSettings1Option', function() { | 1198 test('AdvancedSettings1Option', function() { |
| 1242 var device = getCddTemplateWithAdvancedSettings('FooDevice'); | 1199 var device = getCddTemplateWithAdvancedSettings('FooDevice'); |
| 1243 setInitialSettings(); | 1200 return setupSettingsAndDestinations().then(function() { |
| 1244 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 1201 startAdvancedSettingsTest(device); |
| 1245 setupAdvancedSettingsTest(device); | |
| 1246 | |
| 1247 // Open the advanced settings overlay. | |
| 1248 openAdvancedSettings(); | |
| 1249 | |
| 1250 // Check that advanced settings close button is now visible, | |
| 1251 // but not the search box (only 1 capability). | |
| 1252 var advancedSettingsCloseButton = $('advanced-settings'). | |
| 1253 querySelector('.close-button'); | |
| 1254 checkElementDisplayed(advancedSettingsCloseButton, true); | |
| 1255 checkElementDisplayed($('advanced-settings'). | 1202 checkElementDisplayed($('advanced-settings'). |
| 1256 querySelector('.search-box-area'), false); | 1203 querySelector('.search-box-area'), false); |
| 1257 | 1204 |
| 1258 return whenAnimationDone('more-settings'); | 1205 return whenAnimationDone('more-settings'); |
| 1259 }); | 1206 }); |
| 1260 }); | 1207 }); |
| 1261 | 1208 |
| 1262 | 1209 |
| 1263 // Test advanced settings with 2 capabilities (should have settings search | 1210 // Test advanced settings with 2 capabilities (should have settings search |
| 1264 // box). | 1211 // box). |
| 1265 test('AdvancedSettings2Options', function() { | 1212 test('AdvancedSettings2Options', function() { |
| 1266 var device = getCddTemplateWithAdvancedSettings('FooDevice'); | 1213 var device = getCddTemplateWithAdvancedSettings('FooDevice'); |
| 1267 // Add new capability. | 1214 // Add new capability. |
| 1268 device.capabilities.printer.vendor_capability.push({ | 1215 device.capabilities.printer.vendor_capability.push({ |
| 1269 display_name: 'Paper Type', | 1216 display_name: 'Paper Type', |
| 1270 id: 'Paper Type', | 1217 id: 'Paper Type', |
| 1271 type: 'SELECT', | 1218 type: 'SELECT', |
| 1272 select_cap: { | 1219 select_cap: { |
| 1273 option: [ | 1220 option: [ |
| 1274 {display_name: 'Standard', value: 0, is_default: true}, | 1221 {display_name: 'Standard', value: 0, is_default: true}, |
| 1275 {display_name: 'Recycled', value: 1}, | 1222 {display_name: 'Recycled', value: 1}, |
| 1276 {display_name: 'Special', value: 2} | 1223 {display_name: 'Special', value: 2} |
| 1277 ] | 1224 ] |
| 1278 } | 1225 } |
| 1279 }); | 1226 }); |
| 1280 setInitialSettings(); | 1227 return setupSettingsAndDestinations().then(function() { |
| 1281 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 1228 startAdvancedSettingsTest(device); |
| 1282 setupAdvancedSettingsTest(device); | |
| 1283 | 1229 |
| 1284 // Open the advanced settings overlay. | |
| 1285 openAdvancedSettings(); | |
| 1286 | |
| 1287 // Check advanced settings is visible and that the search box now | |
| 1288 // appears. | |
| 1289 var advancedSettingsCloseButton = $('advanced-settings'). | |
| 1290 querySelector('.close-button'); | |
| 1291 checkElementDisplayed(advancedSettingsCloseButton, true); | |
| 1292 checkElementDisplayed($('advanced-settings'). | 1230 checkElementDisplayed($('advanced-settings'). |
| 1293 querySelector('.search-box-area'), true); | 1231 querySelector('.search-box-area'), true); |
| 1294 | 1232 |
| 1295 return whenAnimationDone('more-settings'); | 1233 return whenAnimationDone('more-settings'); |
| 1296 }); | 1234 }); |
| 1297 }); | 1235 }); |
| 1298 | 1236 |
| 1299 // Test that initialization with saved destination only issues one call | 1237 // Test that initialization with saved destination only issues one call |
| 1300 // to startPreview. | 1238 // to startPreview. |
| 1301 test('InitIssuesOneRequest', function() { | 1239 test('InitIssuesOneRequest', function() { |
| 1302 // Load in a bunch of recent destinations with non null capabilities. | 1240 // Load in a bunch of recent destinations with non null capabilities. |
| 1303 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; | 1241 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1329 setInitialSettings(); | 1267 setInitialSettings(); |
| 1330 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 1268 return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| 1331 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_); | 1269 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_); |
| 1332 }); | 1270 }); |
| 1333 }); | 1271 }); |
| 1334 | 1272 |
| 1335 // Test that invalid settings errors disable the print preview and display | 1273 // Test that invalid settings errors disable the print preview and display |
| 1336 // an error and that the preview dialog can be recovered by selecting a | 1274 // an error and that the preview dialog can be recovered by selecting a |
| 1337 // new destination. | 1275 // new destination. |
| 1338 test('InvalidSettingsError', function() { | 1276 test('InvalidSettingsError', function() { |
| 1339 // Setup | 1277 return setupSettingsAndDestinations().then(function() { |
| 1340 setInitialSettings(); | |
| 1341 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1342 setLocalDestinations(); | |
| 1343 setCapabilities(getCddTemplate('FooDevice')); | 1278 setCapabilities(getCddTemplate('FooDevice')); |
| 1344 | 1279 |
| 1345 // Manually enable the print header. This is needed since there is no | 1280 // Manually enable the print header. This is needed since there is no |
| 1346 // plugin during test, so it will be set as disabled normally. | 1281 // plugin during test, so it will be set as disabled normally. |
| 1347 printPreview.printHeader_.isEnabled = true; | 1282 printPreview.printHeader_.isEnabled = true; |
| 1348 | 1283 |
| 1349 // There will be an error message in the preview area since the plugin | 1284 // There will be an error message in the preview area since the plugin |
| 1350 // is not running. However, it should not be the invalid settings error. | 1285 // is not running. However, it should not be the invalid settings |
| 1286 // error. |
| 1351 var previewAreaEl = $('preview-area'); | 1287 var previewAreaEl = $('preview-area'); |
| 1352 var customMessageEl = | 1288 var customMessageEl = |
| 1353 previewAreaEl. | 1289 previewAreaEl. |
| 1354 getElementsByClassName('preview-area-custom-message')[0]; | 1290 getElementsByClassName('preview-area-custom-message')[0]; |
| 1355 expectFalse(customMessageEl.hidden); | 1291 expectFalse(customMessageEl.hidden); |
| 1356 var expectedMessageStart = 'The selected printer is not available or ' | 1292 var expectedMessageStart = 'The selected printer is not available or ' |
| 1357 + 'not installed correctly.' | 1293 + 'not installed correctly.' |
| 1358 expectFalse(customMessageEl.textContent.includes(expectedMessageStart)); | 1294 expectFalse(customMessageEl.textContent.includes( |
| 1295 expectedMessageStart)); |
| 1359 | 1296 |
| 1360 // Verify that the print button is enabled. | 1297 // Verify that the print button is enabled. |
| 1361 var printHeader = $('print-header'); | 1298 var printHeader = $('print-header'); |
| 1362 var printButton = printHeader.querySelector('button.print'); | 1299 var printButton = printHeader.querySelector('button.print'); |
| 1363 checkElementDisplayed(printButton, true); | 1300 checkElementDisplayed(printButton, true); |
| 1364 expectFalse(printButton.disabled); | 1301 expectFalse(printButton.disabled); |
| 1365 | 1302 |
| 1366 // Report invalid settings error. | 1303 // Report invalid settings error. |
| 1367 var invalidSettingsEvent = | 1304 var invalidSettingsEvent = |
| 1368 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); | 1305 new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); |
| 1369 nativeLayer.getEventTarget().dispatchEvent(invalidSettingsEvent); | 1306 nativeLayer.getEventTarget().dispatchEvent(invalidSettingsEvent); |
| 1370 | 1307 |
| 1371 // Should be in an error state, print button disabled, invalid custom | 1308 // Should be in an error state, print button disabled, invalid custom |
| 1372 // error message shown. | 1309 // error message shown. |
| 1373 expectFalse(customMessageEl.hidden); | 1310 expectFalse(customMessageEl.hidden); |
| 1374 expectTrue(customMessageEl.textContent.includes(expectedMessageStart)); | 1311 expectTrue(customMessageEl.textContent.includes( |
| 1312 expectedMessageStart)); |
| 1375 expectTrue(printButton.disabled); | 1313 expectTrue(printButton.disabled); |
| 1376 | 1314 |
| 1377 // Select a new destination | 1315 // Select a new destination |
| 1378 var barDestination = | 1316 var barDestination = |
| 1379 printPreview.destinationStore_.destinations().find( | 1317 printPreview.destinationStore_.destinations().find( |
| 1380 function(d) { | 1318 function(d) { |
| 1381 return d.id == 'BarDevice'; | 1319 return d.id == 'BarDevice'; |
| 1382 }); | 1320 }); |
| 1383 | 1321 |
| 1384 printPreview.destinationStore_.selectDestination(barDestination); | 1322 printPreview.destinationStore_.selectDestination(barDestination); |
| 1385 | 1323 |
| 1386 // Dispatch events indicating capabilities were fetched and new preview | 1324 // Dispatch events indicating capabilities were fetched and new |
| 1387 // has loaded. | 1325 // preview has loaded. |
| 1388 setCapabilities(getCddTemplate('BarDevice')); | 1326 setCapabilities(getCddTemplate('BarDevice')); |
| 1389 var previewDoneEvent = new Event( | 1327 var previewDoneEvent = new Event( |
| 1390 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); | 1328 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
| 1391 previewArea.dispatchEvent(previewDoneEvent); | 1329 previewArea.dispatchEvent(previewDoneEvent); |
| 1392 | 1330 |
| 1393 // Has active print button and successfully 'prints', indicating | 1331 // Has active print button and successfully 'prints', indicating |
| 1394 // recovery from error state. | 1332 // recovery from error state. |
| 1395 expectFalse(printButton.disabled); | 1333 expectFalse(printButton.disabled); |
| 1396 expectFalse(nativeLayer.isPrintStarted()); | 1334 expectFalse(nativeLayer.isPrintStarted()); |
| 1397 printButton.click(); | 1335 printButton.click(); |
| 1398 expectTrue(nativeLayer.isPrintStarted()); | 1336 expectTrue(nativeLayer.isPrintStarted()); |
| 1399 }); | 1337 }); |
| 1400 }); | 1338 }); |
| 1401 | 1339 |
| 1402 // Test the preview generator to make sure the generate draft parameter is | 1340 // Test the preview generator to make sure the generate draft parameter is |
| 1403 // set correctly. It should be false if the only change is the page range. | 1341 // set correctly. It should be false if the only change is the page range. |
| 1404 test('GenerateDraft', function() { | 1342 test('GenerateDraft', function() { |
| 1405 // Use a real preview generator. | 1343 // Use a real preview generator. |
| 1406 previewArea.previewGenerator_ = | 1344 previewArea.previewGenerator_ = |
| 1407 new print_preview.PreviewGenerator(printPreview.destinationStore_, | 1345 new print_preview.PreviewGenerator(printPreview.destinationStore_, |
| 1408 printPreview.printTicketStore_, nativeLayer, | 1346 printPreview.printTicketStore_, nativeLayer, |
| 1409 printPreview.documentInfo_); | 1347 printPreview.documentInfo_); |
| 1410 | 1348 return setupSettingsAndDestinations().then(function() { |
| 1411 setInitialSettings(); | |
| 1412 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 1413 setLocalDestinations(); | |
| 1414 setCapabilities(getCddTemplate('FooDevice')); | 1349 setCapabilities(getCddTemplate('FooDevice')); |
| 1415 | 1350 |
| 1416 // The first request should generate draft because there was no | 1351 // The first request should generate draft because there was no |
| 1417 // previous print preview draft. | 1352 // previous print preview draft. |
| 1418 expectTrue(nativeLayer.generateDraft()); | 1353 expectTrue(nativeLayer.generateDraft()); |
| 1419 | 1354 |
| 1420 // Change the page range - no new draft needed. | 1355 // Change the page range - no new draft needed. |
| 1421 printPreview.printTicketStore_.pageRange.updateValue('2'); | 1356 printPreview.printTicketStore_.pageRange.updateValue('2'); |
| 1422 expectFalse(nativeLayer.generateDraft()); | 1357 expectFalse(nativeLayer.generateDraft()); |
| 1423 | 1358 |
| 1424 // Change the margin type - need to regenerate again. | 1359 // Change the margin type - need to regenerate again. |
| 1425 printPreview.printTicketStore_.marginsType.updateValue( | 1360 printPreview.printTicketStore_.marginsType.updateValue( |
| 1426 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); | 1361 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); |
| 1427 expectTrue(nativeLayer.generateDraft()); | 1362 expectTrue(nativeLayer.generateDraft()); |
| 1428 }); | 1363 }); |
| 1429 }); | 1364 }); |
| 1430 }); | 1365 }); |
| 1431 }); | 1366 }); |
| OLD | NEW |