OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 /** | 6 /** |
7 * Test version of the native layer. | 7 * Test version of the native layer. |
8 * @constructor | 8 * @constructor |
9 * @extends {TestBrowserProxy} | 9 * @extends {TestBrowserProxy} |
10 */ | 10 */ |
11 function NativeLayerStub() { | 11 function NativeLayerStub() { |
12 TestBrowserProxy.call(this, [ | 12 TestBrowserProxy.call(this, [ |
13 'getInitialSettings', | 13 'getInitialSettings', |
14 'getPrinters', | 14 'getPrinters', |
15 'getExtensionPrinters', | 15 'getExtensionPrinters', |
16 'getPrivetPrinters', | 16 'getPrivetPrinters', |
| 17 'getPrinterCapabilities', |
17 'setupPrinter' | 18 'setupPrinter' |
18 ]); | 19 ]); |
19 | 20 |
20 /** | 21 /** |
21 * @private {!cr.EventTarget} The event target used for dispatching and | 22 * @private {!cr.EventTarget} The event target used for dispatching and |
22 * receiving events. | 23 * receiving events. |
23 */ | 24 */ |
24 this.eventTarget_ = new cr.EventTarget(); | 25 this.eventTarget_ = new cr.EventTarget(); |
25 | 26 |
26 /** @private {boolean} Whether the native layer has sent a print message. */ | 27 /** @private {boolean} Whether the native layer has sent a print message. */ |
(...skipping 12 matching lines...) Expand all Loading... |
39 this.initialSettings_ = null; | 40 this.initialSettings_ = null; |
40 | 41 |
41 /** | 42 /** |
42 * | 43 * |
43 * @private {!Array<!print_preview.LocalDestinationInfo>} Local destination | 44 * @private {!Array<!print_preview.LocalDestinationInfo>} Local destination |
44 * list to be used for the response to |getPrinters|. | 45 * list to be used for the response to |getPrinters|. |
45 */ | 46 */ |
46 this.localDestinationInfos_ = []; | 47 this.localDestinationInfos_ = []; |
47 | 48 |
48 /** | 49 /** |
| 50 * @private {!Map<string, |
| 51 * !Promise<!print_preview.PrinterCapabilitiesResponse>} |
| 52 * A map from destination IDs to the responses to be sent when |
| 53 * |getPrinterCapabilities| is called for the ID. |
| 54 */ |
| 55 this.localDestinationCapabilities_ = new Map(); |
| 56 |
| 57 /** |
49 * @private {!print_preview.PrinterSetupResponse} The response to be sent | 58 * @private {!print_preview.PrinterSetupResponse} The response to be sent |
50 * on a |setupPrinter| call. | 59 * on a |setupPrinter| call. |
51 */ | 60 */ |
52 this.setupPrinterResponse_ = null; | 61 this.setupPrinterResponse_ = null; |
53 | 62 |
54 /** | 63 /** |
55 * @private {boolean} Whether the printer setup request should be rejected. | 64 * @private {boolean} Whether the printer setup request should be rejected. |
56 */ | 65 */ |
57 this.shouldRejectPrinterSetup_ = false; | 66 this.shouldRejectPrinterSetup_ = false; |
58 | |
59 /** | |
60 * @private {string} The destination id to watch for counting calls to | |
61 * |getLocalDestinationCapabilities|. | |
62 */ | |
63 this.destinationToWatch_ = ''; | |
64 | |
65 /** | |
66 * @private {number} The number of calls to | |
67 * |getLocalDestinationCapabilities| with id = |destinationToWatch_|. | |
68 */ | |
69 this.getLocalDestinationCapabilitiesCallCount_ = 0; | |
70 } | 67 } |
71 | 68 |
72 NativeLayerStub.prototype = { | 69 NativeLayerStub.prototype = { |
73 __proto__: TestBrowserProxy.prototype, | 70 __proto__: TestBrowserProxy.prototype, |
74 | 71 |
75 /** @override */ | 72 /** @override */ |
76 getInitialSettings: function() { | 73 getInitialSettings: function() { |
77 this.methodCalled('getInitialSettings'); | 74 this.methodCalled('getInitialSettings'); |
78 return Promise.resolve(this.initialSettings_); | 75 return Promise.resolve(this.initialSettings_); |
79 }, | 76 }, |
(...skipping 10 matching lines...) Expand all Loading... |
90 return Promise.resolve(true); | 87 return Promise.resolve(true); |
91 }, | 88 }, |
92 | 89 |
93 /** @override */ | 90 /** @override */ |
94 getPrivetPrinters: function() { | 91 getPrivetPrinters: function() { |
95 this.methodCalled('getPrivetPrinters'); | 92 this.methodCalled('getPrivetPrinters'); |
96 return Promise.resolve(true); | 93 return Promise.resolve(true); |
97 }, | 94 }, |
98 | 95 |
99 /** @override */ | 96 /** @override */ |
| 97 getPrinterCapabilities: function(printerId) { |
| 98 this.methodCalled('getPrinterCapabilities', printerId); |
| 99 return this.localDestinationCapabilities_.get(printerId); |
| 100 }, |
| 101 |
| 102 /** @override */ |
100 setupPrinter: function(printerId) { | 103 setupPrinter: function(printerId) { |
101 this.methodCalled('setupPrinter', printerId); | 104 this.methodCalled('setupPrinter', printerId); |
102 return this.shouldRejectPrinterSetup_ ? | 105 return this.shouldRejectPrinterSetup_ ? |
103 Promise.reject(this.setupPrinterResponse_) : | 106 Promise.reject(this.setupPrinterResponse_) : |
104 Promise.resolve(this.setupPrinterResponse_); | 107 Promise.resolve(this.setupPrinterResponse_); |
105 }, | 108 }, |
106 | 109 |
107 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ | 110 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ |
108 previewReadyForTest: function() {}, | 111 previewReadyForTest: function() {}, |
109 startGetLocalDestinationCapabilities: function(destinationId) { | 112 |
110 if (destinationId == this.destinationToWatch_) | |
111 this.getLocalDestinationCapabilitiesCallCount_++; | |
112 }, | |
113 startGetPreview: function(destination, printTicketStore, documentInfo, | 113 startGetPreview: function(destination, printTicketStore, documentInfo, |
114 generateDraft, requestId) { | 114 generateDraft, requestId) { |
115 this.generateDraft_ = generateDraft; | 115 this.generateDraft_ = generateDraft; |
116 }, | 116 }, |
117 startPrint: function () { this.printStarted_ = true; }, | 117 startPrint: function () { this.printStarted_ = true; }, |
118 startHideDialog: function () {}, | 118 startHideDialog: function () {}, |
119 | 119 |
120 /** @return {!cr.EventTarget} The native layer event target. */ | 120 /** @return {!cr.EventTarget} The native layer event target. */ |
121 getEventTarget: function() { return this.eventTarget_; }, | 121 getEventTarget: function() { return this.eventTarget_; }, |
122 | 122 |
123 /** @param {!cr.EventTarget} eventTarget The event target to use. */ | 123 /** @param {!cr.EventTarget} eventTarget The event target to use. */ |
124 setEventTarget: function(eventTarget) { | 124 setEventTarget: function(eventTarget) { |
125 this.eventTarget_ = eventTarget; | 125 this.eventTarget_ = eventTarget; |
126 }, | 126 }, |
127 | 127 |
128 /** | |
129 * @return {boolean} Whether capabilities have been requested exactly once | |
130 * for |destinationToWatch_|. | |
131 */ | |
132 didGetCapabilitiesOnce: function(destinationId) { | |
133 return (destinationId == this.destinationToWatch_ && | |
134 this.getLocalDestinationCapabilitiesCallCount_ == 1); | |
135 }, | |
136 | |
137 /** @return {boolean} Whether a new draft was requested for preview. */ | 128 /** @return {boolean} Whether a new draft was requested for preview. */ |
138 generateDraft: function() { return this.generateDraft_; }, | 129 generateDraft: function() { return this.generateDraft_; }, |
139 | 130 |
140 /** @return {boolean} Whether a print request has been issued. */ | 131 /** @return {boolean} Whether a print request has been issued. */ |
141 isPrintStarted: function() { return this.printStarted_; }, | 132 isPrintStarted: function() { return this.printStarted_; }, |
142 | 133 |
143 /** | 134 /** |
144 * @param {string} destinationId The destination ID to watch for | |
145 * |getLocalDestinationCapabilities| calls. | |
146 * Resets |getLocalDestinationCapabilitiesCallCount_|. | |
147 */ | |
148 setDestinationToWatch: function(destinationId) { | |
149 this.destinationToWatch_ = destinationId; | |
150 this.getLocalDestinationCapabilitiesCallCount_ = 0; | |
151 }, | |
152 | |
153 /** | |
154 * @param {!print_preview.NativeInitialSettings} settings The settings | 135 * @param {!print_preview.NativeInitialSettings} settings The settings |
155 * to return as a response to |getInitialSettings|. | 136 * to return as a response to |getInitialSettings|. |
156 */ | 137 */ |
157 setInitialSettings: function(settings) { | 138 setInitialSettings: function(settings) { |
158 this.initialSettings_ = settings; | 139 this.initialSettings_ = settings; |
159 }, | 140 }, |
160 | 141 |
161 /** | 142 /** |
162 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations | 143 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations |
163 * The local destinations to return as a response to |getPrinters|. | 144 * The local destinations to return as a response to |getPrinters|. |
164 */ | 145 */ |
165 setLocalDestinations: function(localDestinations) { | 146 setLocalDestinations: function(localDestinations) { |
166 this.localDestinationInfos_ = localDestinations; | 147 this.localDestinationInfos_ = localDestinations; |
167 }, | 148 }, |
168 | 149 |
169 /** | 150 /** |
| 151 * @param {!print_preview.PrinterCapabilitiesResponse} response The |
| 152 * response to send for the destination whose ID is in the response. |
| 153 * @param {boolean?} opt_reject Whether to reject the callback for this |
| 154 * destination. Defaults to false (will resolve callback) if not |
| 155 * provided. |
| 156 */ |
| 157 setLocalDestinationCapabilities: function(response, opt_reject) { |
| 158 this.localDestinationCapabilities_.set(response.printerId, |
| 159 opt_reject ? Promise.reject() : Promise.resolve(response)); |
| 160 }, |
| 161 |
| 162 /** |
170 * @param {boolean} reject Whether printSetup requests should be rejected. | 163 * @param {boolean} reject Whether printSetup requests should be rejected. |
171 * @param {!print_preview.PrinterSetupResponse} The response to send when | 164 * @param {!print_preview.PrinterSetupResponse} The response to send when |
172 * |setupPrinter| is called. | 165 * |setupPrinter| is called. |
173 */ | 166 */ |
174 setSetupPrinterResponse: function(reject, response) { | 167 setSetupPrinterResponse: function(reject, response) { |
175 this.shouldRejectPrinterSetup_ = reject; | 168 this.shouldRejectPrinterSetup_ = reject; |
176 this.setupPrinterResponse_ = response; | 169 this.setupPrinterResponse_ = response; |
177 }, | 170 }, |
178 }; | 171 }; |
179 | 172 |
180 return { | 173 return { |
181 NativeLayerStub: NativeLayerStub, | 174 NativeLayerStub: NativeLayerStub, |
182 }; | 175 }; |
183 }); | 176 }); |
OLD | NEW |