1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug431701.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=431701 1.8 +--> 1.9 +<head> 1.10 + <meta charset="windows-1252"> 1.11 + <title>Test for Bug 431701</title> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=431701">Mozilla Bug 431701</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + <iframe id="one"></iframe> 1.20 + <iframe id="two"></iframe> 1.21 + <iframe id="three"></iframe> 1.22 + <iframe id="four"></iframe> 1.23 + <iframe id="five"></iframe> 1.24 + <iframe id="six"></iframe> 1.25 + <iframe id="seven"></iframe> 1.26 +</div> 1.27 +<pre id="test"> 1.28 +<script class="testbody" type="text/javascript"> 1.29 + 1.30 +/** Test for Bug 431701 **/ 1.31 +SimpleTest.waitForExplicitFinish(); 1.32 + 1.33 +var docSources = [ 1.34 + "data:text/html,<html></html>", 1.35 + "data:text/html;charset=UTF-8,<html></html>", 1.36 + "data:text/html;charset=ISO-8859-1,<html></html>", 1.37 + "data:text/xml,<html></html>", 1.38 + "data:text/xml,<?xml version='1.0'?><html></html>", 1.39 + "data:text/xml,<?xml version='1.0' encoding='UTF-8'?><html></html>", 1.40 + "data:text/xml,<?xml version='1.0' encoding='ISO-8859-1'?><html></html>", 1.41 +]; 1.42 + 1.43 +for (var i = 0; i < docSources.length; ++i) { 1.44 + document.getElementsByTagName("iframe")[i].src = docSources[i]; 1.45 +} 1.46 + 1.47 +function frameDoc(id) { 1.48 + return function() { return $(id).contentDocument; }; 1.49 +} 1.50 + 1.51 +function createDoc() { 1.52 + return document.implementation.createDocument('', 'html', null); 1.53 +} 1.54 + 1.55 +function xhrDoc(idx) { 1.56 + return function() { 1.57 + // Defy same-origin restrictions! 1.58 + var xhr = new XMLHttpRequest({mozAnon: true, mozSystem: true}); 1.59 + xhr.open("GET", docSources[idx], false); 1.60 + xhr.send(); 1.61 + return xhr.responseXML; 1.62 + }; 1.63 +} 1.64 + 1.65 +// Each row has the document getter function, then the characterSet, 1.66 +// inputEncoding expected for that document. 1.67 + 1.68 +var tests = [ 1.69 + [ frameDoc("one"), "windows-1252", "windows-1252" ], 1.70 + [ frameDoc("two"), "UTF-8", "UTF-8" ], 1.71 + [ frameDoc("three"), "windows-1252", "windows-1252" ], 1.72 + [ frameDoc("four"), "UTF-8", "UTF-8" ], 1.73 + [ frameDoc("five"), "UTF-8", "UTF-8" ], 1.74 + [ frameDoc("six"), "UTF-8", "UTF-8" ], 1.75 + [ frameDoc("seven"), "windows-1252", "windows-1252" ], 1.76 + [ createDoc, "UTF-8", null ], 1.77 + [ xhrDoc(4), "UTF-8", "UTF-8" ], 1.78 + [ xhrDoc(5), "UTF-8", "UTF-8" ], 1.79 + [ xhrDoc(6), "windows-1252", "windows-1252" ], 1.80 +]; 1.81 + 1.82 +function doTest(idx) { 1.83 + var [docGetter, expectedCharacterSet, 1.84 + expectedInputEncoding] = tests[idx]; 1.85 + var doc = docGetter(); 1.86 + 1.87 + // Have to be careful here to catch null vs "" 1.88 + is(doc.characterSet, expectedCharacterSet, "Test " + idx + " characterSet"); 1.89 + is(doc.inputEncoding, expectedInputEncoding, 1.90 + "Test " + idx + " inputEncoding"); 1.91 +} 1.92 + 1.93 +addLoadEvent(function() { 1.94 + SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], startTest); 1.95 +}); 1.96 + 1.97 +function startTest() { 1.98 + // sanity check 1.99 + isnot("", null, "Shouldn't be equal!"); 1.100 + 1.101 + for (var i = 0; i < tests.length; ++i) { 1.102 + doTest(i); 1.103 + } 1.104 + 1.105 + // Now check what xhr does 1.106 + var xhr = new XMLHttpRequest(); 1.107 + xhr.open("POST", document.location.href); 1.108 + xhr.send(createDoc()); 1.109 + is(SpecialPowers.wrap(xhr).channel.QueryInterface(SpecialPowers.Ci.nsIHttpChannel) 1.110 + .getRequestHeader("Content-Type"), 1.111 + "application/xml; charset=UTF-8", "Testing correct type on the wire"); 1.112 + xhr.abort(); 1.113 + 1.114 + SimpleTest.finish(); 1.115 +}; 1.116 + 1.117 + 1.118 + 1.119 + 1.120 +</script> 1.121 +</pre> 1.122 +</body> 1.123 +</html> 1.124 +