| 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 'getPrinterCapabilities', |
| 18 'print', |
| 18 'setupPrinter' | 19 'setupPrinter' |
| 19 ]); | 20 ]); |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * @private {!cr.EventTarget} The event target used for dispatching and | 23 * @private {!cr.EventTarget} The event target used for dispatching and |
| 23 * receiving events. | 24 * receiving events. |
| 24 */ | 25 */ |
| 25 this.eventTarget_ = new cr.EventTarget(); | 26 this.eventTarget_ = new cr.EventTarget(); |
| 26 | 27 |
| 27 /** @private {boolean} Whether the native layer has sent a print message. */ | |
| 28 this.printStarted_ = false; | |
| 29 | |
| 30 /** | 28 /** |
| 31 * @private {boolean} Whether the native layer has set the generate draft | 29 * @private {boolean} Whether the native layer has set the generate draft |
| 32 * parameter when requesting an updated preview. | 30 * parameter when requesting an updated preview. |
| 33 */ | 31 */ |
| 34 this.generateDraft_ = false; | 32 this.generateDraft_ = false; |
| 35 | 33 |
| 36 /** | 34 /** |
| 37 * @private {!print_preview.NativeInitialSettings} The initial settings | 35 * @private {!print_preview.NativeInitialSettings} The initial settings |
| 38 * to be used for the response to a |getInitialSettings| call. | 36 * to be used for the response to a |getInitialSettings| call. |
| 39 */ | 37 */ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 return Promise.resolve(true); | 91 return Promise.resolve(true); |
| 94 }, | 92 }, |
| 95 | 93 |
| 96 /** @override */ | 94 /** @override */ |
| 97 getPrinterCapabilities: function(printerId) { | 95 getPrinterCapabilities: function(printerId) { |
| 98 this.methodCalled('getPrinterCapabilities', printerId); | 96 this.methodCalled('getPrinterCapabilities', printerId); |
| 99 return this.localDestinationCapabilities_.get(printerId); | 97 return this.localDestinationCapabilities_.get(printerId); |
| 100 }, | 98 }, |
| 101 | 99 |
| 102 /** @override */ | 100 /** @override */ |
| 101 print: function() { |
| 102 this.methodCalled('print'); |
| 103 return Promise.resolve(); |
| 104 }, |
| 105 |
| 106 /** @override */ |
| 103 setupPrinter: function(printerId) { | 107 setupPrinter: function(printerId) { |
| 104 this.methodCalled('setupPrinter', printerId); | 108 this.methodCalled('setupPrinter', printerId); |
| 105 return this.shouldRejectPrinterSetup_ ? | 109 return this.shouldRejectPrinterSetup_ ? |
| 106 Promise.reject(this.setupPrinterResponse_) : | 110 Promise.reject(this.setupPrinterResponse_) : |
| 107 Promise.resolve(this.setupPrinterResponse_); | 111 Promise.resolve(this.setupPrinterResponse_); |
| 108 }, | 112 }, |
| 109 | 113 |
| 110 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ | 114 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ |
| 111 previewReadyForTest: function() {}, | 115 previewReadyForTest: function() {}, |
| 112 | 116 |
| 113 startGetPreview: function(destination, printTicketStore, documentInfo, | 117 startGetPreview: function(destination, printTicketStore, documentInfo, |
| 114 generateDraft, requestId) { | 118 generateDraft, requestId) { |
| 115 this.generateDraft_ = generateDraft; | 119 this.generateDraft_ = generateDraft; |
| 116 }, | 120 }, |
| 117 startPrint: function () { this.printStarted_ = true; }, | |
| 118 startHideDialog: function () {}, | 121 startHideDialog: function () {}, |
| 119 | 122 |
| 120 /** @return {!cr.EventTarget} The native layer event target. */ | 123 /** @return {!cr.EventTarget} The native layer event target. */ |
| 121 getEventTarget: function() { return this.eventTarget_; }, | 124 getEventTarget: function() { return this.eventTarget_; }, |
| 122 | 125 |
| 123 /** @param {!cr.EventTarget} eventTarget The event target to use. */ | 126 /** @param {!cr.EventTarget} eventTarget The event target to use. */ |
| 124 setEventTarget: function(eventTarget) { | 127 setEventTarget: function(eventTarget) { |
| 125 this.eventTarget_ = eventTarget; | 128 this.eventTarget_ = eventTarget; |
| 126 }, | 129 }, |
| 127 | 130 |
| 128 /** @return {boolean} Whether a new draft was requested for preview. */ | 131 /** @return {boolean} Whether a new draft was requested for preview. */ |
| 129 generateDraft: function() { return this.generateDraft_; }, | 132 generateDraft: function() { return this.generateDraft_; }, |
| 130 | 133 |
| 131 /** @return {boolean} Whether a print request has been issued. */ | |
| 132 isPrintStarted: function() { return this.printStarted_; }, | |
| 133 | |
| 134 /** | 134 /** |
| 135 * @param {!print_preview.NativeInitialSettings} settings The settings | 135 * @param {!print_preview.NativeInitialSettings} settings The settings |
| 136 * to return as a response to |getInitialSettings|. | 136 * to return as a response to |getInitialSettings|. |
| 137 */ | 137 */ |
| 138 setInitialSettings: function(settings) { | 138 setInitialSettings: function(settings) { |
| 139 this.initialSettings_ = settings; | 139 this.initialSettings_ = settings; |
| 140 }, | 140 }, |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations | 143 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations |
| (...skipping 23 matching lines...) Expand all Loading... |
| 167 setSetupPrinterResponse: function(reject, response) { | 167 setSetupPrinterResponse: function(reject, response) { |
| 168 this.shouldRejectPrinterSetup_ = reject; | 168 this.shouldRejectPrinterSetup_ = reject; |
| 169 this.setupPrinterResponse_ = response; | 169 this.setupPrinterResponse_ = response; |
| 170 }, | 170 }, |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 return { | 173 return { |
| 174 NativeLayerStub: NativeLayerStub, | 174 NativeLayerStub: NativeLayerStub, |
| 175 }; | 175 }; |
| 176 }); | 176 }); |
| OLD | NEW |