Chromium Code Reviews| 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) { | |
|
Lei Zhang
2017/04/05 21:54:31
If it's all the same, put the isChromeOS case insi
skau
2017/04/05 23:41:09
Done.
| |
| 105 nativeLayerMock.expects(once()).startGetLocalDestinationCapabilities( | |
| 106 destId); | |
| 107 resolver.promise.then(function(result) { | |
| 108 // Simulate the native layer dispatching capabilities. | |
| 109 var capsSetEvent = | |
| 110 new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); | |
| 111 capsSetEvent.settingsInfo = result; | |
| 112 destinationStore_.onLocalDestinationCapabilitiesSet_(capsSetEvent); | |
| 113 }.bind(this), function() { | |
| 114 var failEvent = new Event( | |
| 115 print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL); | |
| 116 failEvent.destinationId = destId; | |
| 117 destinationStore_.onGetCapabilitiesFail_(failEvent); | |
| 118 }.bind(this)); | |
| 119 | |
| 120 return resolver; | |
| 121 } | |
| 122 | |
| 123 nativeLayerMock.expects(once()).setupPrinter(destId) | |
| 124 .will(returnValue(resolver.promise)); | |
| 125 | |
| 126 return resolver; | |
| 127 }; | |
| 128 | |
| 129 function requestSetup(destId, destinationSearch) { | |
| 130 var origin = cr.isChromeOS ? print_preview.Destination.Origin.CROS : | |
| 131 print_preview.Destination.Origin.LOCAL; | |
| 132 | |
| 102 var dest = new print_preview.Destination(destId, | 133 var dest = new print_preview.Destination(destId, |
| 103 print_preview.Destination.Type.LOCAL, | 134 print_preview.Destination.Type.LOCAL, |
| 104 print_preview.Destination.Origin.CROS, | 135 origin, |
| 105 "displayName", | 136 "displayName", |
| 106 print_preview.Destination.ConnectionStatus.ONLINE); | 137 print_preview.Destination.ConnectionStatus.ONLINE); |
| 107 | 138 |
| 108 var resolver = new PromiseResolver(); | 139 // Add the destination to the list. |
| 109 nativeLayerMock.expects(once()).setupPrinter(destId). | 140 destinationSearch.localList_.updateDestinations([dest]); |
| 110 will(returnValue(resolver.promise)); | 141 |
| 111 destinationSearch.handleOnDestinationSelect_(dest); | 142 // Select destination. |
| 112 return resolver; | 143 if (cr.isChromeOS) { |
| 144 destinationSearch.handleConfigureDestination_(dest); | |
| 145 } else { | |
| 146 destinationSearch.handleOnDestinationSelect_(dest); | |
| 147 } | |
| 113 }; | 148 }; |
| 114 | 149 |
| 115 function resolveSetup(resolver, printerId, success, capabilities) { | 150 function resolveSetup(resolver, printerId, success, capabilities) { |
| 151 if (!cr.isChromeOS) { | |
|
Lei Zhang
2017/04/05 21:54:31
Why omit the success key/value for non-ChromeOS no
skau
2017/04/05 23:41:09
non-ChromeOS doesn't read the success value. But
| |
| 152 var result = { | |
| 153 printerId: printerId, | |
| 154 capabilities: capabilities, | |
| 155 }; | |
| 156 | |
| 157 resolver.resolve(result); | |
| 158 return; | |
| 159 } | |
| 160 | |
| 116 var response = { | 161 var response = { |
| 117 printerId: printerId, | 162 printerId: printerId, |
| 118 capabilities: capabilities, | 163 capabilities: capabilities, |
| 119 success: success | 164 success: success |
| 120 }; | 165 }; |
| 121 | 166 |
| 122 resolver.resolve(response); | 167 resolver.resolve(response); |
| 123 } | 168 } |
| 124 | 169 |
| 125 setup(function() { | 170 setup(function() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 138 destinationSearch_ = new print_preview.DestinationSearch( | 183 destinationSearch_ = new print_preview.DestinationSearch( |
| 139 destinationStore_, invitationStore_, userInfo_); | 184 destinationStore_, invitationStore_, userInfo_); |
| 140 destinationSearch_.decorate($('destination-search')); | 185 destinationSearch_.decorate($('destination-search')); |
| 141 }); | 186 }); |
| 142 | 187 |
| 143 teardown(function() { | 188 teardown(function() { |
| 144 Mock4JS.verifyAllMocks(); | 189 Mock4JS.verifyAllMocks(); |
| 145 }); | 190 }); |
| 146 | 191 |
| 147 test('ResolutionFails', function() { | 192 test('ResolutionFails', function() { |
| 193 if (!cr.isChromeOS) { | |
| 194 // Capabilities failure logs a console error for non-CrOS printers. | |
| 195 // TODO(crbug.com/708739): Handle this gracefully and activate test. | |
| 196 return; | |
| 197 } | |
| 198 | |
| 148 var destId = "001122DEADBEEF"; | 199 var destId = "001122DEADBEEF"; |
| 149 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); | 200 |
| 201 var resolver = mockSetupCall(destId, nativeLayer_); | |
| 202 requestSetup(destId, destinationSearch_); | |
| 150 resolver.reject(destId); | 203 resolver.reject(destId); |
| 151 }); | 204 }); |
| 152 | 205 |
| 153 test('ReceiveSuccessfulSetup', function() { | 206 test('ReceiveSuccessfulSetup', function() { |
| 207 | |
| 154 var destId = "00112233DEADBEEF"; | 208 var destId = "00112233DEADBEEF"; |
| 155 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); | |
| 156 | 209 |
| 157 waiter = waitForEvent( | 210 var waiter = waitForEvent( |
| 158 destinationStore_, | 211 destinationStore_, |
| 159 print_preview.DestinationStore.EventType.DESTINATION_SELECT); | 212 print_preview.DestinationStore.EventType.DESTINATION_SELECT); |
| 160 | 213 |
| 214 var resolver = mockSetupCall(destId, nativeLayer_); | |
| 215 | |
| 216 requestSetup(destId, destinationSearch_); | |
| 161 resolveSetup(resolver, destId, true, getCaps()); | 217 resolveSetup(resolver, destId, true, getCaps()); |
| 162 | 218 |
| 163 // wait for event propogation to complete. | 219 // wait for event propogation to complete. |
| 164 return waiter.then(function() { | 220 return waiter.then(function() { |
| 165 // after setup succeeds, the destination should be selected. | 221 // after setup succeeds, the destination should be selected. |
| 166 assertNotEquals(null, destinationStore_.selectedDestination); | 222 assertNotEquals(null, destinationStore_.selectedDestination); |
| 167 assertEquals(destId, destinationStore_.selectedDestination.id); | 223 assertEquals(destId, destinationStore_.selectedDestination.id); |
| 168 }); | 224 }); |
| 169 }); | 225 }); |
| 170 | 226 |
| 171 test('ReceiveFailedSetup', function() { | 227 test('ReceiveFailedSetup', function() { |
| 172 var destId = '00112233DEADBEEF'; | 228 var destId = '00112233DEADBEEF'; |
| 173 var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); | |
| 174 | 229 |
| 175 waiter = waitForEvent( | 230 var resolver = mockSetupCall(destId, nativeLayer_); |
| 176 destinationStore_, | 231 requestSetup(destId, destinationSearch_); |
| 177 print_preview.DestinationStore.EventType.PRINTER_CONFIGURED); | |
| 178 | 232 |
| 233 // Force resolution to fail. | |
| 179 resolveSetup(resolver, destId, false, null); | 234 resolveSetup(resolver, destId, false, null); |
| 180 | 235 |
| 181 return waiter.then(function() { | 236 if (cr.isChromeOS) { |
|
Lei Zhang
2017/04/05 21:54:32
How about the non-ChromeOS case?
skau
2017/04/05 23:41:09
I've added the non-CrOS case. It's a bit weird as
Lei Zhang
2017/04/05 23:46:05
Thanks.
| |
| 237 // Selection should not change on ChromeOS. | |
| 182 assertEquals(null, destinationStore_.selectedDestination); | 238 assertEquals(null, destinationStore_.selectedDestination); |
| 183 }); | 239 } |
| 184 }); | 240 }); |
| 185 }); | 241 }); |
| 186 | 242 |
| 187 mocha.run(); | 243 mocha.run(); |
| 188 }); | 244 }); |
| OLD | NEW |