summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/encoding/resources/char-encoding-utils.js
blob: 2007c7ffdd998be14c82e89cf7bd9bfd51b0a1ad (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
66
67
68
69
function encode(charset, unicode)
{
    // Returns a value already encoded, since we can't do it synchronously.
    return results[charset][unicode];
}

function testsDone()
{
    var form = document.getElementById('form');
    var subframe = document.getElementById('subframe');

    form.parentNode.removeChild(form);
    subframe.parentNode.removeChild(subframe);

    description("This tests encoding characters in various character sets.");

    for (i = 0; i < charsets.length; ++i) {
        shouldBe("encode('" + charsets[i] + "', '" + unicodes[i] + "')", "'" + expectedResults[i] + "'");
    }

    isSuccessfullyParsed();

    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

function processResult(result)
{
    var charsetResults = results[charsets[i]];
    if (!charsetResults) {
        charsetResults = new Object;
        results[charsets[i]] = charsetResults;
    }
    charsetResults[unicodes[i]] = result; 
}

function subframeLoaded()
{
    var URL = "" + document.getElementById('subframe').contentWindow.location;
    processResult(URL.substr(URL.indexOf('=') + 1));
    ++i;
    runTest();
}

function runTest()
{    
    if (i >= charsets.length) {
        testsDone();
        return;
    }

    var form = document.getElementById('form');
    var text = document.getElementById('text');
    var subframe = document.getElementById('subframe');

    form.acceptCharset = charsets[i];
    form.action = "resources/dummy.html";
    subframe.onload = subframeLoaded;
    text.value = String.fromCharCode(unicodes[i].replace('U+', '0x'));
    
    form.submit();
}

function testEncode(charsetName, unicode, characterSequence)
{
    charsets.push(charsetName);
    unicodes.push(unicode);
    expectedResults.push(characterSequence);
}