Chromium Code Reviews| Index: chrome/test/data/webui/print_preview_destination_search_test.js |
| diff --git a/chrome/test/data/webui/print_preview_destination_search_test.js b/chrome/test/data/webui/print_preview_destination_search_test.js |
| index e63db9d7c56e5214df5340d17e90c9fc5e3ab8d9..6eac908b83f3efb89d428f5529cb4314a65283c2 100644 |
| --- a/chrome/test/data/webui/print_preview_destination_search_test.js |
| +++ b/chrome/test/data/webui/print_preview_destination_search_test.js |
| @@ -27,7 +27,7 @@ PrintPreviewDestinationSearchTest.prototype = { |
| extraLibraries: PolymerTest.getLibraries(ROOT_PATH), |
| }; |
| -TEST_F('PrintPreviewDestinationSearchTest', 'DISABLED_Select', function() { |
| +TEST_F('PrintPreviewDestinationSearchTest', 'Select', function() { |
| var self = this; |
| suite('DestinationSearchTest', function() { |
| @@ -98,21 +98,66 @@ TEST_F('PrintPreviewDestinationSearchTest', 'DISABLED_Select', function() { |
| }); |
| }; |
| - function requestSetup(destId, nativeLayerMock, destinationSearch) { |
| + function mockSetupCall(destId, nativeLayerMock) { |
| + var resolver = new PromiseResolver(); |
| + |
| + 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.
|
| + nativeLayerMock.expects(once()).startGetLocalDestinationCapabilities( |
| + destId); |
| + resolver.promise.then(function(result) { |
| + // Simulate the native layer dispatching capabilities. |
| + var capsSetEvent = |
| + new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET); |
| + capsSetEvent.settingsInfo = result; |
| + destinationStore_.onLocalDestinationCapabilitiesSet_(capsSetEvent); |
| + }.bind(this), function() { |
| + var failEvent = new Event( |
| + print_preview.NativeLayer.EventType.GET_CAPABILITIES_FAIL); |
| + failEvent.destinationId = destId; |
| + destinationStore_.onGetCapabilitiesFail_(failEvent); |
| + }.bind(this)); |
| + |
| + return resolver; |
| + } |
| + |
| + nativeLayerMock.expects(once()).setupPrinter(destId) |
| + .will(returnValue(resolver.promise)); |
| + |
| + return resolver; |
| + }; |
| + |
| + function requestSetup(destId, destinationSearch) { |
| + var origin = cr.isChromeOS ? print_preview.Destination.Origin.CROS : |
| + print_preview.Destination.Origin.LOCAL; |
| + |
| var dest = new print_preview.Destination(destId, |
| print_preview.Destination.Type.LOCAL, |
| - print_preview.Destination.Origin.CROS, |
| + origin, |
| "displayName", |
| print_preview.Destination.ConnectionStatus.ONLINE); |
| - var resolver = new PromiseResolver(); |
| - nativeLayerMock.expects(once()).setupPrinter(destId). |
| - will(returnValue(resolver.promise)); |
| - destinationSearch.handleOnDestinationSelect_(dest); |
| - return resolver; |
| + // Add the destination to the list. |
| + destinationSearch.localList_.updateDestinations([dest]); |
| + |
| + // Select destination. |
| + if (cr.isChromeOS) { |
| + destinationSearch.handleConfigureDestination_(dest); |
| + } else { |
| + destinationSearch.handleOnDestinationSelect_(dest); |
| + } |
| }; |
| function resolveSetup(resolver, printerId, success, capabilities) { |
| + 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
|
| + var result = { |
| + printerId: printerId, |
| + capabilities: capabilities, |
| + }; |
| + |
| + resolver.resolve(result); |
| + return; |
| + } |
| + |
| var response = { |
| printerId: printerId, |
| capabilities: capabilities, |
| @@ -145,19 +190,30 @@ TEST_F('PrintPreviewDestinationSearchTest', 'DISABLED_Select', function() { |
| }); |
| test('ResolutionFails', function() { |
| + if (!cr.isChromeOS) { |
| + // Capabilities failure logs a console error for non-CrOS printers. |
| + // TODO(crbug.com/708739): Handle this gracefully and activate test. |
| + return; |
| + } |
| + |
| var destId = "001122DEADBEEF"; |
| - var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); |
| + |
| + var resolver = mockSetupCall(destId, nativeLayer_); |
| + requestSetup(destId, destinationSearch_); |
| resolver.reject(destId); |
| }); |
| test('ReceiveSuccessfulSetup', function() { |
| + |
| var destId = "00112233DEADBEEF"; |
| - var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); |
| - waiter = waitForEvent( |
| + var waiter = waitForEvent( |
| destinationStore_, |
| print_preview.DestinationStore.EventType.DESTINATION_SELECT); |
| + var resolver = mockSetupCall(destId, nativeLayer_); |
| + |
| + requestSetup(destId, destinationSearch_); |
| resolveSetup(resolver, destId, true, getCaps()); |
| // wait for event propogation to complete. |
| @@ -170,17 +226,17 @@ TEST_F('PrintPreviewDestinationSearchTest', 'DISABLED_Select', function() { |
| test('ReceiveFailedSetup', function() { |
| var destId = '00112233DEADBEEF'; |
| - var resolver = requestSetup(destId, nativeLayer_, destinationSearch_); |
| - waiter = waitForEvent( |
| - destinationStore_, |
| - print_preview.DestinationStore.EventType.PRINTER_CONFIGURED); |
| + var resolver = mockSetupCall(destId, nativeLayer_); |
| + requestSetup(destId, destinationSearch_); |
| + // Force resolution to fail. |
| resolveSetup(resolver, destId, false, null); |
| - return waiter.then(function() { |
| + 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.
|
| + // Selection should not change on ChromeOS. |
| assertEquals(null, destinationStore_.selectedDestination); |
| - }); |
| + } |
| }); |
| }); |