1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_html_in_xhr.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,113 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=651072 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 651072</title> 1.11 + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> 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 onload=runTest();> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=651072">Mozilla Bug 651072</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script class="testbody" type="text/javascript"> 1.23 + 1.24 +/** Test for Bug 651072 **/ 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 + 1.27 +var xhr = new XMLHttpRequest(); 1.28 + 1.29 +function runTest() { 1.30 + xhr.onreadystatechange = function() { 1.31 + if (this.readyState == 4) { 1.32 + ok(this.responseXML, "Should have gotten responseXML"); 1.33 + is(this.responseXML.characterSet, "windows-1251", "Wrong character encoding"); 1.34 + is(this.responseXML.documentElement.firstChild.data, " \u042E ", "Decoded using the wrong encoding."); 1.35 + try { 1.36 + this.responseText; 1.37 + ok(false, "responseText access should have thrown."); 1.38 + } catch (e) { 1.39 + is(e.name, "InvalidStateError", "Should have thrown InvalidStateError."); 1.40 + is(e.code, 11, "Should have thrown INVALID_STATE_ERR."); 1.41 + } 1.42 + is(this.responseXML.getElementsByTagName("div").length, 1, "There should be one div."); 1.43 + ok(!this.responseXML.documentElement.hasAttribute("data-fail"), "Should not have a data-fail attribute."); 1.44 + var scripts = this.responseXML.getElementsByTagName("script"); 1.45 + is(scripts.length, 4, "Unexpected number of scripts."); 1.46 + while (scripts.length) { 1.47 + // These should not run when moved to another doc 1.48 + document.body.appendChild(scripts[0]); 1.49 + } 1.50 + var s = document.createElement("script"); 1.51 + s.src = "file_html_in_xhr.sjs?report=1"; 1.52 + document.body.appendChild(s); 1.53 + } 1.54 + } 1.55 + xhr.open("GET", "file_html_in_xhr.html", true); 1.56 + xhr.responseType = "document"; 1.57 + xhr.send(); 1.58 +} 1.59 + 1.60 +function continueAfterReport() { 1.61 + xhr = new XMLHttpRequest(); 1.62 + xhr.onreadystatechange = function() { 1.63 + if (this.readyState == 4) { 1.64 + is(this.responseText.indexOf("\u042E"), -1, "Honored meta in default mode."); 1.65 + is(this.responseText.indexOf("\uFFFD"), 29, "Honored meta in default mode 2."); 1.66 + is(this.responseXML, null, "responseXML should be null for HTML in the default mode"); 1.67 + testNonParsingText(); 1.68 + } 1.69 + } 1.70 + xhr.open("GET", "file_html_in_xhr2.html"); 1.71 + xhr.send(); 1.72 +} 1.73 + 1.74 +function testNonParsingText() { 1.75 + xhr = new XMLHttpRequest(); 1.76 + xhr.onreadystatechange = function() { 1.77 + if (this.readyState == 4) { 1.78 + is(this.responseText.indexOf("\u042E"), -1, "Honored meta in text mode."); 1.79 + is(this.responseText.indexOf("\uFFFD"), 29, "Honored meta in text mode 2."); 1.80 + testChunkedText(); 1.81 + } 1.82 + } 1.83 + xhr.open("GET", "file_html_in_xhr2.html"); 1.84 + xhr.responseType = "text"; 1.85 + xhr.send(); 1.86 +} 1.87 + 1.88 +function testChunkedText() { 1.89 + xhr = new XMLHttpRequest(); 1.90 + xhr.onprogress = function() { 1.91 + is(this.responseText.indexOf("\u042E"), -1, "Honored meta in chunked text mode."); 1.92 + } 1.93 + xhr.onreadystatechange = function() { 1.94 + if (this.readyState == 4) { 1.95 + testSyncXHR(); 1.96 + } 1.97 + } 1.98 + xhr.open("GET", "file_html_in_xhr2.html"); 1.99 + xhr.responseType = "moz-chunked-text"; 1.100 + xhr.send(); 1.101 +} 1.102 + 1.103 +function testSyncXHR() { 1.104 + xhr = new XMLHttpRequest(); 1.105 + xhr.open("GET", "file_html_in_xhr3.html", false); 1.106 + xhr.send(); 1.107 + is(xhr.responseText, "SUCCESS\n", "responseText should be ready by now"); 1.108 + is(xhr.responseXML, null, "responseXML should be null in the sync case"); 1.109 + SimpleTest.finish(); 1.110 +} 1.111 + 1.112 +</script> 1.113 +</pre> 1.114 +</body> 1.115 +</html> 1.116 +