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

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

Issue 2881213003: Print Preview: Use cr.sendWithPromise for getInitialSettings (Closed)
Patch Set: Remove extra code copied from print preview tests 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
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 /**
11 * Test fixture for DestinationSearch of Print Preview. 11 * Test fixture for DestinationSearch of Print Preview.
12 * @constructor 12 * @constructor
13 * @extends {PolymerTest} 13 * @extends {PolymerTest}
14 */ 14 */
15 function PrintPreviewDestinationSearchTest() {} 15 function PrintPreviewDestinationSearchTest() {}
16 16
17 PrintPreviewDestinationSearchTest.prototype = { 17 PrintPreviewDestinationSearchTest.prototype = {
18 __proto__: PolymerTest.prototype, 18 __proto__: PolymerTest.prototype,
19 19
20 /** @override */ 20 /** @override */
21 browsePreload: 'chrome://print', 21 browsePreload: 'chrome://print',
22 22
23 /** @override */ 23 /** @override */
24 runAccessibilityChecks: false, 24 runAccessibilityChecks: false,
25 25
26 /** @override */ 26 /** @override */
27 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), 27 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
28 ROOT_PATH + 'chrome/test/data/webui/settings/test_browser_proxy.js',
29 ]),
30
28 }; 31 };
29 32
30 TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { 33 TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() {
31 var self = this; 34 var self = this;
32 35
33 suite('DestinationSearchTest', function() { 36 suite('DestinationSearchTest', function() {
34 var root_; 37 var root_;
35 38
36 var destinationSearch_; 39 var destinationSearch_;
37 var nativeLayer_; 40 var nativeLayer_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 }; 98 };
96 99
97 element.addEventListener(eventName, listener); 100 element.addEventListener(eventName, listener);
98 }); 101 });
99 }; 102 };
100 103
101 function mockSetupCall(destId, nativeLayerMock) { 104 function mockSetupCall(destId, nativeLayerMock) {
102 var resolver = new PromiseResolver(); 105 var resolver = new PromiseResolver();
103 106
104 if (cr.isChromeOS) { 107 if (cr.isChromeOS) {
105 nativeLayerMock.expects(once()).setupPrinter(destId). 108 nativeLayerMock.whenCalled('setupPrinter').
106 will(returnValue(resolver.promise)); 109 will(returnValue(resolver.promise));
107 110
108 return resolver; 111 return resolver;
109 } 112 }
110 113
111 nativeLayerMock.expects(once()).startGetLocalDestinationCapabilities( 114 nativeLayerMock.setDestinationToWatch(destId);
112 destId);
113 resolver.promise.then( 115 resolver.promise.then(
114 function(result) { 116 function(result) {
115 // Simulate the native layer dispatching capabilities. 117 // Simulate the native layer dispatching capabilities.
116 var capsSetEvent = 118 var capsSetEvent =
117 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); 119 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
118 capsSetEvent.settingsInfo = result; 120 capsSetEvent.settingsInfo = result;
119 destinationStore_.onLocalDestinationCapabilitiesSet_(capsSetEvent); 121 destinationStore_.onLocalDestinationCapabilitiesSet_(capsSetEvent);
122 expectTrue(nativeLayerMock.didGetCapabilitiesOnce(destId));
120 }.bind(this), 123 }.bind(this),
121 function() { 124 function() {
122 var failEvent = new Event( 125 var failEvent = new Event(
123 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL); 126 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL);
124 failEvent.destinationId = destId; 127 failEvent.destinationId = destId;
125 destinationStore_.onGetCapabilitiesFail_(failEvent); 128 destinationStore_.onGetCapabilitiesFail_(failEvent);
129 expectTrue(nativeLayerMock.didGetCapabilitiesOnce(destId));
126 }.bind(this)); 130 }.bind(this));
127 131
128 return resolver; 132 return resolver;
129 }; 133 };
130 134
131 function requestSetup(destId, destinationSearch) { 135 function requestSetup(destId, destinationSearch) {
132 var origin = cr.isChromeOS ? print_preview.DestinationOrigin.CROS : 136 var origin = cr.isChromeOS ? print_preview.DestinationOrigin.CROS :
133 print_preview.DestinationOrigin.LOCAL; 137 print_preview.DestinationOrigin.LOCAL;
134 138
135 var dest = new print_preview.Destination(destId, 139 var dest = new print_preview.Destination(destId,
(...skipping 16 matching lines...) Expand all
152 function resolveSetup(resolver, printerId, success, capabilities) { 156 function resolveSetup(resolver, printerId, success, capabilities) {
153 var response = { 157 var response = {
154 printerId: printerId, 158 printerId: printerId,
155 capabilities: capabilities, 159 capabilities: capabilities,
156 success: success 160 success: success
157 }; 161 };
158 162
159 resolver.resolve(response); 163 resolver.resolve(response);
160 } 164 }
161 165
166 /**
167 * Test version of the native layer.
168 * @constructor
169 * @extends {settings.TestBrowserProxy}
170 */
171 function NativeLayerStub() {
172 settings.TestBrowserProxy.call(this, [ 'getInitialSettings' ]);
173 this.destinationToWatch_ = '';
174 this.eventTarget_ = mock(cr.EventTarget);
175 this.getLocalDestinationCapabilitiesCallCount_ = 0;
176 }
177
178 NativeLayerStub.prototype = {
179 __proto__: settings.TestBrowserProxy.prototype,
180 didGetCapabilitiesOnce: function(destinationId) {
181 return (destinationId == this.destinationToWatch_ &&
182 this.getLocalDestinationCapabilitiesCallCount_ == 1);
183 },
184 getEventTarget: function() { return this.eventTarget_; },
185 setDestinationToWatch: function(destinationId) {
186 this.destinationToWatch_ = destinationId;
187 this.getLocalDestinationCapabilitiesCallCount_ = 0;
188 },
189 setupPrinter: function() {
190 this.methodCalled('setupPrinter');
191 },
192 startGetLocalDestinationCapabilities: function(destinationId) {
193 if (destinationId == this.destinationToWatch_)
194 this.getLocalDestinationCapabilitiesCallCount_++;
195 },
196 startHideDialog: function () {},
197 };
198 NativeLayerStub.EventType = print_preview.NativeLayer.EventType;
199
162 setup(function() { 200 setup(function() {
163 Mock4JS.clearMocksToVerify(); 201 Mock4JS.clearMocksToVerify();
164 202 nativeLayer_ = new NativeLayerStub();
165 nativeLayer_ = mock(print_preview.NativeLayer); 203 var nativeLayerEventTarget = nativeLayer_.getEventTarget();
166 nativeLayer_.expects(atLeastOnce()) 204 nativeLayerEventTarget.expects(atLeastOnce())
167 .addEventListener(ANYTHING, ANYTHING, ANYTHING); 205 .addEventListener(ANYTHING, ANYTHING, ANYTHING);
168 206
169 invitationStore_ = new print_preview.InvitationStore(); 207 invitationStore_ = new print_preview.InvitationStore();
208 var nativeLayerProxy = nativeLayer_;
209 nativeLayerProxy.eventTarget_ = nativeLayerEventTarget.proxy();
170 destinationStore_ = new print_preview.DestinationStore( 210 destinationStore_ = new print_preview.DestinationStore(
171 nativeLayer_.proxy(), new print_preview.UserInfo(), 211 nativeLayerProxy, new print_preview.UserInfo(),
172 new print_preview.AppState()); 212 new print_preview.AppState());
173 userInfo_ = new print_preview.UserInfo(); 213 userInfo_ = new print_preview.UserInfo();
174 214
175 destinationSearch_ = new print_preview.DestinationSearch( 215 destinationSearch_ = new print_preview.DestinationSearch(
176 destinationStore_, invitationStore_, userInfo_); 216 destinationStore_, invitationStore_, userInfo_);
177 destinationSearch_.decorate($('destination-search')); 217 destinationSearch_.decorate($('destination-search'));
178 }); 218 });
179 219
180 teardown(function() { 220 teardown(function() {
181 Mock4JS.verifyAllMocks(); 221 Mock4JS.verifyAllMocks();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Simulate a click. 282 // Simulate a click.
243 dest.onActivate_(); 283 dest.onActivate_();
244 284
245 // Verify that the destination has been selected. 285 // Verify that the destination has been selected.
246 assertEquals(printerId, destinationStore_.selectedDestination.id); 286 assertEquals(printerId, destinationStore_.selectedDestination.id);
247 }); 287 });
248 }); 288 });
249 289
250 mocha.run(); 290 mocha.run();
251 }); 291 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698