Chromium Code Reviews| Index: chrome/test/data/webui/print_preview/native_layer_stub.js |
| diff --git a/chrome/test/data/webui/print_preview/native_layer_stub.js b/chrome/test/data/webui/print_preview/native_layer_stub.js |
| index 51f80161229a7f14b40c7e72ba11eb07f7062c4f..57418f3d8596175e0cb6e4b63d60d6e6449134f6 100644 |
| --- a/chrome/test/data/webui/print_preview/native_layer_stub.js |
| +++ b/chrome/test/data/webui/print_preview/native_layer_stub.js |
| @@ -14,6 +14,7 @@ cr.define('print_preview', function() { |
| 'getPrinters', |
| 'getExtensionPrinters', |
| 'getPrivetPrinters', |
| + 'getPrinterCapabilities', |
| 'setupPrinter' |
| ]); |
| @@ -45,6 +46,15 @@ cr.define('print_preview', function() { |
| */ |
| this.localDestinationInfos_ = []; |
| + /** |
| + * @private {!Map<string, |
| + * {response: !print_preview.PrinterCapabilitiesResponse, |
| + * reject: boolean}>} |
| + * A map from destination IDs to the responses to be sent when |
| + * |getPrinterCapabilities| is called for the ID. |
| + */ |
| + this.localDestinationCapabilities_ = new Map(); |
| + |
| /** |
| * @private {!print_preview.PrinterSetupResponse} The response to be sent |
| * on a |setupPrinter| call. |
| @@ -55,18 +65,6 @@ cr.define('print_preview', function() { |
| * @private {boolean} Whether the printer setup request should be rejected. |
| */ |
| this.shouldRejectPrinterSetup_ = false; |
| - |
| - /** |
| - * @private {string} The destination id to watch for counting calls to |
| - * |getLocalDestinationCapabilities|. |
| - */ |
| - this.destinationToWatch_ = ''; |
| - |
| - /** |
| - * @private {number} The number of calls to |
| - * |getLocalDestinationCapabilities| with id = |destinationToWatch_|. |
| - */ |
| - this.getLocalDestinationCapabilitiesCallCount_ = 0; |
| } |
| NativeLayerStub.prototype = { |
| @@ -96,6 +94,17 @@ cr.define('print_preview', function() { |
| return Promise.resolve(true); |
| }, |
| + /** @override */ |
| + getPrinterCapabilities: function(printerId) { |
| + this.methodCalled('getPrinterCapabilities', printerId); |
| + var responseAndReject = this.localDestinationCapabilities_.get(printerId); |
| + if (responseAndReject && !responseAndReject.reject) { |
| + return Promise.resolve(responseAndReject.response); |
| + } else { |
| + return Promise.reject(printerId); |
| + } |
| + }, |
| + |
| /** @override */ |
| setupPrinter: function(printerId) { |
| this.methodCalled('setupPrinter', printerId); |
| @@ -106,10 +115,7 @@ cr.define('print_preview', function() { |
| /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ |
| previewReadyForTest: function() {}, |
| - startGetLocalDestinationCapabilities: function(destinationId) { |
| - if (destinationId == this.destinationToWatch_) |
| - this.getLocalDestinationCapabilitiesCallCount_++; |
| - }, |
| + |
| startGetPreview: function(destination, printTicketStore, documentInfo, |
| generateDraft, requestId) { |
| this.generateDraft_ = generateDraft; |
| @@ -125,31 +131,12 @@ cr.define('print_preview', function() { |
| this.eventTarget_ = eventTarget; |
| }, |
| - /** |
| - * @return {boolean} Whether capabilities have been requested exactly once |
| - * for |destinationToWatch_|. |
| - */ |
| - didGetCapabilitiesOnce: function(destinationId) { |
| - return (destinationId == this.destinationToWatch_ && |
| - this.getLocalDestinationCapabilitiesCallCount_ == 1); |
| - }, |
| - |
| /** @return {boolean} Whether a new draft was requested for preview. */ |
| generateDraft: function() { return this.generateDraft_; }, |
| /** @return {boolean} Whether a print request has been issued. */ |
| isPrintStarted: function() { return this.printStarted_; }, |
| - /** |
| - * @param {string} destinationId The destination ID to watch for |
| - * |getLocalDestinationCapabilities| calls. |
| - * Resets |getLocalDestinationCapabilitiesCallCount_|. |
| - */ |
| - setDestinationToWatch: function(destinationId) { |
| - this.destinationToWatch_ = destinationId; |
| - this.getLocalDestinationCapabilitiesCallCount_ = 0; |
| - }, |
| - |
| /** |
| * @param {!print_preview.NativeInitialSettings} settings The settings |
| * to return as a response to |getInitialSettings|. |
| @@ -166,6 +153,20 @@ cr.define('print_preview', function() { |
| this.localDestinationInfos_ = localDestinations; |
| }, |
| + /** |
| + * @param {!print_preview.PrinterCapabilitiesResponse>} localDestinations |
| + * The local destinations to return as a response to |
| + * |getPrinters(printerId)|. |
| + * @param {boolean | undefined} reject Whether to reject the callback for |
|
dpapad
2017/06/09 17:59:11
The proper way to define optional parameters is as
rbpotter
2017/06/14 03:55:08
Done.
|
| + * this destination. Defaults to false (will resolve callback) if not |
| + * provided. |
| + */ |
| + setLocalDestinationCapabilities: function(capabilities, reject) { |
| + reject = reject || false; |
| + this.localDestinationCapabilities_.set(capabilities.printerId, |
| + {"response": capabilities, "reject": reject}); |
|
dpapad
2017/06/09 17:59:11
Can we directly pass the Promise to be eventually
rbpotter
2017/06/14 03:55:08
Done.
|
| + }, |
| + |
| /** |
| * @param {boolean} reject Whether printSetup requests should be rejected. |
| * @param {!print_preview.PrinterSetupResponse} The response to send when |