summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/xhr/formdata/iteration.any.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/xhr/formdata/iteration.any.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
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.js65
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");