summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/http/tests/plugins/npapi-response-headers.html
blob: 3529b10bb5916cda2517eea47db52f9bca4f8319 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<html>
<head>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

loadedFirstURL = false;

var res1, res2;

function test()
{
    try {
        res1 = document.getElementById("result1");
        res2 = document.getElementById("result2");
    } catch (ex) {
        showErr("Exception: " + ex.description);
        if (window.testRunner)
            testRunner.notifyDone();
    }
}

function streamLoaded()
{
    if (loadedFirstURL)
        return;
        
    loadedFirstURL = true;
    plg.getURLNotify("/plugins/resources/load-me-2.txt", null, "callback");
}

function callback(errCode, streamDump)
{
    var parse = parseStreamDump(streamDump);
    if (parse.err)
        showErr(parse.err);
    else {
        res1.innerHTML = newlinesToHTML(parse.res1);
        res2.innerHTML = newlinesToHTML(parse.res2);
    }

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

// Format passed by plugin: four fields separated by \n\n:
// First URL; first header block; last URL; last header block.
function parseStreamDump(streamDump)
{
    var rtn = {};

    if (typeof streamDump == "string" || ((typeof streamDump == "object") && (streamDump.constructor == String))) {
        var parts = streamDump.split("\n\n");
        if (parts.length >= 4) {
            rtn.res1 = genericURL(parts[0]) + "\n" + parseHeaders(parts[1]);
            rtn.res2 = genericURL(parts[2]) + "\n" + parseHeaders(parts[3]);
        } else
            rtn.err = "streamDump from plugin does not have expected format";
    } else
        rtn.err = "streamDump from plugin is not a string: " + streamDump;

    return rtn;
}

function showErr(err)
{
    res1.innerHTML = "FAILED - " + err;
    res2.innerHTML = "";
}

function newlinesToHTML(str)
{
    return str.replace(/\n/g, "<br>");
}

function genericURL(url)
{
    return url.replace(/^(http:\/\/)[^\/]+/, "$1[varies, not being tested]");
}

function parseHeaders(hdrs)
{
    var parts = hdrs.split("\n");
    var rtn = parts[0] + "\n";

    for (var i = 0; i < parts.length; i++)
        if (parts[i].match(/^Content-Type:/))
            rtn += parts[i];

    return rtn;
}
</script>
</head>
<body onload="test()">
<embed name="plg" type="application/x-webkit-test-netscape" src="/plugins/resources/load-me-1.txt" onstreamload="streamLoaded()"></embed>
<p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=13029">bug 13029<a/>:
Permit NPAPI plug-ins to see HTTP response headers.</p>
<p>Expected result below is two HTTP response extracts, one for the initial stream specified in the "src"
attribute, the other for an NPN_GetURLNotify request. Each block should contain the URL; the status line,
which should say "HTTP 200 OK"; and the MIME-type, which should say "Content-Type: text/plain".</p>
<p>----------</p>
<p id="result1">Running test, result should appear here in a very short time...</p>
<p>----------</p>
<p id="result2">Running test, result should appear here in a very short time...</p>
</body>
</html>