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