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

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

Issue 2893003003: Print Preview: Merge NativeLayerStubs for tests (Closed)
Patch Set: Remove extra variable Created 3 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('print_preview', function() {
6 /**
7 * Test version of the native layer.
8 * @constructor
9 * @extends {settings.TestBrowserProxy}
Dan Beam 2017/06/06 22:00:46 can we remove the settings. from TestBrowserProxy
dpapad 2017/06/06 22:04:25 Sure, I'll move it one level up and update clients
dpapad 2017/06/06 22:35:24 See https://codereview.chromium.org/2927653002.
10 */
11 function NativeLayerStub() {
12 settings.TestBrowserProxy.call(this, [
13 'getInitialSettings', 'setupPrinter' ]);
14
15 /**
16 * @private {!cr.EventTarget} The event target used for dispatching and
17 * receiving events.
18 */
19 this.eventTarget_ = new cr.EventTarget();
20
21 /** @private {boolean} Whether the native layer has sent a print message. */
22 this.printStarted_ = false;
23
24 /**
25 * @private {boolean} Whether the native layer has set the generate draft
26 * parameter when requesting an updated preview.
27 */
28 this.generateDraft_ = false;
29
30 /**
31 * @private {!print_preview.NativeInitialSettings} The initial settings
32 * to be used for the response to a |getInitialSettings| call.
33 */
34 this.initialSettings_ = null;
35
36 /**
37 * @private {!print_preview.PrinterSetupResponse} The response to be sent
38 * on a |setupPrinter| call.
39 */
40 this.setupPrinterResponse_ = null;
41
42 /**
43 * @private {boolean} Whether the printer setup request should be rejected.
44 */
45 this.shouldRejectPrinterSetup_ = false;
46
47 /**
48 * @private {string} The destination id to watch for counting calls to
49 * |getLocalDestinationCapabilities|.
50 */
51 this.destinationToWatch_ = '';
52
53 /**
54 * @private {number} The number of calls to
55 * |getLocalDestinationCapabilities| with id = |destinationToWatch_|.
56 */
57 this.getLocalDestinationCapabilitiesCallCount_ = 0;
58 }
59
60 NativeLayerStub.prototype = {
61 __proto__: settings.TestBrowserProxy.prototype,
62
63 /** @override */
64 getInitialSettings: function() {
65 this.methodCalled('getInitialSettings');
66 return Promise.resolve(this.initialSettings_);
67 },
68
69 /** @override */
70 setupPrinter: function(printerId) {
71 this.methodCalled('setupPrinter', printerId);
72 return this.shouldRejectPrinterSetup_ ?
73 Promise.reject(this.setupPrinterResponse_) :
74 Promise.resolve(this.setupPrinterResponse_);
75 },
76
77 /** Stubs for |print_preview.NativeLayer| methods that call C++ handlers. */
78 previewReadyForTest: function() {},
79 startGetLocalDestinations: function() {},
80 startGetPrivetDestinations: function() {},
81 startGetExtensionDestinations: function() {},
82 startGetLocalDestinationCapabilities: function(destinationId) {
83 if (destinationId == this.destinationToWatch_)
84 this.getLocalDestinationCapabilitiesCallCount_++;
85 },
86 startGetPreview: function(destination, printTicketStore, documentInfo,
87 generateDraft, requestId) {
88 this.generateDraft_ = generateDraft;
89 },
90 startPrint: function () { this.printStarted_ = true; },
91 startHideDialog: function () {},
92
93 /** @return {!cr.EventTarget} The native layer event target. */
94 getEventTarget: function() { return this.eventTarget_; },
95
96 /** @param {!cr.EventTarget} eventTarget The event target to use. */
97 setEventTarget: function(eventTarget) {
98 this.eventTarget_ = eventTarget;
99 },
100
101 /**
102 * @return {boolean} Whether capabilities have been requested exactly once
103 * for |destinationToWatch_|.
104 */
105 didGetCapabilitiesOnce: function(destinationId) {
106 return (destinationId == this.destinationToWatch_ &&
107 this.getLocalDestinationCapabilitiesCallCount_ == 1);
108 },
109
110 /** @return {boolean} Whether a new draft was requested for preview. */
111 generateDraft: function() { return this.generateDraft_; },
112
113 /** @return {boolean} Whether a print request has been issued. */
114 isPrintStarted: function() { return this.printStarted_; },
115
116 /**
117 * @param {string} destinationId The destination ID to watch for
118 * |getLocalDestinationCapabilities| calls.
119 * Resets |getLocalDestinationCapabilitiesCallCount_|.
120 */
121 setDestinationToWatch: function(destinationId) {
122 this.destinationToWatch_ = destinationId;
123 this.getLocalDestinationCapabilitiesCallCount_ = 0;
124 },
125
126 /**
127 * @param {!print_preview.NativeInitialSettings} settings The settings
128 * to return as a response to |getInitialSettings|.
129 */
130 setInitialSettings: function(settings) {
131 this.initialSettings_ = settings;
132 },
133
134 /**
135 * @param {boolean} reject Whether printSetup requests should be rejected.
136 * @param {!print_preview.PrinterSetupResponse} The response to send when
137 * |setupPrinter| is called.
138 */
139 setSetupPrinterResponse: function(reject, response) {
140 this.shouldRejectPrinterSetup_ = reject;
141 this.setupPrinterResponse_ = response;
142 },
143 };
144
145 return {
146 NativeLayerStub: NativeLayerStub,
147 };
148 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/print_preview.js ('k') | chrome/test/data/webui/print_preview/print_preview.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698