summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/xmlhttprequest/xmlhttprequest-html-response-encoding.html
blob: e2d0ecf4dc39065805b4233f2cd89e63cf712af1 (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
<html>
<head>
<title>Test XmlHttpRequest response encoding handling</title>
</head>
<body>
<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=14288">bug 14288</a>:
XMLHttpRequest doesn't use a correct content type for file:// URLs.</p>
<script>

    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    var console_messages = document.createElement("ol");
    document.body.appendChild(console_messages);
    
    var asyncStep = 1;
    
    function log(message)
    {
        var item = document.createElement("li");
        item.appendChild(document.createTextNode(message));
        console_messages.appendChild(item);
    }
    
    function get(url, async)
    {
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
        } else {
            try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (ex) {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        
        if (async)
            req.onreadystatechange = processStateChange;
        
        req.open('GET', url, async);
        req.send(null);
        
        return req;
    }

    function processStateChange(){
        if (req.readyState == 4) {
            log("Async: HTML, charset determined by a META: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
            if (window.testRunner)
                testRunner.notifyDone();
        }
    }

    try {
        req =  get('resources/1251.html', false);
        log("HTML, charset determined by a META: " + req.responseText.replace(/\s/g, "").replace(/.*<body>(.*)<\/body>.*/, "$1"));
    } catch (ex) {
        log("Exception: " + ex.description);
    }

    get('resources/1251.html', true);
    
</script>
</body>
</html>