Skip to content

Commit

Permalink
[dpwa] Update the file handler app to load .foo (txt) files.
Browse files Browse the repository at this point in the history
The file name and the content will be displayed in the app after
finished loading.

Bug: 1401133
Change-Id: I90af66fcc5da12b6573ec244cc41093d2165052a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4108946
Reviewed-by: Daniel Murphy <dmurph@chromium.org>
Commit-Queue: Clifford Cheng <cliffordcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1084607}
  • Loading branch information
Clifford Cheng authored and Chromium LUCI CQ committed Dec 16, 2022
1 parent 4243ef0 commit fd8ca9b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
55 changes: 55 additions & 0 deletions chrome/test/data/webapps_integration/file_handler/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


const openedFilesContainer = document.getElementById(
"opened-files-container"
);

const makeFileViewer = async (launchFile) => {
const readHandle = await launchFile.getFile();

const template = document.getElementById("file-viewer-template");
const fullName = readHandle.name;
const element = template.content.cloneNode(true);
const nameContainer = element.querySelector("[name='file-name']");
nameContainer.innerText = fullName;

const contentContainer = element.querySelector("[name='file-contents']");
contentContainer.innerText = "Loading...";
// Asynchronously load in the file contents.
try {
contentContainer.value = await readHandle.text();
} catch (err) {
console.log(`Failed to load contents for file: ${readHandle.name}`, err);
}

return element;
};

var resolveLaunchFinished;

var launchFinishedPromise = new Promise(resolve => {
window.launchQueue.setConsumer(async (launchParams) => {
console.log("Launched with: ", launchParams);
const viewersContainer = document.getElementById("viewers-container");
if (!launchParams.files.length) {
viewersContainer.innerText =
"Oh poo, no files. Consider granting the permission next time!";
return;
}

for (const launchFile of launchParams.files) {
const editor = await makeFileViewer(launchFile);
openedFilesContainer.appendChild(editor);
}
let results = [];
const fileContents = openedFilesContainer.querySelectorAll(
"[name='file-contents']");
for (const fileContent of fileContents) {
results.push(fileContent.value);
}
resolve(results);
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>File Handler - Text Handler</title>
<script src="/webapps_integration/test_utils.js"></script>
<script src="/webapps_integration/file_handler/app.js" async></script>
</head>
<body>
<h1>File Handler - Text Handler</h1>
Expand All @@ -16,5 +17,20 @@ <h1>File Handler - Text Handler</h1>
href="https://chromium.googlesource.com/chromium/src/+/main/docs/webapps/integration-testing-framework.md">https://chromium.googlesource.com/chromium/src/+/main/docs/webapps/integration-testing-framework.md</a>
</p>
</div>
<br>
<div id="viewers-container"></div>
<div id="opened-files-container"></div>
<template id="file-viewer-template">
<div>
<p>File: <span name="file-name"></span></p>
<textarea
name="file-contents"
cols="80"
rows="10"
style="white-space: pre-wrap"
>
</textarea>
</div>
</template>
</body>
</html>

0 comments on commit fd8ca9b

Please sign in to comment.