chromium/third_party/blink/web_tests/http/tests/xmlhttprequest/xmlhttprequest-latin1.html

<html>
<body>
<p>Test that setRequestHeader encodes header values as latin-1</p>
<pre id=result>FAIL: script didn't run or raised an unexpected exception.</pre>
<script>
    if (window.testRunner)
        testRunner.dumpAsText();

    function log(msg) {
        document.getElementById("result").textContent += msg + "\n";
    }
    document.getElementById("result").textContent = "";

    try {
        req = new XMLHttpRequest;
        req.open("GET", "resources/latin1-test.cgi", false);

        req.setRequestHeader("CUSTOM-HEADER", "\xd5K");

        exceptionThrown = false;
        try {
            req.setRequestHeader("X-SNOWMAN", "\u2603");
        } catch(e) {
            exceptionThrown = true;
        }
        if (exceptionThrown)
            log("PASSED: non-latin-1 header value throws");
        else
            log("FAILED: latin-1 header value accepted");

        req.send("");
        if (req.responseText.indexOf("HTTP_CUSTOM_HEADER: %D5K") >= 0)
            log("PASSED: header bytes preserved as latin-1");
        else
            log("FAILED: header bytes not preserved as latin-1");

        if (req.getResponseHeader("Custom-Header") == "\xd5K")
            log("PASSED: response header interpreted correctly");
        else
            log("FAILED: response header interpreted incorrectly");

	// TODO(davidben): Test req.statusText too. Unfortunately, lighttpd
	// doesn't seem to forward the HTTP status text from the CGI script's
	// status header.
    } catch (ex) {
        log("FAILED: " + ex);
    }
</script>
</body>
</html>