content/base/test/test_html_in_xhr.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=651072
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 651072</title>
michael@0 8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
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 onload=runTest();>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=651072">Mozilla Bug 651072</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content" style="display: none">
michael@0 16
michael@0 17 </div>
michael@0 18 <pre id="test">
michael@0 19 <script class="testbody" type="text/javascript">
michael@0 20
michael@0 21 /** Test for Bug 651072 **/
michael@0 22 SimpleTest.waitForExplicitFinish();
michael@0 23
michael@0 24 var xhr = new XMLHttpRequest();
michael@0 25
michael@0 26 function runTest() {
michael@0 27 xhr.onreadystatechange = function() {
michael@0 28 if (this.readyState == 4) {
michael@0 29 ok(this.responseXML, "Should have gotten responseXML");
michael@0 30 is(this.responseXML.characterSet, "windows-1251", "Wrong character encoding");
michael@0 31 is(this.responseXML.documentElement.firstChild.data, " \u042E ", "Decoded using the wrong encoding.");
michael@0 32 try {
michael@0 33 this.responseText;
michael@0 34 ok(false, "responseText access should have thrown.");
michael@0 35 } catch (e) {
michael@0 36 is(e.name, "InvalidStateError", "Should have thrown InvalidStateError.");
michael@0 37 is(e.code, 11, "Should have thrown INVALID_STATE_ERR.");
michael@0 38 }
michael@0 39 is(this.responseXML.getElementsByTagName("div").length, 1, "There should be one div.");
michael@0 40 ok(!this.responseXML.documentElement.hasAttribute("data-fail"), "Should not have a data-fail attribute.");
michael@0 41 var scripts = this.responseXML.getElementsByTagName("script");
michael@0 42 is(scripts.length, 4, "Unexpected number of scripts.");
michael@0 43 while (scripts.length) {
michael@0 44 // These should not run when moved to another doc
michael@0 45 document.body.appendChild(scripts[0]);
michael@0 46 }
michael@0 47 var s = document.createElement("script");
michael@0 48 s.src = "file_html_in_xhr.sjs?report=1";
michael@0 49 document.body.appendChild(s);
michael@0 50 }
michael@0 51 }
michael@0 52 xhr.open("GET", "file_html_in_xhr.html", true);
michael@0 53 xhr.responseType = "document";
michael@0 54 xhr.send();
michael@0 55 }
michael@0 56
michael@0 57 function continueAfterReport() {
michael@0 58 xhr = new XMLHttpRequest();
michael@0 59 xhr.onreadystatechange = function() {
michael@0 60 if (this.readyState == 4) {
michael@0 61 is(this.responseText.indexOf("\u042E"), -1, "Honored meta in default mode.");
michael@0 62 is(this.responseText.indexOf("\uFFFD"), 29, "Honored meta in default mode 2.");
michael@0 63 is(this.responseXML, null, "responseXML should be null for HTML in the default mode");
michael@0 64 testNonParsingText();
michael@0 65 }
michael@0 66 }
michael@0 67 xhr.open("GET", "file_html_in_xhr2.html");
michael@0 68 xhr.send();
michael@0 69 }
michael@0 70
michael@0 71 function testNonParsingText() {
michael@0 72 xhr = new XMLHttpRequest();
michael@0 73 xhr.onreadystatechange = function() {
michael@0 74 if (this.readyState == 4) {
michael@0 75 is(this.responseText.indexOf("\u042E"), -1, "Honored meta in text mode.");
michael@0 76 is(this.responseText.indexOf("\uFFFD"), 29, "Honored meta in text mode 2.");
michael@0 77 testChunkedText();
michael@0 78 }
michael@0 79 }
michael@0 80 xhr.open("GET", "file_html_in_xhr2.html");
michael@0 81 xhr.responseType = "text";
michael@0 82 xhr.send();
michael@0 83 }
michael@0 84
michael@0 85 function testChunkedText() {
michael@0 86 xhr = new XMLHttpRequest();
michael@0 87 xhr.onprogress = function() {
michael@0 88 is(this.responseText.indexOf("\u042E"), -1, "Honored meta in chunked text mode.");
michael@0 89 }
michael@0 90 xhr.onreadystatechange = function() {
michael@0 91 if (this.readyState == 4) {
michael@0 92 testSyncXHR();
michael@0 93 }
michael@0 94 }
michael@0 95 xhr.open("GET", "file_html_in_xhr2.html");
michael@0 96 xhr.responseType = "moz-chunked-text";
michael@0 97 xhr.send();
michael@0 98 }
michael@0 99
michael@0 100 function testSyncXHR() {
michael@0 101 xhr = new XMLHttpRequest();
michael@0 102 xhr.open("GET", "file_html_in_xhr3.html", false);
michael@0 103 xhr.send();
michael@0 104 is(xhr.responseText, "SUCCESS\n", "responseText should be ready by now");
michael@0 105 is(xhr.responseXML, null, "responseXML should be null in the sync case");
michael@0 106 SimpleTest.finish();
michael@0 107 }
michael@0 108
michael@0 109 </script>
michael@0 110 </pre>
michael@0 111 </body>
michael@0 112 </html>
michael@0 113

mercurial