Skip to content

Commit

Permalink
fixing two more tests that tried to use responseType with sync requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hallvord R. M. Steen committed Nov 1, 2013
1 parent b8e1256 commit a697f64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
16 changes: 11 additions & 5 deletions XMLHttpRequest/responsetext-decoding.htm
Expand Up @@ -11,15 +11,21 @@
<div id="log"></div>
<script>
function request(type, input, output, responseType) {
test(function() {
var test = async_test(document.title + " (" + type + " " + input + ")");
test.step(function() {
var client = new XMLHttpRequest()
if (responseType !== undefined) {
client.responseType = responseType
}
client.open("GET", "resources/status.php?content=" + input + "&type=" + encodeURIComponent(type), false)
client.open("GET", "resources/status.php?content=" + input + "&type=" + encodeURIComponent(type), true)
client.onload = function(){
test.step(function(){
assert_equals(client.responseText, output)
test.done()
})
}
client.send(null)
assert_equals(client.responseText, output)
}, document.title + " (" + type + " " + input + ")")
})
}
request("application/xml", encodeURIComponent("<?xml version='1.0' encoding='windows-1252'?><x>")+'%FF'+encodeURIComponent("<\/x>"), "<?xml version='1.0' encoding='windows-1252'?><x>\u00FF<\/x>")
request("text/html", encodeURIComponent("<!doctype html><meta charset=windows-1252>")+"%FF", "<!doctype html><meta charset=windows-1252>\u00FF")
Expand All @@ -37,7 +43,7 @@
request("text/xml", "%EF%BB%BF", "")
request("text/xml", "%EF%BB%BF%EF%BB%BF", "\uFEFF")
request("text/plain", "%E3%81%B2", "\u3072", 'text')
// the point of the following test: setting responseType=text should (per spec #text-response-entity-body point 3)
// the point of the following test: setting responseType=text should (per spec #text-response-entity-body point 3)
// skip some of the charset detection even for XML resources. The test uses a wilfully mislabelled XMLish response
// and the pass condition is that the responseType = text makes the decoder fall back to UTF-8
request("text/xml", encodeURIComponent("<?xml version='1.0' encoding='windows-1252'?><x>")+"%E3%81%B2"+encodeURIComponent("<\/x>"), "<?xml version='1.0' encoding='windows-1252'?><x>\u3072<\/x>", 'text')
Expand Down
15 changes: 10 additions & 5 deletions XMLHttpRequest/responsexml-non-document-types.htm
Expand Up @@ -12,14 +12,19 @@
<div id="log"></div>
<script>
function request(type) {
test(function() {
var test = async_test(document.title+' ('+type+')')
test.step(function() {
var client = new XMLHttpRequest()
client.responseType = type
client.open("GET", "resources/well-formed.xml", false)
client.open("GET", "resources/well-formed.xml", true)
client.onload = function(){
test.step(function(){
if(type !== 'document')assert_throws("InvalidStateError", function() {var x = client.responseXML}, 'responseXML throw for '+type)
if(type !== 'text')assert_throws("InvalidStateError", function() {var x = client.responseText}, 'responseText throws for '+type)
})
}
client.send(null)
if(type !== 'document')assert_throws("InvalidStateError", function() {var x = client.responseXML}, 'responseXML throw for '+type)
if(type !== 'text')assert_throws("InvalidStateError", function() {var x = client.responseText}, 'responseText throws for '+type)
}, document.title+' ('+type+')')
})
}
request("arraybuffer")
request("blob")
Expand Down

0 comments on commit a697f64

Please sign in to comment.