Commit c1665b3a authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Finish removing global Javascript functions.

Remove remaining global javascript functions from the print preview
native layer and convert to sendWithPromise and web UI events.

BUG=717296
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2969383003
Cr-Commit-Position: refs/heads/master@{#485430}
parent 09ac01b3
...@@ -177,7 +177,6 @@ cr.define('print_preview', function() { ...@@ -177,7 +177,6 @@ cr.define('print_preview', function() {
this.useSystemDefaultAsDefault_ = this.useSystemDefaultAsDefault_ =
loadTimeData.getBoolean('useSystemDefaultPrinter'); loadTimeData.getBoolean('useSystemDefaultPrinter');
this.addEventListeners_();
this.reset_(); this.reset_();
} }
...@@ -545,6 +544,22 @@ cr.define('print_preview', function() { ...@@ -545,6 +544,22 @@ cr.define('print_preview', function() {
this.cloudPrintInterface_.isCloudDestinationSearchInProgress; this.cloudPrintInterface_.isCloudDestinationSearchInProgress;
}, },
/**
* Starts listening for relevant WebUI events and adds the listeners to
* |listenerTracker|. |listenerTracker| is responsible for removing the
* listeners when necessary.
* @param {!WebUIListenerTracker} listenerTracker
*/
addWebUIEventListeners: function(listenerTracker) {
listenerTracker.add(
'privet-printer-added', this.onPrivetPrinterAdded_.bind(this));
listenerTracker.add(
'extension-printers-added',
this.onExtensionPrintersAdded_.bind(this));
listenerTracker.add(
'reload-printer-list', this.onDestinationsReload.bind(this));
},
/** /**
* Initializes the destination store. Sets the initially selected * Initializes the destination store. Sets the initially selected
* destination. If any inserted destinations match this ID, that destination * destination. If any inserted destinations match this ID, that destination
...@@ -1179,8 +1194,8 @@ cr.define('print_preview', function() { ...@@ -1179,8 +1194,8 @@ cr.define('print_preview', function() {
* @param {?print_preview.Destination} destination Information about the * @param {?print_preview.Destination} destination Information about the
* destination if it was resolved successfully. * destination if it was resolved successfully.
*/ */
dispatchProvisionalDestinationResolvedEvent_: function(provisionalId, dispatchProvisionalDestinationResolvedEvent_: function(
destination) { provisionalId, destination) {
var event = new Event( var event = new Event(
DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED); DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED);
event.provisionalId = provisionalId; event.provisionalId = provisionalId;
...@@ -1332,18 +1347,6 @@ cr.define('print_preview', function() { ...@@ -1332,18 +1347,6 @@ cr.define('print_preview', function() {
} }
}, },
/**
* Binds handlers to events.
* @private
*/
addEventListeners_: function() {
var nativeLayerEventTarget = this.nativeLayer_.getEventTarget();
this.tracker_.add(
nativeLayerEventTarget,
print_preview.NativeLayer.EventType.DESTINATIONS_RELOAD,
this.onDestinationsReload_.bind(this));
},
/** /**
* Creates a local PDF print destination. * Creates a local PDF print destination.
* @private * @private
...@@ -1549,7 +1552,7 @@ cr.define('print_preview', function() { ...@@ -1549,7 +1552,7 @@ cr.define('print_preview', function() {
if (printer.serviceName == this.waitForRegisterDestination_ && if (printer.serviceName == this.waitForRegisterDestination_ &&
!printer.isUnregistered) { !printer.isUnregistered) {
this.waitForRegisterDestination_ = null; this.waitForRegisterDestination_ = null;
this.onDestinationsReload_(); this.onDestinationsReload();
} else { } else {
this.insertDestinations_( this.insertDestinations_(
print_preview.PrivetDestinationParser.parse(printer)); print_preview.PrivetDestinationParser.parse(printer));
...@@ -1617,11 +1620,10 @@ cr.define('print_preview', function() { ...@@ -1617,11 +1620,10 @@ cr.define('print_preview', function() {
}, },
/** /**
* Called from native layer after the user was requested to sign in, and did * Called from print preview after the user was requested to sign in, and
* so successfully. * did so successfully.
* @private
*/ */
onDestinationsReload_: function() { onDestinationsReload: function() {
this.reset_(); this.reset_();
this.autoSelectMatchingDestination_ = this.autoSelectMatchingDestination_ =
this.convertPreselectedToDestinationMatch_(); this.convertPreselectedToDestinationMatch_();
......
...@@ -85,19 +85,6 @@ cr.define('print_preview', function() { ...@@ -85,19 +85,6 @@ cr.define('print_preview', function() {
* @constructor * @constructor
*/ */
function NativeLayer() { function NativeLayer() {
// Bind global handlers
global.reloadPrintersList = this.onReloadPrintersList_.bind(this);
global.onDidGetDefaultPageLayout =
this.onDidGetDefaultPageLayout_.bind(this);
global.onDidGetPreviewPageCount = this.onDidGetPreviewPageCount_.bind(this);
global.onDidPreviewPage = this.onDidPreviewPage_.bind(this);
global.onEnableManipulateSettingsForTest =
this.onEnableManipulateSettingsForTest_.bind(this);
global.printPresetOptionsFromDocument =
this.onPrintPresetOptionsFromDocument_.bind(this);
/** @private {!cr.EventTarget} */
this.eventTarget_ = new cr.EventTarget();
} }
/** @private {?print_preview.NativeLayer} */ /** @private {?print_preview.NativeLayer} */
...@@ -121,27 +108,6 @@ cr.define('print_preview', function() { ...@@ -121,27 +108,6 @@ cr.define('print_preview', function() {
currentInstance = instance; currentInstance = instance;
}; };
/**
* Event types dispatched from the Chromium native layer.
* @enum {string}
* @const
*/
NativeLayer.EventType = {
DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD',
DISABLE_SCALING: 'print_preview.NativeLayer.DISABLE_SCALING',
MANIPULATE_SETTINGS_FOR_TEST:
'print_preview.NativeLayer.MANIPULATE_SETTINGS_FOR_TEST',
PAGE_COUNT_READY: 'print_preview.NativeLayer.PAGE_COUNT_READY',
PAGE_LAYOUT_READY: 'print_preview.NativeLayer.PAGE_LAYOUT_READY',
PAGE_PREVIEW_READY: 'print_preview.NativeLayer.PAGE_PREVIEW_READY',
PREVIEW_GENERATION_DONE:
'print_preview.NativeLayer.PREVIEW_GENERATION_DONE',
PREVIEW_GENERATION_FAIL:
'print_preview.NativeLayer.PREVIEW_GENERATION_FAIL',
SETTINGS_INVALID: 'print_preview.NativeLayer.SETTINGS_INVALID',
PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS',
};
/** /**
* Constant values matching printing::DuplexMode enum. * Constant values matching printing::DuplexMode enum.
* @enum {number} * @enum {number}
...@@ -164,11 +130,6 @@ cr.define('print_preview', function() { ...@@ -164,11 +130,6 @@ cr.define('print_preview', function() {
NativeLayer.SERIALIZED_STATE_VERSION_ = 1; NativeLayer.SERIALIZED_STATE_VERSION_ = 1;
NativeLayer.prototype = { NativeLayer.prototype = {
/** @return {!cr.EventTarget} The event target for the native layer.*/
getEventTarget: function() {
return this.eventTarget_;
},
/** /**
* Requests access token for cloud print requests. * Requests access token for cloud print requests.
* @param {string} authType type of access token. * @param {string} authType type of access token.
...@@ -314,13 +275,12 @@ cr.define('print_preview', function() { ...@@ -314,13 +275,12 @@ cr.define('print_preview', function() {
}, },
/** /**
* Requests that a preview be generated. The following events may be * Requests that a preview be generated. The following Web UI events may
* dispatched in response: * be triggered in response:
* - PAGE_COUNT_READY * 'print-preset-options',
* - PAGE_LAYOUT_READY * 'page-count-ready',
* - PAGE_PREVIEW_READY * 'page-layout-ready',
* - PREVIEW_GENERATION_DONE * 'page-preview-ready'
* - PREVIEW_GENERATION_FAIL
* @param {!print_preview.Destination} destination Destination to print to. * @param {!print_preview.Destination} destination Destination to print to.
* @param {!print_preview.PrintTicketStore} printTicketStore Used to get the * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the
* state of the print ticket. * state of the print ticket.
...@@ -526,9 +486,11 @@ cr.define('print_preview', function() { ...@@ -526,9 +486,11 @@ cr.define('print_preview', function() {
* will be dispatched in response. * will be dispatched in response.
* @param {boolean} addAccount Whether to open an 'add a new account' or * @param {boolean} addAccount Whether to open an 'add a new account' or
* default sign in page. * default sign in page.
* @return {!Promise} Promise that resolves when the sign in tab has been
* closed and the destinations should be reloaded.
*/ */
startCloudPrintSignIn: function(addAccount) { signIn: function(addAccount) {
chrome.send('signIn', [addAccount]); return cr.sendWithPromise('signIn', addAccount);
}, },
/** Navigates the user to the system printer settings interface. */ /** Navigates the user to the system printer settings interface. */
...@@ -551,116 +513,13 @@ cr.define('print_preview', function() { ...@@ -551,116 +513,13 @@ cr.define('print_preview', function() {
chrome.send('forceOpenNewTab', [url]); chrome.send('forceOpenNewTab', [url]);
}, },
/** Reloads the printer list. */
onReloadPrintersList_: function() {
cr.dispatchSimpleEvent(
this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD);
},
/**
* @param {{contentWidth: number, contentHeight: number, marginLeft: number,
* marginRight: number, marginTop: number, marginBottom: number,
* printableAreaX: number, printableAreaY: number,
* printableAreaWidth: number, printableAreaHeight: number}}
* pageLayout Specifies default page layout details in points.
* @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed
* document has a custom page size style.
* @private
*/
onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) {
var pageLayoutChangeEvent =
new Event(NativeLayer.EventType.PAGE_LAYOUT_READY);
pageLayoutChangeEvent.pageLayout = pageLayout;
pageLayoutChangeEvent.hasCustomPageSizeStyle = hasCustomPageSizeStyle;
this.eventTarget_.dispatchEvent(pageLayoutChangeEvent);
},
/**
* Update the page count and check the page range.
* Called from PrintPreviewUI::OnDidGetPreviewPageCount().
* @param {number} pageCount The number of pages.
* @param {number} previewResponseId The preview request id that resulted in
* this response.
* @param {number} fitToPageScaling The scaling percentage required to fit
* the document to page, rounded to the nearest integer.
* @private
*/
onDidGetPreviewPageCount_: function(
pageCount, previewResponseId, fitToPageScaling) {
var pageCountChangeEvent =
new Event(NativeLayer.EventType.PAGE_COUNT_READY);
pageCountChangeEvent.pageCount = pageCount;
pageCountChangeEvent.previewResponseId = previewResponseId;
pageCountChangeEvent.fitToPageScaling = fitToPageScaling;
this.eventTarget_.dispatchEvent(pageCountChangeEvent);
},
/**
* Notification that a print preview page has been rendered.
* Check if the settings have changed and request a regeneration if needed.
* Called from PrintPreviewUI::OnDidPreviewPage().
* @param {number} pageNumber The page number, 0-based.
* @param {number} previewUid Preview unique identifier.
* @param {number} previewResponseId The preview request id that resulted in
* this response.
* @private
*/
onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) {
var pagePreviewGenEvent =
new Event(NativeLayer.EventType.PAGE_PREVIEW_READY);
pagePreviewGenEvent.pageIndex = pageNumber;
pagePreviewGenEvent.previewUid = previewUid;
pagePreviewGenEvent.previewResponseId = previewResponseId;
this.eventTarget_.dispatchEvent(pagePreviewGenEvent);
},
/**
* Updates print preset options from source PDF document.
* Called from PrintPreviewUI::OnSetOptionsFromDocument().
* @param {{disableScaling: boolean, copies: number,
* duplex: number}} options Specifies
* printing options according to source document presets.
* @private
*/
onPrintPresetOptionsFromDocument_: function(options) {
var printPresetOptionsEvent =
new Event(NativeLayer.EventType.PRINT_PRESET_OPTIONS);
printPresetOptionsEvent.optionsFromDocument = options;
this.eventTarget_.dispatchEvent(printPresetOptionsEvent);
},
/**
* Allows for onManipulateSettings to be called
* from the native layer.
* @private
*/
onEnableManipulateSettingsForTest_: function() {
global.onManipulateSettingsForTest =
this.onManipulateSettingsForTest_.bind(this);
},
/**
* Dispatches an event to print_preview.js to change
* a particular setting for print preview.
* @param {!print_preview.PreviewSettings} settings Object containing the
* value to be changed and that value should be set to.
* @private
*/
onManipulateSettingsForTest_: function(settings) {
var manipulateSettingsEvent =
new Event(NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST);
manipulateSettingsEvent.settings = settings;
this.eventTarget_.dispatchEvent(manipulateSettingsEvent);
},
/** /**
* Sends a message to the test, letting it know that an * Sends a message to the test, letting it know that an
* option has been set to a particular value and that the change has * option has been set to a particular value and that the change has
* finished modifying the preview area. * finished modifying the preview area.
*/ */
previewReadyForTest: function() { previewReadyForTest: function() {
if (global.onManipulateSettingsForTest) chrome.send('UILoadedForTest');
chrome.send('UILoadedForTest');
}, },
/** /**
...@@ -668,8 +527,7 @@ cr.define('print_preview', function() { ...@@ -668,8 +527,7 @@ cr.define('print_preview', function() {
* had not been changed successfully. * had not been changed successfully.
*/ */
previewFailedForTest: function() { previewFailedForTest: function() {
if (global.onManipulateSettingsForTest) chrome.send('UIFailedLoadingForTest');
chrome.send('UIFailedLoadingForTest');
} }
}; };
......
...@@ -135,15 +135,6 @@ cr.define('print_preview', function() { ...@@ -135,15 +135,6 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
this.selectedDestination_ = null; this.selectedDestination_ = null;
/**
* Event tracker used to keep track of native layer events.
* @type {!EventTracker}
* @private
*/
this.tracker_ = new EventTracker();
this.addEventListeners_();
} }
/** /**
...@@ -170,6 +161,21 @@ cr.define('print_preview', function() { ...@@ -170,6 +161,21 @@ cr.define('print_preview', function() {
PreviewGenerator.prototype = { PreviewGenerator.prototype = {
__proto__: cr.EventTarget.prototype, __proto__: cr.EventTarget.prototype,
/**
* Starts listening for relevant WebUI events and adds the listeners to
* |listenerTracker|. |listenerTracker| is responsible for removing the
* listeners when necessary.
* @param {!WebUIListenerTracker} listenerTracker
*/
addWebUIEventListeners: function(listenerTracker) {
listenerTracker.add(
'page-count-ready', this.onPageCountReady_.bind(this));
listenerTracker.add(
'page-layout-ready', this.onPageLayoutReady_.bind(this));
listenerTracker.add(
'page-preview-ready', this.onPagePreviewReady_.bind(this));
},
/** /**
* Request that new preview be generated. A preview request will not be * Request that new preview be generated. A preview request will not be
* generated if the print ticket has not changed sufficiently. * generated if the print ticket has not changed sufficiently.
...@@ -216,31 +222,6 @@ cr.define('print_preview', function() { ...@@ -216,31 +222,6 @@ cr.define('print_preview', function() {
}; };
}, },
/** Removes all event listeners that the preview generator has attached. */
removeEventListeners: function() {
this.tracker_.removeAll();
},
/**
* Adds event listeners to the relevant native layer events.
* @private
*/
addEventListeners_: function() {
var nativeLayerEventTarget = this.nativeLayer_.getEventTarget();
this.tracker_.add(
nativeLayerEventTarget,
print_preview.NativeLayer.EventType.PAGE_LAYOUT_READY,
this.onPageLayoutReady_.bind(this));
this.tracker_.add(
nativeLayerEventTarget,
print_preview.NativeLayer.EventType.PAGE_COUNT_READY,
this.onPageCountReady_.bind(this));
this.tracker_.add(
nativeLayerEventTarget,
print_preview.NativeLayer.EventType.PAGE_PREVIEW_READY,
this.onPagePreviewReady_.bind(this));
},
/** /**
* Dispatches a PAGE_READY event to signal that a page preview is ready. * Dispatches a PAGE_READY event to signal that a page preview is ready.
* @param {number} previewIndex Index of the page with respect to the pages * @param {number} previewIndex Index of the page with respect to the pages
...@@ -322,70 +303,86 @@ cr.define('print_preview', function() { ...@@ -322,70 +303,86 @@ cr.define('print_preview', function() {
/** /**
* Called when the page layout of the document is ready. Always occurs * Called when the page layout of the document is ready. Always occurs
* as a result of a preview request. * as a result of a preview request.
* @param {Event} event Contains layout info about the document. * @param {{marginTop: number,
* marginLeft: number,
* marginBottom: number,
* marginRight: number,
* contentWidth: number,
* contentHeight: number,
* printableAreaX: number,
* printableAreaY: number,
* printableAreaWidth: number,
* printableAreaHeight: number,
* }} pageLayout Layout information about the document.
* @param {boolean} hasCustomPageSizeStyle Whether this document has a
* custom page size or style to use.
* @private * @private
*/ */
onPageLayoutReady_: function(event) { onPageLayoutReady_: function(pageLayout, hasCustomPageSizeStyle) {
// NOTE: A request ID is not specified, so assuming its for the current // NOTE: A request ID is not specified, so assuming its for the current
// in-flight request. // in-flight request.
var origin = new print_preview.Coordinate2d( var origin = new print_preview.Coordinate2d(
event.pageLayout.printableAreaX, event.pageLayout.printableAreaY); pageLayout.printableAreaX, pageLayout.printableAreaY);
var size = new print_preview.Size( var size = new print_preview.Size(
event.pageLayout.printableAreaWidth, pageLayout.printableAreaWidth, pageLayout.printableAreaHeight);
event.pageLayout.printableAreaHeight);
var margins = new print_preview.Margins( var margins = new print_preview.Margins(
Math.round(event.pageLayout.marginTop), Math.round(pageLayout.marginTop), Math.round(pageLayout.marginRight),
Math.round(event.pageLayout.marginRight), Math.round(pageLayout.marginBottom),
Math.round(event.pageLayout.marginBottom), Math.round(pageLayout.marginLeft));
Math.round(event.pageLayout.marginLeft));
var o = print_preview.ticket_items.CustomMarginsOrientation; var o = print_preview.ticket_items.CustomMarginsOrientation;
var pageSize = new print_preview.Size( var pageSize = new print_preview.Size(
event.pageLayout.contentWidth + margins.get(o.LEFT) + pageLayout.contentWidth + margins.get(o.LEFT) + margins.get(o.RIGHT),
margins.get(o.RIGHT), pageLayout.contentHeight + margins.get(o.TOP) +
event.pageLayout.contentHeight + margins.get(o.TOP) +
margins.get(o.BOTTOM)); margins.get(o.BOTTOM));
this.documentInfo_.updatePageInfo( this.documentInfo_.updatePageInfo(
new print_preview.PrintableArea(origin, size), pageSize, new print_preview.PrintableArea(origin, size), pageSize,
event.hasCustomPageSizeStyle, margins); hasCustomPageSizeStyle, margins);
}, },
/** /**
* Called when the document page count is received from the native layer. * Called when the document page count is received from the native layer.
* Always occurs as a result of a preview request. * Always occurs as a result of a preview request.
* @param {Event} event Contains the document's page count. * @param {number} pageCount The document's page count.
* @param {number} previewResponseId The request ID that corresponds to this
* page count.
* @param {number} fitToPageScaling The scaling required to fit the document
* to page (unused).
* @private * @private
*/ */
onPageCountReady_: function(event) { onPageCountReady_: function(
if (this.inFlightRequestId_ != event.previewResponseId) { pageCount, previewResponseId, fitToPageScaling) {
if (this.inFlightRequestId_ != previewResponseId) {
return; // Ignore old response. return; // Ignore old response.
} }
this.documentInfo_.updatePageCount(event.pageCount); this.documentInfo_.updatePageCount(pageCount);
this.pageRanges_ = this.printTicketStore_.pageRange.getPageRanges(); this.pageRanges_ = this.printTicketStore_.pageRange.getPageRanges();
}, },
/** /**
* Called when a page's preview has been generated. Dispatches a * Called when a page's preview has been generated. Dispatches a
* PAGE_READY event. * PAGE_READY event.
* @param {Event} event Contains the page index and preview UID. * @param {number} pageIndex The index of the page whose preview is ready.
* @param {number} previewUid The unique ID of the print preview UI.
* @param {number} previewResponseId The preview request ID that this page
* preview is a response to.
* @private * @private
*/ */
onPagePreviewReady_: function(event) { onPagePreviewReady_: function(pageIndex, previewUid, previewResponseId) {
if (this.inFlightRequestId_ != event.previewResponseId) { if (this.inFlightRequestId_ != previewResponseId) {
return; // Ignore old response. return; // Ignore old response.
} }
var pageNumber = event.pageIndex + 1; var pageNumber = pageIndex + 1;
var pageNumberSet = this.printTicketStore_.pageRange.getPageNumberSet(); var pageNumberSet = this.printTicketStore_.pageRange.getPageNumberSet();
if (pageNumberSet.hasPageNumber(pageNumber)) { if (pageNumberSet.hasPageNumber(pageNumber)) {
var previewIndex = pageNumberSet.getPageNumberIndex(pageNumber); var previewIndex = pageNumberSet.getPageNumberIndex(pageNumber);
if (previewIndex == 0) { if (previewIndex == 0) {
this.dispatchPreviewStartEvent_(event.previewUid, event.pageIndex); this.dispatchPreviewStartEvent_(previewUid, pageIndex);
} }
this.dispatchPageReadyEvent_( this.dispatchPageReadyEvent_(previewIndex, pageNumber, previewUid);
previewIndex, pageNumber, event.previewUid);
} }
}, },
......
...@@ -357,6 +357,7 @@ cr.define('print_preview', function() { ...@@ -357,6 +357,7 @@ cr.define('print_preview', function() {
this.previewGenerator_, this.previewGenerator_,
print_preview.PreviewGenerator.EventType.DOCUMENT_READY, print_preview.PreviewGenerator.EventType.DOCUMENT_READY,
this.onDocumentReady_.bind(this)); this.onDocumentReady_.bind(this));
this.previewGenerator_.addWebUIEventListeners(this.listenerTracker);
} else { } else {
this.showCustomMessage(loadTimeData.getString('noPlugin')); this.showCustomMessage(loadTimeData.getString('noPlugin'));
} }
...@@ -365,9 +366,6 @@ cr.define('print_preview', function() { ...@@ -365,9 +366,6 @@ cr.define('print_preview', function() {
/** @override */ /** @override */
exitDocument: function() { exitDocument: function() {
print_preview.Component.prototype.exitDocument.call(this); print_preview.Component.prototype.exitDocument.call(this);
if (this.previewGenerator_) {
this.previewGenerator_.removeEventListeners();
}
this.overlayEl_ = null; this.overlayEl_ = null;
this.openSystemDialogButton_ = null; this.openSystemDialogButton_ = null;
}, },
......
...@@ -310,6 +310,13 @@ cr.define('print_preview', function() { ...@@ -310,6 +310,13 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
this.showSystemDialogBeforeNextPrint_ = false; this.showSystemDialogBeforeNextPrint_ = false;
/**
* Whether the preview is listening for the manipulate-settings-for-test
* UI event.
* @private {boolean}
*/
this.isListeningForManipulateSettings_ = false;
} }
PrintPreview.prototype = { PrintPreview.prototype = {
...@@ -332,35 +339,21 @@ cr.define('print_preview', function() { ...@@ -332,35 +339,21 @@ cr.define('print_preview', function() {
print_preview.PrintPreviewFocusManager.getInstance().initialize(); print_preview.PrintPreviewFocusManager.getInstance().initialize();
cr.ui.FocusOutlineManager.forDocument(document); cr.ui.FocusOutlineManager.forDocument(document);
this.listenerTracker.add('print-failed', this.onPrintFailed_.bind(this)); this.listenerTracker.add('print-failed', this.onPrintFailed_.bind(this));
this.destinationStore_.addWebUIEventListeners(this.listenerTracker);
this.listenerTracker.add( this.listenerTracker.add(
'privet-printer-added', 'use-cloud-print', this.onCloudPrintEnable_.bind(this));
this.destinationStore_.onPrivetPrinterAdded_.bind(
this.destinationStore_));
this.listenerTracker.add( this.listenerTracker.add(
'extension-printers-added', 'print-preset-options',
this.destinationStore_.onExtensionPrintersAdded_.bind( this.onPrintPresetOptionsFromDocument_.bind(this));
this.destinationStore_));
this.listenerTracker.add( this.listenerTracker.add(
'use-cloud-print', this.onCloudPrintEnable_.bind(this)); 'preview-page-count', this.onPageCountReady_.bind(this));
this.listenerTracker.add(
'enable-manipulate-settings-for-test',
this.onEnableManipulateSettingsForTest_.bind(this));
}, },
/** @override */ /** @override */
enterDocument: function() { enterDocument: function() {
// Native layer events.
var nativeLayerEventTarget = this.nativeLayer_.getEventTarget();
this.tracker.add(
nativeLayerEventTarget,
print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS,
this.onPrintPresetOptionsFromDocument_.bind(this));
this.tracker.add(
nativeLayerEventTarget,
print_preview.NativeLayer.EventType.PAGE_COUNT_READY,
this.onPageCountReady_.bind(this));
this.tracker.add(
nativeLayerEventTarget,
print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST,
this.onManipulateSettingsForTest_.bind(this));
if ($('system-dialog-link')) { if ($('system-dialog-link')) {
this.tracker.add( this.tracker.add(
getRequiredElement('system-dialog-link'), 'click', getRequiredElement('system-dialog-link'), 'click',
...@@ -824,7 +817,8 @@ cr.define('print_preview', function() { ...@@ -824,7 +817,8 @@ cr.define('print_preview', function() {
onPreviewGenerationDone_: function() { onPreviewGenerationDone_: function() {
this.isPreviewGenerationInProgress_ = false; this.isPreviewGenerationInProgress_ = false;
this.printHeader_.isPrintButtonEnabled = true; this.printHeader_.isPrintButtonEnabled = true;
this.nativeLayer_.previewReadyForTest(); if (this.isListeningForManipulateSettings_)
this.nativeLayer_.previewReadyForTest();
this.printIfReady_(); this.printIfReady_();
}, },
...@@ -1002,41 +996,46 @@ cr.define('print_preview', function() { ...@@ -1002,41 +996,46 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
onCloudPrintSignInActivated_: function(addAccount) { onCloudPrintSignInActivated_: function(addAccount) {
this.nativeLayer_.startCloudPrintSignIn(addAccount); this.nativeLayer_.signIn(addAccount)
.then(this.destinationStore_.onDestinationsReload.bind(
this.destinationStore_));
}, },
/** /**
* Updates printing options according to source document presets. * Updates printing options according to source document presets.
* @param {Event} event Contains options from source document. * @param {boolean} disableScaling Whether the document disables scaling.
* @param {number} copies The default number of copies from the document.
* @param {number} duplex The default duplex setting from the document.
* @private * @private
*/ */
onPrintPresetOptionsFromDocument_: function(event) { onPrintPresetOptionsFromDocument_: function(
if (event.optionsFromDocument.disableScaling) disableScaling, copies, duplex) {
if (disableScaling)
this.documentInfo_.updateIsScalingDisabled(true); this.documentInfo_.updateIsScalingDisabled(true);
if (event.optionsFromDocument.copies > 0 && if (copies > 0 && this.printTicketStore_.copies.isCapabilityAvailable()) {
this.printTicketStore_.copies.isCapabilityAvailable()) { this.printTicketStore_.copies.updateValue(copies);
this.printTicketStore_.copies.updateValue(
event.optionsFromDocument.copies);
} }
if (event.optionsFromDocument.duplex >= 0 && if (duplex >= 0 & this.printTicketStore_.duplex.isCapabilityAvailable()) {
this.printTicketStore_.duplex.isCapabilityAvailable()) { this.printTicketStore_.duplex.updateValue(duplex);
this.printTicketStore_.duplex.updateValue(
event.optionsFromDocument.duplex);
} }
}, },
/** /**
* Called when the Page Count Ready message is received to update the fit to * Called when the Page Count Ready message is received to update the fit to
* page scaling value in the scaling settings. * page scaling value in the scaling settings.
* @param {Event} event Event object representing the page count ready * @param {number} pageCount The document's page count (unused).
* message * @param {number} previewResponseId The request ID that corresponds to this
* page count (unused).
* @param {number} fitToPageScaling The scaling required to fit the document
* to page.
* @private * @private
*/ */
onPageCountReady_: function(event) { onPageCountReady_: function(
if (event.fitToPageScaling >= 0) { pageCount, previewResponseId, fitToPageScaling) {
this.scalingSettings_.updateFitToPageScaling(event.fitToPageScaling); if (fitToPageScaling >= 0) {
this.scalingSettings_.updateFitToPageScaling(fitToPageScaling);
} }
}, },
...@@ -1052,15 +1051,25 @@ cr.define('print_preview', function() { ...@@ -1052,15 +1051,25 @@ cr.define('print_preview', function() {
loadTimeData.getString('couldNotPrint')); loadTimeData.getString('couldNotPrint'));
}, },
/**
* Called to start listening for the manipulate-settings-for-test WebUI
* event so that settings can be modified by this event.
* @private
*/
onEnableManipulateSettingsForTest_: function() {
this.listenerTracker.add(
'manipulate-settings-for-test',
this.onManipulateSettingsForTest_.bind(this));
this.isListeningForManipulateSettings_ = true;
},
/** /**
* Called when the print preview settings need to be changed for testing. * Called when the print preview settings need to be changed for testing.
* @param {Event} event Event object that contains the option that is to * @param {!print_preview.PreviewSettings} settings Contains print preview
* be changed and what to set that option. * settings to change and the values to change them to.
* @private * @private
*/ */
onManipulateSettingsForTest_: function(event) { onManipulateSettingsForTest_: function(settings) {
var settings =
/** @type {print_preview.PreviewSettings} */ (event.settings);
if ('selectSaveAsPdfDestination' in settings) { if ('selectSaveAsPdfDestination' in settings) {
this.saveAsPdfForTest_(); // No parameters. this.saveAsPdfForTest_(); // No parameters.
} else if ('layoutSettings' in settings) { } else if ('layoutSettings' in settings) {
......
...@@ -1173,24 +1173,24 @@ void PrintPreviewHandler::HandlePrinterSetup(const base::ListValue* args) { ...@@ -1173,24 +1173,24 @@ void PrintPreviewHandler::HandlePrinterSetup(const base::ListValue* args) {
weak_factory_.GetWeakPtr(), callback_id, printer_name)); weak_factory_.GetWeakPtr(), callback_id, printer_name));
} }
void PrintPreviewHandler::OnSigninComplete() { void PrintPreviewHandler::OnSigninComplete(const std::string& callback_id) {
if (print_preview_ui()) ResolveJavascriptCallback(base::Value(callback_id), base::Value());
print_preview_ui()->OnReloadPrintersList();
} }
void PrintPreviewHandler::HandleSignin(const base::ListValue* args) { void PrintPreviewHandler::HandleSignin(const base::ListValue* args) {
std::string callback_id;
bool add_account = false; bool add_account = false;
bool success = args->GetBoolean(0, &add_account); CHECK(args->GetString(0, &callback_id));
DCHECK(success); CHECK(!callback_id.empty());
CHECK(args->GetBoolean(1, &add_account));
Profile* profile = Profile::FromBrowserContext( Profile* profile = Profile::FromBrowserContext(
preview_web_contents()->GetBrowserContext()); preview_web_contents()->GetBrowserContext());
chrome::ScopedTabbedBrowserDisplayer displayer(profile); chrome::ScopedTabbedBrowserDisplayer displayer(profile);
print_dialog_cloud::CreateCloudPrintSigninTab( print_dialog_cloud::CreateCloudPrintSigninTab(
displayer.browser(), displayer.browser(), add_account,
add_account,
base::Bind(&PrintPreviewHandler::OnSigninComplete, base::Bind(&PrintPreviewHandler::OnSigninComplete,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr(), callback_id));
} }
void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) { void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) {
...@@ -1460,7 +1460,7 @@ WebContents* PrintPreviewHandler::GetInitiator() const { ...@@ -1460,7 +1460,7 @@ WebContents* PrintPreviewHandler::GetInitiator() const {
void PrintPreviewHandler::OnAddAccountToCookieCompleted( void PrintPreviewHandler::OnAddAccountToCookieCompleted(
const std::string& account_id, const std::string& account_id,
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
OnSigninComplete(); FireWebUIListener("reload-printer-list");
} }
void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename, void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename,
...@@ -1557,6 +1557,34 @@ void PrintPreviewHandler::OnInvalidPrinterSettings() { ...@@ -1557,6 +1557,34 @@ void PrintPreviewHandler::OnInvalidPrinterSettings() {
preview_callbacks_.pop(); preview_callbacks_.pop();
} }
void PrintPreviewHandler::SendPrintPresetOptions(bool disable_scaling,
int copies,
int duplex) {
FireWebUIListener("print-preset-options", base::Value(disable_scaling),
base::Value(copies), base::Value(duplex));
}
void PrintPreviewHandler::SendPageCountReady(int page_count,
int request_id,
int fit_to_page_scaling) {
FireWebUIListener("page-count-ready", base::Value(page_count),
base::Value(request_id), base::Value(fit_to_page_scaling));
}
void PrintPreviewHandler::SendPageLayoutReady(
const base::DictionaryValue& layout,
bool has_custom_page_size_style) {
FireWebUIListener("page-layout-ready", layout,
base::Value(has_custom_page_size_style));
}
void PrintPreviewHandler::SendPagePreviewReady(int page_index,
int preview_uid,
int preview_response_id) {
FireWebUIListener("page-preview-ready", base::Value(page_index),
base::Value(preview_uid), base::Value(preview_response_id));
}
void PrintPreviewHandler::OnPrintPreviewCancelled() { void PrintPreviewHandler::OnPrintPreviewCancelled() {
CHECK(!preview_callbacks_.empty()); CHECK(!preview_callbacks_.empty());
RejectJavascriptCallback(base::Value(preview_callbacks_.front()), RejectJavascriptCallback(base::Value(preview_callbacks_.front()),
......
...@@ -86,6 +86,23 @@ class PrintPreviewHandler ...@@ -86,6 +86,23 @@ class PrintPreviewHandler
// Called when print preview is ready. // Called when print preview is ready.
void OnPrintPreviewReady(int preview_uid, int request_id); void OnPrintPreviewReady(int preview_uid, int request_id);
// Send the print preset options from the document.
void SendPrintPresetOptions(bool disable_scaling, int copies, int duplex);
// Send the print preview page count and fit to page scaling
void SendPageCountReady(int page_count,
int request_id,
int fit_to_page_scaling);
// Send the default page layout
void SendPageLayoutReady(const base::DictionaryValue& layout,
bool has_custom_page_size_style);
// Notify the WebUI that the page preview is ready.
void SendPagePreviewReady(int page_index,
int preview_uid,
int preview_response_id);
#if BUILDFLAG(ENABLE_BASIC_PRINTING) #if BUILDFLAG(ENABLE_BASIC_PRINTING)
// Called when the user press ctrl+shift+p to display the native system // Called when the user press ctrl+shift+p to display the native system
// dialog. // dialog.
...@@ -187,7 +204,7 @@ class PrintPreviewHandler ...@@ -187,7 +204,7 @@ class PrintPreviewHandler
#endif #endif
// Callback for the signin dialog to call once signin is complete. // Callback for the signin dialog to call once signin is complete.
void OnSigninComplete(); void OnSigninComplete(const std::string& callback_id);
// Brings up a dialog to allow the user to sign into cloud print. // Brings up a dialog to allow the user to sign into cloud print.
// |args| is unused. // |args| is unused.
......
...@@ -559,11 +559,8 @@ void PrintPreviewUI::OnDidGetPreviewPageCount( ...@@ -559,11 +559,8 @@ void PrintPreviewUI::OnDidGetPreviewPageCount(
DCHECK_GT(params.page_count, 0); DCHECK_GT(params.page_count, 0);
if (g_testing_delegate) if (g_testing_delegate)
g_testing_delegate->DidGetPreviewPageCount(params.page_count); g_testing_delegate->DidGetPreviewPageCount(params.page_count);
base::Value count(params.page_count); handler_->SendPageCountReady(params.page_count, params.preview_request_id,
base::Value request_id(params.preview_request_id); params.fit_to_page_scaling);
base::Value fit_to_page_scaling(params.fit_to_page_scaling);
web_ui()->CallJavascriptFunctionUnsafe("onDidGetPreviewPageCount", count,
request_id, fit_to_page_scaling);
} }
void PrintPreviewUI::OnDidGetDefaultPageLayout( void PrintPreviewUI::OnDidGetDefaultPageLayout(
...@@ -590,22 +587,15 @@ void PrintPreviewUI::OnDidGetDefaultPageLayout( ...@@ -590,22 +587,15 @@ void PrintPreviewUI::OnDidGetDefaultPageLayout(
printable_area.width()); printable_area.width());
layout.SetInteger(printing::kSettingPrintableAreaHeight, layout.SetInteger(printing::kSettingPrintableAreaHeight,
printable_area.height()); printable_area.height());
handler_->SendPageLayoutReady(layout, has_custom_page_size_style);
base::Value has_page_size_style(has_custom_page_size_style);
web_ui()->CallJavascriptFunctionUnsafe("onDidGetDefaultPageLayout", layout,
has_page_size_style);
} }
void PrintPreviewUI::OnDidPreviewPage(int page_number, void PrintPreviewUI::OnDidPreviewPage(int page_number,
int preview_request_id) { int preview_request_id) {
DCHECK_GE(page_number, 0); DCHECK_GE(page_number, 0);
base::Value number(page_number);
base::Value ui_identifier(id_);
base::Value request_id(preview_request_id);
if (g_testing_delegate) if (g_testing_delegate)
g_testing_delegate->DidRenderPreviewPage(web_ui()->GetWebContents()); g_testing_delegate->DidRenderPreviewPage(web_ui()->GetWebContents());
web_ui()->CallJavascriptFunctionUnsafe("onDidPreviewPage", number, handler_->SendPagePreviewReady(page_number, id_, preview_request_id);
ui_identifier, request_id);
} }
void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
...@@ -667,19 +657,10 @@ void PrintPreviewUI::OnClosePrintPreviewDialog() { ...@@ -667,19 +657,10 @@ void PrintPreviewUI::OnClosePrintPreviewDialog() {
delegate->OnDialogCloseFromWebUI(); delegate->OnDialogCloseFromWebUI();
} }
void PrintPreviewUI::OnReloadPrintersList() {
web_ui()->CallJavascriptFunctionUnsafe("reloadPrintersList");
}
void PrintPreviewUI::OnSetOptionsFromDocument( void PrintPreviewUI::OnSetOptionsFromDocument(
const PrintHostMsg_SetOptionsFromDocument_Params& params) { const PrintHostMsg_SetOptionsFromDocument_Params& params) {
base::DictionaryValue options; handler_->SendPrintPresetOptions(params.is_scaling_disabled, params.copies,
options.SetBoolean(printing::kSettingDisableScaling, params.duplex);
params.is_scaling_disabled);
options.SetInteger(printing::kSettingCopies, params.copies);
options.SetInteger(printing::kSettingDuplexMode, params.duplex);
web_ui()->CallJavascriptFunctionUnsafe("printPresetOptionsFromDocument",
options);
} }
// static // static
......
...@@ -135,9 +135,6 @@ class PrintPreviewUI : public ConstrainedWebDialogUI { ...@@ -135,9 +135,6 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
// Closes the print preview dialog. // Closes the print preview dialog.
void OnClosePrintPreviewDialog(); void OnClosePrintPreviewDialog();
// Reload the printers list.
void OnReloadPrintersList();
// Notifies the WebUI to set print preset options from source PDF. // Notifies the WebUI to set print preset options from source PDF.
void OnSetOptionsFromDocument( void OnSetOptionsFromDocument(
const PrintHostMsg_SetOptionsFromDocument_Params& params); const PrintHostMsg_SetOptionsFromDocument_Params& params);
......
...@@ -20,12 +20,6 @@ cr.define('print_preview', function() { ...@@ -20,12 +20,6 @@ cr.define('print_preview', function() {
'setupPrinter' 'setupPrinter'
]); ]);
/**
* @private {!cr.EventTarget} The event target used for dispatching and
* receiving events.
*/
this.eventTarget_ = new cr.EventTarget();
/** /**
* @private {!print_preview.NativeInitialSettings} The initial settings * @private {!print_preview.NativeInitialSettings} The initial settings
* to be used for the response to a |getInitialSettings| call. * to be used for the response to a |getInitialSettings| call.
...@@ -95,12 +89,31 @@ cr.define('print_preview', function() { ...@@ -95,12 +89,31 @@ cr.define('print_preview', function() {
generateDraft: generateDraft, generateDraft: generateDraft,
requestId: requestId, requestId: requestId,
}); });
var rejectString = print_preview.PreviewArea.EventType.SETTINGS_INVALID; if (destination.id == this.badPrinterId_) {
rejectString = rejectString.substring( var rejectString = print_preview.PreviewArea.EventType.SETTINGS_INVALID;
rejectString.lastIndexOf(".") + 1, rejectString.length); rejectString = rejectString.substring(
return destination.id == this.badPrinterId_ ? rejectString.lastIndexOf('.') + 1, rejectString.length);
Promise.reject(rejectString) : return Promise.reject(rejectString);
Promise.resolve(requestId); }
var pageRanges = printTicketStore.pageRange.getDocumentPageRanges();
if (pageRanges.length == 0) { // assume full length document, 1 page.
cr.webUIListenerCallback('page-count-ready', 1, requestId, 100);
cr.webUIListenerCallback('page-preview-ready', 0, 0, requestId);
} else {
var pages = pageRanges.reduce(function(soFar, range) {
for (var page = range.from; page <= range.to; page++) {
soFar.push(page);
}
return soFar;
}, []);
cr.webUIListenerCallback(
'page-count-ready', pages.length, requestId, 100);
pages.forEach(function(page) {
cr.webUIListenerCallback(
'page-preview-ready', page - 1, 0, requestId);
});
}
return Promise.resolve(requestId);
}, },
/** @override */ /** @override */
...@@ -136,17 +149,8 @@ cr.define('print_preview', function() { ...@@ -136,17 +149,8 @@ cr.define('print_preview', function() {
}, },
/** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */
previewReadyForTest: function() {},
startHideDialog: function () {}, startHideDialog: function () {},
/** @return {!cr.EventTarget} The native layer event target. */
getEventTarget: function() { return this.eventTarget_; },
/** @param {!cr.EventTarget} eventTarget The event target to use. */
setEventTarget: function(eventTarget) {
this.eventTarget_ = eventTarget;
},
/** /**
* @param {!print_preview.NativeInitialSettings} settings The settings * @param {!print_preview.NativeInitialSettings} settings The settings
* to return as a response to |getInitialSettings|. * to return as a response to |getInitialSettings|.
......
...@@ -17,15 +17,6 @@ cr.define('print_preview', function() { ...@@ -17,15 +17,6 @@ cr.define('print_preview', function() {
*/ */
this.loadCallback_ = null; this.loadCallback_ = null;
/** @private {!EventTracker} The plugin stub's event tracker. */
this.tracker_ = new EventTracker();
// Call documentLoadComplete as soon as the preview area starts the
// preview.
this.tracker_.add(
area,
print_preview.PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS,
this.documentLoadComplete.bind(this));
} }
/** /**
...@@ -36,11 +27,6 @@ cr.define('print_preview', function() { ...@@ -36,11 +27,6 @@ cr.define('print_preview', function() {
this.loadCallback_ = callback; this.loadCallback_ = callback;
} }
documentLoadComplete() {
if (this.loadCallback_)
this.loadCallback_();
}
/** /**
* Stubbed out since some tests result in a call. * Stubbed out since some tests result in a call.
* @param {string} url The url to initialize the plugin to. * @param {string} url The url to initialize the plugin to.
...@@ -49,6 +35,17 @@ cr.define('print_preview', function() { ...@@ -49,6 +35,17 @@ cr.define('print_preview', function() {
* @param {boolean} modifiable Whether the source document is modifiable. * @param {boolean} modifiable Whether the source document is modifiable.
*/ */
resetPrintPreviewMode(url, color, pages, modifiable) {} resetPrintPreviewMode(url, color, pages, modifiable) {}
/**
* Called when the preview area wants the plugin to load a preview page.
* Immediately calls loadCallback_().
* @param {string} url The preview URL
* @param {number} index The index of the page number to load.
*/
loadPreviewPage(url, index) {
if (this.loadCallback_)
this.loadCallback_();
}
} }
return {PDFPluginStub: PDFPluginStub}; return {PDFPluginStub: PDFPluginStub};
......
...@@ -124,13 +124,7 @@ TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { ...@@ -124,13 +124,7 @@ TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() {
}; };
setup(function() { setup(function() {
Mock4JS.clearMocksToVerify();
nativeLayer_ = new print_preview.NativeLayerStub(); nativeLayer_ = new print_preview.NativeLayerStub();
var nativeLayerEventTarget = mock(cr.EventTarget);
nativeLayer_.setEventTarget(nativeLayerEventTarget.proxy());
nativeLayerEventTarget.expects(atLeastOnce())
.addEventListener(ANYTHING, ANYTHING, ANYTHING);
invitationStore_ = new print_preview.InvitationStore(); invitationStore_ = new print_preview.InvitationStore();
destinationStore_ = new print_preview.DestinationStore( destinationStore_ = new print_preview.DestinationStore(
nativeLayer_, new print_preview.UserInfo(), nativeLayer_, new print_preview.UserInfo(),
...@@ -142,10 +136,6 @@ TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { ...@@ -142,10 +136,6 @@ TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() {
destinationSearch_.decorate($('destination-search')); destinationSearch_.decorate($('destination-search'));
}); });
teardown(function() {
Mock4JS.verifyAllMocks();
});
test('ResolutionFails', function() { test('ResolutionFails', function() {
var destId = "001122DEADBEEF"; var destId = "001122DEADBEEF";
if (cr.isChromeOS) { if (cr.isChromeOS) {
......
...@@ -693,21 +693,12 @@ cr.define('print_preview_test', function() { ...@@ -693,21 +693,12 @@ cr.define('print_preview_test', function() {
return setupSettingsAndDestinationsWithCapabilities().then(function() { return setupSettingsAndDestinationsWithCapabilities().then(function() {
// Indicate that the number of copies print preset is set for source // Indicate that the number of copies print preset is set for source
// PDF. // PDF.
var printPresetOptions = { var copies = 2;
disableScaling: true, cr.webUIListenerCallback('print-preset-options', true, copies);
copies: 2
};
var printPresetOptionsEvent = new Event(
print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
nativeLayer.getEventTarget().
dispatchEvent(printPresetOptionsEvent);
checkSectionVisible($('copies-settings'), true); checkSectionVisible($('copies-settings'), true);
expectEquals( expectEquals(
printPresetOptions.copies, copies,
parseInt($('copies-settings'). parseInt($('copies-settings').querySelector('.user-value').value));
querySelector('.user-value').value));
return whenAnimationDone('other-options-collapsible'); return whenAnimationDone('other-options-collapsible');
}); });
...@@ -720,15 +711,7 @@ cr.define('print_preview_test', function() { ...@@ -720,15 +711,7 @@ cr.define('print_preview_test', function() {
return setupSettingsAndDestinationsWithCapabilities().then(function() { return setupSettingsAndDestinationsWithCapabilities().then(function() {
// Indicate that the duplex print preset is set to 'long edge' for // Indicate that the duplex print preset is set to 'long edge' for
// source PDF. // source PDF.
var printPresetOptions = { cr.webUIListenerCallback('print-preset-options', false, 1, 1);
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'); var otherOptions = $('other-options-settings');
checkSectionVisible(otherOptions, true); checkSectionVisible(otherOptions, true);
var duplexContainer = var duplexContainer =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment