Bug 1686668 [wpt PR 27185] - Update wpt metadata, a=testonly
[gecko.git] / dom / base / test / test_bug431701.html
blob4009fc017af78729642eab63d8c4308ce9e22d93
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 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 "iframe1_bug431701.html",
32 "iframe2_bug431701.html",
33 "iframe3_bug431701.html",
34 "iframe4_bug431701.xml",
35 "iframe5_bug431701.xml",
36 "iframe6_bug431701.xml",
37 "iframe7_bug431701.xml",
40 for (let 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) {
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;
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" ],
67 [ frameDoc("two"), "UTF-8" ],
68 [ frameDoc("three"), "windows-1252" ],
69 [ frameDoc("four"), "UTF-8" ],
70 [ frameDoc("five"), "UTF-8" ],
71 [ frameDoc("six"), "UTF-8" ],
72 [ frameDoc("seven"), "windows-1252" ],
73 [ createDoc, "UTF-8" ],
74 [ xhrDoc(4), "UTF-8" ],
75 [ xhrDoc(5), "UTF-8" ],
76 [ xhrDoc(6), "windows-1252" ],
79 function doTest(idx) {
80 var [docGetter, expectedCharacterSet] = tests[idx];
81 var doc = docGetter();
83 // Have to be careful here to catch null vs ""
84 is(doc.characterSet, expectedCharacterSet, "Test " + idx + " characterSet");
85 is(doc.inputEncoding, expectedCharacterSet,
86 "Test " + idx + " inputEncoding");
89 addLoadEvent(function() {
90 SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], startTest);
91 });
93 function startTest() {
94 // sanity check
95 isnot("", null, "Shouldn't be equal!");
97 for (let i = 0; i < tests.length; ++i) {
98 doTest(i);
101 // Now check what xhr does
102 var xhr = new XMLHttpRequest();
103 xhr.open("POST", document.location.href);
104 xhr.send(createDoc());
105 is(SpecialPowers.wrap(xhr).channel.QueryInterface(SpecialPowers.Ci.nsIHttpChannel)
106 .getRequestHeader("Content-Type"),
107 "application/xml;charset=UTF-8", "Testing correct type on the wire");
108 xhr.abort();
110 SimpleTest.finish();
116 </script>
117 </pre>
118 </body>
119 </html>