| <!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 = req2; |
| |
| 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> |