<!DOCTYPE html>
<html>
<head>
<meta charset="big5"> <!-- test breaks if the server overrides this -->
<title>Big5 encoding errors (form, hangul)</title>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="big5_index.js"></script>
<script src="big5-encoder.js"></script>
<link rel="author" title="Richard Ishida" href="mailto:ishida@w3.org">
<link rel="help" href="https://encoding.spec.whatwg.org/#big5">
<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 big5 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 miscellaneous unicode codepoints that are not encoded
    var codepoints = [];

    for (i = 0xac00; i < 0xd7af; i++) {
        result = big5Encoder(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 = "big5";
        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>
