content/base/test/test_bug431701.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial