1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

LibWeb+LibWebView+WebContent: Implement more <input type=file> behavior

We had previous implemented some plumbing for file input elements in
commit 636602a54e.

This implements the return path for chromes to inform WebContent of the
file(s) the user selected. This patch includes a dummy implementation
for headless-browser to enable testing.
This commit is contained in:
Timothy Flynn 2024-02-25 13:02:47 -05:00 committed by Andreas Kling
parent 435c2c24d1
commit 108521a566
23 changed files with 307 additions and 5 deletions

View file

@ -0,0 +1,7 @@
Select file...file1 Select files...4 files selected. input1:
file1: Contents for file1
input2:
file1: Contents for file1
file2: Contents for file2
file3: Contents for file3
file4: Contents for file4

View file

@ -0,0 +1,32 @@
<input id="input1" type="file" />
<input id="input2" type="file" multiple />
<script src="./include.js"></script>
<script type="text/javascript">
const runTest = async id => {
let input = document.getElementById(id);
return new Promise(resolve => {
input.addEventListener("input", async () => {
println(`${id}:`);
for (let i = 0; i < input.files.length; ++i) {
const file = input.files.item(i);
const text = await file.text();
println(`${file.name}: ${text}`);
}
resolve();
});
internals.dispatchUserActivatedEvent(input, new Event("mousedown"));
input.showPicker();
});
};
asyncTest(async done => {
await runTest("input1");
await runTest("input2");
done();
});
</script>