| 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 'getPrivetPrinters', | 17 'getPrivetPrinters', |
| 17 'getPrinterCapabilities', | 18 'getPrinterCapabilities', |
| 18 'print', | 19 'print', |
| 19 'setupPrinter' | 20 'setupPrinter' |
| 20 ]); | 21 ]); |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * @private {!cr.EventTarget} The event target used for dispatching and | 24 * @private {!cr.EventTarget} The event target used for dispatching and |
| 24 * receiving events. | 25 * receiving events. |
| 25 */ | 26 */ |
| 26 this.eventTarget_ = new cr.EventTarget(); | 27 this.eventTarget_ = new cr.EventTarget(); |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * @private {boolean} Whether the native layer has set the generate draft | |
| 30 * parameter when requesting an updated preview. | |
| 31 */ | |
| 32 this.generateDraft_ = false; | |
| 33 | |
| 34 /** | |
| 35 * @private {!print_preview.NativeInitialSettings} The initial settings | 30 * @private {!print_preview.NativeInitialSettings} The initial settings |
| 36 * to be used for the response to a |getInitialSettings| call. | 31 * to be used for the response to a |getInitialSettings| call. |
| 37 */ | 32 */ |
| 38 this.initialSettings_ = null; | 33 this.initialSettings_ = null; |
| 39 | 34 |
| 40 /** | 35 /** |
| 41 * | 36 * |
| 42 * @private {!Array<!print_preview.LocalDestinationInfo>} Local destination | 37 * @private {!Array<!print_preview.LocalDestinationInfo>} Local destination |
| 43 * list to be used for the response to |getPrinters|. | 38 * list to be used for the response to |getPrinters|. |
| 44 */ | 39 */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 return Promise.resolve(this.localDestinationInfos_); | 74 return Promise.resolve(this.localDestinationInfos_); |
| 80 }, | 75 }, |
| 81 | 76 |
| 82 /** @override */ | 77 /** @override */ |
| 83 getExtensionPrinters: function() { | 78 getExtensionPrinters: function() { |
| 84 this.methodCalled('getExtensionPrinters'); | 79 this.methodCalled('getExtensionPrinters'); |
| 85 return Promise.resolve(true); | 80 return Promise.resolve(true); |
| 86 }, | 81 }, |
| 87 | 82 |
| 88 /** @override */ | 83 /** @override */ |
| 84 getPreview: function( |
| 85 destination, printTicketStore, documentInfo, generateDraft, requestId) { |
| 86 this.methodCalled('getPreview', { |
| 87 destination: destination, |
| 88 printTicketStore: printTicketStore, |
| 89 documentInfo: documentInfo, |
| 90 generateDraft: generateDraft, |
| 91 requestId: requestId, |
| 92 }); |
| 93 return Promise.resolve(requestId); |
| 94 }, |
| 95 |
| 96 /** @override */ |
| 89 getPrivetPrinters: function() { | 97 getPrivetPrinters: function() { |
| 90 this.methodCalled('getPrivetPrinters'); | 98 this.methodCalled('getPrivetPrinters'); |
| 91 return Promise.resolve(true); | 99 return Promise.resolve(true); |
| 92 }, | 100 }, |
| 93 | 101 |
| 94 /** @override */ | 102 /** @override */ |
| 95 getPrinterCapabilities: function(printerId) { | 103 getPrinterCapabilities: function(printerId) { |
| 96 this.methodCalled('getPrinterCapabilities', printerId); | 104 this.methodCalled('getPrinterCapabilities', printerId); |
| 97 return this.localDestinationCapabilities_.get(printerId); | 105 return this.localDestinationCapabilities_.get(printerId); |
| 98 }, | 106 }, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 112 /** @override */ | 120 /** @override */ |
| 113 setupPrinter: function(printerId) { | 121 setupPrinter: function(printerId) { |
| 114 this.methodCalled('setupPrinter', printerId); | 122 this.methodCalled('setupPrinter', printerId); |
| 115 return this.shouldRejectPrinterSetup_ ? | 123 return this.shouldRejectPrinterSetup_ ? |
| 116 Promise.reject(this.setupPrinterResponse_) : | 124 Promise.reject(this.setupPrinterResponse_) : |
| 117 Promise.resolve(this.setupPrinterResponse_); | 125 Promise.resolve(this.setupPrinterResponse_); |
| 118 }, | 126 }, |
| 119 | 127 |
| 120 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ | 128 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ |
| 121 previewReadyForTest: function() {}, | 129 previewReadyForTest: function() {}, |
| 122 | |
| 123 startGetPreview: function(destination, printTicketStore, documentInfo, | |
| 124 generateDraft, requestId) { | |
| 125 this.generateDraft_ = generateDraft; | |
| 126 }, | |
| 127 startHideDialog: function () {}, | 130 startHideDialog: function () {}, |
| 128 | 131 |
| 129 /** @return {!cr.EventTarget} The native layer event target. */ | 132 /** @return {!cr.EventTarget} The native layer event target. */ |
| 130 getEventTarget: function() { return this.eventTarget_; }, | 133 getEventTarget: function() { return this.eventTarget_; }, |
| 131 | 134 |
| 132 /** @param {!cr.EventTarget} eventTarget The event target to use. */ | 135 /** @param {!cr.EventTarget} eventTarget The event target to use. */ |
| 133 setEventTarget: function(eventTarget) { | 136 setEventTarget: function(eventTarget) { |
| 134 this.eventTarget_ = eventTarget; | 137 this.eventTarget_ = eventTarget; |
| 135 }, | 138 }, |
| 136 | 139 |
| 137 /** @return {boolean} Whether a new draft was requested for preview. */ | |
| 138 generateDraft: function() { return this.generateDraft_; }, | |
| 139 | |
| 140 /** | 140 /** |
| 141 * @param {!print_preview.NativeInitialSettings} settings The settings | 141 * @param {!print_preview.NativeInitialSettings} settings The settings |
| 142 * to return as a response to |getInitialSettings|. | 142 * to return as a response to |getInitialSettings|. |
| 143 */ | 143 */ |
| 144 setInitialSettings: function(settings) { | 144 setInitialSettings: function(settings) { |
| 145 this.initialSettings_ = settings; | 145 this.initialSettings_ = settings; |
| 146 }, | 146 }, |
| 147 | 147 |
| 148 /** | 148 /** |
| 149 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations | 149 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations |
| (...skipping 23 matching lines...) Expand all Loading... |
| 173 setSetupPrinterResponse: function(reject, response) { | 173 setSetupPrinterResponse: function(reject, response) { |
| 174 this.shouldRejectPrinterSetup_ = reject; | 174 this.shouldRejectPrinterSetup_ = reject; |
| 175 this.setupPrinterResponse_ = response; | 175 this.setupPrinterResponse_ = response; |
| 176 }, | 176 }, |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 return { | 179 return { |
| 180 NativeLayerStub: NativeLayerStub, | 180 NativeLayerStub: NativeLayerStub, |
| 181 }; | 181 }; |
| 182 }); | 182 }); |
| OLD | NEW |