tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_html_in_xhr.html (3229B)


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