Commit 23d6aea5 authored by dmurph@chromium.org's avatar dmurph@chromium.org

Adding ArrayBuffer support to ServiceWorker Response and tests

BUG=412027

Review URL: https://codereview.chromium.org/556563002

git-svn-id: svn://svn.chromium.org/blink/trunk@181751 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 04365d3e
importScripts('worker-test-harness.js');
promise_test(function() {
var response = new Response('test string');
assert_equals(
response.headers.get('Content-Type'),
'text/plain;charset=UTF-8',
'A Response constructed with a string should have a Content-Type.');
return response.body.asText()
.then(function(text) {
assert_equals(text, 'test string',
'Response body text should match the string on construction.');
});
}, 'Behavior of Response with string content.');
promise_test(function() {
var intView = new Int32Array([0, 1, 2, 3, 4, 55, 6, 7, 8, 9]);
var buffer = intView.buffer;
var response = new Response(buffer);
assert_false(response.headers.has('Content-Type'),
'A Response constructed with ArrayBuffer should not have a content type.');
return response.body.asArrayBuffer()
.then(function(buffer) {
var resultIntView = new Int32Array(buffer);
assert_array_equals(
resultIntView, [0, 1, 2, 3, 4, 55, 6, 7, 8, 9],
'Response body ArrayBuffer should match ArrayBuffer ' +
'it was constructed with.');
});
}, 'Behavior of Response with arraybuffer content.');
\ No newline at end of file
<!DOCTYPE html>
<title>Service Worker: Response Content</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<script>
service_worker_test(
'resources/response-content-worker.js',
'Response content in ServiceWorkerGlobalScope');
</script>
......@@ -11,6 +11,7 @@
#include "modules/serviceworkers/FetchBodyStream.h"
#include "modules/serviceworkers/ResponseInit.h"
#include "public/platform/WebServiceWorkerResponse.h"
#include "wtf/ArrayBuffer.h"
namespace blink {
......@@ -60,6 +61,15 @@ Response* Response::create(const String& body, const Dictionary& responseInit, E
return create(blob.get(), ResponseInit(responseInit), exceptionState);
}
Response* Response::create(const ArrayBuffer* body, const Dictionary& responseInit, ExceptionState& exceptionState)
{
OwnPtr<BlobData> blobData = BlobData::create();
blobData->appendArrayBuffer(body);
const long long length = blobData->length();
RefPtrWillBeRawPtr<Blob> blob = Blob::create(BlobDataHandle::create(blobData.release(), length));
return create(blob.get(), ResponseInit(responseInit), exceptionState);
}
Response* Response::create(Blob* body, const ResponseInit& responseInit, ExceptionState& exceptionState)
{
// "1. If |init|'s status member is not in the range 200 to 599, throw a
......
......@@ -27,6 +27,7 @@ class Response FINAL : public GarbageCollected<Response>, public ScriptWrappable
public:
static Response* create(Blob*, const Dictionary&, ExceptionState&);
static Response* create(const String&, const Dictionary&, ExceptionState&);
static Response* create(const ArrayBuffer*, const Dictionary&, ExceptionState&);
static Response* create(Blob*, const ResponseInit&, ExceptionState&);
static Response* create(FetchResponseData*);
static Response* create(const WebServiceWorkerResponse&);
......
......@@ -7,10 +7,11 @@
enum ResponseType { "basic", "cors", "default", "error", "opaque" };
[
// FIXME: Add ctors for ArrayBuffer, ArrayBufferView, FormData,
// and URLSearchParams response bodies.
// FIXME: Add ctors for ArrayBufferView, FormData and URLSearchParams
// response bodies.
Constructor(ScalarValueString body, optional Dictionary responseInitDict),
Constructor(Blob? body, optional Dictionary responseInitDict),
Constructor(ArrayBuffer input, optional Dictionary requestInitDict),
RuntimeEnabled=ServiceWorker,
Exposed=ServiceWorker,
RaisesException=Constructor,
......
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