| 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 = []; |
| 104 var totalPages = 0; |
| 105 pageRanges.forEach(function(range) { |
| 106 for (var page = range.from; page <= range.to; page++) { |
| 107 pages[totalPages] = page; |
| 108 totalPages++; |
| 109 } |
| 110 }); |
| 111 cr.webUIListenerCallback( |
| 112 'page-count-ready', totalPages, requestId, 100); |
| 113 pages.forEach(function(page) { |
| 114 cr.webUIListenerCallback( |
| 115 'page-preview-ready', page - 1, 0, requestId); |
| 116 }); |
| 117 } |
| 118 return Promise.resolve(requestId); |
| 104 }, | 119 }, |
| 105 | 120 |
| 106 /** @override */ | 121 /** @override */ |
| 107 getPrivetPrinters: function() { | 122 getPrivetPrinters: function() { |
| 108 this.methodCalled('getPrivetPrinters'); | 123 this.methodCalled('getPrivetPrinters'); |
| 109 return Promise.resolve(true); | 124 return Promise.resolve(true); |
| 110 }, | 125 }, |
| 111 | 126 |
| 112 /** @override */ | 127 /** @override */ |
| 113 getPrinterCapabilities: function(printerId) { | 128 getPrinterCapabilities: function(printerId) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 129 | 144 |
| 130 /** @override */ | 145 /** @override */ |
| 131 setupPrinter: function(printerId) { | 146 setupPrinter: function(printerId) { |
| 132 this.methodCalled('setupPrinter', printerId); | 147 this.methodCalled('setupPrinter', printerId); |
| 133 return this.shouldRejectPrinterSetup_ ? | 148 return this.shouldRejectPrinterSetup_ ? |
| 134 Promise.reject(this.setupPrinterResponse_) : | 149 Promise.reject(this.setupPrinterResponse_) : |
| 135 Promise.resolve(this.setupPrinterResponse_); | 150 Promise.resolve(this.setupPrinterResponse_); |
| 136 }, | 151 }, |
| 137 | 152 |
| 138 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ | 153 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ |
| 139 previewReadyForTest: function() {}, | |
| 140 startHideDialog: function () {}, | 154 startHideDialog: function () {}, |
| 141 | 155 |
| 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 /** | 156 /** |
| 151 * @param {!print_preview.NativeInitialSettings} settings The settings | 157 * @param {!print_preview.NativeInitialSettings} settings The settings |
| 152 * to return as a response to |getInitialSettings|. | 158 * to return as a response to |getInitialSettings|. |
| 153 */ | 159 */ |
| 154 setInitialSettings: function(settings) { | 160 setInitialSettings: function(settings) { |
| 155 this.initialSettings_ = settings; | 161 this.initialSettings_ = settings; |
| 156 }, | 162 }, |
| 157 | 163 |
| 158 /** | 164 /** |
| 159 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations | 165 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 */ | 198 */ |
| 193 setInvalidPrinterId: function(id) { | 199 setInvalidPrinterId: function(id) { |
| 194 this.badPrinterId_ = id; | 200 this.badPrinterId_ = id; |
| 195 }, | 201 }, |
| 196 }; | 202 }; |
| 197 | 203 |
| 198 return { | 204 return { |
| 199 NativeLayerStub: NativeLayerStub, | 205 NativeLayerStub: NativeLayerStub, |
| 200 }; | 206 }; |
| 201 }); | 207 }); |
| OLD | NEW |