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

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

Issue 2931843003: Print Preview: Change getPrinterCapabilities 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 var ROOT_PATH = '../../../../../'; 5 var ROOT_PATH = '../../../../../';
6 6
7 GEN_INCLUDE( 7 GEN_INCLUDE(
8 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); 8 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']);
9 9
10 /** 10 /**
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return new Promise(function(resolve) { 95 return new Promise(function(resolve) {
96 var listener = function(e) { 96 var listener = function(e) {
97 resolve(); 97 resolve();
98 element.removeEventListener(eventName, listener); 98 element.removeEventListener(eventName, listener);
99 }; 99 };
100 100
101 element.addEventListener(eventName, listener); 101 element.addEventListener(eventName, listener);
102 }); 102 });
103 }; 103 };
104 104
105 function mockSetupCall(destId, nativeLayerMock) {
106 assert (!cr.isChromeOS);
107 nativeLayerMock.setDestinationToWatch(destId);
108 var resolver = new PromiseResolver();
109
110 resolver.promise.then(
111 function(result) {
112 // Simulate the native layer dispatching capabilities.
113 var capsSetEvent =
114 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
115 capsSetEvent.settingsInfo = result;
116 destinationStore_.onLocalDestinationCapabilitiesSet_(capsSetEvent);
117 expectTrue(nativeLayerMock.didGetCapabilitiesOnce(destId));
118 }.bind(this),
119 function() {
120 var failEvent = new Event(
121 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL);
122 failEvent.destinationId = destId;
123 destinationStore_.onGetCapabilitiesFail_(failEvent);
124 expectTrue(nativeLayerMock.didGetCapabilitiesOnce(destId));
125 }.bind(this));
126
127 return resolver;
128 };
129
130 function requestSetup(destId, destinationSearch) { 105 function requestSetup(destId, destinationSearch) {
131 var origin = cr.isChromeOS ? print_preview.DestinationOrigin.CROS : 106 var origin = cr.isChromeOS ? print_preview.DestinationOrigin.CROS :
132 print_preview.DestinationOrigin.LOCAL; 107 print_preview.DestinationOrigin.LOCAL;
133 108
134 var dest = new print_preview.Destination(destId, 109 var dest = new print_preview.Destination(destId,
135 print_preview.DestinationType.LOCAL, 110 print_preview.DestinationType.LOCAL,
136 origin, 111 origin,
137 "displayName", 112 "displayName",
138 print_preview.DestinationConnectionStatus.ONLINE); 113 print_preview.DestinationConnectionStatus.ONLINE);
139 114
(...skipping 29 matching lines...) Expand all
169 144
170 teardown(function() { 145 teardown(function() {
171 Mock4JS.verifyAllMocks(); 146 Mock4JS.verifyAllMocks();
172 }); 147 });
173 148
174 test('ResolutionFails', function() { 149 test('ResolutionFails', function() {
175 var destId = "001122DEADBEEF"; 150 var destId = "001122DEADBEEF";
176 if (cr.isChromeOS) { 151 if (cr.isChromeOS) {
177 nativeLayer_.setSetupPrinterResponse(true, { printerId: destId, 152 nativeLayer_.setSetupPrinterResponse(true, { printerId: destId,
178 success: false,}); 153 success: false,});
179 requestSetup(destId, destinationSearch_);
180 return nativeLayer_.whenCalled('setupPrinter').then(
181 function(actualDestId) {
182 assertEquals(destId, actualDestId);
183 });
184 } else { 154 } else {
185 var resolver = mockSetupCall(destId, nativeLayer_); 155 nativeLayer_.setLocalDestinationCapabilities({printerId: destId,
186 requestSetup(destId, destinationSearch_); 156 capabilities: getCaps()},
187 resolver.reject(destId); 157 true);
188 } 158 }
159 requestSetup(destId, destinationSearch_);
160 var callback = cr.isChromeOS ? 'setupPrinter' : 'getPrinterCapabilities';
161 return nativeLayer_.whenCalled(callback).then(
162 function(actualDestId) {
163 assertEquals(destId, actualDestId);
164 });
189 }); 165 });
190 166
191 test('ReceiveSuccessfulSetup', function() { 167 test('ReceiveSuccessfulSetup', function() {
192 var destId = "00112233DEADBEEF"; 168 var destId = "00112233DEADBEEF";
193 var response = { 169 var response = {
194 printerId: destId, 170 printerId: destId,
195 capabilities: getCaps(), 171 capabilities: getCaps(),
196 success: true, 172 success: true,
197 }; 173 };
198 if (cr.isChromeOS) 174 if (cr.isChromeOS)
199 nativeLayer_.setSetupPrinterResponse(false, response); 175 nativeLayer_.setSetupPrinterResponse(false, response);
176 else
177 nativeLayer_.setLocalDestinationCapabilities({printerId: destId,
178 capabilities: getCaps()});
200 179
201 var waiter = waitForEvent( 180 var waiter = waitForEvent(
202 destinationStore_, 181 destinationStore_,
203 print_preview.DestinationStore.EventType.DESTINATION_SELECT); 182 print_preview.DestinationStore.EventType.DESTINATION_SELECT);
204 if (cr.isChromeOS) { 183 requestSetup(destId, destinationSearch_);
205 requestSetup(destId, destinationSearch_); 184 var callback = cr.isChromeOS ? 'setupPrinter' : 'getPrinterCapabilities';
206 return Promise.all([ 185 return Promise.all([nativeLayer_.whenCalled(callback), waiter]).then(
207 nativeLayer_.whenCalled('setupPrinter'), waiter 186 function(results) {
208 ]).then(function(results) { 187 assertEquals(destId, results[0]);
209 assertEquals(destId, results[0]); 188 // after setup succeeds, the destination should be selected.
210 189 assertNotEquals(null, destinationStore_.selectedDestination);
211 // after setup succeeds and event arrives, the destination should 190 assertEquals(destId, destinationStore_.selectedDestination.id);
212 // be selected. 191 });
213 assertNotEquals(null, destinationStore_.selectedDestination);
214 assertEquals(destId, destinationStore_.selectedDestination.id);
215 });
216 } else { //!cr.isChromeOS
217 var resolver = mockSetupCall(destId, nativeLayer_);
218 requestSetup(destId, destinationSearch_);
219 resolver.resolve(response);
220 return waiter.then(function() {
221 // after setup succeeds, the destination should be selected.
222 assertNotEquals(null, destinationStore_.selectedDestination);
223 assertEquals(destId, destinationStore_.selectedDestination.id);
224 });
225 }
226 }); 192 });
227 193
228 if (cr.isChromeOS) { 194 if (cr.isChromeOS) {
229 // The 'ResolutionFails' test covers this case for non-CrOS. 195 // The 'ResolutionFails' test covers this case for non-CrOS.
230 test('ReceiveFailedSetup', function() { 196 test('ReceiveFailedSetup', function() {
231 var destId = '00112233DEADBEEF'; 197 var destId = '00112233DEADBEEF';
232 var response = { 198 var response = {
233 printerId: destId, 199 printerId: destId,
234 capabilities: getCaps(), 200 capabilities: getCaps(),
235 success: false, 201 success: false,
(...skipping 26 matching lines...) Expand all
262 // Simulate a click. 228 // Simulate a click.
263 dest.onActivate_(); 229 dest.onActivate_();
264 230
265 // Verify that the destination has been selected. 231 // Verify that the destination has been selected.
266 assertEquals(printerId, destinationStore_.selectedDestination.id); 232 assertEquals(printerId, destinationStore_.selectedDestination.id);
267 }); 233 });
268 }); 234 });
269 235
270 mocha.run(); 236 mocha.run();
271 }); 237 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/print_preview/native_layer_stub.js ('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