Closed Bug 1390394 Opened 4 years ago Closed 4 years ago

Write mochitest to ensure that after setting <input type=file>.files using FormData gets the new files

Categories

(Core :: DOM: Core & HTML, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla57
Tracking Status
firefox57 --- fixed

People

(Reporter: ben.tian, Assigned: ben.tian)

Details

Attachments

(1 file, 2 obsolete files)

Assignee: nobody → btian
Olli, can you review my mochitest patch that verifies FormData gets the new files after setting <input type=file>.files?

Prior discussion was from bug 1384030 comment 7.
Attachment #8897789 - Flags: review?(bugs)
Comment on attachment 8897789 [details] [diff] [review]
Patch 1 (v1): Mochitest to ensure FormData gets the new files after setting <input type=file>.files

>+  // Assign input1.files to input2.files
>+  input2.files = input1.files;
>+  ok(input2.files.length === 2, "input2.files has incorrect length");
Nit, I'd use is() in this kind of checks

>+
>+  // Append input2.files into FormData
>+  var fd = new FormData();
>+  fd.append("file0", input2.files[0]);
>+  fd.append("file1", input2.files[1]);

Hmm, I wasn't thinking this, but to have type=file elements inside a form element and then do something like 
var fd = new FormData(formElement);
and then check that the FormData has reasonable content.
https://xhr.spec.whatwg.org/#interface-formdata

Sorry if I wasn't clear.
Attachment #8897789 - Flags: review?(bugs) → review-
Revise per reviewer's suggestion.
Attachment #8897789 - Attachment is obsolete: true
Attachment #8898103 - Flags: review?(bugs)
Comment on attachment 8898103 [details] [diff] [review]
Patch 1 (v2): Mochitest to ensure FormData gets the new files after setting <input type=file>.files

I wouldn't mind if it was also checked that inputFiles[0] is the same object as the first File create and [1] the second one.
So perhaps something like
is(inputFiles[0], input.files[0], "Expected File object");
is(inputFiles[1], input.files[1], "Expected File object");
Attachment #8898103 - Flags: review?(bugs) → review+
Keywords: checkin-needed
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/ddec76e7257b
Mochitest to ensure FormData gets the new files after setting <input type=file>.files. r=smaug
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/ddec76e7257b
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla57
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.