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