Commit 77a34cfd authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Make chrome://media-app tests using loadFiles() more deterministic.

The media app has the ability to "interrupt" image decodes by revoking
Blob URLs, but this makes tests confusing.

Update the chrome://media-app tests to properly propagate the
completion of image loads on the initial loads and on navigation.

Bug: b/152729704
Change-Id: Iaca65ac183f5fd4cfa5f84be93c724266e4ae4fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127996Reviewed-by: default avatardstockwell <dstockwell@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754790}
parent 8002cc2e
......@@ -91,14 +91,17 @@ guestMessagePipe.registerHandler(Message.DELETE_FILE, async (message) => {
return {deleteResult: DeleteResult.SUCCESS};
});
guestMessagePipe.registerHandler(Message.NAVIGATE, (message) => {
guestMessagePipe.registerHandler(Message.NAVIGATE, async (message) => {
const navigate = /** @type {NavigateMessage} */ (message);
advance(navigate.direction);
await advance(navigate.direction);
});
/** Loads the current file list into the guest. */
function sendFilesToGuest() {
/**
* Loads the current file list into the guest.
* @return {!Promise<undefined>}
*/
async function sendFilesToGuest() {
// Before sending to guest ensure writableFileIndex is set to be writable,
// also clear the old token.
if (currentlyWritableFile) {
......@@ -113,7 +116,7 @@ function sendFilesToGuest() {
// Handle can't be passed through a message pipe.
files: currentFiles.map(fd => ({token: fd.token, file: fd.file}))
};
guestMessagePipe.sendMessage(Message.LOAD_FILES, loadFilesMessage);
await guestMessagePipe.sendMessage(Message.LOAD_FILES, loadFilesMessage);
}
/**
......@@ -185,7 +188,7 @@ async function advance(direction) {
entryIndex += currentFiles.length;
}
sendFilesToGuest();
await sendFilesToGuest();
}
document.querySelector('#prev-container')
......
......@@ -104,7 +104,11 @@ class ReceivedFileList {
* @return {!Promise<undefined>}
*/
async loadNext() {
parentMessagePipe.sendMessage(Message.NAVIGATE, {direction: 1});
// Awaiting this message send allows callers to wait for the full effects of
// the navigation to complete. This may include a call to load a new set of
// files, and the initial decode, which replaces this AbstractFileList and
// alters other app state.
await parentMessagePipe.sendMessage(Message.NAVIGATE, {direction: 1});
}
/**
......@@ -112,13 +116,13 @@ class ReceivedFileList {
* @return {!Promise<undefined>}
*/
async loadPrev() {
parentMessagePipe.sendMessage(Message.NAVIGATE, {direction: -1});
await parentMessagePipe.sendMessage(Message.NAVIGATE, {direction: -1});
}
}
parentMessagePipe.registerHandler(Message.LOAD_FILES, (message) => {
parentMessagePipe.registerHandler(Message.LOAD_FILES, async (message) => {
const filesMessage = /** @type{!LoadFilesMessage} */ (message);
loadFiles(new ReceivedFileList(filesMessage));
await loadFiles(new ReceivedFileList(filesMessage));
});
/**
......@@ -147,12 +151,14 @@ function getApp() {
/**
* Loads a file list into the media app.
* @param {!ReceivedFileList} fileList
* @return {!Promise<undefined>}
*/
async function loadFiles(fileList) {
const app = getApp();
if (app) {
await app.loadFiles(fileList);
} else {
// Note we don't await in this case, which may affect b/152729704.
window.customLaunchData = {files: fileList};
}
}
......
......@@ -196,6 +196,7 @@ function loadFile(file, handle) {
/**
* Helper to send multiple file to the guest.
* @param {!Array<{file: !File, handle: !FileSystemFileHandle}>} files
* @return {!Promise<undefined>}
*/
function loadMultipleFiles(files) {
currentFiles.length = 0;
......@@ -203,5 +204,5 @@ function loadMultipleFiles(files) {
currentFiles.push({token: -1, file: f.file, handle: f.handle});
}
entryIndex = 0;
sendFilesToGuest();
return sendFilesToGuest();
}
......@@ -141,7 +141,7 @@ function installTestHandlers() {
const realLoadFiles = loadFiles;
loadFiles = async (/** !ReceivedFileList */ fileList) => {
lastReceivedFileList = fileList;
realLoadFiles(fileList);
return realLoadFiles(fileList);
};
signalTestHandlersReady();
}
......
......@@ -237,7 +237,7 @@ TEST_F('MediaAppUIBrowserTest', 'DeleteOriginalIPC', async () => {
// Tests the IPC behind the loadNext and loadPrev functions on the received file
// list in the untrusted context.
TEST_F('MediaAppUIBrowserTest', 'NavigateIPC', async () => {
loadMultipleFiles([
await loadMultipleFiles([
{file: await createTestImageFile(), handle: new FakeFileSystemFileHandle()},
{file: await createTestImageFile(), handle: new FakeFileSystemFileHandle()}
]);
......
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