diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/xhr/formdata/iteration.any.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/xhr/formdata/iteration.any.js')
-rw-r--r-- | testing/web-platform/tests/xhr/formdata/iteration.any.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/testing/web-platform/tests/xhr/formdata/iteration.any.js b/testing/web-platform/tests/xhr/formdata/iteration.any.js new file mode 100644 index 0000000000..1633fd9c4d --- /dev/null +++ b/testing/web-platform/tests/xhr/formdata/iteration.any.js @@ -0,0 +1,65 @@ +// META: title=FormData: changes to entry list during iteration + +// These are tests for next()'s behavior as specified in +// https://webidl.spec.whatwg.org/#es-iterator-prototype-object + +"use strict"; + +function createFormData(input) { + const formData = new FormData(); + + for (const [name, value] of input) { + formData.append(name, value); + } + + return formData; +} + +test(() => { + const formData = createFormData([["foo", "0"], + ["baz", "1"], + ["BAR", "2"]]); + const actualKeys = []; + const actualValues = []; + for (const [name, value] of formData) { + actualKeys.push(name); + actualValues.push(value); + formData.delete("baz"); + } + assert_array_equals(actualKeys, ["foo", "BAR"]); + assert_array_equals(actualValues, ["0", "2"]); +}, "Iteration skips elements removed while iterating"); + +test(() => { + const formData = createFormData([["foo", "0"], + ["baz", "1"], + ["BAR", "2"], + ["quux", "3"]]); + const actualKeys = []; + const actualValues = []; + for (const [name, value] of formData) { + actualKeys.push(name); + actualValues.push(value); + if (name === "baz") + formData.delete("foo"); + } + assert_array_equals(actualKeys, ["foo", "baz", "quux"]); + assert_array_equals(actualValues, ["0", "1", "3"]); +}, "Removing elements already iterated over causes an element to be skipped during iteration"); + +test(() => { + const formData = createFormData([["foo", "0"], + ["baz", "1"], + ["BAR", "2"], + ["quux", "3"]]); + const actualKeys = []; + const actualValues = []; + for (const [name, value] of formData) { + actualKeys.push(name); + actualValues.push(value); + if (name === "baz") + formData.append("X-yZ", "4"); + } + assert_array_equals(actualKeys, ["foo", "baz", "BAR", "quux", "X-yZ"]); + assert_array_equals(actualValues, ["0", "1", "2", "3", "4"]); +}, "Appending a value pair during iteration causes it to be reached during iteration"); |