Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8415)

Unified Diff: chrome/test/data/webui/print_preview/native_layer_stub.js

Issue 2931843003: Print Preview: Change getPrinterCapabilities to cr.sendWithPromise (Closed)
Patch Set: Address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..73ba1244b89b5e788a15ae5d6a690ca3df07c510 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,14 @@ cr.define('print_preview', function() {
*/
this.localDestinationInfos_ = [];
+ /**
+ * @private {!Map<string,
+ * !Promise<!print_preview.PrinterCapabilitiesResponse>}
+ * 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 +64,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 +93,12 @@ cr.define('print_preview', function() {
return Promise.resolve(true);
},
+ /** @override */
+ getPrinterCapabilities: function(printerId) {
+ this.methodCalled('getPrinterCapabilities', printerId);
+ return this.localDestinationCapabilities_.get(printerId);
+ },
+
/** @override */
setupPrinter: function(printerId) {
this.methodCalled('setupPrinter', printerId);
@@ -106,10 +109,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 +125,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 +147,18 @@ cr.define('print_preview', function() {
this.localDestinationInfos_ = localDestinations;
},
+ /**
+ * @param {!print_preview.PrinterCapabilitiesResponse} response The
+ * response to send for the destination whose ID is in the response.
+ * @param {boolean?} opt_reject Whether to reject the callback for this
+ * destination. Defaults to false (will resolve callback) if not
+ * provided.
+ */
+ setLocalDestinationCapabilities: function(response, opt_reject) {
+ this.localDestinationCapabilities_.set(response.printerId,
+ opt_reject ? Promise.reject() : Promise.resolve(response));
+ },
+
/**
* @param {boolean} reject Whether printSetup requests should be rejected.
* @param {!print_preview.PrinterSetupResponse} The response to send when

Powered by Google App Engine
This is Rietveld 408576698