test_bug431701.html (3174B)
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"> 26 SpecialPowers.pushPrefEnv({ 27 set: [["network.xhr.block_sync_system_requests", false]] 28 }); 29 30 /** Test for Bug 431701 */ 31 SimpleTest.waitForExplicitFinish(); 32 33 var docSources = [ 34 "iframe1_bug431701.html", 35 "iframe2_bug431701.html", 36 "iframe3_bug431701.html", 37 "iframe4_bug431701.xml", 38 "iframe5_bug431701.xml", 39 "iframe6_bug431701.xml", 40 "iframe7_bug431701.xml", 41 ]; 42 43 for (let i = 0; i < docSources.length; ++i) { 44 document.getElementsByTagName("iframe")[i].src = docSources[i]; 45 } 46 47 function frameDoc(id) { 48 return function() { return $(id).contentDocument; }; 49 } 50 51 function createDoc() { 52 return document.implementation.createDocument('', 'html', null); 53 } 54 55 function xhrDoc(idx) { 56 return function() { 57 // Defy same-origin restrictions! 58 var xhr = new XMLHttpRequest({mozAnon: true, mozSystem: true}); 59 xhr.open("GET", docSources[idx], false); 60 xhr.send(); 61 return xhr.responseXML; 62 }; 63 } 64 65 // Each row has the document getter function, then the characterSet, 66 // inputEncoding expected for that document. 67 68 var tests = [ 69 [ frameDoc("one"), "windows-1252" ], 70 [ frameDoc("two"), "UTF-8" ], 71 [ frameDoc("three"), "windows-1252" ], 72 [ frameDoc("four"), "UTF-8" ], 73 [ frameDoc("five"), "UTF-8" ], 74 [ frameDoc("six"), "UTF-8" ], 75 [ frameDoc("seven"), "windows-1252" ], 76 [ createDoc, "UTF-8" ], 77 [ xhrDoc(4), "UTF-8" ], 78 [ xhrDoc(5), "UTF-8" ], 79 [ xhrDoc(6), "windows-1252" ], 80 ]; 81 82 function doTest(idx) { 83 var [docGetter, expectedCharacterSet] = tests[idx]; 84 var doc = docGetter(); 85 86 // Have to be careful here to catch null vs "" 87 is(doc.characterSet, expectedCharacterSet, "Test " + idx + " characterSet"); 88 is(doc.inputEncoding, expectedCharacterSet, 89 "Test " + idx + " inputEncoding"); 90 } 91 92 addLoadEvent(function() { 93 SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], startTest); 94 }); 95 96 function startTest() { 97 // sanity check 98 isnot("", null, "Shouldn't be equal!"); 99 100 for (let i = 0; i < tests.length; ++i) { 101 doTest(i); 102 } 103 104 // Now check what xhr does 105 var xhr = new XMLHttpRequest(); 106 xhr.open("POST", document.location.href); 107 xhr.send(createDoc()); 108 is(SpecialPowers.wrap(xhr).channel.QueryInterface(SpecialPowers.Ci.nsIHttpChannel) 109 .getRequestHeader("Content-Type"), 110 "application/xml;charset=UTF-8", "Testing correct type on the wire"); 111 xhr.abort(); 112 113 SimpleTest.finish(); 114 }; 115 116 117 118 119 </script> 120 </pre> 121 </body> 122 </html>