107 lines
2.7 KiB
HTML
107 lines
2.7 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../resources/js-test-pre.js"></script>
|
|
<style type="text/css">
|
|
.box {
|
|
display: box;
|
|
border: 1px solid black;
|
|
margin-bottom: 0.5em;
|
|
}
|
|
.boxheader {
|
|
font-weight: bold;
|
|
color: maroon;
|
|
}
|
|
pre {
|
|
margin-left: 2em;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="description"></div>
|
|
|
|
<div class="box"><span class="boxheader">responseText</span>
|
|
<pre id="id1">@@No result@@</pre>
|
|
</div>
|
|
<br>
|
|
|
|
<div id="console"></div>
|
|
|
|
<script>
|
|
description("Tests XMLHttpRequest 'text' loading with the .responseType and .response attributes.");
|
|
|
|
var xhr = 0;
|
|
|
|
function load() {
|
|
testPassed('DONE LOADING');
|
|
testPassed('received response object of type : ' + typeof xhr.response + ".");
|
|
|
|
// Make sure exception is thrown if responseType is set too late in the loading process.
|
|
// .responseType was previously set to "text". Let's try setting it to "arraybuffer".
|
|
try {
|
|
xhr.responseType = "arraybuffer";
|
|
} catch(e) {
|
|
testPassed("exception correctly thrown when xhr.responseType is set to valid value too late in the loading process : " + e + ".");
|
|
}
|
|
|
|
// Get .responseText
|
|
document.getElementById("id1").firstChild.nodeValue = xhr.responseText;
|
|
|
|
// .response is really just an alias to .responseText when .responseType is set to "text".
|
|
// Make sure they're the same.
|
|
if (xhr.response == xhr.responseText)
|
|
testPassed("xhr.response == xhr.responseText.");
|
|
else
|
|
testFailed("xhr.response == xhr.responseText.");
|
|
|
|
xhr = null;
|
|
finishJSTest();
|
|
}
|
|
|
|
function runTest() {
|
|
if (window.testRunner) {
|
|
testRunner.dumpAsText();
|
|
testRunner.waitUntilDone();
|
|
}
|
|
|
|
xhr = new XMLHttpRequest();
|
|
xhr.onload = load;
|
|
xhr.open("GET", "resources/xmlhttprequest-get-data.xml", true);
|
|
|
|
try {
|
|
if ("responseType" in xhr)
|
|
testPassed("responseType property exists.");
|
|
else
|
|
testFailed("responseType property does not exist.");
|
|
|
|
|
|
if ("response" in xhr)
|
|
testPassed("response property exists.");
|
|
else
|
|
testFailed("response property does not exist.");
|
|
|
|
// Make sure we can set responseType to "text" before send() is called.
|
|
try {
|
|
xhr.responseType = "text";
|
|
if (xhr.responseType == "text")
|
|
testPassed("xhr.responseType has been correctly set to 'text'.");
|
|
} catch(e) {
|
|
testFailed("unable to set xhr.responseType to 'text' " + e + ".");
|
|
}
|
|
} catch(e) {
|
|
testFailed("Caught exception " + e + ".");
|
|
}
|
|
|
|
xhr.send(null);
|
|
window.jsTestIsAsync = true;
|
|
}
|
|
|
|
runTest();
|
|
|
|
</script>
|
|
|
|
<script src="../../resources/js-test-post.js"></script>
|
|
|
|
</body>
|
|
</html>
|