From aa5d839aacae93f061d6232d435d90487733587b Mon Sep 17 00:00:00 2001 From: Raphael Kubo da Costa Date: Fri, 21 Oct 2022 17:10:27 +0000 Subject: [PATCH] Bug 1795923 [wpt PR 36532] - XHR FormData: Add tests for changes to the entry list during iteration., a=testonly Automatic update from web-platform-tests XHR FormData: add tests for changes to the entry list during iteration This is similar to #36455 and #20445: we want to make sure that adding and deleting elements during iteration is reflected in FormData's value pairs to iterate over (i.e., iteration does not happen on a cached version). -- wpt-commits: bfa61347807bc133f4a8afeb9f0ccc47abf1f0bd wpt-pr: 36532 --- .../tests/xhr/formdata/iteration.any.js | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 testing/web-platform/tests/xhr/formdata/iteration.any.js 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 000000000000..1633fd9c4daa --- /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"); -- 2.11.4.GIT