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

scanning: Show error toast when saved scan file not found

Show error toast when the user clicks "Show file location" to open the
Files app but the saved scan file no longer exists at its original saved
location.

http://screen/Bufy35SXPNVM7Tp

Bug: 1059779
Change-Id: Id8a08b37f1f957c26ad013f8463b3e8be4c2d338
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566779Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832555}
parent 5875dba5
......@@ -6,7 +6,7 @@ import 'chrome://scanning/scan_done_section.js';
import {ScanningBrowserProxyImpl} from 'chrome://scanning/scanning_browser_proxy.js';
import {assertEquals, assertTrue} from '../../chai_assert.js';
import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js';
import {flushTasks} from '../../test_util.m.js';
import {TestScanningBrowserProxy} from './test_scanning_browser_proxy.js';
......@@ -50,12 +50,33 @@ export function scanDoneSectionTest() {
});
test('showFileLocation', () => {
let fileNotFoundEventFired = false;
scanDoneSection.addEventListener('file-not-found', function() {
fileNotFoundEventFired = true;
});
const lastScannedFilePath = {'path': '/test/path/scan.jpg'};
scanningBrowserProxy.setPathToFile(lastScannedFilePath.path);
scanDoneSection.lastScannedFilePath = lastScannedFilePath;
scanDoneSection.$$('#showFileButton').click();
return flushTasks().then(() => {
assertEquals(1, scanningBrowserProxy.getCallCount('showFileInLocation'));
assertFalse(fileNotFoundEventFired);
});
});
test('showFileLocationFileNotFound', () => {
let fileNotFoundEventFired = false;
scanDoneSection.addEventListener('file-not-found', function() {
fileNotFoundEventFired = true;
});
scanningBrowserProxy.setPathToFile('/wrong/path/file/so/not/found.jpg');
scanDoneSection.lastScannedFilePath = {'path': '/test/path/scan.jpg'};
scanDoneSection.$$('#showFileButton').click();
return flushTasks().then(() => {
assertEquals(1, scanningBrowserProxy.getCallCount('showFileInLocation'));
assertTrue(fileNotFoundEventFired);
});
});
}
......@@ -43,8 +43,7 @@ export class TestScanningBrowserProxy extends TestBrowserProxy {
/** @param {string} pathToFile */
showFileInLocation(pathToFile) {
this.methodCalled('showFileInLocation');
assertEquals(this.pathToFile_, pathToFile);
return Promise.resolve(true);
return Promise.resolve(this.pathToFile_ === pathToFile);
}
/** @param {!SelectedPath} selectedPath */
......
......@@ -591,6 +591,9 @@ Try tapping the mic to ask me anything.
<message name="IDS_SCANNING_APP_CANCELING_SCANNING_TEXT" desc="The text displayed in the scan preview to indicate a scan job is being canceled.">
Canceling scanning
</message>
<message name="IDS_SCANNING_APP_FILE_NOT_FOUND_TOAST_TEXT" desc="The message displayed when attempting to open a saved scan file and it is either missing or deleted.">
File not found
</message>
<!-- Diagnostics App -->
<!-- TODO(michaelcheco): Update with finalized copies of the strings -->
......
e502251c2b1097563fbc7bf0625cf25ac36a1405
\ No newline at end of file
......@@ -58,6 +58,12 @@ Polymer({
/** @private */
showFileInLocation_() {
this.browserProxy_.showFileInLocation(this.lastScannedFilePath.path);
this.browserProxy_.showFileInLocation(this.lastScannedFilePath.path)
.then(
/* @type {boolean} */ (succesful) => {
if (!succesful) {
this.fire('file-not-found');
}
});
},
});
......@@ -173,7 +173,7 @@
</template>
<template is="dom-if" if="[[showDoneSection_]]">
<scan-done-section page-number="[[pageNumber_]]"
on-done-click="onDoneClick_"
on-done-click="onDoneClick_" on-file-not-found="onFileNotFound_"
last-scanned-file-path="[[lastScannedFilePath_]]">
</scan-done-section>
</template>
......
......@@ -536,6 +536,13 @@ Polymer({
/** @private */
onToastMessageKeyChange_() {
this.showToastInfoIcon_ = this.toastMessageKey_ !== 'scanCanceledToastText';
this.showToastHelpLink_ = this.toastMessageKey_ !== 'scanCanceledToastText';
this.showToastHelpLink_ =
this.toastMessageKey_ !== 'scanCanceledToastText' &&
this.toastMessageKey_ !== 'fileNotFoundToastText';
},
/** @private */
onFileNotFound_() {
this.showToast_('fileNotFoundToastText');
},
});
......@@ -62,6 +62,7 @@ void AddScanningAppStrings(content::WebUIDataSource* html_source) {
{"colorOptionText", IDS_SCANNING_APP_COLOR_OPTION_TEXT},
{"defaultSourceOptionText", IDS_SCANNING_APP_DEFAULT_SOURCE_OPTION_TEXT},
{"doneButtonText", IDS_SCANNING_APP_DONE_BUTTON_TEXT},
{"fileNotFoundToastText", IDS_SCANNING_APP_FILE_NOT_FOUND_TOAST_TEXT},
{"fileSavedText", IDS_SCANNING_APP_FILE_SAVED_TEXT},
{"fileSavedTextPlural", IDS_SCANNING_APP_FILE_SAVED_TEXT_PLURAL},
{"fileTypeDropdownLabel", IDS_SCANNING_APP_FILE_TYPE_DROPDOWN_LABEL},
......
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