mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Preserve File last modified timestamp in FormData copies
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
+1 WPT pass
This commit is contained in:
parent
da40419c5b
commit
c3e470569e
Notes:
github-actions[bot]
2025-07-09 09:22:04 +00:00
Author: https://github.com/veeti
Commit: c3e470569e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5364
Reviewed-by: https://github.com/tcl3 ✅
4 changed files with 87 additions and 0 deletions
|
@ -47,6 +47,7 @@ WebIDL::ExceptionOr<XHR::FormDataEntry> create_entry(JS::Realm& realm, String co
|
||||||
if (filename.has_value()) {
|
if (filename.has_value()) {
|
||||||
FileAPI::FilePropertyBag options {};
|
FileAPI::FilePropertyBag options {};
|
||||||
options.type = blob->type();
|
options.type = blob->type();
|
||||||
|
options.last_modified = as<FileAPI::File>(*blob).last_modified();
|
||||||
|
|
||||||
blob = TRY(FileAPI::File::create(realm, { GC::make_root(*blob) }, *filename, move(options)));
|
blob = TRY(FileAPI::File::create(realm, { GC::make_root(*blob) }, *filename, move(options)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 5 tests
|
||||||
|
|
||||||
|
5 Pass
|
||||||
|
Pass blob without type
|
||||||
|
Pass blob with type
|
||||||
|
Pass blob with custom name
|
||||||
|
Pass file without lastModified or custom name
|
||||||
|
Pass file with lastModified and custom name
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset=utf-8>
|
||||||
|
<title>formData.set(blob) and formData.set(file)</title>
|
||||||
|
<script>
|
||||||
|
self.GLOBAL = {
|
||||||
|
isWindow: function() { return true; },
|
||||||
|
isWorker: function() { return false; },
|
||||||
|
isShadowRealm: function() { return false; },
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script src="../../resources/testharness.js"></script>
|
||||||
|
<script src="../../resources/testharnessreport.js"></script>
|
||||||
|
|
||||||
|
<div id=log></div>
|
||||||
|
<script src="../../xhr/formdata/set-blob.any.js"></script>
|
|
@ -0,0 +1,61 @@
|
||||||
|
// META: title=formData.set(blob) and formData.set(file)
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
const value = new Blob();
|
||||||
|
formData.set("blob-1", value);
|
||||||
|
const blob1 = formData.get("blob-1");
|
||||||
|
assert_not_equals(blob1, value);
|
||||||
|
assert_equals(blob1.constructor.name, "File");
|
||||||
|
assert_equals(blob1.name, "blob");
|
||||||
|
assert_equals(blob1.type, "");
|
||||||
|
assert_equals(formData.get("blob-1") === formData.get("blob-1"), true, "should return the same value when get the same blob entry from FormData");
|
||||||
|
assert_less_than(Math.abs(blob1.lastModified - Date.now()), 200, "lastModified should be now");
|
||||||
|
}, "blob without type");
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
const value = new Blob([], { type: "text/plain" });
|
||||||
|
formData.set("blob-2", value);
|
||||||
|
const blob2 = formData.get("blob-2");
|
||||||
|
assert_not_equals(blob2, value);
|
||||||
|
assert_equals(blob2.constructor.name, "File");
|
||||||
|
assert_equals(blob2.name, "blob");
|
||||||
|
assert_equals(blob2.type, "text/plain");
|
||||||
|
assert_less_than(Math.abs(blob2.lastModified - Date.now()), 200, "lastModified should be now");
|
||||||
|
}, "blob with type");
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
const value = new Blob();
|
||||||
|
formData.set("blob-3", value, "custom name");
|
||||||
|
const blob3 = formData.get("blob-3");
|
||||||
|
assert_not_equals(blob3, value);
|
||||||
|
assert_equals(blob3.constructor.name, "File");
|
||||||
|
assert_equals(blob3.name, "custom name");
|
||||||
|
assert_equals(blob3.type, "");
|
||||||
|
assert_less_than(Math.abs(blob3.lastModified - Date.now()), 200, "lastModified should be now");
|
||||||
|
}, "blob with custom name");
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
const value = new File([], "name");
|
||||||
|
formData.set("file-1", value);
|
||||||
|
const file1 = formData.get("file-1");
|
||||||
|
assert_equals(file1, value);
|
||||||
|
assert_equals(file1.constructor.name, "File");
|
||||||
|
assert_equals(file1.name, "name");
|
||||||
|
assert_equals(file1.type, "");
|
||||||
|
assert_less_than(Math.abs(file1.lastModified - Date.now()), 200, "lastModified should be now");
|
||||||
|
}, "file without lastModified or custom name");
|
||||||
|
|
||||||
|
test(() => {
|
||||||
|
const value = new File([], "name", { lastModified: 123 });
|
||||||
|
formData.set("file-2", value, "custom name");
|
||||||
|
const file2 = formData.get("file-2");
|
||||||
|
assert_not_equals(file2, value);
|
||||||
|
assert_equals(file2.constructor.name, "File");
|
||||||
|
assert_equals(file2.name, "custom name");
|
||||||
|
assert_equals(file2.type, "");
|
||||||
|
assert_equals(file2.lastModified, 123, "lastModified should be 123");
|
||||||
|
}, "file with lastModified and custom name");
|
Loading…
Add table
Add a link
Reference in a new issue