<!DOCTYPE html>
<html>
<head>
<meta charset="shift_jis"> <!-- test breaks if the server overrides this -->
<title>Shift_jis encoding errors (form, hangul)</title>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="jis0208_index.js"></script>
<script src="sjis-encoder.js"></script>
<link rel="author" title="Richard Ishida" href="mailto:ishida@w3.org">
<link rel="help" href="https://encoding.spec.whatwg.org//#shift_jis">
<meta name="assert" content="The browser produces percent-escaped character references for a URL produced by a form when encoding hangul characters that are not in the shift_jis encoding.">
<style>
 iframe { display:none }
 form { display:none }
</style>
</head>
<body>
<div id="log"></div>
<script>
var tests = [];
var cplist = [];
var numTests = null;
var numFrames = 2;
var chunkSize = 400;
var numChunks = null;
var frames = null;
var frames = null;
var forms = null;
var seperator = ",";
var encodedSeperator = encodeURIComponent(",");
var currentChunkIndex = 0;

setup(function() {
    // set up a simple array of unicode codepoints that are not encoded
    var codepoints = [];

    for (i = 0xac00; i < 0xd7af; i++) {
        result = sjisEncoder(String.fromCodePoint(i));
        if (!result) {
            var item = {};
            codepoints.push(item);
            item.cp = i;
            item.expected = "%26%23" + item.cp + "%3B";
            item.desc = "hangul ";
        }
    }

    // convert the information into a simple array of objects that can be easily traversed
    var currentChunk = [];
    var currentTests = [];
    cplist = [currentChunk];
    tests = [currentTests];
    for (i = 0; i < codepoints.length; i++) {
        if (currentChunk.length == chunkSize) {
            currentChunk = [];
            cplist.push(currentChunk);
            currentTests = [];
            tests.push(currentTests);
        }
        var item = {};
        currentChunk.push(item);
        item.cp = codepoints[i].cp;
        item.expected = codepoints[i].expected;
        item.desc = codepoints[i].desc;
        currentTests.push(
            async_test(
                item.desc +
                    "U+" +
                    item.cp.toString(16).toUpperCase() +
                    " " +
                    String.fromCodePoint(item.cp) +
                    " " +
                    item.expected
            )
        );
    }

    numChunks = cplist.length;

    for (var i = 0; i < numFrames; i++) {
        var frame = document.createElement("iframe");
        frame.id = frame.name = "frame-" + i;
        document.body.appendChild(frame);
        var form = document.createElement("form");
        form.id = "form-" + i;
        form.method = "GET";
        form.action = "/common/blank.html";
        form.acceptCharset = "shift_jis";
        form.target = frame.id;
        var input = document.createElement("input");
        input.id = input.name = "input-" + i;
        form.appendChild(input);
        document.body.appendChild(form);
    }

    addEventListener("load", function() {
        frames = Array.prototype.slice.call(
            document.getElementsByTagName("iframe")
        );
        forms = Array.prototype.slice.call(
            document.getElementsByTagName("form")
        );
        inputs = Array.prototype.slice.call(
            document.getElementsByTagName("input")
        );
        for (var i = 0; i < Math.min(numFrames, numChunks); i++) {
            runNext(i);
        }
    });
});

function runNext(id) {
    var i = currentChunkIndex;
    currentChunkIndex += 1;

    var iframe = frames[id];
    var form = forms[id];
    var input = inputs[id];

    input.value = cplist[i]
        .map(function(x) {
            return String.fromCodePoint(x.cp);
        })
        .join(seperator);
    form.submit();

    iframe.onload = function() {
        var url = iframe.contentWindow.location;
        var query = url.search;
        var result_string = query.substr(query.indexOf("=") + 1);
        var results = result_string.split(encodedSeperator);

        for (var j = 0; j < cplist[i].length; j++) {
            var t = tests[i][j];
            t.step(function() {
                assert_equals(
                    normalizeStr(results[j]),
                    normalizeStr(cplist[i][j].expected)
                );
            });
            t.done();
        }
        if (currentChunkIndex < numChunks) {
            runNext(id);
        }
    };
}
</script>
</body>
</html>
