Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / request-encoding2.html
blob1adeb9868933f43f24b752152270f916ad024e91
1 <html>
2 <head>
3 <meta http-equiv="content-type" content="text/html;charset=utf-8">
4 <body>
5 <p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=34653">bug 34653</a>:
6 XMLHttpRequest should force to send content-type as charset equals UTF-8.</p>
7 <div id=result1>FAIL: script didn't run to completion.</div>
8 <div id=result2>FAIL: script didn't run to completion.</div>
9 <div id=result3>FAIL: script didn't run to completion.</div>
10 <div id=result4>FAIL: script didn't run to completion.</div>
11 <script>
13 function test1() {
14 // Test when content-type is not set.
15 req = new XMLHttpRequest;
16 req.open("POST", "print-content-type.cgi", false);
18 req.send("");
20 document.getElementById("result1").firstChild.data = "Test1 (setRequestHeader was not called):";
21 if (req.responseText == "application/xml\n")
22 document.getElementById("result1").firstChild.data += " SUCCESS";
23 else
24 document.getElementById("result1").firstChild.data += " FAILURE: '" + req.responseText + "'";
27 function test2() {
28 // Test when content-type is set without charset.
29 req = new XMLHttpRequest;
30 req.open("POST", "print-content-type.cgi", false);
32 req.setRequestHeader("Content-Type", "application/xml");
33 req.send("");
35 document.getElementById("result2").firstChild.data = "Test2 (setRequestHeader was called without a charset):";
36 if (req.responseText == "application/xml\n")
37 document.getElementById("result2").firstChild.data += " SUCCESS";
38 else
39 document.getElementById("result2").firstChild.data += " FAILURE: '" + req.responseText + "'";
42 function test3() {
43 // Test when content-type is set with non-UTF-8 charset.
44 req = new XMLHttpRequest;
45 req.open("POST", "print-content-type.cgi", false);
47 req.setRequestHeader("Content-Type", "application/xml; charset=KOI8-R");
48 req.send("");
50 document.getElementById("result3").firstChild.data = "Test3 (setRequestHeader was called with a non-UTF8 charset):";
51 if (req.responseText == "application/xml; charset=UTF-8\n")
52 document.getElementById("result3").firstChild.data += " SUCCESS";
53 else
54 document.getElementById("result3").firstChild.data += " FAILURE: '" + req.responseText + "'";
57 function test4() {
58 // Test when content-type is set with multiple charsets and other attributes.
59 req = new XMLHttpRequest;
60 req.open("POST", "print-content-type.cgi", false);
62 req.setRequestHeader("Content-Type", "application/xml; charset=KOI8-R; charset=UTF-8; charset=iso-8859-1; KOI8-R");
63 req.send("");
65 document.getElementById("result4").firstChild.data = "Test4 (setRequestHeader was called with multiple charsets and other attributes):";
66 if (req.responseText == "application/xml; charset=UTF-8; charset=UTF-8; charset=UTF-8; KOI8-R\n")
67 document.getElementById("result4").firstChild.data += " SUCCESS";
68 else
69 document.getElementById("result4").firstChild.data += " FAILURE: '" + req.responseText + "'";
72 if (window.testRunner)
73 testRunner.dumpAsText();
75 test1();
76 test2();
77 test3();
78 test4();
80 </script>
81 </body>
82 </html>