OLD | NEW |
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), |
28 }; | 28 }; |
29 | 29 |
30 TEST_F('PrintPreviewDestinationSearchTest', 'DISABLED_Select', function() { | 30 TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { |
31 var self = this; | 31 var self = this; |
32 | 32 |
33 suite('DestinationSearchTest', function() { | 33 suite('DestinationSearchTest', function() { |
34 var root_; | 34 var root_; |
35 | 35 |
36 var destinationSearch_; | 36 var destinationSearch_; |
37 var nativeLayer_; | 37 var nativeLayer_; |
38 var invitationStore_; | 38 var invitationStore_; |
39 var destinationStore_; | 39 var destinationStore_; |
40 var userInfo_; | 40 var userInfo_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return new Promise(function(resolve) { | 91 return new Promise(function(resolve) { |
92 var listener = function(e) { | 92 var listener = function(e) { |
93 resolve(); | 93 resolve(); |
94 element.removeEventListener(eventName, listener); | 94 element.removeEventListener(eventName, listener); |
95 }; | 95 }; |
96 | 96 |
97 element.addEventListener(eventName, listener); | 97 element.addEventListener(eventName, listener); |
98 }); | 98 }); |
99 }; | 99 }; |
100 | 100 |
101 function requestSetup(destId, nativeLayerMock, destinationSearch) { | 101 function mockSetupCall(destId, nativeLayerMock) { |
| 102 var resolver = new PromiseResolver(); |
| 103 |
| 104 if (cr.isChromeOS) { |
| 105 nativeLayerMock.expects(once()).setupPrinter(destId). |
| 106 will(returnValue(resolver.promise)); |
| 107 |
| 108 return resolver; |
| 109 } |
| 110 |
| 111 nativeLayerMock.expects(once()).startGetLocalDestinationCapabilities( |
| 112 destId); |
| 113 resolver.promise.then( |
| 114 function(result) { |
| 115 // Simulate the native layer dispatching capabilities. |
| 116 var capsSetEvent = |
| 117 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
| 118 capsSetEvent.settingsInfo = result; |
| 119 destinationStore_.onLocalDestinationCapabilitiesSet_(capsSetEvent); |
| 120 }.bind(this), |
| 121 function() { |
| 122 var failEvent = new Event( |
| 123 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL); |
| 124 failEvent.destinationId = destId; |
| 125 destinationStore_.onGetCapabilitiesFail_(failEvent); |
| 126 }.bind(this)); |
| 127 |
| 128 return resolver; |
| 129 }; |
| 130 |
| 131 function requestSetup(destId, destinationSearch) { |
| 132 var origin = cr.isChromeOS ? print_preview.Destination.Origin.CROS : |
| 133 print_preview.Destination.Origin.LOCAL; |
| 134 |
102 var dest = new print_preview.Destination(destId, | 135 var dest = new print_preview.Destination(destId, |
103 print_preview.Destination.Type.LOCAL, | 136 print_preview.Destination.Type.LOCAL, |
104 print_preview.Destination.Origin.CROS, | 137 origin, |
105 "displayName", | 138 "displayName", |
106 print_preview.Destination.ConnectionStatus.ONLINE); | 139 print_preview.Destination.ConnectionStatus.ONLINE); |
107 | 140 |
108 var resolver = new PromiseResolver(); | 141 // Add the destination to the list. |
109 nativeLayerMock.expects(once()).setupPrinter(destId). | 142 destinationSearch.localList_.updateDestinations([dest]); |
110 will(returnValue(resolver.promise)); | 143 |
111 destinationSearch.handleOnDestinationSelect_(dest); | 144 // Select destination. |
112 return resolver; | 145 if (cr.isChromeOS) { |
| 146 destinationSearch.handleConfigureDestination_(dest); |
| 147 } else { |
| 148 destinationSearch.handleOnDestinationSelect_(dest); |
| 149 } |
113 }; | 150 }; |
114 | 151 |
115 function resolveSetup(resolver, printerId, success, capabilities) { | 152 function resolveSetup(resolver, printerId, success, capabilities) { |
116 var response = { | 153 var response = { |
117 printerId: printerId, | 154 printerId: printerId, |
118 capabilities: capabilities, | 155 capabilities: capabilities, |
119 success: success | 156 success: success |
120 }; | 157 }; |
121 | 158 |
122 resolver.resolve(response); | 159 resolver.resolve(response); |
(...skipping 15 matching lines...) Expand all Loading... |
138 destinationSearch_ = new print_preview.DestinationSearch( | 175 destinationSearch_ = new print_preview.DestinationSearch( |
139 destinationStore_, invitationStore_, userInfo_); | 176 destinationStore_, invitationStore_, userInfo_); |
140 destinationSearch_.decorate($('destination-search')); | 177 destinationSearch_.decorate($('destination-search')); |
141 }); | 178 }); |
142 | 179 |
143 teardown(function() { | 180 teardown(function() { |
144 Mock4JS.verifyAllMocks(); | 181 Mock4JS.verifyAllMocks(); |
145 }); | 182 }); |
146 | 183 |
147 test('ResolutionFails', function() { | 184 test('ResolutionFails', function() { |
| 185 if (!cr.isChromeOS) { |
| 186 // Capabilities failure logs a console error for non-CrOS printers. |
| 187 // TODO(crbug.com/708739): Handle this gracefully and activate test. |
| 188 return; |
| 189 } |
| 190 |
148 var destId = "001122DEADBEEF"; | 191 var destId = "001122DEADBEEF"; |
149 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); | 192 |
| 193 var resolver = mockSetupCall(destId, nativeLayer_); |
| 194 requestSetup(destId, destinationSearch_); |
150 resolver.reject(destId); | 195 resolver.reject(destId); |
151 }); | 196 }); |
152 | 197 |
153 test('ReceiveSuccessfulSetup', function() { | 198 test('ReceiveSuccessfulSetup', function() { |
| 199 |
154 var destId = "00112233DEADBEEF"; | 200 var destId = "00112233DEADBEEF"; |
155 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); | |
156 | 201 |
157 waiter = waitForEvent( | 202 var waiter = waitForEvent( |
158 destinationStore_, | 203 destinationStore_, |
159 print_preview.DestinationStore.EventType.DESTINATION_SELECT); | 204 print_preview.DestinationStore.EventType.DESTINATION_SELECT); |
160 | 205 |
| 206 var resolver = mockSetupCall(destId, nativeLayer_); |
| 207 |
| 208 requestSetup(destId, destinationSearch_); |
161 resolveSetup(resolver, destId, true, getCaps()); | 209 resolveSetup(resolver, destId, true, getCaps()); |
162 | 210 |
163 // wait for event propogation to complete. | 211 // wait for event propogation to complete. |
164 return waiter.then(function() { | 212 return waiter.then(function() { |
165 // after setup succeeds, the destination should be selected. | 213 // after setup succeeds, the destination should be selected. |
166 assertNotEquals(null, destinationStore_.selectedDestination); | 214 assertNotEquals(null, destinationStore_.selectedDestination); |
167 assertEquals(destId, destinationStore_.selectedDestination.id); | 215 assertEquals(destId, destinationStore_.selectedDestination.id); |
168 }); | 216 }); |
169 }); | 217 }); |
170 | 218 |
171 test('ReceiveFailedSetup', function() { | 219 test('ReceiveFailedSetup', function() { |
172 var destId = '00112233DEADBEEF'; | 220 var destId = '00112233DEADBEEF'; |
173 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); | |
174 | 221 |
175 waiter = waitForEvent( | 222 var resolver = mockSetupCall(destId, nativeLayer_); |
176 destinationStore_, | 223 requestSetup(destId, destinationSearch_); |
177 print_preview.DestinationStore.EventType.PRINTER_CONFIGURED); | |
178 | 224 |
| 225 // Force resolution to fail. |
179 resolveSetup(resolver, destId, false, null); | 226 resolveSetup(resolver, destId, false, null); |
180 | 227 |
181 return waiter.then(function() { | 228 if (cr.isChromeOS) { |
| 229 // Selection should not change on ChromeOS. |
182 assertEquals(null, destinationStore_.selectedDestination); | 230 assertEquals(null, destinationStore_.selectedDestination); |
183 }); | 231 } else { |
| 232 // Other code expects selection to be present so it still occurs |
| 233 // for non-CrOS. |
| 234 assertEquals(destId, destinationStore_.selectedDestination.id); |
| 235 } |
184 }); | 236 }); |
185 }); | 237 }); |
186 | 238 |
187 mocha.run(); | 239 mocha.run(); |
188 }); | 240 }); |
OLD | NEW |