LCOV - code coverage report
Current view: top level - test/wpt/xhr/formdata - iteration.any.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 144 144 100.0 %
Date: 2025-01-24 02:02:48 Functions: 5 5 100.0 %
Branches: 12 12 100.0 %

           Branch data     Line data    Source code
       1            [ + ]:          1 : import assert from 'node:assert/strict';
       2                 :          1 : import { FormData } from '../../../../lib/whatwg-xhr.js';
       3                 :          1 : 
       4            [ + ]:          1 : export default (activeURL) => {
       5                 :          1 : 
       6            [ + ]:          1 :         (() => {
       7                 :          1 :                 const formData = createFormData([["foo", "0"],
       8                 :          1 :                                                                                  ["baz", "1"],
       9                 :          1 :                                                                                  ["BAR", "2"]]);
      10                 :          1 :                 const actualKeys = [];
      11                 :          1 :                 const actualValues = [];
      12                 :          1 : 
      13            [ + ]:          1 :                 for (const [name, value] of formData) {
      14                 :          2 :                         actualKeys.push(name);
      15                 :          2 :                         actualValues.push(value);
      16                 :          2 :                         formData.delete("baz");
      17                 :          2 :                 }
      18                 :          1 : 
      19                 :          1 :                 assert.deepStrictEqual(actualKeys, ["foo", "BAR"]);
      20                 :          1 :                 assert.deepStrictEqual(actualValues, ["0", "2"]);
      21                 :          1 :         })("Iteration skips elements removed while iterating");
      22                 :          1 : 
      23            [ + ]:          1 :         (() => {
      24                 :          1 :                 const formData = createFormData([["foo", "0"],
      25                 :          1 :                                                                                  ["baz", "1"],
      26                 :          1 :                                                                                  ["BAR", "2"],
      27                 :          1 :                                                                                  ["quux", "3"]]);
      28                 :          1 :                 const actualKeys = [];
      29                 :          1 :                 const actualValues = [];
      30                 :          1 : 
      31            [ + ]:          1 :                 for (const [name, value] of formData) {
      32                 :          3 :                         actualKeys.push(name);
      33                 :          3 :                         actualValues.push(value);
      34                 :          3 :                         if (name === "baz")
      35            [ + ]:          3 :                                 formData.delete("foo");
      36                 :          3 :                 }
      37                 :          1 : 
      38                 :          1 :                 assert.deepStrictEqual(actualKeys, ["foo", "baz", "quux"]);
      39                 :          1 :                 assert.deepStrictEqual(actualValues, ["0", "1", "3"]);
      40                 :          1 :         })("Removing elements already iterated over causes an element to be skipped during iteration");
      41                 :          1 : 
      42            [ + ]:          1 :         (() => {
      43                 :          1 :                 const formData = createFormData([["foo", "0"],
      44                 :          1 :                                                                                  ["baz", "1"],
      45                 :          1 :                                                                                  ["BAR", "2"],
      46                 :          1 :                                                                                  ["quux", "3"]]);
      47                 :          1 :                 const actualKeys = [];
      48                 :          1 :                 const actualValues = [];
      49                 :          1 : 
      50            [ + ]:          1 :                 for (const [name, value] of formData) {
      51                 :          5 :                         actualKeys.push(name);
      52                 :          5 :                         actualValues.push(value);
      53                 :          5 :                         if (name === "baz")
      54            [ + ]:          5 :                                 formData.append("X-yZ", "4");
      55                 :          5 :                 }
      56                 :          1 : 
      57                 :          1 :                 assert.deepStrictEqual(actualKeys, ["foo", "baz", "BAR", "quux", "X-yZ"]);
      58                 :          1 :                 assert.deepStrictEqual(actualValues, ["0", "1", "2", "3", "4"]);
      59                 :          1 :         })("Appending a value pair during iteration causes it to be reached during iteration");
      60                 :          1 : 
      61            [ + ]:          1 :         function createFormData(input){
      62                 :          3 :                 const formData = new FormData();
      63                 :          3 : 
      64            [ + ]:          3 :                 for(const [name, value] of input){
      65                 :         11 :                         formData.append(name, value);
      66                 :         11 :                 }
      67                 :          3 : 
      68                 :          3 :                 return formData;
      69                 :          3 :         }
      70                 :          1 : }
      71                 :          1 : 
      72                 :          1 : /*
      73                 :          1 :  * iteration.any.js
      74                 :          1 :  *
      75                 :          1 : 
      76                 :          1 : // META: title=FormData: changes to entry list during iteration
      77                 :          1 : 
      78                 :          1 : // These are tests for next()'s behavior as specified in
      79                 :          1 : // https://webidl.spec.whatwg.org/#es-iterator-prototype-object
      80                 :          1 : 
      81                 :          1 : "use strict";
      82                 :          1 : 
      83                 :          1 : function createFormData(input) {
      84                 :          1 :     const formData = new FormData();
      85                 :          1 : 
      86                 :          1 :     for (const [name, value] of input) {
      87                 :          1 :         formData.append(name, value);
      88                 :          1 :     }
      89                 :          1 : 
      90                 :          1 :     return formData;
      91                 :          1 : }
      92                 :          1 : 
      93                 :          1 : test(() => {
      94                 :          1 :     const formData = createFormData([["foo", "0"],
      95                 :          1 :                                      ["baz", "1"],
      96                 :          1 :                                      ["BAR", "2"]]);
      97                 :          1 :     const actualKeys = [];
      98                 :          1 :     const actualValues = [];
      99                 :          1 :     for (const [name, value] of formData) {
     100                 :          1 :         actualKeys.push(name);
     101                 :          1 :         actualValues.push(value);
     102                 :          1 :         formData.delete("baz");
     103                 :          1 :     }
     104                 :          1 :     assert_array_equals(actualKeys, ["foo", "BAR"]);
     105                 :          1 :     assert_array_equals(actualValues, ["0", "2"]);
     106                 :          1 : }, "Iteration skips elements removed while iterating");
     107                 :          1 : 
     108                 :          1 : test(() => {
     109                 :          1 :     const formData = createFormData([["foo", "0"],
     110                 :          1 :                                      ["baz", "1"],
     111                 :          1 :                                      ["BAR", "2"],
     112                 :          1 :                                      ["quux", "3"]]);
     113                 :          1 :     const actualKeys = [];
     114                 :          1 :     const actualValues = [];
     115                 :          1 :     for (const [name, value] of formData) {
     116                 :          1 :         actualKeys.push(name);
     117                 :          1 :         actualValues.push(value);
     118                 :          1 :         if (name === "baz")
     119                 :          1 :             formData.delete("foo");
     120                 :          1 :     }
     121                 :          1 :     assert_array_equals(actualKeys, ["foo", "baz", "quux"]);
     122                 :          1 :     assert_array_equals(actualValues, ["0", "1", "3"]);
     123                 :          1 : }, "Removing elements already iterated over causes an element to be skipped during iteration");
     124                 :          1 : 
     125                 :          1 : test(() => {
     126                 :          1 :     const formData = createFormData([["foo", "0"],
     127                 :          1 :                                      ["baz", "1"],
     128                 :          1 :                                      ["BAR", "2"],
     129                 :          1 :                                      ["quux", "3"]]);
     130                 :          1 :     const actualKeys = [];
     131                 :          1 :     const actualValues = [];
     132                 :          1 :     for (const [name, value] of formData) {
     133                 :          1 :         actualKeys.push(name);
     134                 :          1 :         actualValues.push(value);
     135                 :          1 :         if (name === "baz")
     136                 :          1 :             formData.append("X-yZ", "4");
     137                 :          1 :     }
     138                 :          1 :     assert_array_equals(actualKeys, ["foo", "baz", "BAR", "quux", "X-yZ"]);
     139                 :          1 :     assert_array_equals(actualValues, ["0", "1", "2", "3", "4"]);
     140                 :          1 : }, "Appending a value pair during iteration causes it to be reached during iteration");
     141                 :          1 : 
     142                 :          1 :  *
     143                 :          1 :  *
     144                 :          1 :  */

Generated by: LCOV version 1.14