Commit 01f283a2 authored by crogers@google.com's avatar crogers@google.com

2010-11-23 Chris Rogers <crogers@google.com>

        Reviewed by Alexey Proskuryakov.

        Add .responseType and .response to XMLHttpRequest
        https://bugs.webkit.org/show_bug.cgi?id=49633

        Tests: fast/xmlhttprequest/xmlhttprequest-responsetype-abort.html
               fast/xmlhttprequest/xmlhttprequest-responsetype-arraybuffer.html
               fast/xmlhttprequest/xmlhttprequest-responsetype-document.html
               fast/xmlhttprequest/xmlhttprequest-responsetype-text.html

        * bindings/js/JSXMLHttpRequestCustom.cpp:
        (WebCore::JSXMLHttpRequest::markChildren):
        (WebCore::JSXMLHttpRequest::open):
        (WebCore::JSXMLHttpRequest::response):
        * bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
        (WebCore::V8XMLHttpRequest::responseAccessorGetter):
        * xml/XMLHttpRequest.cpp:
        (WebCore::XMLHttpRequest::XMLHttpRequest):
        (WebCore::XMLHttpRequest::responseText):
        (WebCore::XMLHttpRequest::responseXML):
        (WebCore::XMLHttpRequest::responseBlob):
        (WebCore::XMLHttpRequest::responseArrayBuffer):
        (WebCore::XMLHttpRequest::setResponseType):
        (WebCore::XMLHttpRequest::responseType):
        (WebCore::XMLHttpRequest::setAsBlob):
        (WebCore::XMLHttpRequest::open):
        (WebCore::XMLHttpRequest::clearResponse):
        (WebCore::XMLHttpRequest::didFinishLoading):
        (WebCore::XMLHttpRequest::didReceiveData):
        * xml/XMLHttpRequest.h:
        (WebCore::XMLHttpRequest::asBlob):
        (WebCore::XMLHttpRequest::optionalResponseXML):
        (WebCore::XMLHttpRequest::optionalResponseBlob):
        (WebCore::XMLHttpRequest::responseTypeCode):
        (WebCore::XMLHttpRequest::optionalResponseArrayBuffer):
        * xml/XMLHttpRequest.idl:
2010-11-23  Chris Rogers  <crogers@google.com>

        Reviewed by Alexey Proskuryakov.

        Add .responseType and .response to XMLHttpRequest
        https://bugs.webkit.org/show_bug.cgi?id=49633

        * fast/xmlhttprequest/xmlhttprequest-responsetype-abort-expected.txt: Added.
        * fast/xmlhttprequest/xmlhttprequest-responsetype-abort.html: Added.
        * fast/xmlhttprequest/xmlhttprequest-responsetype-arraybuffer-expected.txt: Added.
        * fast/xmlhttprequest/xmlhttprequest-responsetype-arraybuffer.html: Added.
        * fast/xmlhttprequest/xmlhttprequest-responsetype-document-expected.txt: Added.
        * fast/xmlhttprequest/xmlhttprequest-responsetype-document.html: Added.
        * fast/xmlhttprequest/xmlhttprequest-responsetype-text-expected.txt: Added.
        * fast/xmlhttprequest/xmlhttprequest-responsetype-text.html: Added.
        * http/tests/resources/balls-of-the-orient.aif: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72626 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 19619a92
2010-11-23 Chris Rogers <crogers@google.com>
Reviewed by Alexey Proskuryakov.
Add .responseType and .response to XMLHttpRequest
https://bugs.webkit.org/show_bug.cgi?id=49633
* fast/xmlhttprequest/xmlhttprequest-responsetype-abort-expected.txt: Added.
* fast/xmlhttprequest/xmlhttprequest-responsetype-abort.html: Added.
* fast/xmlhttprequest/xmlhttprequest-responsetype-arraybuffer-expected.txt: Added.
* fast/xmlhttprequest/xmlhttprequest-responsetype-arraybuffer.html: Added.
* fast/xmlhttprequest/xmlhttprequest-responsetype-document-expected.txt: Added.
* fast/xmlhttprequest/xmlhttprequest-responsetype-document.html: Added.
* fast/xmlhttprequest/xmlhttprequest-responsetype-text-expected.txt: Added.
* fast/xmlhttprequest/xmlhttprequest-responsetype-text.html: Added.
* http/tests/resources/balls-of-the-orient.aif: Added.
2010-11-23 Abhishek Arya <inferno@chromium.org>
Reviewed by Adam Barth.
Tests aborting XMLHttpRequest 'arraybuffer' loading with the .responseType and .response attributes.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS responseType property exists.
PASS response property exists.
PASS xhr.responseType has been correctly set to 'arraybuffer'.
PASS abort() was called.
PASS 'arraybuffer' .response does not exist after aborted load.
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css"/>
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Tests aborting XMLHttpRequest 'arraybuffer' loading with the .responseType and .response attributes.");
var xhr = 0;
function abort() {
testPassed("abort() was called.");
// For aborted 'arraybuffer' the .response should not yet exist.
if (!xhr.response)
testPassed("'arraybuffer' .response does not exist after aborted load.");
else
testFailed("'arraybuffer' .response should not exist after aborted load.");
xhr = null;
finishJSTest();
}
function load() {
testFailed("onload() should not be called since loading was aborted.");
xhr = null;
finishJSTest();
}
function runTest() {
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
xhr = new XMLHttpRequest();
xhr.onload = load;
xhr.onabort = abort;
xhr.open("GET", "../../http/tests/resources/balls-of-the-orient.aif", true);
try {
if ("responseType" in xhr)
testPassed("responseType property exists.");
if ("response" in xhr)
testPassed("response property exists.");
// Make sure we can set responseType to "arraybuffer" before send() is called.
try {
xhr.responseType = "arraybuffer";
if (xhr.responseType == "arraybuffer")
testPassed("xhr.responseType has been correctly set to 'arraybuffer'.");
} catch(e) {
testFailed("unable to set xhr.responseType to 'arraybuffer' " + e + ".");
}
} catch(e) {
testFailed("Caught exception " + e + ".");
}
xhr.send(null);
xhr.abort();
window.jsTestIsAsync = true;
}
runTest();
successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
Tests XMLHttpRequest 'arraybuffer' loading with the .responseType and .response attributes.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS 'arraybuffer' .response does not exist when .readyState is 1.
PASS responseType property exists.
PASS response property exists.
PASS xhr.responseType is initially set to default value of empty string.
PASS xhr.responseType has been correctly set to ''.
PASS xhr.responseType has been correctly set to 'text'.
PASS xhr.responseType has been correctly set to 'document'.
PASS xhr.responseType has been correctly set to 'arraybuffer'.
PASS exception correctly thrown when xhr.responseType is set to invalid value : Error: SYNTAX_ERR: DOM Exception 12.
PASS 'arraybuffer' .response does not exist when .readyState is 2.
PASS 'arraybuffer' .response does not exist when .readyState is 3.
PASS 'arraybuffer' .response exists when .readyState is 4.
PASS DONE LOADING
PASS received response object : [object ArrayBuffer].
PASS exception correctly thrown when xhr.responseType is set to valid value too late in the loading process : Error: INVALID_STATE_ERR: DOM Exception 11.
response length : 670184.
bytes at offset 0 : 46 4f 52 4d 0 a 39 e0
bytes at offset 356874 : a 91 f 5f 8 2f e fd
bytes at offset 670166 : 8 be 3 c 6 91 2 8
checksum : 84637740
PASS exception correctly thrown when xhr.responseText is accessed but responseType is 'arraybuffer' : Error: INVALID_STATE_ERR: DOM Exception 11.
PASS exception correctly thrown when xhr.responseXML is accessed but responseType is 'arraybuffer' : Error: INVALID_STATE_ERR: DOM Exception 11.
PASS xhr.response.foo is 'bar'
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css"/>
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Tests XMLHttpRequest 'arraybuffer' loading with the .responseType and .response attributes.");
var xhr = 0;
var lastState = 0;
function stateChange() {
// Protect against race-condition where .onreadystatechange sometimes will be called multiple times for the same state.
if (xhr.readyState == lastState)
return;
lastState = xhr.readyState;
if (xhr.readyState == XMLHttpRequest.DONE) {
// Check that .response exists when .readyState is DONE
if (xhr.response)
testPassed("'arraybuffer' .response exists when .readyState is " + xhr.readyState + ".");
else
testFailed("'arraybuffer' .response should exist when .readyState is " + xhr.readyState + ".");
} else {
// Otherwise, for 'arraybuffer' the .response should not yet exist.
if (!xhr.response)
testPassed("'arraybuffer' .response does not exist when .readyState is " + xhr.readyState + ".");
else
testFailed("'arraybuffer' .response should not exist when .readyState is " + xhr.readyState + ".");
}
}
function logBytesAtOffset(buffer8, offset) {
var s = "bytes at offset " + offset + " : ";
for (var i = 0; i < 8; ++i)
s += buffer8[i + offset].toString(16) + ' ';
debug(s);
}
function load() {
testPassed('DONE LOADING');
testPassed('received response object : ' + xhr.response + ".");
// Make sure exception is thrown if responseType is set too late in the loading process.
try {
xhr.responseType = "text";
} catch(e) {
testPassed("exception correctly thrown when xhr.responseType is set to valid value too late in the loading process : " + e + ".");
}
var buffer = xhr.response;
// Interpret the ArrayBuffer as Uint8Array.
var buffer8 = new Uint8Array(buffer);
buffer8.set(buffer);
var totalLength = buffer8.length;
debug('response length : ' + totalLength + ".");
// Log the bytes at the start, in the middle, and near the end:
logBytesAtOffset(buffer8, 0);
logBytesAtOffset(buffer8, 0x5720A);
logBytesAtOffset(buffer8, 0xA39D6);
// Calculate checksum.
var sum = 0;
for (var i = 0; i < totalLength; ++i) {
sum += buffer8[i];
}
debug('checksum : ' + sum);
// Check that xhr.responseText throws an exception:
try {
var x = xhr.responseText;
} catch(e) {
testPassed("exception correctly thrown when xhr.responseText is accessed but responseType is 'arraybuffer' : " + e + ".");
}
// Check that xhr.responseXML throws an exception:
try {
var x = xhr.responseXML;
} catch(e) {
testPassed("exception correctly thrown when xhr.responseXML is accessed but responseType is 'arraybuffer' : " + e + ".");
}
// Test .response garbage collection.
xhr.response.foo = "bar";
gc();
shouldBe("xhr.response.foo", "'bar'");
xhr = null;
finishJSTest();
}
function runTest() {
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
xhr = new XMLHttpRequest();
xhr.onreadystatechange = stateChange;
xhr.onload = load;
xhr.open("GET", "../../http/tests/resources/balls-of-the-orient.aif", true);
try {
if ("responseType" in xhr)
testPassed("responseType property exists.");
if ("response" in xhr)
testPassed("response property exists.");
if (xhr.responseType == "")
testPassed("xhr.responseType is initially set to default value of empty string.");
// Make sure we can set responseType to valid values before send() is called.
try {
xhr.responseType = "";
if (xhr.responseType == "")
testPassed("xhr.responseType has been correctly set to ''.");
xhr.responseType = "text";
if (xhr.responseType == "text")
testPassed("xhr.responseType has been correctly set to 'text'.");
xhr.responseType = "document";
if (xhr.responseType == "document")
testPassed("xhr.responseType has been correctly set to 'document'.");
xhr.responseType = "arraybuffer";
if (xhr.responseType == "arraybuffer")
testPassed("xhr.responseType has been correctly set to 'arraybuffer'.");
} catch(e) {
testFailed("unable to set xhr.responseType to a valid value " + e + ".");
}
// Make sure exception is thrown if responseType is set to invalid value.
try {
xhr.responseType = "dkjdfkjdfkj";
} catch(e) {
testPassed("exception correctly thrown when xhr.responseType is set to invalid value : " + e + ".");
}
} catch(e) {
testFailed("Caught exception " + e + ".");
}
xhr.send(null);
window.jsTestIsAsync = true;
}
runTest();
successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
Tests XMLHttpRequest 'document' loading with the .responseType and .response attributes.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS responseType property exists.
PASS response property exists.
PASS xhr.responseType has been correctly set to 'document'.
PASS DONE LOADING
PASS received response object of type : object.
PASS exception correctly thrown when xhr.responseType is set to valid value too late in the loading process : Error: INVALID_STATE_ERR: DOM Exception 11.
PASS xhr.response is a Document.
PASS xhr.response == xhr.responseXML.
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css"/>
<script src="../js/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 id="console"></div>
<script>
description("Tests XMLHttpRequest 'document' 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 "document". 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 + ".");
}
// Check that .response is a Document
if (xhr.response.documentElement.tagName == 'doc')
testPassed("xhr.response is a Document.");
else
testFailed("xhr.response should be a Document.");
// .response is really just an alias to .responseXML when .responseType is set to "document".
// Make sure they're the same.
if (xhr.response == xhr.responseXML)
testPassed("xhr.response == xhr.responseXML.");
else
testFailed("xhr.response == xhr.responseXML.");
xhr = null;
finishJSTest();
}
function runTest() {
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.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 "document" before send() is called.
try {
xhr.responseType = "document";
if (xhr.responseType == "document")
testPassed("xhr.responseType has been correctly set to 'document'.");
} catch(e) {
testFailed("unable to set xhr.responseType to 'document' " + e + ".");
}
} catch(e) {
testFailed("Caught exception " + e + ".");
}
xhr.send(null);
window.jsTestIsAsync = true;
}
runTest();
successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
Tests XMLHttpRequest 'text' loading with the .responseType and .response attributes.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
responseText
<?xml version="1.0"?>
<!DOCTYPE doc [
<!ATTLIST d id ID #IMPLIED>
]>
<doc>
<foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>
<d id="id3">Three</d>
</doc>
PASS responseType property exists.
PASS response property exists.
PASS xhr.responseType has been correctly set to 'text'.
PASS DONE LOADING
PASS received response object of type : string.
PASS exception correctly thrown when xhr.responseType is set to valid value too late in the loading process : Error: INVALID_STATE_ERR: DOM Exception 11.
PASS xhr.response == xhr.responseText.
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css"/>
<script src="../js/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.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.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();
successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
2010-11-23 Chris Rogers <crogers@google.com>
Reviewed by Alexey Proskuryakov.
Add .responseType and .response to XMLHttpRequest
https://bugs.webkit.org/show_bug.cgi?id=49633
Tests: fast/xmlhttprequest/xmlhttprequest-responsetype-abort.html
fast/xmlhttprequest/xmlhttprequest-responsetype-arraybuffer.html
fast/xmlhttprequest/xmlhttprequest-responsetype-document.html
fast/xmlhttprequest/xmlhttprequest-responsetype-text.html
* bindings/js/JSXMLHttpRequestCustom.cpp:
(WebCore::JSXMLHttpRequest::markChildren):
(WebCore::JSXMLHttpRequest::open):
(WebCore::JSXMLHttpRequest::response):
* bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
(WebCore::V8XMLHttpRequest::responseAccessorGetter):
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::XMLHttpRequest):
(WebCore::XMLHttpRequest::responseText):
(WebCore::XMLHttpRequest::responseXML):
(WebCore::XMLHttpRequest::responseBlob):
(WebCore::XMLHttpRequest::responseArrayBuffer):
(WebCore::XMLHttpRequest::setResponseType):
(WebCore::XMLHttpRequest::responseType):
(WebCore::XMLHttpRequest::setAsBlob):
(WebCore::XMLHttpRequest::open):
(WebCore::XMLHttpRequest::clearResponse):
(WebCore::XMLHttpRequest::didFinishLoading):
(WebCore::XMLHttpRequest::didReceiveData):
* xml/XMLHttpRequest.h:
(WebCore::XMLHttpRequest::asBlob):
(WebCore::XMLHttpRequest::optionalResp