Commit dc58dd03 authored by Gavin Williams's avatar Gavin Williams Committed by Chromium LUCI CQ

scanning: Show toast when cancel fails

When cancel scan request fails, a toast with error message will pop up,
the scan will continue, and the scan progress page will keep showing.

Bug: 1059779
Change-Id: I9ba3a7a29837f55e8b166224949be1d403e3661c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2559496
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832156}
parent 0750b6d8
...@@ -182,6 +182,15 @@ class FakeScanService { ...@@ -182,6 +182,15 @@ class FakeScanService {
return flushTasks(); return flushTasks();
} }
/**
* @param {boolean} success
* @return {!Promise}
*/
simulateCancelComplete(success) {
this.scanJobObserverRemote_.onCancelComplete(success);
return flushTasks();
}
// scanService methods: // scanService methods:
/** @return {!Promise<{scanners: !ScannerArr}>} */ /** @return {!Promise<{scanners: !ScannerArr}>} */
...@@ -541,7 +550,11 @@ export function scanningAppTest() { ...@@ -541,7 +550,11 @@ export function scanningAppTest() {
.then(() => { .then(() => {
// Click the cancel button to cancel the scan. // Click the cancel button to cancel the scan.
cancelButton.click(); cancelButton.click();
return fakeScanService_.cancelScan(); return fakeScanService_.whenCalled('cancelScan');
})
.then(() => {
// Simulate cancel completing successfully.
return fakeScanService_.simulateCancelComplete(true);
}) })
.then(() => { .then(() => {
// After canceling is complete, the scan button should be visible and // After canceling is complete, the scan button should be visible and
...@@ -551,6 +564,64 @@ export function scanningAppTest() { ...@@ -551,6 +564,64 @@ export function scanningAppTest() {
}); });
}); });
test('CancelScanFailed', () => {
const expectedScanners = [
createScanner(firstScannerId, firstScannerName),
];
let capabilities = new Map();
capabilities.set(firstScannerId, firstCapabilities);
/** @type {!CrButtonElement} */
let scanButton;
/** @type {!CrButtonElement} */
let cancelButton;
return initializeScanningApp(expectedScanners, capabilities)
.then(() => {
scanButton =
/** @type {!CrButtonElement} */ (scanningApp.$$('#scanButton'));
cancelButton =
/** @type {!CrButtonElement} */ (scanningApp.$$('#cancelButton'));
return fakeScanService_.whenCalled('getScannerCapabilities');
})
.then(() => {
// Click the Scan button and wait till the scan is started.
scanButton.click();
return fakeScanService_.whenCalled('startScan');
})
.then(() => {
// Simulate a progress update and verify the progress bar and text are
// updated correctly.
return fakeScanService_.simulateProgress(1, 17);
})
.then(() => {
// Click the cancel button to cancel the scan.
cancelButton.click();
assertFalse(scanningApp.$$('#toast').open);
return fakeScanService_.whenCalled('cancelScan');
})
.then(() => {
// Simulate cancel failing.
return fakeScanService_.simulateCancelComplete(false);
})
.then(() => {
// After canceling fails, the error toast should pop up.
assertTrue(scanningApp.$$('#toast').open);
assertEquals(
scanningApp.i18n('cancelFailedToastText'),
scanningApp.$$('#toastText').textContent.trim());
// The scan progress page should still be showing with the cancel
// button visible.
assertTrue(
isVisible(scanningApp.$$('#scanPreview').$$('#scanProgress')));
assertTrue(isVisible(cancelButton));
assertFalse(
isVisible(scanningApp.$$('#scanPreview').$$('#helperText')));
assertFalse(isVisible(scanButton));
});
});
test('ScanFailedToStart', () => { test('ScanFailedToStart', () => {
const expectedScanners = [ const expectedScanners = [
createScanner(firstScannerId, firstScannerName), createScanner(firstScannerId, firstScannerName),
......
...@@ -582,6 +582,9 @@ Try tapping the mic to ask me anything. ...@@ -582,6 +582,9 @@ Try tapping the mic to ask me anything.
<message name="IDS_SCANNING_APP_GET_HELP_LINK_TEXT" desc="The text used for the link that navigates to the Scan app help webpage. This is shown to the user after a scanning error."> <message name="IDS_SCANNING_APP_GET_HELP_LINK_TEXT" desc="The text used for the link that navigates to the Scan app help webpage. This is shown to the user after a scanning error.">
Get help Get help
</message> </message>
<message name="IDS_SCANNING_APP_CANCEL_FAILED_TOAST_TEXT" desc="The error message displayed when a user attempts to cancel a scan job but the cancel request fails.">
Couldn't cancel scanning
</message>
<!-- Diagnostics App --> <!-- Diagnostics App -->
<!-- TODO(michaelcheco): Update with finalized copies of the strings --> <!-- TODO(michaelcheco): Update with finalized copies of the strings -->
......
78e37b5f7d89b511799f4f8c706d997a4f1953d6
\ No newline at end of file
...@@ -256,6 +256,20 @@ Polymer({ ...@@ -256,6 +256,20 @@ Polymer({
this.setAppState_(AppState.READY); this.setAppState_(AppState.READY);
}, },
/**
* Overrides chromeos.scanning.mojom.ScanJobObserverInterface.
* @param {boolean} success
*/
onCancelComplete(success) {
// If the cancel request fails, continue showing the scan progress page.
if (!success) {
this.showToast_('cancelFailedToastText');
return;
}
this.setAppState_(AppState.READY);
},
/** /**
* @param {string} selectedSource * @param {string} selectedSource
* @return {!Array<chromeos.scanning.mojom.PageSize>} * @return {!Array<chromeos.scanning.mojom.PageSize>}
...@@ -414,17 +428,9 @@ Polymer({ ...@@ -414,17 +428,9 @@ Polymer({
/** @private */ /** @private */
onCancelClick_() { onCancelClick_() {
assert(this.appState_ === AppState.SCANNING); assert(this.appState_ === AppState.SCANNING);
this.scanService_.cancelScan(); this.scanService_.cancelScan();
this.setAppState_(AppState.READY);
}, },
/**
* Overrides chromeos.scanning.mojom.ScanJobObserverInterface.
* @param {boolean} success
*/
onCancelComplete(success) {},
/** /**
* Revokes and removes all of the object URLs. * Revokes and removes all of the object URLs.
* @private * @private
......
...@@ -56,6 +56,7 @@ void AddScanningAppStrings(content::WebUIDataSource* html_source) { ...@@ -56,6 +56,7 @@ void AddScanningAppStrings(content::WebUIDataSource* html_source) {
{"appTitle", IDS_SCANNING_APP_TITLE}, {"appTitle", IDS_SCANNING_APP_TITLE},
{"blackAndWhiteOptionText", IDS_SCANNING_APP_BLACK_AND_WHITE_OPTION_TEXT}, {"blackAndWhiteOptionText", IDS_SCANNING_APP_BLACK_AND_WHITE_OPTION_TEXT},
{"cancelButtonText", IDS_SCANNING_APP_CANCEL_BUTTON_TEXT}, {"cancelButtonText", IDS_SCANNING_APP_CANCEL_BUTTON_TEXT},
{"cancelFailedToastText", IDS_SCANNING_APP_CANCEL_FAILED_TOAST_TEXT},
{"colorModeDropdownLabel", IDS_SCANNING_APP_COLOR_MODE_DROPDOWN_LABEL}, {"colorModeDropdownLabel", IDS_SCANNING_APP_COLOR_MODE_DROPDOWN_LABEL},
{"colorOptionText", IDS_SCANNING_APP_COLOR_OPTION_TEXT}, {"colorOptionText", IDS_SCANNING_APP_COLOR_OPTION_TEXT},
{"defaultSourceOptionText", IDS_SCANNING_APP_DEFAULT_SOURCE_OPTION_TEXT}, {"defaultSourceOptionText", IDS_SCANNING_APP_DEFAULT_SOURCE_OPTION_TEXT},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment