Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=431701
5 -->
6 <head>
7 <meta charset="windows-1252">
8 <title>Test for Bug 431701</title>
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=431701">Mozilla Bug 431701</a>
14 <p id="display"></p>
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>
23 </div>
24 <pre id="test">
25 <script class="testbody" type="text/javascript">
27 /** Test for Bug 431701 **/
28 SimpleTest.waitForExplicitFinish();
30 var docSources = [
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>",
38 ];
40 for (var i = 0; i < docSources.length; ++i) {
41 document.getElementsByTagName("iframe")[i].src = docSources[i];
42 }
44 function frameDoc(id) {
45 return function() { return $(id).contentDocument; };
46 }
48 function createDoc() {
49 return document.implementation.createDocument('', 'html', null);
50 }
52 function xhrDoc(idx) {
53 return function() {
54 // Defy same-origin restrictions!
55 var xhr = new XMLHttpRequest({mozAnon: true, mozSystem: true});
56 xhr.open("GET", docSources[idx], false);
57 xhr.send();
58 return xhr.responseXML;
59 };
60 }
62 // Each row has the document getter function, then the characterSet,
63 // inputEncoding expected for that document.
65 var tests = [
66 [ frameDoc("one"), "windows-1252", "windows-1252" ],
67 [ frameDoc("two"), "UTF-8", "UTF-8" ],
68 [ frameDoc("three"), "windows-1252", "windows-1252" ],
69 [ frameDoc("four"), "UTF-8", "UTF-8" ],
70 [ frameDoc("five"), "UTF-8", "UTF-8" ],
71 [ frameDoc("six"), "UTF-8", "UTF-8" ],
72 [ frameDoc("seven"), "windows-1252", "windows-1252" ],
73 [ createDoc, "UTF-8", null ],
74 [ xhrDoc(4), "UTF-8", "UTF-8" ],
75 [ xhrDoc(5), "UTF-8", "UTF-8" ],
76 [ xhrDoc(6), "windows-1252", "windows-1252" ],
77 ];
79 function doTest(idx) {
80 var [docGetter, expectedCharacterSet,
81 expectedInputEncoding] = tests[idx];
82 var doc = docGetter();
84 // Have to be careful here to catch null vs ""
85 is(doc.characterSet, expectedCharacterSet, "Test " + idx + " characterSet");
86 is(doc.inputEncoding, expectedInputEncoding,
87 "Test " + idx + " inputEncoding");
88 }
90 addLoadEvent(function() {
91 SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], startTest);
92 });
94 function startTest() {
95 // sanity check
96 isnot("", null, "Shouldn't be equal!");
98 for (var i = 0; i < tests.length; ++i) {
99 doTest(i);
100 }
102 // Now check what xhr does
103 var xhr = new XMLHttpRequest();
104 xhr.open("POST", document.location.href);
105 xhr.send(createDoc());
106 is(SpecialPowers.wrap(xhr).channel.QueryInterface(SpecialPowers.Ci.nsIHttpChannel)
107 .getRequestHeader("Content-Type"),
108 "application/xml; charset=UTF-8", "Testing correct type on the wire");
109 xhr.abort();
111 SimpleTest.finish();
112 };
117 </script>
118 </pre>
119 </body>
120 </html>