<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="/js-test-resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="../local/formdata/resources/send-form-data-common.js"></script>
<script>
description("Test escaping of filename passed to FormData.append().");

function runTest()
{
    debug("Sending FormData containing blob with plain filename and MIME type:");
    response = testSendingFormData([{
        'type': 'blob',
        'name': 'file',
        'value': new Blob(['1234567890'], {type: "text/plain"}),
        'filename': 'no-tricks.txt'
    }]);
    shouldBe("window.response", "'file=no-tricks.txt:text/plain:1234567890'");

    debug("Sending FormData containing Blob with quote in filename:");
    response = testSendingFormData([{
        'type': 'blob',
        'name': 'file',
        'value': new Blob(['1234567890'], {type: "text/plain"}),
        'filename': 'has"quote.txt'
    }]);
    shouldBe("response", "'file=has%22quote.txt:text/plain:1234567890'");

    debug("Sending FormData containing Blob with LF in filename:");
    response = testSendingFormData([{
        'type': 'blob',
        'name': 'file',
        'value': new Blob(['1234567890'], {type: "text/plain"}),
        'filename': 'has\nlf.txt'
    }]);
    shouldBe("response", "'file=has%0Alf.txt:text/plain:1234567890'");

    debug("Sending FormData containing Blob with CR in filename:");
    response = testSendingFormData([{
        'type': 'blob',
        'name': 'file',
        'value': new Blob(['1234567890'], {type: "text/plain"}),
        'filename': 'has\rcr.txt'
    }]);
    shouldBe("response", "'file=has%0Dcr.txt:text/plain:1234567890'");

    debug("Sending FormData containing Blob with CR LF and \" in filename:");
    response = testSendingFormData([{
        'type': 'blob',
        'name': 'file',
        'value': new Blob(['1234567890'], {type: "text/plain"}),
        'filename': 'has\r\ncrlf"andquote.txt'
    }]);
    shouldBe("response", "'file=has%0D%0Acrlf%22andquote.txt:text/plain:1234567890'");
}

runTest();
formDataTestingCleanup();

var successfullyParsed = true;
</script>
<script src="/js-test-resources/js-test-post.js"></script>
</body>
</html>

