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
...@@ -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