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 'getPreview', | 16 'getPreview', |
17 'getPrivetPrinters', | 17 'getPrivetPrinters', |
18 'getPrinterCapabilities', | 18 'getPrinterCapabilities', |
19 'print', | 19 'print', |
20 'setupPrinter' | 20 'setupPrinter' |
21 ]); | 21 ]); |
22 | 22 |
23 /** | 23 /** |
24 * @private {!cr.EventTarget} The event target used for dispatching and | |
25 * receiving events. | |
26 */ | |
27 this.eventTarget_ = new cr.EventTarget(); | |
28 | |
29 /** | |
30 * @private {!print_preview.NativeInitialSettings} The initial settings | 24 * @private {!print_preview.NativeInitialSettings} The initial settings |
31 * to be used for the response to a |getInitialSettings| call. | 25 * to be used for the response to a |getInitialSettings| call. |
32 */ | 26 */ |
33 this.initialSettings_ = null; | 27 this.initialSettings_ = null; |
34 | 28 |
35 /** | 29 /** |
36 * | 30 * |
37 * @private {!Array<!print_preview.LocalDestinationInfo>} Local destination | 31 * @private {!Array<!print_preview.LocalDestinationInfo>} Local destination |
38 * list to be used for the response to |getPrinters|. | 32 * list to be used for the response to |getPrinters|. |
39 */ | 33 */ |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 /** @override */ | 82 /** @override */ |
89 getPreview: function( | 83 getPreview: function( |
90 destination, printTicketStore, documentInfo, generateDraft, requestId) { | 84 destination, printTicketStore, documentInfo, generateDraft, requestId) { |
91 this.methodCalled('getPreview', { | 85 this.methodCalled('getPreview', { |
92 destination: destination, | 86 destination: destination, |
93 printTicketStore: printTicketStore, | 87 printTicketStore: printTicketStore, |
94 documentInfo: documentInfo, | 88 documentInfo: documentInfo, |
95 generateDraft: generateDraft, | 89 generateDraft: generateDraft, |
96 requestId: requestId, | 90 requestId: requestId, |
97 }); | 91 }); |
98 var rejectString = print_preview.PreviewArea.EventType.SETTINGS_INVALID; | 92 if (destination.id == this.badPrinterId_) { |
99 rejectString = rejectString.substring( | 93 var rejectString = print_preview.PreviewArea.EventType.SETTINGS_INVALID; |
100 rejectString.lastIndexOf(".") + 1, rejectString.length); | 94 rejectString = rejectString.substring( |
101 return destination.id == this.badPrinterId_ ? | 95 rejectString.lastIndexOf('.') + 1, rejectString.length); |
102 Promise.reject(rejectString) : | 96 return Promise.reject(rejectString); |
103 Promise.resolve(requestId); | 97 } |
| 98 var pageRanges = printTicketStore.pageRange.getDocumentPageRanges(); |
| 99 if (pageRanges.length == 0) { // assume full length document, 1 page. |
| 100 cr.webUIListenerCallback('page-count-ready', 1, requestId, 100); |
| 101 cr.webUIListenerCallback('page-preview-ready', 0, 0, requestId); |
| 102 } else { |
| 103 var pages = pageRanges.reduce(function(soFar, range) { |
| 104 for (var page = range.from; page <= range.to; page++) { |
| 105 soFar.push(page); |
| 106 } |
| 107 return soFar; |
| 108 }, []); |
| 109 cr.webUIListenerCallback( |
| 110 'page-count-ready', pages.length, requestId, 100); |
| 111 pages.forEach(function(page) { |
| 112 cr.webUIListenerCallback( |
| 113 'page-preview-ready', page - 1, 0, requestId); |
| 114 }); |
| 115 } |
| 116 return Promise.resolve(requestId); |
104 }, | 117 }, |
105 | 118 |
106 /** @override */ | 119 /** @override */ |
107 getPrivetPrinters: function() { | 120 getPrivetPrinters: function() { |
108 this.methodCalled('getPrivetPrinters'); | 121 this.methodCalled('getPrivetPrinters'); |
109 return Promise.resolve(true); | 122 return Promise.resolve(true); |
110 }, | 123 }, |
111 | 124 |
112 /** @override */ | 125 /** @override */ |
113 getPrinterCapabilities: function(printerId) { | 126 getPrinterCapabilities: function(printerId) { |
(...skipping 15 matching lines...) Expand all Loading... |
129 | 142 |
130 /** @override */ | 143 /** @override */ |
131 setupPrinter: function(printerId) { | 144 setupPrinter: function(printerId) { |
132 this.methodCalled('setupPrinter', printerId); | 145 this.methodCalled('setupPrinter', printerId); |
133 return this.shouldRejectPrinterSetup_ ? | 146 return this.shouldRejectPrinterSetup_ ? |
134 Promise.reject(this.setupPrinterResponse_) : | 147 Promise.reject(this.setupPrinterResponse_) : |
135 Promise.resolve(this.setupPrinterResponse_); | 148 Promise.resolve(this.setupPrinterResponse_); |
136 }, | 149 }, |
137 | 150 |
138 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ | 151 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ |
139 previewReadyForTest: function() {}, | |
140 startHideDialog: function () {}, | 152 startHideDialog: function () {}, |
141 | 153 |
142 /** @return {!cr.EventTarget} The native layer event target. */ | |
143 getEventTarget: function() { return this.eventTarget_; }, | |
144 | |
145 /** @param {!cr.EventTarget} eventTarget The event target to use. */ | |
146 setEventTarget: function(eventTarget) { | |
147 this.eventTarget_ = eventTarget; | |
148 }, | |
149 | |
150 /** | 154 /** |
151 * @param {!print_preview.NativeInitialSettings} settings The settings | 155 * @param {!print_preview.NativeInitialSettings} settings The settings |
152 * to return as a response to |getInitialSettings|. | 156 * to return as a response to |getInitialSettings|. |
153 */ | 157 */ |
154 setInitialSettings: function(settings) { | 158 setInitialSettings: function(settings) { |
155 this.initialSettings_ = settings; | 159 this.initialSettings_ = settings; |
156 }, | 160 }, |
157 | 161 |
158 /** | 162 /** |
159 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations | 163 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 */ | 196 */ |
193 setInvalidPrinterId: function(id) { | 197 setInvalidPrinterId: function(id) { |
194 this.badPrinterId_ = id; | 198 this.badPrinterId_ = id; |
195 }, | 199 }, |
196 }; | 200 }; |
197 | 201 |
198 return { | 202 return { |
199 NativeLayerStub: NativeLayerStub, | 203 NativeLayerStub: NativeLayerStub, |
200 }; | 204 }; |
201 }); | 205 }); |
OLD | NEW |