haikuwebkit/LayoutTests/streams/readable-stream-byob-reques...

315 lines
9.4 KiB
JavaScript
Raw Permalink Normal View History

[Readable Streams API] Add ReadableByteStreamController byobRequest attribute https://bugs.webkit.org/show_bug.cgi?id=168319 Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-02-20 Reviewed by Youenn Fablet. LayoutTests/imported/w3c: Updated expectations for imported w3c tests (new type of error is now obtained). * web-platform-tests/streams/readable-byte-streams/general-expected.txt: Updated. * web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt: Updated. Source/WebCore: Added ReadableByteStreamController byobRequest attribute. Added tests related to ReadableStreamBYOBRequest as a dedicated object and also as an attribute of ReadableByteStreamController. * CMakeLists.txt: Added new files. * DerivedSources.cpp: Added new files. * DerivedSources.make: Added new files. * Modules/streams/ReadableByteStreamController.idl: Added byobRequest support. * Modules/streams/ReadableByteStreamController.js: Added byobRequest support. * Modules/streams/ReadableByteStreamInternals.js: (privateInitializeReadableStreamBYOBRequest): Added constructor. * Modules/streams/ReadableStreamBYOBRequest.idl: Added. * Modules/streams/ReadableStreamBYOBRequest.js: Added. (respond): Not implemented yet. (respondWithNewView): Not implemented yet. (view): Not implemented yet. * WebCore.xcodeproj/project.pbxproj: Added new files. * bindings/js/JSDOMGlobalObject.cpp: Added ReadableStreamBYOBRequest support. (WebCore::JSDOMGlobalObject::addBuiltinGlobals): (WebCore::JSDOMGlobalObject::finishCreation): (WebCore::JSDOMGlobalObject::visitChildren): * bindings/js/JSReadableStreamPrivateConstructors.cpp: Added ReadableStreamBYOBRequest support. (WebCore::constructJSReadableByteStreamController): (WebCore::constructJSReadableStreamBYOBRequest): (WebCore::JSBuiltinReadableStreamBYOBRequestPrivateConstructor::initializeExecutable): (WebCore::createReadableStreamBYOBRequestPrivateConstructor): * bindings/js/JSReadableStreamPrivateConstructors.h: Added ReadableStreamBYOBRequest support. * bindings/js/WebCoreBuiltinNames.h: Added ReadableStreamBYOBRequest support. LayoutTests: Added tests related to ReadableStreamBYOBRequest as a dedicated object and also as an attribute of ReadableByteStreamController. * streams/readable-byte-stream-controller.js: Updated with byobRequest attribute test. * streams/readable-stream-byob-request-expected.txt: Added. * streams/readable-stream-byob-request.html: Added. * streams/readable-stream-byob-request.js: Added to cover tests related to ReadableStreamBYOBRequest. Canonical link: https://commits.webkit.org/185611@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212656 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-20 18:18:06 +00:00
'use strict';
if (self.importScripts) {
self.importScripts('../resources/testharness.js');
}
// FIXME: Remove next line when bug https://bugs.webkit.org/show_bug.cgi?id=167697
// is fixed. For the moment, so that test may pass, we have to insert a reference
// to Uint8Array here (otherwise, the private variable cannot be resolved).
const d = new Uint8Array(1);
[Readable Streams API] Add ReadableByteStreamController byobRequest attribute https://bugs.webkit.org/show_bug.cgi?id=168319 Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-02-20 Reviewed by Youenn Fablet. LayoutTests/imported/w3c: Updated expectations for imported w3c tests (new type of error is now obtained). * web-platform-tests/streams/readable-byte-streams/general-expected.txt: Updated. * web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt: Updated. Source/WebCore: Added ReadableByteStreamController byobRequest attribute. Added tests related to ReadableStreamBYOBRequest as a dedicated object and also as an attribute of ReadableByteStreamController. * CMakeLists.txt: Added new files. * DerivedSources.cpp: Added new files. * DerivedSources.make: Added new files. * Modules/streams/ReadableByteStreamController.idl: Added byobRequest support. * Modules/streams/ReadableByteStreamController.js: Added byobRequest support. * Modules/streams/ReadableByteStreamInternals.js: (privateInitializeReadableStreamBYOBRequest): Added constructor. * Modules/streams/ReadableStreamBYOBRequest.idl: Added. * Modules/streams/ReadableStreamBYOBRequest.js: Added. (respond): Not implemented yet. (respondWithNewView): Not implemented yet. (view): Not implemented yet. * WebCore.xcodeproj/project.pbxproj: Added new files. * bindings/js/JSDOMGlobalObject.cpp: Added ReadableStreamBYOBRequest support. (WebCore::JSDOMGlobalObject::addBuiltinGlobals): (WebCore::JSDOMGlobalObject::finishCreation): (WebCore::JSDOMGlobalObject::visitChildren): * bindings/js/JSReadableStreamPrivateConstructors.cpp: Added ReadableStreamBYOBRequest support. (WebCore::constructJSReadableByteStreamController): (WebCore::constructJSReadableStreamBYOBRequest): (WebCore::JSBuiltinReadableStreamBYOBRequestPrivateConstructor::initializeExecutable): (WebCore::createReadableStreamBYOBRequestPrivateConstructor): * bindings/js/JSReadableStreamPrivateConstructors.h: Added ReadableStreamBYOBRequest support. * bindings/js/WebCoreBuiltinNames.h: Added ReadableStreamBYOBRequest support. LayoutTests: Added tests related to ReadableStreamBYOBRequest as a dedicated object and also as an attribute of ReadableByteStreamController. * streams/readable-byte-stream-controller.js: Updated with byobRequest attribute test. * streams/readable-stream-byob-request-expected.txt: Added. * streams/readable-stream-byob-request.html: Added. * streams/readable-stream-byob-request.js: Added to cover tests related to ReadableStreamBYOBRequest. Canonical link: https://commits.webkit.org/185611@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212656 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-20 18:18:06 +00:00
test(function() {
let controller;
const rs = new ReadableStream({
start: function(c) {
controller = c;
},
type: "bytes"
});
assert_equals(controller.byobRequest, undefined, "by default byobRequest should be undefined");
}, "By default, byobRequest should be undefined");
test(function() {
let controller;
const autoAllocateChunkSize = 128;
const rs = new ReadableStream({
autoAllocateChunkSize,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_equals(byobReq.view.length, autoAllocateChunkSize, "byobRequest length should be equal to autoAllocateChunkSize value")
}, "byobRequest.view length should be equal to autoAllocateChunkSize")
[Readable Streams API] Implement ReadableStreamBYOBRequest respond() (closed stream state) https://bugs.webkit.org/show_bug.cgi?id=168781 Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-03-12 Reviewed by Youenn Fablet. LayoutTests/imported/w3c: Updated WPT expectations for readable byte streams tests. * web-platform-tests/streams/readable-byte-streams/general-expected.txt: * web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt: Source/WebCore: Implemented ReadableStreamBYOBRequest respond() method in the case of a closed stream. Added tests related to respond() method and updated WPT imported tests expectations. * Modules/streams/ReadableByteStreamInternals.js: (readableByteStreamControllerRespond): Added. (readableByteStreamControllerRespondInternal): Added. (readableByteStreamControllerRespondInClosedState): Added. (readableByteStreamControllerShiftPendingPullInto): Added. (readableByteStreamControllerInvalidateBYOBRequest): Added. (readableByteStreamControllerCommitPullIntoDescriptor): Added. (readableByteStreamControllerConvertPullIntoDescriptor): Added. (readableStreamFulfillReadIntoRequest): Added. * Modules/streams/ReadableStreamBYOBRequest.js: (respond): Implemented. LayoutTests: Added new tests related to ReadableStreamBYOBRequeset respond() method. * streams/readable-stream-byob-request-expected.txt: * streams/readable-stream-byob-request.js: Canonical link: https://commits.webkit.org/186517@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213770 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-12 17:27:48 +00:00
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_throws(new TypeError("Can only call ReadableStreamBYOBRequest.respond on instances of ReadableStreamBYOBRequest"),
function() { byobReq.respond.apply(rs, 1); });
}, "Calling respond() with a this object different from ReadableStreamBYOBRequest should throw a TypeError");
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_throws(new RangeError("bytesWritten has an incorrect value"),
function() { byobReq.respond(-1); });
}, "Calling respond() with a negative bytesWritten value should throw a RangeError");
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_throws(new RangeError("bytesWritten has an incorrect value"),
function() { byobReq.respond("abc"); });
}, "Calling respond() with a bytesWritten value which is not a number should throw a RangeError");
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_throws(new RangeError("bytesWritten has an incorrect value"),
function() { byobReq.respond(Number.POSITIVE_INFINITY); });
}, "Calling respond() with a positive infinity bytesWritten value should throw a RangeError");
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
controller.close();
assert_throws(new TypeError("bytesWritten is different from 0 even though stream is closed"),
function() { byobReq.respond(1); });
}, "Calling respond() with a bytesWritten value different from 0 when stream is closed should throw a TypeError");
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
// FIXME: When ReadableStreamBYOBReader is implemented, another test (or even several ones)
// based on this one should be added so that reader's readIntoRequests attribute is not empty
// and currently unreachable code is reached.
rs.getReader().read();
const byobReq = controller.byobRequest;
controller.close();
byobReq.respond(0);
}, "Calling respond() with a bytesWritten value of 0 when stream is closed should succeed");
[Readable Streams API] Implement ReadableStreamBYOBRequest respond() (readable stream state) https://bugs.webkit.org/show_bug.cgi?id=169759 Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-03-22 Reviewed by Youenn Fablet. LayoutTests/imported/w3c: Updated test expectations. * web-platform-tests/streams/readable-byte-streams/general-expected.txt: * web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt: Source/WebCore: Implemented readable state part of respond() function. Parts of code cannot currently be reached as they require ReadableStreamBYOBReader to be implemented. Added new tests and updated expectations. * Modules/streams/ReadableByteStreamInternals.js: (readableByteStreamControllerEnqueue): Name shortened. (readableByteStreamControllerRespondInternal): Updated with readable state case. (cloneArrayBuffer): Added. (readableByteStreamControllerRespondInReadableState): Added. (readableByteStreamControllerRespondInClosedState): Updated. (readableByteStreamControllerProcessPullDescriptors): Added. (readableByteStreamControllerFillDescriptorFromQueue): Added. (readableByteStreamControllerShiftPendingDescriptor): Name shortened. (readableByteStreamControllerCommitDescriptor): Name shortened. (readableByteStreamControllerConvertDescriptor): Name shortened. LayoutTests: Added new tests to check code that can currently be reached. * streams/readable-stream-byob-request-expected.txt: Updated. * streams/readable-stream-byob-request.js: Updated. Canonical link: https://commits.webkit.org/186894@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214265 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-03-22 18:07:49 +00:00
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_throws(new RangeError("bytesWritten value is too great"),
function() { byobReq.respond(17); });
}, "Calling respond() with a bytesWritten value greater than autoAllocateChunkSize should fail");
promise_test(function() {
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
pull: function(controller) {
const br = controller.byobRequest;
br.view[0] = 1;
br.view[1] = 2;
br.respond(2);
},
type: "bytes"
});
return rs.getReader().read().then(result => {
assert_equals(result.value.byteLength, 2);
assert_equals(result.value.byteOffset, 0);
assert_equals(result.value.buffer.byteLength, 16);
assert_equals(result.value[0], 1);
assert_equals(result.value[1], 2);
});
}, "Calling respond() with a bytesWritten value lower than autoAllocateChunkSize should succeed");
// FIXME: when ReadableStreamBYOBReader is implemented, add tests with elementSize different from 1
// so that more code can be covered.
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_throws(new TypeError("Can only call ReadableStreamBYOBRequest.respondWithNewView on instances of ReadableStreamBYOBRequest"),
function() { byobReq.respondWithNewView.apply(rs, new Uint8Array(1)); });
}, "Calling respondWithNewView() with a this object different from ReadableStreamBYOBRequest should throw a TypeError");
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_throws(new TypeError("Provided view is not an object"),
function() { byobReq.respondWithNewView(function() {}); });
}, "Calling respondWithNewView() with an argument that is not an object should throw a TypeError");
test(function() {
let controller;
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
start: function(c) {
controller = c;
},
type: "bytes"
});
rs.getReader().read();
const byobReq = controller.byobRequest;
assert_throws(new TypeError("Provided view is not an ArrayBufferView"),
function() { byobReq.respondWithNewView({}); });
}, "Calling respondWithNewView() with an argument that is not an ArrayBufferView should throw a TypeError");
promise_test(function() {
const rs = new ReadableStream({
autoAllocateChunkSize: 2,
pull: function(controller) {
const newView = new Uint8Array([3, 6]);
const br = controller.byobRequest;
br.respondWithNewView(newView);
},
type: "bytes"
});
return rs.getReader().read().then(result => {
assert_equals(result.value.byteLength, 2);
assert_equals(result.value.byteOffset, 0);
assert_equals(result.value.buffer.byteLength, 2);
assert_equals(result.value[0], 3);
assert_equals(result.value[1], 6);
});
}, "When using autoAllocateChunkSize, calling respondWithNewView() should succeed if view.byteLength is equal to autoAllocateChunkSize");
promise_test(function(test) {
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
pull: function(controller) {
const newView = new Uint8Array([3, 6]);
const br = controller.byobRequest;
br.respondWithNewView(newView);
},
type: "bytes"
});
const error = new RangeError("Invalid value for view.byteLength");
return promise_rejects(test, error, rs.getReader().read());
}, "When using autoAllocateChunkSize, calling respondWithNewView() should throw a RangeError if view.byteOffset is different from 0");
promise_test(function(test) {
const rs = new ReadableStream({
autoAllocateChunkSize: 16,
pull: function(controller) {
const buffer = new ArrayBuffer(3);
const newView = new Uint8Array(buffer, 1); // byteOffset of 1
const br = controller.byobRequest;
br.respondWithNewView(newView);
},
type: "bytes"
});
const error = new RangeError("Invalid value for view.byteOffset");
return promise_rejects(test, error, rs.getReader().read());
}, "When using autoAllocateChunkSize, calling respondWithNewView() should throw a RangeError if view.byteLength is different from autoAllocateChunkSize");
[Readable Streams API] Add ReadableByteStreamController byobRequest attribute https://bugs.webkit.org/show_bug.cgi?id=168319 Patch by Romain Bellessort <romain.bellessort@crf.canon.fr> on 2017-02-20 Reviewed by Youenn Fablet. LayoutTests/imported/w3c: Updated expectations for imported w3c tests (new type of error is now obtained). * web-platform-tests/streams/readable-byte-streams/general-expected.txt: Updated. * web-platform-tests/streams/readable-byte-streams/general.dedicatedworker-expected.txt: Updated. Source/WebCore: Added ReadableByteStreamController byobRequest attribute. Added tests related to ReadableStreamBYOBRequest as a dedicated object and also as an attribute of ReadableByteStreamController. * CMakeLists.txt: Added new files. * DerivedSources.cpp: Added new files. * DerivedSources.make: Added new files. * Modules/streams/ReadableByteStreamController.idl: Added byobRequest support. * Modules/streams/ReadableByteStreamController.js: Added byobRequest support. * Modules/streams/ReadableByteStreamInternals.js: (privateInitializeReadableStreamBYOBRequest): Added constructor. * Modules/streams/ReadableStreamBYOBRequest.idl: Added. * Modules/streams/ReadableStreamBYOBRequest.js: Added. (respond): Not implemented yet. (respondWithNewView): Not implemented yet. (view): Not implemented yet. * WebCore.xcodeproj/project.pbxproj: Added new files. * bindings/js/JSDOMGlobalObject.cpp: Added ReadableStreamBYOBRequest support. (WebCore::JSDOMGlobalObject::addBuiltinGlobals): (WebCore::JSDOMGlobalObject::finishCreation): (WebCore::JSDOMGlobalObject::visitChildren): * bindings/js/JSReadableStreamPrivateConstructors.cpp: Added ReadableStreamBYOBRequest support. (WebCore::constructJSReadableByteStreamController): (WebCore::constructJSReadableStreamBYOBRequest): (WebCore::JSBuiltinReadableStreamBYOBRequestPrivateConstructor::initializeExecutable): (WebCore::createReadableStreamBYOBRequestPrivateConstructor): * bindings/js/JSReadableStreamPrivateConstructors.h: Added ReadableStreamBYOBRequest support. * bindings/js/WebCoreBuiltinNames.h: Added ReadableStreamBYOBRequest support. LayoutTests: Added tests related to ReadableStreamBYOBRequest as a dedicated object and also as an attribute of ReadableByteStreamController. * streams/readable-byte-stream-controller.js: Updated with byobRequest attribute test. * streams/readable-stream-byob-request-expected.txt: Added. * streams/readable-stream-byob-request.html: Added. * streams/readable-stream-byob-request.js: Added to cover tests related to ReadableStreamBYOBRequest. Canonical link: https://commits.webkit.org/185611@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@212656 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-02-20 18:18:06 +00:00
done();