Revision 149c83d77d05dafea4a5a4dadf6670bfadc8e360 authored by moz-wptsync-bot on 16 March 2018, 13:38:52 UTC, committed by moz-wptsync-bot on 16 March 2018, 13:38:52 UTC
bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1445883 gecko-commit: 0f81334efa0a008db8931a41eef2d26a77d0e800 gecko-integration-branch: mozilla-inbound gecko-reviewers: smaug
1 parent 1cbb928
formdata-foreach.html
<!doctype html>
<html lang=en>
<meta charset=utf-8>
<title>FormData: foreach</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://xhr.spec.whatwg.org/#interface-formdata" />
<script>
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');
</script>
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...