OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('print_preview', function() { |
| 6 /** |
| 7 * Test version of the native layer. |
| 8 * @constructor |
| 9 * @extends {settings.TestBrowserProxy} |
| 10 */ |
| 11 function NativeLayerStub() { |
| 12 settings.TestBrowserProxy.call(this, [ |
| 13 'getInitialSettings', 'setupPrinter' ]); |
| 14 |
| 15 /** |
| 16 * @private {!cr.EventTarget} The event target used for dispatching and |
| 17 * receiving events. |
| 18 */ |
| 19 this.eventTarget_ = new cr.EventTarget(); |
| 20 |
| 21 /** @private {boolean} Whether the native layer has sent a print message. */ |
| 22 this.printStarted_ = false; |
| 23 |
| 24 /** |
| 25 * @private {boolean} Whether the native layer has set the generate draft |
| 26 * parameter when requesting an updated preview. |
| 27 */ |
| 28 this.generateDraft_ = false; |
| 29 |
| 30 /** |
| 31 * @private {!print_preview.NativeInitialSettings} The initial settings |
| 32 * to be used for the response to a |getInitialSettings| call. |
| 33 */ |
| 34 this.initialSettings_ = null; |
| 35 |
| 36 /** |
| 37 * @private {!print_preview.PrinterSetupResponse} The response to be sent |
| 38 * on a |setupPrinter| call. |
| 39 */ |
| 40 this.setupPrinterResponse_ = null; |
| 41 |
| 42 /** |
| 43 * @private {boolean} Whether the printer setup request should be rejected. |
| 44 */ |
| 45 this.shouldRejectPrinterSetup_ = false; |
| 46 |
| 47 /** |
| 48 * @private {string} The destination id to watch for counting calls to |
| 49 * |getLocalDestinationCapabilities|. |
| 50 */ |
| 51 this.destinationToWatch_ = ''; |
| 52 |
| 53 /** |
| 54 * @private {number} The number of calls to |
| 55 * |getLocalDestinationCapabilities| with id = |destinationToWatch_|. |
| 56 */ |
| 57 this.getLocalDestinationCapabilitiesCallCount_ = 0; |
| 58 } |
| 59 |
| 60 NativeLayerStub.prototype = { |
| 61 __proto__: settings.TestBrowserProxy.prototype, |
| 62 |
| 63 /** @override */ |
| 64 getInitialSettings: function() { |
| 65 this.methodCalled('getInitialSettings'); |
| 66 return Promise.resolve(this.initialSettings_); |
| 67 }, |
| 68 |
| 69 /** @override */ |
| 70 setupPrinter: function(printerId) { |
| 71 this.methodCalled('setupPrinter', printerId); |
| 72 return this.shouldRejectPrinterSetup_ ? |
| 73 Promise.reject(this.setupPrinterResponse_) : |
| 74 Promise.resolve(this.setupPrinterResponse_); |
| 75 }, |
| 76 |
| 77 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ |
| 78 previewReadyForTest: function() {}, |
| 79 startGetLocalDestinations: function() {}, |
| 80 startGetPrivetDestinations: function() {}, |
| 81 startGetExtensionDestinations: function() {}, |
| 82 startGetLocalDestinationCapabilities: function(destinationId) { |
| 83 if (destinationId == this.destinationToWatch_) |
| 84 this.getLocalDestinationCapabilitiesCallCount_++; |
| 85 }, |
| 86 startGetPreview: function(destination, printTicketStore, documentInfo, |
| 87 generateDraft, requestId) { |
| 88 this.generateDraft_ = generateDraft; |
| 89 }, |
| 90 startPrint: function () { this.printStarted_ = true; }, |
| 91 startHideDialog: function () {}, |
| 92 |
| 93 /** @return {!cr.EventTarget} The native layer event target. */ |
| 94 getEventTarget: function() { return this.eventTarget_; }, |
| 95 |
| 96 /** @param {!cr.EventTarget} eventTarget The event target to use. */ |
| 97 setEventTarget: function(eventTarget) { |
| 98 this.eventTarget_ = eventTarget; |
| 99 }, |
| 100 |
| 101 /** |
| 102 * @return {boolean} Whether capabilities have been requested exactly once |
| 103 * for |destinationToWatch_|. |
| 104 */ |
| 105 didGetCapabilitiesOnce: function(destinationId) { |
| 106 return (destinationId == this.destinationToWatch_ && |
| 107 this.getLocalDestinationCapabilitiesCallCount_ == 1); |
| 108 }, |
| 109 |
| 110 /** @return {boolean} Whether a new draft was requested for preview. */ |
| 111 generateDraft: function() { return this.generateDraft_; }, |
| 112 |
| 113 /** @return {boolean} Whether a print request has been issued. */ |
| 114 isPrintStarted: function() { return this.printStarted_; }, |
| 115 |
| 116 /** |
| 117 * @param {string} destinationId The destination ID to watch for |
| 118 * |getLocalDestinationCapabilities| calls. |
| 119 * Resets |getLocalDestinationCapabilitiesCallCount_|. |
| 120 */ |
| 121 setDestinationToWatch: function(destinationId) { |
| 122 this.destinationToWatch_ = destinationId; |
| 123 this.getLocalDestinationCapabilitiesCallCount_ = 0; |
| 124 }, |
| 125 |
| 126 /** |
| 127 * @param {!print_preview.NativeInitialSettings} settings The settings |
| 128 * to return as a response to |getInitialSettings|. |
| 129 */ |
| 130 setInitialSettings: function(settings) { |
| 131 this.initialSettings_ = settings; |
| 132 }, |
| 133 |
| 134 /** |
| 135 * @param {boolean} reject Whether printSetup requests should be rejected. |
| 136 * @param {!print_preview.PrinterSetupResponse} The response to send when |
| 137 * |setupPrinter| is called. |
| 138 */ |
| 139 setSetupPrinterResponse: function(reject, response) { |
| 140 this.shouldRejectPrinterSetup_ = reject; |
| 141 this.setupPrinterResponse_ = response; |
| 142 }, |
| 143 }; |
| 144 |
| 145 return { |
| 146 NativeLayerStub: NativeLayerStub, |
| 147 }; |
| 148 }); |
OLD | NEW |