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 /** |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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)); | |
|
rbpotter
2017/06/09 10:24:23
I do not think we need this only-called-once check
dpapad
2017/06/09 17:59:11
+1 on removing it.
| |
| 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 Loading... | |
| 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(getCaps(), true); |
| 186 requestSetup(destId, destinationSearch_); | |
| 187 resolver.reject(destId); | |
| 188 } | 156 } |
| 157 requestSetup(destId, destinationSearch_); | |
| 158 var callback = cr.isChromeOS ? 'setupPrinter' : 'getPrinterCapabilities'; | |
| 159 return nativeLayer_.whenCalled(callback).then( | |
| 160 function(actualDestId) { | |
| 161 assertEquals(destId, actualDestId); | |
| 162 }); | |
| 189 }); | 163 }); |
| 190 | 164 |
| 191 test('ReceiveSuccessfulSetup', function() { | 165 test('ReceiveSuccessfulSetup', function() { |
| 192 var destId = "00112233DEADBEEF"; | 166 var destId = "00112233DEADBEEF"; |
| 193 var response = { | 167 var response = { |
| 194 printerId: destId, | 168 printerId: destId, |
| 195 capabilities: getCaps(), | 169 capabilities: getCaps(), |
| 196 success: true, | 170 success: true, |
| 197 }; | 171 }; |
| 198 if (cr.isChromeOS) | 172 if (cr.isChromeOS) |
| 199 nativeLayer_.setSetupPrinterResponse(false, response); | 173 nativeLayer_.setSetupPrinterResponse(false, response); |
| 174 else | |
| 175 nativeLayer_.setLocalDestinationCapabilities(getCaps()); | |
| 200 | 176 |
| 201 var waiter = waitForEvent( | 177 var waiter = waitForEvent( |
| 202 destinationStore_, | 178 destinationStore_, |
| 203 print_preview.DestinationStore.EventType.DESTINATION_SELECT); | 179 print_preview.DestinationStore.EventType.DESTINATION_SELECT); |
| 204 if (cr.isChromeOS) { | 180 requestSetup(destId, destinationSearch_); |
| 205 requestSetup(destId, destinationSearch_); | 181 var callback = cr.isChromeOS ? 'setupPrinter' : 'getPrinterCapabilities'; |
| 206 return Promise.all([ | 182 return Promise.all([nativeLayer_.whenCalled(callback), waiter]).then( |
| 207 nativeLayer_.whenCalled('setupPrinter'), waiter | 183 function(results) { |
| 208 ]).then(function(results) { | 184 assertEquals(destId, results[0]); |
| 209 assertEquals(destId, results[0]); | 185 // after setup succeeds, the destination should be selected. |
| 210 | 186 assertNotEquals(null, destinationStore_.selectedDestination); |
| 211 // after setup succeeds and event arrives, the destination should | 187 assertEquals(destId, destinationStore_.selectedDestination.id); |
| 212 // be selected. | 188 }); |
| 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 }); | 189 }); |
| 227 | 190 |
| 228 if (cr.isChromeOS) { | 191 if (cr.isChromeOS) { |
| 229 // The 'ResolutionFails' test covers this case for non-CrOS. | 192 // The 'ResolutionFails' test covers this case for non-CrOS. |
| 230 test('ReceiveFailedSetup', function() { | 193 test('ReceiveFailedSetup', function() { |
| 231 var destId = '00112233DEADBEEF'; | 194 var destId = '00112233DEADBEEF'; |
| 232 var response = { | 195 var response = { |
| 233 printerId: destId, | 196 printerId: destId, |
| 234 capabilities: getCaps(), | 197 capabilities: getCaps(), |
| 235 success: false, | 198 success: false, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 262 // Simulate a click. | 225 // Simulate a click. |
| 263 dest.onActivate_(); | 226 dest.onActivate_(); |
| 264 | 227 |
| 265 // Verify that the destination has been selected. | 228 // Verify that the destination has been selected. |
| 266 assertEquals(printerId, destinationStore_.selectedDestination.id); | 229 assertEquals(printerId, destinationStore_.selectedDestination.id); |
| 267 }); | 230 }); |
| 268 }); | 231 }); |
| 269 | 232 |
| 270 mocha.run(); | 233 mocha.run(); |
| 271 }); | 234 }); |
| OLD | NEW |