Commit 746675a1 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Reflect renames on save in the File model for chrome://media-app

Previously it used a return value, but that caused increased coupling.

Just move the updated file properties into the AbstractFile which can
already represent what's needed.

Bug: b/161108779
Change-Id: I6dc4d2e889b8c6d3247af00fa613a8c768f27171
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2300901Reviewed-by: default avatarRachel Carpenter <carpenterr@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789352}
parent b459766a
......@@ -94,7 +94,7 @@ guestMessagePipe.registerHandler(Message.OVERWRITE_FILE, async (message) => {
* @param {string} fileName
* @param {string} errorName
* @param {!OverwriteFileMessage} overwrite
* @return {!Promise<!OverwriteFileResponse>}
* @return {!Promise<!OverwriteViaFilePickerResponse>}
*/
async function pickFileForFailedOverwrite(fileName, errorName, overwrite) {
const fileHandle = await pickWritableFile(fileName, overwrite.blob.type);
......
......@@ -9,15 +9,6 @@
* TODO(b/142750452): Convert this file to ES6.
*/
/**
* Response message to a successful overwrite (no error thrown). If defined,
* indicates that an overwrite failed, but the user was able to select a new
* file from a file picker. The UI should update to reflect the new name.
* `errorName` is the error on the write attempt that triggered the picker.
* @typedef {{renamedTo: string, errorName: string}|undefined}
*/
let OverwriteFileResponse;
/** @const */
const mediaApp = {};
......@@ -66,7 +57,7 @@ mediaApp.AbstractFile.prototype.error;
* rejects. Upon success, `size` will reflect the new file size.
* If null, then in-place overwriting is not supported for this file.
* Note the "overwrite" may be simulated with a download operation.
* @type {function(!Blob): !Promise<!OverwriteFileResponse>}
* @type {function(!Blob): !Promise<undefined>|undefined}
*/
mediaApp.AbstractFile.prototype.overwriteOriginal;
/**
......
......@@ -72,6 +72,15 @@ let LoadFilesMessage;
*/
let OverwriteFileMessage;
/**
* Response message to a successful overwrite (no error thrown). If fields are
* defined, indicates that an overwrite failed, but the user was able to select
* a new file from a file picker. The UI should update to reflect the new name.
* `errorName` is the error on the write attempt that triggered the picker.
* @typedef {{renamedTo: (string|undefined), errorName: (string|undefined)}}
*/
let OverwriteViaFilePickerResponse;
/**
* Message sent by the unprivileged context to the privileged context requesting
* the app be relaunched with the next/previous file in the current directory
......
......@@ -36,14 +36,16 @@ class ReceivedFile {
/** @type {!OverwriteFileMessage} */
const message = {token: this.token, blob: blob};
const result = /** @type {!OverwriteFileResponse} */ (
const result = /** @type {!OverwriteViaFilePickerResponse} */ (
await parentMessagePipe.sendMessage(Message.OVERWRITE_FILE, message));
// Note the following are skipped if an exception is thrown above.
if (result.renamedTo) {
this.name = result.renamedTo;
}
this.error = result.errorName || '';
this.blob = blob;
this.size = blob.size;
this.mimeType = blob.type;
return result;
}
/**
......
......@@ -55,8 +55,12 @@ async function runTestQuery(data) {
}
} else if (data.overwriteLastFile) {
const testBlob = new Blob([data.overwriteLastFile]);
extraResultData = await assertCast(firstReceivedItem().overwriteOriginal)
.call(firstReceivedItem(), testBlob);
const file = firstReceivedItem();
await assertCast(file.overwriteOriginal).call(file, testBlob);
extraResultData = {
receiverFileName: file.name,
receiverErrorName: file.error
};
result = 'overwriteOriginal resolved';
} else if (data.deleteLastFile) {
try {
......
......@@ -488,6 +488,9 @@ TEST_F('MediaAppUIBrowserTest', 'OverwriteOriginalIPC', async () => {
const writeResult = await handle.lastWritable.closePromise;
assertEquals(testResponse.testQueryResult, 'overwriteOriginal resolved');
assertEquals(
testResponse.testQueryResultData['receiverFileName'], 'test_file.png');
assertEquals(testResponse.testQueryResultData['receiverErrorName'], '');
assertEquals(await writeResult.text(), 'Foo');
assertEquals(handle.lastWritable.writes.length, 1);
assertDeepEquals(
......@@ -511,8 +514,10 @@ TEST_F('MediaAppUIBrowserTest', 'OverwriteOriginalPickerFallback', async () => {
const writeResult = await pickedFile.lastWritable.closePromise;
assertEquals(testResponse.testQueryResult, 'overwriteOriginal resolved');
assertEquals(testResponse.testQueryResultData['renamedTo'], 'pickme.png');
assertEquals(testResponse.testQueryResultData['errorName'], 'FakeError');
assertEquals(
testResponse.testQueryResultData['receiverFileName'], 'pickme.png');
assertEquals(
testResponse.testQueryResultData['receiverErrorName'], 'FakeError');
assertEquals(await writeResult.text(), 'Foo');
assertEquals(pickedFile.lastWritable.writes.length, 1);
assertDeepEquals(
......
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