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 22 matching lines...) Expand all Loading... | |
| 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|. | 35 * |initialSettings|. |
| 36 */ | 36 */ |
| 37 function setInitialSettings() { | 37 function setInitialSettings() { |
| 38 nativeLayer.setInitialSettings(initialSettings); | 38 nativeLayer.setInitialSettings(initialSettings); |
| 39 printPreview.initialize(); | 39 printPreview.initialize(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Start loading the local destinations using the destination infos currently | 43 * Sets settings and destinations and local destination that is the system |
| 44 * stored in |localDestinationInfos|. | 44 * default. |
| 45 * @param {?print_preview.PrinterCapabilitiesResponse} Response parameters | |
|
dpapad
2017/06/14 17:19:36
@param {Type} paramName Description
Parameter nam
rbpotter
2017/06/14 18:28:25
Done.
| |
| 46 * to use when the system default printer is loaded. If not defined, | |
| 47 * a default will be used. | |
| 48 * @return {!Promise<print_preview.PrinterCapabilitiesResponse>} a | |
| 49 * promise that will resolve when getPrinterCapabilities has been | |
| 50 * called for the device (either default or provided). | |
| 45 */ | 51 */ |
| 46 function setLocalDestinations() { | 52 function setupSettingsAndDestinationsWithCapabilities(device) { |
| 53 nativeLayer.setInitialSettings(initialSettings); | |
| 47 nativeLayer.setLocalDestinations(localDestinationInfos); | 54 nativeLayer.setLocalDestinations(localDestinationInfos); |
| 48 printPreview.destinationStore_.startLoadLocalDestinations(); | 55 device = device || getCddTemplate('FooDevice', 'FooName'); |
| 49 } | 56 nativeLayer.setLocalDestinationCapabilities(device); |
| 50 | 57 |
| 51 /** | 58 printPreview.initialize(); |
| 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() { | 59 return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| 63 setLocalDestinations(); | 60 printPreview.destinationStore_.startLoadLocalDestinations(); |
| 64 return nativeLayer.whenCalled('getPrinters'); | 61 return nativeLayer.whenCalled('getPrinters'); |
|
dpapad
2017/06/14 17:19:36
Nit:
return Promise.all([
nativeLayer.whenCalle
rbpotter
2017/06/14 18:28:25
Done.
| |
| 62 }).then(function() { | |
| 63 return nativeLayer.whenCalled('getPrinterCapabilities'); | |
| 65 }); | 64 }); |
| 66 } | 65 } |
| 67 | 66 |
| 68 /** | 67 /** |
| 69 * Dispatch the CAPABILITIES_SET event. This call is NOT async and will | |
| 70 * happen in the same thread. | |
| 71 * @param {!Object} device The device whose capabilities should be dispatched. | |
| 72 */ | |
| 73 function setCapabilities(device) { | |
| 74 var capsSetEvent = | |
| 75 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 76 capsSetEvent.settingsInfo = device; | |
| 77 nativeLayer.getEventTarget().dispatchEvent(capsSetEvent); | |
| 78 } | |
| 79 | |
| 80 /** | |
| 81 * Verify that |section| visibility matches |visible|. | 68 * Verify that |section| visibility matches |visible|. |
| 82 * @param {HTMLDivElement} section The section to check. | 69 * @param {HTMLDivElement} section The section to check. |
| 83 * @param {boolean} visible The expected state of visibility. | 70 * @param {boolean} visible The expected state of visibility. |
| 84 */ | 71 */ |
| 85 function checkSectionVisible(section, visible) { | 72 function checkSectionVisible(section, visible) { |
| 86 assertNotEquals(null, section); | 73 assertNotEquals(null, section); |
| 87 expectEquals( | 74 expectEquals( |
| 88 visible, | 75 visible, |
| 89 section.classList.contains('visible'), 'section=' + section.id); | 76 section.classList.contains('visible'), 'section=' + section.id); |
| 90 } | 77 } |
| 91 | 78 |
| 92 /** | 79 /** |
| 93 * @param {?HTMLElement} el | 80 * @param {?HTMLElement} el |
| 94 * @param {boolean} isDisplayed | 81 * @param {boolean} isDisplayed |
| 95 */ | 82 */ |
| 96 function checkElementDisplayed(el, isDisplayed) { | 83 function checkElementDisplayed(el, isDisplayed) { |
| 97 assertNotEquals(null, el); | 84 assertNotEquals(null, el); |
| 98 expectEquals(isDisplayed, | 85 expectEquals(isDisplayed, |
| 99 !el.hidden, | 86 !el.hidden, |
| 100 'element="' + el.id + '" of class "' + el.classList + '"'); | 87 'element="' + el.id + '" of class "' + el.classList + '"'); |
| 101 } | 88 } |
| 102 | 89 |
| 103 /** | 90 /** |
| 104 * @param {string} printerId | 91 * @param {string} printerId |
| 105 * @return {!Object} | 92 * @param {string | undefined} printerName Defaults to an empty string. |
|
dpapad
2017/06/14 17:19:36
Same here. Optional params are usually defined as
rbpotter
2017/06/14 18:28:25
Done.
| |
| 93 * @return {!print_preview.PrinterCapabilitiesResponse} | |
| 106 */ | 94 */ |
| 107 function getCddTemplate(printerId) { | 95 function getCddTemplate(printerId, printerName) { |
| 108 return { | 96 return { |
| 109 printerId: printerId, | 97 printerId: printerId, |
| 98 printerName: printerName || '', | |
| 110 capabilities: { | 99 capabilities: { |
| 111 version: '1.0', | 100 version: '1.0', |
| 112 printer: { | 101 printer: { |
| 113 supported_content_type: [{content_type: 'application/pdf'}], | 102 supported_content_type: [{content_type: 'application/pdf'}], |
| 114 collate: {}, | 103 collate: {}, |
| 115 color: { | 104 color: { |
| 116 option: [ | 105 option: [ |
| 117 {type: 'STANDARD_COLOR', is_default: true}, | 106 {type: 'STANDARD_COLOR', is_default: true}, |
| 118 {type: 'STANDARD_MONOCHROME'} | 107 {type: 'STANDARD_MONOCHROME'} |
| 119 ] | 108 ] |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 advancedOptionsSettingsButton.click(); | 197 advancedOptionsSettingsButton.click(); |
| 209 } | 198 } |
| 210 | 199 |
| 211 /** | 200 /** |
| 212 * Repeated setup steps for the advanced settings tests. | 201 * Repeated setup steps for the advanced settings tests. |
| 213 * Sets capabilities, and verifies advanced options section is visible | 202 * Sets capabilities, and verifies advanced options section is visible |
| 214 * after expanding more settings. Then opens the advanced settings overlay | 203 * after expanding more settings. Then opens the advanced settings overlay |
| 215 * and verifies it is displayed. | 204 * and verifies it is displayed. |
| 216 */ | 205 */ |
| 217 function startAdvancedSettingsTest(device) { | 206 function startAdvancedSettingsTest(device) { |
| 218 setCapabilities(device); | |
| 219 expandMoreSettings(); | 207 expandMoreSettings(); |
| 220 | 208 |
| 221 // Check that the advanced options settings section is visible. | 209 // Check that the advanced options settings section is visible. |
| 222 checkSectionVisible($('advanced-options-settings'), true); | 210 checkSectionVisible($('advanced-options-settings'), true); |
| 223 | 211 |
| 224 // Open the advanced settings overlay. | 212 // Open the advanced settings overlay. |
| 225 openAdvancedSettings(); | 213 openAdvancedSettings(); |
| 226 | 214 |
| 227 // Check advanced settings overlay is visible by checking that the close | 215 // Check advanced settings overlay is visible by checking that the close |
| 228 // button is displayed. | 216 // button is displayed. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 ]; | 266 ]; |
| 279 | 267 |
| 280 nativeLayer = new print_preview.NativeLayerStub(); | 268 nativeLayer = new print_preview.NativeLayerStub(); |
| 281 print_preview.NativeLayer.setInstance(nativeLayer); | 269 print_preview.NativeLayer.setInstance(nativeLayer); |
| 282 printPreview = new print_preview.PrintPreview(); | 270 printPreview = new print_preview.PrintPreview(); |
| 283 previewArea = printPreview.getPreviewArea(); | 271 previewArea = printPreview.getPreviewArea(); |
| 284 }); | 272 }); |
| 285 | 273 |
| 286 // Test some basic assumptions about the print preview WebUI. | 274 // Test some basic assumptions about the print preview WebUI. |
| 287 test('PrinterList', function() { | 275 test('PrinterList', function() { |
| 288 return setupSettingsAndDestinations().then(function() { | 276 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 289 var recentList = | 277 var recentList = |
| 290 $('destination-search').querySelector('.recent-list ul'); | 278 $('destination-search').querySelector('.recent-list ul'); |
| 291 var localList = | 279 var localList = |
| 292 $('destination-search').querySelector('.local-list ul'); | 280 $('destination-search').querySelector('.local-list ul'); |
| 293 assertNotEquals(null, recentList); | 281 assertNotEquals(null, recentList); |
| 294 assertEquals(1, recentList.childNodes.length); | 282 assertEquals(1, recentList.childNodes.length); |
| 295 assertEquals('FooName', | 283 assertEquals('FooName', |
| 296 recentList.childNodes.item(0).querySelector( | 284 recentList.childNodes.item(0).querySelector( |
| 297 '.destination-list-item-name').textContent); | 285 '.destination-list-item-name').textContent); |
| 298 assertNotEquals(null, localList); | 286 assertNotEquals(null, localList); |
| 299 assertEquals(3, localList.childNodes.length); | 287 assertEquals(3, localList.childNodes.length); |
| 300 assertEquals( | 288 assertEquals( |
| 301 'Save as PDF', | 289 'Save as PDF', |
| 302 localList.childNodes.item(PDF_INDEX). | 290 localList.childNodes.item(PDF_INDEX). |
| 303 querySelector('.destination-list-item-name').textContent); | 291 querySelector('.destination-list-item-name').textContent); |
| 304 assertEquals( | 292 assertEquals( |
| 305 'FooName', | 293 'FooName', |
| 306 localList.childNodes.item(FOO_INDEX). | 294 localList.childNodes.item(FOO_INDEX). |
| 307 querySelector('.destination-list-item-name').textContent); | 295 querySelector('.destination-list-item-name').textContent); |
| 308 assertEquals( | 296 assertEquals( |
| 309 'BarName', | 297 'BarName', |
| 310 localList.childNodes.item(BAR_INDEX). | 298 localList.childNodes.item(BAR_INDEX). |
| 311 querySelector('.destination-list-item-name').textContent); | 299 querySelector('.destination-list-item-name').textContent); |
| 312 }); | 300 }); |
| 313 }); | 301 }); |
| 314 | 302 |
| 315 // Test that the printer list is structured correctly after calling | 303 // Test that the printer list is structured correctly after calling |
| 316 // addCloudPrinters with an empty list. | 304 // addCloudPrinters with an empty list. |
| 317 test('PrinterListCloudEmpty', function() { | 305 test('PrinterListCloudEmpty', function() { |
| 318 return setupSettingsAndDestinations().then(function() { | 306 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 319 var cloudPrintEnableEvent = new Event( | 307 var cloudPrintEnableEvent = new Event( |
| 320 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); | 308 print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
| 321 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; | 309 cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; |
| 322 nativeLayer.getEventTarget().dispatchEvent( | 310 nativeLayer.getEventTarget().dispatchEvent( |
| 323 cloudPrintEnableEvent); | 311 cloudPrintEnableEvent); |
| 324 | 312 |
| 325 var searchDoneEvent = | 313 var searchDoneEvent = |
| 326 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); | 314 new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); |
| 327 searchDoneEvent.printers = []; | 315 searchDoneEvent.printers = []; |
| 328 searchDoneEvent.isRecent = true; | 316 searchDoneEvent.isRecent = true; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 id: 'ID', | 362 id: 'ID', |
| 375 origin: cr.isChromeOS ? 'chrome_os' : 'local', | 363 origin: cr.isChromeOS ? 'chrome_os' : 'local', |
| 376 account: '', | 364 account: '', |
| 377 capabilities: 0, | 365 capabilities: 0, |
| 378 name: '', | 366 name: '', |
| 379 extensionId: '', | 367 extensionId: '', |
| 380 extensionName: '', | 368 extensionName: '', |
| 381 }, | 369 }, |
| 382 ], | 370 ], |
| 383 }); | 371 }); |
| 384 | 372 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID')); |
| 385 setInitialSettings(); | 373 setInitialSettings(); |
| 386 return nativeLayer.whenCalled('getInitialSettings'); | 374 return nativeLayer.whenCalled('getInitialSettings'); |
| 387 }); | 375 }); |
| 388 | 376 |
| 389 test('RestoreMultipleDestinations', function() { | 377 test('RestoreMultipleDestinations', function() { |
| 390 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; | 378 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; |
| 391 | 379 |
| 392 initialSettings.serializedAppStateStr_ = JSON.stringify({ | 380 initialSettings.serializedAppStateStr_ = JSON.stringify({ |
| 393 version: 2, | 381 version: 2, |
| 394 recentDestinations: [ | 382 recentDestinations: [ |
| 395 { | 383 { |
| 396 id: 'ID1', | 384 id: 'ID1', |
| 397 origin: origin, | 385 origin: origin, |
| 398 account: '', | 386 account: '', |
| 399 capabilities: 0, | 387 capabilities: 0, |
| 400 name: '', | 388 name: 'One', |
| 401 extensionId: '', | 389 extensionId: '', |
| 402 extensionName: '', | 390 extensionName: '', |
| 403 }, { | 391 }, { |
| 404 id: 'ID2', | 392 id: 'ID2', |
| 405 origin: origin, | 393 origin: origin, |
| 406 account: '', | 394 account: '', |
| 407 capabilities: 0, | 395 capabilities: 0, |
| 408 name: '', | 396 name: 'Two', |
| 409 extensionId: '', | 397 extensionId: '', |
| 410 extensionName: '', | 398 extensionName: '', |
| 411 }, { | 399 }, { |
| 412 id: 'ID3', | 400 id: 'ID3', |
| 413 origin: origin, | 401 origin: origin, |
| 414 account: '', | 402 account: '', |
| 415 capabilities: 0, | 403 capabilities: 0, |
| 416 name: '', | 404 name: 'Three', |
| 417 extensionId: '', | 405 extensionId: '', |
| 418 extensionName: '', | 406 extensionName: '', |
| 419 }, | 407 }, |
| 420 ], | 408 ], |
| 421 }); | 409 }); |
| 410 // Set all three of these destinations in the local destination infos | |
| 411 // (represents currently available printers), plus an extra destination. | |
| 412 localDestinationInfos = [ | |
| 413 { printerName: 'One', deviceName: 'ID1' }, | |
| 414 { printerName: 'Two', deviceName: 'ID2' }, | |
| 415 { printerName: 'Three', deviceName: 'ID3' }, | |
| 416 { printerName: 'Four', deviceName: 'ID4' } | |
| 417 ]; | |
| 422 | 418 |
| 423 setInitialSettings(); | 419 // Set up capabilities for ID1. This should be the device that should hav |
| 420 // its capabilities fetched, since it is the most recent. If another | |
| 421 // device is selected the native layer will reject the callback. | |
| 422 var device = getCddTemplate('ID1', 'One'); | |
| 424 | 423 |
| 425 return nativeLayer.whenCalled('getInitialSettings').then( | 424 return setupSettingsAndDestinationsWithCapabilities(device).then( |
| 426 function() { | 425 function() { |
| 427 // Set capabilities for the three recently used destinations + 1 | |
| 428 // more. | |
| 429 setCapabilities(getCddTemplate('ID1')); | |
| 430 setCapabilities(getCddTemplate('ID2')); | |
| 431 setCapabilities(getCddTemplate('ID3')); | |
| 432 setCapabilities(getCddTemplate('ID4')); | |
| 433 | |
| 434 // The most recently used destination should be the currently | 426 // The most recently used destination should be the currently |
| 435 // selected one. This is ID1. | 427 // selected one. This is ID1. |
| 436 assertEquals( | 428 assertEquals( |
| 437 'ID1', printPreview.destinationStore_.selectedDestination.id); | 429 'ID1', printPreview.destinationStore_.selectedDestination.id); |
| 438 | 430 |
| 439 // Look through the destinations. ID1, ID2, and ID3 should all be | 431 // Look through the destinations. ID1, ID2, and ID3 should all be |
| 440 // recent. | 432 // recent. |
| 441 var destinations = printPreview.destinationStore_.destinations_; | 433 var destinations = printPreview.destinationStore_.destinations_; |
| 442 var idsFound = []; | 434 var idsFound = []; |
| 443 | 435 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 454 assertNotEquals(-1, idsFound.indexOf('ID1')); | 446 assertNotEquals(-1, idsFound.indexOf('ID1')); |
| 455 assertNotEquals(-1, idsFound.indexOf('ID2')); | 447 assertNotEquals(-1, idsFound.indexOf('ID2')); |
| 456 assertNotEquals(-1, idsFound.indexOf('ID3')); | 448 assertNotEquals(-1, idsFound.indexOf('ID3')); |
| 457 }); | 449 }); |
| 458 }); | 450 }); |
| 459 | 451 |
| 460 test('DefaultDestinationSelectionRules', function() { | 452 test('DefaultDestinationSelectionRules', function() { |
| 461 // It also makes sure these rules do override system default destination. | 453 // It also makes sure these rules do override system default destination. |
| 462 initialSettings.serializedDefaultDestinationSelectionRulesStr_ = | 454 initialSettings.serializedDefaultDestinationSelectionRulesStr_ = |
| 463 JSON.stringify({namePattern: '.*Bar.*'}); | 455 JSON.stringify({namePattern: '.*Bar.*'}); |
| 464 // Set this early as the app state selection string will trigger a load | 456 return setupSettingsAndDestinationsWithCapabilities( |
| 465 // of local destinations on initialization. | 457 getCddTemplate('BarDevice', 'BarName')).then(function() { |
| 466 nativeLayer.setLocalDestinations(localDestinationInfos); | 458 assertEquals('BarDevice', |
| 467 setInitialSettings(); | 459 printPreview.destinationStore_.selectedDestination.id); |
| 468 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 460 }); |
| 469 return nativeLayer.whenCalled('getPrinters').then(function() { | |
| 470 assertEquals('BarDevice', | |
| 471 printPreview.destinationStore_.selectedDestination.id); | |
| 472 }); | |
| 473 }); | |
| 474 }); | 461 }); |
| 475 | 462 |
| 476 test('SystemDialogLinkIsHiddenInAppKioskMode', function() { | 463 test('SystemDialogLinkIsHiddenInAppKioskMode', function() { |
| 477 if (!cr.isChromeOS) | 464 if (!cr.isChromeOS) |
| 478 initialSettings.isInAppKioskMode_ = true; | 465 initialSettings.isInAppKioskMode_ = true; |
| 479 | 466 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice')); |
| 480 setInitialSettings(); | 467 setInitialSettings(); |
| 481 return nativeLayer.whenCalled('getInitialSettings').then( | 468 return nativeLayer.whenCalled('getInitialSettings').then( |
| 482 function() { | 469 function() { |
| 483 if (cr.isChromeOS) | 470 if (cr.isChromeOS) |
| 484 assertEquals(null, $('system-dialog-link')); | 471 assertEquals(null, $('system-dialog-link')); |
| 485 else | 472 else |
| 486 checkElementDisplayed($('system-dialog-link'), false); | 473 checkElementDisplayed($('system-dialog-link'), false); |
| 487 }); | 474 }); |
| 488 }); | 475 }); |
| 489 | 476 |
| 490 test('SectionsDisabled', function() { | 477 test('SectionsDisabled', function() { |
| 491 checkSectionVisible($('layout-settings'), false); | 478 checkSectionVisible($('layout-settings'), false); |
| 492 checkSectionVisible($('color-settings'), false); | 479 checkSectionVisible($('color-settings'), false); |
| 493 checkSectionVisible($('copies-settings'), false); | 480 checkSectionVisible($('copies-settings'), false); |
| 481 var device = getCddTemplate('FooDevice'); | |
| 482 device.capabilities.printer.color = { | |
| 483 option: [{is_default: true, type: 'STANDARD_COLOR'}] | |
| 484 }; | |
| 485 delete device.capabilities.printer.copies; | |
| 494 | 486 |
| 495 return setupSettingsAndDestinations().then(function() { | 487 return setupSettingsAndDestinationsWithCapabilities(device) |
| 496 var device = getCddTemplate('FooDevice'); | 488 .then(function() { |
| 497 device.capabilities.printer.color = { | 489 checkSectionVisible($('layout-settings'), true); |
| 498 option: [{is_default: true, type: 'STANDARD_COLOR'}] | 490 checkSectionVisible($('color-settings'), false); |
| 499 }; | 491 checkSectionVisible($('copies-settings'), false); |
| 500 delete device.capabilities.printer.copies; | |
| 501 setCapabilities(device); | |
| 502 | 492 |
| 503 checkSectionVisible($('layout-settings'), true); | 493 return whenAnimationDone('other-options-collapsible'); |
| 504 checkSectionVisible($('color-settings'), false); | 494 }); |
| 505 checkSectionVisible($('copies-settings'), false); | |
| 506 | |
| 507 return whenAnimationDone('other-options-collapsible'); | |
| 508 }); | |
| 509 }); | 495 }); |
| 510 | 496 |
| 511 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide | 497 // When the source is 'PDF' and 'Save as PDF' option is selected, we hide |
| 512 // the fit to page option. | 498 // the fit to page option. |
| 513 test('PrintToPDFSelectedCapabilities', function() { | 499 test('PrintToPDFSelectedCapabilities', function() { |
| 514 // Add PDF printer. | 500 // Setup initial settings |
| 515 initialSettings.isDocumentModifiable_ = false; | 501 initialSettings.isDocumentModifiable_ = false; |
| 516 initialSettings.systemDefaultDestinationId_ = 'Save as PDF'; | 502 initialSettings.systemDefaultDestinationId_ = 'Save as PDF'; |
| 517 setInitialSettings(); | |
| 518 | 503 |
| 519 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 504 // Set PDF printer |
| 520 var device = { | 505 var device = { |
| 521 printerId: 'Save as PDF', | 506 printerId: 'Save as PDF', |
| 522 capabilities: { | 507 capabilities: { |
| 523 version: '1.0', | 508 version: '1.0', |
| 524 printer: { | 509 printer: { |
| 525 page_orientation: { | 510 page_orientation: { |
| 526 option: [ | 511 option: [ |
| 527 {type: 'AUTO', is_default: true}, | 512 {type: 'AUTO', is_default: true}, |
| 528 {type: 'PORTRAIT'}, | 513 {type: 'PORTRAIT'}, |
| 529 {type: 'LANDSCAPE'} | 514 {type: 'LANDSCAPE'} |
| 530 ] | 515 ] |
| 531 }, | 516 }, |
| 532 color: { | 517 color: { |
| 533 option: [ | 518 option: [ |
| 534 {type: 'STANDARD_COLOR', is_default: true} | 519 {type: 'STANDARD_COLOR', is_default: true} |
| 535 ] | 520 ] |
| 536 }, | 521 }, |
| 537 media_size: { | 522 media_size: { |
| 538 option: [ | 523 option: [ |
| 539 { name: 'NA_LETTER', | 524 { name: 'NA_LETTER', |
| 540 width_microns: 0, | 525 width_microns: 0, |
| 541 height_microns: 0, | 526 height_microns: 0, |
| 542 is_default: true | 527 is_default: true |
| 543 } | 528 } |
| 544 ] | 529 ] |
| 545 } | |
| 546 } | 530 } |
| 547 } | 531 } |
| 548 }; | 532 } |
| 549 setCapabilities(device); | 533 }; |
| 534 nativeLayer.setLocalDestinationCapabilities(device); | |
| 535 | |
| 536 setInitialSettings(); | |
| 537 return nativeLayer.whenCalled('getInitialSettings').then(function() { | |
| 538 return nativeLayer.whenCalled('getPrinterCapabilities'); | |
| 539 }).then(function() { | |
| 550 var otherOptions = $('other-options-settings'); | 540 var otherOptions = $('other-options-settings'); |
| 551 // If rasterization is an option, other options should be visible. | 541 // If rasterization is an option, other options should be visible. |
| 552 // If not, there should be no available other options. | 542 // If not, there should be no available other options. |
| 553 checkSectionVisible(otherOptions, isPrintAsImageEnabled()); | 543 checkSectionVisible(otherOptions, isPrintAsImageEnabled()); |
| 554 if (isPrintAsImageEnabled()) { | 544 if (isPrintAsImageEnabled()) { |
| 555 checkElementDisplayed( | 545 checkElementDisplayed( |
| 556 otherOptions.querySelector('#fit-to-page-container'), false); | 546 otherOptions.querySelector('#fit-to-page-container'), false); |
| 557 checkElementDisplayed( | 547 checkElementDisplayed( |
| 558 otherOptions.querySelector('#rasterize-container'), true); | 548 otherOptions.querySelector('#rasterize-container'), true); |
| 559 } | 549 } |
| 560 checkSectionVisible($('media-size-settings'), false); | 550 checkSectionVisible($('media-size-settings'), false); |
| 561 checkSectionVisible($('scaling-settings'), false); | 551 checkSectionVisible($('scaling-settings'), false); |
| 562 }); | 552 }); |
| 563 }); | 553 }); |
| 564 | 554 |
| 565 // When the source is 'HTML', we always hide the fit to page option and show | 555 // When the source is 'HTML', we always hide the fit to page option and show |
| 566 // media size option. | 556 // media size option. |
| 567 test('SourceIsHTMLCapabilities', function() { | 557 test('SourceIsHTMLCapabilities', function() { |
| 568 return setupSettingsAndDestinations().then(function() { | 558 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 569 setCapabilities(getCddTemplate('FooDevice')); | |
| 570 | |
| 571 var otherOptions = $('other-options-settings'); | 559 var otherOptions = $('other-options-settings'); |
| 572 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); | 560 var fitToPage = otherOptions.querySelector('#fit-to-page-container'); |
| 573 var rasterize; | 561 var rasterize; |
| 574 if (isPrintAsImageEnabled()) | 562 if (isPrintAsImageEnabled()) |
| 575 rasterize = otherOptions.querySelector('#rasterize-container'); | 563 rasterize = otherOptions.querySelector('#rasterize-container'); |
| 576 var mediaSize = $('media-size-settings'); | 564 var mediaSize = $('media-size-settings'); |
| 577 var scalingSettings = $('scaling-settings'); | 565 var scalingSettings = $('scaling-settings'); |
| 578 | 566 |
| 579 // Check that options are collapsed (section is visible, because | 567 // Check that options are collapsed (section is visible, because |
| 580 // duplex is available). | 568 // duplex is available). |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 594 checkSectionVisible(scalingSettings, true); | 582 checkSectionVisible(scalingSettings, true); |
| 595 | 583 |
| 596 return whenAnimationDone('more-settings'); | 584 return whenAnimationDone('more-settings'); |
| 597 }); | 585 }); |
| 598 }); | 586 }); |
| 599 | 587 |
| 600 // When the source is 'PDF', depending on the selected destination printer, | 588 // When the source is 'PDF', depending on the selected destination printer, |
| 601 // we show/hide the fit to page option and hide media size selection. | 589 // we show/hide the fit to page option and hide media size selection. |
| 602 test('SourceIsPDFCapabilities', function() { | 590 test('SourceIsPDFCapabilities', function() { |
| 603 initialSettings.isDocumentModifiable_ = false; | 591 initialSettings.isDocumentModifiable_ = false; |
| 604 return setupSettingsAndDestinations().then(function() { | 592 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 605 setCapabilities(getCddTemplate('FooDevice')); | |
| 606 | |
| 607 var otherOptions = $('other-options-settings'); | 593 var otherOptions = $('other-options-settings'); |
| 608 var scalingSettings = $('scaling-settings'); | 594 var scalingSettings = $('scaling-settings'); |
| 609 var fitToPageContainer = | 595 var fitToPageContainer = |
| 610 otherOptions.querySelector('#fit-to-page-container'); | 596 otherOptions.querySelector('#fit-to-page-container'); |
| 611 var rasterizeContainer; | 597 var rasterizeContainer; |
| 612 if (isPrintAsImageEnabled()) { | 598 if (isPrintAsImageEnabled()) { |
| 613 rasterizeContainer = | 599 rasterizeContainer = |
| 614 otherOptions.querySelector('#rasterize-container'); | 600 otherOptions.querySelector('#rasterize-container'); |
| 615 } | 601 } |
| 616 | 602 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 630 checkSectionVisible(scalingSettings, true); | 616 checkSectionVisible(scalingSettings, true); |
| 631 | 617 |
| 632 return whenAnimationDone('other-options-collapsible'); | 618 return whenAnimationDone('other-options-collapsible'); |
| 633 }); | 619 }); |
| 634 }); | 620 }); |
| 635 | 621 |
| 636 // When the source is 'PDF', depending on the selected destination printer, | 622 // When the source is 'PDF', depending on the selected destination printer, |
| 637 // we show/hide the fit to page option and hide media size selection. | 623 // we show/hide the fit to page option and hide media size selection. |
| 638 test('ScalingUnchecksFitToPage', function() { | 624 test('ScalingUnchecksFitToPage', function() { |
| 639 initialSettings.isDocumentModifiable_ = false; | 625 initialSettings.isDocumentModifiable_ = false; |
| 640 return setupSettingsAndDestinations().then(function() { | 626 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 641 setCapabilities(getCddTemplate('FooDevice')); | |
| 642 | |
| 643 var otherOptions = $('other-options-settings'); | 627 var otherOptions = $('other-options-settings'); |
| 644 var scalingSettings = $('scaling-settings'); | 628 var scalingSettings = $('scaling-settings'); |
| 645 | 629 |
| 646 checkSectionVisible(otherOptions, true); | 630 checkSectionVisible(otherOptions, true); |
| 647 var fitToPageContainer = | 631 var fitToPageContainer = |
| 648 otherOptions.querySelector('#fit-to-page-container'); | 632 otherOptions.querySelector('#fit-to-page-container'); |
| 649 checkElementDisplayed(fitToPageContainer, true); | 633 checkElementDisplayed(fitToPageContainer, true); |
| 650 expectTrue( | 634 expectTrue( |
| 651 fitToPageContainer.querySelector('.checkbox').checked); | 635 fitToPageContainer.querySelector('.checkbox').checked); |
| 652 expandMoreSettings(); | 636 expandMoreSettings(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 668 fitToPageContainer.querySelector('.checkbox').checked); | 652 fitToPageContainer.querySelector('.checkbox').checked); |
| 669 | 653 |
| 670 return whenAnimationDone('other-options-collapsible'); | 654 return whenAnimationDone('other-options-collapsible'); |
| 671 }); | 655 }); |
| 672 }); | 656 }); |
| 673 | 657 |
| 674 // When the number of copies print preset is set for source 'PDF', we update | 658 // When the number of copies print preset is set for source 'PDF', we update |
| 675 // the copies value if capability is supported by printer. | 659 // the copies value if capability is supported by printer. |
| 676 test('CheckNumCopiesPrintPreset', function() { | 660 test('CheckNumCopiesPrintPreset', function() { |
| 677 initialSettings.isDocumentModifiable_ = false; | 661 initialSettings.isDocumentModifiable_ = false; |
| 678 return setupSettingsAndDestinations().then(function() { | 662 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 679 setCapabilities(getCddTemplate('FooDevice')); | |
| 680 | |
| 681 // Indicate that the number of copies print preset is set for source | 663 // Indicate that the number of copies print preset is set for source |
| 682 // PDF. | 664 // PDF. |
| 683 var printPresetOptions = { | 665 var printPresetOptions = { |
| 684 disableScaling: true, | 666 disableScaling: true, |
| 685 copies: 2 | 667 copies: 2 |
| 686 }; | 668 }; |
| 687 var printPresetOptionsEvent = new Event( | 669 var printPresetOptionsEvent = new Event( |
| 688 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); | 670 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| 689 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; | 671 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| 690 nativeLayer.getEventTarget(). | 672 nativeLayer.getEventTarget(). |
| 691 dispatchEvent(printPresetOptionsEvent); | 673 dispatchEvent(printPresetOptionsEvent); |
| 692 | 674 |
| 693 checkSectionVisible($('copies-settings'), true); | 675 checkSectionVisible($('copies-settings'), true); |
| 694 expectEquals( | 676 expectEquals( |
| 695 printPresetOptions.copies, | 677 printPresetOptions.copies, |
| 696 parseInt($('copies-settings'). | 678 parseInt($('copies-settings'). |
| 697 querySelector('.user-value').value)); | 679 querySelector('.user-value').value)); |
| 698 | 680 |
| 699 return whenAnimationDone('other-options-collapsible'); | 681 return whenAnimationDone('other-options-collapsible'); |
| 700 }); | 682 }); |
| 701 }); | 683 }); |
| 702 | 684 |
| 703 // When the duplex print preset is set for source 'PDF', we update the | 685 // When the duplex print preset is set for source 'PDF', we update the |
| 704 // duplex setting if capability is supported by printer. | 686 // duplex setting if capability is supported by printer. |
| 705 test('CheckDuplexPrintPreset', function() { | 687 test('CheckDuplexPrintPreset', function() { |
| 706 initialSettings.isDocumentModifiable_ = false; | 688 initialSettings.isDocumentModifiable_ = false; |
| 707 return setupSettingsAndDestinations().then(function() { | 689 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 708 setCapabilities(getCddTemplate('FooDevice')); | |
| 709 | |
| 710 // Indicate that the duplex print preset is set to 'long edge' for | 690 // Indicate that the duplex print preset is set to 'long edge' for |
| 711 // source PDF. | 691 // source PDF. |
| 712 var printPresetOptions = { | 692 var printPresetOptions = { |
| 713 duplex: 1 | 693 duplex: 1 |
| 714 }; | 694 }; |
| 715 var printPresetOptionsEvent = new Event( | 695 var printPresetOptionsEvent = new Event( |
| 716 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); | 696 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| 717 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; | 697 printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| 718 nativeLayer.getEventTarget(). | 698 nativeLayer.getEventTarget(). |
| 719 dispatchEvent(printPresetOptionsEvent); | 699 dispatchEvent(printPresetOptionsEvent); |
| 720 | 700 |
| 721 var otherOptions = $('other-options-settings'); | 701 var otherOptions = $('other-options-settings'); |
| 722 checkSectionVisible(otherOptions, true); | 702 checkSectionVisible(otherOptions, true); |
| 723 var duplexContainer = | 703 var duplexContainer = |
| 724 otherOptions.querySelector('#duplex-container'); | 704 otherOptions.querySelector('#duplex-container'); |
| 725 checkElementDisplayed(duplexContainer, true); | 705 checkElementDisplayed(duplexContainer, true); |
| 726 expectTrue(duplexContainer.querySelector('.checkbox').checked); | 706 expectTrue(duplexContainer.querySelector('.checkbox').checked); |
| 727 | 707 |
| 728 return whenAnimationDone('other-options-collapsible'); | 708 return whenAnimationDone('other-options-collapsible'); |
| 729 }); | 709 }); |
| 730 }); | 710 }); |
| 731 | 711 |
| 732 // Make sure that custom margins controls are properly set up. | 712 // Make sure that custom margins controls are properly set up. |
| 733 test('CustomMarginsControlsCheck', function() { | 713 test('CustomMarginsControlsCheck', function() { |
| 734 return setupSettingsAndDestinations().then(function() { | 714 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 735 setCapabilities(getCddTemplate('FooDevice')); | |
| 736 | |
| 737 printPreview.printTicketStore_.marginsType.updateValue( | 715 printPreview.printTicketStore_.marginsType.updateValue( |
| 738 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 716 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 739 | 717 |
| 740 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { | 718 ['left', 'top', 'right', 'bottom'].forEach(function(margin) { |
| 741 var control = | 719 var control = |
| 742 $('preview-area').querySelector('.margin-control-' + margin); | 720 $('preview-area').querySelector('.margin-control-' + margin); |
| 743 assertNotEquals(null, control); | 721 assertNotEquals(null, control); |
| 744 var input = control.querySelector('.margin-control-textbox'); | 722 var input = control.querySelector('.margin-control-textbox'); |
| 745 assertTrue(input.hasAttribute('aria-label')); | 723 assertTrue(input.hasAttribute('aria-label')); |
| 746 assertNotEquals('undefined', input.getAttribute('aria-label')); | 724 assertNotEquals('undefined', input.getAttribute('aria-label')); |
| 747 }); | 725 }); |
| 748 return whenAnimationDone('more-settings'); | 726 return whenAnimationDone('more-settings'); |
| 749 }); | 727 }); |
| 750 }); | 728 }); |
| 751 | 729 |
| 752 // Page layout has zero margins. Hide header and footer option. | 730 // Page layout has zero margins. Hide header and footer option. |
| 753 test('PageLayoutHasNoMarginsHideHeaderFooter', function() { | 731 test('PageLayoutHasNoMarginsHideHeaderFooter', function() { |
| 754 return setupSettingsAndDestinations().then(function() { | 732 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 755 setCapabilities(getCddTemplate('FooDevice')); | |
| 756 | |
| 757 var otherOptions = $('other-options-settings'); | 733 var otherOptions = $('other-options-settings'); |
| 758 var headerFooter = | 734 var headerFooter = |
| 759 otherOptions.querySelector('#header-footer-container'); | 735 otherOptions.querySelector('#header-footer-container'); |
| 760 | 736 |
| 761 // Check that options are collapsed (section is visible, because | 737 // Check that options are collapsed (section is visible, because |
| 762 // duplex is available). | 738 // duplex is available). |
| 763 checkSectionVisible(otherOptions, true); | 739 checkSectionVisible(otherOptions, true); |
| 764 checkElementDisplayed(headerFooter, false); | 740 checkElementDisplayed(headerFooter, false); |
| 765 | 741 |
| 766 expandMoreSettings(); | 742 expandMoreSettings(); |
| 767 | 743 |
| 768 checkElementDisplayed(headerFooter, true); | 744 checkElementDisplayed(headerFooter, true); |
| 769 | 745 |
| 770 printPreview.printTicketStore_.marginsType.updateValue( | 746 printPreview.printTicketStore_.marginsType.updateValue( |
| 771 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 747 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 772 printPreview.printTicketStore_.customMargins.updateValue( | 748 printPreview.printTicketStore_.customMargins.updateValue( |
| 773 new print_preview.Margins(0, 0, 0, 0)); | 749 new print_preview.Margins(0, 0, 0, 0)); |
| 774 | 750 |
| 775 checkElementDisplayed(headerFooter, false); | 751 checkElementDisplayed(headerFooter, false); |
| 776 | 752 |
| 777 return whenAnimationDone('more-settings'); | 753 return whenAnimationDone('more-settings'); |
| 778 }); | 754 }); |
| 779 }); | 755 }); |
| 780 | 756 |
| 781 // Page layout has half-inch margins. Show header and footer option. | 757 // Page layout has half-inch margins. Show header and footer option. |
| 782 test('PageLayoutHasMarginsShowHeaderFooter', function() { | 758 test('PageLayoutHasMarginsShowHeaderFooter', function() { |
| 783 return setupSettingsAndDestinations().then(function() { | 759 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 784 setCapabilities(getCddTemplate('FooDevice')); | |
| 785 | |
| 786 var otherOptions = $('other-options-settings'); | 760 var otherOptions = $('other-options-settings'); |
| 787 var headerFooter = | 761 var headerFooter = |
| 788 otherOptions.querySelector('#header-footer-container'); | 762 otherOptions.querySelector('#header-footer-container'); |
| 789 | 763 |
| 790 // Check that options are collapsed (section is visible, because | 764 // Check that options are collapsed (section is visible, because |
| 791 // duplex is available). | 765 // duplex is available). |
| 792 checkSectionVisible(otherOptions, true); | 766 checkSectionVisible(otherOptions, true); |
| 793 checkElementDisplayed(headerFooter, false); | 767 checkElementDisplayed(headerFooter, false); |
| 794 | 768 |
| 795 expandMoreSettings(); | 769 expandMoreSettings(); |
| 796 | 770 |
| 797 checkElementDisplayed(headerFooter, true); | 771 checkElementDisplayed(headerFooter, true); |
| 798 | 772 |
| 799 printPreview.printTicketStore_.marginsType.updateValue( | 773 printPreview.printTicketStore_.marginsType.updateValue( |
| 800 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 774 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 801 printPreview.printTicketStore_.customMargins.updateValue( | 775 printPreview.printTicketStore_.customMargins.updateValue( |
| 802 new print_preview.Margins(36, 36, 36, 36)); | 776 new print_preview.Margins(36, 36, 36, 36)); |
| 803 | 777 |
| 804 checkElementDisplayed(headerFooter, true); | 778 checkElementDisplayed(headerFooter, true); |
| 805 | 779 |
| 806 return whenAnimationDone('more-settings'); | 780 return whenAnimationDone('more-settings'); |
| 807 }); | 781 }); |
| 808 }); | 782 }); |
| 809 | 783 |
| 810 // Page layout has zero top and bottom margins. Hide header and footer | 784 // Page layout has zero top and bottom margins. Hide header and footer |
| 811 // option. | 785 // option. |
| 812 test('ZeroTopAndBottomMarginsHideHeaderFooter', function() { | 786 test('ZeroTopAndBottomMarginsHideHeaderFooter', function() { |
| 813 return setupSettingsAndDestinations().then(function() { | 787 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 814 setCapabilities(getCddTemplate('FooDevice')); | |
| 815 | |
| 816 var otherOptions = $('other-options-settings'); | 788 var otherOptions = $('other-options-settings'); |
| 817 var headerFooter = | 789 var headerFooter = |
| 818 otherOptions.querySelector('#header-footer-container'); | 790 otherOptions.querySelector('#header-footer-container'); |
| 819 | 791 |
| 820 // Check that options are collapsed (section is visible, because | 792 // Check that options are collapsed (section is visible, because |
| 821 // duplex is available). | 793 // duplex is available). |
| 822 checkSectionVisible(otherOptions, true); | 794 checkSectionVisible(otherOptions, true); |
| 823 checkElementDisplayed(headerFooter, false); | 795 checkElementDisplayed(headerFooter, false); |
| 824 | 796 |
| 825 expandMoreSettings(); | 797 expandMoreSettings(); |
| 826 | 798 |
| 827 checkElementDisplayed(headerFooter, true); | 799 checkElementDisplayed(headerFooter, true); |
| 828 | 800 |
| 829 printPreview.printTicketStore_.marginsType.updateValue( | 801 printPreview.printTicketStore_.marginsType.updateValue( |
| 830 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 802 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 831 printPreview.printTicketStore_.customMargins.updateValue( | 803 printPreview.printTicketStore_.customMargins.updateValue( |
| 832 new print_preview.Margins(0, 36, 0, 36)); | 804 new print_preview.Margins(0, 36, 0, 36)); |
| 833 | 805 |
| 834 checkElementDisplayed(headerFooter, false); | 806 checkElementDisplayed(headerFooter, false); |
| 835 | 807 |
| 836 return whenAnimationDone('more-settings'); | 808 return whenAnimationDone('more-settings'); |
| 837 }); | 809 }); |
| 838 }); | 810 }); |
| 839 | 811 |
| 840 // Page layout has zero top and half-inch bottom margin. Show header and | 812 // Page layout has zero top and half-inch bottom margin. Show header and |
| 841 // footer option. | 813 // footer option. |
| 842 test('ZeroTopAndNonZeroBottomMarginShowHeaderFooter', function() { | 814 test('ZeroTopAndNonZeroBottomMarginShowHeaderFooter', function() { |
| 843 return setupSettingsAndDestinations().then(function() { | 815 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 844 setCapabilities(getCddTemplate('FooDevice')); | |
| 845 | |
| 846 var otherOptions = $('other-options-settings'); | 816 var otherOptions = $('other-options-settings'); |
| 847 var headerFooter = | 817 var headerFooter = |
| 848 otherOptions.querySelector('#header-footer-container'); | 818 otherOptions.querySelector('#header-footer-container'); |
| 849 | 819 |
| 850 // Check that options are collapsed (section is visible, because | 820 // Check that options are collapsed (section is visible, because |
| 851 // duplex is available). | 821 // duplex is available). |
| 852 checkSectionVisible(otherOptions, true); | 822 checkSectionVisible(otherOptions, true); |
| 853 checkElementDisplayed(headerFooter, false); | 823 checkElementDisplayed(headerFooter, false); |
| 854 | 824 |
| 855 expandMoreSettings(); | 825 expandMoreSettings(); |
| 856 | 826 |
| 857 checkElementDisplayed(headerFooter, true); | 827 checkElementDisplayed(headerFooter, true); |
| 858 | 828 |
| 859 printPreview.printTicketStore_.marginsType.updateValue( | 829 printPreview.printTicketStore_.marginsType.updateValue( |
| 860 print_preview.ticket_items.MarginsTypeValue.CUSTOM); | 830 print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| 861 printPreview.printTicketStore_.customMargins.updateValue( | 831 printPreview.printTicketStore_.customMargins.updateValue( |
| 862 new print_preview.Margins(0, 36, 36, 36)); | 832 new print_preview.Margins(0, 36, 36, 36)); |
| 863 | 833 |
| 864 checkElementDisplayed(headerFooter, true); | 834 checkElementDisplayed(headerFooter, true); |
| 865 | 835 |
| 866 return whenAnimationDone('more-settings'); | 836 return whenAnimationDone('more-settings'); |
| 867 }); | 837 }); |
| 868 }); | 838 }); |
| 869 | 839 |
| 870 // Check header footer availability with small (label) page size. | 840 // Check header footer availability with small (label) page size. |
| 871 test('SmallPaperSizeHeaderFooter', function() { | 841 test('SmallPaperSizeHeaderFooter', function() { |
| 872 return setupSettingsAndDestinations().then(function() { | 842 var device = getCddTemplate('FooDevice'); |
| 873 var device = getCddTemplate('FooDevice'); | 843 device.capabilities.printer.media_size = { |
| 874 device.capabilities.printer.media_size = { | 844 'option': [ |
| 875 'option': [ | 845 {'name': 'SmallLabel', 'width_microns': 38100, |
| 876 {'name': 'SmallLabel', 'width_microns': 38100, | 846 'height_microns': 12700, 'is_default': false}, |
| 877 'height_microns': 12700, 'is_default': false}, | 847 {'name': 'BigLabel', 'width_microns': 50800, |
| 878 {'name': 'BigLabel', 'width_microns': 50800, | 848 'height_microns': 76200, 'is_default': true} |
| 879 'height_microns': 76200, 'is_default': true} | 849 ] |
| 880 ] | 850 }; |
| 881 }; | 851 return setupSettingsAndDestinationsWithCapabilities(device) |
| 882 setCapabilities(device); | 852 .then(function() { |
| 883 | |
| 884 var otherOptions = $('other-options-settings'); | 853 var otherOptions = $('other-options-settings'); |
| 885 var headerFooter = | 854 var headerFooter = |
| 886 otherOptions.querySelector('#header-footer-container'); | 855 otherOptions.querySelector('#header-footer-container'); |
| 887 | 856 |
| 888 // Check that options are collapsed (section is visible, because | 857 // Check that options are collapsed (section is visible, because |
| 889 // duplex is available). | 858 // duplex is available). |
| 890 checkSectionVisible(otherOptions, true); | 859 checkSectionVisible(otherOptions, true); |
| 891 checkElementDisplayed(headerFooter, false); | 860 checkElementDisplayed(headerFooter, false); |
| 892 | 861 |
| 893 expandMoreSettings(); | 862 expandMoreSettings(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 904 // header/footer. | 873 // header/footer. |
| 905 printPreview.printTicketStore_.landscape.updateValue(true); | 874 printPreview.printTicketStore_.landscape.updateValue(true); |
| 906 checkElementDisplayed(headerFooter, true); | 875 checkElementDisplayed(headerFooter, true); |
| 907 | 876 |
| 908 return whenAnimationDone('more-settings'); | 877 return whenAnimationDone('more-settings'); |
| 909 }); | 878 }); |
| 910 }); | 879 }); |
| 911 | 880 |
| 912 // Test that the color settings, one option, standard monochrome. | 881 // Test that the color settings, one option, standard monochrome. |
| 913 test('ColorSettingsMonochrome', function() { | 882 test('ColorSettingsMonochrome', function() { |
| 914 return setupSettingsAndDestinations().then(function() { | 883 // Only one option, standard monochrome. |
| 915 // Only one option, standard monochrome. | 884 var device = getCddTemplate('FooDevice'); |
| 916 var device = getCddTemplate('FooDevice'); | 885 device.capabilities.printer.color = { |
| 917 device.capabilities.printer.color = { | 886 'option': [ |
| 918 'option': [ | 887 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} |
| 919 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} | 888 ] |
| 920 ] | 889 }; |
| 921 }; | |
| 922 setCapabilities(device); | |
| 923 | 890 |
| 891 return setupSettingsAndDestinationsWithCapabilities(device) | |
| 892 .then(function() { | |
| 924 checkSectionVisible($('color-settings'), false); | 893 checkSectionVisible($('color-settings'), false); |
| 925 | 894 |
| 926 return whenAnimationDone('more-settings'); | 895 return whenAnimationDone('more-settings'); |
| 927 }); | 896 }); |
| 928 }); | 897 }); |
| 929 | 898 |
| 930 // Test that the color settings, one option, custom monochrome. | 899 // Test that the color settings, one option, custom monochrome. |
| 931 test('ColorSettingsCustomMonochrome', function() { | 900 test('ColorSettingsCustomMonochrome', function() { |
| 932 return setupSettingsAndDestinations().then(function() { | 901 // Only one option, standard monochrome. |
| 933 // Only one option, standard monochrome. | 902 var device = getCddTemplate('FooDevice'); |
| 934 var device = getCddTemplate('FooDevice'); | 903 device.capabilities.printer.color = { |
| 935 device.capabilities.printer.color = { | 904 'option': [ |
| 936 'option': [ | 905 {'is_default': true, 'type': 'CUSTOM_MONOCHROME', |
| 937 {'is_default': true, 'type': 'CUSTOM_MONOCHROME', | 906 'vendor_id': '42'} |
| 938 'vendor_id': '42'} | 907 ] |
| 939 ] | 908 }; |
| 940 }; | |
| 941 setCapabilities(device); | |
| 942 | 909 |
| 910 return setupSettingsAndDestinationsWithCapabilities(device) | |
| 911 .then(function() { | |
| 943 checkSectionVisible($('color-settings'), false); | 912 checkSectionVisible($('color-settings'), false); |
| 944 | 913 |
| 945 return whenAnimationDone('more-settings'); | 914 return whenAnimationDone('more-settings'); |
| 946 }); | 915 }); |
| 947 }); | 916 }); |
| 948 | 917 |
| 949 // Test that the color settings, one option, standard color. | 918 // Test that the color settings, one option, standard color. |
| 950 test('ColorSettingsColor', function() { | 919 test('ColorSettingsColor', function() { |
| 951 return setupSettingsAndDestinations().then(function() { | 920 var device = getCddTemplate('FooDevice'); |
| 952 var device = getCddTemplate('FooDevice'); | 921 device.capabilities.printer.color = { |
| 953 device.capabilities.printer.color = { | 922 'option': [ |
| 954 'option': [ | 923 {'is_default': true, 'type': 'STANDARD_COLOR'} |
| 955 {'is_default': true, 'type': 'STANDARD_COLOR'} | 924 ] |
| 956 ] | 925 }; |
| 957 }; | |
| 958 setCapabilities(device); | |
| 959 | 926 |
| 927 return setupSettingsAndDestinationsWithCapabilities(device) | |
| 928 .then(function() { | |
| 960 checkSectionVisible($('color-settings'), false); | 929 checkSectionVisible($('color-settings'), false); |
| 961 | 930 |
| 962 return whenAnimationDone('more-settings'); | 931 return whenAnimationDone('more-settings'); |
| 963 }); | 932 }); |
| 964 }); | 933 }); |
| 965 | 934 |
| 966 // Test that the color settings, one option, custom color. | 935 // Test that the color settings, one option, custom color. |
| 967 test('ColorSettingsCustomColor', function() { | 936 test('ColorSettingsCustomColor', function() { |
| 968 return setupSettingsAndDestinations().then(function() { | 937 var device = getCddTemplate('FooDevice'); |
| 969 var device = getCddTemplate('FooDevice'); | 938 device.capabilities.printer.color = { |
| 970 device.capabilities.printer.color = { | 939 'option': [ |
| 971 'option': [ | 940 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'} |
| 972 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'} | 941 ] |
| 973 ] | 942 }; |
| 974 }; | 943 return setupSettingsAndDestinationsWithCapabilities(device) |
| 975 setCapabilities(device); | 944 .then(function() { |
| 976 | |
| 977 checkSectionVisible($('color-settings'), false); | 945 checkSectionVisible($('color-settings'), false); |
| 978 | 946 |
| 979 return whenAnimationDone('more-settings'); | 947 return whenAnimationDone('more-settings'); |
| 980 }); | 948 }); |
| 981 }); | 949 }); |
| 982 | 950 |
| 983 // Test that the color settings, two options, both standard, defaults to | 951 // Test that the color settings, two options, both standard, defaults to |
| 984 // color. | 952 // color. |
| 985 test('ColorSettingsBothStandardDefaultColor', function() { | 953 test('ColorSettingsBothStandardDefaultColor', function() { |
| 986 return setupSettingsAndDestinations().then(function() { | 954 var device = getCddTemplate('FooDevice'); |
| 987 var device = getCddTemplate('FooDevice'); | 955 device.capabilities.printer.color = { |
| 988 device.capabilities.printer.color = { | 956 'option': [ |
| 989 'option': [ | 957 {'type': 'STANDARD_MONOCHROME'}, |
| 990 {'type': 'STANDARD_MONOCHROME'}, | 958 {'is_default': true, 'type': 'STANDARD_COLOR'} |
| 991 {'is_default': true, 'type': 'STANDARD_COLOR'} | 959 ] |
| 992 ] | 960 }; |
| 993 }; | 961 return setupSettingsAndDestinationsWithCapabilities(device) |
| 994 setCapabilities(device); | 962 .then(function() { |
| 995 | |
| 996 checkSectionVisible($('color-settings'), true); | 963 checkSectionVisible($('color-settings'), true); |
| 997 expectEquals( | 964 expectEquals( |
| 998 'color', | 965 'color', |
| 999 $('color-settings').querySelector( | 966 $('color-settings').querySelector( |
| 1000 '.color-settings-select').value); | 967 '.color-settings-select').value); |
| 1001 | 968 |
| 1002 return whenAnimationDone('more-settings'); | 969 return whenAnimationDone('more-settings'); |
| 1003 }); | 970 }); |
| 1004 }); | 971 }); |
| 1005 | 972 |
| 1006 // Test that the color settings, two options, both standard, defaults to | 973 // Test that the color settings, two options, both standard, defaults to |
| 1007 // monochrome. | 974 // monochrome. |
| 1008 test('ColorSettingsBothStandardDefaultMonochrome', function() { | 975 test('ColorSettingsBothStandardDefaultMonochrome', function() { |
| 1009 return setupSettingsAndDestinations().then(function() { | 976 var device = getCddTemplate('FooDevice'); |
| 1010 var device = getCddTemplate('FooDevice'); | 977 device.capabilities.printer.color = { |
| 1011 device.capabilities.printer.color = { | 978 'option': [ |
| 1012 'option': [ | 979 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}, |
| 1013 {'is_default': true, 'type': 'STANDARD_MONOCHROME'}, | 980 {'type': 'STANDARD_COLOR'} |
| 1014 {'type': 'STANDARD_COLOR'} | 981 ] |
| 1015 ] | 982 }; |
| 1016 }; | 983 return setupSettingsAndDestinationsWithCapabilities(device) |
| 1017 setCapabilities(device); | 984 .then(function() { |
| 1018 | |
| 1019 checkSectionVisible($('color-settings'), true); | 985 checkSectionVisible($('color-settings'), true); |
| 1020 expectEquals( | 986 expectEquals( |
| 1021 'bw', | 987 'bw', |
| 1022 $('color-settings').querySelector( | 988 $('color-settings').querySelector( |
| 1023 '.color-settings-select').value); | 989 '.color-settings-select').value); |
| 1024 | 990 |
| 1025 return whenAnimationDone('more-settings'); | 991 return whenAnimationDone('more-settings'); |
| 1026 }); | 992 }); |
| 1027 }); | 993 }); |
| 1028 | 994 |
| 1029 // Test that the color settings, two options, both custom, defaults to | 995 // Test that the color settings, two options, both custom, defaults to |
| 1030 // color. | 996 // color. |
| 1031 test('ColorSettingsBothCustomDefaultColor', function() { | 997 test('ColorSettingsBothCustomDefaultColor', function() { |
| 1032 return setupSettingsAndDestinations().then(function() { | 998 var device = getCddTemplate('FooDevice'); |
| 1033 var device = getCddTemplate('FooDevice'); | 999 device.capabilities.printer.color = { |
| 1034 device.capabilities.printer.color = { | 1000 'option': [ |
| 1035 'option': [ | 1001 {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'}, |
| 1036 {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'}, | 1002 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'} |
| 1037 {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'} | 1003 ] |
| 1038 ] | 1004 }; |
| 1039 }; | 1005 return setupSettingsAndDestinationsWithCapabilities(device) |
| 1040 setCapabilities(device); | 1006 .then(function() { |
| 1041 | |
| 1042 checkSectionVisible($('color-settings'), true); | 1007 checkSectionVisible($('color-settings'), true); |
| 1043 expectEquals( | 1008 expectEquals( |
| 1044 'color', | 1009 'color', |
| 1045 $('color-settings').querySelector( | 1010 $('color-settings').querySelector( |
| 1046 '.color-settings-select').value); | 1011 '.color-settings-select').value); |
| 1047 | 1012 |
| 1048 return whenAnimationDone('more-settings'); | 1013 return whenAnimationDone('more-settings'); |
| 1049 }); | 1014 }); |
| 1050 }); | 1015 }); |
| 1051 | 1016 |
| 1052 // Test to verify that duplex settings are set according to the printer | 1017 // Test to verify that duplex settings are set according to the printer |
| 1053 // capabilities. | 1018 // capabilities. |
| 1054 test('DuplexSettingsTrue', function() { | 1019 test('DuplexSettingsTrue', function() { |
| 1055 return setupSettingsAndDestinations().then(function() { | 1020 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1056 setCapabilities(getCddTemplate('FooDevice')); | |
| 1057 | |
| 1058 var otherOptions = $('other-options-settings'); | 1021 var otherOptions = $('other-options-settings'); |
| 1059 checkSectionVisible(otherOptions, true); | 1022 checkSectionVisible(otherOptions, true); |
| 1060 duplexContainer = otherOptions.querySelector('#duplex-container'); | 1023 duplexContainer = otherOptions.querySelector('#duplex-container'); |
| 1061 expectFalse(duplexContainer.hidden); | 1024 expectFalse(duplexContainer.hidden); |
| 1062 expectFalse(duplexContainer.querySelector('.checkbox').checked); | 1025 expectFalse(duplexContainer.querySelector('.checkbox').checked); |
| 1063 | 1026 |
| 1064 return whenAnimationDone('more-settings'); | 1027 return whenAnimationDone('more-settings'); |
| 1065 }); | 1028 }); |
| 1066 }); | 1029 }); |
| 1067 | 1030 |
| 1068 // Test to verify that duplex settings are set according to the printer | 1031 // Test to verify that duplex settings are set according to the printer |
| 1069 // capabilities. | 1032 // capabilities. |
| 1070 test('DuplexSettingsFalse', function() { | 1033 test('DuplexSettingsFalse', function() { |
| 1071 return setupSettingsAndDestinations().then(function() { | 1034 var device = getCddTemplate('FooDevice'); |
| 1072 var device = getCddTemplate('FooDevice'); | 1035 delete device.capabilities.printer.duplex; |
| 1073 delete device.capabilities.printer.duplex; | 1036 return setupSettingsAndDestinationsWithCapabilities(device) |
| 1074 setCapabilities(device); | 1037 .then(function() { |
| 1075 | |
| 1076 // Check that it is collapsed. | 1038 // Check that it is collapsed. |
| 1077 var otherOptions = $('other-options-settings'); | 1039 var otherOptions = $('other-options-settings'); |
| 1078 checkSectionVisible(otherOptions, false); | 1040 checkSectionVisible(otherOptions, false); |
| 1079 | 1041 |
| 1080 expandMoreSettings(); | 1042 expandMoreSettings(); |
| 1081 | 1043 |
| 1082 // Now it should be visible. | 1044 // Now it should be visible. |
| 1083 checkSectionVisible(otherOptions, true); | 1045 checkSectionVisible(otherOptions, true); |
| 1084 expectTrue(otherOptions.querySelector('#duplex-container').hidden); | 1046 expectTrue(otherOptions.querySelector('#duplex-container').hidden); |
| 1085 | 1047 |
| 1086 return whenAnimationDone('more-settings'); | 1048 return whenAnimationDone('more-settings'); |
| 1087 }); | 1049 }); |
| 1088 }); | 1050 }); |
| 1089 | 1051 |
| 1090 // Test that changing the selected printer updates the preview. | 1052 // Test that changing the selected printer updates the preview. |
| 1091 test('PrinterChangeUpdatesPreview', function() { | 1053 test('PrinterChangeUpdatesPreview', function() { |
| 1092 return setupSettingsAndDestinations().then(function() { | 1054 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1093 setCapabilities(getCddTemplate('FooDevice')); | |
| 1094 | |
| 1095 var previewGenerator = mock(print_preview.PreviewGenerator); | 1055 var previewGenerator = mock(print_preview.PreviewGenerator); |
| 1096 previewArea.previewGenerator_ = previewGenerator.proxy(); | 1056 previewArea.previewGenerator_ = previewGenerator.proxy(); |
| 1097 | 1057 |
| 1098 // The number of settings that can change due to a change in the | 1058 // The number of settings that can change due to a change in the |
| 1099 // destination that will therefore dispatch ticket item change events. | 1059 // destination that will therefore dispatch ticket item change events. |
| 1100 previewGenerator.expects(exactly(9)).requestPreview(); | 1060 previewGenerator.expects(exactly(9)).requestPreview(); |
| 1101 | 1061 |
| 1102 var barDestination = | 1062 // Setup capabilities for BarDevice. |
| 1103 printPreview.destinationStore_.destinations().find( | |
| 1104 function(d) { | |
| 1105 return d.id == 'BarDevice'; | |
| 1106 }); | |
| 1107 | |
| 1108 printPreview.destinationStore_.selectDestination(barDestination); | |
| 1109 | |
| 1110 var device = getCddTemplate('BarDevice'); | 1063 var device = getCddTemplate('BarDevice'); |
| 1111 device.capabilities.printer.color = { | 1064 device.capabilities.printer.color = { |
| 1112 'option': [ | 1065 'option': [ |
| 1113 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} | 1066 {'is_default': true, 'type': 'STANDARD_MONOCHROME'} |
| 1114 ] | 1067 ] |
| 1115 }; | 1068 }; |
| 1116 setCapabilities(device); | 1069 nativeLayer.setLocalDestinationCapabilities(device); |
| 1117 | 1070 |
| 1071 // Select BarDevice | |
| 1072 var barDestination = | |
| 1073 printPreview.destinationStore_.destinations().find( | |
| 1074 function(d) { | |
| 1075 return d.id == 'BarDevice'; | |
| 1076 }); | |
| 1077 printPreview.destinationStore_.selectDestination(barDestination); | |
| 1078 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice'); | |
| 1079 }).then(function(){ | |
| 1118 return whenAnimationDone('more-settings'); | 1080 return whenAnimationDone('more-settings'); |
| 1119 }); | 1081 }); |
| 1120 }); | 1082 }); |
| 1121 | 1083 |
| 1122 // Test that error message is displayed when plugin doesn't exist. | 1084 // Test that error message is displayed when plugin doesn't exist. |
| 1123 test('NoPDFPluginErrorMessage', function() { | 1085 test('NoPDFPluginErrorMessage', function() { |
| 1086 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('FooDevice')); | |
| 1124 setInitialSettings(); | 1087 setInitialSettings(); |
| 1125 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 1088 return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| 1126 var previewAreaEl = $('preview-area'); | 1089 var previewAreaEl = $('preview-area'); |
| 1127 | 1090 |
| 1128 var loadingMessageEl = | 1091 var loadingMessageEl = |
| 1129 previewAreaEl. | 1092 previewAreaEl. |
| 1130 getElementsByClassName('preview-area-loading-message')[0]; | 1093 getElementsByClassName('preview-area-loading-message')[0]; |
| 1131 expectTrue(loadingMessageEl.hidden); | 1094 expectTrue(loadingMessageEl.hidden); |
| 1132 | 1095 |
| 1133 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( | 1096 var previewFailedMessageEl = previewAreaEl.getElementsByClassName( |
| 1134 'preview-area-preview-failed-message')[0]; | 1097 'preview-area-preview-failed-message')[0]; |
| 1135 expectTrue(previewFailedMessageEl.hidden); | 1098 expectTrue(previewFailedMessageEl.hidden); |
| 1136 | 1099 |
| 1137 var printFailedMessageEl = | 1100 var printFailedMessageEl = |
| 1138 previewAreaEl. | 1101 previewAreaEl. |
| 1139 getElementsByClassName('preview-area-print-failed')[0]; | 1102 getElementsByClassName('preview-area-print-failed')[0]; |
| 1140 expectTrue(printFailedMessageEl.hidden); | 1103 expectTrue(printFailedMessageEl.hidden); |
| 1141 | 1104 |
| 1142 var customMessageEl = | 1105 var customMessageEl = |
| 1143 previewAreaEl. | 1106 previewAreaEl. |
| 1144 getElementsByClassName('preview-area-custom-message')[0]; | 1107 getElementsByClassName('preview-area-custom-message')[0]; |
| 1145 expectFalse(customMessageEl.hidden); | 1108 expectFalse(customMessageEl.hidden); |
| 1146 }); | 1109 }); |
| 1147 }); | 1110 }); |
| 1148 | 1111 |
| 1149 // Test custom localized paper names. | 1112 // Test custom localized paper names. |
| 1150 test('CustomPaperNames', function() { | 1113 test('CustomPaperNames', function() { |
| 1151 return setupSettingsAndDestinations().then(function() { | 1114 var customLocalizedMediaName = 'Vendor defined localized media name'; |
| 1152 var customLocalizedMediaName = 'Vendor defined localized media name'; | 1115 var customMediaName = 'Vendor defined media name'; |
| 1153 var customMediaName = 'Vendor defined media name'; | |
| 1154 | 1116 |
| 1155 var device = getCddTemplate('FooDevice'); | 1117 var device = getCddTemplate('FooDevice'); |
| 1156 device.capabilities.printer.media_size = { | 1118 device.capabilities.printer.media_size = { |
| 1157 option: [ | 1119 option: [ |
| 1158 { name: 'CUSTOM', | 1120 { name: 'CUSTOM', |
| 1159 width_microns: 15900, | 1121 width_microns: 15900, |
| 1160 height_microns: 79400, | 1122 height_microns: 79400, |
| 1161 is_default: true, | 1123 is_default: true, |
| 1162 custom_display_name_localized: [ | 1124 custom_display_name_localized: [ |
| 1163 { locale: navigator.language, | 1125 { locale: navigator.language, |
| 1164 value: customLocalizedMediaName | 1126 value: customLocalizedMediaName |
| 1165 } | 1127 } |
| 1166 ] | 1128 ] |
| 1167 }, | 1129 }, |
| 1168 { name: 'CUSTOM', | 1130 { name: 'CUSTOM', |
| 1169 width_microns: 15900, | 1131 width_microns: 15900, |
| 1170 height_microns: 79400, | 1132 height_microns: 79400, |
| 1171 custom_display_name: customMediaName | 1133 custom_display_name: customMediaName |
| 1172 } | 1134 } |
| 1173 ] | 1135 ] |
| 1174 }; | 1136 }; |
| 1175 | 1137 |
| 1176 setCapabilities(device); | 1138 return setupSettingsAndDestinationsWithCapabilities(device) |
| 1177 | 1139 .then(function() { |
| 1178 expandMoreSettings(); | 1140 expandMoreSettings(); |
| 1179 | 1141 |
| 1180 checkSectionVisible($('media-size-settings'), true); | 1142 checkSectionVisible($('media-size-settings'), true); |
| 1181 var mediaSelect = | 1143 var mediaSelect = |
| 1182 $('media-size-settings').querySelector('.settings-select'); | 1144 $('media-size-settings').querySelector('.settings-select'); |
| 1183 // Check the default media item. | 1145 // Check the default media item. |
| 1184 expectEquals( | 1146 expectEquals( |
| 1185 customLocalizedMediaName, | 1147 customLocalizedMediaName, |
| 1186 mediaSelect.options[mediaSelect.selectedIndex].text); | 1148 mediaSelect.options[mediaSelect.selectedIndex].text); |
| 1187 // Check the other media item. | 1149 // Check the other media item. |
| 1188 expectEquals( | 1150 expectEquals( |
| 1189 customMediaName, | 1151 customMediaName, |
| 1190 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); | 1152 mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); |
| 1191 | 1153 |
| 1192 return whenAnimationDone('more-settings'); | 1154 return whenAnimationDone('more-settings'); |
| 1193 }); | 1155 }); |
| 1194 }); | 1156 }); |
| 1195 | 1157 |
| 1196 // Test advanced settings with 1 capability (should not display settings | 1158 // Test advanced settings with 1 capability (should not display settings |
| 1197 // search box). | 1159 // search box). |
| 1198 test('AdvancedSettings1Option', function() { | 1160 test('AdvancedSettings1Option', function() { |
| 1199 var device = getCddTemplateWithAdvancedSettings('FooDevice'); | 1161 var device = getCddTemplateWithAdvancedSettings('FooDevice'); |
| 1200 return setupSettingsAndDestinations().then(function() { | 1162 return setupSettingsAndDestinationsWithCapabilities(device) |
| 1163 .then(function() { | |
| 1201 startAdvancedSettingsTest(device); | 1164 startAdvancedSettingsTest(device); |
| 1202 checkElementDisplayed($('advanced-settings'). | 1165 checkElementDisplayed($('advanced-settings'). |
| 1203 querySelector('.search-box-area'), false); | 1166 querySelector('.search-box-area'), false); |
| 1204 | 1167 |
| 1205 return whenAnimationDone('more-settings'); | 1168 return whenAnimationDone('more-settings'); |
| 1206 }); | 1169 }); |
| 1207 }); | 1170 }); |
| 1208 | 1171 |
| 1209 | 1172 |
| 1210 // Test advanced settings with 2 capabilities (should have settings search | 1173 // Test advanced settings with 2 capabilities (should have settings search |
| 1211 // box). | 1174 // box). |
| 1212 test('AdvancedSettings2Options', function() { | 1175 test('AdvancedSettings2Options', function() { |
| 1213 var device = getCddTemplateWithAdvancedSettings('FooDevice'); | 1176 var device = getCddTemplateWithAdvancedSettings('FooDevice'); |
| 1214 // Add new capability. | 1177 // Add new capability. |
| 1215 device.capabilities.printer.vendor_capability.push({ | 1178 device.capabilities.printer.vendor_capability.push({ |
| 1216 display_name: 'Paper Type', | 1179 display_name: 'Paper Type', |
| 1217 id: 'Paper Type', | 1180 id: 'Paper Type', |
| 1218 type: 'SELECT', | 1181 type: 'SELECT', |
| 1219 select_cap: { | 1182 select_cap: { |
| 1220 option: [ | 1183 option: [ |
| 1221 {display_name: 'Standard', value: 0, is_default: true}, | 1184 {display_name: 'Standard', value: 0, is_default: true}, |
| 1222 {display_name: 'Recycled', value: 1}, | 1185 {display_name: 'Recycled', value: 1}, |
| 1223 {display_name: 'Special', value: 2} | 1186 {display_name: 'Special', value: 2} |
| 1224 ] | 1187 ] |
| 1225 } | 1188 } |
| 1226 }); | 1189 }); |
| 1227 return setupSettingsAndDestinations().then(function() { | 1190 return setupSettingsAndDestinationsWithCapabilities(device) |
| 1191 .then(function() { | |
| 1228 startAdvancedSettingsTest(device); | 1192 startAdvancedSettingsTest(device); |
| 1229 | 1193 |
| 1230 checkElementDisplayed($('advanced-settings'). | 1194 checkElementDisplayed($('advanced-settings'). |
| 1231 querySelector('.search-box-area'), true); | 1195 querySelector('.search-box-area'), true); |
| 1232 | 1196 |
| 1233 return whenAnimationDone('more-settings'); | 1197 return whenAnimationDone('more-settings'); |
| 1234 }); | 1198 }); |
| 1235 }); | 1199 }); |
| 1236 | 1200 |
| 1237 // Test that initialization with saved destination only issues one call | 1201 // Test that initialization with saved destination only issues one call |
| 1238 // to startPreview. | 1202 // to startPreview. |
| 1239 test('InitIssuesOneRequest', function() { | 1203 test('InitIssuesOneRequest', function() { |
| 1240 // Load in a bunch of recent destinations with non null capabilities. | 1204 // Load in a bunch of recent destinations with non null capabilities. |
| 1241 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; | 1205 var origin = cr.isChromeOS ? 'chrome_os' : 'local'; |
| 1242 initialSettings.serializedAppStateStr_ = JSON.stringify({ | 1206 initialSettings.serializedAppStateStr_ = JSON.stringify({ |
| 1243 version: 2, | 1207 version: 2, |
| 1244 recentDestinations: [1, 2, 3].map(function(i) { | 1208 recentDestinations: [1, 2, 3].map(function(i) { |
| 1245 return { | 1209 return { |
| 1246 id: 'ID' + i, origin: origin, account: '', | 1210 id: 'ID' + i, origin: origin, account: '', |
| 1247 capabilities: getCddTemplate('ID' + i), name: '', | 1211 capabilities: getCddTemplate('ID' + i), name: '', |
| 1248 extensionId: '', extensionName: '' | 1212 extensionId: '', extensionName: '' |
| 1249 }; | 1213 }; |
| 1250 }), | 1214 }), |
| 1251 }); | 1215 }); |
| 1252 setCapabilities(getCddTemplate('ID1')); | 1216 |
| 1253 setCapabilities(getCddTemplate('ID2')); | 1217 // Ensure all capabilities are available for fetch. |
| 1254 setCapabilities(getCddTemplate('ID3')); | 1218 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID1')); |
| 1219 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID2')) | |
| 1220 nativeLayer.setLocalDestinationCapabilities(getCddTemplate('ID3')); | |
| 1255 | 1221 |
| 1256 // Use a real preview generator. | 1222 // Use a real preview generator. |
| 1257 previewArea.previewGenerator_ = | 1223 previewArea.previewGenerator_ = |
| 1258 new print_preview.PreviewGenerator(printPreview.destinationStore_, | 1224 new print_preview.PreviewGenerator(printPreview.destinationStore_, |
| 1259 printPreview.printTicketStore_, nativeLayer, | 1225 printPreview.printTicketStore_, nativeLayer, |
| 1260 printPreview.documentInfo_); | 1226 printPreview.documentInfo_); |
| 1261 | 1227 |
| 1262 // Preview generator starts out with inFlightRequestId_ == -1. The id | 1228 // Preview generator starts out with inFlightRequestId_ == -1. The id |
| 1263 // increments by 1 for each startGetPreview call it makes. It should only | 1229 // increments by 1 for each startGetPreview call it makes. It should only |
| 1264 // make one such call during initialization or there will be a race; see | 1230 // make one such call during initialization or there will be a race; see |
| 1265 // crbug.com/666595 | 1231 // crbug.com/666595 |
| 1266 expectEquals(-1, previewArea.previewGenerator_.inFlightRequestId_); | 1232 expectEquals(-1, previewArea.previewGenerator_.inFlightRequestId_); |
| 1267 setInitialSettings(); | 1233 setInitialSettings(); |
| 1268 return nativeLayer.whenCalled('getInitialSettings').then(function() { | 1234 return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| 1235 return nativeLayer.whenCalled('getPrinterCapabilities', 'ID1'); | |
| 1236 }).then(function() { | |
| 1269 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_); | 1237 expectEquals(0, previewArea.previewGenerator_.inFlightRequestId_); |
| 1270 }); | 1238 }); |
| 1271 }); | 1239 }); |
| 1272 | 1240 |
| 1273 // Test that invalid settings errors disable the print preview and display | 1241 // Test that invalid settings errors disable the print preview and display |
| 1274 // an error and that the preview dialog can be recovered by selecting a | 1242 // an error and that the preview dialog can be recovered by selecting a |
| 1275 // new destination. | 1243 // new destination. |
| 1276 test('InvalidSettingsError', function() { | 1244 test('InvalidSettingsError', function() { |
| 1277 return setupSettingsAndDestinations().then(function() { | 1245 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1278 setCapabilities(getCddTemplate('FooDevice')); | |
| 1279 | |
| 1280 // Manually enable the print header. This is needed since there is no | 1246 // Manually enable the print header. This is needed since there is no |
| 1281 // plugin during test, so it will be set as disabled normally. | 1247 // plugin during test, so it will be set as disabled normally. |
| 1282 printPreview.printHeader_.isEnabled = true; | 1248 printPreview.printHeader_.isEnabled = true; |
| 1283 | 1249 |
| 1284 // There will be an error message in the preview area since the plugin | 1250 // There will be an error message in the preview area since the plugin |
| 1285 // is not running. However, it should not be the invalid settings | 1251 // is not running. However, it should not be the invalid settings |
| 1286 // error. | 1252 // error. |
| 1287 var previewAreaEl = $('preview-area'); | 1253 var previewAreaEl = $('preview-area'); |
| 1288 var customMessageEl = | 1254 var customMessageEl = |
| 1289 previewAreaEl. | 1255 previewAreaEl. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1312 expectedMessageStart)); | 1278 expectedMessageStart)); |
| 1313 expectTrue(printButton.disabled); | 1279 expectTrue(printButton.disabled); |
| 1314 | 1280 |
| 1315 // Select a new destination | 1281 // Select a new destination |
| 1316 var barDestination = | 1282 var barDestination = |
| 1317 printPreview.destinationStore_.destinations().find( | 1283 printPreview.destinationStore_.destinations().find( |
| 1318 function(d) { | 1284 function(d) { |
| 1319 return d.id == 'BarDevice'; | 1285 return d.id == 'BarDevice'; |
| 1320 }); | 1286 }); |
| 1321 | 1287 |
| 1288 nativeLayer.setLocalDestinationCapabilities( | |
| 1289 getCddTemplate('BarDevice')); | |
| 1322 printPreview.destinationStore_.selectDestination(barDestination); | 1290 printPreview.destinationStore_.selectDestination(barDestination); |
| 1323 | 1291 |
| 1324 // Dispatch events indicating capabilities were fetched and new | 1292 return nativeLayer.whenCalled('getPrinterCapabilities', 'BarDevice') |
| 1325 // preview has loaded. | 1293 .then(function() { |
| 1326 setCapabilities(getCddTemplate('BarDevice')); | 1294 // Dispatch event indicating new preview has loaded. |
| 1327 var previewDoneEvent = new Event( | 1295 var previewDoneEvent = new Event( |
| 1328 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); | 1296 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
| 1329 previewArea.dispatchEvent(previewDoneEvent); | 1297 previewArea.dispatchEvent(previewDoneEvent); |
| 1330 | 1298 |
| 1331 // Has active print button and successfully 'prints', indicating | 1299 // Has active print button and successfully 'prints', indicating |
| 1332 // recovery from error state. | 1300 // recovery from error state. |
| 1333 expectFalse(printButton.disabled); | 1301 expectFalse(printButton.disabled); |
| 1334 expectFalse(nativeLayer.isPrintStarted()); | 1302 expectFalse(nativeLayer.isPrintStarted()); |
| 1335 printButton.click(); | 1303 printButton.click(); |
| 1336 expectTrue(nativeLayer.isPrintStarted()); | 1304 expectTrue(nativeLayer.isPrintStarted()); |
| 1305 }); | |
| 1337 }); | 1306 }); |
| 1338 }); | 1307 }); |
| 1339 | 1308 |
| 1340 // Test the preview generator to make sure the generate draft parameter is | 1309 // Test the preview generator to make sure the generate draft parameter is |
| 1341 // set correctly. It should be false if the only change is the page range. | 1310 // set correctly. It should be false if the only change is the page range. |
| 1342 test('GenerateDraft', function() { | 1311 test('GenerateDraft', function() { |
| 1343 // Use a real preview generator. | 1312 // Use a real preview generator. |
| 1344 previewArea.previewGenerator_ = | 1313 previewArea.previewGenerator_ = |
| 1345 new print_preview.PreviewGenerator(printPreview.destinationStore_, | 1314 new print_preview.PreviewGenerator(printPreview.destinationStore_, |
| 1346 printPreview.printTicketStore_, nativeLayer, | 1315 printPreview.printTicketStore_, nativeLayer, |
| 1347 printPreview.documentInfo_); | 1316 printPreview.documentInfo_); |
| 1348 return setupSettingsAndDestinations().then(function() { | 1317 return setupSettingsAndDestinationsWithCapabilities().then(function() { |
| 1349 setCapabilities(getCddTemplate('FooDevice')); | |
| 1350 | |
| 1351 // The first request should generate draft because there was no | 1318 // The first request should generate draft because there was no |
| 1352 // previous print preview draft. | 1319 // previous print preview draft. |
| 1353 expectTrue(nativeLayer.generateDraft()); | 1320 expectTrue(nativeLayer.generateDraft()); |
| 1354 | 1321 |
| 1355 // Change the page range - no new draft needed. | 1322 // Change the page range - no new draft needed. |
| 1356 printPreview.printTicketStore_.pageRange.updateValue('2'); | 1323 printPreview.printTicketStore_.pageRange.updateValue('2'); |
| 1357 expectFalse(nativeLayer.generateDraft()); | 1324 expectFalse(nativeLayer.generateDraft()); |
| 1358 | 1325 |
| 1359 // Change the margin type - need to regenerate again. | 1326 // Change the margin type - need to regenerate again. |
| 1360 printPreview.printTicketStore_.marginsType.updateValue( | 1327 printPreview.printTicketStore_.marginsType.updateValue( |
| 1361 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); | 1328 print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); |
| 1362 expectTrue(nativeLayer.generateDraft()); | 1329 expectTrue(nativeLayer.generateDraft()); |
| 1363 }); | 1330 }); |
| 1364 }); | 1331 }); |
| 1365 }); | 1332 }); |
| 1366 }); | 1333 }); |
| OLD | NEW |