Chromium Code Reviews| Index: chrome/test/data/webui/print_preview/print_preview_tests.js |
| diff --git a/chrome/test/data/webui/print_preview/print_preview_tests.js b/chrome/test/data/webui/print_preview/print_preview_tests.js |
| index c7277f5be004f6d0e9cddcf915b432df37ad29ac..f36570b56dac45a94eefe01322fed626eeb93b8c 100644 |
| --- a/chrome/test/data/webui/print_preview/print_preview_tests.js |
| +++ b/chrome/test/data/webui/print_preview/print_preview_tests.js |
| @@ -32,8 +32,7 @@ cr.define('print_preview_test', function() { |
| /** |
| * Initialize print preview with the initial settings currently stored in |
| - * |initialSettings|. Creates |printPreview| if it does not |
| - * already exist. |
| + * |initialSettings|. |
| */ |
| function setInitialSettings() { |
| nativeLayer.setInitialSettings(initialSettings); |
| @@ -41,14 +40,12 @@ cr.define('print_preview_test', function() { |
| } |
| /** |
| - * Dispatch the LOCAL_DESTINATIONS_SET event. This call is NOT async and will |
| - * happen in the same thread. |
| + * Start loading the local destinations using the destination infos currently |
| + * stored in |localDestinationInfos|. |
| */ |
| function setLocalDestinations() { |
| - var localDestsSetEvent = |
| - new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET); |
| - localDestsSetEvent.destinationInfos = localDestinationInfos; |
| - nativeLayer.getEventTarget().dispatchEvent(localDestsSetEvent); |
| + nativeLayer.setLocalDestinations(localDestinationInfos); |
| + printPreview.destinationStore_.startLoadLocalDestinations(); |
| } |
| /** |
| @@ -201,11 +198,13 @@ cr.define('print_preview_test', function() { |
| */ |
| function setupAdvancedSettingsTest(device) { |
| setLocalDestinations(); |
| - setCapabilities(device); |
| - expandMoreSettings(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(device); |
| + expandMoreSettings(); |
| - // Check that the advanced options settings section is visible. |
| - checkSectionVisible($('advanced-options-settings'), true); |
| + // Check that the advanced options settings section is visible. |
| + checkSectionVisible($('advanced-options-settings'), true); |
| + }); |
| } |
| /** @return {boolean} */ |
| @@ -263,33 +262,34 @@ cr.define('print_preview_test', function() { |
| // Test some basic assumptions about the print preview WebUI. |
| test('PrinterList', function() { |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - var recentList = |
| - $('destination-search').querySelector('.recent-list ul'); |
| - var localList = |
| - $('destination-search').querySelector('.local-list ul'); |
| - assertNotEquals(null, recentList); |
| - assertEquals(1, recentList.childNodes.length); |
| - assertEquals('FooName', |
| - recentList.childNodes.item(0).querySelector( |
| - '.destination-list-item-name').textContent); |
| - assertNotEquals(null, localList); |
| - assertEquals(3, localList.childNodes.length); |
| - assertEquals( |
| - 'Save as PDF', |
| - localList.childNodes.item(PDF_INDEX). |
| - querySelector('.destination-list-item-name').textContent); |
| - assertEquals( |
| - 'FooName', |
| - localList.childNodes.item(FOO_INDEX). |
| - querySelector('.destination-list-item-name').textContent); |
| - assertEquals( |
| - 'BarName', |
| - localList.childNodes.item(BAR_INDEX). |
| - querySelector('.destination-list-item-name').textContent); |
| - }); |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + setLocalDestinations(); |
| + 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
|
| + var recentList = |
| + $('destination-search').querySelector('.recent-list ul'); |
| + var localList = |
| + $('destination-search').querySelector('.local-list ul'); |
| + assertNotEquals(null, recentList); |
| + assertEquals(1, recentList.childNodes.length); |
| + assertEquals('FooName', |
| + recentList.childNodes.item(0).querySelector( |
| + '.destination-list-item-name').textContent); |
| + assertNotEquals(null, localList); |
| + assertEquals(3, localList.childNodes.length); |
| + assertEquals( |
| + 'Save as PDF', |
| + localList.childNodes.item(PDF_INDEX). |
| + querySelector('.destination-list-item-name').textContent); |
| + assertEquals( |
| + 'FooName', |
| + localList.childNodes.item(FOO_INDEX). |
| + querySelector('.destination-list-item-name').textContent); |
| + assertEquals( |
| + 'BarName', |
| + localList.childNodes.item(BAR_INDEX). |
| + querySelector('.destination-list-item-name').textContent); |
| + }); |
| + }); |
| }); |
| // Test that the printer list is structured correctly after calling |
| @@ -297,57 +297,57 @@ cr.define('print_preview_test', function() { |
| test('PrinterListCloudEmpty', function() { |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - |
| - var cloudPrintEnableEvent = new Event( |
| - print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
| - cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; |
| - nativeLayer.getEventTarget().dispatchEvent( |
| - cloudPrintEnableEvent); |
| - |
| - var searchDoneEvent = |
| - new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); |
| - searchDoneEvent.printers = []; |
| - searchDoneEvent.isRecent = true; |
| - searchDoneEvent.email = 'foo@chromium.org'; |
| - printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent); |
| - |
| - var recentList = |
| - $('destination-search').querySelector('.recent-list ul'); |
| - var localList = |
| - $('destination-search').querySelector('.local-list ul'); |
| - var cloudList = |
| - $('destination-search').querySelector('.cloud-list ul'); |
| - |
| - assertNotEquals(null, recentList); |
| - assertEquals(1, recentList.childNodes.length); |
| - assertEquals('FooName', |
| - recentList.childNodes.item(0). |
| - querySelector('.destination-list-item-name'). |
| - textContent); |
| - |
| - assertNotEquals(null, localList); |
| - assertEquals(3, localList.childNodes.length); |
| - assertEquals('Save as PDF', |
| - localList.childNodes.item(PDF_INDEX). |
| - querySelector('.destination-list-item-name'). |
| - textContent); |
| - assertEquals('FooName', |
| - localList.childNodes. |
| - item(FOO_INDEX). |
| - querySelector('.destination-list-item-name'). |
| - textContent); |
| - assertEquals('BarName', |
| - localList.childNodes. |
| - item(BAR_INDEX). |
| - querySelector('.destination-list-item-name'). |
| - textContent); |
| - |
| - assertNotEquals(null, cloudList); |
| - assertEquals(0, cloudList.childNodes.length); |
| - }); |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var cloudPrintEnableEvent = new Event( |
| + print_preview.NativeLayer.EventType.CLOUD_PRINT_ENABLE); |
| + cloudPrintEnableEvent.baseCloudPrintUrl = 'cloudprint url'; |
| + nativeLayer.getEventTarget().dispatchEvent( |
| + cloudPrintEnableEvent); |
| + |
| + var searchDoneEvent = |
| + new Event(cloudprint.CloudPrintInterfaceEventType.SEARCH_DONE); |
| + searchDoneEvent.printers = []; |
| + searchDoneEvent.isRecent = true; |
| + searchDoneEvent.email = 'foo@chromium.org'; |
| + printPreview.cloudPrintInterface_.dispatchEvent(searchDoneEvent); |
| + |
| + var recentList = |
| + $('destination-search').querySelector('.recent-list ul'); |
| + var localList = |
| + $('destination-search').querySelector('.local-list ul'); |
| + var cloudList = |
| + $('destination-search').querySelector('.cloud-list ul'); |
| + |
| + assertNotEquals(null, recentList); |
| + assertEquals(1, recentList.childNodes.length); |
| + assertEquals('FooName', |
| + recentList.childNodes.item(0). |
| + querySelector('.destination-list-item-name'). |
| + textContent); |
| + |
| + assertNotEquals(null, localList); |
| + assertEquals(3, localList.childNodes.length); |
| + assertEquals('Save as PDF', |
| + localList.childNodes.item(PDF_INDEX). |
| + querySelector('.destination-list-item-name'). |
| + textContent); |
| + assertEquals('FooName', |
| + localList.childNodes. |
| + item(FOO_INDEX). |
| + querySelector('.destination-list-item-name'). |
| + textContent); |
| + assertEquals('BarName', |
| + localList.childNodes. |
| + item(BAR_INDEX). |
| + querySelector('.destination-list-item-name'). |
| + textContent); |
| + |
| + assertNotEquals(null, cloudList); |
| + assertEquals(0, cloudList.childNodes.length); |
| + }); |
| + }); |
| }); |
| // Test restore settings with one destination. |
| @@ -446,14 +446,16 @@ cr.define('print_preview_test', function() { |
| // It also makes sure these rules do override system default destination. |
| initialSettings.serializedDefaultDestinationSelectionRulesStr_ = |
| JSON.stringify({namePattern: '.*Bar.*'}); |
| + // Set this early as the app state selection string will trigger a load |
| + // of local destinations on initialization. |
| + nativeLayer.setLocalDestinations(localDestinationInfos); |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - assertEquals( |
| - 'BarDevice', |
| - printPreview.destinationStore_.selectedDestination.id); |
| - }); |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + assertEquals('BarDevice', |
| + printPreview.destinationStore_.selectedDestination.id); |
| + }); |
| + }); |
| }); |
| test('SystemDialogLinkIsHiddenInAppKioskMode', function() { |
| @@ -476,22 +478,23 @@ cr.define('print_preview_test', function() { |
| checkSectionVisible($('copies-settings'), false); |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.color = { |
| - option: [{is_default: true, type: 'STANDARD_COLOR'}] |
| - }; |
| - delete device.capabilities.printer.copies; |
| - setCapabilities(device); |
| - |
| - checkSectionVisible($('layout-settings'), true); |
| - checkSectionVisible($('color-settings'), false); |
| - checkSectionVisible($('copies-settings'), false); |
| - |
| - return whenAnimationDone('other-options-collapsible'); |
| - }); |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.color = { |
| + option: [{is_default: true, type: 'STANDARD_COLOR'}] |
| + }; |
| + delete device.capabilities.printer.copies; |
| + setCapabilities(device); |
| + |
| + checkSectionVisible($('layout-settings'), true); |
| + checkSectionVisible($('color-settings'), false); |
| + checkSectionVisible($('copies-settings'), false); |
| + |
| + return whenAnimationDone('other-options-collapsible'); |
| + }); |
| + }); |
| }); |
| // When the source is 'PDF' and 'Save as PDF' option is selected, we hide |
| @@ -533,10 +536,9 @@ cr.define('print_preview_test', function() { |
| } |
| }; |
| setCapabilities(device); |
| - |
| var otherOptions = $('other-options-settings'); |
| - // If rasterization is an option, other options should be visible. If |
| - // not, there should be no available other options. |
| + // If rasterization is an option, other options should be visible. |
| + // If not, there should be no available other options. |
| checkSectionVisible(otherOptions, isPrintAsImageEnabled()); |
| if (isPrintAsImageEnabled()) { |
| checkElementDisplayed( |
| @@ -555,34 +557,36 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| - |
| - var otherOptions = $('other-options-settings'); |
| - var fitToPage = otherOptions.querySelector('#fit-to-page-container'); |
| - var rasterize; |
| - if (isPrintAsImageEnabled()) |
| - rasterize = otherOptions.querySelector('#rasterize-container'); |
| - var mediaSize = $('media-size-settings'); |
| - var scalingSettings = $('scaling-settings'); |
| - |
| - // Check that options are collapsed (section is visible, because duplex |
| - // is available). |
| - checkSectionVisible(otherOptions, true); |
| - checkElementDisplayed(fitToPage, false); |
| - if (isPrintAsImageEnabled()) |
| - checkElementDisplayed(rasterize, false); |
| - checkSectionVisible(mediaSize, false); |
| - checkSectionVisible(scalingSettings, false); |
| - |
| - expandMoreSettings(); |
| - |
| - checkElementDisplayed(fitToPage, false); |
| - if (isPrintAsImageEnabled()) |
| - checkElementDisplayed(rasterize, false); |
| - checkSectionVisible(mediaSize, true); |
| - checkSectionVisible(scalingSettings, true); |
| - |
| - return whenAnimationDone('more-settings'); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| + |
| + var otherOptions = $('other-options-settings'); |
| + var fitToPage = otherOptions.querySelector('#fit-to-page-container'); |
| + var rasterize; |
| + if (isPrintAsImageEnabled()) |
| + rasterize = otherOptions.querySelector('#rasterize-container'); |
| + var mediaSize = $('media-size-settings'); |
| + var scalingSettings = $('scaling-settings'); |
| + |
| + // Check that options are collapsed (section is visible, because |
| + // duplex is available). |
| + checkSectionVisible(otherOptions, true); |
| + checkElementDisplayed(fitToPage, false); |
| + if (isPrintAsImageEnabled()) |
| + checkElementDisplayed(rasterize, false); |
| + checkSectionVisible(mediaSize, false); |
| + checkSectionVisible(scalingSettings, false); |
| + |
| + expandMoreSettings(); |
| + |
| + checkElementDisplayed(fitToPage, false); |
| + if (isPrintAsImageEnabled()) |
| + checkElementDisplayed(rasterize, false); |
| + checkSectionVisible(mediaSize, true); |
| + checkSectionVisible(scalingSettings, true); |
| + |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -591,38 +595,39 @@ cr.define('print_preview_test', function() { |
| test('SourceIsPDFCapabilities', function() { |
| initialSettings.isDocumentModifiable_ = false; |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| - |
| - var otherOptions = $('other-options-settings'); |
| - var scalingSettings = $('scaling-settings'); |
| - var fitToPageContainer = |
| - otherOptions.querySelector('#fit-to-page-container'); |
| - var rasterizeContainer; |
| - if (isPrintAsImageEnabled()) { |
| - rasterizeContainer = |
| - otherOptions.querySelector('#rasterize-container'); |
| - } |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| + |
| + var otherOptions = $('other-options-settings'); |
| + var scalingSettings = $('scaling-settings'); |
| + var fitToPageContainer = |
| + otherOptions.querySelector('#fit-to-page-container'); |
| + var rasterizeContainer; |
| + if (isPrintAsImageEnabled()) { |
| + rasterizeContainer = |
| + otherOptions.querySelector('#rasterize-container'); |
| + } |
| - checkSectionVisible(otherOptions, true); |
| - checkElementDisplayed(fitToPageContainer, true); |
| - if (isPrintAsImageEnabled()) |
| - checkElementDisplayed(rasterizeContainer, false); |
| - expectTrue( |
| - fitToPageContainer.querySelector('.checkbox').checked); |
| - expandMoreSettings(); |
| - if (isPrintAsImageEnabled()) { |
| - checkElementDisplayed(rasterizeContainer, true); |
| - expectFalse( |
| - rasterizeContainer.querySelector('.checkbox').checked); |
| - } |
| - checkSectionVisible($('media-size-settings'), true); |
| - checkSectionVisible(scalingSettings, true); |
| + checkSectionVisible(otherOptions, true); |
| + checkElementDisplayed(fitToPageContainer, true); |
| + if (isPrintAsImageEnabled()) |
| + checkElementDisplayed(rasterizeContainer, false); |
| + expectTrue( |
| + fitToPageContainer.querySelector('.checkbox').checked); |
| + expandMoreSettings(); |
| + if (isPrintAsImageEnabled()) { |
| + checkElementDisplayed(rasterizeContainer, true); |
| + expectFalse( |
| + rasterizeContainer.querySelector('.checkbox').checked); |
| + } |
| + checkSectionVisible($('media-size-settings'), true); |
| + checkSectionVisible(scalingSettings, true); |
| - return whenAnimationDone('other-options-collapsible'); |
| - }); |
| + return whenAnimationDone('other-options-collapsible'); |
| + }); |
| + }); |
| }); |
| // When the source is 'PDF', depending on the selected destination printer, |
| @@ -630,40 +635,41 @@ cr.define('print_preview_test', function() { |
| test('ScalingUnchecksFitToPage', function() { |
| initialSettings.isDocumentModifiable_ = false; |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| - |
| - var otherOptions = $('other-options-settings'); |
| - var scalingSettings = $('scaling-settings'); |
| - |
| - checkSectionVisible(otherOptions, true); |
| - var fitToPageContainer = |
| - otherOptions.querySelector('#fit-to-page-container'); |
| - checkElementDisplayed(fitToPageContainer, true); |
| - expectTrue( |
| - fitToPageContainer.querySelector('.checkbox').checked); |
| - expandMoreSettings(); |
| - checkSectionVisible($('media-size-settings'), true); |
| - checkSectionVisible(scalingSettings, true); |
| - |
| - // Change scaling input |
| - var scalingInput = scalingSettings.querySelector('.user-value'); |
| - expectEquals('100', scalingInput.value); |
| - scalingInput.stepUp(5); |
| - expectEquals('105', scalingInput.value); |
| - |
| - // Trigger the event |
| - var enterEvent = document.createEvent('Event'); |
| - enterEvent.initEvent('keydown'); |
| - enterEvent.keyCode = 'Enter'; |
| - scalingInput.dispatchEvent(enterEvent); |
| - expectFalse( |
| - fitToPageContainer.querySelector('.checkbox').checked); |
| - |
| - return whenAnimationDone('other-options-collapsible'); |
| - }); |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| + |
| + var otherOptions = $('other-options-settings'); |
| + var scalingSettings = $('scaling-settings'); |
| + |
| + checkSectionVisible(otherOptions, true); |
| + var fitToPageContainer = |
| + otherOptions.querySelector('#fit-to-page-container'); |
| + checkElementDisplayed(fitToPageContainer, true); |
| + expectTrue( |
| + fitToPageContainer.querySelector('.checkbox').checked); |
| + expandMoreSettings(); |
| + checkSectionVisible($('media-size-settings'), true); |
| + checkSectionVisible(scalingSettings, true); |
| + |
| + // Change scaling input |
| + var scalingInput = scalingSettings.querySelector('.user-value'); |
| + expectEquals('100', scalingInput.value); |
| + scalingInput.stepUp(5); |
| + expectEquals('105', scalingInput.value); |
| + |
| + // Trigger the event |
| + var enterEvent = document.createEvent('Event'); |
| + enterEvent.initEvent('keydown'); |
| + enterEvent.keyCode = 'Enter'; |
| + scalingInput.dispatchEvent(enterEvent); |
| + expectFalse( |
| + fitToPageContainer.querySelector('.checkbox').checked); |
| + |
| + return whenAnimationDone('other-options-collapsible'); |
| + }); |
| + }); |
| }); |
| // When the number of copies print preset is set for source 'PDF', we update |
| @@ -673,26 +679,29 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| - |
| - // Indicate that the number of copies print preset is set for source |
| - // PDF. |
| - var printPresetOptions = { |
| - disableScaling: true, |
| - copies: 2 |
| - }; |
| - var printPresetOptionsEvent = new Event( |
| - print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| - printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| - nativeLayer.getEventTarget(). |
| - dispatchEvent(printPresetOptionsEvent); |
| - |
| - checkSectionVisible($('copies-settings'), true); |
| - expectEquals( |
| - printPresetOptions.copies, |
| - parseInt($('copies-settings').querySelector('.user-value').value)); |
| - |
| - return whenAnimationDone('other-options-collapsible'); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| + |
| + // Indicate that the number of copies print preset is set for source |
| + // PDF. |
| + var printPresetOptions = { |
| + disableScaling: true, |
| + copies: 2 |
| + }; |
| + var printPresetOptionsEvent = new Event( |
| + print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| + printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| + nativeLayer.getEventTarget(). |
| + dispatchEvent(printPresetOptionsEvent); |
| + |
| + checkSectionVisible($('copies-settings'), true); |
| + expectEquals( |
| + printPresetOptions.copies, |
| + parseInt($('copies-settings'). |
| + querySelector('.user-value').value)); |
| + |
| + return whenAnimationDone('other-options-collapsible'); |
| + }); |
| }); |
| }); |
| @@ -702,86 +711,89 @@ cr.define('print_preview_test', function() { |
| initialSettings.isDocumentModifiable_ = false; |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| - |
| - // Indicate that the duplex print preset is set to 'long edge' for |
| - // source PDF. |
| - var printPresetOptions = { |
| - duplex: 1 |
| - }; |
| - var printPresetOptionsEvent = new Event( |
| - print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| - printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| - nativeLayer.getEventTarget(). |
| - dispatchEvent(printPresetOptionsEvent); |
| - |
| - var otherOptions = $('other-options-settings'); |
| - checkSectionVisible(otherOptions, true); |
| - var duplexContainer = |
| - otherOptions.querySelector('#duplex-container'); |
| - checkElementDisplayed(duplexContainer, true); |
| - expectTrue(duplexContainer.querySelector('.checkbox').checked); |
| - |
| - return whenAnimationDone('other-options-collapsible'); |
| - }); |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| + |
| + // Indicate that the duplex print preset is set to 'long edge' for |
| + // source PDF. |
| + var printPresetOptions = { |
| + duplex: 1 |
| + }; |
| + var printPresetOptionsEvent = new Event( |
| + print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| + printPresetOptionsEvent.optionsFromDocument = printPresetOptions; |
| + nativeLayer.getEventTarget(). |
| + dispatchEvent(printPresetOptionsEvent); |
| + |
| + var otherOptions = $('other-options-settings'); |
| + checkSectionVisible(otherOptions, true); |
| + var duplexContainer = |
| + otherOptions.querySelector('#duplex-container'); |
| + checkElementDisplayed(duplexContainer, true); |
| + expectTrue(duplexContainer.querySelector('.checkbox').checked); |
| + |
| + return whenAnimationDone('other-options-collapsible'); |
| + }); |
| + }); |
| }); |
| // Make sure that custom margins controls are properly set up. |
| test('CustomMarginsControlsCheck', function() { |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| - |
| - printPreview.printTicketStore_.marginsType.updateValue( |
| - print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| - |
| - ['left', 'top', 'right', 'bottom'].forEach(function(margin) { |
| - var control = |
| - $('preview-area').querySelector('.margin-control-' + margin); |
| - assertNotEquals(null, control); |
| - var input = control.querySelector('.margin-control-textbox'); |
| - assertTrue(input.hasAttribute('aria-label')); |
| - assertNotEquals('undefined', input.getAttribute('aria-label')); |
| - }); |
| - return whenAnimationDone('more-settings'); |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| + |
| + printPreview.printTicketStore_.marginsType.updateValue( |
| + print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| + |
| + ['left', 'top', 'right', 'bottom'].forEach(function(margin) { |
| + var control = |
| + $('preview-area').querySelector('.margin-control-' + margin); |
| + assertNotEquals(null, control); |
| + var input = control.querySelector('.margin-control-textbox'); |
| + assertTrue(input.hasAttribute('aria-label')); |
| + assertNotEquals('undefined', input.getAttribute('aria-label')); |
| }); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| + }); |
| }); |
| // Page layout has zero margins. Hide header and footer option. |
| test('PageLayoutHasNoMarginsHideHeaderFooter', function() { |
| setInitialSettings(); |
| - return nativeLayer.whenCalled('getInitialSettings').then( |
| - function() { |
| - setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| + return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| + setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| - var otherOptions = $('other-options-settings'); |
| - var headerFooter = |
| - otherOptions.querySelector('#header-footer-container'); |
| + var otherOptions = $('other-options-settings'); |
| + var headerFooter = |
| + otherOptions.querySelector('#header-footer-container'); |
| - // Check that options are collapsed (section is visible, because |
| - // duplex is available). |
| - checkSectionVisible(otherOptions, true); |
| - checkElementDisplayed(headerFooter, false); |
| + // Check that options are collapsed (section is visible, because |
| + // duplex is available). |
| + checkSectionVisible(otherOptions, true); |
| + checkElementDisplayed(headerFooter, false); |
| - expandMoreSettings(); |
| + expandMoreSettings(); |
| - checkElementDisplayed(headerFooter, true); |
| + checkElementDisplayed(headerFooter, true); |
| - printPreview.printTicketStore_.marginsType.updateValue( |
| - print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| - printPreview.printTicketStore_.customMargins.updateValue( |
| - new print_preview.Margins(0, 0, 0, 0)); |
| + printPreview.printTicketStore_.marginsType.updateValue( |
| + print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| + printPreview.printTicketStore_.customMargins.updateValue( |
| + new print_preview.Margins(0, 0, 0, 0)); |
| - checkElementDisplayed(headerFooter, false); |
| + checkElementDisplayed(headerFooter, false); |
| - return whenAnimationDone('more-settings'); |
| - }); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| + }); |
| }); |
| // Page layout has half-inch margins. Show header and footer option. |
| @@ -789,62 +801,65 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| - var otherOptions = $('other-options-settings'); |
| - var headerFooter = |
| - otherOptions.querySelector('#header-footer-container'); |
| + var otherOptions = $('other-options-settings'); |
| + var headerFooter = |
| + otherOptions.querySelector('#header-footer-container'); |
| - // Check that options are collapsed (section is visible, because |
| - // duplex is available). |
| - checkSectionVisible(otherOptions, true); |
| - checkElementDisplayed(headerFooter, false); |
| + // Check that options are collapsed (section is visible, because |
| + // duplex is available). |
| + checkSectionVisible(otherOptions, true); |
| + checkElementDisplayed(headerFooter, false); |
| - expandMoreSettings(); |
| + expandMoreSettings(); |
| - checkElementDisplayed(headerFooter, true); |
| + checkElementDisplayed(headerFooter, true); |
| - printPreview.printTicketStore_.marginsType.updateValue( |
| - print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| - printPreview.printTicketStore_.customMargins.updateValue( |
| - new print_preview.Margins(36, 36, 36, 36)); |
| + printPreview.printTicketStore_.marginsType.updateValue( |
| + print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| + printPreview.printTicketStore_.customMargins.updateValue( |
| + new print_preview.Margins(36, 36, 36, 36)); |
| - checkElementDisplayed(headerFooter, true); |
| + checkElementDisplayed(headerFooter, true); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| - |
| // Page layout has zero top and bottom margins. Hide header and footer |
| // option. |
| test('ZeroTopAndBottomMarginsHideHeaderFooter', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| - var otherOptions = $('other-options-settings'); |
| - var headerFooter = |
| - otherOptions.querySelector('#header-footer-container'); |
| + var otherOptions = $('other-options-settings'); |
| + var headerFooter = |
| + otherOptions.querySelector('#header-footer-container'); |
| - // Check that options are collapsed (section is visible, because duplex |
| - // is available). |
| - checkSectionVisible(otherOptions, true); |
| - checkElementDisplayed(headerFooter, false); |
| + // Check that options are collapsed (section is visible, because |
| + // duplex is available). |
| + checkSectionVisible(otherOptions, true); |
| + checkElementDisplayed(headerFooter, false); |
| - expandMoreSettings(); |
| + expandMoreSettings(); |
| - checkElementDisplayed(headerFooter, true); |
| + checkElementDisplayed(headerFooter, true); |
| - printPreview.printTicketStore_.marginsType.updateValue( |
| - print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| - printPreview.printTicketStore_.customMargins.updateValue( |
| - new print_preview.Margins(0, 36, 0, 36)); |
| + printPreview.printTicketStore_.marginsType.updateValue( |
| + print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| + printPreview.printTicketStore_.customMargins.updateValue( |
| + new print_preview.Margins(0, 36, 0, 36)); |
| - checkElementDisplayed(headerFooter, false); |
| + checkElementDisplayed(headerFooter, false); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -854,29 +869,31 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| - var otherOptions = $('other-options-settings'); |
| - var headerFooter = |
| - otherOptions.querySelector('#header-footer-container'); |
| + var otherOptions = $('other-options-settings'); |
| + var headerFooter = |
| + otherOptions.querySelector('#header-footer-container'); |
| - // Check that options are collapsed (section is visible, because duplex |
| - // is available). |
| - checkSectionVisible(otherOptions, true); |
| - checkElementDisplayed(headerFooter, false); |
| + // Check that options are collapsed (section is visible, because |
| + // duplex is available). |
| + checkSectionVisible(otherOptions, true); |
| + checkElementDisplayed(headerFooter, false); |
| - expandMoreSettings(); |
| + expandMoreSettings(); |
| - checkElementDisplayed(headerFooter, true); |
| + checkElementDisplayed(headerFooter, true); |
| - printPreview.printTicketStore_.marginsType.updateValue( |
| - print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| - printPreview.printTicketStore_.customMargins.updateValue( |
| - new print_preview.Margins(0, 36, 36, 36)); |
| + printPreview.printTicketStore_.marginsType.updateValue( |
| + print_preview.ticket_items.MarginsTypeValue.CUSTOM); |
| + printPreview.printTicketStore_.customMargins.updateValue( |
| + new print_preview.Margins(0, 36, 36, 36)); |
| - checkElementDisplayed(headerFooter, true); |
| + checkElementDisplayed(headerFooter, true); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -885,42 +902,44 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.media_size = { |
| - 'option': [ |
| - {'name': 'SmallLabel', 'width_microns': 38100, |
| - 'height_microns': 12700, 'is_default': false}, |
| - {'name': 'BigLabel', 'width_microns': 50800, |
| - 'height_microns': 76200, 'is_default': true} |
| - ] |
| - }; |
| - setCapabilities(device); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.media_size = { |
| + 'option': [ |
| + {'name': 'SmallLabel', 'width_microns': 38100, |
| + 'height_microns': 12700, 'is_default': false}, |
| + {'name': 'BigLabel', 'width_microns': 50800, |
| + 'height_microns': 76200, 'is_default': true} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - var otherOptions = $('other-options-settings'); |
| - var headerFooter = |
| - otherOptions.querySelector('#header-footer-container'); |
| + var otherOptions = $('other-options-settings'); |
| + var headerFooter = |
| + otherOptions.querySelector('#header-footer-container'); |
| - // Check that options are collapsed (section is visible, because duplex |
| - // is available). |
| - checkSectionVisible(otherOptions, true); |
| - checkElementDisplayed(headerFooter, false); |
| + // Check that options are collapsed (section is visible, because |
| + // duplex is available). |
| + checkSectionVisible(otherOptions, true); |
| + checkElementDisplayed(headerFooter, false); |
| - expandMoreSettings(); |
| + expandMoreSettings(); |
| - // Big label should have header/footer |
| - checkElementDisplayed(headerFooter, true); |
| + // Big label should have header/footer |
| + checkElementDisplayed(headerFooter, true); |
| - // Small label should not |
| - printPreview.printTicketStore_.mediaSize.updateValue( |
| - device.capabilities.printer.media_size.option[0]); |
| - checkElementDisplayed(headerFooter, false); |
| + // Small label should not |
| + printPreview.printTicketStore_.mediaSize.updateValue( |
| + device.capabilities.printer.media_size.option[0]); |
| + checkElementDisplayed(headerFooter, false); |
| - // Oriented in landscape, there should be enough space for |
| - // header/footer. |
| - printPreview.printTicketStore_.landscape.updateValue(true); |
| - checkElementDisplayed(headerFooter, true); |
| + // Oriented in landscape, there should be enough space for |
| + // header/footer. |
| + printPreview.printTicketStore_.landscape.updateValue(true); |
| + checkElementDisplayed(headerFooter, true); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -929,19 +948,20 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + // Only one option, standard monochrome. |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.color = { |
| + 'option': [ |
| + {'is_default': true, 'type': 'STANDARD_MONOCHROME'} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - // Only one option, standard monochrome. |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.color = { |
| - 'option': [ |
| - {'is_default': true, 'type': 'STANDARD_MONOCHROME'} |
| - ] |
| - }; |
| - setCapabilities(device); |
| - |
| - checkSectionVisible($('color-settings'), false); |
| + checkSectionVisible($('color-settings'), false); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -950,20 +970,21 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + // Only one option, standard monochrome. |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.color = { |
| + 'option': [ |
| + {'is_default': true, 'type': 'CUSTOM_MONOCHROME', |
| + 'vendor_id': '42'} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - // Only one option, standard monochrome. |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.color = { |
| - 'option': [ |
| - {'is_default': true, 'type': 'CUSTOM_MONOCHROME', |
| - 'vendor_id': '42'} |
| - ] |
| - }; |
| - setCapabilities(device); |
| - |
| - checkSectionVisible($('color-settings'), false); |
| + checkSectionVisible($('color-settings'), false); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -972,18 +993,19 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.color = { |
| + 'option': [ |
| + {'is_default': true, 'type': 'STANDARD_COLOR'} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.color = { |
| - 'option': [ |
| - {'is_default': true, 'type': 'STANDARD_COLOR'} |
| - ] |
| - }; |
| - setCapabilities(device); |
| - |
| - checkSectionVisible($('color-settings'), false); |
| + checkSectionVisible($('color-settings'), false); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -992,18 +1014,19 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.color = { |
| + 'option': [ |
| + {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.color = { |
| - 'option': [ |
| - {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '42'} |
| - ] |
| - }; |
| - setCapabilities(device); |
| - |
| - checkSectionVisible($('color-settings'), false); |
| + checkSectionVisible($('color-settings'), false); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1013,22 +1036,24 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.color = { |
| + 'option': [ |
| + {'type': 'STANDARD_MONOCHROME'}, |
| + {'is_default': true, 'type': 'STANDARD_COLOR'} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.color = { |
| - 'option': [ |
| - {'type': 'STANDARD_MONOCHROME'}, |
| - {'is_default': true, 'type': 'STANDARD_COLOR'} |
| - ] |
| - }; |
| - setCapabilities(device); |
| - |
| - checkSectionVisible($('color-settings'), true); |
| - expectEquals( |
| - 'color', |
| - $('color-settings').querySelector('.color-settings-select').value); |
| + checkSectionVisible($('color-settings'), true); |
| + expectEquals( |
| + 'color', |
| + $('color-settings').querySelector( |
| + '.color-settings-select').value); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1038,22 +1063,24 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.color = { |
| + 'option': [ |
| + {'is_default': true, 'type': 'STANDARD_MONOCHROME'}, |
| + {'type': 'STANDARD_COLOR'} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.color = { |
| - 'option': [ |
| - {'is_default': true, 'type': 'STANDARD_MONOCHROME'}, |
| - {'type': 'STANDARD_COLOR'} |
| - ] |
| - }; |
| - setCapabilities(device); |
| - |
| - checkSectionVisible($('color-settings'), true); |
| - expectEquals( |
| - 'bw', |
| - $('color-settings').querySelector('.color-settings-select').value); |
| + checkSectionVisible($('color-settings'), true); |
| + expectEquals( |
| + 'bw', |
| + $('color-settings').querySelector( |
| + '.color-settings-select').value); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1063,23 +1090,24 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.color = { |
| + 'option': [ |
| + {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'}, |
| + {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.color = { |
| - 'option': [ |
| - {'type': 'CUSTOM_MONOCHROME', 'vendor_id': '42'}, |
| - {'is_default': true, 'type': 'CUSTOM_COLOR', 'vendor_id': '43'} |
| - ] |
| - }; |
| - setCapabilities(device); |
| - |
| - checkSectionVisible($('color-settings'), true); |
| - expectEquals( |
| - 'color', |
| - $('color-settings').querySelector( |
| - '.color-settings-select').value); |
| + checkSectionVisible($('color-settings'), true); |
| + expectEquals( |
| + 'color', |
| + $('color-settings').querySelector( |
| + '.color-settings-select').value); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1089,15 +1117,17 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| - var otherOptions = $('other-options-settings'); |
| - checkSectionVisible(otherOptions, true); |
| - duplexContainer = otherOptions.querySelector('#duplex-container'); |
| - expectFalse(duplexContainer.hidden); |
| - expectFalse(duplexContainer.querySelector('.checkbox').checked); |
| + var otherOptions = $('other-options-settings'); |
| + checkSectionVisible(otherOptions, true); |
| + duplexContainer = otherOptions.querySelector('#duplex-container'); |
| + expectFalse(duplexContainer.hidden); |
| + expectFalse(duplexContainer.querySelector('.checkbox').checked); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1107,21 +1137,23 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - var device = getCddTemplate('FooDevice'); |
| - delete device.capabilities.printer.duplex; |
| - setCapabilities(device); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var device = getCddTemplate('FooDevice'); |
| + delete device.capabilities.printer.duplex; |
| + setCapabilities(device); |
| - // Check that it is collapsed. |
| - var otherOptions = $('other-options-settings'); |
| - checkSectionVisible(otherOptions, false); |
| + // Check that it is collapsed. |
| + var otherOptions = $('other-options-settings'); |
| + checkSectionVisible(otherOptions, false); |
| - expandMoreSettings(); |
| + expandMoreSettings(); |
| - // Now it should be visible. |
| - checkSectionVisible(otherOptions, true); |
| - expectTrue(otherOptions.querySelector('#duplex-container').hidden); |
| + // Now it should be visible. |
| + checkSectionVisible(otherOptions, true); |
| + expectTrue(otherOptions.querySelector('#duplex-container').hidden); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1130,32 +1162,34 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| - var previewGenerator = mock(print_preview.PreviewGenerator); |
| - previewArea.previewGenerator_ = previewGenerator.proxy(); |
| + var previewGenerator = mock(print_preview.PreviewGenerator); |
| + previewArea.previewGenerator_ = previewGenerator.proxy(); |
| - // The number of settings that can change due to a change in the |
| - // destination that will therefore dispatch ticket item change events. |
| - previewGenerator.expects(exactly(9)).requestPreview(); |
| + // The number of settings that can change due to a change in the |
| + // destination that will therefore dispatch ticket item change events. |
| + previewGenerator.expects(exactly(9)).requestPreview(); |
| - var barDestination = |
| - printPreview.destinationStore_.destinations().find( |
| - function(d) { |
| - return d.id == 'BarDevice'; |
| - }); |
| + var barDestination = |
| + printPreview.destinationStore_.destinations().find( |
| + function(d) { |
| + return d.id == 'BarDevice'; |
| + }); |
| - printPreview.destinationStore_.selectDestination(barDestination); |
| + printPreview.destinationStore_.selectDestination(barDestination); |
| - var device = getCddTemplate('BarDevice'); |
| - device.capabilities.printer.color = { |
| - 'option': [ |
| - {'is_default': true, 'type': 'STANDARD_MONOCHROME'} |
| - ] |
| - }; |
| - setCapabilities(device); |
| + var device = getCddTemplate('BarDevice'); |
| + device.capabilities.printer.color = { |
| + 'option': [ |
| + {'is_default': true, 'type': 'STANDARD_MONOCHROME'} |
| + ] |
| + }; |
| + setCapabilities(device); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1191,48 +1225,49 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + var customLocalizedMediaName = 'Vendor defined localized media name'; |
| + var customMediaName = 'Vendor defined media name'; |
| - var customLocalizedMediaName = 'Vendor defined localized media name'; |
| - var customMediaName = 'Vendor defined media name'; |
| - |
| - var device = getCddTemplate('FooDevice'); |
| - device.capabilities.printer.media_size = { |
| - option: [ |
| - { name: 'CUSTOM', |
| - width_microns: 15900, |
| - height_microns: 79400, |
| - is_default: true, |
| - custom_display_name_localized: [ |
| - { locale: navigator.language, |
| - value: customLocalizedMediaName |
| - } |
| - ] |
| - }, |
| - { name: 'CUSTOM', |
| - width_microns: 15900, |
| - height_microns: 79400, |
| - custom_display_name: customMediaName |
| - } |
| - ] |
| - }; |
| + var device = getCddTemplate('FooDevice'); |
| + device.capabilities.printer.media_size = { |
| + option: [ |
| + { name: 'CUSTOM', |
| + width_microns: 15900, |
| + height_microns: 79400, |
| + is_default: true, |
| + custom_display_name_localized: [ |
| + { locale: navigator.language, |
| + value: customLocalizedMediaName |
| + } |
| + ] |
| + }, |
| + { name: 'CUSTOM', |
| + width_microns: 15900, |
| + height_microns: 79400, |
| + custom_display_name: customMediaName |
| + } |
| + ] |
| + }; |
| - setCapabilities(device); |
| + setCapabilities(device); |
| + |
| + expandMoreSettings(); |
| + |
| + checkSectionVisible($('media-size-settings'), true); |
| + var mediaSelect = |
| + $('media-size-settings').querySelector('.settings-select'); |
| + // Check the default media item. |
| + expectEquals( |
| + customLocalizedMediaName, |
| + mediaSelect.options[mediaSelect.selectedIndex].text); |
| + // Check the other media item. |
| + expectEquals( |
| + customMediaName, |
| + mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); |
| - expandMoreSettings(); |
| - |
| - checkSectionVisible($('media-size-settings'), true); |
| - var mediaSelect = |
| - $('media-size-settings').querySelector('.settings-select'); |
| - // Check the default media item. |
| - expectEquals( |
| - customLocalizedMediaName, |
| - mediaSelect.options[mediaSelect.selectedIndex].text); |
| - // Check the other media item. |
| - expectEquals( |
| - customMediaName, |
| - mediaSelect.options[mediaSelect.selectedIndex == 0 ? 1 : 0].text); |
| - |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1242,20 +1277,21 @@ cr.define('print_preview_test', function() { |
| var device = getCddTemplateWithAdvancedSettings('FooDevice'); |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| - setupAdvancedSettingsTest(device); |
| + return setupAdvancedSettingsTest(device).then(function() { |
| - // Open the advanced settings overlay. |
| - openAdvancedSettings(); |
| + // Open the advanced settings overlay. |
| + openAdvancedSettings(); |
| - // Check that advanced settings close button is now visible, |
| - // but not the search box (only 1 capability). |
| - var advancedSettingsCloseButton = $('advanced-settings'). |
| - querySelector('.close-button'); |
| - checkElementDisplayed(advancedSettingsCloseButton, true); |
| - checkElementDisplayed($('advanced-settings'). |
| - querySelector('.search-box-area'), false); |
| + // Check that advanced settings close button is now visible, |
| + // but not the search box (only 1 capability). |
| + var advancedSettingsCloseButton = $('advanced-settings'). |
| + querySelector('.close-button'); |
| + checkElementDisplayed(advancedSettingsCloseButton, true); |
| + checkElementDisplayed($('advanced-settings'). |
| + querySelector('.search-box-area'), false); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1279,20 +1315,20 @@ cr.define('print_preview_test', function() { |
| }); |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| - setupAdvancedSettingsTest(device); |
| - |
| - // Open the advanced settings overlay. |
| - openAdvancedSettings(); |
| + return setupAdvancedSettingsTest(device).then(function() { |
| + // Open the advanced settings overlay. |
| + openAdvancedSettings(); |
| - // Check advanced settings is visible and that the search box now |
| - // appears. |
| - var advancedSettingsCloseButton = $('advanced-settings'). |
| - querySelector('.close-button'); |
| - checkElementDisplayed(advancedSettingsCloseButton, true); |
| - checkElementDisplayed($('advanced-settings'). |
| - querySelector('.search-box-area'), true); |
| + // Check advanced settings is visible and that the search box now |
| + // appears. |
| + var advancedSettingsCloseButton = $('advanced-settings'). |
| + querySelector('.close-button'); |
| + checkElementDisplayed(advancedSettingsCloseButton, true); |
| + checkElementDisplayed($('advanced-settings'). |
| + querySelector('.search-box-area'), true); |
| - return whenAnimationDone('more-settings'); |
| + return whenAnimationDone('more-settings'); |
| + }); |
| }); |
| }); |
| @@ -1340,62 +1376,67 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| - |
| - // Manually enable the print header. This is needed since there is no |
| - // plugin during test, so it will be set as disabled normally. |
| - printPreview.printHeader_.isEnabled = true; |
| - |
| - // There will be an error message in the preview area since the plugin |
| - // is not running. However, it should not be the invalid settings error. |
| - var previewAreaEl = $('preview-area'); |
| - var customMessageEl = |
| - previewAreaEl. |
| - getElementsByClassName('preview-area-custom-message')[0]; |
| - expectFalse(customMessageEl.hidden); |
| - var expectedMessageStart = 'The selected printer is not available or ' |
| - + 'not installed correctly.' |
| - expectFalse(customMessageEl.textContent.includes(expectedMessageStart)); |
| - |
| - // Verify that the print button is enabled. |
| - var printHeader = $('print-header'); |
| - var printButton = printHeader.querySelector('button.print'); |
| - checkElementDisplayed(printButton, true); |
| - expectFalse(printButton.disabled); |
| - |
| - // Report invalid settings error. |
| - var invalidSettingsEvent = |
| - new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); |
| - nativeLayer.getEventTarget().dispatchEvent(invalidSettingsEvent); |
| - |
| - // Should be in an error state, print button disabled, invalid custom |
| - // error message shown. |
| - expectFalse(customMessageEl.hidden); |
| - expectTrue(customMessageEl.textContent.includes(expectedMessageStart)); |
| - expectTrue(printButton.disabled); |
| - |
| - // Select a new destination |
| - var barDestination = |
| - printPreview.destinationStore_.destinations().find( |
| - function(d) { |
| - return d.id == 'BarDevice'; |
| - }); |
| - |
| - printPreview.destinationStore_.selectDestination(barDestination); |
| - |
| - // Dispatch events indicating capabilities were fetched and new preview |
| - // has loaded. |
| - setCapabilities(getCddTemplate('BarDevice')); |
| - var previewDoneEvent = new Event( |
| - print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
| - previewArea.dispatchEvent(previewDoneEvent); |
| - |
| - // Has active print button and successfully 'prints', indicating |
| - // recovery from error state. |
| - expectFalse(printButton.disabled); |
| - expectFalse(nativeLayer.isPrintStarted()); |
| - printButton.click(); |
| - expectTrue(nativeLayer.isPrintStarted()); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| + |
| + // Manually enable the print header. This is needed since there is no |
| + // plugin during test, so it will be set as disabled normally. |
| + printPreview.printHeader_.isEnabled = true; |
| + |
| + // There will be an error message in the preview area since the plugin |
| + // is not running. However, it should not be the invalid settings |
| + // error. |
| + var previewAreaEl = $('preview-area'); |
| + var customMessageEl = |
| + previewAreaEl. |
| + getElementsByClassName('preview-area-custom-message')[0]; |
| + expectFalse(customMessageEl.hidden); |
| + var expectedMessageStart = 'The selected printer is not available or ' |
| + + 'not installed correctly.' |
| + expectFalse(customMessageEl.textContent.includes( |
| + expectedMessageStart)); |
| + |
| + // Verify that the print button is enabled. |
| + var printHeader = $('print-header'); |
| + var printButton = printHeader.querySelector('button.print'); |
| + checkElementDisplayed(printButton, true); |
| + expectFalse(printButton.disabled); |
| + |
| + // Report invalid settings error. |
| + var invalidSettingsEvent = |
| + new Event(print_preview.NativeLayer.EventType.SETTINGS_INVALID); |
| + nativeLayer.getEventTarget().dispatchEvent(invalidSettingsEvent); |
| + |
| + // Should be in an error state, print button disabled, invalid custom |
| + // error message shown. |
| + expectFalse(customMessageEl.hidden); |
| + expectTrue(customMessageEl.textContent.includes( |
| + expectedMessageStart)); |
| + expectTrue(printButton.disabled); |
| + |
| + // Select a new destination |
| + var barDestination = |
| + printPreview.destinationStore_.destinations().find( |
| + function(d) { |
| + return d.id == 'BarDevice'; |
| + }); |
| + |
| + printPreview.destinationStore_.selectDestination(barDestination); |
| + |
| + // Dispatch events indicating capabilities were fetched and new |
| + // preview has loaded. |
| + setCapabilities(getCddTemplate('BarDevice')); |
| + var previewDoneEvent = new Event( |
| + print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
| + previewArea.dispatchEvent(previewDoneEvent); |
| + |
| + // Has active print button and successfully 'prints', indicating |
| + // recovery from error state. |
| + expectFalse(printButton.disabled); |
| + expectFalse(nativeLayer.isPrintStarted()); |
| + printButton.click(); |
| + expectTrue(nativeLayer.isPrintStarted()); |
| + }); |
| }); |
| }); |
| @@ -1411,20 +1452,22 @@ cr.define('print_preview_test', function() { |
| setInitialSettings(); |
| return nativeLayer.whenCalled('getInitialSettings').then(function() { |
| setLocalDestinations(); |
| - setCapabilities(getCddTemplate('FooDevice')); |
| - |
| - // The first request should generate draft because there was no |
| - // previous print preview draft. |
| - expectTrue(nativeLayer.generateDraft()); |
| - |
| - // Change the page range - no new draft needed. |
| - printPreview.printTicketStore_.pageRange.updateValue('2'); |
| - expectFalse(nativeLayer.generateDraft()); |
| - |
| - // Change the margin type - need to regenerate again. |
| - printPreview.printTicketStore_.marginsType.updateValue( |
| - print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); |
| - expectTrue(nativeLayer.generateDraft()); |
| + return nativeLayer.whenCalled('getPrinters').then(function() { |
| + setCapabilities(getCddTemplate('FooDevice')); |
| + |
| + // The first request should generate draft because there was no |
| + // previous print preview draft. |
| + expectTrue(nativeLayer.generateDraft()); |
| + |
| + // Change the page range - no new draft needed. |
| + printPreview.printTicketStore_.pageRange.updateValue('2'); |
| + expectFalse(nativeLayer.generateDraft()); |
| + |
| + // Change the margin type - need to regenerate again. |
| + printPreview.printTicketStore_.marginsType.updateValue( |
| + print_preview.ticket_items.MarginsTypeValue.NO_MARGINS); |
| + expectTrue(nativeLayer.generateDraft()); |
| + }); |
| }); |
| }); |
| }); |