1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// META: title=FormData: foreach
var fd = new FormData();
fd.append('n1', 'v1');
fd.append('n2', 'v2');
fd.append('n3', 'v3');
fd.append('n1', 'v4');
fd.append('n2', 'v5');
fd.append('n3', 'v6');
fd.delete('n2');
var file = new File(['hello'], "hello.txt");
fd.append('f1', file);
var expected_keys = ['n1', 'n3', 'n1', 'n3', 'f1'];
var expected_values = ['v1', 'v3', 'v4', 'v6', file];
test(function() {
var mykeys = [], myvalues = [];
for(var entry of fd) {
assert_equals(entry.length, 2,
'Default iterator should yield key/value pairs');
mykeys.push(entry[0]);
myvalues.push(entry[1]);
}
assert_array_equals(mykeys, expected_keys,
'Default iterator should see duplicate keys');
assert_array_equals(myvalues, expected_values,
'Default iterator should see non-deleted values');
}, 'Iterator should return duplicate keys and non-deleted values');
test(function() {
var mykeys = [], myvalues = [];
for(var entry of fd.entries()) {
assert_equals(entry.length, 2,
'entries() iterator should yield key/value pairs');
mykeys.push(entry[0]);
myvalues.push(entry[1]);
}
assert_array_equals(mykeys, expected_keys,
'entries() iterator should see duplicate keys');
assert_array_equals(myvalues, expected_values,
'entries() iterator should see non-deleted values');
}, 'Entries iterator should return duplicate keys and non-deleted values');
test(function() {
var mykeys = [];
for(var entry of fd.keys())
mykeys.push(entry);
assert_array_equals(mykeys, expected_keys,
'keys() iterator should see duplicate keys');
}, 'Keys iterator should return duplicates');
test(function() {
var myvalues = [];
for(var entry of fd.values())
myvalues.push(entry);
assert_array_equals(myvalues, expected_values,
'values() iterator should see non-deleted values');
}, 'Values iterator should return non-deleted values');
|