summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/XMLHttpRequest/formdata-delete.htm
blob: 283b44b5ab01d1aaa51ba8751547d0f5670d6fcb (plain)
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
57
58
59
60
61
62
63
64
65
<!doctype html>
<html lang=en>
<meta charset=utf-8>
<title>FormData: delete</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
    <link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata-get" />
    <link rel="help" href="https://xhr.spec.whatwg.org/#dom-formdata-getall" />
<div id="log"></div>
<form id="form1">
    <input type="hidden" name="key" value="value1">
    <input type="hidden" name="key" value="value2">
</form>
<form id="form2">
    <input type="hidden" name="key1" value="value1">
    <input type="hidden" name="key2" value="value2">
</form>
<form id="empty-form" />
<script>
    test(function() {
        var fd = create_formdata(['key', 'value1'], ['key', 'value2']);
        fd.delete('key');
        assert_equals(fd.get('key'), null);
    }, 'testFormDataDelete');
    test(function() {
        var fd = new FormData(document.getElementById('form1'));
        fd.delete('key');
        assert_equals(fd.get('key'), null);
    }, 'testFormDataDeleteFromForm');
    test(function() {
        var fd = new FormData(document.getElementById('form1'));
        fd.delete('nil');
        assert_equals(fd.get('key'), 'value1');
    }, 'testFormDataDeleteFromFormNonExistentKey');
    test(function() {
        var fd = new FormData(document.getElementById('form2'));
        fd.delete('key1');
        assert_equals(fd.get('key1'), null);
        assert_equals(fd.get('key2'), 'value2');
    }, 'testFormDataDeleteFromFormOtherKey');
    test(function() {
        var fd = new FormData(document.getElementById('empty-form'));
        fd.delete('key');
        assert_equals(fd.get('key'), null);
    }, 'testFormDataDeleteFromEmptyForm');
    test(function() {
        var fd = create_formdata(['key', 'value1'], ['key', 'value2']);
        fd.delete('nil');
        assert_equals(fd.get('key'), 'value1');
    }, 'testFormDataDeleteNonExistentKey');
    test(function() {
        var fd = create_formdata(['key1', 'value1'], ['key2', 'value2']);
        fd.delete('key1');
        assert_equals(fd.get('key1'), null);
        assert_equals(fd.get('key2'), 'value2');
    }, 'testFormDataDeleteOtherKey');

    function create_formdata() {
        var fd = new FormData();
        for (var i = 0; i < arguments.length; i++) {
            fd.append.apply(fd, arguments[i]);
        };
        return fd;
    }
</script>