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

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

Issue 2962983002: Print Preview: change getPreview to cr.sendWithPromise (Closed)
Patch Set: Fix check Created 3 years, 5 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 {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 10 matching lines...) Expand all
55 /** 50 /**
56 * @private {!print_preview.PrinterSetupResponse} The response to be sent 51 * @private {!print_preview.PrinterSetupResponse} The response to be sent
57 * on a |setupPrinter| call. 52 * on a |setupPrinter| call.
58 */ 53 */
59 this.setupPrinterResponse_ = null; 54 this.setupPrinterResponse_ = null;
60 55
61 /** 56 /**
62 * @private {boolean} Whether the printer setup request should be rejected. 57 * @private {boolean} Whether the printer setup request should be rejected.
63 */ 58 */
64 this.shouldRejectPrinterSetup_ = false; 59 this.shouldRejectPrinterSetup_ = false;
60
61 /**
62 * @private {string} The ID of a printer with a bad driver.
63 */
64 this.badPrinterId_ = '';
65 } 65 }
66 66
67 NativeLayerStub.prototype = { 67 NativeLayerStub.prototype = {
68 __proto__: TestBrowserProxy.prototype, 68 __proto__: TestBrowserProxy.prototype,
69 69
70 /** @override */ 70 /** @override */
71 getInitialSettings: function() { 71 getInitialSettings: function() {
72 this.methodCalled('getInitialSettings'); 72 this.methodCalled('getInitialSettings');
73 return Promise.resolve(this.initialSettings_); 73 return Promise.resolve(this.initialSettings_);
74 }, 74 },
75 75
76 /** @override */ 76 /** @override */
77 getPrinters: function() { 77 getPrinters: function() {
78 this.methodCalled('getPrinters'); 78 this.methodCalled('getPrinters');
79 return Promise.resolve(this.localDestinationInfos_); 79 return Promise.resolve(this.localDestinationInfos_);
80 }, 80 },
81 81
82 /** @override */ 82 /** @override */
83 getExtensionPrinters: function() { 83 getExtensionPrinters: function() {
84 this.methodCalled('getExtensionPrinters'); 84 this.methodCalled('getExtensionPrinters');
85 return Promise.resolve(true); 85 return Promise.resolve(true);
86 }, 86 },
87 87
88 /** @override */ 88 /** @override */
89 getPreview: function(
90 destination, printTicketStore, documentInfo, generateDraft, requestId) {
91 this.methodCalled('getPreview', {
92 destination: destination,
93 printTicketStore: printTicketStore,
94 documentInfo: documentInfo,
95 generateDraft: generateDraft,
96 requestId: requestId,
97 });
98 var rejectString = print_preview.PreviewArea.EventType.SETTINGS_INVALID;
99 rejectString = rejectString.substring(
100 rejectString.lastIndexOf(".") + 1, rejectString.length);
101 return destination.id == this.badPrinterId_ ?
102 Promise.reject(rejectString) :
103 Promise.resolve(requestId);
104 },
105
106 /** @override */
89 getPrivetPrinters: function() { 107 getPrivetPrinters: function() {
90 this.methodCalled('getPrivetPrinters'); 108 this.methodCalled('getPrivetPrinters');
91 return Promise.resolve(true); 109 return Promise.resolve(true);
92 }, 110 },
93 111
94 /** @override */ 112 /** @override */
95 getPrinterCapabilities: function(printerId) { 113 getPrinterCapabilities: function(printerId) {
96 this.methodCalled('getPrinterCapabilities', printerId); 114 this.methodCalled('getPrinterCapabilities', printerId);
97 return this.localDestinationCapabilities_.get(printerId); 115 return this.localDestinationCapabilities_.get(printerId);
98 }, 116 },
(...skipping 13 matching lines...) Expand all
112 /** @override */ 130 /** @override */
113 setupPrinter: function(printerId) { 131 setupPrinter: function(printerId) {
114 this.methodCalled('setupPrinter', printerId); 132 this.methodCalled('setupPrinter', printerId);
115 return this.shouldRejectPrinterSetup_ ? 133 return this.shouldRejectPrinterSetup_ ?
116 Promise.reject(this.setupPrinterResponse_) : 134 Promise.reject(this.setupPrinterResponse_) :
117 Promise.resolve(this.setupPrinterResponse_); 135 Promise.resolve(this.setupPrinterResponse_);
118 }, 136 },
119 137
120 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */ 138 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */
121 previewReadyForTest: function() {}, 139 previewReadyForTest: function() {},
122
123 startGetPreview: function(destination, printTicketStore, documentInfo,
124 generateDraft, requestId) {
125 this.generateDraft_ = generateDraft;
126 },
127 startHideDialog: function () {}, 140 startHideDialog: function () {},
128 141
129 /** @return {!cr.EventTarget} The native layer event target. */ 142 /** @return {!cr.EventTarget} The native layer event target. */
130 getEventTarget: function() { return this.eventTarget_; }, 143 getEventTarget: function() { return this.eventTarget_; },
131 144
132 /** @param {!cr.EventTarget} eventTarget The event target to use. */ 145 /** @param {!cr.EventTarget} eventTarget The event target to use. */
133 setEventTarget: function(eventTarget) { 146 setEventTarget: function(eventTarget) {
134 this.eventTarget_ = eventTarget; 147 this.eventTarget_ = eventTarget;
135 }, 148 },
136 149
137 /** @return {boolean} Whether a new draft was requested for preview. */
138 generateDraft: function() { return this.generateDraft_; },
139
140 /** 150 /**
141 * @param {!print_preview.NativeInitialSettings} settings The settings 151 * @param {!print_preview.NativeInitialSettings} settings The settings
142 * to return as a response to |getInitialSettings|. 152 * to return as a response to |getInitialSettings|.
143 */ 153 */
144 setInitialSettings: function(settings) { 154 setInitialSettings: function(settings) {
145 this.initialSettings_ = settings; 155 this.initialSettings_ = settings;
146 }, 156 },
147 157
148 /** 158 /**
149 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations 159 * @param {!Array<!print_preview.LocalDestinationInfo>} localDestinations
(...skipping 17 matching lines...) Expand all
167 177
168 /** 178 /**
169 * @param {boolean} reject Whether printSetup requests should be rejected. 179 * @param {boolean} reject Whether printSetup requests should be rejected.
170 * @param {!print_preview.PrinterSetupResponse} The response to send when 180 * @param {!print_preview.PrinterSetupResponse} The response to send when
171 * |setupPrinter| is called. 181 * |setupPrinter| is called.
172 */ 182 */
173 setSetupPrinterResponse: function(reject, response) { 183 setSetupPrinterResponse: function(reject, response) {
174 this.shouldRejectPrinterSetup_ = reject; 184 this.shouldRejectPrinterSetup_ = reject;
175 this.setupPrinterResponse_ = response; 185 this.setupPrinterResponse_ = response;
176 }, 186 },
187
188 /**
189 * @param {string} bad_id The printer ID that should cause an
190 * SETTINGS_INVALID error in response to a preview request. Models a
191 * bad printer driver.
192 */
193 setInvalidPrinterId: function(id) {
194 this.badPrinterId_ = id;
195 },
177 }; 196 };
178 197
179 return { 198 return {
180 NativeLayerStub: NativeLayerStub, 199 NativeLayerStub: NativeLayerStub,
181 }; 200 };
182 }); 201 });
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview/print_preview_ui.cc ('k') | chrome/test/data/webui/print_preview/print_preview_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698