Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / plugins / npapi-response-headers.html
blob7eb7460b67bf7681e85d2c36f3ecdc0fd831a8ce
1 <html>
2 <head>
3 <script>
4 if (window.testRunner) {
5 testRunner.dumpAsText();
6 testRunner.waitUntilDone();
9 loadedFirstURL = false;
11 var res1, res2;
13 function test()
15 try {
16 res1 = document.getElementById("result1");
17 res2 = document.getElementById("result2");
18 } catch (ex) {
19 showErr("Exception: " + ex.description);
20 if (window.testRunner)
21 testRunner.notifyDone();
25 function streamLoaded()
27 if (loadedFirstURL)
28 return;
30 loadedFirstURL = true;
31 plg.getURLNotify("/plugins/resources/load-me-2.txt", null, "callback");
34 function callback(errCode, streamDump)
36 var parse = parseStreamDump(streamDump);
37 if (parse.err)
38 showErr(parse.err);
39 else {
40 res1.innerHTML = newlinesToHTML(parse.res1);
41 res2.innerHTML = newlinesToHTML(parse.res2);
44 if (window.testRunner)
45 testRunner.notifyDone();
48 // Format passed by plugin: four fields separated by \n\n:
49 // First URL; first header block; last URL; last header block.
50 function parseStreamDump(streamDump)
52 var rtn = {};
54 if (typeof streamDump == "string" || ((typeof streamDump == "object") && (streamDump.constructor == String))) {
55 var parts = streamDump.split("\n\n");
56 if (parts.length >= 4) {
57 rtn.res1 = genericURL(parts[0]) + "\n" + parseHeaders(parts[1]);
58 rtn.res2 = genericURL(parts[2]) + "\n" + parseHeaders(parts[3]);
59 } else
60 rtn.err = "streamDump from plugin does not have expected format";
61 } else
62 rtn.err = "streamDump from plugin is not a string: " + streamDump;
64 return rtn;
67 function showErr(err)
69 res1.innerHTML = "FAILED - " + err;
70 res2.innerHTML = "";
73 function newlinesToHTML(str)
75 return str.replace(/\n/g, "<br>");
78 function genericURL(url)
80 return url.replace(/^(http:\/\/)[^\/]+/, "$1[varies, not being tested]");
83 function parseHeaders(hdrs)
85 var parts = hdrs.split("\n");
86 var rtn = parts[0] + "\n";
88 for (var i = 0; i < parts.length; i++)
89 if (parts[i].match(/^Content-Type:/))
90 rtn += parts[i];
92 return rtn;
94 </script>
95 </head>
96 <body onload="test()">
97 <embed name="plg" type="application/x-webkit-test-netscape" src="/plugins/resources/load-me-1.txt" onstreamload="streamLoaded()"></embed>
98 <p>Test for <a href="https://bugs.webkit.org/show_bug.cgi?id=13029">bug 13029<a/>:
99 Permit NPAPI plugins to see HTTP response headers.</p>
100 <p>Expected result below is two HTTP response extracts, one for the initial stream specified in the "src"
101 attribute, the other for an NPN_GetURLNotify request. Each block should contain the URL; the status line,
102 which should say "HTTP 200 OK"; and the MIME-type, which should say "Content-Type: text/plain".</p>
103 <p>----------</p>
104 <p id="result1">Running test, result should appear here in a very short time...</p>
105 <p>----------</p>
106 <p id="result2">Running test, result should appear here in a very short time...</p>
107 </body>
108 </html>