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) => { ...@@ -94,7 +94,7 @@ guestMessagePipe.registerHandler(Message.OVERWRITE_FILE, async (message) => {
* @param {string} fileName * @param {string} fileName
* @param {string} errorName * @param {string} errorName
* @param {!OverwriteFileMessage} overwrite * @param {!OverwriteFileMessage} overwrite
* @return {!Promise<!OverwriteFileResponse>} * @return {!Promise<!OverwriteViaFilePickerResponse>}
*/ */
async function pickFileForFailedOverwrite(fileName, errorName, overwrite) { async function pickFileForFailedOverwrite(fileName, errorName, overwrite) {
const fileHandle = await pickWritableFile(fileName, overwrite.blob.type); const fileHandle = await pickWritableFile(fileName, overwrite.blob.type);
......
...@@ -9,15 +9,6 @@ ...@@ -9,15 +9,6 @@
* TODO(b/142750452): Convert this file to ES6. * 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 */
const mediaApp = {}; const mediaApp = {};
...@@ -66,7 +57,7 @@ mediaApp.AbstractFile.prototype.error; ...@@ -66,7 +57,7 @@ mediaApp.AbstractFile.prototype.error;
* rejects. Upon success, `size` will reflect the new file size. * rejects. Upon success, `size` will reflect the new file size.
* If null, then in-place overwriting is not supported for this file. * If null, then in-place overwriting is not supported for this file.
* Note the "overwrite" may be simulated with a download operation. * 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; mediaApp.AbstractFile.prototype.overwriteOriginal;
/** /**
......
...@@ -72,6 +72,15 @@ let LoadFilesMessage; ...@@ -72,6 +72,15 @@ let LoadFilesMessage;
*/ */
let OverwriteFileMessage; 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 * Message sent by the unprivileged context to the privileged context requesting
* the app be relaunched with the next/previous file in the current directory * the app be relaunched with the next/previous file in the current directory
......
...@@ -36,14 +36,16 @@ class ReceivedFile { ...@@ -36,14 +36,16 @@ class ReceivedFile {
/** @type {!OverwriteFileMessage} */ /** @type {!OverwriteFileMessage} */
const message = {token: this.token, blob: blob}; const message = {token: this.token, blob: blob};
const result = /** @type {!OverwriteFileResponse} */ ( const result = /** @type {!OverwriteViaFilePickerResponse} */ (
await parentMessagePipe.sendMessage(Message.OVERWRITE_FILE, message)); await parentMessagePipe.sendMessage(Message.OVERWRITE_FILE, message));
// Note the following are skipped if an exception is thrown above. // 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.blob = blob;
this.size = blob.size; this.size = blob.size;
this.mimeType = blob.type; this.mimeType = blob.type;
return result;
} }
/** /**
......
...@@ -55,8 +55,12 @@ async function runTestQuery(data) { ...@@ -55,8 +55,12 @@ async function runTestQuery(data) {
} }
} else if (data.overwriteLastFile) { } else if (data.overwriteLastFile) {
const testBlob = new Blob([data.overwriteLastFile]); const testBlob = new Blob([data.overwriteLastFile]);
extraResultData = await assertCast(firstReceivedItem().overwriteOriginal) const file = firstReceivedItem();
.call(firstReceivedItem(), testBlob); await assertCast(file.overwriteOriginal).call(file, testBlob);
extraResultData = {
receiverFileName: file.name,
receiverErrorName: file.error
};
result = 'overwriteOriginal resolved'; result = 'overwriteOriginal resolved';
} else if (data.deleteLastFile) { } else if (data.deleteLastFile) {
try { try {
......
...@@ -488,6 +488,9 @@ TEST_F('MediaAppUIBrowserTest', 'OverwriteOriginalIPC', async () => { ...@@ -488,6 +488,9 @@ TEST_F('MediaAppUIBrowserTest', 'OverwriteOriginalIPC', async () => {
const writeResult = await handle.lastWritable.closePromise; const writeResult = await handle.lastWritable.closePromise;
assertEquals(testResponse.testQueryResult, 'overwriteOriginal resolved'); assertEquals(testResponse.testQueryResult, 'overwriteOriginal resolved');
assertEquals(
testResponse.testQueryResultData['receiverFileName'], 'test_file.png');
assertEquals(testResponse.testQueryResultData['receiverErrorName'], '');
assertEquals(await writeResult.text(), 'Foo'); assertEquals(await writeResult.text(), 'Foo');
assertEquals(handle.lastWritable.writes.length, 1); assertEquals(handle.lastWritable.writes.length, 1);
assertDeepEquals( assertDeepEquals(
...@@ -511,8 +514,10 @@ TEST_F('MediaAppUIBrowserTest', 'OverwriteOriginalPickerFallback', async () => { ...@@ -511,8 +514,10 @@ TEST_F('MediaAppUIBrowserTest', 'OverwriteOriginalPickerFallback', async () => {
const writeResult = await pickedFile.lastWritable.closePromise; const writeResult = await pickedFile.lastWritable.closePromise;
assertEquals(testResponse.testQueryResult, 'overwriteOriginal resolved'); assertEquals(testResponse.testQueryResult, 'overwriteOriginal resolved');
assertEquals(testResponse.testQueryResultData['renamedTo'], 'pickme.png'); assertEquals(
assertEquals(testResponse.testQueryResultData['errorName'], 'FakeError'); testResponse.testQueryResultData['receiverFileName'], 'pickme.png');
assertEquals(
testResponse.testQueryResultData['receiverErrorName'], 'FakeError');
assertEquals(await writeResult.text(), 'Foo'); assertEquals(await writeResult.text(), 'Foo');
assertEquals(pickedFile.lastWritable.writes.length, 1); assertEquals(pickedFile.lastWritable.writes.length, 1);
assertDeepEquals( 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