4 https://bugzilla.mozilla.org/show_bug.cgi?id=431701
7 <title>Test for Bug
431701</title>
8 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
9 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=431701">Mozilla Bug
431701</a>
15 <div id=
"content" style=
"display: none">
16 <iframe id=
"one"></iframe>
17 <iframe id=
"two"></iframe>
18 <iframe id=
"three"></iframe>
19 <iframe id=
"four"></iframe>
20 <iframe id=
"five"></iframe>
21 <iframe id=
"six"></iframe>
22 <iframe id=
"seven"></iframe>
25 <script class=
"testbody" type=
"text/javascript">
27 /** Test for Bug
431701 **/
28 SimpleTest.waitForExplicitFinish();
31 "data:text/html,<html></html>",
32 "data:text/html;charset=UTF-8,<html></html>",
33 "data:text/html;charset=ISO-8859-1,<html></html>",
34 "data:text/xml,<html></html>",
35 "data:text/xml,<?xml version='1.0'?><html></html>",
36 "data:text/xml,<?xml version='1.0' encoding='UTF-8'?><html></html>",
37 "data:text/xml,<?xml version='1.0' encoding='ISO-8859-1'?><html></html>",
40 for (var i =
0; i < docSources.length; ++i) {
41 document.getElementsByTagName(
"iframe")[i].src = docSources[i];
44 function frameDoc(id) {
45 return function() { return $(id).contentDocument; };
48 function createDoc() {
49 return document.implementation.createDocument('', 'html', null);
52 function xhrDoc(idx) {
54 // Defy same-origin restrictions!
55 netscape.security.PrivilegeManager.enablePrivilege(
"UniversalXPConnect");
56 var xhr = new XMLHttpRequest();
57 xhr.open(
"GET", docSources[idx], false);
59 return xhr.responseXML;
63 // Each row has the document getter function, then the characterSet,
64 // inputEncoding, xmlEncoding expected for that document.
67 [ frameDoc(
"one"),
"ISO-8859-1",
"ISO-8859-1", null ],
68 [ frameDoc(
"two"),
"UTF-8",
"UTF-8", null ],
69 [ frameDoc(
"three"),
"ISO-8859-1",
"ISO-8859-1", null ],
70 [ frameDoc(
"four"),
"UTF-8",
"UTF-8", null ],
71 [ frameDoc(
"five"),
"UTF-8",
"UTF-8", null ],
72 [ frameDoc(
"six"),
"UTF-8",
"UTF-8",
"UTF-8"],
73 [ frameDoc(
"seven"),
"ISO-8859-1",
"ISO-8859-1",
"ISO-8859-1" ],
74 [ createDoc,
"UTF-8", null, null ],
75 [ xhrDoc(
4),
"UTF-8",
"UTF-8", null ],
76 [ xhrDoc(
5),
"UTF-8",
"UTF-8",
"UTF-8" ],
77 [ xhrDoc(
6),
"ISO-8859-1",
"ISO-8859-1",
"ISO-8859-1" ],
80 function doTest(idx) {
81 var [docGetter, expectedCharacterSet,
82 expectedInputEncoding, expectedXMLEncoding] = tests[idx];
83 var doc = docGetter();
85 // Have to be careful here to catch null vs
""
86 is(doc.characterSet, expectedCharacterSet,
"Test " + idx +
" characterSet");
87 is(doc.inputEncoding, expectedInputEncoding,
88 "Test " + idx +
" inputEncoding");
89 is(doc.xmlEncoding, expectedXMLEncoding,
"Test " + idx +
" xmlEncoding");
92 addLoadEvent(function() {
94 isnot(
"", null,
"Shouldn't be equal!");
96 for (var i =
0; i < tests.length; ++i) {
100 // Now check what xhr does
101 var xhr = new XMLHttpRequest();
102 xhr.open(
"POST", document.location.href);
103 xhr.send(createDoc());
104 netscape.security.PrivilegeManager.enablePrivilege(
"UniversalXPConnect");
105 is(xhr.channel.QueryInterface(Components.interfaces.nsIHttpChannel)
106 .getRequestHeader(
"Content-Type"),
107 "application/xml; charset=UTF-8",
"Testing correct type on the wire");