Commit 4d7deb1f authored by ap@apple.com's avatar ap@apple.com

XHR.response is null when requesting empty file as arraybuffer

https://bugs.webkit.org/show_bug.cgi?id=123457

Source/WebCore:

Reviewed by Sam Weinig.

Test: http/tests/xmlhttprequest/response-empty-arraybuffer.html

* xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::responseArrayBuffer): Don't do this.

LayoutTests:

Based on a Blink test by yusukesuzuki@chromium.org.

Reviewed by Sam Weinig.

Failures in expected results appear to mean that Blink caches XHR responses in more
cases. It's not directly related to the patch.

* http/tests/xmlhttprequest/response-empty-arraybuffer-expected.txt: Added.
* http/tests/xmlhttprequest/response-empty-arraybuffer.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@158333 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3a38f1e0
2013-10-30 Alexey Proskuryakov <ap@apple.com>
XHR.response is null when requesting empty file as arraybuffer
https://bugs.webkit.org/show_bug.cgi?id=123457
Based on a Blink test by yusukesuzuki@chromium.org.
Reviewed by Sam Weinig.
Failures in expected results appear to mean that Blink caches XHR responses in more
cases. It's not directly related to the patch.
* http/tests/xmlhttprequest/response-empty-arraybuffer-expected.txt: Added.
* http/tests/xmlhttprequest/response-empty-arraybuffer.html: Added.
2013-10-30 Samuel White <samuel_white@apple.com>
AX: AXFocused not exposed on ARIA menuitems
......
Test that XMLHttpRequest.response returns an empty ArrayBuffer when received a response without an entity body.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Test that XMLHttpRequest.response returns an empty ArrayBuffer when received a response with zero content length.
PASS request.status is 200
PASS Object.prototype.toString.call(request.response) is '[object ArrayBuffer]'
PASS request.response.byteLength is 0
Test that XMLHttpRequest.response returns an empty ArrayBuffer when received status is '304 not modified'.
PASS request.status is 200
PASS Object.prototype.toString.call(request.response) is '[object ArrayBuffer]'
PASS request.response.byteLength is 68
FAIL request2.status should be 304. Was 200.
PASS Object.prototype.toString.call(request2.response) is '[object ArrayBuffer]'
FAIL request2.response.byteLength should be 0. Was 68.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/js-test-resources/js-test-pre.js"></script>
</head>
<body onload="zeroContentLengthTest()">
<script>
description("Test that XMLHttpRequest.response returns an empty ArrayBuffer when received a response without an entity body.");
jsTestIsAsync = true;
function zeroContentLengthTest()
{
debug("Test that XMLHttpRequest.response returns an empty ArrayBuffer when received a response with zero content length.");
var req = new XMLHttpRequest;
req.responseType = 'arraybuffer';
req.open('GET', 'resources/zero-length.xml', true);
req.onreadystatechange = function() {
if (req.readyState != 4)
return;
request = req;
shouldBe("request.status", "200");
shouldBe("Object.prototype.toString.call(request.response)", "'[object ArrayBuffer]'");
shouldBe("request.response.byteLength", "0");
notModifiedTest();
}
req.send(null);
}
function notModifiedTest()
{
debug("Test that XMLHttpRequest.response returns an empty ArrayBuffer when received status is '304 not modified'.");
var req = new XMLHttpRequest;
req.responseType = 'arraybuffer';
req.open('GET', 'resources/reply.xml', true);
req.onreadystatechange = function() {
if (req.readyState != 4)
return;
request = req;
shouldBe("request.status", "200");
shouldBe("Object.prototype.toString.call(request.response)", "'[object ArrayBuffer]'");
shouldBe("request.response.byteLength", "68");
var lastModified = req.getResponseHeader("Last-Modified");
var req2 = new XMLHttpRequest;
req2.responseType = 'arraybuffer';
req2.open('GET', 'resources/reply.xml', true);
req2.setRequestHeader("If-Modified-Since", lastModified);
req2.onreadystatechange = function() {
if (req2.readyState != 4)
return;
request2 = req;
shouldBe("request2.status", "304");
shouldBe("Object.prototype.toString.call(request2.response)", "'[object ArrayBuffer]'");
shouldBe("request2.response.byteLength", "0");
finishJSTest();
}
req2.send(null);
}
req.send(null);
}
</script>
<script src="/js-test-resources/js-test-post.js"></script>
</body>
</html>
2013-10-30 Alexey Proskuryakov <ap@apple.com>
XHR.response is null when requesting empty file as arraybuffer
https://bugs.webkit.org/show_bug.cgi?id=123457
Reviewed by Sam Weinig.
Test: http/tests/xmlhttprequest/response-empty-arraybuffer.html
* xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::responseArrayBuffer): Don't do this.
2013-10-30 Samuel White <samuel_white@apple.com>
AX: AXFocused not exposed on ARIA menuitems
......
......@@ -325,8 +325,11 @@ ArrayBuffer* XMLHttpRequest::responseArrayBuffer()
if (m_state != DONE)
return 0;
if (!m_responseArrayBuffer.get() && m_binaryResponseBuilder.get() && m_binaryResponseBuilder->size() > 0) {
m_responseArrayBuffer = ArrayBuffer::create(const_cast<char*>(m_binaryResponseBuilder->data()), static_cast<unsigned>(m_binaryResponseBuilder->size()));
if (!m_responseArrayBuffer) {
if (m_binaryResponseBuilder)
m_responseArrayBuffer = ArrayBuffer::create(const_cast<char*>(m_binaryResponseBuilder->data()), static_cast<unsigned>(m_binaryResponseBuilder->size()));
else
m_responseArrayBuffer = ArrayBuffer::create(nullptr, 0);
m_binaryResponseBuilder.clear();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment