Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/test/data/webui/print_preview/native_layer_stub.js

Issue 2919693002: Print Preview: Change getPrinters to cr.sendWithPromise (Closed)
Patch Set: Address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 {settings.TestBrowserProxy} 9 * @extends {settings.TestBrowserProxy}
10 */ 10 */
11 function NativeLayerStub() { 11 function NativeLayerStub() {
12 settings.TestBrowserProxy.call(this, [ 12 settings.TestBrowserProxy.call(this, [
13 'getInitialSettings', 'setupPrinter' ]); 13 'getInitialSettings', 'getPrinters', 'setupPrinter' ]);
14 14
15 /** 15 /**
16 * @private {!cr.EventTarget} The event target used for dispatching and 16 * @private {!cr.EventTarget} The event target used for dispatching and
17 * receiving events. 17 * receiving events.
18 */ 18 */
19 this.eventTarget_ = new cr.EventTarget(); 19 this.eventTarget_ = new cr.EventTarget();
20 20
21 /** @private {boolean} Whether the native layer has sent a print message. */ 21 /** @private {boolean} Whether the native layer has sent a print message. */
22 this.printStarted_ = false; 22 this.printStarted_ = false;
23 23
24 /** 24 /**
25 * @private {boolean} Whether the native layer has set the generate draft 25 * @private {boolean} Whether the native layer has set the generate draft
26 * parameter when requesting an updated preview. 26 * parameter when requesting an updated preview.
27 */ 27 */
28 this.generateDraft_ = false; 28 this.generateDraft_ = false;
29 29
30 /** 30 /**
31 * @private {!print_preview.NativeInitialSettings} The initial settings 31 * @private {!print_preview.NativeInitialSettings} The initial settings
32 * to be used for the response to a |getInitialSettings| call. 32 * to be used for the response to a |getInitialSettings| call.
33 */ 33 */
34 this.initialSettings_ = null; 34 this.initialSettings_ = null;
35 35
36 /** 36 /**
37 *
38 * @private {!Array<!print_preview.LocalDestinationInfo>} Local destination
39 * list to be used for the response to |getPrinters|.
40 */
41 this.localDestinationInfos_ = [];
42
43 /**
37 * @private {!print_preview.PrinterSetupResponse} The response to be sent 44 * @private {!print_preview.PrinterSetupResponse} The response to be sent
38 * on a |setupPrinter| call. 45 * on a |setupPrinter| call.
39 */ 46 */
40 this.setupPrinterResponse_ = null; 47 this.setupPrinterResponse_ = null;
41 48
42 /** 49 /**
43 * @private {boolean} Whether the printer setup request should be rejected. 50 * @private {boolean} Whether the printer setup request should be rejected.
44 */ 51 */
45 this.shouldRejectPrinterSetup_ = false; 52 this.shouldRejectPrinterSetup_ = false;
46 53
(...skipping 13 matching lines...) Expand all
60 NativeLayerStub.prototype = { 67 NativeLayerStub.prototype = {
61 __proto__: settings.TestBrowserProxy.prototype, 68 __proto__: settings.TestBrowserProxy.prototype,
62 69
63 /** @override */ 70 /** @override */
64 getInitialSettings: function() { 71 getInitialSettings: function() {
65 this.methodCalled('getInitialSettings'); 72 this.methodCalled('getInitialSettings');
66 return Promise.resolve(this.initialSettings_); 73 return Promise.resolve(this.initialSettings_);
67 }, 74 },
68 75
69 /** @override */ 76 /** @override */
77 getPrinters: function() {
78 this.methodCalled('getPrinters');
79 return Promise.resolve(this.localDestinationInfos_);
80 },
81
82 /** @override */
70 setupPrinter: function(printerId) { 83 setupPrinter: function(printerId) {
71 this.methodCalled('setupPrinter', printerId); 84 this.methodCalled('setupPrinter', printerId);
72 return this.shouldRejectPrinterSetup_ ? 85 return this.shouldRejectPrinterSetup_ ?
73 Promise.reject(this.setupPrinterResponse_) : 86 Promise.reject(this.setupPrinterResponse_) :
74 Promise.resolve(this.setupPrinterResponse_); 87 Promise.resolve(this.setupPrinterResponse_);
75 }, 88 },
76 89
77 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ 90 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */
78 previewReadyForTest: function() {}, 91 previewReadyForTest: function() {},
79 startGetLocalDestinations: function() {}, 92 startGetLocalDestinations: function() {},
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 138
126 /** 139 /**
127 * @param {!print_preview.NativeInitialSettings} settings The settings 140 * @param {!print_preview.NativeInitialSettings} settings The settings
128 * to return as a response to |getInitialSettings|. 141 * to return as a response to |getInitialSettings|.
129 */ 142 */
130 setInitialSettings: function(settings) { 143 setInitialSettings: function(settings) {
131 this.initialSettings_ = settings; 144 this.initialSettings_ = settings;
132 }, 145 },
133 146
134 /** 147 /**
148 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations
149 * The local destinations to return as a response to |getPrinters|.
150 */
151 setLocalDestinations: function(localDestinations) {
152 this.localDestinationInfos_ = localDestinations;
153 },
154
155 /**
135 * @param {boolean} reject Whether printSetup requests should be rejected. 156 * @param {boolean} reject Whether printSetup requests should be rejected.
136 * @param {!print_preview.PrinterSetupResponse} The response to send when 157 * @param {!print_preview.PrinterSetupResponse} The response to send when
137 * |setupPrinter| is called. 158 * |setupPrinter| is called.
138 */ 159 */
139 setSetupPrinterResponse: function(reject, response) { 160 setSetupPrinterResponse: function(reject, response) {
140 this.shouldRejectPrinterSetup_ = reject; 161 this.shouldRejectPrinterSetup_ = reject;
141 this.setupPrinterResponse_ = response; 162 this.setupPrinterResponse_ = response;
142 }, 163 },
143 }; 164 };
144 165
145 return { 166 return {
146 NativeLayerStub: NativeLayerStub, 167 NativeLayerStub: NativeLayerStub,
147 }; 168 };
148 }); 169 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698