Commit 0fbef2a0 authored by dpapad's avatar dpapad Committed by Commit Bot

Print preview: Convert NativeLayer, NativeLayerStub to ES6 class syntax.

Bug: None
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ida67f99137833161bdccc05b29f41e0f184bb7a0
Reviewed-on: https://chromium-review.googlesource.com/592132Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491078}
parent 7a7d7202
...@@ -92,68 +92,40 @@ cr.define('print_preview', function() { ...@@ -92,68 +92,40 @@ cr.define('print_preview', function() {
/** /**
* An interface to the native Chromium printing system layer. * An interface to the native Chromium printing system layer.
* @constructor
*/ */
function NativeLayer() { class NativeLayer {
} /**
* Creates a new NativeLayer if the current instance is not set.
/** @private {?print_preview.NativeLayer} */ * @return {!print_preview.NativeLayer} The singleton instance.
var currentInstance = null; */
static getInstance() {
/** if (currentInstance == null)
* @return {!print_preview.NativeLayer} The singleton instance. currentInstance = new NativeLayer();
* Creates a new NativeLayer if the current instance is not set. return assert(currentInstance);
*/ }
NativeLayer.getInstance = function() {
if (currentInstance == null)
currentInstance = new NativeLayer();
return assert(currentInstance);
};
/**
* @param {!print_preview.NativeLayer} instance The NativeLayer instance
* to set for print preview construction.
*/
NativeLayer.setInstance = function(instance) {
currentInstance = instance;
};
/**
* Constant values matching printing::DuplexMode enum.
* @enum {number}
*/
NativeLayer.DuplexMode = {SIMPLEX: 0, LONG_EDGE: 1, UNKNOWN_DUPLEX_MODE: -1};
/**
* Enumeration of color modes used by Chromium.
* @enum {number}
* @private
*/
NativeLayer.ColorMode_ = {GRAY: 1, COLOR: 2};
/** /**
* Version of the serialized state of the print preview. * @param {!print_preview.NativeLayer} instance The NativeLayer instance
* @type {number} * to set for print preview construction.
* @const */
* @private static setInstance(instance) {
*/ currentInstance = instance;
NativeLayer.SERIALIZED_STATE_VERSION_ = 1; }
NativeLayer.prototype = {
/** /**
* 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.
* @return {!Promise<string>} * @return {!Promise<string>}
*/ */
getAccessToken: function(authType) { getAccessToken(authType) {
return cr.sendWithPromise('getAccessToken', authType); return cr.sendWithPromise('getAccessToken', authType);
}, }
/** /**
* Gets the initial settings to initialize the print preview with. * Gets the initial settings to initialize the print preview with.
* @return {!Promise<!print_preview.NativeInitialSettings>} * @return {!Promise<!print_preview.NativeInitialSettings>}
*/ */
getInitialSettings: function() { getInitialSettings() {
return cr.sendWithPromise('getInitialSettings') return cr.sendWithPromise('getInitialSettings')
.then( .then(
/** /**
...@@ -182,16 +154,16 @@ cr.define('print_preview', function() { ...@@ -182,16 +154,16 @@ cr.define('print_preview', function() {
initialSettings['defaultDestinationSelectionRules'] || initialSettings['defaultDestinationSelectionRules'] ||
null); null);
}); });
}, }
/** /**
* Requests the system's local print destinations. The promise will be * Requests the system's local print destinations. The promise will be
* resolved with a list of the local destinations. * resolved with a list of the local destinations.
* @return {!Promise<!Array<print_preview.LocalDestinationInfo>>} * @return {!Promise<!Array<print_preview.LocalDestinationInfo>>}
*/ */
getPrinters: function() { getPrinters() {
return cr.sendWithPromise('getPrinters'); return cr.sendWithPromise('getPrinters');
}, }
/** /**
* Requests the network's privet print destinations. After this is called, * Requests the network's privet print destinations. After this is called,
...@@ -199,11 +171,11 @@ cr.define('print_preview', function() { ...@@ -199,11 +171,11 @@ cr.define('print_preview', function() {
* @return {!Promise} Resolves when privet printer search is completed. * @return {!Promise} Resolves when privet printer search is completed.
* Rejected if privet printers are not enabled. * Rejected if privet printers are not enabled.
*/ */
getPrivetPrinters: function() { getPrivetPrinters() {
return cr.sendWithPromise( return cr.sendWithPromise(
'getExtensionOrPrivetPrinters', 'getExtensionOrPrivetPrinters',
print_preview.PrinterType.PRIVET_PRINTER); print_preview.PrinterType.PRIVET_PRINTER);
}, }
/** /**
* Request a list of extension printers. Printers are reported as they are * Request a list of extension printers. Printers are reported as they are
...@@ -211,11 +183,11 @@ cr.define('print_preview', function() { ...@@ -211,11 +183,11 @@ cr.define('print_preview', function() {
* @return {!Promise} Will be resolved when all extension managed printers * @return {!Promise} Will be resolved when all extension managed printers
* have been sent. * have been sent.
*/ */
getExtensionPrinters: function() { getExtensionPrinters() {
return cr.sendWithPromise( return cr.sendWithPromise(
'getExtensionOrPrivetPrinters', 'getExtensionOrPrivetPrinters',
print_preview.PrinterType.EXTENSION_PRINTER); print_preview.PrinterType.EXTENSION_PRINTER);
}, }
/** /**
* Requests the destination's printing capabilities. Returns a promise that * Requests the destination's printing capabilities. Returns a promise that
...@@ -223,9 +195,9 @@ cr.define('print_preview', function() { ...@@ -223,9 +195,9 @@ cr.define('print_preview', function() {
* @param {string} destinationId ID of the destination. * @param {string} destinationId ID of the destination.
* @return {!Promise<!print_preview.PrinterCapabilitiesResponse>} * @return {!Promise<!print_preview.PrinterCapabilitiesResponse>}
*/ */
getPrinterCapabilities: function(destinationId) { getPrinterCapabilities(destinationId) {
return cr.sendWithPromise('getPrinterCapabilities', destinationId); return cr.sendWithPromise('getPrinterCapabilities', destinationId);
}, }
/** /**
* Requests the privet destination's printing capabilities. Returns a * Requests the privet destination's printing capabilities. Returns a
...@@ -234,11 +206,11 @@ cr.define('print_preview', function() { ...@@ -234,11 +206,11 @@ cr.define('print_preview', function() {
* @param {string} destinationId The ID of the destination * @param {string} destinationId The ID of the destination
* @return {!Promise<!print_preview.PrivetPrinterCapabilitiesResponse>} * @return {!Promise<!print_preview.PrivetPrinterCapabilitiesResponse>}
*/ */
getPrivetPrinterCapabilities: function(destinationId) { getPrivetPrinterCapabilities(destinationId) {
return cr.sendWithPromise( return cr.sendWithPromise(
'getExtensionOrPrivetPrinterCapabilities', destinationId, 'getExtensionOrPrivetPrinterCapabilities', destinationId,
print_preview.PrinterType.PRIVET_PRINTER); print_preview.PrinterType.PRIVET_PRINTER);
}, }
/** /**
* Requests the extension destination's printing capabilities. Returns a * Requests the extension destination's printing capabilities. Returns a
...@@ -248,11 +220,11 @@ cr.define('print_preview', function() { ...@@ -248,11 +220,11 @@ cr.define('print_preview', function() {
* capabilities are requested. * capabilities are requested.
* @return {!Promise<!print_preview.Cdd>} * @return {!Promise<!print_preview.Cdd>}
*/ */
getExtensionPrinterCapabilities: function(destinationId) { getExtensionPrinterCapabilities(destinationId) {
return cr.sendWithPromise( return cr.sendWithPromise(
'getExtensionOrPrivetPrinterCapabilities', destinationId, 'getExtensionOrPrivetPrinterCapabilities', destinationId,
print_preview.PrinterType.EXTENSION_PRINTER); print_preview.PrinterType.EXTENSION_PRINTER);
}, }
/** /**
* Requests Chrome to resolve provisional extension destination by granting * Requests Chrome to resolve provisional extension destination by granting
...@@ -260,19 +232,19 @@ cr.define('print_preview', function() { ...@@ -260,19 +232,19 @@ cr.define('print_preview', function() {
* @param {string} provisionalDestinationId * @param {string} provisionalDestinationId
* @return {!Promise<!print_preview.ProvisionalDestinationInfo>} * @return {!Promise<!print_preview.ProvisionalDestinationInfo>}
*/ */
grantExtensionPrinterAccess: function(provisionalDestinationId) { grantExtensionPrinterAccess(provisionalDestinationId) {
return cr.sendWithPromise('grantExtensionPrinterAccess', return cr.sendWithPromise('grantExtensionPrinterAccess',
provisionalDestinationId); provisionalDestinationId);
}, }
/** /**
* Requests that Chrome peform printer setup for the given printer. * Requests that Chrome peform printer setup for the given printer.
* @param {string} printerId * @param {string} printerId
* @return {!Promise<!print_preview.PrinterSetupResponse>} * @return {!Promise<!print_preview.PrinterSetupResponse>}
*/ */
setupPrinter: function(printerId) { setupPrinter(printerId) {
return cr.sendWithPromise('setupPrinter', printerId); return cr.sendWithPromise('setupPrinter', printerId);
}, }
/** /**
* @param {!print_preview.Destination} destination Destination to print to. * @param {!print_preview.Destination} destination Destination to print to.
...@@ -280,7 +252,7 @@ cr.define('print_preview', function() { ...@@ -280,7 +252,7 @@ cr.define('print_preview', function() {
* @return {number} Native layer color model. * @return {number} Native layer color model.
* @private * @private
*/ */
getNativeColorModel_: function(destination, color) { getNativeColorModel_(destination, color) {
// For non-local printers native color model is ignored anyway. // For non-local printers native color model is ignored anyway.
var option = destination.isLocal ? color.getSelectedOption() : null; var option = destination.isLocal ? color.getSelectedOption() : null;
var nativeColorModel = parseInt(option ? option.vendor_id : null, 10); var nativeColorModel = parseInt(option ? option.vendor_id : null, 10);
...@@ -289,7 +261,7 @@ cr.define('print_preview', function() { ...@@ -289,7 +261,7 @@ cr.define('print_preview', function() {
NativeLayer.ColorMode_.GRAY; NativeLayer.ColorMode_.GRAY;
} }
return nativeColorModel; return nativeColorModel;
}, }
/** /**
* Requests that a preview be generated. The following Web UI events may * Requests that a preview be generated. The following Web UI events may
...@@ -307,7 +279,7 @@ cr.define('print_preview', function() { ...@@ -307,7 +279,7 @@ cr.define('print_preview', function() {
* @return {!Promise<number>} Promise that resolves with the unique ID of * @return {!Promise<number>} Promise that resolves with the unique ID of
* the preview UI when the preview has been generated. * the preview UI when the preview has been generated.
*/ */
getPreview: function( getPreview(
destination, printTicketStore, documentInfo, generateDraft, requestId) { destination, printTicketStore, documentInfo, generateDraft, requestId) {
assert( assert(
printTicketStore.isTicketValidForPreview(), printTicketStore.isTicketValidForPreview(),
...@@ -373,7 +345,7 @@ cr.define('print_preview', function() { ...@@ -373,7 +345,7 @@ cr.define('print_preview', function() {
return cr.sendWithPromise( return cr.sendWithPromise(
'getPreview', JSON.stringify(ticket), 'getPreview', JSON.stringify(ticket),
requestId > 0 ? documentInfo.pageCount : -1); requestId > 0 ? documentInfo.pageCount : -1);
}, }
/** /**
* Requests that the document be printed. * Requests that the document be printed.
...@@ -390,7 +362,7 @@ cr.define('print_preview', function() { ...@@ -390,7 +362,7 @@ cr.define('print_preview', function() {
* @return {!Promise} Promise that will resolve when the print request is * @return {!Promise} Promise that will resolve when the print request is
* finished or rejected. * finished or rejected.
*/ */
print: function( print(
destination, printTicketStore, cloudPrintInterface, documentInfo, destination, printTicketStore, cloudPrintInterface, documentInfo,
opt_isOpenPdfInPreview, opt_showSystemDialog) { opt_isOpenPdfInPreview, opt_showSystemDialog) {
assert( assert(
...@@ -467,26 +439,26 @@ cr.define('print_preview', function() { ...@@ -467,26 +439,26 @@ cr.define('print_preview', function() {
} }
return cr.sendWithPromise('print', JSON.stringify(ticket)); return cr.sendWithPromise('print', JSON.stringify(ticket));
}, }
/** Requests that the current pending print request be cancelled. */ /** Requests that the current pending print request be cancelled. */
cancelPendingPrintRequest: function() { cancelPendingPrintRequest() {
chrome.send('cancelPendingPrintRequest'); chrome.send('cancelPendingPrintRequest');
}, }
/** /**
* Sends the app state to be saved in the sticky settings. * Sends the app state to be saved in the sticky settings.
* @param {string} appStateStr JSON string of the app state to persist * @param {string} appStateStr JSON string of the app state to persist
*/ */
saveAppState: function(appStateStr) { saveAppState(appStateStr) {
chrome.send('saveAppState', [appStateStr]); chrome.send('saveAppState', [appStateStr]);
}, }
/** Shows the system's native printing dialog. */ /** Shows the system's native printing dialog. */
showSystemDialog: function() { showSystemDialog() {
assert(!cr.isWindows); assert(!cr.isWindows);
chrome.send('showSystemDialog'); chrome.send('showSystemDialog');
}, }
/** /**
* Closes the print preview dialog. * Closes the print preview dialog.
...@@ -495,16 +467,16 @@ cr.define('print_preview', function() { ...@@ -495,16 +467,16 @@ cr.define('print_preview', function() {
* @param {boolean} isCancel whether this was called due to the user * @param {boolean} isCancel whether this was called due to the user
* closing the dialog without printing. * closing the dialog without printing.
*/ */
dialogClose: function(isCancel) { dialogClose(isCancel) {
if (isCancel) if (isCancel)
chrome.send('closePrintPreviewDialog'); chrome.send('closePrintPreviewDialog');
chrome.send('dialogClose'); chrome.send('dialogClose');
}, }
/** Hide the print preview dialog and allow the native layer to close it. */ /** Hide the print preview dialog and allow the native layer to close it. */
hidePreview: function() { hidePreview() {
chrome.send('hidePreview'); chrome.send('hidePreview');
}, }
/** /**
* Opens the Google Cloud Print sign-in tab. The DESTINATIONS_RELOAD event * Opens the Google Cloud Print sign-in tab. The DESTINATIONS_RELOAD event
...@@ -514,14 +486,14 @@ cr.define('print_preview', function() { ...@@ -514,14 +486,14 @@ cr.define('print_preview', function() {
* @return {!Promise} Promise that resolves when the sign in tab has been * @return {!Promise} Promise that resolves when the sign in tab has been
* closed and the destinations should be reloaded. * closed and the destinations should be reloaded.
*/ */
signIn: function(addAccount) { signIn(addAccount) {
return cr.sendWithPromise('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. */
manageLocalPrinters: function() { manageLocalPrinters() {
chrome.send('manageLocalPrinters'); chrome.send('manageLocalPrinters');
}, }
/** /**
* Navigates the user to the Google Cloud Print management page. * Navigates the user to the Google Cloud Print management page.
...@@ -529,39 +501,39 @@ cr.define('print_preview', function() { ...@@ -529,39 +501,39 @@ cr.define('print_preview', function() {
* page for (user must be currently logged in, indeed) or {@code null} * page for (user must be currently logged in, indeed) or {@code null}
* to open this page for the primary user. * to open this page for the primary user.
*/ */
manageCloudPrinters: function(user) { manageCloudPrinters(user) {
chrome.send('manageCloudPrinters', [user || '']); chrome.send('manageCloudPrinters', [user || '']);
}, }
/** Forces browser to open a new tab with the given URL address. */ /** Forces browser to open a new tab with the given URL address. */
forceOpenNewTab: function(url) { forceOpenNewTab(url) {
chrome.send('forceOpenNewTab', [url]); chrome.send('forceOpenNewTab', [url]);
}, }
/** /**
* 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.
*/ */
uiLoadedForTest: function() { uiLoadedForTest() {
chrome.send('UILoadedForTest'); chrome.send('UILoadedForTest');
}, }
/** /**
* Notifies the test that the option it tried to change * Notifies the test that the option it tried to change
* had not been changed successfully. * had not been changed successfully.
*/ */
uiFailedLoadingForTest: function() { uiFailedLoadingForTest() {
chrome.send('UIFailedLoadingForTest'); chrome.send('UIFailedLoadingForTest');
}, }
/** /**
* Notifies the metrics handler to record an action. * Notifies the metrics handler to record an action.
* @param {string} action The action to record. * @param {string} action The action to record.
*/ */
recordAction: function(action) { recordAction(action) {
chrome.send('metricsHandler:recordAction', [action]); chrome.send('metricsHandler:recordAction', [action]);
}, }
/** /**
* Notifies the metrics handler to record a histogram value. * Notifies the metrics handler to record a histogram value.
...@@ -569,122 +541,149 @@ cr.define('print_preview', function() { ...@@ -569,122 +541,149 @@ cr.define('print_preview', function() {
* @param {number} bucket The bucket to record * @param {number} bucket The bucket to record
* @param {number} maxBucket The maximum bucket value in the histogram. * @param {number} maxBucket The maximum bucket value in the histogram.
*/ */
recordInHistogram: function(histogram, bucket, maxBucket) { recordInHistogram(histogram, bucket, maxBucket) {
chrome.send( chrome.send(
'metricsHandler:recordInHistogram', [histogram, bucket, maxBucket]); 'metricsHandler:recordInHistogram', [histogram, bucket, maxBucket]);
}, }
}; }
/** @private {?print_preview.NativeLayer} */
var currentInstance = null;
/** /**
* Initial settings retrieved from the native layer. * Constant values matching printing::DuplexMode enum.
* @param {boolean} isInKioskAutoPrintMode Whether the print preview should be * @enum {number}
* in auto-print mode.
* @param {boolean} isInAppKioskMode Whether the print preview is in App Kiosk
* mode.
* @param {string} thousandsDelimeter Character delimeter of thousands digits.
* @param {string} decimalDelimeter Character delimeter of the decimal point.
* @param {!print_preview.MeasurementSystemUnitType} unitType Unit type of
* local machine's measurement system.
* @param {boolean} isDocumentModifiable Whether the document to print is
* modifiable.
* @param {string} documentTitle Title of the document.
* @param {boolean} documentHasSelection Whether the document has selected
* content.
* @param {boolean} selectionOnly Whether only selected content should be
* printed.
* @param {?string} systemDefaultDestinationId ID of the system default
* destination.
* @param {?string} serializedAppStateStr Serialized app state.
* @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
* default destination selection rules.
* @constructor
*/ */
function NativeInitialSettings( NativeLayer.DuplexMode = {SIMPLEX: 0, LONG_EDGE: 1, UNKNOWN_DUPLEX_MODE: -1};
isInKioskAutoPrintMode, isInAppKioskMode, thousandsDelimeter,
decimalDelimeter, unitType, isDocumentModifiable, documentTitle,
documentHasSelection, selectionOnly, systemDefaultDestinationId,
serializedAppStateStr, serializedDefaultDestinationSelectionRulesStr) {
/**
* Whether the print preview should be in auto-print mode.
* @private {boolean}
*/
this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode;
/**
* Whether the print preview should switch to App Kiosk mode.
* @private {boolean}
*/
this.isInAppKioskMode_ = isInAppKioskMode;
/**
* Character delimeter of thousands digits.
* @private {string}
*/
this.thousandsDelimeter_ = thousandsDelimeter;
/**
* Character delimeter of the decimal point.
* @private {string}
*/
this.decimalDelimeter_ = decimalDelimeter;
/**
* Unit type of local machine's measurement system.
* @private {print_preview.MeasurementSystemUnitType}
*/
this.unitType_ = unitType;
/**
* Whether the document to print is modifiable.
* @private {boolean}
*/
this.isDocumentModifiable_ = isDocumentModifiable;
/**
* Title of the document.
* @private {string}
*/
this.documentTitle_ = documentTitle;
/**
* Whether the document has selection.
* @private {boolean}
*/
this.documentHasSelection_ = documentHasSelection;
/**
* Whether selection only should be printed.
* @private {boolean}
*/
this.selectionOnly_ = selectionOnly;
/** /**
* ID of the system default destination. * Enumeration of color modes used by Chromium.
* @private {?string} * @enum {number}
*/ * @private
this.systemDefaultDestinationId_ = systemDefaultDestinationId; */
NativeLayer.ColorMode_ = {GRAY: 1, COLOR: 2};
/** /**
* Serialized app state. * Version of the serialized state of the print preview.
* @private {?string} * @type {number}
*/ * @const
this.serializedAppStateStr_ = serializedAppStateStr; * @private
*/
NativeLayer.SERIALIZED_STATE_VERSION_ = 1;
/** /**
* Serialized default destination selection rules. * Initial settings retrieved from the native layer.
* @private {?string} */
*/ class NativeInitialSettings {
this.serializedDefaultDestinationSelectionRulesStr_ = /**
serializedDefaultDestinationSelectionRulesStr; * @param {boolean} isInKioskAutoPrintMode Whether the print preview should
} * be in auto-print mode.
* @param {boolean} isInAppKioskMode Whether the print preview is in App
* Kiosk mode.
* @param {string} thousandsDelimeter Character delimeter of thousands
* digits.
* @param {string} decimalDelimeter Character delimeter of the decimal
* point.
* @param {!print_preview.MeasurementSystemUnitType} unitType Unit type of
* local machine's measurement system.
* @param {boolean} isDocumentModifiable Whether the document to print is
* modifiable.
* @param {string} documentTitle Title of the document.
* @param {boolean} documentHasSelection Whether the document has selected
* content.
* @param {boolean} selectionOnly Whether only selected content should be
* printed.
* @param {?string} systemDefaultDestinationId ID of the system default
* destination.
* @param {?string} serializedAppStateStr Serialized app state.
* @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
* default destination selection rules.
*/
constructor(
isInKioskAutoPrintMode, isInAppKioskMode, thousandsDelimeter,
decimalDelimeter, unitType, isDocumentModifiable, documentTitle,
documentHasSelection, selectionOnly, systemDefaultDestinationId,
serializedAppStateStr, serializedDefaultDestinationSelectionRulesStr) {
/**
* Whether the print preview should be in auto-print mode.
* @private {boolean}
*/
this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode;
/**
* Whether the print preview should switch to App Kiosk mode.
* @private {boolean}
*/
this.isInAppKioskMode_ = isInAppKioskMode;
/**
* Character delimeter of thousands digits.
* @private {string}
*/
this.thousandsDelimeter_ = thousandsDelimeter;
/**
* Character delimeter of the decimal point.
* @private {string}
*/
this.decimalDelimeter_ = decimalDelimeter;
/**
* Unit type of local machine's measurement system.
* @private {print_preview.MeasurementSystemUnitType}
*/
this.unitType_ = unitType;
/**
* Whether the document to print is modifiable.
* @private {boolean}
*/
this.isDocumentModifiable_ = isDocumentModifiable;
/**
* Title of the document.
* @private {string}
*/
this.documentTitle_ = documentTitle;
/**
* Whether the document has selection.
* @private {boolean}
*/
this.documentHasSelection_ = documentHasSelection;
/**
* Whether selection only should be printed.
* @private {boolean}
*/
this.selectionOnly_ = selectionOnly;
/**
* ID of the system default destination.
* @private {?string}
*/
this.systemDefaultDestinationId_ = systemDefaultDestinationId;
/**
* Serialized app state.
* @private {?string}
*/
this.serializedAppStateStr_ = serializedAppStateStr;
/**
* Serialized default destination selection rules.
* @private {?string}
*/
this.serializedDefaultDestinationSelectionRulesStr_ =
serializedDefaultDestinationSelectionRulesStr;
}
NativeInitialSettings.prototype = {
/** /**
* @return {boolean} Whether the print preview should be in auto-print mode. * @return {boolean} Whether the print preview should be in auto-print mode.
*/ */
get isInKioskAutoPrintMode() { get isInKioskAutoPrintMode() {
return this.isInKioskAutoPrintMode_; return this.isInKioskAutoPrintMode_;
}, }
/** /**
* @return {boolean} Whether the print preview should switch to App Kiosk * @return {boolean} Whether the print preview should switch to App Kiosk
...@@ -692,17 +691,17 @@ cr.define('print_preview', function() { ...@@ -692,17 +691,17 @@ cr.define('print_preview', function() {
*/ */
get isInAppKioskMode() { get isInAppKioskMode() {
return this.isInAppKioskMode_; return this.isInAppKioskMode_;
}, }
/** @return {string} Character delimeter of thousands digits. */ /** @return {string} Character delimeter of thousands digits. */
get thousandsDelimeter() { get thousandsDelimeter() {
return this.thousandsDelimeter_; return this.thousandsDelimeter_;
}, }
/** @return {string} Character delimeter of the decimal point. */ /** @return {string} Character delimeter of the decimal point. */
get decimalDelimeter() { get decimalDelimeter() {
return this.decimalDelimeter_; return this.decimalDelimeter_;
}, }
/** /**
* @return {!print_preview.MeasurementSystemUnitType} Unit type of local * @return {!print_preview.MeasurementSystemUnitType} Unit type of local
...@@ -710,43 +709,43 @@ cr.define('print_preview', function() { ...@@ -710,43 +709,43 @@ cr.define('print_preview', function() {
*/ */
get unitType() { get unitType() {
return this.unitType_; return this.unitType_;
}, }
/** @return {boolean} Whether the document to print is modifiable. */ /** @return {boolean} Whether the document to print is modifiable. */
get isDocumentModifiable() { get isDocumentModifiable() {
return this.isDocumentModifiable_; return this.isDocumentModifiable_;
}, }
/** @return {string} Document title. */ /** @return {string} Document title. */
get documentTitle() { get documentTitle() {
return this.documentTitle_; return this.documentTitle_;
}, }
/** @return {boolean} Whether the document has selection. */ /** @return {boolean} Whether the document has selection. */
get documentHasSelection() { get documentHasSelection() {
return this.documentHasSelection_; return this.documentHasSelection_;
}, }
/** @return {boolean} Whether selection only should be printed. */ /** @return {boolean} Whether selection only should be printed. */
get selectionOnly() { get selectionOnly() {
return this.selectionOnly_; return this.selectionOnly_;
}, }
/** @return {?string} ID of the system default destination. */ /** @return {?string} ID of the system default destination. */
get systemDefaultDestinationId() { get systemDefaultDestinationId() {
return this.systemDefaultDestinationId_; return this.systemDefaultDestinationId_;
}, }
/** @return {?string} Serialized app state. */ /** @return {?string} Serialized app state. */
get serializedAppStateStr() { get serializedAppStateStr() {
return this.serializedAppStateStr_; return this.serializedAppStateStr_;
}, }
/** @return {?string} Serialized default destination selection rules. */ /** @return {?string} Serialized default destination selection rules. */
get serializedDefaultDestinationSelectionRulesStr() { get serializedDefaultDestinationSelectionRulesStr() {
return this.serializedDefaultDestinationSelectionRulesStr_; return this.serializedDefaultDestinationSelectionRulesStr_;
} }
}; }
// Export // Export
return { return {
......
...@@ -5,83 +5,80 @@ ...@@ -5,83 +5,80 @@
cr.define('print_preview', function() { cr.define('print_preview', function() {
/** /**
* Test version of the native layer. * Test version of the native layer.
* @constructor
* @extends {TestBrowserProxy}
*/ */
function NativeLayerStub() { class NativeLayerStub extends TestBrowserProxy {
TestBrowserProxy.call(this, [ constructor() {
'getInitialSettings', super([
'getPrinters', 'getInitialSettings',
'getExtensionPrinters', 'getPrinters',
'getPreview', 'getExtensionPrinters',
'getPrivetPrinters', 'getPreview',
'getPrinterCapabilities', 'getPrivetPrinters',
'hidePreview', 'getPrinterCapabilities',
'print', 'hidePreview',
'setupPrinter', 'print',
]); 'setupPrinter',
]);
/**
* @private {!print_preview.NativeInitialSettings} The initial settings /**
* to be used for the response to a |getInitialSettings| call. * @private {!print_preview.NativeInitialSettings} The initial settings
*/ * to be used for the response to a |getInitialSettings| call.
this.initialSettings_ = null; */
this.initialSettings_ = null;
/**
* /**
* @private {!Array<!print_preview.LocalDestinationInfo>} Local destination *
* list to be used for the response to |getPrinters|. * @private {!Array<!print_preview.LocalDestinationInfo>} Local
*/ * destination list to be used for the response to |getPrinters|.
this.localDestinationInfos_ = []; */
this.localDestinationInfos_ = [];
/**
* @private {!Map<string, /**
* !Promise<!print_preview.PrinterCapabilitiesResponse>} * @private {!Map<string,
* A map from destination IDs to the responses to be sent when * !Promise<!print_preview.PrinterCapabilitiesResponse>}
* |getPrinterCapabilities| is called for the ID. * A map from destination IDs to the responses to be sent when
*/ * |getPrinterCapabilities| is called for the ID.
this.localDestinationCapabilities_ = new Map(); */
this.localDestinationCapabilities_ = new Map();
/**
* @private {!print_preview.PrinterSetupResponse} The response to be sent /**
* on a |setupPrinter| call. * @private {!print_preview.PrinterSetupResponse} The response to be sent
*/ * on a |setupPrinter| call.
this.setupPrinterResponse_ = null; */
this.setupPrinterResponse_ = null;
/**
* @private {boolean} Whether the printer setup request should be rejected. /**
*/ * @private {boolean} Whether the printer setup request should be
this.shouldRejectPrinterSetup_ = false; * rejected.
*/
/** this.shouldRejectPrinterSetup_ = false;
* @private {string} The ID of a printer with a bad driver.
*/ /**
this.badPrinterId_ = ''; * @private {string} The ID of a printer with a bad driver.
} */
this.badPrinterId_ = '';
NativeLayerStub.prototype = { }
__proto__: TestBrowserProxy.prototype,
/** @override */ /** @override */
getInitialSettings: function() { getInitialSettings() {
this.methodCalled('getInitialSettings'); this.methodCalled('getInitialSettings');
return Promise.resolve(this.initialSettings_); return Promise.resolve(this.initialSettings_);
}, }
/** @override */ /** @override */
getPrinters: function() { getPrinters() {
this.methodCalled('getPrinters'); this.methodCalled('getPrinters');
return Promise.resolve(this.localDestinationInfos_); return Promise.resolve(this.localDestinationInfos_);
}, }
/** @override */ /** @override */
getExtensionPrinters: function() { getExtensionPrinters() {
this.methodCalled('getExtensionPrinters'); this.methodCalled('getExtensionPrinters');
return Promise.resolve(true); return Promise.resolve(true);
}, }
/** @override */ /** @override */
getPreview: function( getPreview(
destination, printTicketStore, documentInfo, generateDraft, requestId) { destination, printTicketStore, documentInfo, generateDraft, requestId) {
this.methodCalled('getPreview', { this.methodCalled('getPreview', {
destination: destination, destination: destination,
...@@ -115,24 +112,29 @@ cr.define('print_preview', function() { ...@@ -115,24 +112,29 @@ cr.define('print_preview', function() {
}); });
} }
return Promise.resolve(requestId); return Promise.resolve(requestId);
}, }
/** @override */ /** @override */
getPrivetPrinters: function() { getPrivetPrinters() {
this.methodCalled('getPrivetPrinters'); this.methodCalled('getPrivetPrinters');
return Promise.resolve(true); return Promise.resolve(true);
}, }
/** @override */ /** @override */
getPrinterCapabilities: function(printerId) { getPrinterCapabilities(printerId) {
this.methodCalled('getPrinterCapabilities', printerId); this.methodCalled('getPrinterCapabilities', printerId);
return this.localDestinationCapabilities_.get(printerId); return this.localDestinationCapabilities_.get(printerId);
}, }
/** @override */ /** @override */
print: function( print(
destination, printTicketStore, cloudPrintInterface, documentInfo, destination,
opt_isOpenPdfInPreview, opt_showSystemDialog) { printTicketStore,
cloudPrintInterface,
documentInfo,
opt_isOpenPdfInPreview,
opt_showSystemDialog
) {
this.methodCalled('print', { this.methodCalled('print', {
destination: destination, destination: destination,
printTicketStore: printTicketStore, printTicketStore: printTicketStore,
...@@ -142,45 +144,45 @@ cr.define('print_preview', function() { ...@@ -142,45 +144,45 @@ cr.define('print_preview', function() {
showSystemDialog: opt_showSystemDialog || false, showSystemDialog: opt_showSystemDialog || false,
}); });
return Promise.resolve(); return Promise.resolve();
}, }
/** @override */ /** @override */
setupPrinter: function(printerId) { setupPrinter(printerId) {
this.methodCalled('setupPrinter', printerId); this.methodCalled('setupPrinter', printerId);
return this.shouldRejectPrinterSetup_ ? return this.shouldRejectPrinterSetup_ ?
Promise.reject(this.setupPrinterResponse_) : Promise.reject(this.setupPrinterResponse_) :
Promise.resolve(this.setupPrinterResponse_); Promise.resolve(this.setupPrinterResponse_);
}, }
/** @override */ /** @override */
hidePreview: function() { hidePreview() {
this.methodCalled('hidePreview'); this.methodCalled('hidePreview');
}, }
/** @override */ /** @override */
recordAction: function() {}, recordAction() {}
/** @override */ /** @override */
recordInHistogram: function() {}, recordInHistogram() {}
/** @override */ /** @override */
saveAppState: function() {}, saveAppState() {}
/** /**
* @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|.
*/ */
setInitialSettings: function(settings) { setInitialSettings(settings) {
this.initialSettings_ = settings; this.initialSettings_ = settings;
}, }
/** /**
* @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations
* The local destinations to return as a response to |getPrinters|. * The local destinations to return as a response to |getPrinters|.
*/ */
setLocalDestinations: function(localDestinations) { setLocalDestinations(localDestinations) {
this.localDestinationInfos_ = localDestinations; this.localDestinationInfos_ = localDestinations;
}, }
/** /**
* @param {!print_preview.PrinterCapabilitiesResponse} response The * @param {!print_preview.PrinterCapabilitiesResponse} response The
...@@ -189,30 +191,30 @@ cr.define('print_preview', function() { ...@@ -189,30 +191,30 @@ cr.define('print_preview', function() {
* destination. Defaults to false (will resolve callback) if not * destination. Defaults to false (will resolve callback) if not
* provided. * provided.
*/ */
setLocalDestinationCapabilities: function(response, opt_reject) { setLocalDestinationCapabilities(response, opt_reject) {
this.localDestinationCapabilities_.set(response.printerId, this.localDestinationCapabilities_.set(response.printerId,
opt_reject ? Promise.reject() : Promise.resolve(response)); opt_reject ? Promise.reject() : Promise.resolve(response));
}, }
/** /**
* @param {boolean} reject Whether printSetup requests should be rejected. * @param {boolean} reject Whether printSetup requests should be rejected.
* @param {!print_preview.PrinterSetupResponse} The response to send when * @param {!print_preview.PrinterSetupResponse} The response to send when
* |setupPrinter| is called. * |setupPrinter| is called.
*/ */
setSetupPrinterResponse: function(reject, response) { setSetupPrinterResponse(reject, response) {
this.shouldRejectPrinterSetup_ = reject; this.shouldRejectPrinterSetup_ = reject;
this.setupPrinterResponse_ = response; this.setupPrinterResponse_ = response;
}, }
/** /**
* @param {string} bad_id The printer ID that should cause an * @param {string} bad_id The printer ID that should cause an
* SETTINGS_INVALID error in response to a preview request. Models a * SETTINGS_INVALID error in response to a preview request. Models a
* bad printer driver. * bad printer driver.
*/ */
setInvalidPrinterId: function(id) { setInvalidPrinterId(id) {
this.badPrinterId_ = id; this.badPrinterId_ = id;
}, }
}; }
return { return {
NativeLayerStub: NativeLayerStub, NativeLayerStub: NativeLayerStub,
......
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